|
22 | 22 | #include "zend_enum_arginfo.h" |
23 | 23 | #include "zend_interfaces.h" |
24 | 24 | #include "zend_enum.h" |
| 25 | +#include "zend_extensions.h" |
25 | 26 |
|
26 | 27 | #define ZEND_ENUM_DISALLOW_MAGIC_METHOD(propertyName, methodName) \ |
27 | 28 | do { \ |
@@ -401,59 +402,48 @@ static ZEND_NAMED_FUNCTION(zend_enum_try_from_func) |
401 | 402 | zend_enum_from_base(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); |
402 | 403 | } |
403 | 404 |
|
| 405 | +static void zend_enum_register_func(zend_class_entry *ce, zend_known_string_id name_id, zend_internal_function *zif) { |
| 406 | + zend_string *name = ZSTR_KNOWN(name_id); |
| 407 | + zif->type = ZEND_INTERNAL_FUNCTION; |
| 408 | + zif->module = EG(current_module); |
| 409 | + zif->scope = ce; |
| 410 | + ZEND_MAP_PTR_NEW(zif->run_time_cache); |
| 411 | + ZEND_MAP_PTR_SET(zif->run_time_cache, zend_arena_alloc(&CG(arena), zend_internal_run_time_cache_reserved_size())); |
| 412 | + |
| 413 | + if (!zend_hash_add_ptr(&ce->function_table, name, zif)) { |
| 414 | + zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare %s::%s()", ZSTR_VAL(ce->name), ZSTR_VAL(name)); |
| 415 | + } |
| 416 | +} |
| 417 | + |
404 | 418 | void zend_enum_register_funcs(zend_class_entry *ce) |
405 | 419 | { |
406 | 420 | const uint32_t fn_flags = |
407 | 421 | ZEND_ACC_PUBLIC|ZEND_ACC_STATIC|ZEND_ACC_HAS_RETURN_TYPE|ZEND_ACC_ARENA_ALLOCATED; |
408 | | - zend_internal_function *cases_function = |
409 | | - zend_arena_alloc(&CG(arena), sizeof(zend_internal_function)); |
410 | | - memset(cases_function, 0, sizeof(zend_internal_function)); |
411 | | - cases_function->type = ZEND_INTERNAL_FUNCTION; |
412 | | - cases_function->module = EG(current_module); |
| 422 | + zend_internal_function *cases_function = zend_arena_calloc(&CG(arena), sizeof(zend_internal_function), 1); |
413 | 423 | cases_function->handler = zend_enum_cases_func; |
414 | 424 | cases_function->function_name = ZSTR_KNOWN(ZEND_STR_CASES); |
415 | | - cases_function->scope = ce; |
416 | 425 | cases_function->fn_flags = fn_flags; |
417 | 426 | cases_function->arg_info = (zend_internal_arg_info *) (arginfo_class_UnitEnum_cases + 1); |
418 | | - if (!zend_hash_add_ptr(&ce->function_table, ZSTR_KNOWN(ZEND_STR_CASES), cases_function)) { |
419 | | - zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare %s::cases()", ZSTR_VAL(ce->name)); |
420 | | - } |
| 427 | + zend_enum_register_func(ce, ZEND_STR_CASES, cases_function); |
421 | 428 |
|
422 | 429 | if (ce->enum_backing_type != IS_UNDEF) { |
423 | | - zend_internal_function *from_function = |
424 | | - zend_arena_alloc(&CG(arena), sizeof(zend_internal_function)); |
425 | | - memset(from_function, 0, sizeof(zend_internal_function)); |
426 | | - from_function->type = ZEND_INTERNAL_FUNCTION; |
427 | | - from_function->module = EG(current_module); |
| 430 | + zend_internal_function *from_function = zend_arena_calloc(&CG(arena), sizeof(zend_internal_function), 1); |
428 | 431 | from_function->handler = zend_enum_from_func; |
429 | 432 | from_function->function_name = ZSTR_KNOWN(ZEND_STR_FROM); |
430 | | - from_function->scope = ce; |
431 | 433 | from_function->fn_flags = fn_flags; |
432 | 434 | from_function->num_args = 1; |
433 | 435 | from_function->required_num_args = 1; |
434 | 436 | from_function->arg_info = (zend_internal_arg_info *) (arginfo_class_BackedEnum_from + 1); |
435 | | - if (!zend_hash_add_ptr(&ce->function_table, ZSTR_KNOWN(ZEND_STR_FROM), from_function)) { |
436 | | - zend_error_noreturn(E_COMPILE_ERROR, |
437 | | - "Cannot redeclare %s::from()", ZSTR_VAL(ce->name)); |
438 | | - } |
| 437 | + zend_enum_register_func(ce, ZEND_STR_FROM, from_function); |
439 | 438 |
|
440 | | - zend_internal_function *try_from_function = |
441 | | - zend_arena_alloc(&CG(arena), sizeof(zend_internal_function)); |
442 | | - memset(try_from_function, 0, sizeof(zend_internal_function)); |
443 | | - try_from_function->type = ZEND_INTERNAL_FUNCTION; |
444 | | - try_from_function->module = EG(current_module); |
| 439 | + zend_internal_function *try_from_function = zend_arena_calloc(&CG(arena), sizeof(zend_internal_function), 1); |
445 | 440 | try_from_function->handler = zend_enum_try_from_func; |
446 | 441 | try_from_function->function_name = ZSTR_KNOWN(ZEND_STR_TRYFROM); |
447 | | - try_from_function->scope = ce; |
448 | 442 | try_from_function->fn_flags = fn_flags; |
449 | 443 | try_from_function->num_args = 1; |
450 | 444 | try_from_function->required_num_args = 1; |
451 | 445 | try_from_function->arg_info = (zend_internal_arg_info *) (arginfo_class_BackedEnum_tryFrom + 1); |
452 | | - if (!zend_hash_add_ptr( |
453 | | - &ce->function_table, ZSTR_KNOWN(ZEND_STR_TRYFROM_LOWERCASE), try_from_function)) { |
454 | | - zend_error_noreturn(E_COMPILE_ERROR, |
455 | | - "Cannot redeclare %s::tryFrom()", ZSTR_VAL(ce->name)); |
456 | | - } |
| 446 | + zend_enum_register_func(ce, ZEND_STR_TRYFROM_LOWERCASE, try_from_function); |
457 | 447 | } |
458 | 448 | } |
459 | 449 |
|
|
0 commit comments