summaryrefslogtreecommitdiff
path: root/src/sp_php_compat.h
diff options
context:
space:
mode:
authorBen Fuhrmannek2021-08-08 12:44:13 +0200
committerBen Fuhrmannek2021-08-08 12:44:13 +0200
commitecbc2bba7ba2d1c0c766dd16195ee88edbe550a8 (patch)
tree88a1caa56a709066cdb38759a265a5b4bc593bb8 /src/sp_php_compat.h
parentf41303ebed6f5de3a264ba5c70851d4da215061c (diff)
more PHP 7 compatibility and license clarification
Diffstat (limited to 'src/sp_php_compat.h')
-rw-r--r--src/sp_php_compat.h93
1 files changed, 87 insertions, 6 deletions
diff --git a/src/sp_php_compat.h b/src/sp_php_compat.h
index 380abe4..992c3e2 100644
--- a/src/sp_php_compat.h
+++ b/src/sp_php_compat.h
@@ -1,12 +1,93 @@
1#if PHP_VERSION_ID < 80000 1#if PHP_VERSION_ID < 80000
2
3// copied from PHP 8.0.9 sources
2ZEND_API zend_string *zend_string_concat2( 4ZEND_API zend_string *zend_string_concat2(
3 const char *str1, size_t str1_len, 5 const char *str1, size_t str1_len,
4 const char *str2, size_t str2_len); 6 const char *str2, size_t str2_len);
5 7
6#define ZEND_HASH_REVERSE_FOREACH_KEY_PTR(ht, _h, _key, _ptr) \ 8#define ZEND_HASH_REVERSE_FOREACH_KEY_PTR(ht, _h, _key, _ptr) \
7 ZEND_HASH_REVERSE_FOREACH(ht, 0); \ 9 ZEND_HASH_REVERSE_FOREACH(ht, 0); \
8 _h = _p->h; \ 10 _h = _p->h; \
9 _key = _p->key; \ 11 _key = _p->key; \
10 _ptr = Z_PTR_P(_z); 12 _ptr = Z_PTR_P(_z);
13
14#endif
15
16#if PHP_VERSION_ID < 70300
17
18// copied from PHP 7.4.22 sources
19
20static zend_always_inline uint32_t zend_gc_delref(zend_refcounted_h *p) {
21 ZEND_ASSERT(p->refcount > 0);
22 // ZEND_RC_MOD_CHECK(p);
23 return --(p->refcount);
24}
25#define GC_DELREF(p) zend_gc_delref(&(p)->gc)
26
27static zend_always_inline void zend_string_release_ex(zend_string *s, int persistent)
28{
29 if (!ZSTR_IS_INTERNED(s)) {
30 if (GC_DELREF(s) == 0) {
31 if (persistent) {
32 ZEND_ASSERT(GC_FLAGS(s) & IS_STR_PERSISTENT);
33 free(s);
34 } else {
35 ZEND_ASSERT(!(GC_FLAGS(s) & IS_STR_PERSISTENT));
36 efree(s);
37 }
38 }
39 }
40}
41
42static zend_always_inline void zend_string_efree(zend_string *s)
43{
44 ZEND_ASSERT(!ZSTR_IS_INTERNED(s));
45 ZEND_ASSERT(GC_REFCOUNT(s) <= 1);
46 ZEND_ASSERT(!(GC_FLAGS(s) & IS_STR_PERSISTENT));
47 efree(s);
48}
49
50#endif
51
52#if PHP_VERSION_ID < 70200
53
54#undef ZEND_HASH_REVERSE_FOREACH
55
56// copied from PHP 7.4.22 sources
57
58#define ZEND_HASH_REVERSE_FOREACH(_ht, indirect) do { \
59 HashTable *__ht = (_ht); \
60 uint32_t _idx = __ht->nNumUsed; \
61 Bucket *_p = __ht->arData + _idx; \
62 zval *_z; \
63 for (_idx = __ht->nNumUsed; _idx > 0; _idx--) { \
64 _p--; \
65 _z = &_p->val; \
66 if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \
67 _z = Z_INDIRECT_P(_z); \
68 } \
69 if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue;
70
71
72#define ZEND_HASH_FOREACH_END_DEL() \
73 __ht->nNumOfElements--; \
74 do { \
75 uint32_t j = HT_IDX_TO_HASH(_idx - 1); \
76 uint32_t nIndex = _p->h | __ht->nTableMask; \
77 uint32_t i = HT_HASH(__ht, nIndex); \
78 if (UNEXPECTED(j != i)) { \
79 Bucket *prev = HT_HASH_TO_BUCKET(__ht, i); \
80 while (Z_NEXT(prev->val) != j) { \
81 i = Z_NEXT(prev->val); \
82 prev = HT_HASH_TO_BUCKET(__ht, i); \
83 } \
84 Z_NEXT(prev->val) = Z_NEXT(_p->val); \
85 } else { \
86 HT_HASH(__ht, nIndex) = Z_NEXT(_p->val); \
87 } \
88 } while (0); \
89 } \
90 __ht->nNumUsed = _idx; \
91 } while (0)
11 92
12#endif \ No newline at end of file 93#endif \ No newline at end of file