1
0
Fork 0

refactor: split compatibility

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@991 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
3.0
Xuefer 2012-07-18 07:52:35 +00:00
parent 0af13b375c
commit 79feb1e772
8 changed files with 281 additions and 269 deletions

View File

@ -28,6 +28,7 @@ if test "$PHP_XCACHE" != "no"; then
util/xc_trace.c \
xcache.c \
xcache/xc_const_string.c \
xcache/xc_compatibility.c \
xcache/xc_lock.c \
xcache/xc_mem.c \
xcache/xc_opcode_spec.c \

View File

@ -16,6 +16,7 @@ if (PHP_XCACHE != "no") {
util/xc_trace.c \
xcache.c \
xcache/xc_const_string.c \
xcache/xc_compatibility.c \
xcache/xc_lock.c \
xcache/xc_mem.c \
xcache/xc_opcode_spec.c \

218
xcache.h
View File

@ -21,210 +21,11 @@
#endif
#include "xcache/xc_shm.h"
#include "xcache/xc_lock.h"
#if !defined(ZEND_ENGINE_2_4) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4 || PHP_MAJOR_VERSION > 5)
# define ZEND_ENGINE_2_4
#endif
#if !defined(ZEND_ENGINE_2_3) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 3 || defined(ZEND_ENGINE_2_4))
# define ZEND_ENGINE_2_3
#endif
#if !defined(ZEND_ENGINE_2_2) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 2 || defined(ZEND_ENGINE_2_3))
# define ZEND_ENGINE_2_2
#endif
#if !defined(ZEND_ENGINE_2_1) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 1 || defined(ZEND_ENGINE_2_2))
# define ZEND_ENGINE_2_1
#endif
#define NOTHING
/* ZendEngine code Switcher */
#ifndef ZEND_ENGINE_2
# define ZESW(v1, v2) v1
#else
# define ZESW(v1, v2) v2
#endif
#ifdef ZEND_ENGINE_2_4
# define ZEND_24(pre24, v24) v24
#else
# define ZEND_24(pre24, v24) pre24
#endif
#ifdef do_alloca_with_limit
# define my_do_alloca(size, use_heap) do_alloca_with_limit(size, use_heap)
# define my_free_alloca(size, use_heap) free_alloca_with_limit(size, use_heap)
#elif defined(ALLOCA_FLAG)
# define my_do_alloca(size, use_heap) do_alloca(size, use_heap)
# define my_free_alloca(size, use_heap) free_alloca(size, use_heap)
#else
# define my_do_alloca(size, use_heap) do_alloca(size)
# define my_free_alloca(size, use_heap) free_alloca(size)
# define ALLOCA_FLAG(x)
#endif
#ifndef Z_ISREF
# define Z_ISREF(z) (z).is_ref
#endif
#ifndef Z_SET_ISREF
# define Z_SET_ISREF(z) (z).is_ref = 1
#endif
#ifndef Z_UNSET_ISREF
# define Z_UNSET_ISREF(z) (z).is_ref = 0
#endif
#ifndef Z_REFCOUNT
# define Z_REFCOUNT(z) (z).refcount
#endif
#ifndef Z_SET_REFCOUNT
# define Z_SET_REFCOUNT(z, rc) (z).refcount = rc
#endif
#ifndef IS_CONSTANT_TYPE_MASK
# define IS_CONSTANT_TYPE_MASK (~IS_CONSTANT_INDEX)
#endif
/* {{{ dirty fix for PHP 6 */
#ifdef add_assoc_long_ex
static inline void my_add_assoc_long_ex(zval *arg, char *key, uint key_len, long value)
{
add_assoc_long_ex(arg, key, key_len, value);
}
# undef add_assoc_long_ex
# define add_assoc_long_ex my_add_assoc_long_ex
#endif
#ifdef add_assoc_bool_ex
static inline void my_add_assoc_bool_ex(zval *arg, char *key, uint key_len, zend_bool value)
{
add_assoc_bool_ex(arg, key, key_len, value);
}
# undef add_assoc_bool_ex
# define add_assoc_bool_ex my_add_assoc_bool_ex
#endif
#ifdef add_assoc_null_ex
static inline void my_add_assoc_null_ex(zval *arg, char *key, uint key_len)
{
add_assoc_null_ex(arg, key, key_len);
}
# undef add_assoc_null_ex
# define add_assoc_null_ex my_add_assoc_null_ex
#endif
#ifdef ZEND_ENGINE_2_4
# define Z_OP(op) (op)
# define Z_OP_CONSTANT(op) (op).literal->constant
# define Z_OP_TYPE(op) op##_##type
# define Z_OP_TYPEOF_TYPE zend_uchar
# define Z_CLASS_INFO(className) (className).info.user
#else
# define Z_OP(op) (op).u
# define Z_OP_CONSTANT(op) (op).u.constant
# define Z_OP_TYPE(op) (op).op_type
# define Z_OP_TYPEOF_TYPE int
typedef znode znode_op;
# define Z_CLASS_INFO(className) (className)
#endif
/* }}} */
/* unicode */
#ifdef IS_UNICODE
# define UNISW(text, unicode) unicode
#else
# define UNISW(text, unicode) text
#endif
#define BUCKET_KEY_SIZE(b) \
(UNISW( \
(b)->nKeyLength, \
((b)->key.type == IS_UNICODE) \
? UBYTES(b->nKeyLength) \
: b->nKeyLength \
))
#define BUCKET_KEY(b) (UNISW((b)->arKey, (b)->key.arKey))
#define BUCKET_KEY_S(b) ZSTR_S(BUCKET_KEY(b))
#define BUCKET_KEY_U(b) ZSTR_U(BUCKET_KEY(b))
#define BUCKET_KEY_TYPE(b) (UNISW(IS_STRING, (b)->key.type))
#ifdef IS_UNICODE
# define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, key.arKey)
#else
# define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, arKey)
#endif
#ifdef ZEND_ENGINE_2_4
# define BUCKET_SIZE(b) (sizeof(Bucket) + BUCKET_KEY_SIZE(b))
#else
# define BUCKET_SIZE(b) (BUCKET_HEAD_SIZE(b) + BUCKET_KEY_SIZE(b))
#endif
#ifndef IS_UNICODE
typedef char *zstr;
typedef const char *const_zstr;
#ifdef ZEND_ENGINE_2_4
typedef const char *const24_zstr;
typedef const char *const24_str;
#else
typedef char *const24_zstr;
typedef char *const24_str;
#endif
# define ZSTR_S(s) (s)
# define ZSTR_U(s) (s)
# define ZSTR_V(s) (s)
# define ZSTR_PS(s) (s)
# define ZSTR_PU(s) (s)
# define ZSTR_PV(s) (s)
#else
typedef const zstr const_zstr;
# define ZSTR_S(zs) ((zs).s)
# define ZSTR_U(zs) ((zs).u)
# define ZSTR_V(zs) ((zs).v)
# define ZSTR_PS(pzs) ((pzs)->s)
# define ZSTR_PU(pzs) ((pzs)->u)
# define ZSTR_PV(pzs) ((pzs)->v)
#endif
#ifndef ZSTR
# define ZSTR(s) (s)
#endif
#ifndef Z_UNIVAL
# define Z_UNIVAL(zval) (zval).value.str.val
# define Z_UNILEN(zval) (zval).value.str.len
#endif
/* {{{ u hash wrapper */
#ifndef IS_UNICODE
# define zend_u_hash_add(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
zend_hash_add(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, pData, nDataSize, pDest)
# define zend_u_hash_quick_add(ht, type, arKey, nKeyLength, h, pData, nDataSize, pDest) \
zend_hash_quick_add(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, h, pData, nDataSize, pDest)
# define zend_u_hash_update(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
zend_hash_update(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, pData, nDataSize, pDest)
# define zend_u_hash_quick_update(ht, type, arKey, nKeyLength, h, pData, nDataSize, pDest) \
zend_hash_quick_update(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, h, pData, nDataSize, pDest)
# define zend_u_hash_find(ht, type, arKey, nKeyLength, pData) \
zend_hash_find(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, pData)
# define zend_u_hash_quick_find(ht, type, arKey, nKeyLength, h, pData) \
zend_hash_quick_find(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, h, pData)
# define zend_u_hash_exists(ht, type, arKey, nKeyLength) \
zend_hash_exists(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength)
# define add_u_assoc_zval_ex(arg, type, key, key_len, value) \
add_assoc_zval_ex(arg, key, key_len, value)
# define zend_u_is_auto_global(type, name, name_len) \
zend_is_auto_global(name, name_len)
#endif
/* }}} */
#include "xcache/xc_compatibility.h"
#define ECALLOC_N(x, n) ((x) = ecalloc(n, sizeof((x)[0])))
#define ECALLOC_ONE(x) ECALLOC_N(x, 1)
typedef ulong xc_hash_value_t;
typedef struct {
size_t bits;
@ -232,23 +33,6 @@ typedef struct {
xc_hash_value_t mask;
} xc_hash_t;
/* the class entry type to be stored in class_table */
typedef ZESW(zend_class_entry, zend_class_entry*) xc_cest_t;
/* xc_cest_t to (zend_class_entry*) */
#define CestToCePtr(st) (ZESW(\
&(st), \
st \
) )
/* ZCEP=zend class entry ptr */
#define ZCEP_REFCOUNT_PTR(pce) (ZESW( \
(pce)->refcount, \
&((pce)->refcount) \
))
#define ZCE_REFCOUNT_PTR(ce) ZCE_REFCOUNT_PTR(&ce)
typedef zend_op_array *(zend_compile_file_t)(zend_file_handle *h, int type TSRMLS_DC);
typedef struct _xc_entry_t xc_entry_t;

