source: trunk/xcache/xc_compatibility.h @ 1486

Last change on this file since 1486 was 1486, checked in by moo, 2 months ago

WIP PHP_5_6 support

  • Property svn:eol-style set to native
File size: 7.5 KB
Line 
1#ifndef XC_COMPATIBILITY_H_54F26ED90198353558718191D5EE244C
2#define XC_COMPATIBILITY_H_54F26ED90198353558718191D5EE244C
3
4#if _MSC_VER > 1000
5#pragma once
6#endif /* _MSC_VER > 1000 */
7
8#include "php.h"
9
10/* Purpose: Privode stuffs for compatibility with different PHP version
11 */
12
13#if !defined(ZEND_ENGINE_2_6) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 6 || PHP_MAJOR_VERSION > 6)
14#   define ZEND_ENGINE_2_6
15#endif
16#if !defined(ZEND_ENGINE_2_5) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 5 || defined(ZEND_ENGINE_2_6))
17#   define ZEND_ENGINE_2_5
18#endif
19#if !defined(ZEND_ENGINE_2_4) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 4 || defined(ZEND_ENGINE_2_5))
20#   define ZEND_ENGINE_2_4
21#endif
22#if !defined(ZEND_ENGINE_2_3) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 3 || defined(ZEND_ENGINE_2_4))
23#   define ZEND_ENGINE_2_3
24#endif
25#if !defined(ZEND_ENGINE_2_2) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 2 || defined(ZEND_ENGINE_2_3))
26#   define ZEND_ENGINE_2_2
27#endif
28#if !defined(ZEND_ENGINE_2_1) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 1 || defined(ZEND_ENGINE_2_2))
29#   define ZEND_ENGINE_2_1
30#endif
31
32#define NOTHING
33/* ZendEngine code Switcher */
34#ifndef ZEND_ENGINE_2
35#   define ZESW(v1, v2) v1
36#else
37#   define ZESW(v1, v2) v2
38#endif
39#ifdef ZEND_ENGINE_2_4
40#   define ZEND_24(pre24, v24) v24
41#else
42#   define ZEND_24(pre24, v24) pre24
43#endif
44
45#ifdef do_alloca_with_limit
46#   define xc_do_alloca(size, use_heap) do_alloca_with_limit(size, use_heap)
47#   define xc_free_alloca(size, use_heap) free_alloca_with_limit(size, use_heap)
48#elif defined(ALLOCA_FLAG)
49#   define xc_do_alloca(size, use_heap) do_alloca(size, use_heap)
50#   define xc_free_alloca(size, use_heap) free_alloca(size, use_heap)
51#else
52#   define xc_do_alloca(size, use_heap) do_alloca(size)
53#   define xc_free_alloca(size, use_heap) free_alloca(size)
54#   define ALLOCA_FLAG(x)
55#endif
56#ifndef Z_ISREF
57#   define Z_ISREF(z) (z).is_ref
58#endif
59#ifndef Z_SET_ISREF
60#   define Z_SET_ISREF(z) (z).is_ref = 1
61#endif
62#ifndef Z_UNSET_ISREF
63#   define Z_UNSET_ISREF(z) (z).is_ref = 0
64#endif
65#ifndef Z_REFCOUNT
66#   define Z_REFCOUNT(z) (z).refcount
67#endif
68#ifndef Z_SET_REFCOUNT
69#   define Z_SET_REFCOUNT(z, rc) (z).refcount = rc
70#endif
71#ifndef IS_CONSTANT_TYPE_MASK
72#   define IS_CONSTANT_TYPE_MASK (~IS_CONSTANT_INDEX)
73#endif
74/* {{{ dirty fix for PHP 6 */
75#ifdef add_assoc_long_ex
76static inline void xc_add_assoc_long_ex(zval *arg, char *key, uint key_len, long value)
77{
78    add_assoc_long_ex(arg, key, key_len, value);
79}
80#   undef add_assoc_long_ex
81#   define add_assoc_long_ex xc_add_assoc_long_ex
82#endif
83#ifdef add_assoc_bool_ex
84static inline void xc_add_assoc_bool_ex(zval *arg, char *key, uint key_len, zend_bool value)
85{
86    add_assoc_bool_ex(arg, key, key_len, value);
87}
88#   undef add_assoc_bool_ex
89#   define add_assoc_bool_ex xc_add_assoc_bool_ex
90#endif
91#ifdef add_assoc_null_ex
92static inline void xc_add_assoc_null_ex(zval *arg, char *key, uint key_len)
93{
94    add_assoc_null_ex(arg, key, key_len);
95}
96#   undef add_assoc_null_ex
97#   define add_assoc_null_ex xc_add_assoc_null_ex
98#endif
99/* }}} */
100
101#ifdef ZEND_ENGINE_2_4
102#   define Z_OP(op) (op)
103#   define Z_OP_CONSTANT(op) (op).literal->constant
104#   define Z_OP_TYPE(op) op##_##type
105#   define Z_OP_TYPEOF_TYPE zend_uchar
106
107#   define Z_CLASS_INFO(className) (className).info.user
108#else
109#   define Z_OP(op) (op).u
110#   define Z_OP_CONSTANT(op) (op).u.constant
111#   define Z_OP_TYPE(op) (op).op_type
112#   define Z_OP_TYPEOF_TYPE int
113typedef znode znode_op;
114
115#   define Z_CLASS_INFO(className) (className)
116
117static inline int php_output_start_default(TSRMLS_D) { return php_start_ob_buffer(NULL, 0, 1 TSRMLS_CC); }
118static inline int php_output_get_contents(zval *p TSRMLS_DC) { return php_ob_get_buffer(p TSRMLS_CC); }
119static inline int php_output_discard(TSRMLS_D) { php_end_ob_buffer(0, 0 TSRMLS_CC); return SUCCESS; }
120#endif
121
122/* unicode */
123#ifdef IS_UNICODE
124#   define UNISW(text, unicode) unicode
125#else
126#   define UNISW(text, unicode) text
127#endif
128#define BUCKET_KEY_SIZE(b) \
129        (UNISW( \
130            (b)->nKeyLength, \
131                ((b)->key.type == IS_UNICODE) \
132                ? UBYTES(b->nKeyLength) \
133                : b->nKeyLength \
134                ))
135#define BUCKET_KEY(b)      (UNISW((b)->arKey, (b)->key.arKey))
136#define BUCKET_KEY_S(b)    ZSTR_S(BUCKET_KEY(b))
137#define BUCKET_KEY_U(b)    ZSTR_U(BUCKET_KEY(b))
138#define BUCKET_KEY_TYPE(b) (UNISW(IS_STRING,  (b)->key.type))
139#ifdef IS_UNICODE
140#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, key.arKey)
141#else
142#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, arKey)
143#endif
144
145#ifdef ZEND_ENGINE_2_4
146#   define BUCKET_SIZE(b) (sizeof(Bucket) + BUCKET_KEY_SIZE(b))
147#else
148#   define BUCKET_SIZE(b) (BUCKET_HEAD_SIZE(b) + BUCKET_KEY_SIZE(b))
149#endif
150
151#ifndef IS_UNICODE
152typedef char *zstr;
153typedef const char *const_zstr;
154#ifdef ZEND_ENGINE_2_4
155typedef const char *const24_zstr;
156typedef const char *const24_str;
157#else
158typedef char *const24_zstr;
159typedef char *const24_str;
160#endif
161
162#   define ZSTR_S(s)     (s)
163#   define ZSTR_U(s)     (s)
164#   define ZSTR_V(s)     (s)
165#   define ZSTR_PS(s)    (s)
166#   define ZSTR_PU(s)    (s)
167#   define ZSTR_PV(s)    (s)
168#else
169typedef const zstr const_zstr;
170#   define ZSTR_S(zs)    ((zs).s)
171#   define ZSTR_U(zs)    ((zs).u)
172#   define ZSTR_V(zs)    ((zs).v)
173#   define ZSTR_PS(pzs)  ((pzs)->s)
174#   define ZSTR_PU(pzs)  ((pzs)->u)
175#   define ZSTR_PV(pzs)  ((pzs)->v)
176#endif
177
178#ifndef ZSTR
179#   define ZSTR(s)      (s)
180#endif
181
182#ifndef Z_UNIVAL
183#   define Z_UNIVAL(zval) (zval).value.str.val
184#   define Z_UNILEN(zval) (zval).value.str.len
185#endif
186
187/* {{{ u hash wrapper */
188#ifndef IS_UNICODE
189#   define zend_u_hash_add(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
190       zend_hash_add(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, pData, nDataSize, pDest)
191
192#   define zend_u_hash_quick_add(ht, type, arKey, nKeyLength, h, pData, nDataSize, pDest) \
193       zend_hash_quick_add(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, h, pData, nDataSize, pDest)
194
195#   define zend_u_hash_update(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
196       zend_hash_update(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, pData, nDataSize, pDest)
197
198#   define zend_u_hash_quick_update(ht, type, arKey, nKeyLength, h, pData, nDataSize, pDest) \
199       zend_hash_quick_update(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, h, pData, nDataSize, pDest)
200
201#   define zend_u_hash_find(ht, type, arKey, nKeyLength, pData) \
202       zend_hash_find(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, pData)
203
204#   define zend_u_hash_quick_find(ht, type, arKey, nKeyLength, h, pData) \
205       zend_hash_quick_find(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, h, pData)
206
207#   define zend_u_hash_exists(ht, type, arKey, nKeyLength) \
208       zend_hash_exists(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength)
209
210#   define add_u_assoc_zval_ex(arg, type, key, key_len, value) \
211        add_assoc_zval_ex(arg, key, key_len, value)
212
213#   define zend_u_is_auto_global(type, name, name_len) \
214        zend_is_auto_global(name, name_len)
215#endif
216/* }}} */
217
218/* the class entry type to be stored in class_table */
219typedef ZESW(zend_class_entry, zend_class_entry*) xc_cest_t;
220
221/* xc_cest_t to (zend_class_entry*) */
222#define CestToCePtr(st) (ZESW(\
223            &(st), \
224            st \
225            ) )
226
227/* ZCEP=zend class entry ptr */
228#define ZCEP_REFCOUNT_PTR(pce) (ZESW( \
229            (pce)->refcount, \
230            &((pce)->refcount) \
231            ))
232
233#ifndef ZEND_ENGINE_2_3
234size_t xc_dirname(char *path, size_t len);
235#define zend_dirname xc_dirname
236long xc_atol(const char *str, int len);
237#define zend_atol xc_atol
238#endif
239
240#ifndef ZEND_MOD_END
241#   define ZEND_MOD_END {NULL, NULL, NULL, 0}
242#endif
243
244#ifndef PHP_FE_END
245#   ifdef ZEND_ENGINE_2
246#       define PHP_FE_END {NULL, NULL, NULL, 0, 0}
247#   else
248#       define PHP_FE_END {NULL, NULL, NULL}
249#   endif
250#endif
251
252#endif /* XC_COMPATIBILITY_H_54F26ED90198353558718191D5EE244C */
Note: See TracBrowser for help on using the repository browser.