source: trunk/xcache/xc_compatibility.h @ 1281

Last change on this file since 1281 was 1281, checked in by moo, 16 months ago

remove php 4 support completely

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