com php-src: Fixed ArrayObject::sort() family: ext/spl/spl_ar ray.c

From: Date: Wed, 09 Apr 2014 10:25:35 +0000
Subject: com php-src: Fixed ArrayObject::sort() family: ext/spl/spl_ar ray.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-77465@lists.php.net to get a copy of this message
Commit: 085be9d61815ab347db1cbe777e91a07d03307fb Author: Dmitry Stogov <dmitry@zend.com> Wed, 9 Apr 2014 14:25:35 +0400 Parents: 39d2cede7404b545df99fa00576f0d92e9e967ae Branches: phpng Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=085be9d61815ab347db1cbe777e91a07d03307fb Log: Fixed ArrayObject::sort() family Changed paths: M ext/spl/spl_array.c Diff: diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index cf12aa6..ae817a0 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -1436,9 +1436,10 @@ static void spl_array_method(INTERNAL_FUNCTION_PARAMETERS, char *fname, int fnam zval tmp, *arg = NULL; zval retval; - // ??? how to pass aht as a reference to later method call? - array_init(&tmp); - zend_hash_copy(Z_ARRVAL(tmp), aht, (copy_ctor_func_t)zval_add_ref); + /* A tricky way to pass "aht" by reference, copy HashTable */ + //??? It may be not safe, if user comparison handler accesses "aht" + ZVAL_NEW_ARR(&tmp); + *Z_ARRVAL(tmp) = *aht; if (!use_arg) { aht->nApplyCount++; @@ -1463,7 +1464,13 @@ static void spl_array_method(INTERNAL_FUNCTION_PARAMETERS, char *fname, int fnam zend_call_method(NULL, NULL, NULL, fname, fname_len, &retval, 2, &tmp, arg TSRMLS_CC); aht->nApplyCount--; } - zval_ptr_dtor(&tmp); + /* A tricky way to pass "aht" by reference, copy back and cleanup */ + if (Z_ISREF(tmp) && Z_TYPE_P(Z_REFVAL(tmp))) { + *aht = *Z_ARRVAL_P(Z_REFVAL(tmp)); + GC_REMOVE_FROM_BUFFER(Z_ARR_P(Z_REFVAL(tmp))); + efree(Z_ARR_P(Z_REFVAL(tmp))); + efree(Z_REF(tmp)); + } if (!ZVAL_IS_UNDEF(&retval)) { COPY_PZVAL_TO_ZVAL(*return_value, &retval); }

« previous php.cvs (#77465) next »