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
zend_string_equals_cstr(const zend_string * s1,const char * s2,size_t s2_length)344 static zend_always_inline bool zend_string_equals_cstr(const zend_string *s1, const char *s2, size_t s2_length)
345 {
346 return ZSTR_LEN(s1) == s2_length && !memcmp(ZSTR_VAL(s1), s2, s2_length);
347 }
348
349 #if defined(__GNUC__) && (defined(__i386__) || (defined(__x86_64__) && !defined(__ILP32__)))
350 BEGIN_EXTERN_C()
351 ZEND_API bool ZEND_FASTCALL zend_string_equal_val(const zend_string *s1, const zend_string *s2);
END_EXTERN_C()352 END_EXTERN_C()
353 #else
354 static zend_always_inline bool zend_string_equal_val(const zend_string *s1, const zend_string *s2)
355 {
356 return !memcmp(ZSTR_VAL(s1), ZSTR_VAL(s2), ZSTR_LEN(s1));
357 }
358 #endif
359
360 static zend_always_inline bool zend_string_equal_content(const zend_string *s1, const zend_string *s2)
361 {
362 return ZSTR_LEN(s1) == ZSTR_LEN(s2) && zend_string_equal_val(s1, s2);
363 }
364
zend_string_equals(const zend_string * s1,const zend_string * s2)365 static zend_always_inline bool zend_string_equals(const zend_string *s1, const zend_string *s2)
366 {
367 return s1 == s2 || zend_string_equal_content(s1, s2);
368 }
369
370 #define zend_string_equals_ci(s1, s2) \
371 (ZSTR_LEN(s1) == ZSTR_LEN(s2) && !zend_binary_strcasecmp(ZSTR_VAL(s1), ZSTR_LEN(s1), ZSTR_VAL(s2), ZSTR_LEN(s2)))
372
373 #define zend_string_equals_literal_ci(str, c) \
374 (ZSTR_LEN(str) == sizeof(c) - 1 && !zend_binary_strcasecmp(ZSTR_VAL(str), ZSTR_LEN(str), (c), sizeof(c) - 1))
375
376 #define zend_string_equals_literal(str, literal) \
377 zend_string_equals_cstr(str, literal, strlen(literal))
378
zend_string_starts_with_cstr(const zend_string * str,const char * prefix,size_t prefix_length)379 static zend_always_inline bool zend_string_starts_with_cstr(const zend_string *str, const char *prefix, size_t prefix_length)
380 {
381 return ZSTR_LEN(str) >= prefix_length && !memcmp(ZSTR_VAL(str), prefix, prefix_length);
382 }
383
zend_string_starts_with(const zend_string * str,const zend_string * prefix)384 static zend_always_inline bool zend_string_starts_with(const zend_string *str, const zend_string *prefix)
385 {
386 return zend_string_starts_with_cstr(str, ZSTR_VAL(prefix), ZSTR_LEN(prefix));
387 }
388
389 #define zend_string_starts_with_literal(str, prefix) \
390 zend_string_starts_with_cstr(str, prefix, strlen(prefix))
391
392 /*
393 * DJBX33A (Daniel J. Bernstein, Times 33 with Addition)
394 *
395 * This is Daniel J. Bernstein's popular `times 33' hash function as
396 * posted by him years ago on comp.lang.c. It basically uses a function
397 * like ``hash(i) = hash(i-1) * 33 + str[i]''. This is one of the best
398 * known hash functions for strings. Because it is both computed very
399 * fast and distributes very well.
400 *
401 * The magic of number 33, i.e. why it works better than many other
402 * constants, prime or not, has never been adequately explained by
403 * anyone. So I try an explanation: if one experimentally tests all
404 * multipliers between 1 and 256 (as RSE did now) one detects that even
405 * numbers are not usable at all. The remaining 128 odd numbers
406 * (except for the number 1) work more or less all equally well. They
407 * all distribute in an acceptable way and this way fill a hash table
408 * with an average percent of approx. 86%.
409 *
410 * If one compares the Chi^2 values of the variants, the number 33 not
411 * even has the best value. But the number 33 and a few other equally
412 * good numbers like 17, 31, 63, 127 and 129 have nevertheless a great
413 * advantage to the remaining numbers in the large set of possible
414 * multipliers: their multiply operation can be replaced by a faster
415 * operation based on just one shift plus either a single addition
416 * or subtraction operation. And because a hash function has to both
417 * distribute good _and_ has to be very fast to compute, those few
418 * numbers should be preferred and seems to be the reason why Daniel J.
419 * Bernstein also preferred it.
420 *
421 *
422 * -- Ralf S. Engelschall <rse@engelschall.com>
423 */
424
zend_inline_hash_func(const char * str,size_t len)425 static zend_always_inline zend_ulong zend_inline_hash_func(const char *str, size_t len)
426 {
427 zend_ulong hash = Z_UL(5381);
428
429 #if defined(_WIN32) || defined(__i386__) || defined(__x86_64__) || defined(__aarch64__)
430 /* Version with multiplication works better on modern CPU */
431 for (; len >= 8; len -= 8, str += 8) {
432 # if defined(__aarch64__) && !defined(WORDS_BIGENDIAN)
433 /* On some architectures it is beneficial to load 8 bytes at a
434 time and extract each byte with a bit field extract instr. */
435 uint64_t chunk;
436
437 memcpy(&chunk, str, sizeof(chunk));
438 hash =
439 hash * 33 * 33 * 33 * 33 +
440 ((chunk >> (8 * 0)) & 0xff) * 33 * 33 * 33 +
441 ((chunk >> (8 * 1)) & 0xff) * 33 * 33 +
442 ((chunk >> (8 * 2)) & 0xff) * 33 +
443 ((chunk >> (8 * 3)) & 0xff);
444 hash =
445 hash * 33 * 33 * 33 * 33 +
446 ((chunk >> (8 * 4)) & 0xff) * 33 * 33 * 33 +
447 ((chunk >> (8 * 5)) & 0xff) * 33 * 33 +
448 ((chunk >> (8 * 6)) & 0xff) * 33 +
449 ((chunk >> (8 * 7)) & 0xff);
450 # else
451 hash =
452 hash * Z_L(33 * 33 * 33 * 33) +
453 str[0] * Z_L(33 * 33 * 33) +
454 str[1] * Z_L(33 * 33) +
455 str[2] * Z_L(33) +
456 str[3];
457 hash =
458 hash * Z_L(33 * 33 * 33 * 33) +
459 str[4] * Z_L(33 * 33 * 33) +
460 str[5] * Z_L(33 * 33) +
461 str[6] * Z_L(33) +
462 str[7];
463 # endif
464 }
465 if (len >= 4) {
466 hash =
467 hash * Z_L(33 * 33 * 33 * 33) +
468 str[0] * Z_L(33 * 33 * 33) +
469 str[1] * Z_L(33 * 33) +
470 str[2] * Z_L(33) +
471 str[3];
472 len -= 4;
473 str += 4;
474 }
475 if (len >= 2) {
476 if (len > 2) {
477 hash =
478 hash * Z_L(33 * 33 * 33) +
479 str[0] * Z_L(33 * 33) +
480 str[1] * Z_L(33) +
481 str[2];
482 } else {
483 hash =
484 hash * Z_L(33 * 33) +
485 str[0] * Z_L(33) +
486 str[1];
487 }
488 } else if (len != 0) {
489 hash = hash * Z_L(33) + *str;
490 }
491 #else
492 /* variant with the hash unrolled eight times */
493 for (; len >= 8; len -= 8) {
494 hash = ((hash << 5) + hash) + *str++;
495 hash = ((hash << 5) + hash) + *str++;
496 hash = ((hash << 5) + hash) + *str++;
497 hash = ((hash << 5) + hash) + *str++;
498 hash = ((hash << 5) + hash) + *str++;
499 hash = ((hash << 5) + hash) + *str++;
500 hash = ((hash << 5) + hash) + *str++;
501 hash = ((hash << 5) + hash) + *str++;
502 }
503 switch (len) {
504 case 7: hash = ((hash << 5) + hash) + *str++; /* fallthrough... */
505 case 6: hash = ((hash << 5) + hash) + *str++; /* fallthrough... */
506 case 5: hash = ((hash << 5) + hash) + *str++; /* fallthrough... */
507 case 4: hash = ((hash << 5) + hash) + *str++; /* fallthrough... */
508 case 3: hash = ((hash << 5) + hash) + *str++; /* fallthrough... */
509 case 2: hash = ((hash << 5) + hash) + *str++; /* fallthrough... */
510 case 1: hash = ((hash << 5) + hash) + *str++; break;
511 case 0: break;
512 EMPTY_SWITCH_DEFAULT_CASE()
513 }
514 #endif
515
516 /* Hash value can't be zero, so we always set the high bit */
517 #if SIZEOF_ZEND_LONG == 8
518 return hash | Z_UL(0x8000000000000000);
519 #elif SIZEOF_ZEND_LONG == 4
520 return hash | Z_UL(0x80000000);
521 #else
522 # error "Unknown SIZEOF_ZEND_LONG"
523 #endif
524 }
525
526 #define ZEND_KNOWN_STRINGS(_) \
527 _(ZEND_STR_FILE, "file") \
528 _(ZEND_STR_LINE, "line") \
529 _(ZEND_STR_FUNCTION, "function") \
530 _(ZEND_STR_CLASS, "class") \
531 _(ZEND_STR_OBJECT, "object") \
532 _(ZEND_STR_TYPE, "type") \
533 _(ZEND_STR_OBJECT_OPERATOR, "->") \
534 _(ZEND_STR_PAAMAYIM_NEKUDOTAYIM, "::") \
535 _(ZEND_STR_ARGS, "args") \
536 _(ZEND_STR_UNKNOWN, "unknown") \
537 _(ZEND_STR_UNKNOWN_CAPITALIZED, "Unknown") \
538 _(ZEND_STR_EVAL, "eval") \
539 _(ZEND_STR_INCLUDE, "include") \
540 _(ZEND_STR_REQUIRE, "require") \
541 _(ZEND_STR_INCLUDE_ONCE, "include_once") \
542 _(ZEND_STR_REQUIRE_ONCE, "require_once") \
543 _(ZEND_STR_SCALAR, "scalar") \
544 _(ZEND_STR_ERROR_REPORTING, "error_reporting") \
545 _(ZEND_STR_STATIC, "static") \
546 _(ZEND_STR_THIS, "this") \
547 _(ZEND_STR_VALUE, "value") \
548 _(ZEND_STR_KEY, "key") \
549 _(ZEND_STR_MAGIC_INVOKE, "__invoke") \
550 _(ZEND_STR_PREVIOUS, "previous") \
551 _(ZEND_STR_CODE, "code") \
552 _(ZEND_STR_MESSAGE, "message") \
553 _(ZEND_STR_SEVERITY, "severity") \
554 _(ZEND_STR_STRING, "string") \
555 _(ZEND_STR_TRACE, "trace") \
556 _(ZEND_STR_SCHEME, "scheme") \
557 _(ZEND_STR_HOST, "host") \
558 _(ZEND_STR_PORT, "port") \
559 _(ZEND_STR_USER, "user") \
560 _(ZEND_STR_PASS, "pass") \
561 _(ZEND_STR_PATH, "path") \
562 _(ZEND_STR_QUERY, "query") \
563 _(ZEND_STR_FRAGMENT, "fragment") \
564 _(ZEND_STR_NULL, "NULL") \
565 _(ZEND_STR_BOOLEAN, "boolean") \
566 _(ZEND_STR_INTEGER, "integer") \
567 _(ZEND_STR_DOUBLE, "double") \
568 _(ZEND_STR_ARRAY, "array") \
569 _(ZEND_STR_RESOURCE, "resource") \
570 _(ZEND_STR_CLOSED_RESOURCE, "resource (closed)") \
571 _(ZEND_STR_NAME, "name") \
572 _(ZEND_STR_ARGV, "argv") \
573 _(ZEND_STR_ARGC, "argc") \
574 _(ZEND_STR_ARRAY_CAPITALIZED, "Array") \
575 _(ZEND_STR_BOOL, "bool") \
576 _(ZEND_STR_INT, "int") \
577 _(ZEND_STR_FLOAT, "float") \
578 _(ZEND_STR_CALLABLE, "callable") \
579 _(ZEND_STR_ITERABLE, "iterable") \
580 _(ZEND_STR_VOID, "void") \
581 _(ZEND_STR_NEVER, "never") \
582 _(ZEND_STR_FALSE, "false") \
583 _(ZEND_STR_TRUE, "true") \
584 _(ZEND_STR_NULL_LOWERCASE, "null") \
585 _(ZEND_STR_MIXED, "mixed") \
586 _(ZEND_STR_TRAVERSABLE, "Traversable") \
587 _(ZEND_STR_SLEEP, "__sleep") \
588 _(ZEND_STR_WAKEUP, "__wakeup") \
589 _(ZEND_STR_CASES, "cases") \
590 _(ZEND_STR_FROM, "from") \
591 _(ZEND_STR_TRYFROM, "tryFrom") \
592 _(ZEND_STR_TRYFROM_LOWERCASE, "tryfrom") \
593 _(ZEND_STR_AUTOGLOBAL_SERVER, "_SERVER") \
594 _(ZEND_STR_AUTOGLOBAL_ENV, "_ENV") \
595 _(ZEND_STR_AUTOGLOBAL_REQUEST, "_REQUEST") \
596 _(ZEND_STR_COUNT, "count") \
597 _(ZEND_STR_SENSITIVEPARAMETER, "SensitiveParameter") \
598
599
600 typedef enum _zend_known_string_id {
601 #define _ZEND_STR_ID(id, str) id,
602 ZEND_KNOWN_STRINGS(_ZEND_STR_ID)
603 #undef _ZEND_STR_ID
604 ZEND_STR_LAST_KNOWN
605 } zend_known_string_id;
606
607 #endif /* ZEND_STRING_H */
608