Skip to content

Commit 92fedbd

Browse files
committed
Fix a bunch of issues, clean up keys and hashtables
1 parent 8319b0c commit 92fedbd

File tree

1 file changed

+26
-33
lines changed

1 file changed

+26
-33
lines changed

Zend/zend_autoload.c

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -109,38 +109,12 @@ void* zend_autoload_call(zend_string *name, zend_string *lname, long type)
109109
return zend_hash_find_ptr(symbol_table, lname);
110110
}
111111

112-
static zend_string* zend_autoload_get_key(zend_fcall_info *fci)
113-
{
114-
switch (Z_TYPE(fci->function_name)) {
115-
case IS_STRING: {
116-
zend_string *ret = Z_STR(fci->function_name);
117-
zend_string_addref(ret);
118-
return ret;
119-
}
120-
case IS_OBJECT: {
121-
char handle[16];
122-
sprintf(handle, "%lu", (unsigned long) Z_OBJ_HANDLE(fci->function_name));
123-
return zend_string_init(handle, sizeof(uint32_t), 0);
124-
}
125-
}
126-
return NULL;
127-
}
128-
129-
130112
int zend_autoload_register(zend_autoload_func* func, zend_bool prepend)
131113
{
132-
zend_string *key;
133114

134-
key = zend_autoload_get_key(&func->fci);
135-
if (key == NULL) {
136-
zend_error_noreturn(E_ERROR, "Unknown function type provided");
137-
}
138-
139-
if (zend_hash_add_ptr(&EG(autoload.functions), key, func) == NULL) {
140-
zend_string_release(key);
115+
if (zend_hash_next_index_insert_ptr(&EG(autoload.functions), func) == NULL) {
141116
return FAILURE;
142117
}
143-
zend_string_release(key);
144118

145119
if (prepend) {
146120
HT_MOVE_TAIL_TO_HEAD(&EG(autoload.functions));
@@ -150,15 +124,34 @@ int zend_autoload_register(zend_autoload_func* func, zend_bool prepend)
150124

151125
int zend_autoload_unregister(zend_autoload_func* func)
152126
{
153-
zend_string *key;
127+
zval *val;
128+
zend_ulong h;
154129

155-
key = zend_autoload_get_key(&func->fci);
130+
zval func_name = func->fci.function_name;
131+
zval current;
156132

157-
zend_hash_del(&EG(autoload.functions), key);
158-
159-
zend_string_release(key);
133+
ZEND_HASH_FOREACH_NUM_KEY_VAL(&EG(autoload.functions), h, val)
134+
current = ((zend_autoload_func*) Z_PTR_P(val))->fci.function_name;
135+
if (Z_TYPE(func_name) != Z_TYPE(current)) {
136+
continue;
137+
}
138+
switch (Z_TYPE(func_name)) {
139+
case IS_STRING:
140+
if (zend_string_equals(Z_STR(func_name), Z_STR(current))) {
141+
// unset this one
142+
zend_hash_index_del(&EG(autoload.functions), h);
143+
return SUCCESS;
144+
}
145+
case IS_OBJECT:
146+
if (Z_OBJ_HANDLE(current) == Z_OBJ_HANDLE(func_name)) {
147+
// unset this one
148+
zend_hash_index_del(&EG(autoload.functions), h);
149+
return SUCCESS;
150+
}
151+
}
152+
ZEND_HASH_FOREACH_END();
160153

161-
return SUCCESS;
154+
return FAILURE;
162155
}
163156

164157
void zend_autoload_dtor(zval *pzv)

0 commit comments

Comments
 (0)