Skip to content

Instantly share code, notes, and snippets.

@weltling
Created May 13, 2014 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weltling/a941d8cf6c731640b51f to your computer and use it in GitHub Desktop.
Save weltling/a941d8cf6c731640b51f to your computer and use it in GitHub Desktop.
diff --git a/Zend/zend.h b/Zend/zend.h
index 2780181..86e66ac 100644
--- a/Zend/zend.h
+++ b/Zend/zend.h
@@ -497,8 +497,8 @@ struct _zend_class_entry {
union {
struct {
zend_string *filename;
- zend_uint line_start;
- zend_uint line_end;
+ zend_size_t line_start;
+ zend_size_t line_end;
zend_string *doc_comment;
} user;
struct {
diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h
index 1ff45ff..f00e7e3 100644
--- a/Zend/zend_compile.h
+++ b/Zend/zend_compile.h
@@ -68,8 +68,8 @@ typedef struct _zend_compiler_context {
typedef union _znode_op {
zend_uint constant;
zend_uint var;
- zend_uint num;
- zend_ulong hash;
+ zend_size_t num;
+ zend_uint_t hash;
zend_uint opline_num; /* Needs to be signed */
zend_op *jmp_addr;
zval *zv;
@@ -102,8 +102,8 @@ struct _zend_op {
znode_op op1;
znode_op op2;
znode_op result;
- ulong extended_value;
- uint lineno;
+ zend_uint_t extended_value;
+ zend_size_t lineno;
zend_uchar opcode;
zend_uchar op1_type;
zend_uchar op2_type;
@@ -212,7 +212,7 @@ char *zend_visibility_string(zend_uint fn_flags);
typedef struct _zend_property_info {
zend_uint flags;
zend_string *name;
- ulong h;
+ zend_uint_t h;
int offset;
zend_string *doc_comment;
zend_class_entry *ce;
@@ -220,9 +220,9 @@ typedef struct _zend_property_info {
typedef struct _zend_arg_info {
const char *name; // TODO: convert into zend_string ???
- zend_uint name_len;
+ zend_size_t name_len;
const char *class_name; // TODO: convert into zend_string ???
- zend_uint class_name_len;
+ zend_size_t class_name_len;
zend_uchar type_hint;
zend_uchar pass_by_reference;
zend_bool allow_null;
@@ -235,9 +235,9 @@ typedef struct _zend_arg_info {
*/
typedef struct _zend_internal_function_info {
const char *_name;
- zend_uint _name_len;
+ zend_size_t _name_len;
const char *_class_name;
- zend_uint required_num_args;
+ zend_size_t required_num_args;
zend_uchar _type_hint;
zend_bool return_reference;
zend_bool _allow_null;
@@ -251,8 +251,8 @@ struct _zend_op_array {
zend_class_entry *scope;
zend_uint fn_flags;
zend_function *prototype;
- zend_uint num_args;
- zend_uint required_num_args;
+ zend_size_t num_args;
+ zend_size_t required_num_args;
zend_arg_info *arg_info;
/* END of common elements */
@@ -282,8 +282,8 @@ struct _zend_op_array {
zend_uint this_var;
zend_string *filename;
- zend_uint line_start;
- zend_uint line_end;
+ zend_size_t line_start;
+ zend_size_t line_end;
zend_string *doc_comment;
zend_uint early_binding; /* the linked list of delayed declarations */
@@ -307,8 +307,8 @@ typedef struct _zend_internal_function {
zend_class_entry *scope;
zend_uint fn_flags;
zend_function *prototype;
- zend_uint num_args;
- zend_uint required_num_args;
+ zend_size_t num_args;
+ zend_size_t required_num_args;
zend_arg_info *arg_info;
/* END of common elements */
@@ -327,8 +327,8 @@ union _zend_function {
zend_class_entry *scope;
zend_uint fn_flags;
union _zend_function *prototype;
- zend_uint num_args;
- zend_uint required_num_args;
+ zend_size_t num_args;
+ zend_size_t required_num_args;
zend_arg_info *arg_info;
} common;
diff --git a/Zend/zend_generators.h b/Zend/zend_generators.h
index 999ead4..3b0f3bb 100644
--- a/Zend/zend_generators.h
+++ b/Zend/zend_generators.h
@@ -43,7 +43,7 @@ typedef struct _zend_generator {
/* Variable to put sent value into */
zval *send_target;
/* Largest used integer key for auto-incrementing keys */
- long largest_used_integer_key;
+ zend_int_t largest_used_integer_key;
/* ZEND_GENERATOR_* flags */
zend_uchar flags;
diff --git a/Zend/zend_globals.h b/Zend/zend_globals.h
index 2a29e33..d22409c 100644
--- a/Zend/zend_globals.h
+++ b/Zend/zend_globals.h
@@ -87,7 +87,7 @@ struct _zend_compiler_globals {
zend_string *compiled_filename;
- int zend_lineno;
+ zend_size_t zend_lineno;
zend_op_array *active_op_array;
@@ -111,7 +111,7 @@ struct _zend_compiler_globals {
zend_llist open_files;
- long catch_begin;
+ zend_int_t catch_begin;
struct _zend_ini_parser_param *ini_parser_param;
@@ -191,7 +191,7 @@ struct _zend_executor_globals {
zval This;
- long precision;
+ zend_int_t precision;
int ticks_count;
@@ -224,7 +224,7 @@ struct _zend_executor_globals {
zend_class_entry *exception_class;
/* timeout support */
- int timeout_seconds;
+ zend_int_t timeout_seconds;
int lambda_count;
@@ -303,7 +303,7 @@ struct _zend_php_scanner_globals {
const zend_encoding *script_encoding;
/* initial string length after scanning to first variable */
- int scanned_string_len;
+ zend_size_t scanned_string_len;
};
#endif /* ZEND_GLOBALS_H */
diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h
index 56c7b9a..626683b 100644
--- a/Zend/zend_hash.h
+++ b/Zend/zend_hash.h
@@ -49,7 +49,7 @@
#define HASH_MASK_CONSISTENCY 0x60
typedef struct _zend_hash_key {
- ulong h;
+ zend_uint_t h;
zend_string *key;
} zend_hash_key;
diff --git a/Zend/zend_ini.h b/Zend/zend_ini.h
index 0a0c113..64569e4 100644
--- a/Zend/zend_ini.h
+++ b/Zend/zend_ini.h
@@ -34,17 +34,17 @@ struct _zend_ini_entry {
int module_number;
int modifiable;
char *name; // TODO: convert into zend_string ???
- uint name_length;
+ zend_size_t name_length;
ZEND_INI_MH((*on_modify));
void *mh_arg1;
void *mh_arg2;
void *mh_arg3;
char *value; // TODO: convert into zend_string ???
- uint value_length;
+ zend_size_t value_length;
char *orig_value; // TODO: convert into zend_string ???
- uint orig_value_length;
+ zend_size_t orig_value_length;
int orig_modifiable;
int modified;
diff --git a/Zend/zend_int.h b/Zend/zend_int.h
index e69de29..de48718 100644
--- a/Zend/zend_int.h
+++ b/Zend/zend_int.h
@@ -0,0 +1,145 @@
+/*
+ +----------------------------------------------------------------------+
+ | Zend Engine |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1998-2013 Zend Technologies Ltd. (http://www.zend.com) |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.00 of the Zend license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.zend.com/license/2_00.txt. |
+ | If you did not receive a copy of the Zend license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@zend.com so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Authors: Anatol Belski <ab@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+/* $Id$ */
+
+
+#ifndef ZEND_INT_H
+#define ZEND_INT_H
+
+#ifndef ZEND_WIN32
+/* this probably needs more on non windows, like for C++ and C99*/
+# include <stdint.h>
+# include <inttypes.h>
+#endif
+
+/* This is the heart of the whole int64 enablement in zval. Based on this
+ macros the zend_size_t datatype is handled, see zend_types.h */
+#if defined(__X86_64__) || defined(__LP64__) || defined(_LP64) || defined(_WIN64)
+# define ZEND_ENABLE_INT64 1
+#endif
+
+/* Integer types or the old bad long. */
+#ifdef ZEND_ENABLE_INT64
+# ifdef ZEND_WIN32
+# ifdef _WIN64
+typedef __int64 zend_int_t;
+typedef unsigned __int64 zend_uint_t;
+typedef __int64 zend_off_t;
+# define ZEND_INT_MAX _I64_MAX
+# define ZEND_INT_MIN _I64_MIN
+# define ZEND_UINT_MAX _UI64_MAX
+# define Z_I(i) i##i64
+# define Z_UI(i) i##Ui64
+# else
+# error Cant enable 64 bit integers on non 64 bit platform
+# endif
+# else
+# if defined(__X86_64__) || defined(__LP64__) || defined(_LP64)
+typedef int64_t zend_int_t;
+typedef uint64_t zend_uint_t;
+typedef off_t zend_off_t;
+# define ZEND_INT_MAX INT64_MAX
+# define ZEND_INT_MIN INT64_MIN
+# define ZEND_UINT_MAX UINT64_MAX
+# define Z_I(i) i##LL
+# define Z_UI(i) i##ULL
+# else
+# error Cant enable 64 bit integers on non 64 bit platform
+# endif
+# endif
+# define SIZEOF_ZEND_INT 8
+#else
+typedef long zend_int_t;
+typedef unsigned long zend_uint_t;
+typedef long zend_off_t;
+# define ZEND_INT_MAX LONG_MAX
+# define ZEND_INT_MIN LONG_MIN
+# define ZEND_UINT_MAX ULONG_MAX
+# define Z_I(i) i##L
+# define Z_UI(i) i##UL
+# define SIZEOF_ZEND_INT SIZEOF_LONG
+#endif
+
+
+/* conversion macros */
+#define ZEND_ITOA_BUF_LEN 65
+
+#ifdef ZEND_ENABLE_INT64
+# ifdef PHP_WIN32
+# define ZEND_ITOA(i, s, len) _i64toa_s((i), (s), (len), 10)
+# define ZEND_ATOI(i, s) i = _atoi64((s))
+# define ZEND_STRTOI(s0, s1, base) _strtoi64((s0), (s1), (base))
+# define ZEND_STRTOUI(s0, s1, base) _strtoui64((s0), (s1), (base))
+# define ZEND_INT_FMT "%I64d"
+# define ZEND_UINT_FMT "%I64u"
+# define ZEND_INT_FMT_SPEC "I64d"
+# define ZEND_UINT_FMT_SPEC "I64u"
+# define ZEND_STRTOI_PTR _strtoi64
+# define ZEND_STRTOUI_PTR _strtoui64
+# define ZEND_ABS _abs64
+# else
+# define ZEND_ITOA(i, s, len) \
+ do { \
+ int st = snprintf((s), (len), "%lld", (i)); \
+ (s)[st] = '\0'; \
+ } while (0)
+# define ZEND_ATOI(i, s) (i) = atoll((s))
+# define ZEND_STRTOI(s0, s1, base) strtoll((s0), (s1), (base))
+# define ZEND_STRTOUI(s0, s1, base) strtoull((s0), (s1), (base))
+# define ZEND_INT_FMT "%" PRId64
+# define ZEND_UINT_FMT "%" PRIu64
+# define ZEND_INT_FMT_SPEC PRId64
+# define ZEND_UINT_FMT_SPEC PRIu64
+# define ZEND_STRTOI_PTR strtoll
+# define ZEND_STRTOUI_PTR strtoull
+# define ZEND_ABS llabs
+# endif
+#else
+# define ZEND_STRTOI(s0, s1, base) strtol((s0), (s1), (base))
+# define ZEND_STRTOUI(s0, s1, base) strtoul((s0), (s1), (base))
+# ifdef PHP_WIN32
+# define ZEND_ITOA(i, s, len) _ltoa_s((i), (s), (len), 10)
+# define ZEND_ATOI(i, s) i = atol((s))
+# else
+# define ZEND_ITOA(i, s, len) \
+ do { \
+ int st = snprintf((s), (len), "%ld", (i)); \
+ (s)[st] = '\0'; \
+ } while (0)
+# define ZEND_ATOI(i, s) (i) = atol((s))
+# endif
+# define ZEND_INT_FMT "%ld"
+# define ZEND_UINT_FMT "%lu"
+# define ZEND_INT_FMT_SPEC "ld"
+# define ZEND_UINT_FMT_SPEC "lu"
+# define ZEND_STRTOI_PTR strtol
+# define ZEND_STRTOUI_PTR strtoul
+# define ZEND_ABS abs
+#endif
+
+
+#endif /* ZEND_INT_H */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: t
+ * End:
+ */
diff --git a/Zend/zend_stack.h b/Zend/zend_stack.h
index 6700053..642d5f4 100644
--- a/Zend/zend_stack.h
+++ b/Zend/zend_stack.h
@@ -23,7 +23,7 @@
#define ZEND_STACK_H
typedef struct _zend_stack {
- int size, top, max;
+ zend_size_t size, top, max;
void *elements;
} zend_stack;
diff --git a/Zend/zend_stream.h b/Zend/zend_stream.h
index 5306b49..10fa8d8 100644
--- a/Zend/zend_stream.h
+++ b/Zend/zend_stream.h
@@ -24,6 +24,9 @@
#ifndef ZEND_STREAM_H
#define ZEND_STREAM_H
+#include <sys/types.h>
+#include <sys/stat.h>
+
/* Lightweight stream implementation for the ZE scanners.
* These functions are private to the engine.
* */
@@ -78,4 +81,20 @@ ZEND_API void zend_file_handle_dtor(zend_file_handle *fh TSRMLS_DC);
ZEND_API int zend_compare_file_handles(zend_file_handle *fh1, zend_file_handle *fh2);
END_EXTERN_C()
+#ifdef _WIN64
+# define zend_fseek _fseeki64
+# define zend_ftell _ftelli64
+# define zend_lseek _lseeki64
+# define zend_fstat _fstat64
+# define zend_stat _stat64
+typedef struct __stat64 zend_stat_t;
+#else
+# define zend_fseek fseek
+# define zend_ftell ftell
+# define zend_lseek lseek
+# define zend_fstat fstat
+# define zend_stat stat
+typedef struct stat zend_stat_t;
+#endif
+
#endif
diff --git a/Zend/zend_types.h b/Zend/zend_types.h
index 343c670..f5689de 100644
--- a/Zend/zend_types.h
+++ b/Zend/zend_types.h
@@ -22,6 +22,8 @@
#ifndef ZEND_TYPES_H
#define ZEND_TYPES_H
+#include "zend_int.h"
+
#ifdef WORDS_BIGENDIAN
# define ZEND_ENDIAN_LOHI(lo, hi) hi; lo;
# define ZEND_ENDIAN_LOHI_3(lo, mi, hi) hi; mi; lo;
@@ -44,6 +46,21 @@ typedef unsigned int zend_uint;
typedef unsigned long zend_ulong;
typedef unsigned short zend_ushort;
+#ifdef ZEND_ENABLE_INT64
+# ifdef ZEND_WIN32
+# define ZEND_SIZE_MAX _UI64_MAX
+# else
+# define ZEND_SIZE_MAX SIZE_MAX
+# endif
+#else
+# if defined(ZEND_WIN32)
+# define ZEND_SIZE_MAX _UI32_MAX
+# else
+# define ZEND_SIZE_MAX SIZE_MAX
+# endif
+#endif
+typedef size_t zend_size_t;
+
#define HAVE_ZEND_LONG64
#ifdef ZEND_WIN32
typedef __int64 zend_long64;
@@ -87,7 +104,7 @@ typedef void (*dtor_func_t)(zval *pDest);
typedef void (*copy_ctor_func_t)(zval *pElement);
typedef union _zend_value {
- long lval; /* long value */
+ zend_int_t lval; /* long value */
double dval; /* double value */
zend_refcounted *counted;
zend_string *str;
@@ -137,25 +154,25 @@ struct _zend_refcounted {
struct _zend_string {
zend_refcounted gc;
- zend_ulong h; /* hash value */
- int len;
+ zend_uint_t h; /* hash value */
+ zend_size_t len;
char val[1];
};
typedef struct _Bucket {
- zend_ulong h; /* hash value (or numeric index) */
+ zend_uint_t h; /* hash value (or numeric index) */
zend_string *key; /* string key or NULL for numerics */
zval val;
} Bucket;
typedef struct _HashTable {
- zend_uint nTableSize;
- zend_uint nTableMask;
- zend_uint nNumUsed;
- zend_uint nNumOfElements;
- long nNextFreeElement;
+ zend_uint_t nTableSize;
+ zend_uint_t nTableMask;
+ zend_uint_t nNumUsed;
+ zend_uint_t nNumOfElements;
+ zend_int_t nNextFreeElement;
Bucket *arData;
- zend_uint *arHash;
+ zend_uint_t *arHash;
dtor_func_t pDestructor;
zend_uint nInternalPointer;
union {
@@ -176,7 +193,7 @@ struct _zend_array {
struct _zend_object {
zend_refcounted gc;
- zend_uint handle; // TODO: may be removed ???
+ zend_uint_t handle; // TODO: may be removed ???
zend_class_entry *ce;
const zend_object_handlers *handlers;
HashTable *properties;
@@ -206,7 +223,7 @@ struct _zend_ast_ref {
#define IS_NULL 1
#define IS_FALSE 2
#define IS_TRUE 3
-#define IS_LONG 4
+#define IS_INT 4
#define IS_DOUBLE 5
#define IS_STRING 6
#define IS_ARRAY 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment