Skip to content

Commit

Permalink
Fix #1915 Update property
Browse files Browse the repository at this point in the history
fix bug: #1915
  • Loading branch information
chrysanthemum committed Sep 22, 2019
1 parent d9107b6 commit 1f6962d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
4 changes: 3 additions & 1 deletion kernels/ZendEngine3/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,9 @@ int zephir_update_property_array_append(zval *object, char *property, unsigned i
zval new_zv;
ZVAL_DUP(&new_zv, &tmp);
ZVAL_COPY_VALUE(&tmp, &new_zv);
Z_TRY_DELREF(new_zv);
if (Z_REFCOUNT(tmp) > 1) {
Z_TRY_DELREF(new_zv);
}
separated = 1;
}
}
Expand Down
10 changes: 10 additions & 0 deletions test/properties/propertyupdate.zep
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Test\Properties;

class PropertyUpdate
{
public p1;

public function update1() {
let this->p1[] = "aaa";
}
}
28 changes: 28 additions & 0 deletions unit-tests/Extension/Properties/PropertyUpdateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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.
*/

namespace Extension\Properties;

use PHPUnit\Framework\TestCase;
use Test\Properties\PropertyUpdate;

class PropertyUpdateTest extends TestCase
{
public function testUpdate11()
{
// before fixed. Assertion failed: (((ht)->gc.refcount == 1) || ((ht)->u.flags & (1<<6))), function _zend_hash_index_add_or_update_i
$t = new PropertyUpdate();
$t->p1 = [111];
$t->update1();

$this->assertSame($t->p1, [111, 'aaa']);
}
}

1 comment on commit 1f6962d

@sergeyklay
Copy link
Contributor

@sergeyklay sergeyklay commented on 1f6962d Oct 2, 2019

Choose a reason for hiding this comment

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

@chrysanthemum Just got (((ht)->gc.refcount == 1) || ((ht)->u.flags & (1<<6))) assertion here.

Commit: 1cacb6c
PHP: 7.2.20 (cli) ( ZTS DEBUG )
Test:

use Test\Properties\PropertyUpdate;

$t = new PropertyUpdate();
$t->p1 = [111];
$t->update1();

var_dump($t->p1);
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x00007ffff4bbb535 in __GI_abort () at abort.c:79
#2  0x00007ffff4bbb40f in __assert_fail_base (fmt=0x7ffff4d1dee0 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n",
assertion=0x55555674eff8 "((ht)->gc.refcount == 1) || ((ht)->u.flags & (1<<6))",
    file=0x55555674ef80 "/home/klay/src/php/source/7.2.20/Zend/zend_hash.c", line=712, function=<optimized out>) at assert.c:92
#3  0x00007ffff4bc9102 in __GI___assert_fail (assertion=0x55555674eff8 "((ht)->gc.refcount == 1) || ((ht)->u.flags & (1<<6))",
    file=0x55555674ef80 "/home/klay/src/php/source/7.2.20/Zend/zend_hash.c", line=712,
    function=0x55555674f360 <__PRETTY_FUNCTION__.12223> "_zend_hash_index_add_or_update_i") at assert.c:101
#4  0x0000555555ec01df in _zend_hash_index_add_or_update_i (ht=0x7ffff3c65a20, h=1, pData=0x7fffffffb060, flag=18,
    __zend_filename=0x55555674d718 "/home/klay/src/php/source/7.2.20/Zend/zend_API.c", __zend_lineno=1591)
    at /home/klay/src/php/source/7.2.20/Zend/zend_hash.c:712
#5  0x0000555555ec09f5 in _zend_hash_next_index_insert (ht=0x7ffff3c65a20, pData=0x7fffffffb060,
    __zend_filename=0x55555674d718 "/home/klay/src/php/source/7.2.20/Zend/zend_API.c", __zend_lineno=1591)
    at /home/klay/src/php/source/7.2.20/Zend/zend_hash.c:839
#6  0x0000555555eb2761 in add_next_index_zval (arg=0x7fffffffb070, value=0x7fffffffb060) at /home/klay/src/php/source/7.2.20/Zend/zend_API.c:1591
#7  0x00007ffff059698b in zephir_update_property_array_append (object=0x7ffff3c210c0, property=0x7ffff0bd9e8e "p1", property_length=2,
    value=0x7fffffffb150) at /mnt/work/zephir/php-zephir/ext/kernel/object.c:791
#8  0x00007ffff070948f in zim_Test_Properties_PropertyUpdate_update1 (execute_data=0x7ffff3c210a0, return_value=0x7fffffffb1a0)
    at /mnt/work/zephir/php-zephir/ext/test/properties/propertyupdate.zep.c:39
#9  0x0000555555f1691e in ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER () at /home/klay/src/php/source/7.2.20/Zend/zend_vm_execute.h:907
#10 0x0000555555f9e171 in execute_ex (ex=0x7ffff3c21030) at /home/klay/src/php/source/7.2.20/Zend/zend_vm_execute.h:59765
#11 0x0000555555fa361f in zend_execute (op_array=0x7ffff3c7c400, return_value=0x0) at /home/klay/src/php/source/7.2.20/Zend/zend_vm_execute.h:63776
#12 0x0000555555eab03a in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /home/klay/src/php/source/7.2.20/Zend/zend.c:1498
#13 0x0000555555deaca8 in php_execute_script (primary_file=0x7fffffffd840) at /home/klay/src/php/source/7.2.20/main/main.c:2594
#14 0x0000555555fa6236 in do_cli (argc=4, argv=0x5555569aff20) at /home/klay/src/php/source/7.2.20/sapi/cli/php_cli.c:1011
#15 0x0000555555fa74d6 in main (argc=4, argv=0x5555569aff20) at /home/klay/src/php/source/7.2.20/sapi/cli/php_cli.c:1403

Please sign in to comment.