Skip to content

Commit ceba50b

Browse files
committed
- Fix a nasty bug in the hash, introduced in the recent migration to macros
- Make array_init() and friends trackable
1 parent eb9d799 commit ceba50b

File tree

4 files changed

+40
-13
lines changed

4 files changed

+40
-13
lines changed

Zend/zend_API.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ ZEND_API void wrong_param_count()
186186
}
187187

188188

189-
ZEND_API inline int array_init(zval *arg)
189+
ZEND_API inline int _array_init(zval *arg ZEND_FILE_LINE_DC)
190190
{
191-
ALLOC_HASHTABLE(arg->value.ht);
191+
ALLOC_HASHTABLE_REL(arg->value.ht);
192192

193193
if (!arg->value.ht || zend_hash_init(arg->value.ht, 0, NULL, ZVAL_PTR_DTOR, 0)) {
194194
zend_error(E_CORE_ERROR, "Cannot allocate memory for array");
@@ -199,7 +199,7 @@ ZEND_API inline int array_init(zval *arg)
199199
}
200200

201201

202-
ZEND_API inline int object_init_ex(zval *arg, zend_class_entry *class_type)
202+
ZEND_API inline int _object_init_ex(zval *arg, zend_class_entry *class_type ZEND_FILE_LINE_DC)
203203
{
204204
zval *tmp;
205205

@@ -208,7 +208,7 @@ ZEND_API inline int object_init_ex(zval *arg, zend_class_entry *class_type)
208208
class_type->constants_updated = 1;
209209
}
210210

211-
ALLOC_HASHTABLE(arg->value.obj.properties);
211+
ALLOC_HASHTABLE_REL(arg->value.obj.properties);
212212
zend_hash_init(arg->value.obj.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
213213
zend_hash_copy(arg->value.obj.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
214214
arg->type = IS_OBJECT;
@@ -217,9 +217,9 @@ ZEND_API inline int object_init_ex(zval *arg, zend_class_entry *class_type)
217217
}
218218

219219

220-
ZEND_API inline int object_init(zval *arg)
220+
ZEND_API inline int _object_init(zval *arg ZEND_FILE_LINE_DC)
221221
{
222-
return object_init_ex(arg, &zend_standard_class_def);
222+
return _object_init_ex(arg, &zend_standard_class_def ZEND_FILE_LINE_CC);
223223
}
224224

225225

Zend/zend_API.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,12 @@ ZEND_API void wrong_param_count(void);
9090

9191
ZEND_API int zend_startup_module(zend_module_entry *module);
9292

93-
ZEND_API int array_init(zval *arg);
94-
ZEND_API int object_init(zval *arg);
95-
ZEND_API int object_init_ex(zval *arg, zend_class_entry *ce);
93+
#define array_init(arg) _array_init((arg) ZEND_FILE_LINE_CC)
94+
#define object_init(arg) _object_init((arg) ZEND_FILE_LINE_CC)
95+
#define object_init_ex(arg, ce) _object_init_ex((arg), (ce) ZEND_FILE_LINE_CC)
96+
ZEND_API int _array_init(zval *arg ZEND_FILE_LINE_DC);
97+
ZEND_API int _object_init(zval *arg ZEND_FILE_LINE_DC);
98+
ZEND_API int _object_init_ex(zval *arg, zend_class_entry *ce ZEND_FILE_LINE_DC);
9699

97100
/* no longer supported */
98101
ZEND_API int add_assoc_function(zval *arg, char *key,void (*function_ptr)(INTERNAL_FUNCTION_PARAMETERS));

Zend/zend_fast_cache.h

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ typedef struct _zend_fast_cache_list_entry {
7878
AG(fast_cache_list_head)[fc_type] = (zend_fast_cache_list_entry *) (p); \
7979
}
8080

81+
#define ZEND_FAST_ALLOC_REL(p, type, fc_type) \
82+
ZEND_FAST_ALLOC(p, type, fc_type)
83+
84+
#define ZEND_FAST_FREE_REL(p, fc_type) \
85+
ZEND_FAST_FREE(p, fc_type)
86+
8187

8288
#else /* !ZEND_ENABLE_FAST_CACHE */
8389

@@ -87,6 +93,12 @@ typedef struct _zend_fast_cache_list_entry {
8793
#define ZEND_FAST_FREE(p, fc_type) \
8894
efree(p)
8995

96+
#define ZEND_FAST_ALLOC_REL(p, type, fc_type) \
97+
(p) = (type *) emalloc_rel(sizeof(type))
98+
99+
#define ZEND_FAST_FREE_REL(p, fc_type) \
100+
efree_rel(p)
101+
90102
#endif /* ZEND_ENABLE_FAST_CACHE */
91103

92104

@@ -99,13 +111,25 @@ typedef struct _zend_fast_cache_list_entry {
99111
#define FREE_ZVAL(z) \
100112
ZEND_FAST_FREE(z, ZVAL_CACHE_LIST)
101113

114+
#define ALLOC_ZVAL_REL(z) \
115+
ZEND_FAST_ALLOC_REL(z, zval, ZVAL_CACHE_LIST)
116+
117+
#define FREE_ZVAL_REL(z) \
118+
ZEND_FAST_FREE_REL(z, ZVAL_CACHE_LIST)
119+
102120
/* fast cache for HashTable's */
103-
#define ALLOC_HASHTABLE(b) \
104-
ZEND_FAST_ALLOC(b, HashTable, HASHTABLE_CACHE_LIST)
121+
#define ALLOC_HASHTABLE(ht) \
122+
ZEND_FAST_ALLOC(ht, HashTable, HASHTABLE_CACHE_LIST)
105123

106124
#define FREE_HASHTABLE(ht) \
107125
ZEND_FAST_FREE(ht, HASHTABLE_CACHE_LIST)
108126

127+
#define ALLOC_HASHTABLE_REL(ht) \
128+
ZEND_FAST_ALLOC_REL(ht, HashTable, HASHTABLE_CACHE_LIST)
129+
130+
#define FREE_HASHTABLE_REL(ht) \
131+
ZEND_FAST_FREE_REL(ht, HASHTABLE_CACHE_LIST)
132+
109133
#endif /* _ZEND_FAST_CACHE_H */
110134

111135
/*

Zend/zend_hash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
#define HT_OK 0
8585

8686
static void _zend_is_inconsistent(HashTable *ht, char *file, int line)
87-
{
87+
{
8888
switch (ht->inconsistent) {
8989
case HT_IS_DESTROYING:
9090
zend_error(E_CORE_ERROR, "ht=%08x is destroying in %s:%d", ht, file, line);
@@ -136,7 +136,7 @@ ZEND_API ulong hashpjw(char *arKey, uint nKeyLength)
136136
#define UPDATE_DATA(ht, p, pData, nDataSize) \
137137
if (flag & HASH_ADD_PTR) { \
138138
if (!(p)->pDataPtr) { \
139-
pefree(p, (ht)->persistent); \
139+
pefree((p)->pData, (ht)->persistent); \
140140
} \
141141
(p)->pDataPtr = pData; \
142142
(p)->pData = &(p)->pDataPtr; \

0 commit comments

Comments
 (0)