source: trunk/xcache/xc_compatibility.h

Last change on this file was 1572, checked in by moo, 5 weeks ago

support for reference value

  • Property svn:eol-style set to native
File size: 8.8 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 Z_ADDREF
72#   define Z_ADDREF(z) (z).refcount++
73#endif
74#ifndef IS_CONSTANT_TYPE_MASK
75#   define IS_CONSTANT_TYPE_MASK (~IS_CONSTANT_INDEX)
76#endif
77/* {{{ dirty fix for PHP 6 */
78#ifdef add_assoc_long_ex
79static inline void xc_add_assoc_long_ex(zval *arg, char *key, uint key_len, long value)
80{
81    add_assoc_long_ex(arg, key, key_len, value);
82}
83#   undef add_assoc_long_ex
84#   define add_assoc_long_ex xc_add_assoc_long_ex
85#endif
86#ifdef add_assoc_bool_ex
87static inline void xc_add_assoc_bool_ex(zval *arg, char *key, uint key_len, zend_bool value)
88{
89    add_assoc_bool_ex(arg, key, key_len, value);
90}
91#   undef add_assoc_bool_ex
92#   define add_assoc_bool_ex xc_add_assoc_bool_ex
93#endif
94#ifdef add_assoc_null_ex
95static inline void xc_add_assoc_null_ex(zval *arg, char *key, uint key_len)
96{
97    add_assoc_null_ex(arg, key, key_len);
98}
99#   undef add_assoc_null_ex
100#   define add_assoc_null_ex xc_add_assoc_null_ex
101#endif
102/* }}} */
103
104#ifndef ZEND_ENGINE_2_6
105typedef void zend_ast;
106#endif
107
108#ifdef ZEND_ENGINE_2_4
109#   define Z_OP(op) (op)
110#   define Z_OP_CONSTANT(op) (op).literal->constant
111#   define Z_OP_TYPE(op) op##_##type
112#   define Z_OP_TYPEOF_TYPE zend_uchar
113
114#   define Z_CLASS_INFO(className) (className).info.user
115#else
116#   define Z_OP(op) (op).u
117#   define Z_OP_CONSTANT(op) (op).u.constant
118#   define Z_OP_TYPE(op) (op).op_type
119#   define Z_OP_TYPEOF_TYPE int
120typedef znode znode_op;
121
122#   define Z_CLASS_INFO(className) (className)
123
124static inline int php_output_start_default(TSRMLS_D) { return php_start_ob_buffer(NULL, 0, 1 TSRMLS_CC); }
125static inline int php_output_get_contents(zval *p TSRMLS_DC) { return php_ob_get_buffer(p TSRMLS_CC); }
126static inline int php_output_discard(TSRMLS_D) { php_end_ob_buffer(0, 0 TSRMLS_CC); return SUCCESS; }
127#endif
128
129/* unicode */
130#ifdef IS_UNICODE
131#   define UNISW(text, unicode) unicode
132#else
133#   define UNISW(text, unicode) text
134#endif
135#define BUCKET_KEY_SIZE(b) \
136        (UNISW( \
137            (b)->nKeyLength, \
138                ((b)->key.type == IS_UNICODE) \
139                ? UBYTES(b->nKeyLength) \
140                : b->nKeyLength \
141                ))
142#define BUCKET_KEY(b)      (UNISW((b)->arKey, (b)->key.arKey))
143#define BUCKET_KEY_S(b)    ZSTR_S(BUCKET_KEY(b))
144#define BUCKET_KEY_U(b)    ZSTR_U(BUCKET_KEY(b))
145#define BUCKET_KEY_TYPE(b) (UNISW(IS_STRING,  (b)->key.type))
146#ifdef IS_UNICODE
147#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, key.arKey)
148#else
149#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, arKey)
150#endif
151
152#ifdef ZEND_ENGINE_2_4
153#   define BUCKET_SIZE(b) (sizeof(Bucket) + BUCKET_KEY_SIZE(b))
154#else
155#   define BUCKET_SIZE(b) (BUCKET_HEAD_SIZE(b) + BUCKET_KEY_SIZE(b))
156#endif
157
158#ifndef IS_UNICODE
159typedef char *zstr;
160typedef const char *const_zstr;
161#ifdef ZEND_ENGINE_2_4
162typedef const char *const24_zstr;
163typedef const char *const24_str;
164#else
165typedef char *const24_zstr;
166typedef char *const24_str;
167#endif
168
169#   define ZSTR_S(s)     (s)
170#   define ZSTR_U(s)     (s)
171#   define ZSTR_V(s)     (s)
172#   define ZSTR_PS(s)    (s)
173#   define ZSTR_PU(s)    (s)
174#   define ZSTR_PV(s)    (s)
175#else
176typedef const zstr const_zstr;
177#   define ZSTR_S(zs)    ((zs).s)
178#   define ZSTR_U(zs)    ((zs).u)
179#   define ZSTR_V(zs)    ((zs).v)
180#   define ZSTR_PS(pzs)  ((pzs)->s)
181#   define ZSTR_PU(pzs)  ((pzs)->u)
182#   define ZSTR_PV(pzs)  ((pzs)->v)
183#endif
184
185#ifndef ZSTR
186#   define ZSTR(s)      (s)
187#endif
188
189#ifndef Z_UNIVAL
190#   define Z_UNIVAL(zval) (zval).value.str.val
191#   define Z_UNILEN(zval) (zval).value.str.len
192#endif
193
194/* {{{ u hash wrapper */
195#ifndef IS_UNICODE
196#   define zend_u_hash_add(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
197       zend_hash_add(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, pData, nDataSize, pDest)
198
199#   define zend_u_hash_quick_add(ht, type, arKey, nKeyLength, h, pData, nDataSize, pDest) \
200       zend_hash_quick_add(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, h, pData, nDataSize, pDest)
201
202#   define zend_u_hash_update(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
203       zend_hash_update(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, pData, nDataSize, pDest)
204
205#   define zend_u_hash_quick_update(ht, type, arKey, nKeyLength, h, pData, nDataSize, pDest) \
206       zend_hash_quick_update(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, h, pData, nDataSize, pDest)
207
208#   define zend_u_hash_find(ht, type, arKey, nKeyLength, pData) \
209       zend_hash_find(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, pData)
210
211#   define zend_u_hash_quick_find(ht, type, arKey, nKeyLength, h, pData) \
212       zend_hash_quick_find(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, h, pData)
213
214#   define zend_u_hash_exists(ht, type, arKey, nKeyLength) \
215       zend_hash_exists(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength)
216
217#   define add_u_assoc_zval_ex(arg, type, key, key_len, value) \
218        add_assoc_zval_ex(arg, key, key_len, value)
219
220#   define zend_u_is_auto_global(type, name, name_len) \
221        zend_is_auto_global(name, name_len)
222#endif
223/* }}} */
224
225#ifndef ZVAL_COPY_VALUE
226#   define ZVAL_COPY_VALUE(z, v) (z)->value = (v)->value
227#endif
228
229#ifndef ZVAL_ZVAL
230#   define ZVAL_ZVAL(z, zv, copy, dtor) do {    \
231        zval *__z = (z);                        \
232        zval *__zv = (zv);                      \
233        ZVAL_COPY_VALUE(__z, __zv);             \
234        if (copy) {                             \
235            zval_copy_ctor(__z);                \
236        }                                       \
237        if (dtor) {                             \
238            if (!copy) {                        \
239                ZVAL_NULL(__zv);                \
240            }                                   \
241            zval_ptr_dtor(&__zv);               \
242        }                                       \
243    } while (0)
244#endif
245
246#ifndef RETVAL_ZVAL
247#   define RETVAL_ZVAL(zv, copy, dtor)      ZVAL_ZVAL(return_value, zv, copy, dtor)
248#endif
249
250#ifndef RETURN_ZVAL
251#   define RETURN_ZVAL(zv, copy, dtor)      { RETVAL_ZVAL(zv, copy, dtor); return; }
252#endif
253
254/* the class entry type to be stored in class_table */
255typedef ZESW(zend_class_entry, zend_class_entry*) xc_cest_t;
256
257/* xc_cest_t to (zend_class_entry*) */
258#define CestToCePtr(st) (ZESW(\
259            &(st), \
260            st \
261            ) )
262
263/* ZCEP=zend class entry ptr */
264#define ZCEP_REFCOUNT_PTR(pce) (ZESW( \
265            (pce)->refcount, \
266            &((pce)->refcount) \
267            ))
268
269#ifndef ZEND_ENGINE_2_3
270size_t xc_dirname(char *path, size_t len);
271#define zend_dirname xc_dirname
272long xc_atol(const char *str, int len);
273#define zend_atol xc_atol
274#endif
275
276#ifndef ZEND_MOD_END
277#   define ZEND_MOD_END {NULL, NULL, NULL, 0}
278#endif
279
280#ifndef PHP_FE_END
281#   ifdef ZEND_ENGINE_2
282#       define PHP_FE_END {NULL, NULL, NULL, 0, 0}
283#   else
284#       define PHP_FE_END {NULL, NULL, NULL}
285#   endif
286#endif
287
288#if defined(ZEND_ENGINE_2) && !defined(ZEND_ENGINE_2_2)
289void *xc_object_store_get_object_by_handle(zend_object_handle handle TSRMLS_DC);
290#   define zend_object_store_get_object_by_handle xc_object_store_get_object_by_handle
291
292void xc_objects_store_add_ref_by_handle(zend_object_handle handle TSRMLS_DC);
293#   define zend_objects_store_add_ref_by_handle xc_objects_store_add_ref_by_handle
294
295void xc_objects_store_del_ref_by_handle(zend_object_handle handle TSRMLS_DC);
296#   define zend_objects_store_del_ref_by_handle xc_objects_store_del_ref_by_handle
297#endif
298
299#endif /* XC_COMPATIBILITY_H_54F26ED90198353558718191D5EE244C */
Note: See TracBrowser for help on using the repository browser.