@@ -109,38 +109,12 @@ void* zend_autoload_call(zend_string *name, zend_string *lname, long type)
109
109
return zend_hash_find_ptr (symbol_table , lname );
110
110
}
111
111
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
-
130
112
int zend_autoload_register (zend_autoload_func * func , zend_bool prepend )
131
113
{
132
- zend_string * key ;
133
114
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 ) {
141
116
return FAILURE ;
142
117
}
143
- zend_string_release (key );
144
118
145
119
if (prepend ) {
146
120
HT_MOVE_TAIL_TO_HEAD (& EG (autoload .functions ));
@@ -150,15 +124,34 @@ int zend_autoload_register(zend_autoload_func* func, zend_bool prepend)
150
124
151
125
int zend_autoload_unregister (zend_autoload_func * func )
152
126
{
153
- zend_string * key ;
127
+ zval * val ;
128
+ zend_ulong h ;
154
129
155
- key = zend_autoload_get_key (& func -> fci );
130
+ zval func_name = func -> fci .function_name ;
131
+ zval current ;
156
132
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 ();
160
153
161
- return SUCCESS ;
154
+ return FAILURE ;
162
155
}
163
156
164
157
void zend_autoload_dtor (zval * pzv )
0 commit comments