Skip to content
This repository was archived by the owner on May 27, 2022. It is now read-only.

Commit 3c66e8b

Browse files
committed
- windows support
1 parent 33a1a98 commit 3c66e8b

8 files changed

+86
-28
lines changed

config.w32

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// $Id$
2+
// vim:ft=javascript
3+
4+
ARG_ENABLE("igbinary", "whether to enable igbinary support", "no");
5+
6+
if (PHP_IGBINARY == "yes") {
7+
EXTENSION("igbinary", "igbinary.c hash_si.c hash_function.c");
8+
AC_DEFINE('HAVE_IGBINARY', 1, 'Have igbinary support', false);
9+
ADD_EXTENSION_DEP('igbinary', 'session');
10+
}

hash.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88
#define HASH_H
99

1010
#include <assert.h>
11-
#include <stdint.h>
11+
12+
#ifdef PHP_WIN32
13+
# include "ig_win32.h"
14+
#else
15+
# include <stdint.h> /* defines uint32_t etc */
16+
#endif
17+
1218
#include <stddef.h>
1319

1420
/** Key/value pair of hash_si.

hash_function.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
-------------------------------------------------------------------------------
33
lookup3.c, by Bob Jenkins, May 2006, Public Domain.
44
*/
5-
6-
#include <sys/param.h> /* attempt to define endianness */
7-
#ifdef linux
8-
# include <endian.h> /* attempt to define endianness */
5+
#ifdef PHP_WIN32
6+
# include "ig_win32.h"
7+
#else
8+
# include <sys/param.h> /* attempt to define endianness */
9+
# ifdef linux
10+
# include <endian.h> /* attempt to define endianness */
11+
# endif
912
#endif
10-
1113
#include "hash_function.h"
1214

1315
#define hashsize(n) ((uint32_t)1<<(n))

hash_function.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
#ifndef HASH_FUNCTION_H
88
#define HASH_FUNCTION_H
9-
10-
#include <stdint.h> /* defines uint32_t etc */
11-
9+
#ifdef PHP_WIN32
10+
# include "ig_win32.h"
11+
#else
12+
# include <stdint.h> /* defines uint32_t etc */
13+
#endif
1214
/**
1315
* Hash function
1416
*

hash_si.c

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
*
44
* $Id: hash_si.c,v 1.5 2008/07/01 17:02:18 phadej Exp $
55
*/
6+
#ifdef PHP_WIN32
7+
# include "ig_win32.h"
8+
#endif
69

710
#include <stdio.h>
811
#include <stdlib.h>

ig_win32.h

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef _IG_WIN32_H
2+
#define _IG_WIN32_H
3+
4+
#if PHP_WIN32
5+
# include "win32/php_stdint.h"
6+
# ifndef inline
7+
# define inline __inline
8+
# endif
9+
10+
# ifndef __cplusplus
11+
# if !0
12+
typedef enum { false = 0, true = 1 } _Bool;
13+
# endif
14+
# else
15+
typedef bool _Bool;
16+
# endif
17+
# define bool _Bool
18+
19+
# define false 0
20+
# define true 1
21+
# define __bool_true_false_are_defined 1
22+
#endif
23+
24+
#endif

igbinary.c

+25-16
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
#include "config.h"
99
#endif
1010

11+
#ifdef PHP_WIN32
12+
# include "ig_win32.h"
13+
#endif
14+
1115
#include "php.h"
1216
#include "php_ini.h"
1317
#include "zend_dynamic_array.h"
@@ -21,11 +25,14 @@
2125

2226
#include <assert.h>
2327

24-
#include <inttypes.h>
25-
#include <stdbool.h>
26-
#include <stddef.h>
27-
#include <stdint.h>
28+
#ifndef PHP_WIN32
29+
# include <inttypes.h>
30+
# include <stdbool.h>
31+
# include <stdint.h>
32+
#endif
2833

34+
35+
#include <stddef.h>
2936
#include "hash.h"
3037

