source: trunk/xcache/xc_compatibility.h @ 991

Last change on this file since 991 was 991, checked in by moo, 22 months ago

refactor: split compatibility

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