php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63132 Generators do not back up argument type stack
Submitted: 2012-09-21 14:53 UTC Modified: -
From: nikic@php.net Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.4Git-2012-09-21 (Git) OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: nikic@php.net
New email:
PHP Version: OS:

 

 [2012-09-21 14:53 UTC] nikic@php.net
Description:
------------
As reported by dmitry in https://bugs.php.net/bug.php?id=63066 there currently are issues with yield interruptions in nested method calls.

The following code:

<?php
class A {
    function foo() {
        echo "Called A::foo\n";
    }
}

class B {
    function foo() {
        echo "Called B::foo\n";
    }
}

function gen($obj) {
    $obj->foo($obj->foo(yield));
}

$g1 = gen(new A);
$g1->current();

$g2 = gen(new B);
$g2->current();

$g1->next();

Will output:

Called A::foo
Called B::foo
[Fri Sep 21 16:49:14 2012]  Script:  '/home/nikic/dev/php-src/t26.php'
/home/nikic/dev/php-src/Zend/zend_vm_execute.h(949) :  Freeing 0xB77579F0 (20 bytes), script=/home/nikic/dev/php-src/t26.php
=== Total 1 memory leaks detected ===

The issue is that generators currently only back up the argument stack (the main VM stack), but don't back up the argument type stack EG(arg_types_stack). This stack contains object and fbc.

So when two generators with nested method calls are intermixed the VM mixes up the different objects/fbcs (and if a generator is closed during the nested method call the object leaks).


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-09-22 17:17 UTC] nikic@php.net
-Status: Open +Status: Closed
 [2012-09-22 17:17 UTC] nikic@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a31fa55b44bcb342c00e9ab2f4a851d054897a39
Log: Fixed bug #63132
 [2013-11-17 09:32 UTC] laruence@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a31fa55b44bcb342c00e9ab2f4a851d054897a39
Log: Fixed bug #63132
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Mar 02 12:01:23 2021 UTC