XCache is a fast, stable PHP opcode cacher that has been proven and is now running on production servers under high load. https://xcache.lighttpd.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

299 lines
8.8 KiB

  1. #ifndef XC_COMPATIBILITY_H_54F26ED90198353558718191D5EE244C
  2. #define XC_COMPATIBILITY_H_54F26ED90198353558718191D5EE244C
  3. #if _MSC_VER > 1000
  4. #pragma once
  5. #endif /* _MSC_VER > 1000 */
  6. #include "php.h"
  7. /* Purpose: Privode stuffs for compatibility with different PHP version
  8. */
  9. #if !defined(ZEND_ENGINE_2_6) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 6 || PHP_MAJOR_VERSION > 6)
  10. # define ZEND_ENGINE_2_6
  11. #endif
  12. #if !defined(ZEND_ENGINE_2_5) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 5 || defined(ZEND_ENGINE_2_6))
  13. # define ZEND_ENGINE_2_5
  14. #endif
  15. #if !defined(ZEND_ENGINE_2_4) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 4 || defined(ZEND_ENGINE_2_5))
  16. # define ZEND_ENGINE_2_4
  17. #endif
  18. #if !defined(ZEND_ENGINE_2_3) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 3 || defined(ZEND_ENGINE_2_4))
  19. # define ZEND_ENGINE_2_3
  20. #endif
  21. #if !defined(ZEND_ENGINE_2_2) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 2 || defined(ZEND_ENGINE_2_3))
  22. # define ZEND_ENGINE_2_2
  23. #endif
  24. #if !defined(ZEND_ENGINE_2_1) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 1 || defined(ZEND_ENGINE_2_2))
  25. # define ZEND_ENGINE_2_1
  26. #endif
  27. #define NOTHING
  28. /* ZendEngine code Switcher */
  29. #ifndef ZEND_ENGINE_2
  30. # define ZESW(v1, v2) v1
  31. #else
  32. # define ZESW(v1, v2) v2
  33. #endif
  34. #ifdef ZEND_ENGINE_2_4
  35. # define ZEND_24(pre24, v24) v24
  36. #else
  37. # define ZEND_24(pre24, v24) pre24
  38. #endif
  39. #ifdef do_alloca_with_limit
  40. # define xc_do_alloca(size, use_heap) do_alloca_with_limit(size, use_heap)
  41. # define xc_free_alloca(size, use_heap) free_alloca_with_limit(size, use_heap)
  42. #elif defined(ALLOCA_FLAG)
  43. # define xc_do_alloca(size, use_heap) do_alloca(size, use_heap)
  44. # define xc_free_alloca(size, use_heap) free_alloca(size, use_heap)
  45. #else
  46. # define xc_do_alloca(size, use_heap) do_alloca(size)
  47. # define xc_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 Z_ADDREF
  66. # define Z_ADDREF(z) (z).refcount++
  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
  73. static 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
  81. static 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
  89. static 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. #ifndef ZEND_ENGINE_2_6
  98. typedef void zend_ast;
  99. #endif
  100. #ifdef ZEND_ENGINE_2_4
  101. # define Z_OP(op) (op)
  102. # define Z_OP_CONSTANT(op) (op).literal->constant
  103. # define Z_OP_TYPE(op) op##_##type
  104. # define Z_OP_TYPEOF_TYPE zend_uchar
  105. # define Z_CLASS_INFO(className) (className).info.user
  106. #else
  107. # define Z_OP(op) (op).u
  108. # define Z_OP_CONSTANT(op) (op).u.constant
  109. # define Z_OP_TYPE(op) (op).op_type
  110. # define Z_OP_TYPEOF_TYPE int
  111. typedef znode znode_op;
  112. # define Z_CLASS_INFO(className) (className)
  113. static inline int php_output_start_default(TSRMLS_D) { return php_start_ob_buffer(NULL, 0, 1 TSRMLS_CC); }
  114. static inline int php_output_get_contents(zval *p TSRMLS_DC) { return php_ob_get_buffer(p TSRMLS_CC); }
  115. static inline int php_output_discard(TSRMLS_D) { php_end_ob_buffer(0, 0 TSRMLS_CC); return SUCCESS; }
  116. #endif
  117. /* unicode */
  118. #ifdef IS_UNICODE
  119. # define UNISW(text, unicode) unicode
  120. #else
  121. # define UNISW(text, unicode) text
  122. #endif
  123. #define BUCKET_KEY_SIZE(b) \
  124. (UNISW( \
  125. (b)->nKeyLength, \
  126. ((b)->key.type == IS_UNICODE) \
  127. ? UBYTES(b->nKeyLength) \
  128. : b->nKeyLength \
  129. ))
  130. #define BUCKET_KEY(b) (UNISW((b)->arKey, (b)->key.arKey))
  131. #define BUCKET_KEY_S(b) ZSTR_S(BUCKET_KEY(b))
  132. #define BUCKET_KEY_U(b) ZSTR_U(BUCKET_KEY(b))
  133. #define BUCKET_KEY_TYPE(b) (UNISW(IS_STRING, (b)->key.type))
  134. #ifdef IS_UNICODE
  135. # define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, key.arKey)
  136. #else
  137. # define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, arKey)
  138. #endif
  139. #ifdef ZEND_ENGINE_2_4
  140. # define BUCKET_SIZE(b) (sizeof(Bucket) + BUCKET_KEY_SIZE(b))
  141. #else
  142. # define BUCKET_SIZE(b) (BUCKET_HEAD_SIZE(b) + BUCKET_KEY_SIZE(b))
  143. #endif
  144. #ifndef IS_UNICODE
  145. typedef char *zstr;
  146. typedef const char *const_zstr;
  147. #ifdef ZEND_ENGINE_2_4
  148. typedef const char *const24_zstr;
  149. typedef const char *const24_str;
  150. #else
  151. typedef char *const24_zstr;
  152. typedef char *const24_str;
  153. #endif
  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
  161. typedef 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. #ifndef ZSTR
  170. # define ZSTR(s) (s)
  171. #endif
  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. /* {{{ u hash wrapper */
  177. #ifndef IS_UNICODE
  178. # define zend_u_hash_add(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
  179. zend_hash_add(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, pData, nDataSize, pDest)
  180. # define zend_u_hash_quick_add(ht, type, arKey, nKeyLength, h, pData, nDataSize, pDest) \
  181. zend_hash_quick_add(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, h, pData, nDataSize, pDest)
  182. # define zend_u_hash_update(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
  183. zend_hash_update(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, pData, nDataSize, pDest)
  184. # define zend_u_hash_quick_update(ht, type, arKey, nKeyLength, h, pData, nDataSize, pDest) \
  185. zend_hash_quick_update(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, h, pData, nDataSize, pDest)
  186. # define zend_u_hash_find(ht, type, arKey, nKeyLength, pData) \
  187. zend_hash_find(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, pData)
  188. # define zend_u_hash_quick_find(ht, type, arKey, nKeyLength, h, pData) \
  189. zend_hash_quick_find(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, h, pData)
  190. # define zend_u_hash_exists(ht, type, arKey, nKeyLength) \
  191. zend_hash_exists(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength)
  192. # define add_u_assoc_zval_ex(arg, type, key, key_len, value) \
  193. add_assoc_zval_ex(arg, key, key_len, value)
  194. # define zend_u_is_auto_global(type, name, name_len) \
  195. zend_is_auto_global(name, name_len)
  196. #endif
  197. /* }}} */
  198. #ifndef ZVAL_COPY_VALUE
  199. # define ZVAL_COPY_VALUE(z, v) (z)->value = (v)->value
  200. #endif
  201. #ifndef ZVAL_ZVAL
  202. # define ZVAL_ZVAL(z, zv, copy, dtor) do { \
  203. zval *__z = (z); \
  204. zval *__zv = (zv); \
  205. ZVAL_COPY_VALUE(__z, __zv); \
  206. if (copy) { \
  207. zval_copy_ctor(__z); \
  208. } \
  209. if (dtor) { \
  210. if (!copy) { \
  211. ZVAL_NULL(__zv); \
  212. } \
  213. zval_ptr_dtor(&__zv); \
  214. } \
  215. } while (0)
  216. #endif
  217. #ifndef RETVAL_ZVAL
  218. # define RETVAL_ZVAL(zv, copy, dtor) ZVAL_ZVAL(return_value, zv, copy, dtor)
  219. #endif
  220. #ifndef RETURN_ZVAL
  221. # define RETURN_ZVAL(zv, copy, dtor) { RETVAL_ZVAL(zv, copy, dtor); return; }
  222. #endif
  223. /* the class entry type to be stored in class_table */
  224. typedef ZESW(zend_class_entry, zend_class_entry*) xc_cest_t;
  225. /* xc_cest_t to (zend_class_entry*) */
  226. #define CestToCePtr(st) (ZESW(\
  227. &(st), \
  228. st \
  229. ) )
  230. /* ZCEP=zend class entry ptr */
  231. #define ZCEP_REFCOUNT_PTR(pce) (ZESW( \
  232. (pce)->refcount, \
  233. &((pce)->refcount) \
  234. ))
  235. #ifndef ZEND_ENGINE_2_3
  236. size_t xc_dirname(char *path, size_t len);
  237. #define zend_dirname xc_dirname
  238. long xc_atol(const char *str, int len);
  239. #define zend_atol xc_atol
  240. #endif
  241. #ifndef ZEND_MOD_END
  242. # define ZEND_MOD_END {NULL, NULL, NULL, 0}
  243. #endif
  244. #ifndef PHP_FE_END
  245. # ifdef ZEND_ENGINE_2
  246. # define PHP_FE_END {NULL, NULL, NULL, 0, 0}
  247. # else
  248. # define PHP_FE_END {NULL, NULL, NULL}
  249. # endif
  250. #endif
  251. #if defined(ZEND_ENGINE_2) && !defined(ZEND_ENGINE_2_2)
  252. void *xc_object_store_get_object_by_handle(zend_object_handle handle TSRMLS_DC);
  253. # define zend_object_store_get_object_by_handle xc_object_store_get_object_by_handle
  254. void xc_objects_store_add_ref_by_handle(zend_object_handle handle TSRMLS_DC);
  255. # define zend_objects_store_add_ref_by_handle xc_objects_store_add_ref_by_handle
  256. void xc_objects_store_del_ref_by_handle(zend_object_handle handle TSRMLS_DC);
  257. # define zend_objects_store_del_ref_by_handle xc_objects_store_del_ref_by_handle
  258. #endif
  259. #endif /* XC_COMPATIBILITY_H_54F26ED90198353558718191D5EE244C */