source: trunk/xcache/xc_compatibility.h @ 1213

Last change on this file since 1213 was 1213, checked in by moo, 2 years ago

add support for PHP_5_5

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