Skip to content

Fix handling of nested generator in zend_test observer #16530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions Zend/tests/gh16514.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
--TEST--
GH-16514: Nested generator in zend_test observer
--INI--
zend_test.observer.enabled=1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved into zend_test

zend_test.observer.show_init_backtrace=1
--FILE--
<?php

class Foo {
public function __destruct() {
debug_print_backtrace();
}
}
function bar() {
yield from foo();
}
function foo() {
$foo = new Foo();
yield;
}
$gen = bar();
foreach ($gen as $dummy);

?>
--EXPECTF--
<!-- init '%sgh16514.php' -->
<!--
{main} %sgh16514.php
-->
<!-- init bar() -->
<!--
bar()
{main} %sgh16514.php
-->
<!-- init foo() -->
<!--
foo()
bar()
{main} %sgh16514.php
-->
<!-- init Foo::__destruct() -->
<!--
Foo::__destruct()
bar()
{main} %sgh16514.php
-->
<!-- init debug_print_backtrace() -->
<!--
debug_print_backtrace()
Foo::__destruct()
bar()
{main} %sgh16514.php
-->
#0 %s(%d): Foo->__destruct()
#1 %s(%d): bar()
6 changes: 6 additions & 0 deletions ext/zend_test/observer.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "zend_observer.h"
#include "zend_smart_str.h"
#include "ext/standard/php_var.h"
#include "zend_generators.h"

static zend_observer_fcall_handlers observer_fcall_init(zend_execute_data *execute_data);

Expand Down Expand Up @@ -163,6 +164,11 @@ static void observer_show_init_backtrace(zend_execute_data *execute_data)
zend_execute_data *ex = execute_data;
php_printf("%*s<!--\n", 2 * ZT_G(observer_nesting_depth), "");
do {
if (UNEXPECTED(!ex->func)) {
ex = zend_generator_check_placeholder_frame(ex);
ZEND_ASSERT(ex->func);
}

zend_function *fbc = ex->func;
int indent = 2 * ZT_G(observer_nesting_depth) + 4;
if (fbc->common.function_name) {
Expand Down
Loading