wrapper.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. #ifndef EBP_C_WRAPPER_H
  2. #define EBP_C_WRAPPER_H
  3. // PHP7.4 +
  4. #if !defined(ZEND_ACC_IMPLICIT_PUBLIC)
  5. # define ZEND_ACC_IMPLICIT_PUBLIC ZEND_ACC_PUBLIC
  6. #endif
  7. // PHP8+
  8. #if !defined(ZEND_ACC_DTOR)
  9. #define ZEND_ACC_DTOR 0x4000
  10. #endif
  11. // PHP5+
  12. #if PHP_MAJOR_VERSION <7
  13. #if PHP_VERSION_ID < 50500
  14. #define sc_zend_throw_exception(a, b, c) zend_throw_exception(a, (char *)b, c)
  15. #else
  16. #define sc_zend_throw_exception zend_throw_exception
  17. #endif
  18. #define sc_zend_throw_exception_tsrmls_cc sc_zend_throw_exception
  19. #define IS_TRUE 1
  20. #define SC_MAKE_STD_ZVAL(p) MAKE_STD_ZVAL(p)
  21. #define SC_RETURN_STRINGL(k, l) RETURN_STRINGL(k, l, 1)
  22. #define sc_zval_ptr_dtor zval_ptr_dtor
  23. #define sc_zval_add_ref(a) zval_add_ref(&a)
  24. static inline int sc_add_assoc_long_ex(zval *arg, const char *key, size_t key_len, long value)
  25. {
  26. return add_assoc_long_ex(arg, key, key_len + 1, value);
  27. }
  28. static inline int sc_add_assoc_double_ex(zval *arg, const char *key, size_t key_len, double value)
  29. {
  30. return add_assoc_double_ex(arg, key, key_len + 1, value);
  31. }
  32. static inline int sc_add_assoc_zval_ex(zval *arg, const char *key, size_t key_len, zval* value)
  33. {
  34. return add_assoc_zval_ex(arg, key, key_len + 1, value);
  35. }
  36. static inline int sc_add_assoc_stringl_ex(zval *arg, const char *key, size_t key_len, char *str, size_t length, int __duplicate)
  37. {
  38. return add_assoc_stringl_ex(arg, key, key_len + 1, str, length, __duplicate);
  39. }
  40. static inline int sc_add_assoc_null_ex(zval *arg, const char *key, size_t key_len)
  41. {
  42. return add_assoc_null_ex(arg, key, key_len + 1);
  43. }
  44. static inline zval *sc_zend_hash_find(HashTable *ht, char *k, int len)
  45. {
  46. zval **tmp = NULL;
  47. if (zend_hash_find(ht, k, len + 1, (void **) &tmp) == SUCCESS)
  48. {
  49. return *tmp;
  50. }
  51. else
  52. {
  53. return NULL;
  54. }
  55. }
  56. static inline zval *sc_zend_hash_index_find(HashTable *ht, ulong h)
  57. {
  58. zval **tmp = NULL;
  59. if (zend_hash_index_find(ht, h, (void **) &tmp) == SUCCESS)
  60. {
  61. return *tmp;
  62. }
  63. else
  64. {
  65. return NULL;
  66. }
  67. }
  68. #define sc_zend_update_property_string zend_update_property_string
  69. #define sc_zend_read_property(a, b, c, d, e) zend_read_property(a, b, c, d, e TSRMLS_CC)
  70. #define SC_HASHTABLE_FOREACH_START2(ht, k, klen, ktype, entry)\
  71. zval **tmp = NULL; ulong_t idx;\
  72. for (zend_hash_internal_pointer_reset(ht); \
  73. (ktype = zend_hash_get_current_key_ex(ht, &k, &klen, &idx, 0, NULL)) != HASH_KEY_NON_EXISTANT; \
  74. zend_hash_move_forward(ht)\
  75. ) { \
  76. if (zend_hash_get_current_data(ht, (void**)&tmp) == FAILURE) {\
  77. continue;\
  78. }\
  79. entry = *tmp;\
  80. klen --;
  81. #define SC_HASHTABLE_FOREACH_END() }
  82. #define sc_add_next_index_stringl add_next_index_stringl
  83. #define sc_zend_hash_get_current_data zend_hash_get_current_data
  84. #else
  85. // PHP7
  86. #define sc_zend_throw_exception zend_throw_exception
  87. #define sc_zend_hash_find zend_hash_str_find
  88. #define sc_zend_hash_index_find zend_hash_index_find
  89. #define SC_MAKE_STD_ZVAL(p) zval _stack_zval_##p; p = &(_stack_zval_##p)
  90. #define SC_RETURN_STRINGL(k, l) RETURN_STRINGL(k, l)
  91. #define sc_zval_ptr_dtor(p) zval_ptr_dtor(*p)
  92. #define sc_zval_add_ref(p) Z_TRY_ADDREF_P(p)
  93. #define sc_add_assoc_long_ex add_assoc_long_ex
  94. #define sc_add_assoc_double_ex add_assoc_double_ex
  95. #define sc_add_assoc_zval_ex add_assoc_zval_ex
  96. #define sc_add_assoc_stringl_ex(a, b, c, d, e, f) add_assoc_stringl_ex(a, b, c, d, e)
  97. #define sc_add_assoc_null_ex(a, b, c) add_assoc_null_ex(a, b, c)
  98. #if PHP_VERSION_ID < 80000
  99. #define sc_zend_throw_exception_tsrmls_cc(a, b, c) sc_zend_throw_exception(a, b, c TSRMLS_CC)
  100. #else
  101. #define sc_zend_throw_exception_tsrmls_cc(a, b, c) sc_zend_throw_exception(a, b, c)
  102. #endif
  103. static inline zval* sc_zend_read_property(zend_class_entry *class_ptr, zval *obj, const char *s, size_t len, int silent)
  104. {
  105. zval rv;
  106. #if PHP_VERSION_ID < 80000
  107. return zend_read_property(class_ptr, obj, s, len, silent, &rv);
  108. #else
  109. zend_object *zendObject;
  110. zendObject=Z_OBJ_P(obj);
  111. return zend_read_property(class_ptr, zendObject, s, len, silent, &rv);
  112. #endif
  113. }
  114. static inline void sc_zend_update_property_string( zend_class_entry *scope, zval *object, const char *name, size_t name_length, const char *value)
  115. {
  116. #if PHP_VERSION_ID < 80000
  117. return zend_update_property_string(scope, object, name, name_length, value TSRMLS_CC);
  118. #else
  119. zend_object *zendObject;
  120. zendObject=Z_OBJ_P(object);
  121. return zend_update_property_string(scope, zendObject, name, name_length, value);
  122. #endif
  123. }
  124. static inline void sc_zend_update_property(zend_class_entry *scope, zval *return_value, const char *name, size_t name_length, zval *value)
  125. {
  126. #if PHP_VERSION_ID < 80000
  127. return zend_update_property(scope, return_value, name, name_length, value TSRMLS_CC);
  128. #else
  129. zend_object *zendObject;
  130. zendObject=Z_OBJ_P(return_value);
  131. return zend_update_property(scope, zendObject, name, name_length, value);
  132. #endif
  133. }
  134. static inline void sc_zend_update_property_long(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_long value)
  135. {
  136. #if PHP_VERSION_ID < 80000
  137. return zend_update_property_long(scope, object, name, name_length, value TSRMLS_CC);
  138. #else
  139. zend_object *zendObject;
  140. zendObject=Z_OBJ_P(object);
  141. return zend_update_property_long(scope, zendObject, name, name_length, value);
  142. #endif
  143. }
  144. static inline void sc_zend_update_property_bool(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_long value) /* {{{ */
  145. {
  146. #if PHP_VERSION_ID < 80000
  147. return zend_update_property_bool(scope, object, name, name_length, value TSRMLS_CC);
  148. #else
  149. zend_object *zendObject;
  150. zendObject=Z_OBJ_P(object);
  151. return zend_update_property_bool(scope, zendObject, name, name_length, value);
  152. #endif
  153. }
  154. #define SC_HASHTABLE_FOREACH_START2(ht, k, klen, ktype, _val) zend_string *_foreach_key;\
  155. ZEND_HASH_FOREACH_STR_KEY_VAL(ht, _foreach_key, _val);\
  156. if (!_foreach_key) {k = NULL; klen = 0; ktype = 0;}\
  157. else {k = _foreach_key->val, klen=_foreach_key->len; ktype = 1;} {
  158. #define SC_HASHTABLE_FOREACH_END() } ZEND_HASH_FOREACH_END();
  159. #define sc_add_next_index_stringl(arr, str, len, dup) add_next_index_stringl(arr, str, len)
  160. static inline int sc_zend_hash_get_current_data(HashTable *ht, void **v)
  161. {
  162. zval *value = zend_hash_get_current_data(ht);
  163. if (value == NULL)
  164. {
  165. return FAILURE;
  166. }
  167. else
  168. {
  169. *v = (void *) value;
  170. return SUCCESS;
  171. }
  172. }
  173. #endif
  174. #define php_array_get_value(ht, str, v) ((v = sc_zend_hash_find(ht, (char *)str, sizeof(str)-1)) && !ZVAL_IS_NULL(v))
  175. #endif //EBP_C_WRAPPER_H