45
xcache/xc_compatibility.c Normal file
View File

@ -0,0 +1,45 @@
#include "xc_compatibility.h"
#ifndef ZEND_ENGINE_2_3
#include "ext/standard/php_string.h"
size_t xc_dirname(char *path, size_t len) /* {{{ */
{
#ifdef ZEND_ENGINE_2
return php_dirname(path, len);
#else
php_dirname(path, len);
return strlen(path);
#endif
}
/* }}} */
long xc_atol(const char *str, int str_len) /* {{{ */
{
long retval;
if (!str_len) {
str_len = strlen(str);
}
retval = strtol(str, NULL, 0);
if (str_len > 0) {
switch (str[str_len - 1]) {
case 'g':
case 'G':
retval *= 1024;
/* break intentionally missing */
case 'm':
case 'M':
retval *= 1024;
/* break intentionally missing */
case 'k':
case 'K':
retval *= 1024;
break;
}
}
return retval;
}
/* }}} */
#endif

230
xcache/xc_compatibility.h Normal file
View File

@ -0,0 +1,230 @@
#ifndef XC_COMPATIBILITY_H_54F26ED90198353558718191D5EE244C
#define XC_COMPATIBILITY_H_54F26ED90198353558718191D5EE244C
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "php.h"
/* Purpose: Privode stuffs for compatibility with different PHP version
*/
#if !defined(ZEND_ENGINE_2_4) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4 || PHP_MAJOR_VERSION > 5)
# define ZEND_ENGINE_2_4
#endif
#if !defined(ZEND_ENGINE_2_3) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 3 || defined(ZEND_ENGINE_2_4))
# define ZEND_ENGINE_2_3
#endif
#if !defined(ZEND_ENGINE_2_2) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 2 || defined(ZEND_ENGINE_2_3))
# define ZEND_ENGINE_2_2
#endif
#if !defined(ZEND_ENGINE_2_1) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 1 || defined(ZEND_ENGINE_2_2))
# define ZEND_ENGINE_2_1
#endif
#define NOTHING
/* ZendEngine code Switcher */
#ifndef ZEND_ENGINE_2
# define ZESW(v1, v2) v1
#else
# define ZESW(v1, v2) v2
#endif
#ifdef ZEND_ENGINE_2_4
# define ZEND_24(pre24, v24) v24
#else
# define ZEND_24(pre24, v24) pre24
#endif
#ifdef do_alloca_with_limit
# define my_do_alloca(size, use_heap) do_alloca_with_limit(size, use_heap)
# define my_free_alloca(size, use_heap) free_alloca_with_limit(size, use_heap)
#elif defined(ALLOCA_FLAG)
# define my_do_alloca(size, use_heap) do_alloca(size, use_heap)
# define my_free_alloca(size, use_heap) free_alloca(size, use_heap)
#else
# define my_do_alloca(size, use_heap) do_alloca(size)
# define my_free_alloca(size, use_heap) free_alloca(size)
# define ALLOCA_FLAG(x)
#endif
#ifndef Z_ISREF
# define Z_ISREF(z) (z).is_ref
#endif
#ifndef Z_SET_ISREF
# define Z_SET_ISREF(z) (z).is_ref = 1
#endif
#ifndef Z_UNSET_ISREF
# define Z_UNSET_ISREF(z) (z).is_ref = 0
#endif
#ifndef Z_REFCOUNT
# define Z_REFCOUNT(z) (z).refcount
#endif
#ifndef Z_SET_REFCOUNT
# define Z_SET_REFCOUNT(z, rc) (z).refcount = rc
#endif
#ifndef IS_CONSTANT_TYPE_MASK
# define IS_CONSTANT_TYPE_MASK (~IS_CONSTANT_INDEX)
#endif
/* {{{ dirty fix for PHP 6 */
#ifdef add_assoc_long_ex
static inline void my_add_assoc_long_ex(zval *arg, char *key, uint key_len, long value)
{
add_assoc_long_ex(arg, key, key_len, value);
}
# undef add_assoc_long_ex
# define add_assoc_long_ex my_add_assoc_long_ex
#endif
#ifdef add_assoc_bool_ex
static inline void my_add_assoc_bool_ex(zval *arg, char *key, uint key_len, zend_bool value)
{
add_assoc_bool_ex(arg, key, key_len, value);
}
# undef add_assoc_bool_ex
# define add_assoc_bool_ex my_add_assoc_bool_ex
#endif
#ifdef add_assoc_null_ex
static inline void my_add_assoc_null_ex(zval *arg, char *key, uint key_len)
{
add_assoc_null_ex(arg, key, key_len);
}
# undef add_assoc_null_ex
# define add_assoc_null_ex my_add_assoc_null_ex
#endif
/* }}} */
#ifdef ZEND_ENGINE_2_4
# define Z_OP(op) (op)
# define Z_OP_CONSTANT(op) (op).literal->constant
# define Z_OP_TYPE(op) op##_##type
# define Z_OP_TYPEOF_TYPE zend_uchar
# define Z_CLASS_INFO(className) (className).info.user
#else
# define Z_OP(op) (op).u
# define Z_OP_CONSTANT(op) (op).u.constant
# define Z_OP_TYPE(op) (op).op_type
# define Z_OP_TYPEOF_TYPE int
typedef znode znode_op;
# define Z_CLASS_INFO(className) (className)
#endif
/* unicode */
#ifdef IS_UNICODE
# define UNISW(text, unicode) unicode
#else
# define UNISW(text, unicode) text
#endif
#define BUCKET_KEY_SIZE(b) \
(UNISW( \
(b)->nKeyLength, \
((b)->key.type == IS_UNICODE) \
? UBYTES(b->nKeyLength) \
: b->nKeyLength \
))
#define BUCKET_KEY(b) (UNISW((b)->arKey, (b)->key.arKey))
#define BUCKET_KEY_S(b) ZSTR_S(BUCKET_KEY(b))
#define BUCKET_KEY_U(b) ZSTR_U(BUCKET_KEY(b))
#define BUCKET_KEY_TYPE(b) (UNISW(IS_STRING, (b)->key.type))
#ifdef IS_UNICODE
# define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, key.arKey)
#else
# define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, arKey)
#endif
#ifdef ZEND_ENGINE_2_4
# define BUCKET_SIZE(b) (sizeof(Bucket) + BUCKET_KEY_SIZE(b))
#else
# define BUCKET_SIZE(b) (BUCKET_HEAD_SIZE(b) + BUCKET_KEY_SIZE(b))
#endif
#ifndef IS_UNICODE
typedef char *zstr;
typedef const char *const_zstr;
#ifdef ZEND_ENGINE_2_4
typedef const char *const24_zstr;
typedef const char *const24_str;
#else
typedef char *const24_zstr;
typedef char *const24_str;
#endif
# define ZSTR_S(s) (s)
# define ZSTR_U(s) (s)
# define ZSTR_V(s) (s)
# define ZSTR_PS(s) (s)
# define ZSTR_PU(s) (s)
# define ZSTR_PV(s) (s)
#else
typedef const zstr const_zstr;
# define ZSTR_S(zs) ((zs).s)
# define ZSTR_U(zs) ((zs).u)
# define ZSTR_V(zs) ((zs).v)
# define ZSTR_PS(pzs) ((pzs)->s)
# define ZSTR_PU(pzs) ((pzs)->u)
# define ZSTR_PV(pzs) ((pzs)->v)
#endif
#ifndef ZSTR
# define ZSTR(s) (s)
#endif
#ifndef Z_UNIVAL
# define Z_UNIVAL(zval) (zval).value.str.val
# define Z_UNILEN(zval) (zval).value.str.len
#endif
/* {{{ u hash wrapper */
#ifndef IS_UNICODE
# define zend_u_hash_add(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
zend_hash_add(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, pData, nDataSize, pDest)
# define zend_u_hash_quick_add(ht, type, arKey, nKeyLength, h, pData, nDataSize, pDest) \
zend_hash_quick_add(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, h, pData, nDataSize, pDest)
# define zend_u_hash_update(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
zend_hash_update(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, pData, nDataSize, pDest)
# define zend_u_hash_quick_update(ht, type, arKey, nKeyLength, h, pData, nDataSize, pDest) \
zend_hash_quick_update(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, h, pData, nDataSize, pDest)
# define zend_u_hash_find(ht, type, arKey, nKeyLength, pData) \
zend_hash_find(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, pData)
# define zend_u_hash_quick_find(ht, type, arKey, nKeyLength, h, pData) \
zend_hash_quick_find(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, h, pData)
# define zend_u_hash_exists(ht, type, arKey, nKeyLength) \
zend_hash_exists(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength)
# define add_u_assoc_zval_ex(arg, type, key, key_len, value) \
add_assoc_zval_ex(arg, key, key_len, value)
# define zend_u_is_auto_global(type, name, name_len) \
zend_is_auto_global(name, name_len)
#endif
/* }}} */
/* the class entry type to be stored in class_table */
typedef ZESW(zend_class_entry, zend_class_entry*) xc_cest_t;
/* xc_cest_t to (zend_class_entry*) */
#define CestToCePtr(st) (ZESW(\
&(st), \
st \
) )
/* ZCEP=zend class entry ptr */
#define ZCEP_REFCOUNT_PTR(pce) (ZESW( \
(pce)->refcount, \
&((pce)->refcount) \
))
#ifndef ZEND_ENGINE_2_3
size_t xc_dirname(char *path, size_t len);
#define zend_dirname xc_dirname
long xc_atol(const char *str, int len);
#define zend_atol xc_atol
#endif
#endif /* XC_COMPATIBILITY_H_54F26ED90198353558718191D5EE244C */

