Skip to content

Commit 8cbfa65

Browse files
committed
Use common function for autoload_list functions
1 parent 695e05a commit 8cbfa65

File tree

1 file changed

+34
-56
lines changed

1 file changed

+34
-56
lines changed

Zend/zend_autoload.c

Lines changed: 34 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,38 @@ ZEND_API void zend_register_class_autoloader(zend_fcall_info *fci, zend_fcall_in
204204
}
205205

206206
// TODO USERLAND FUNCTIONS, maybe namespace them?
207+
static void autoload_list(INTERNAL_FUNCTION_PARAMETERS, HashTable *symbol_table)
208+
{
209+
zend_autoload_func *func_info;
210+
211+
if (zend_parse_parameters_none() == FAILURE) {
212+
RETURN_THROWS();
213+
}
214+
215+
array_init(return_value);
216+
217+
ZEND_HASH_FOREACH_PTR(symbol_table, func_info) {
218+
if (func_info->closure) {
219+
GC_ADDREF(func_info->closure);
220+
add_next_index_object(return_value, func_info->closure);
221+
} else if (func_info->fcc.function_handler->common.scope) {
222+
zval tmp;
223+
224+
array_init(&tmp);
225+
if (func_info->fcc.object) {
226+
GC_ADDREF(func_info->fcc.object);
227+
add_next_index_object(&tmp, func_info->fcc.object);
228+
} else {
229+
add_next_index_str(&tmp, zend_string_copy(func_info->fcc.calling_scope->name));
230+
}
231+
add_next_index_str(&tmp, zend_string_copy(func_info->fcc.function_handler->common.function_name));
232+
add_next_index_zval(return_value, &tmp);
233+
} else {
234+
add_next_index_str(return_value, zend_string_copy(func_info->fcc.function_handler->common.function_name));
235+
}
236+
} ZEND_HASH_FOREACH_END();
237+
}
238+
207239
/* Register given function as a class autoloader */
208240
ZEND_FUNCTION(autoload_register_class)
209241
{
@@ -270,34 +302,7 @@ ZEND_FUNCTION(autoload_call_class)
270302
/* Return all registered class autoloader functions */
271303
ZEND_FUNCTION(autoload_list_class)
272304
{
273-
zend_autoload_func *func_info;
274-
275-
if (zend_parse_parameters_none() == FAILURE) {
276-
RETURN_THROWS();
277-
}
278-
279-
array_init(return_value);
280-
281-
ZEND_HASH_FOREACH_PTR(&EG(autoloaders).class_autoload_functions, func_info) {
282-
if (func_info->closure) {
283-
GC_ADDREF(func_info->closure);
284-
add_next_index_object(return_value, func_info->closure);
285-
} else if (func_info->fcc.function_handler->common.scope) {
286-
zval tmp;
287-
288-
array_init(&tmp);
289-
if (func_info->fcc.object) {
290-
GC_ADDREF(func_info->fcc.object);
291-
add_next_index_object(&tmp, func_info->fcc.object);
292-
} else {
293-
add_next_index_str(&tmp, zend_string_copy(func_info->fcc.calling_scope->name));
294-
}
295-
add_next_index_str(&tmp, zend_string_copy(func_info->fcc.function_handler->common.function_name));
296-
add_next_index_zval(return_value, &tmp);
297-
} else {
298-
add_next_index_str(return_value, zend_string_copy(func_info->fcc.function_handler->common.function_name));
299-
}
300-
} ZEND_HASH_FOREACH_END();
305+
autoload_list(INTERNAL_FUNCTION_PARAM_PASSTHRU, &EG(autoloaders).class_autoload_functions);
301306
}
302307

303308
/* Register given function as a function autoloader */
@@ -386,34 +391,7 @@ ZEND_FUNCTION(autoload_call_function)
386391
/* Return all registered function autoloader functions */
387392
ZEND_FUNCTION(autoload_list_function)
388393
{
389-
zend_autoload_func *func_info;
390-
391-
if (zend_parse_parameters_none() == FAILURE) {
392-
RETURN_THROWS();
393-
}
394-
395-
array_init(return_value);
396-
397-
ZEND_HASH_FOREACH_PTR(&EG(autoloaders).function_autoload_functions, func_info) {
398-
if (func_info->closure) {
399-
GC_ADDREF(func_info->closure);
400-
add_next_index_object(return_value, func_info->closure);
401-
} else if (func_info->fcc.function_handler->common.scope) {
402-
zval tmp;
403-
404-
array_init(&tmp);
405-
if (func_info->fcc.object) {
406-
GC_ADDREF(func_info->fcc.object);
407-
add_next_index_object(&tmp, func_info->fcc.object);
408-
} else {
409-
add_next_index_str(&tmp, zend_string_copy(func_info->fcc.calling_scope->name));
410-
}
411-
add_next_index_str(&tmp, zend_string_copy(func_info->fcc.function_handler->common.function_name));
412-
add_next_index_zval(return_value, &tmp);
413-
} else {
414-
add_next_index_str(return_value, zend_string_copy(func_info->fcc.function_handler->common.function_name));
415-
}
416-
} ZEND_HASH_FOREACH_END();
394+
autoload_list(INTERNAL_FUNCTION_PARAM_PASSTHRU, &EG(autoloaders).function_autoload_functions);
417395
}
418396

419397
void zend_autoload_shutdown(void)

0 commit comments

Comments
 (0)