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

Commit

Permalink
- windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrejoye committed Dec 31, 2010
1 parent 33a1a98 commit 3c66e8b
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 28 deletions.
10 changes: 10 additions & 0 deletions config.w32
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// $Id$
// vim:ft=javascript

ARG_ENABLE("igbinary", "whether to enable igbinary support", "no");

if (PHP_IGBINARY == "yes") {
EXTENSION("igbinary", "igbinary.c hash_si.c hash_function.c");
AC_DEFINE('HAVE_IGBINARY', 1, 'Have igbinary support', false);
ADD_EXTENSION_DEP('igbinary', 'session');
}
8 changes: 7 additions & 1 deletion hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
#define HASH_H

#include <assert.h>
#include <stdint.h>

#ifdef PHP_WIN32
# include "ig_win32.h"
#else
# include <stdint.h> /* defines uint32_t etc */
#endif

#include <stddef.h>

/** Key/value pair of hash_si.
Expand Down
12 changes: 7 additions & 5 deletions hash_function.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
-------------------------------------------------------------------------------
lookup3.c, by Bob Jenkins, May 2006, Public Domain.
*/

#include <sys/param.h> /* attempt to define endianness */
#ifdef linux
# include <endian.h> /* attempt to define endianness */
#ifdef PHP_WIN32
# include "ig_win32.h"
#else
# include <sys/param.h> /* attempt to define endianness */
# ifdef linux
# include <endian.h> /* attempt to define endianness */
# endif
#endif

#include "hash_function.h"

#define hashsize(n) ((uint32_t)1<<(n))
Expand Down
8 changes: 5 additions & 3 deletions hash_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

#ifndef HASH_FUNCTION_H
#define HASH_FUNCTION_H

#include <stdint.h> /* defines uint32_t etc */

#ifdef PHP_WIN32
# include "ig_win32.h"
#else
# include <stdint.h> /* defines uint32_t etc */
#endif
/**
* Hash function
*
Expand Down
3 changes: 3 additions & 0 deletions hash_si.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
*
* $Id: hash_si.c,v 1.5 2008/07/01 17:02:18 phadej Exp $
*/
#ifdef PHP_WIN32
# include "ig_win32.h"
#endif

#include <stdio.h>
#include <stdlib.h>
Expand Down
24 changes: 24 additions & 0 deletions ig_win32.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef _IG_WIN32_H
#define _IG_WIN32_H

#if PHP_WIN32
# include "win32/php_stdint.h"
# ifndef inline
# define inline __inline
# endif

# ifndef __cplusplus
# if !0
typedef enum { false = 0, true = 1 } _Bool;
# endif
# else
typedef bool _Bool;
# endif
# define bool _Bool

# define false 0
# define true 1
# define __bool_true_false_are_defined 1
#endif

#endif
41 changes: 25 additions & 16 deletions igbinary.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include "config.h"
#endif

#ifdef PHP_WIN32
# include "ig_win32.h"
#endif

#include "php.h"
#include "php_ini.h"
#include "zend_dynamic_array.h"
Expand All @@ -21,11 +25,14 @@

#include <assert.h>

#include <inttypes.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#ifndef PHP_WIN32
# include <inttypes.h>
# include <stdbool.h>
# include <stdint.h>
#endif


#include <stddef.h>
#include "hash.h"

/** Session serializer function prototypes. */
Expand Down Expand Up @@ -326,13 +333,13 @@ int igbinary_unserialize(const uint8_t *buf, size_t buf_len, zval **z TSRMLS_DC)
/* }}} */
/* {{{ proto string igbinary_unserialize(mixed value) */
PHP_FUNCTION(igbinary_unserialize) {
char *string;
int string_len;

(void) return_value_ptr;
(void) this_ptr;
(void) return_value_used;

char *string;
int string_len;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &string, &string_len) == FAILURE) {
RETURN_NULL();
}
Expand All @@ -348,12 +355,13 @@ PHP_FUNCTION(igbinary_unserialize) {
/* }}} */
/* {{{ proto mixed igbinary_serialize(string value) */
PHP_FUNCTION(igbinary_serialize) {
zval *z;
struct igbinary_serialize_data igsd;

(void) return_value_ptr;
(void) this_ptr;
(void) return_value_used;

zval *z;
struct igbinary_serialize_data igsd;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &z) == FAILURE) {
RETURN_NULL();
Expand Down Expand Up @@ -642,13 +650,13 @@ inline static int igbinary_serialize_long(struct igbinary_serialize_data *igsd,
/* {{{ igbinary_serialize_double */
/** Serializes double. */
inline static int igbinary_serialize_double(struct igbinary_serialize_data *igsd, double d TSRMLS_DC) {
igbinary_serialize8(igsd, igbinary_type_double TSRMLS_CC);

union {
double d;
uint64_t u;
} u;

igbinary_serialize8(igsd, igbinary_type_double TSRMLS_CC);

u.d = d;

igbinary_serialize64(igsd, u.u TSRMLS_CC);
Expand Down Expand Up @@ -1331,17 +1339,18 @@ inline static int igbinary_unserialize_long(struct igbinary_unserialize_data *ig
/* {{{ igbinary_unserialize_double */
/** Unserializes double. */
inline static int igbinary_unserialize_double(struct igbinary_unserialize_data *igsd, enum igbinary_type t, double *ret TSRMLS_DC) {
union {
double d;
uint64_t u;
} u;

(void) t;

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

union {
double d;
uint64_t u;
} u;

u.u = igbinary_unserialize64(igsd TSRMLS_CC);

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

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

Expand Down
8 changes: 5 additions & 3 deletions igbinary.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

#ifndef IGBINARY_H
#define IGBINARY_H

#include <stdint.h>

#ifdef PHP_WIN32
# include "ig_win32.h"
#else
# include <stdint.h>
#endif
#include "php.h"

#define IGBINARY_VERSION "1.0.2"
Expand Down

0 comments on commit 3c66e8b

Please sign in to comment.