Skip to content

Commit

Permalink
Fixed "create_symbol_table" for ZendEngine3
Browse files Browse the repository at this point in the history
Closes: #1621, #1488, #1403, #1428
  • Loading branch information
sergeyklay committed Nov 18, 2018
1 parent 9dd1737 commit 03606ee
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 21 deletions.
30 changes: 27 additions & 3 deletions ext/kernel/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)

This comment was marked as abuse.

Copy link
@dschissler

dschissler Nov 19, 2018

I don't believe about the Russian fairy tails, especially such as begin with the American cowboy words.

{
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
2 changes: 1 addition & 1 deletion ext/php_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#define PHP_TEST_VERSION "1.0.0"
#define PHP_TEST_EXTNAME "test"
#define PHP_TEST_AUTHOR "Zephir Team"
#define PHP_TEST_ZEPVERSION "0.11.4-$Id$"
#define PHP_TEST_ZEPVERSION "0.11.5-$Id$"
#define PHP_TEST_DESCRIPTION "Description test for<br/>Test Extension"

typedef struct _zephir_struct_test {
Expand Down
77 changes: 68 additions & 9 deletions ext/test/requires.zep.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions ext/test/requires.zep.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 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());
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 <team@zephir-lang.com>
*
* 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 03606ee

Please sign in to comment.