xref: /PHP-8.1/Zend/zend_string.h (revision b5726c2c)
1 /*
2    +----------------------------------------------------------------------+
3    | Zend Engine                                                          |
4    +----------------------------------------------------------------------+
5    | Copyright (c) Zend Technologies Ltd. (http://www.zend.com)           |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 2.00 of the Zend license,     |
8    | that is bundled with this package in the file LICENSE, and is        |
9    | available through the world-wide-web at the following url:           |
10    | http://www.zend.com/license/2_00.txt.                                |
11    | If you did not receive a copy of the Zend license and are unable to  |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@zend.com so we can mail you a copy immediately.              |
14    +----------------------------------------------------------------------+
15    | Authors: Dmitry Stogov <dmitry@php.net>                              |
16    +----------------------------------------------------------------------+
17 */
18 
19 #ifndef ZEND_STRING_H
20 #define ZEND_STRING_H
21 
22 #include "zend.h"
23 
24 BEGIN_EXTERN_C()
25 
26 typedef void (*zend_string_copy_storage_func_t)(void);
27 typedef zend_string *(ZEND_FASTCALL *zend_new_interned_string_func_t)(zend_string *str);
28 typedef zend_string *(ZEND_FASTCALL *zend_string_init_interned_func_t)(const char *str, size_t size, bool permanent);
29 typedef zend_string *(ZEND_FASTCALL *zend_string_init_existing_interned_func_t)(const char *str, size_t size, bool permanent);
30 
31 ZEND_API extern zend_new_interned_string_func_t zend_new_interned_string;
32 ZEND_API extern zend_string_init_interned_func_t zend_string_init_interned;
33 /* Init an interned string if it already exists, but do not create a new one if it does not. */
34 ZEND_API extern zend_string_init_existing_interned_func_t zend_string_init_existing_interned;
35 
36 ZEND_API zend_ulong ZEND_FASTCALL zend_string_hash_func(zend_string *str);
37 ZEND_API zend_ulong ZEND_FASTCALL zend_hash_func(const char *str, size_t len);
38 ZEND_API zend_string* ZEND_FASTCALL zend_interned_string_find_permanent(zend_string *str);
39 
40 ZEND_API zend_string *zend_string_concat2(
41 	const char *str1, size_t str1_len,
42 	const char *str2, size_t str2_len);
43 ZEND_API zend_string *zend_string_concat3(
44 	const char *str1, size_t str1_len,
45 	const char *str2, size_t str2_len,
46 	const char *str3, size_t str3_len);
47 
48 ZEND_API void zend_interned_strings_init(void);
49 ZEND_API void zend_interned_strings_dtor(void);
50 ZEND_API void zend_interned_strings_activate(void);
51 ZEND_API void zend_interned_strings_deactivate(void);
52 ZEND_API void zend_interned_strings_set_request_storage_handlers(
53 	zend_new_interned_string_func_t handler,
54 	zend_string_init_interned_func_t init_handler,
55 	zend_string_init_existing_interned_func_t init_existing_handler);
56 ZEND_API void zend_interned_strings_switch_storage(bool request);
57 
58 ZEND_API extern zend_string  *zend_empty_string;
59 ZEND_API extern zend_string  *zend_one_char_string[256];
60 ZEND_API extern zend_string **zend_known_strings;
61 
END_EXTERN_C()62 END_EXTERN_C()
63 
64 /* Shortcuts */
65 
66 #define ZSTR_VAL(zstr)  (zstr)->val
67 #define ZSTR_LEN(zstr)  (zstr)->len
68 #define ZSTR_H(zstr)    (zstr)->h
69 #define ZSTR_HASH(zstr) zend_string_hash_val(zstr)
70 
71 /* Compatibility macros */
72 
73 #define IS_INTERNED(s)	ZSTR_IS_INTERNED(s)
74 #define STR_EMPTY_ALLOC()	ZSTR_EMPTY_ALLOC()
75 #define _STR_HEADER_SIZE _ZSTR_HEADER_SIZE
76 #define STR_ALLOCA_ALLOC(str, _len, use_heap) ZSTR_ALLOCA_ALLOC(str, _len, use_heap)
77 #define STR_ALLOCA_INIT(str, s, len, use_heap) ZSTR_ALLOCA_INIT(str, s, len, use_heap)
78 #define STR_ALLOCA_FREE(str, use_heap) ZSTR_ALLOCA_FREE(str, use_heap)
79 
80 /*---*/
81 
82 #define ZSTR_IS_INTERNED(s)					(GC_FLAGS(s) & IS_STR_INTERNED)
83 
84 #define ZSTR_EMPTY_ALLOC() zend_empty_string
85 #define ZSTR_CHAR(c) zend_one_char_string[c]
86 #define ZSTR_KNOWN(idx) zend_known_strings[idx]
87 
88 #define _ZSTR_HEADER_SIZE XtOffsetOf(zend_string, val)
89 
90 #define _ZSTR_STRUCT_SIZE(len) (_ZSTR_HEADER_SIZE + len + 1)
91 
92 #define ZSTR_MAX_OVERHEAD (ZEND_MM_ALIGNED_SIZE(_ZSTR_HEADER_SIZE + 1))
93 #define ZSTR_MAX_LEN (SIZE_MAX - ZSTR_MAX_OVERHEAD)
94 
95 #define ZSTR_ALLOCA_ALLOC(str, _len, use_heap) do { \
96 	(str) = (zend_string *)do_alloca(ZEND_MM_ALIGNED_SIZE_EX(_ZSTR_STRUCT_SIZE(_len), 8), (use_heap)); \
97 	GC_SET_REFCOUNT(str, 1); \
98 	GC_TYPE_INFO(str) = GC_STRING; \
99 	ZSTR_H(str) = 0; \
100 	ZSTR_LEN(str) = _len; \
101 } while (0)
102 
103 #define ZSTR_ALLOCA_INIT(str, s, len, use_heap) do { \
104 	ZSTR_ALLOCA_ALLOC(str, len, use_heap); \
105 	memcpy(ZSTR_VAL(str), (s), (len)); \
106 	ZSTR_VAL(str)[(len)] = '\0'; \
107 } while (0)
108 
109 #define ZSTR_ALLOCA_FREE(str, use_heap) free_alloca(str, use_heap)
110 
111 #define ZSTR_INIT_LITERAL(s, persistent) (zend_string_init((s), strlen(s), (persistent)))
112 
113 /*---*/
114 
115 static zend_always_inline zend_ulong zend_string_hash_val(zend_string *s)
116 {
117 	return ZSTR_H(s) ? ZSTR_H(s) : zend_string_hash_func(s);
118 }
119 
zend_string_forget_hash_val(zend_string * s)120 static zend_always_inline void zend_string_forget_hash_val(zend_string *s)
121 {
122 	ZSTR_H(s) = 0;
123 	GC_DEL_FLAGS(s, IS_STR_VALID_UTF8);
124 }
125 
zend_string_refcount(const zend_string * s)126 static zend_always_inline uint32_t zend_string_refcount(const zend_string *s)
127 {
128 	if (!ZSTR_IS_INTERNED(s)) {
129 		return GC_REFCOUNT(s);
130 	}
131 	return 1;
132 }
133 
zend_string_addref(zend_string * s)134 static zend_always_inline uint32_t zend_string_addref(zend_string *s)
135 {
136 	if (!ZSTR_IS_INTERNED(s)) {
137 		return GC_ADDREF(s);
138 	}
139 	return 1;
140 }
141 
zend_string_delref(zend_string * s)142 static zend_always_inline uint32_t zend_string_delref(zend_string *s)
143 {
144 	if (!ZSTR_IS_INTERNED(s)) {
145 		return GC_DELREF(s);
146 	}
147 	return 1;
148 }
149 
zend_string_alloc(size_t len,bool persistent)150 static zend_always_inline zend_string *zend_string_alloc(size_t len, bool persistent)
151 {
152 	zend_string *ret = (zend_string *)pemalloc(ZEND_MM_ALIGNED_SIZE(_ZSTR_STRUCT_SIZE(len)), persistent);
153 
154 	GC_SET_REFCOUNT(ret, 1);
155 	GC_TYPE_INFO(ret) = GC_STRING | ((persistent ? IS_STR_PERSISTENT : 0) << GC_FLAGS_SHIFT);
156 	ZSTR_H(ret) = 0;
157 	ZSTR_LEN(ret) = len;
158 	return ret;
159 }
160 
zend_string_safe_alloc(size_t n,size_t m,size_t l,bool persistent)161 static zend_always_inline zend_string *zend_string_safe_alloc(size_t n, size_t m, size_t l, bool persistent)
162 {
163 	zend_string *ret = (zend_string *)safe_pemalloc(n, m, ZEND_MM_ALIGNED_SIZE(_ZSTR_STRUCT_SIZE(l)), persistent);
164 
165 	GC_SET_REFCOUNT(ret, 1);
166 	GC_TYPE_INFO(ret) = GC_STRING | ((persistent ? IS_STR_PERSISTENT : 0) << GC_FLAGS_SHIFT);
167 	ZSTR_H(ret) = 0;
168 	ZSTR_LEN(ret) = (n * m) + l;
169 	return ret;
170 }
171 
zend_string_init(const char * str,size_t len,bool persistent)172 static zend_always_inline zend_string *zend_string_init(const char *str, size_t len, bool persistent)
173 {
174 	zend_string *ret = zend_string_alloc(len, persistent);
175 
176 	memcpy(ZSTR_VAL(ret), str, len);
177 	ZSTR_VAL(ret)[len] = '\0';
178 	return ret;
179 }
180 
zend_string_init_fast(const char * str,size_t len)181 static zend_always_inline zend_string *zend_string_init_fast(const char *str, size_t len)
182 {
183 	if (len > 1) {
184 		return zend_string_init(str, len, 0);
185 	} else if (len == 0) {
186 		return zend_empty_string;
187 	} else /* if (len == 1) */ {
188 		return ZSTR_CHAR((zend_uchar) *str);
189 	}
190 }
191 
zend_string_copy(zend_string * s)192 static zend_always_inline zend_string *zend_string_copy(zend_string *s)
193 {
194 	if (!ZSTR_IS_INTERNED(s)) {
195 		GC_ADDREF(s);
196 	}
197 	return s;
198 }
199 
zend_string_dup(zend_string * s,bool persistent)200 static zend_always_inline zend_string *zend_string_dup(zend_string *s, bool persistent)
201 {
202 	if (ZSTR_IS_INTERNED(s)) {
203 		return s;
204 	} else {
205 		return zend_string_init(ZSTR_VAL(s), ZSTR_LEN(s), persistent);
206 	}
207 }
208 
zend_string_separate(zend_string * s,bool persistent)209 static zend_always_inline zend_string *zend_string_separate(zend_string *s, bool persistent)
210 {
211 	if (ZSTR_IS_INTERNED(s) || GC_REFCOUNT(s) > 1) {
212 		if (!ZSTR_IS_INTERNED(s)) {
213 			GC_DELREF(s);
214 		}
215 		return zend_string_init(ZSTR_VAL(s), ZSTR_LEN(s), persistent);
216 	}
217 
218 	zend_string_forget_hash_val(s);
219 	return s;
220 }
221 
zend_string_realloc(zend_string * s,size_t len,bool persistent)222 static zend_always_inline zend_string *zend_string_realloc(zend_string *s, size_t len, bool persistent)
223 {
224 	zend_string *ret;
225 
226 	if (!ZSTR_IS_INTERNED(s)) {
227 		if (EXPECTED(GC_REFCOUNT(s) == 1)) {
228 			ret = (zend_string *)perealloc(s, ZEND_MM_ALIGNED_SIZE(_ZSTR_STRUCT_SIZE(len)), persistent);
229 			ZSTR_LEN(ret) = len;
230 			zend_string_forget_hash_val(ret);
231 			return ret;
232 		}
233 	}
234 	ret = zend_string_alloc(len, persistent);
235 	memcpy(ZSTR_VAL(ret), ZSTR_VAL(s), MIN(len, ZSTR_LEN(s)) + 1);
236 	if (!ZSTR_IS_INTERNED(s)) {
237 		GC_DELREF(s);
238 	}
239 	return ret;
240 }
241 
zend_string_extend(zend_string * s,size_t len,bool persistent)242 static zend_always_inline zend_string *zend_string_extend(zend_string *s, size_t len, bool persistent)
243 {
244 	zend_string *ret;
245 
246 	ZEND_ASSERT(len >= ZSTR_LEN(s));
247 	if (!ZSTR_IS_INTERNED(s)) {
248 		if (EXPECTED(GC_REFCOUNT(s) == 1)) {
249 			ret = (zend_string *)perealloc(s, ZEND_MM_ALIGNED_SIZE(_ZSTR_STRUCT_SIZE(len)), persistent);
250 			ZSTR_LEN(ret) = len;
251 			zend_string_forget_hash_val(ret);
252 			return ret;
253 		}
254 	}
255 	ret = zend_string_alloc(len, persistent);
256 	memcpy(ZSTR_VAL(ret), ZSTR_VAL(s), ZSTR_LEN(s) + 1);
257 	if (!ZSTR_IS_INTERNED(s)) {
258 		GC_DELREF(s);
259 	}
260 	return ret;
261 }
262 
zend_string_truncate(zend_string * s,size_t len,bool persistent)263 static zend_always_inline zend_string *zend_string_truncate(zend_string *s, size_t len, bool persistent)
264 {
265 	zend_string *ret;
266 
267 	ZEND_ASSERT(len <= ZSTR_LEN(s));
268 	if (!ZSTR_IS_INTERNED(s)) {
269 		if (EXPECTED(GC_REFCOUNT(s) == 1)) {
270 			ret = (zend_string *)perealloc(s, ZEND_MM_ALIGNED_SIZE(_ZSTR_STRUCT_SIZE(len)), persistent);
271 			ZSTR_LEN(ret) = len;
272 			zend_string_forget_hash_val(ret);
273 			return ret;
274 		}
275 	}
276 	ret = zend_string_alloc(len, persistent);
277 	memcpy(ZSTR_VAL(ret), ZSTR_VAL(s), len + 1);
278 	if (!ZSTR_IS_INTERNED(s)) {
279 		GC_DELREF(s);
280 	}
281 	return ret;
282 }
283 
zend_string_safe_realloc(zend_string * s,size_t n,size_t m,size_t l,bool persistent)284 static zend_always_inline zend_string *zend_string_safe_realloc(zend_string *s, size_t n, size_t m, size_t l, bool persistent)
285 {
286 	zend_string *ret;
287 
288 	if (!ZSTR_IS_INTERNED(s)) {
289 		if (GC_REFCOUNT(s) == 1) {
290 			ret = (zend_string *)safe_perealloc(s, n, m, ZEND_MM_ALIGNED_SIZE(_ZSTR_STRUCT_SIZE(l)), persistent);
291 			ZSTR_LEN(ret) = (n * m) + l;
292 			zend_string_forget_hash_val(ret);
293 			return ret;
294 		}
295 	}
296 	ret = zend_string_safe_alloc(n, m, l, persistent);
297 	memcpy(ZSTR_VAL(ret), ZSTR_VAL(s), MIN((n * m) + l, ZSTR_LEN(s)) + 1);
298 	if (!ZSTR_IS_INTERNED(s)) {
299 		GC_DELREF(s);
300 	}
301 	return ret;
302 }
303 
zend_string_free(zend_string * s)304 static zend_always_inline void zend_string_free(zend_string *s)
305 {
306 	if (!ZSTR_IS_INTERNED(s)) {
307 		ZEND_ASSERT(GC_REFCOUNT(s) <= 1);
308 		pefree(s, GC_FLAGS(s) & IS_STR_PERSISTENT);
309 	}
310 }
311 
zend_string_efree(zend_string * s)312 static zend_always_inline void zend_string_efree(zend_string *s)
313 {
314 	ZEND_ASSERT(!ZSTR_IS_INTERNED(s));
315 	ZEND_ASSERT(GC_REFCOUNT(s) <= 1);
316 	ZEND_ASSERT(!(GC_FLAGS(s) & IS_STR_PERSISTENT));
317 	efree(s);
318 }
319 
zend_string_release(zend_string * s)320 static zend_always_inline void zend_string_release(zend_string *s)
321 {
322 	if (!ZSTR_IS_INTERNED(s)) {
323 		if (GC_DELREF(s) == 0) {
324 			pefree(s, GC_FLAGS(s) & IS_STR_PERSISTENT);
325 		}
326 	}
327 }
328 
zend_string_release_ex(zend_string * s,bool persistent)329 static zend_always_inline void zend_string_release_ex(zend_string *s, bool persistent)
330 {
331 	if (!ZSTR_IS_INTERNED(s)) {
332 		if (GC_DELREF(s) == 0) {
333 			if (persistent) {
334 				ZEND_ASSERT(GC_FLAGS(s) & IS_STR_PERSISTENT);
335 				free(s);
336 			} else {
337 				ZEND_ASSERT(!(GC_FLAGS(s) & IS_STR_PERSISTENT));
338 				efree(s);
339 			}
340 		}
341 	}
342 }
343 
344 #if defined(__GNUC__) && (defined(__i386__) || (defined(__x86_64__) && !defined(__ILP32__)))
345 BEGIN_EXTERN_C()
346 ZEND_API bool ZEND_FASTCALL zend_string_equal_val(zend_string *s1, zend_string *s2);
END_EXTERN_C()347 END_EXTERN_C()
348 #else
349 static zend_always_inline bool zend_string_equal_val(zend_string *s1, zend_string *s2)
350 {
351 	return !memcmp(ZSTR_VAL(s1), ZSTR_VAL(s2), ZSTR_LEN(s1));
352 }
353 #endif
354 
355 static zend_always_inline bool zend_string_equal_content(zend_string *s1, zend_string *s2)
356 {
357 	return ZSTR_LEN(s1) == ZSTR_LEN(s2) && zend_string_equal_val(s1, s2);
358 }
359 
zend_string_equals(zend_string * s1,zend_string * s2)360 static zend_always_inline bool zend_string_equals(zend_string *s1, zend_string *s2)
361 {
362 	return s1 == s2 || zend_string_equal_content(s1, s2);
363 }
364 
365 #define zend_string_equals_ci(s1, s2) \
366 	(ZSTR_LEN(s1) == ZSTR_LEN(s2) && !zend_binary_strcasecmp(ZSTR_VAL(s1), ZSTR_LEN(s1), ZSTR_VAL(s2), ZSTR_LEN(s2)))
367 
368 #define zend_string_equals_literal_ci(str, c) \
369 	(ZSTR_LEN(str) == sizeof(c) - 1 && !zend_binary_strcasecmp(ZSTR_VAL(str), ZSTR_LEN(str), (c), sizeof(c) - 1))
370 
371 #define zend_string_equals_literal(str, literal) \
372 	(ZSTR_LEN(str) == sizeof(literal)-1 && !memcmp(ZSTR_VAL(str), literal, sizeof(literal) - 1))
373 
374 /*
375  * DJBX33A (Daniel J. Bernstein, Times 33 with Addition)
376  *
377  * This is Daniel J. Bernstein's popular `times 33' hash function as
378  * posted by him years ago on comp.lang.c. It basically uses a function
379  * like ``hash(i) = hash(i-1) * 33 + str[i]''. This is one of the best
380  * known hash functions for strings. Because it is both computed very
381  * fast and distributes very well.
382  *
383  * The magic of number 33, i.e. why it works better than many other
384  * constants, prime or not, has never been adequately explained by
385  * anyone. So I try an explanation: if one experimentally tests all
386  * multipliers between 1 and 256 (as RSE did now) one detects that even
387  * numbers are not usable at all. The remaining 128 odd numbers
388  * (except for the number 1) work more or less all equally well. They
389  * all distribute in an acceptable way and this way fill a hash table
390  * with an average percent of approx. 86%.
391  *
392  * If one compares the Chi^2 values of the variants, the number 33 not
393  * even has the best value. But the number 33 and a few other equally
394  * good numbers like 17, 31, 63, 127 and 129 have nevertheless a great
395  * advantage to the remaining numbers in the large set of possible
396  * multipliers: their multiply operation can be replaced by a faster
397  * operation based on just one shift plus either a single addition
398  * or subtraction operation. And because a hash function has to both
399  * distribute good _and_ has to be very fast to compute, those few
400  * numbers should be preferred and seems to be the reason why Daniel J.
401  * Bernstein also preferred it.
402  *
403  *
404  *                  -- Ralf S. Engelschall <rse@engelschall.com>
405  */
406 
zend_inline_hash_func(const char * str,size_t len)407 static zend_always_inline zend_ulong zend_inline_hash_func(const char *str, size_t len)
408 {
409 	zend_ulong hash = Z_UL(5381);
410 
411 #if defined(_WIN32) || defined(__i386__) || defined(__x86_64__) || defined(__aarch64__)
412 	/* Version with multiplication works better on modern CPU */
413 	for (; len >= 8; len -= 8, str += 8) {
414 # if defined(__aarch64__) && !defined(WORDS_BIGENDIAN)
415 		/* On some architectures it is beneficial to load 8 bytes at a
416 		   time and extract each byte with a bit field extract instr. */
417 		uint64_t chunk;
418 
419 		memcpy(&chunk, str, sizeof(chunk));
420 		hash =
421 			hash                        * 33 * 33 * 33 * 33 +
422 			((chunk >> (8 * 0)) & 0xff) * 33 * 33 * 33 +
423 			((chunk >> (8 * 1)) & 0xff) * 33 * 33 +
424 			((chunk >> (8 * 2)) & 0xff) * 33 +
425 			((chunk >> (8 * 3)) & 0xff);
426 		hash =
427 			hash                        * 33 * 33 * 33 * 33 +
428 			((chunk >> (8 * 4)) & 0xff) * 33 * 33 * 33 +
429 			((chunk >> (8 * 5)) & 0xff) * 33 * 33 +
430 			((chunk >> (8 * 6)) & 0xff) * 33 +
431 			((chunk >> (8 * 7)) & 0xff);
432 # else
433 		hash =
434 			hash   * 33 * 33 * 33 * 33 +
435 			str[0] * 33 * 33 * 33 +
436 			str[1] * 33 * 33 +
437 			str[2] * 33 +
438 			str[3];
439 		hash =
440 			hash   * 33 * 33 * 33 * 33 +
441 			str[4] * 33 * 33 * 33 +
442 			str[5] * 33 * 33 +
443 			str[6] * 33 +
444 			str[7];
445 # endif
446 	}
447 	if (len >= 4) {
448 		hash =
449 			hash   * 33 * 33 * 33 * 33 +
450 			str[0] * 33 * 33 * 33 +
451 			str[1] * 33 * 33 +
452 			str[2] * 33 +
453 			str[3];
454 		len -= 4;
455 		str += 4;
456 	}
457 	if (len >= 2) {
458 		if (len > 2) {
459 			hash =
460 				hash   * 33 * 33 * 33 +
461 				str[0] * 33 * 33 +
462 				str[1] * 33 +
463 				str[2];
464 		} else {
465 			hash =
466 				hash   * 33 * 33 +
467 				str[0] * 33 +
468 				str[1];
469 		}
470 	} else if (len != 0) {
471 		hash = hash * 33 + *str;
472 	}
473 #else
474 	/* variant with the hash unrolled eight times */
475 	for (; len >= 8; len -= 8) {
476 		hash = ((hash << 5) + hash) + *str++;
477 		hash = ((hash << 5) + hash) + *str++;
478 		hash = ((hash << 5) + hash) + *str++;
479 		hash = ((hash << 5) + hash) + *str++;
480 		hash = ((hash << 5) + hash) + *str++;
481 		hash = ((hash << 5) + hash) + *str++;
482 		hash = ((hash << 5) + hash) + *str++;
483 		hash = ((hash << 5) + hash) + *str++;
484 	}
485 	switch (len) {
486 		case 7: hash = ((hash << 5) + hash) + *str++; /* fallthrough... */
487 		case 6: hash = ((hash << 5) + hash) + *str++; /* fallthrough... */
488 		case 5: hash = ((hash << 5) + hash) + *str++; /* fallthrough... */
489 		case 4: hash = ((hash << 5) + hash) + *str++; /* fallthrough... */
490 		case 3: hash = ((hash << 5) + hash) + *str++; /* fallthrough... */
491 		case 2: hash = ((hash << 5) + hash) + *str++; /* fallthrough... */
492 		case 1: hash = ((hash << 5) + hash) + *str++; break;
493 		case 0: break;
494 EMPTY_SWITCH_DEFAULT_CASE()
495 	}
496 #endif
497 
498 	/* Hash value can't be zero, so we always set the high bit */
499 #if SIZEOF_ZEND_LONG == 8
500 	return hash | Z_UL(0x8000000000000000);
501 #elif SIZEOF_ZEND_LONG == 4
502 	return hash | Z_UL(0x80000000);
503 #else
504 # error "Unknown SIZEOF_ZEND_LONG"
505 #endif
506 }
507 
508 #define ZEND_KNOWN_STRINGS(_) \
509 	_(ZEND_STR_FILE,                   "file") \
510 	_(ZEND_STR_LINE,                   "line") \
511 	_(ZEND_STR_FUNCTION,               "function") \
512 	_(ZEND_STR_CLASS,                  "class") \
513 	_(ZEND_STR_OBJECT,                 "object") \
514 	_(ZEND_STR_TYPE,                   "type") \
515 	_(ZEND_STR_OBJECT_OPERATOR,        "->") \
516 	_(ZEND_STR_PAAMAYIM_NEKUDOTAYIM,   "::") \
517 	_(ZEND_STR_ARGS,                   "args") \
518 	_(ZEND_STR_UNKNOWN,                "unknown") \
519 	_(ZEND_STR_UNKNOWN_CAPITALIZED,    "Unknown") \
520 	_(ZEND_STR_EVAL,                   "eval") \
521 	_(ZEND_STR_INCLUDE,                "include") \
522 	_(ZEND_STR_REQUIRE,                "require") \
523 	_(ZEND_STR_INCLUDE_ONCE,           "include_once") \
524 	_(ZEND_STR_REQUIRE_ONCE,           "require_once") \
525 	_(ZEND_STR_SCALAR,                 "scalar") \
526 	_(ZEND_STR_ERROR_REPORTING,        "error_reporting") \
527 	_(ZEND_STR_STATIC,                 "static") \
528 	_(ZEND_STR_THIS,                   "this") \
529 	_(ZEND_STR_VALUE,                  "value") \
530 	_(ZEND_STR_KEY,                    "key") \
531 	_(ZEND_STR_MAGIC_INVOKE,           "__invoke") \
532 	_(ZEND_STR_PREVIOUS,               "previous") \
533 	_(ZEND_STR_CODE,                   "code") \
534 	_(ZEND_STR_MESSAGE,                "message") \
535 	_(ZEND_STR_SEVERITY,               "severity") \
536 	_(ZEND_STR_STRING,                 "string") \
537 	_(ZEND_STR_TRACE,                  "trace") \
538 	_(ZEND_STR_SCHEME,                 "scheme") \
539 	_(ZEND_STR_HOST,                   "host") \
540 	_(ZEND_STR_PORT,                   "port") \
541 	_(ZEND_STR_USER,                   "user") \
542 	_(ZEND_STR_PASS,                   "pass") \
543 	_(ZEND_STR_PATH,                   "path") \
544 	_(ZEND_STR_QUERY,                  "query") \
545 	_(ZEND_STR_FRAGMENT,               "fragment") \
546 	_(ZEND_STR_NULL,                   "NULL") \
547 	_(ZEND_STR_BOOLEAN,                "boolean") \
548 	_(ZEND_STR_INTEGER,                "integer") \
549 	_(ZEND_STR_DOUBLE,                 "double") \
550 	_(ZEND_STR_ARRAY,                  "array") \
551 	_(ZEND_STR_RESOURCE,               "resource") \
552 	_(ZEND_STR_CLOSED_RESOURCE,        "resource (closed)") \
553 	_(ZEND_STR_NAME,                   "name") \
554 	_(ZEND_STR_ARGV,                   "argv") \
555 	_(ZEND_STR_ARGC,                   "argc") \
556 	_(ZEND_STR_ARRAY_CAPITALIZED,      "Array") \
557 	_(ZEND_STR_BOOL,                   "bool") \
558 	_(ZEND_STR_INT,                    "int") \
559 	_(ZEND_STR_FLOAT,                  "float") \
560 	_(ZEND_STR_CALLABLE,               "callable") \
561 	_(ZEND_STR_ITERABLE,               "iterable") \
562 	_(ZEND_STR_VOID,                   "void") \
563 	_(ZEND_STR_NEVER,                  "never") \
564 	_(ZEND_STR_FALSE,                  "false") \
565 	_(ZEND_STR_NULL_LOWERCASE,         "null") \
566 	_(ZEND_STR_MIXED,                  "mixed") \
567 	_(ZEND_STR_SLEEP,                  "__sleep") \
568 	_(ZEND_STR_WAKEUP,                 "__wakeup") \
569 	_(ZEND_STR_CASES,                  "cases") \
570 	_(ZEND_STR_FROM,                   "from") \
571 	_(ZEND_STR_TRYFROM,                "tryFrom") \
572 	_(ZEND_STR_TRYFROM_LOWERCASE,      "tryfrom") \
573 	_(ZEND_STR_AUTOGLOBAL_SERVER,      "_SERVER") \
574 	_(ZEND_STR_AUTOGLOBAL_ENV,         "_ENV") \
575 	_(ZEND_STR_AUTOGLOBAL_REQUEST,     "_REQUEST") \
576 
577 
578 typedef enum _zend_known_string_id {
579 #define _ZEND_STR_ID(id, str) id,
580 ZEND_KNOWN_STRINGS(_ZEND_STR_ID)
581 #undef _ZEND_STR_ID
582 	ZEND_STR_LAST_KNOWN
583 } zend_known_string_id;
584 
585 #endif /* ZEND_STRING_H */
586