3138
/** Session serializer function prototypes. */
@@ -326,13 +333,13 @@ int igbinary_unserialize(const uint8_t *buf, size_t buf_len, zval **z TSRMLS_DC)
326333
/* }}} */
327334
/* {{{ proto string igbinary_unserialize(mixed value) */
328335
PHP_FUNCTION(igbinary_unserialize) {
336+
char *string;
337+
int string_len;
338+
329339
(void) return_value_ptr;
330340
(void) this_ptr;
331341
(void) return_value_used;
332342

333-
char *string;
334-
int string_len;
335-
336343
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &string, &string_len) == FAILURE) {
337344
RETURN_NULL();
338345
}
@@ -348,12 +355,13 @@ PHP_FUNCTION(igbinary_unserialize) {
348355
/* }}} */
349356
/* {{{ proto mixed igbinary_serialize(string value) */
350357
PHP_FUNCTION(igbinary_serialize) {
358+
zval *z;
359+
struct igbinary_serialize_data igsd;
360+
351361
(void) return_value_ptr;
352362
(void) this_ptr;
353363
(void) return_value_used;
354364

355-
zval *z;
356-
struct igbinary_serialize_data igsd;
357365

358366
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &z) == FAILURE) {
359367
RETURN_NULL();
@@ -642,13 +650,13 @@ inline static int igbinary_serialize_long(struct igbinary_serialize_data *igsd,
642650
/* {{{ igbinary_serialize_double */
643651
/** Serializes double. */
644652
inline static int igbinary_serialize_double(struct igbinary_serialize_data *igsd, double d TSRMLS_DC) {
645-
igbinary_serialize8(igsd, igbinary_type_double TSRMLS_CC);
646-
647653
union {
648654
double d;
649655
uint64_t u;
650656
} u;
651657

658+
igbinary_serialize8(igsd, igbinary_type_double TSRMLS_CC);
659+
652660
u.d = d;
653661

654662
igbinary_serialize64(igsd, u.u TSRMLS_CC);
@@ -1331,17 +1339,18 @@ inline static int igbinary_unserialize_long(struct igbinary_unserialize_data *ig
13311339
/* {{{ igbinary_unserialize_double */
13321340
/** Unserializes double. */
13331341
inline static int igbinary_unserialize_double(struct igbinary_unserialize_data *igsd, enum igbinary_type t, double *ret TSRMLS_DC) {
1342+
union {
1343+
double d;
1344+
uint64_t u;
1345+
} u;
1346+
13341347
(void) t;
13351348

13361349
if (igsd->buffer_offset + 8 > igsd->buffer_size) {
13371350
zend_error(E_WARNING, "igbinary_unserialize_double: end-of-data");
13381351
return 1;
13391352
}
13401353

1341-
union {
1342-
double d;
1343-
uint64_t u;
1344-
} u;
13451354

13461355
u.u = igbinary_unserialize64(igsd TSRMLS_CC);
13471356

@@ -1498,7 +1507,7 @@ inline static int igbinary_unserialize_array(struct igbinary_unserialize_data *i
14981507

14991508
// n cannot be larger than the number of minimum "objects" in the array
15001509
if (n > igsd->buffer_size - igsd->buffer_offset) {
1501-
zend_error(E_WARNING, "%s: data size %zu smaller that requested array length %zu.", __func__, igsd->buffer_size - igsd->buffer_offset, n);
1510+
zend_error(E_WARNING, "%s: data size %zu smaller that requested array length %zu.", "igbinary_unserialize_array", igsd->buffer_size - igsd->buffer_offset, n);
15021511
return 1;
15031512
}
15041513

igbinary.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
#ifndef IGBINARY_H
88
#define IGBINARY_H
9-
10-
#include <stdint.h>
11-
9+
#ifdef PHP_WIN32
10+
# include "ig_win32.h"
11+
#else
12+
# include <stdint.h>
13+
#endif
1214
#include "php.h"
1315

1416
#define IGBINARY_VERSION "1.0.2"

0 commit comments

Comments
 (0)