This source file includes following definitions.
- _str_erealloc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #ifndef ZEND_STRING_H
22 #define ZEND_STRING_H
23
24 #include "zend.h"
25
26 BEGIN_EXTERN_C()
27 ZEND_API extern const char *(*zend_new_interned_string)(const char *str, int len, int free_src TSRMLS_DC);
28 ZEND_API extern void (*zend_interned_strings_snapshot)(TSRMLS_D);
29 ZEND_API extern void (*zend_interned_strings_restore)(TSRMLS_D);
30
31 void zend_interned_strings_init(TSRMLS_D);
32 void zend_interned_strings_dtor(TSRMLS_D);
33 END_EXTERN_C()
34
35 #ifndef ZTS
36
37 #define IS_INTERNED(s) \
38 (((s) >= CG(interned_strings_start)) && ((s) < CG(interned_strings_end)))
39
40 #else
41
42 #define IS_INTERNED(s) \
43 (0)
44
45 #endif
46
47 #define INTERNED_LEN(s) \
48 (((Bucket*)(((char*)(s))-sizeof(Bucket)))->nKeyLength)
49
50 #define INTERNED_HASH(s) \
51 (((Bucket*)(((char*)(s))-sizeof(Bucket)))->h)
52
53 #define str_efree(s) do { \
54 if (!IS_INTERNED(s)) { \
55 efree((char*)s); \
56 } \
57 } while (0)
58
59 #define str_efree_rel(s) do { \
60 if (!IS_INTERNED(s)) { \
61 efree_rel((char *)s); \
62 } \
63 } while (0)
64
65 #define str_free(s) do { \
66 if (!IS_INTERNED(s)) { \
67 free((char*)s); \
68 } \
69 } while (0)
70
71 #define str_erealloc(str, new_len) \
72 (IS_INTERNED(str) \
73 ? _str_erealloc(str, new_len, INTERNED_LEN(str)) \
74 : erealloc(str, new_len))
75
76 static inline char *_str_erealloc(char *str, size_t new_len, size_t old_len) {
77 char *buf = (char *) emalloc(new_len);
78 memcpy(buf, str, old_len);
79 return buf;
80 }
81
82 #define str_estrndup(str, len) \
83 (IS_INTERNED(str) ? (str) : estrndup((str), (len)))
84
85 #define str_strndup(str, len) \
86 (IS_INTERNED(str) ? (str) : zend_strndup((str), (len)));
87
88 #define str_hash(str, len) \
89 (IS_INTERNED(str) ? INTERNED_HASH(str) : zend_hash_func((str), (len)+1))
90
91
92 #endif
93
94
95
96
97
98
99
100