source: trunk/xcache/xc_compatibility.h @ 1276

Last change on this file since 1276 was 1276, checked in by moo, 14 months ago

optimizer: fix debug build

  • Property svn:eol-style set to native
File size: 7.3 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
114static inline int php_output_start_default(TSRMLS_D) { php_start_ob_buffer(NULL, 0, 1 TSRMLS_CC); }
115static inline int php_output_get_contents(zval *p TSRMLS_DC) { php_ob_get_buffer(p TSRMLS_CC); }
116static inline int php_output_end(TSRMLS_D) { php_end_ob_buffer(0, 0 TSRMLS_CC); }
117#endif
118
119/* unicode */
120#ifdef IS_UNICODE
121#   define UNISW(text, unicode) unicode
122#else
123#   define UNISW(text, unicode) text
124#endif
125#define BUCKET_KEY_SIZE(b) \
126        (UNISW( \
127            (b)->nKeyLength, \
128                ((b)->key.type == IS_UNICODE) \
129                ? UBYTES(b->nKeyLength) \
130                : b->nKeyLength \
131                ))
132#define BUCKET_KEY(b)      (UNISW((b)->arKey, (b)->key.arKey))
133#define BUCKET_KEY_S(b)    ZSTR_S(BUCKET_KEY(b))
134#define BUCKET_KEY_U(b)    ZSTR_U(BUCKET_KEY(b))
135#define BUCKET_KEY_TYPE(b) (UNISW(IS_STRING,  (b)->key.type))
136#ifdef IS_UNICODE
137#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, key.arKey)
138#else
139#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, arKey)
140#endif
141
142#ifdef ZEND_ENGINE_2_4
143#   define BUCKET_SIZE(b) (sizeof(Bucket) + BUCKET_KEY_SIZE(b))
144#else
145#   define BUCKET_SIZE(b) (BUCKET_HEAD_SIZE(b) + BUCKET_KEY_SIZE(b))
146#endif
147
148#ifndef IS_UNICODE
149typedef char *zstr;
150typedef const char *const_zstr;
151#ifdef ZEND_ENGINE_2_4
152typedef const char *const24_zstr;
153typedef const char *const24_str;
154#else
155typedef char *const24_zstr;
156typedef char *const24_str;
157#endif
158
159#   define ZSTR_S(s)     (s)
160#   define ZSTR_U(s)     (s)
161#   define ZSTR_V(s)     (s)
162#   define ZSTR_PS(s)    (s)
163#   define ZSTR_PU(s)    (s)
164#   define ZSTR_PV(s)    (s)
165#else
166typedef const zstr const_zstr;
167#   define ZSTR_S(zs)    ((zs).s)
168#   define ZSTR_U(zs)    ((zs).u)
169#   define ZSTR_V(zs)    ((zs).v)
170#   define ZSTR_PS(pzs)  ((pzs)->s)
171#   define ZSTR_PU(pzs)  ((pzs)->u)
172#   define ZSTR_PV(pzs)  ((pzs)->v)
173#endif
174
175#ifndef ZSTR
176#   define ZSTR(s)      (s)
177#endif
178
179#ifndef Z_UNIVAL
180#   define Z_UNIVAL(zval) (zval).value.str.val
181#   define Z_UNILEN(zval) (zval).value.str.len
182#endif
183
184/* {{{ u hash wrapper */
185#ifndef IS_UNICODE
186#   define zend_u_hash_add(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
187       zend_hash_add(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, pData, nDataSize, pDest)
188
189#   define zend_u_hash_quick_add(ht, type, arKey, nKeyLength, h, pData, nDataSize, pDest) \
190       zend_hash_quick_add(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, h, pData, nDataSize, pDest)
191
192#   define zend_u_hash_update(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
193       zend_hash_update(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, pData, nDataSize, pDest)
194
195#   define zend_u_hash_quick_update(ht, type, arKey, nKeyLength, h, pData, nDataSize, pDest) \
196       zend_hash_quick_update(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, h, pData, nDataSize, pDest)
197
198#   define zend_u_hash_find(ht, type, arKey, nKeyLength, pData) \
199       zend_hash_find(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, pData)
200
201#   define zend_u_hash_quick_find(ht, type, arKey, nKeyLength, h, pData) \
202       zend_hash_quick_find(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, h, pData)
203
204#   define zend_u_hash_exists(ht, type, arKey, nKeyLength) \
205       zend_hash_exists(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength)
206
207#   define add_u_assoc_zval_ex(arg, type, key, key_len, value) \
208        add_assoc_zval_ex(arg, key, key_len, value)
209
210#   define zend_u_is_auto_global(type, name, name_len) \
211        zend_is_auto_global(name, name_len)
212#endif
213/* }}} */
214
215/* the class entry type to be stored in class_table */
216typedef ZESW(zend_class_entry, zend_class_entry*) xc_cest_t;
217
218/* xc_cest_t to (zend_class_entry*) */
219#define CestToCePtr(st) (ZESW(\
220            &(st), \
221            st \
222            ) )
223
224/* ZCEP=zend class entry ptr */
225#define ZCEP_REFCOUNT_PTR(pce) (ZESW( \
226            (pce)->refcount, \
227            &((pce)->refcount) \
228            ))
229
230#ifndef ZEND_ENGINE_2_3
231size_t xc_dirname(char *path, size_t len);
232#define zend_dirname xc_dirname
233long xc_atol(const char *str, int len);
234#define zend_atol xc_atol
235#endif
236
237#ifndef ZEND_MOD_END
238#   define ZEND_MOD_END {NULL, NULL, NULL, 0}
239#endif
240
241#ifndef PHP_FE_END
242#   ifdef ZEND_ENGINE_2
243#       define PHP_FE_END {NULL, NULL, NULL, 0, 0}
244#   else
245#       define PHP_FE_END {NULL, NULL, NULL}
246#   endif
247#endif
248
249#endif /* XC_COMPATIBILITY_H_54F26ED90198353558718191D5EE244C */
Note: See TracBrowser for help on using the repository browser.