Skip to content

Commit 6ce7044

Browse files
committed
Generate zend class entries based on stubs
Closes GH-6685
1 parent 31088ee commit 6ce7044

15 files changed

+172
-68
lines changed

Zend/zend_attributes.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,12 @@ ZEND_API zend_internal_attribute *zend_internal_attribute_get(zend_string *lcnam
263263
void zend_register_attribute_ce(void)
264264
{
265265
zend_internal_attribute *attr;
266-
zend_class_entry ce;
267-
zend_string *str;
268-
zval tmp;
269266

270267
zend_hash_init(&internal_attributes, 8, NULL, free_internal_attribute, 1);
271268

272-
INIT_CLASS_ENTRY(ce, "Attribute", class_Attribute_methods);
273-
zend_ce_attribute = zend_register_internal_class(&ce);
274-
zend_ce_attribute->ce_flags |= ZEND_ACC_FINAL;
269+
zend_ce_attribute = register_class_Attribute();
270+
attr = zend_internal_attribute_register(zend_ce_attribute, ZEND_ATTRIBUTE_TARGET_CLASS);
271+
attr->validator = validate_attribute;
275272

276273
zend_declare_class_constant_long(zend_ce_attribute, ZEND_STRL("TARGET_CLASS"), ZEND_ATTRIBUTE_TARGET_CLASS);
277274
zend_declare_class_constant_long(zend_ce_attribute, ZEND_STRL("TARGET_FUNCTION"), ZEND_ATTRIBUTE_TARGET_FUNCTION);
@@ -281,14 +278,6 @@ void zend_register_attribute_ce(void)
281278
zend_declare_class_constant_long(zend_ce_attribute, ZEND_STRL("TARGET_PARAMETER"), ZEND_ATTRIBUTE_TARGET_PARAMETER);
282279
zend_declare_class_constant_long(zend_ce_attribute, ZEND_STRL("TARGET_ALL"), ZEND_ATTRIBUTE_TARGET_ALL);
283280
zend_declare_class_constant_long(zend_ce_attribute, ZEND_STRL("IS_REPEATABLE"), ZEND_ATTRIBUTE_IS_REPEATABLE);
284-
285-
ZVAL_UNDEF(&tmp);
286-
str = zend_string_init(ZEND_STRL("flags"), 1);
287-
zend_declare_typed_property(zend_ce_attribute, str, &tmp, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_CODE(IS_LONG, 0, 0));
288-
zend_string_release(str);
289-
290-
attr = zend_internal_attribute_register(zend_ce_attribute, ZEND_ATTRIBUTE_TARGET_CLASS);
291-
attr->validator = validate_attribute;
292281
}
293282

294283
void zend_attributes_shutdown(void)

Zend/zend_attributes.stub.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
22

3-
/** @generate-function-entries */
3+
/** @generate-class-entries */
44

55
final class Attribute
66
{
7+
public int $flags;
8+
79
public function __construct(int $flags = Attribute::TARGET_ALL) {}
810
}

Zend/zend_attributes_arginfo.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 54eede8541597ec2ac5c04e31d14e2db7e8c5556 */
2+
* Stub hash: 0183e750e66999862a7688ecb251017110d06d1f */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Attribute___construct, 0, 0, 0)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "Attribute::TARGET_ALL")
@@ -13,3 +13,21 @@ static const zend_function_entry class_Attribute_methods[] = {
1313
ZEND_ME(Attribute, __construct, arginfo_class_Attribute___construct, ZEND_ACC_PUBLIC)
1414
ZEND_FE_END
1515
};
16+
17+
zend_class_entry *register_class_Attribute()
18+
{
19+
zend_class_entry ce, *class_entry;
20+
21+
INIT_CLASS_ENTRY(ce, "Attribute", class_Attribute_methods);
22+
class_entry = zend_register_internal_class_ex(&ce, NULL);
23+
class_entry->ce_flags |= ZEND_ACC_FINAL;
24+
25+
zval property_flags_default_value;
26+
ZVAL_UNDEF(&property_flags_default_value);
27+
zend_string *property_flags_name = zend_string_init("flags", sizeof("flags") - 1, 1);
28+
zend_declare_typed_property(class_entry, property_flags_name, &property_flags_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
29+
zend_string_release(property_flags_name);
30+
31+
return class_entry;
32+
}
33+

Zend/zend_builtin_functions.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
/** @generate-function-entries */
3+
/** @generate-class-entries */
44

55
function zend_version(): string {}
66

Zend/zend_builtin_functions_arginfo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: b09e9199a21595a3b6f6c02db81c8e22c36c277f */
2+
* Stub hash: b2216a294367f50c8b6208653ebf6fa43dc106d1 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_version, 0, 0, IS_STRING, 0)
55
ZEND_END_ARG_INFO()
@@ -333,3 +333,4 @@ static const zend_function_entry ext_functions[] = {
333333
ZEND_FE(gc_status, arginfo_gc_status)
334334
ZEND_FE_END
335335
};
336+

Zend/zend_closures.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -629,11 +629,7 @@ ZEND_COLD ZEND_METHOD(Closure, __construct)
629629

630630
void zend_register_closure_ce(void) /* {{{ */
631631
{
632-
zend_class_entry ce;
633-
634-
INIT_CLASS_ENTRY(ce, "Closure", class_Closure_methods);
635-
zend_ce_closure = zend_register_internal_class(&ce);
636-
zend_ce_closure->ce_flags |= ZEND_ACC_FINAL;
632+
zend_ce_closure = register_class_Closure();
637633
zend_ce_closure->create_object = zend_closure_new;
638634
zend_ce_closure->serialize = zend_class_serialize_deny;
639635
zend_ce_closure->unserialize = zend_class_unserialize_deny;

Zend/zend_closures.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
/** @generate-function-entries */
3+
/** @generate-class-entries */
44

55
final class Closure
66
{

Zend/zend_closures_arginfo.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 0a2dd53716d30893aa5dd92a9907b2298abb3f70 */
2+
* Stub hash: 62da9b1e75331f30a0c63e82c9fd366e26b5724d */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Closure___construct, 0, 0, 0)
55
ZEND_END_ARG_INFO()
@@ -40,3 +40,15 @@ static const zend_function_entry class_Closure_methods[] = {
4040
ZEND_ME(Closure, fromCallable, arginfo_class_Closure_fromCallable, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
4141
ZEND_FE_END
4242
};
43+
44+
zend_class_entry *register_class_Closure()
45+
{
46+
zend_class_entry ce, *class_entry;
47+
48+
INIT_CLASS_ENTRY(ce, "Closure", class_Closure_methods);
49+
class_entry = zend_register_internal_class_ex(&ce, NULL);
50+
class_entry->ce_flags |= ZEND_ACC_FINAL;
51+
52+
return class_entry;
53+
}
54+

Zend/zend_interfaces.c

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -596,31 +596,25 @@ ZEND_METHOD(InternalIterator, rewind) {
596596
/* {{{ zend_register_interfaces */
597597
ZEND_API void zend_register_interfaces(void)
598598
{
599-
zend_class_entry ce;
599+
zend_ce_traversable = register_class_Traversable();
600+
zend_ce_traversable->interface_gets_implemented = zend_implement_traversable;
600601

601-
REGISTER_MAGIC_INTERFACE(traversable, Traversable);
602+
zend_ce_aggregate = register_class_IteratorAggregate(zend_ce_traversable);
603+
zend_ce_aggregate->interface_gets_implemented = zend_implement_aggregate;
602604

603-
REGISTER_MAGIC_INTERFACE(aggregate, IteratorAggregate);
604-
REGISTER_MAGIC_IMPLEMENT(aggregate, traversable);
605+
zend_ce_iterator = register_class_Iterator(zend_ce_traversable);
606+
zend_ce_iterator->interface_gets_implemented = zend_implement_iterator;
605607

606-
REGISTER_MAGIC_INTERFACE(iterator, Iterator);
607-
REGISTER_MAGIC_IMPLEMENT(iterator, traversable);
608+
zend_ce_serializable = register_class_Serializable();
609+
zend_ce_serializable->interface_gets_implemented = zend_implement_serializable;
608610

609-
REGISTER_MAGIC_INTERFACE(serializable, Serializable);
611+
zend_ce_arrayaccess = register_class_ArrayAccess();
610612

611-
INIT_CLASS_ENTRY(ce, "ArrayAccess", class_ArrayAccess_methods);
612-
zend_ce_arrayaccess = zend_register_internal_interface(&ce);
613+
zend_ce_countable = register_class_Countable();
613614

614-
INIT_CLASS_ENTRY(ce, "Countable", class_Countable_methods);
615-
zend_ce_countable = zend_register_internal_interface(&ce);
615+
zend_ce_stringable = register_class_Stringable();
616616

617-
INIT_CLASS_ENTRY(ce, "Stringable", class_Stringable_methods);
618-
zend_ce_stringable = zend_register_internal_interface(&ce);
619-
620-
INIT_CLASS_ENTRY(ce, "InternalIterator", class_InternalIterator_methods);
621-
zend_ce_internal_iterator = zend_register_internal_class(&ce);
622-
zend_class_implements(zend_ce_internal_iterator, 1, zend_ce_iterator);
623-
zend_ce_internal_iterator->ce_flags |= ZEND_ACC_FINAL;
617+
zend_ce_internal_iterator = register_class_InternalIterator(zend_ce_iterator);
624618
zend_ce_internal_iterator->create_object = zend_internal_iterator_create;
625619
zend_ce_internal_iterator->serialize = zend_class_serialize_deny;
626620
zend_ce_internal_iterator->unserialize = zend_class_unserialize_deny;

Zend/zend_interfaces.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,6 @@ ZEND_API zval* zend_call_method(zend_object *object, zend_class_entry *obj_ce, z
4949
#define zend_call_method_with_2_params(obj, obj_ce, fn_proxy, function_name, retval, arg1, arg2) \
5050
zend_call_method(obj, obj_ce, fn_proxy, function_name, sizeof(function_name)-1, retval, 2, arg1, arg2)
5151

52-
#define REGISTER_MAGIC_INTERFACE(class_name, class_name_str) \
53-
{\
54-
zend_class_entry ce;\
55-
INIT_CLASS_ENTRY(ce, # class_name_str, class_ ## class_name_str ## _methods) \
56-
zend_ce_ ## class_name = zend_register_internal_interface(&ce);\
57-
zend_ce_ ## class_name->interface_gets_implemented = zend_implement_ ## class_name;\
58-
}
59-
60-
#define REGISTER_MAGIC_IMPLEMENT(class_name, interface_name) \
61-
zend_class_implements(zend_ce_ ## class_name, 1, zend_ce_ ## interface_name)
62-
6352
ZEND_API void zend_user_it_rewind(zend_object_iterator *_iter);
6453
ZEND_API zend_result zend_user_it_valid(zend_object_iterator *_iter);
6554
ZEND_API void zend_user_it_get_current_key(zend_object_iterator *_iter, zval *key);

0 commit comments

Comments
 (0)