svn: /pecl/hidef/trunk/ frozenarray.c frozenarray.h hidef.c tests/hidef_015.phpt
| From: | Gopal Vijayaraghavan | Date: | Thu, 08 Dec 2011 18:37:34 +0000 |
| Subject: | svn: /pecl/hidef/trunk/ frozenarray.c frozenarray.h hidef.c tests/hidef_015.phpt | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-17335@lists.php.net to get a copy of this message | ||
gopalv Thu, 08 Dec 2011 18:37:34 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=320687
Log:
fix refcount issues with hidef_wrap
Changed paths:
U pecl/hidef/trunk/frozenarray.c
U pecl/hidef/trunk/frozenarray.h
U pecl/hidef/trunk/hidef.c
A pecl/hidef/trunk/tests/hidef_015.phpt
Modified: pecl/hidef/trunk/frozenarray.c
===================================================================
--- pecl/hidef/trunk/frozenarray.c 2011-12-08 18:33:40 UTC (rev 320686)
+++ pecl/hidef/trunk/frozenarray.c 2011-12-08 18:37:34 UTC (rev 320687)
@@ -105,6 +105,7 @@
#endif
intern->thawed = NULL;
+ intern->pinned = NULL;
return intern;
}
@@ -177,6 +178,13 @@
}
intern->thawed = NULL;
}
+
+ if(intern->pinned)
+ {
+ /* release the array */
+ Z_DELREF_P(intern->pinned);
+ intern->pinned = NULL;
+ }
if(intern->data)
{
@@ -221,6 +229,26 @@
return dst;
}
+zval* frozen_array_pin_zval(zval* src TSRMLS_DC)
+{
+ zval* dst;
+ frozen_array_object *intern;
+
+ dst = frozen_array_wrap_zval(src TSRMLS_CC);
+
+ if(dst && Z_TYPE_P(dst) == IS_OBJECT)
+ {
+ intern = (frozen_array_object*)zend_object_store_get_object(dst TSRMLS_CC);
+ if(intern->data)
+ {
+ Z_ADDREF_P(src);
+ intern->pinned = src;
+ }
+ }
+
+ return dst;
+}
+
zval* frozen_array_thaw_zval(zval* object, size_t* allocated TSRMLS_DC)
{
frozen_array_object *intern = (frozen_array_object*)zend_object_store_get_object(object
TSRMLS_CC);
Modified: pecl/hidef/trunk/frozenarray.h
===================================================================
--- pecl/hidef/trunk/frozenarray.h 2011-12-08 18:33:40 UTC (rev 320686)
+++ pecl/hidef/trunk/frozenarray.h 2011-12-08 18:37:34 UTC (rev 320687)
@@ -32,6 +32,7 @@
zend_object zo;
zval *data;
zval *thawed;
+ zval *pinned;
} frozen_array_object;
void frozen_array_init(TSRMLS_D);
@@ -39,6 +40,7 @@
zval* frozen_array_unserialize(const char* filename TSRMLS_DC);
zval* frozen_array_wrap_zval(zval* src TSRMLS_DC);
+zval* frozen_array_pin_zval(zval* src TSRMLS_DC);
zval* frozen_array_copy_zval_ptr(zval *dst, zval *src, int persistent, size_t *allocated
TSRMLS_DC);
void frozen_array_free_zval_ptr(zval** val, int persistent TSRMLS_DC);
Modified: pecl/hidef/trunk/hidef.c
===================================================================
--- pecl/hidef/trunk/hidef.c 2011-12-08 18:33:40 UTC (rev 320686)
+++ pecl/hidef/trunk/hidef.c 2011-12-08 18:37:34 UTC (rev 320687)
@@ -755,12 +755,16 @@
return;
}
- if (value->type == IS_OBJECT) {
+ if (Z_TYPE_P(value) == IS_OBJECT) {
zend_error(E_ERROR, "Object is not a valid frozen array data type");
zend_bailout();
}
- wrapped = frozen_array_wrap_zval(value TSRMLS_CC);
+ if(Z_TYPE_P(value) == IS_ARRAY) {
+ /* this is almost the same as _wrap_zval, except it does a refcount++ */
+ wrapped = frozen_array_pin_zval(value TSRMLS_CC);
+ }
+
RETURN_ZVAL(wrapped, 0, 1);
}
/* }}} */
Added: pecl/hidef/trunk/tests/hidef_015.phpt
===================================================================
--- pecl/hidef/trunk/tests/hidef_015.phpt (rev 0)
+++ pecl/hidef/trunk/tests/hidef_015.phpt 2011-12-08 18:37:34 UTC (rev 320687)
@@ -0,0 +1,37 @@
+--TEST--
+HIDEF: test hidef_wrap()
+--SKIPIF--
+<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
+--INI--
+hidef.data_path=.
+--FILE--
+<?php
+$a = array("Refcounting is hard, but it's the only way I'll survive");
+$fa = hidef_wrap($a);
+print $fa[0]."\n";
+$a[0] = "Can I change my mind?";
+print $fa[0]."\n";
+unset($a);
+print $fa[0]."\n";
+
+print "REVERSE POLARITY\n";
+
+$a = array("Refcounting is hard, but it's the only way I'll survive");
+$fa = hidef_wrap($a);
+print $fa[0]."\n";
+$a[0] = "Can I change my mind?";
+print $fa[0]."\n";
+unset($fa);
+print $a[0]."\n";
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECTF--
+Refcounting is hard, but it's the only way I'll survive
+Refcounting is hard, but it's the only way I'll survive
+Refcounting is hard, but it's the only way I'll survive
+REVERSE POLARITY
+Refcounting is hard, but it's the only way I'll survive
+Refcounting is hard, but it's the only way I'll survive
+Can I change my mind?
+===DONE===