Skip to content
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

BUG: zephir_get_global #1961

Closed
chrysanthemum opened this issue Oct 11, 2019 · 14 comments
Closed

BUG: zephir_get_global #1961

chrysanthemum opened this issue Oct 11, 2019 · 14 comments
Labels

Comments

@chrysanthemum
Copy link
Contributor

chrysanthemum commented Oct 11, 2019

Close all extensions compiled by zephir, including the phaclon extension. Leave only the test extension.

test/globals/server.zep

namespace Test\Globals;

class Server
{
    public function f1() -> void
    {
        echo _SERVER["PHP_SELF"];
        this->f2();
        echo _SERVER["PHP_SELF"];
    }
    
    public function f2() -> void
    {
        echo _SERVER["SCRIPT_NAME"];
    }
}

manual.php

$t = new Test\Globals\Server();
$t->f1();

output:

/php-src/php-7.2/Zend/zend_hash.c(1968) : ht=0x107e65720 is already destroyed
Assertion failed: (0), function _zend_is_inconsistent, file /php-src/php-7.2/Zend/zend_hash.c, line 64.
@chrysanthemum
Copy link
Contributor Author

chrysanthemum commented Oct 11, 2019

@dreamsxin Could you fix this BUG? I'm afraid I'll make a mistake.

@sergeyklay sergeyklay added the bug label Oct 11, 2019
@sergeyklay
Copy link
Member

@chrysanthemum Could you please provide exact PHP version and used Zephir version/commit

@chrysanthemum
Copy link
Contributor Author

php:

PHP 7.2.22 (cli) (built: Sep 21 2019 13:19:31) ( NTS DEBUG )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans
    with Zend OPcache v7.2.22, Copyright (c) 1999-2018, by Zend Technologies

zephir:

Zephir 0.12.9
git revision number: 4155edf8824ee64a4255be929c48ee108528e8d5

operating system:

macOS Mojave 10.14.6

@chrysanthemum
Copy link
Contributor Author

@dreamsxin I got it wrong. There's no bug :)

@sergeyklay
Copy link
Member

@chrysanthemum Should we close this one?

@chrysanthemum
Copy link
Contributor Author

chrysanthemum commented Oct 11, 2019

@sergeyklay

Oddly enough, this problem occurred when I closed all the zephir compiled extensions, leaving only the test extension.

If I open the phaclon extension, the bug does not appear.

Do you have this bug? (Close all zephir compiled extensions, leaving only the test extension.)

@chrysanthemum chrysanthemum reopened this Oct 11, 2019
@chrysanthemum
Copy link
Contributor Author

chrysanthemum commented Oct 11, 2019

This strange bug does exist.
@dreamsxin

@dreamsxin
Copy link
Contributor

@sergeyklay Revoke that commit ed65fa7#diff-91d00b5ec72fef64318f760cae59fbda

@sergeyklay
Copy link
Member

Fixed in the development branch. Feel free to open a new issue if the problem appears again. Thank you for bug report.

@sergeyklay
Copy link
Member

@sergeyklay sergeyklay reopened this Oct 13, 2019
@dreamsxin
Copy link
Contributor

@sergeyklay

public function f1() -> void
{
	echo _SERVER["PHP_SELF"];
	this->f2(); // In zephir_get_global use ZVAL_DUP will separation
	echo _SERVER["PHP_SELF"];
}

generate c code:

ZEPHIR_MM_GROW();
zephir_get_global(&_SERVER, SL("_SERVER")); // separation

zephir_array_fetch_string(&_0, &_SERVER, SL("PHP_SELF"), ...);
zend_print_zval(&_0, 0);

ZEPHIR_CALL_METHOD(NULL, this_ptr, "f2", NULL, 0); // separation
zephir_check_call_status();

zephir_array_fetch_string(&_1, &_SERVER, SL("PHP_SELF"), ...); // <-- After separation, the variables here fail. is already destroyed
zend_print_zval(&_1, 0);
ZEPHIR_MM_RESTORE();

@dreamsxin
Copy link
Contributor

dreamsxin commented Oct 14, 2019

@sergeyklay So we need to get global every time.

ZEPHIR_MM_GROW();
zephir_get_global(&_SERVER, SL("_SERVER"));

zephir_array_fetch_string(&_0, &_SERVER, SL("PHP_SELF"), ...);
zend_print_zval(&_0, 0);

ZEPHIR_CALL_METHOD(NULL, this_ptr, "f2", NULL, 0);
zephir_check_call_status();

zephir_get_global(&_SERVER, SL("_SERVER")); // <-- Get global again
zephir_array_fetch_string(&_1, &_SERVER, SL("PHP_SELF"), ...);
zend_print_zval(&_1, 0);
ZEPHIR_MM_RESTORE();

sergeyklay added a commit that referenced this issue Oct 19, 2019
sergeyklay added a commit that referenced this issue Oct 19, 2019
@sergeyklay sergeyklay mentioned this issue Oct 19, 2019
3 tasks
dreamsxin added a commit to dreamsxin/zephir that referenced this issue Nov 6, 2019
dreamsxin pushed a commit to dreamsxin/zephir that referenced this issue Nov 6, 2019
@mruz
Copy link
Contributor

mruz commented Mar 30, 2020

I have similar issue. If I access to the global variable in zephir and then access with isset in php:

if (isset($_POST[$key])) {
    unset($_POST[$key]);
}

then I'm getting "502 Bad Gateway":

[error] 1319#1319: *114 recv() failed (104: Connection reset by peer) while reading response header from upstream

@sergeyklay
Copy link
Member

@mruz Most likely this is a different issue. Could you please create a new issue with code to reproduce?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants