Skip to content

Commit

Permalink
Fix bug about closure (#1867)
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamsxin committed Jun 4, 2019
1 parent acbcb38 commit 843f5c8
Show file tree
Hide file tree
Showing 27 changed files with 902 additions and 77 deletions.
2 changes: 2 additions & 0 deletions Library/ClassMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,8 @@ public function compile(CompilationContext $compilationContext)
$localVar = clone $var;
$localVar->setIsExternal(true);
$localVar->setLocalOnly(true);
$localVar->setDynamicTypes($localVar->getType());
$localVar->setType('variable');
$localVar->setIsDoublePointer(false);
$symbolTable->addRawVariable($localVar);
}
Expand Down
1 change: 1 addition & 0 deletions ext/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ if test "$PHP_TEST" = "yes"; then
test/oo/extendpdoclass.zep.c
test/oo/ooconstruct.zep.c
test/oo/ooconstructparams.zep.c
test/oo/oodestruct.zep.c
test/oo/oodynamicb.zep.c
test/oo/oonativeimplements.zep.c
test/oo/oonoconstruct.zep.c
Expand Down
2 changes: 1 addition & 1 deletion ext/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (PHP_TEST != "no") {
ADD_SOURCES(configure_module_dirname + "/test/oo/extend", "exception.zep.c", "test");
ADD_SOURCES(configure_module_dirname + "/test/oo/extend/db", "exception.zep.c", "test");
ADD_SOURCES(configure_module_dirname + "/test/globals/session", "base.zep.c child.zep.c", "test");
ADD_SOURCES(configure_module_dirname + "/test/oo", "abstractstatic.zep.c oodynamica.zep.c abstractclass.zep.c concretestatic.zep.c constantsinterface.zep.c deprecatedmethods.zep.c dynamicprop.zep.c extendpdoclass.zep.c ooconstruct.zep.c ooconstructparams.zep.c oodynamicb.zep.c oonativeimplements.zep.c oonoconstruct.zep.c ooparams.zep.c param.zep.c propertyaccess.zep.c", "test");
ADD_SOURCES(configure_module_dirname + "/test/oo", "abstractstatic.zep.c oodynamica.zep.c abstractclass.zep.c concretestatic.zep.c constantsinterface.zep.c deprecatedmethods.zep.c dynamicprop.zep.c extendpdoclass.zep.c ooconstruct.zep.c ooconstructparams.zep.c oodestruct.zep.c oodynamicb.zep.c oonativeimplements.zep.c oonoconstruct.zep.c ooparams.zep.c param.zep.c propertyaccess.zep.c", "test");
ADD_SOURCES(configure_module_dirname + "/test/oo/extend/db/query", "exception.zep.c", "test");
ADD_SOURCES(configure_module_dirname + "/test/oo/scopes", "hasprivatemethod.zep.c scopetesterinterface.zep.c privatescopetester.zep.c", "test");
ADD_SOURCES(configure_module_dirname + "/test/ooimpl", "zbeginning.zep.c abeginning.zep.c", "test");
Expand Down
18 changes: 8 additions & 10 deletions ext/kernel/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ int zephir_read_property_zval(zval *result, zval *object, zval *property, int fl
int zephir_update_property_zval(zval *object, const char *property_name, unsigned int property_length, zval *value)
{
zend_class_entry *ce, *old_scope;
zval property;
zval property, sep_value;

#if PHP_VERSION_ID >= 70100
old_scope = EG(fake_scope);
Expand Down Expand Up @@ -570,20 +570,18 @@ int zephir_update_property_zval(zval *object, const char *property_name, unsigne
}

ZVAL_STRINGL(&property, property_name, property_length);

if (Z_TYPE_P(value) == IS_ARRAY) {
if (EXPECTED(!(GC_FLAGS(Z_ARRVAL_P(value)) & IS_ARRAY_IMMUTABLE))) {
if (UNEXPECTED(GC_REFCOUNT(Z_ARR_P(value)) > 1)) {
if (Z_REFCOUNTED_P(value)) {
GC_DELREF(Z_ARR_P(value));
}
ZVAL_COPY_VALUE(&sep_value, value);
if (Z_TYPE(sep_value) == IS_ARRAY) {
ZVAL_ARR(&sep_value, zend_array_dup(Z_ARR(sep_value)));
if (EXPECTED(!(GC_FLAGS(Z_ARRVAL(sep_value)) & IS_ARRAY_IMMUTABLE))) {
if (UNEXPECTED(GC_REFCOUNT(Z_ARR(sep_value)) > 0)) {
GC_DELREF(Z_ARR(sep_value));
}
}
ZVAL_ARR(value, zend_array_dup(Z_ARR_P(value)));
}

/* write_property will add 1 to refcount, so no Z_TRY_ADDREF_P(value); is necessary */
Z_OBJ_HT_P(object)->write_property(object, &property, value, 0);
Z_OBJ_HT_P(object)->write_property(object, &property, &sep_value, 0);
zval_ptr_dtor(&property);

#if PHP_VERSION_ID >= 70100
Expand Down
2 changes: 2 additions & 0 deletions ext/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ zend_class_entry *test_oo_extend_spl_tempfileobject_ce;
zend_class_entry *test_oo_extendpdoclass_ce;
zend_class_entry *test_oo_ooconstruct_ce;
zend_class_entry *test_oo_ooconstructparams_ce;
zend_class_entry *test_oo_oodestruct_ce;
zend_class_entry *test_oo_oodynamicb_ce;
zend_class_entry *test_oo_oonativeimplements_ce;
zend_class_entry *test_oo_oonoconstruct_ce;
Expand Down Expand Up @@ -339,6 +340,7 @@ static PHP_MINIT_FUNCTION(test)
ZEPHIR_INIT(Test_Oo_Extend_Spl_TempFileObject);
ZEPHIR_INIT(Test_Oo_OoConstruct);
ZEPHIR_INIT(Test_Oo_OoConstructParams);
ZEPHIR_INIT(Test_Oo_OoDestruct);
ZEPHIR_INIT(Test_Oo_OoDynamicB);
ZEPHIR_INIT(Test_Oo_OoNativeImplements);
ZEPHIR_INIT(Test_Oo_OoNoConstruct);
Expand Down
1 change: 1 addition & 0 deletions ext/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
#include "test/oo/extendpdoclass.zep.h"
#include "test/oo/ooconstruct.zep.h"
#include "test/oo/ooconstructparams.zep.h"
#include "test/oo/oodestruct.zep.h"
#include "test/oo/oodynamicb.zep.h"
#include "test/oo/oonativeimplements.zep.h"
#include "test/oo/oonoconstruct.zep.h"
Expand Down
6 changes: 4 additions & 2 deletions ext/test/8__closure.zep.c

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

3 changes: 1 addition & 2 deletions ext/test/9__closure.zep.c

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

Loading

2 comments on commit 843f5c8

@dreamsxin
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sergeyklay
Some checks were not successful
2 failing and 2 successful checks
@codecov
codecov/patch — 9.64% of diff hit (target 33.32%)
Details
@codecov
codecov/project — 33.06% (-0.26%) compared to acbcb

@sergeyklay
Copy link
Member

Choose a reason for hiding this comment

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

@dreamsxin It is no so bad I think. Just code coverage.

Please sign in to comment.