Skip to content

Commit

Permalink
Backport #1741 from the upstream
Browse files Browse the repository at this point in the history
Fixed "create_symbol_table" for ZendEngine3
  • Loading branch information
sergeyklay committed Nov 18, 2018
1 parent 50907cb commit 53e1938
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 8 deletions.
30 changes: 27 additions & 3 deletions kernels/ZendEngine3/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@
* Not all methods must grow/restore the zephir_memory_entry.
*/

static zend_always_inline zend_execute_data*
find_symbol_table(zend_execute_data* ex)
{
while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->common.type))) {
ex = ex->prev_execute_data;
}

return ex;
}

static zephir_memory_entry* zephir_memory_grow_stack_common(zend_zephir_globals_def *g)
{
assert(g->start_memory != NULL);
Expand Down Expand Up @@ -102,8 +112,14 @@ static void zephir_memory_restore_stack_common(zend_zephir_globals_def *g)
if (g->active_symbol_table) {
active_symbol_table = g->active_symbol_table;
while (active_symbol_table && active_symbol_table->scope == active_memory) {
zend_execute_data *ex = EG(current_execute_data);

zend_execute_data *ex = find_symbol_table(EG(current_execute_data));
#ifndef ZEPHIR_RELEASE
if (UNEXPECTED(!ex)) {
fprintf(stderr, "ERROR: unable to find a symbol table");
zephir_print_backtrace();
return;
}
#endif
zend_hash_destroy(ex->symbol_table);
efree(ex->symbol_table);
ex->symbol_table = active_symbol_table->symbol_table;
Expand Down Expand Up @@ -387,7 +403,6 @@ void zephir_create_symbol_table()
{
zephir_symbol_table *entry;
zend_zephir_globals_def *gptr = ZEPHIR_VGLOBAL;
zend_execute_data *ex = EG(current_execute_data);
zend_array *symbol_table;

#ifndef ZEPHIR_RELEASE
Expand All @@ -398,6 +413,15 @@ void zephir_create_symbol_table()
}
#endif

zend_execute_data* ex = find_symbol_table(EG(current_execute_data));
#ifndef ZEPHIR_RELEASE
if (UNEXPECTED(!ex)) {
fprintf(stderr, "ERROR: unable to find a symbol table");
zephir_print_backtrace();
return;
}
#endif

zend_rebuild_symbol_table();
zend_detach_symbol_table(ex);

Expand Down
19 changes: 16 additions & 3 deletions test/requires.zep
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ class Requires
{
var external3;

if PHP_MAJOR_VERSION == 5 {
create_symbol_table();
}
create_symbol_table();

let external3 = new External3();
external3->req(path, this);
Expand All @@ -35,4 +33,19 @@ class Requires
{
let this->content = content;
}

public function renderTemplate(string! templatePath, var params) -> var
{
create_symbol_table();

var key, value;

if typeof params == "array" {
for key, value in params {
let {key} = value;
}
}

return require templatePath;
}
}
2 changes: 1 addition & 1 deletion unit-tests/Extension/Oo/ExtendClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ExtendClassTest extends \PHPUnit_Framework_TestCase
public function testPDOExtending()
{
if (!extension_loaded('pdo')) {
$this->markTestSkipped('The PDO extendsion is not loaded');
$this->markTestSkipped('The PDO extension is not loaded');
}
$this->assertSame(PDO::getAvailableDrivers(), ExtendPdoClass::getAvailableDrivers());
$this->assertSame(PDO::PARAM_STR, ExtendPdoClass::PARAM_STR);
Expand Down
23 changes: 22 additions & 1 deletion unit-tests/Extension/RequiresTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ public function testRequireExternal1()
$this->assertTrue(defined('REQUIRE_ME'));
}

public function testRequireExternal3()
/**
* @test
* @issue https://github.com/phalcon/zephir/pull/1428
*/
public function shouldRequireUsingNewSymbolTable()
{
$r = new Requires();

Expand All @@ -40,6 +44,23 @@ public function testRequireExternal3()
);
}

/**
* @test
* @issue https://github.com/phalcon/zephir/issues/1621
*/
public function shouldRenderTemplate()
{
$r = new Requires();
$a = 1;

$this->assertEquals(
2,
$r->renderTemplate(__DIR__ . '/../fixtures/template.php', ['a' => 2])
);

$this->assertEquals(1, $a);
}

/**
* @test
* @issue https://github.com/phalcon/zephir/issues/1713
Expand Down
12 changes: 12 additions & 0 deletions unit-tests/fixtures/template.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

/**
* This file is part of the Zephir.
*
* (c) Zephir Team <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

return $a;

0 comments on commit 53e1938

Please sign in to comment.