Skip to content

Commit 969a472

Browse files
committed
Automatically handle ZEND_ACC_MAY_BE_CYCLIC for extensions
If get_gc is customized, assume cyclic classes for now.
1 parent f6e49bb commit 969a472

File tree

22 files changed

+17
-49
lines changed

22 files changed

+17
-49
lines changed

Zend/zend_API.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2390,6 +2390,8 @@ ZEND_API zend_result zend_startup_module_ex(zend_module_entry *module) /* {{{ */
23902390
}
23912391
module->module_started = 1;
23922392

2393+
uint32_t prev_class_count = zend_hash_num_elements(CG(class_table));
2394+
23932395
/* Check module dependencies */
23942396
if (module->deps) {
23952397
const zend_module_dep *dep = module->deps;
@@ -2434,6 +2436,19 @@ ZEND_API zend_result zend_startup_module_ex(zend_module_entry *module) /* {{{ */
24342436
}
24352437
EG(current_module) = NULL;
24362438
}
2439+
2440+
/* Mark classes with custom get_gc handler as potentially cyclic, even if
2441+
* their properties don't indicate so. */
2442+
if (prev_class_count != zend_hash_num_elements(CG(class_table))) {
2443+
Bucket *p;
2444+
ZEND_HASH_MAP_FOREACH_BUCKET_FROM(CG(class_table), p, prev_class_count) {
2445+
zend_class_entry *ce = Z_PTR(p->val);
2446+
if (ce->default_object_handlers->get_gc != zend_std_get_gc) {
2447+
ce->ce_flags |= ZEND_ACC_MAY_BE_CYCLIC;
2448+
}
2449+
} ZEND_HASH_FOREACH_END();
2450+
}
2451+
24372452
return SUCCESS;
24382453
}
24392454
/* }}} */

Zend/zend_closures.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -705,9 +705,8 @@ void zend_register_closure_ce(void) /* {{{ */
705705
zend_ce_closure = register_class_Closure();
706706
zend_ce_closure->create_object = zend_closure_new;
707707
zend_ce_closure->default_object_handlers = &closure_handlers;
708-
/* FIXME: Potentially improve during construction of closure? static closures
709-
* not binding by references can't be cyclic. */
710-
zend_ce_closure->ce_flags |= ZEND_ACC_MAY_BE_CYCLIC;
708+
/* FIXME: Potentially infer ZEND_ACC_MAY_BE_CYCLIC during construction of
709+
* closure? static closures not binding by references can't be cyclic. */
711710

712711
memcpy(&closure_handlers, &std_object_handlers, sizeof(zend_object_handlers));
713712
closure_handlers.free_obj = zend_closure_free_storage;

Zend/zend_fibers.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,6 @@ void zend_register_fiber_ce(void)
11071107
zend_ce_fiber = register_class_Fiber();
11081108
zend_ce_fiber->create_object = zend_fiber_object_create;
11091109
zend_ce_fiber->default_object_handlers = &zend_fiber_handlers;
1110-
zend_ce_fiber->ce_flags |= ZEND_ACC_MAY_BE_CYCLIC;
11111110

11121111
zend_fiber_handlers = std_object_handlers;
11131112
zend_fiber_handlers.dtor_obj = zend_fiber_object_destroy;

Zend/zend_generators.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,6 @@ void zend_register_generator_ce(void) /* {{{ */
12151215
/* get_iterator has to be assigned *after* implementing the interface */
12161216
zend_ce_generator->get_iterator = zend_generator_get_iterator;
12171217
zend_ce_generator->default_object_handlers = &zend_generator_handlers;
1218-
zend_ce_generator->ce_flags |= ZEND_ACC_MAY_BE_CYCLIC;
12191218

12201219
memcpy(&zend_generator_handlers, &std_object_handlers, sizeof(zend_object_handlers));
12211220
zend_generator_handlers.free_obj = zend_generator_free_storage;

Zend/zend_weakrefs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,6 @@ void zend_register_weakref_ce(void) /* {{{ */
788788
zend_ce_weakmap->create_object = zend_weakmap_create_object;
789789
zend_ce_weakmap->get_iterator = zend_weakmap_get_iterator;
790790
zend_ce_weakmap->default_object_handlers = &zend_weakmap_handlers;
791-
zend_ce_weakmap->ce_flags |= ZEND_ACC_MAY_BE_CYCLIC;
792791

