-
Notifications
You must be signed in to change notification settings - Fork 182
Expand file tree
/
Copy pathphp_compat.h
More file actions
178 lines (156 loc) · 6.56 KB
/
Copy pathphp_compat.h
File metadata and controls
178 lines (156 loc) · 6.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// Unless explicitly stated otherwise all files in this repository are
// dual-licensed under the Apache-2.0 License or BSD-3-Clause License.
//
// This product includes software developed at Datadog
// (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
#pragma once
#include <php.h>
#include <stdbool.h>
// target the definitions of PHP 7.4
#if PHP_VERSION_ID < 70100
// for arginfo purposes
# define IS_VOID IS_UNDEF
# define HT_IS_PACKED(ht) 0
# define HT_IS_WITHOUT_HOLES(ht) 0
# define MAY_BE_NULL 0
# define MAY_BE_STRING 0
# define MAY_BE_ARRAY 0
# include <Zend/zend_smart_str.h>
void zend_print_zval_r_to_buf_compat(smart_str *buf, zval *expr, int indent);
static inline zend_string *zend_print_zval_r_to_str(zval *expr, int indent)
{
smart_str buf = {0};
zend_print_zval_r_to_buf_compat(&buf, expr, indent);
smart_str_0(&buf);
return buf.s;
}
#endif
#if PHP_VERSION_ID < 70200
# undef ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX
# undef ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO
# define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX( \
name, return_reference, required_num_args, type, allow_null) \
static const zend_internal_arg_info name[] = { \
{(const char *)(zend_uintptr_t)(required_num_args), NULL, type, \
return_reference, allow_null, 0},
# define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(name, type, allow_null) \
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, 0, -1, type, allow_null)
# define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX( \
name, return_reference, required_num_args, class_name, allow_null) \
static const zend_internal_arg_info name[] = { \
{(const char *)(zend_uintptr_t)(required_num_args), #class_name, \
IS_OBJECT, return_reference, allow_null, 0},
# define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(name, class_name, allow_null) \
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX( \
name, 0, -1, class_name, allow_null)
// persistent must be true iif we're on the startup phase
static zend_always_inline zend_string *zend_string_init_interned(
const char *str, size_t len, int persistent)
{
zend_string *ret = zend_string_init(str, len, persistent);
# ifdef ZTS
// believe it or not zend_new_interned_string() is an identity function
// set the interned flag manually so zend_string_release() is a no-op
GC_FLAGS(ret) |= IS_STR_INTERNED;
zend_string_hash_val(ret);
return ret;
# else
return zend_new_interned_string(ret);
# endif
}
extern zend_string *zend_empty_string;
#endif
#if PHP_VERSION_ID < 70300
extern const HashTable zend_empty_array;
# define zend_hash_find_ex(ht, key, known) zend_hash_find(ht, key)
# define GC_ADDREF(x) (++GC_REFCOUNT(x))
# define GC_DELREF(x) (--GC_REFCOUNT(x))
static zend_always_inline void _gc_try_addref(zend_refcounted_h *_rc)
{
struct _zend_refcounted *rc = (struct _zend_refcounted *)_rc;
if (!(GC_FLAGS(rc) & IS_ARRAY_IMMUTABLE)) {
GC_ADDREF(rc);
}
}
# define GC_TRY_ADDREF(p) _gc_try_addref(&(p)->gc)
static zend_always_inline void _gc_try_delref(zend_refcounted_h *_rc)
{
struct _zend_refcounted *rc = (struct _zend_refcounted *)_rc;
if (!(GC_FLAGS(rc) & IS_ARRAY_IMMUTABLE)) {
GC_DELREF(rc);
}
}
# define GC_TRY_DELREF(p) _gc_try_delref(&(p)->gc)
zend_bool zend_ini_parse_bool(zend_string *str);
# define zend_string_efree zend_string_free
static inline HashTable *zend_new_array(uint32_t nSize)
{
HashTable *ht = (HashTable *)emalloc(sizeof(HashTable));
zend_hash_init(ht, nSize, dummy, ZVAL_PTR_DTOR, 0);
return ht;
}
#endif
#if PHP_VERSION_ID < 70400
zend_bool try_convert_to_string(zval *op);
# define tsrm_env_lock()
# define tsrm_env_unlock()
#endif
#if PHP_VERSION_ID < 80000
/* ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE was added in PHP 8.0 */
# define ZEND_ARG_TYPE_MASK(pass_by_ref, name, type_mask, default_value) \
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(pass_by_ref, name, default_value)
# define ZEND_ARG_INFO_WITH_DEFAULT_VALUE(pass_by_ref, name, default_value) \
ZEND_ARG_INFO(pass_by_ref, name)
# ifndef ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE
# define ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE( \
pass_by_ref, name, type_hint, allow_null, default_value) \
ZEND_ARG_TYPE_INFO(pass_by_ref, name, type_hint, allow_null)
# endif
# define IS_MIXED 0
#endif
#if PHP_VERSION_ID >= 70300 && PHP_VERSION_ID < 80000
static zend_always_inline void _gc_try_addref(zend_refcounted_h *rc)
{
if (!(rc->u.type_info & GC_IMMUTABLE)) {
rc->refcount++;
}
}
# define GC_TRY_ADDREF(p) _gc_try_addref(&(p)->gc)
#endif
#if PHP_VERSION_ID >= 70300 && PHP_VERSION_ID < 80100
static zend_always_inline void _gc_try_delref(zend_refcounted_h *rc)
{
if (!(rc->u.type_info & GC_IMMUTABLE)) {
rc->refcount--;
}
}
# define GC_TRY_DELREF(p) _gc_try_delref(&(p)->gc)
#endif
#if PHP_VERSION_ID < 80100
# define ZEND_HASH_FOREACH_FROM(_ht, indirect, _from) \
do { \
Bucket *_p = (_ht)->arData + _from; \
Bucket *_end = (_ht)->arData + (_ht)->nNumUsed; \
for (; _p != _end; _p++) { \
zval *_z = &_p->val; \
if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \
_z = Z_INDIRECT_P(_z); \
} \
if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) \
continue;
#endif
#if PHP_VERSION_ID < 80200
# define DD_FOREACH_FROM(_ht, indirect, _from, index) \
ZEND_HASH_FOREACH_FROM(_ht, indirect, _from) \
index = _p->h;
static zend_always_inline bool zend_string_starts_with_cstr(
const zend_string *str, const char *prefix, size_t prefix_length)
{
return ZSTR_LEN(str) >= prefix_length &&
!memcmp(ZSTR_VAL(str), prefix, prefix_length);
}
#else
# define DD_FOREACH_FROM(_ht, indirect, _from, index) \
ZEND_HASH_FOREACH_FROM(_ht, indirect, _from) \
index = __h;
#endif