View File

@ -433,51 +433,6 @@ zend_uint xc_sandbox_compilererror_cnt(TSRMLS_D) /* {{{ */
/* }}} */
#endif
#ifndef ZEND_ENGINE_2_3
#include "ext/standard/php_string.h"
size_t xc_dirname(char *path, size_t len) /* {{{ */
{
#ifdef ZEND_ENGINE_2
return php_dirname(path, len);
#else
php_dirname(path, len);
return strlen(path);
#endif
}
/* }}} */
long xc_atol(const char *str, int str_len) /* {{{ */
{
long retval;
if (!str_len) {
str_len = strlen(str);
}
retval = strtol(str, NULL, 0);
if (str_len > 0) {
switch (str[str_len - 1]) {
case 'g':
case 'G':
retval *= 1024;
/* break intentionally missing */
case 'm':
case 'M':
retval *= 1024;
/* break intentionally missing */
case 'k':
case 'K':
retval *= 1024;
break;
}
}
return retval;
}
/* }}} */
#endif
/* init/destroy */
int xc_util_init(int module_number TSRMLS_DC) /* {{{ */
{

View File

@ -5,6 +5,9 @@
#pragma once
#endif // _MSC_VER > 1000
/* Purpose: run specified function in compiler sandbox, restore everything to previous state after it returns
*/
/* return op_array to install */
typedef zend_op_array *(*xc_sandboxed_func_t)(void *data TSRMLS_DC);
zend_op_array *xc_sandbox(xc_sandboxed_func_t sandboxed_func, void *data, ZEND_24(NOTHING, const) char *filename TSRMLS_DC);

View File

@ -48,10 +48,3 @@ void xc_zend_constant_ctor(zend_constant *c);
void xc_zend_constant_dtor(zend_constant *c);
void xc_copy_internal_zend_constants(HashTable *target, HashTable *source);
#endif
#ifndef ZEND_ENGINE_2_3
size_t xc_dirname(char *path, size_t len);
#define zend_dirname xc_dirname
long xc_atol(const char *str, int len);
#define zend_atol xc_atol
#endif