793792
memcpy(&zend_weakmap_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
794793
zend_weakmap_handlers.offset = XtOffsetOf(zend_weakmap, std);

ext/curl/interface.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,6 @@ PHP_MINIT_FUNCTION(curl)
395395
curl_ce = register_class_CurlHandle();
396396
curl_ce->create_object = curl_create_object;
397397
curl_ce->default_object_handlers = &curl_object_handlers;
398-
curl_ce->ce_flags |= ZEND_ACC_MAY_BE_CYCLIC;
399398

400399
memcpy(&curl_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
401400
curl_object_handlers.offset = XtOffsetOf(php_curl, std);

ext/curl/multi.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,6 @@ static zend_object_handlers curl_multi_handlers;
606606
void curl_multi_register_handlers(void) {
607607
curl_multi_ce->create_object = curl_multi_create_object;
608608
curl_multi_ce->default_object_handlers = &curl_multi_handlers;
609-
curl_multi_ce->ce_flags |= ZEND_ACC_MAY_BE_CYCLIC;
610609

611610
memcpy(&curl_multi_handlers, &std_object_handlers, sizeof(zend_object_handlers));
612611
curl_multi_handlers.offset = XtOffsetOf(php_curlm, std);

ext/dom/php_dom.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,6 @@ PHP_MINIT_FUNCTION(dom)
12921292
dom_xpath_class_entry = register_class_DOMXPath();
12931293
dom_xpath_class_entry->create_object = dom_xpath_objects_new;
12941294
dom_xpath_class_entry->default_object_handlers = &dom_xpath_object_handlers;
1295-
dom_xpath_class_entry->ce_flags |= ZEND_ACC_MAY_BE_CYCLIC;
12961295

12971296
zend_hash_init(&dom_xpath_prop_handlers, 0, NULL, NULL, true);
12981297
DOM_REGISTER_PROP_HANDLER(&dom_xpath_prop_handlers, "document", dom_xpath_document_read, NULL);
@@ -1302,7 +1301,6 @@ PHP_MINIT_FUNCTION(dom)
13021301
dom_modern_xpath_class_entry = register_class_Dom_XPath();
13031302
dom_modern_xpath_class_entry->create_object = dom_xpath_objects_new;
13041303
dom_modern_xpath_class_entry->default_object_handlers = &dom_xpath_object_handlers;
1305-
dom_modern_xpath_class_entry->ce_flags |= ZEND_ACC_MAY_BE_CYCLIC;
13061304

13071305
zend_hash_add_new_ptr(&classes, dom_modern_xpath_class_entry->name, &dom_xpath_prop_handlers);
13081306
#endif

ext/pdo/pdo_dbh.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,6 @@ void pdo_dbh_init(int module_number)
14491449
pdo_dbh_ce = register_class_PDO();
14501450
pdo_dbh_ce->create_object = pdo_dbh_new;
14511451
pdo_dbh_ce->default_object_handlers = &pdo_dbh_object_handlers;
1452-
pdo_dbh_ce->ce_flags |= ZEND_ACC_MAY_BE_CYCLIC;
14531452

14541453
memcpy(&pdo_dbh_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
14551454
pdo_dbh_object_handlers.offset = XtOffsetOf(pdo_dbh_object_t, std);

ext/pdo/pdo_stmt.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2491,7 +2491,6 @@ void pdo_stmt_init(void)
24912491
pdo_dbstmt_ce->get_iterator = pdo_stmt_iter_get;
24922492
pdo_dbstmt_ce->create_object = pdo_dbstmt_new;
24932493
pdo_dbstmt_ce->default_object_handlers = &pdo_dbstmt_object_handlers;
2494-
pdo_dbstmt_ce->ce_flags |= ZEND_ACC_MAY_BE_CYCLIC;
24952494

24962495
memcpy(&pdo_dbstmt_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
24972496
pdo_dbstmt_object_handlers.offset = XtOffsetOf(pdo_stmt_t, std);

0 commit comments

Comments
 (0)