diff --git a/CHANGELOG b/CHANGELOG index 47240907b2f..1b818c0ee17 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -26,6 +26,8 @@ - Fixed invalid memory reads/writes across the code (#1340) - Fixed HAVING handling in Phalcon\Mvc\QueryBuilder (#1396) - Bug fixes in \Phalcon\Logger\{Adapter,Formatter}\FirePhp (#1333) + - Bug fixes in Phalcon\Cache\Backend\Xcache (#1406) + - Phalcon\Forms\Element::__toString() does not throw exceptions anymore (#1413) - Other bug fixes (#947, #1131, #1040, #1275, #1392, #1396, #1399, backported patches from 1.3.0 etc) 1.2.3 diff --git a/build/32bits/phalcon.c b/build/32bits/phalcon.c index 3329be0a4dc..00af09ced89 100644 --- a/build/32bits/phalcon.c +++ b/build/32bits/phalcon.c @@ -89117,13 +89117,11 @@ static PHP_METHOD(Phalcon_Cache_Backend_Xcache, save){ array_init(keys); } - if (!zend_is_true(keys)) { - phalcon_array_update_zval(&keys, last_key, &ttl, PH_COPY | PH_SEPARATE); - - PHALCON_INIT_VAR(zero); - ZVAL_LONG(zero, 0); - phalcon_call_func_p3_noret("xcache_set", special_key, keys, zero); - } + phalcon_array_update_zval(&keys, last_key, &ttl, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_VAR(zero); + ZVAL_LONG(zero, 0); + phalcon_call_func_p3_noret("xcache_set", special_key, keys, zero); } PHALCON_MM_RESTORE(); @@ -89158,7 +89156,7 @@ static PHP_METHOD(Phalcon_Cache_Backend_Xcache, delete){ if (Z_TYPE_P(keys) == IS_ARRAY) { PHALCON_INIT_VAR(zero); ZVAL_LONG(zero, 0); - phalcon_array_unset(&keys, special_key, PH_SEPARATE); + phalcon_array_unset(&keys, prefixed_key, PH_SEPARATE); phalcon_call_func_p3_noret("xcache_set", special_key, keys, zero); } @@ -90969,10 +90967,26 @@ static PHP_METHOD(Phalcon_Forms_Element, clear){ static PHP_METHOD(Phalcon_Forms_Element, __toString){ - PHALCON_MM_GROW(); - phalcon_call_method_key(return_value, this_ptr, "render", 1053215877UL); + if (phalcon_call_method_params(return_value, this_ptr, SL("render"), 0, NULL, zend_inline_hash_func(SS("render")), 1 TSRMLS_CC) == FAILURE) { + if (EG(exception)) { + zval *e = EG(exception); + zval *m = zend_read_property(Z_OBJCE_P(e), e, SL("message"), 1 TSRMLS_CC); + + Z_ADDREF_P(m); + if (Z_TYPE_P(m) != IS_STRING) { + convert_to_string_ex(&m); + } + + zend_clear_exception(TSRMLS_C); + zend_error(E_ERROR, "%s", Z_STRVAL_P(m)); + zval_ptr_dtor(&m); + } + + return; + } + RETURN_MM(); } @@ -97268,6 +97282,9 @@ static void phalcon_tag_write_attributes(zval *code, zval *attributes TSRMLS_DC) PHALCON_OBS_VAR(escaper); phalcon_tag_get_escaper(&escaper, attributes TSRMLS_CC); + if (EG(exception)) { + RETURN_MM(); + } if (escaper) { for ( @@ -97658,6 +97675,9 @@ static PHP_METHOD(Phalcon_Tag, _inputField){ PHALCON_OBS_VAR(escaper); phalcon_tag_get_escaper(&escaper, params TSRMLS_CC); + if (EG(exception)) { + RETURN_MM(); + } phalcon_array_update_quick_string(¶ms, SS("type"), 276192743UL, &type, PH_COPY | PH_SEPARATE); @@ -97999,6 +98019,9 @@ static PHP_METHOD(Phalcon_Tag, textArea){ PHALCON_OBS_VAR(escaper); phalcon_tag_get_escaper(&escaper, params TSRMLS_CC); + if (EG(exception)) { + RETURN_MM(); + } if (escaper) { PHALCON_INIT_VAR(escaped); diff --git a/build/64bits/phalcon.c b/build/64bits/phalcon.c index d0d7dc13a00..0882ec4c924 100644 --- a/build/64bits/phalcon.c +++ b/build/64bits/phalcon.c @@ -89117,13 +89117,11 @@ static PHP_METHOD(Phalcon_Cache_Backend_Xcache, save){ array_init(keys); } - if (!zend_is_true(keys)) { - phalcon_array_update_zval(&keys, last_key, &ttl, PH_COPY | PH_SEPARATE); - - PHALCON_INIT_VAR(zero); - ZVAL_LONG(zero, 0); - phalcon_call_func_p3_noret("xcache_set", special_key, keys, zero); - } + phalcon_array_update_zval(&keys, last_key, &ttl, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_VAR(zero); + ZVAL_LONG(zero, 0); + phalcon_call_func_p3_noret("xcache_set", special_key, keys, zero); } PHALCON_MM_RESTORE(); @@ -89158,7 +89156,7 @@ static PHP_METHOD(Phalcon_Cache_Backend_Xcache, delete){ if (Z_TYPE_P(keys) == IS_ARRAY) { PHALCON_INIT_VAR(zero); ZVAL_LONG(zero, 0); - phalcon_array_unset(&keys, special_key, PH_SEPARATE); + phalcon_array_unset(&keys, prefixed_key, PH_SEPARATE); phalcon_call_func_p3_noret("xcache_set", special_key, keys, zero); } @@ -90969,10 +90967,26 @@ static PHP_METHOD(Phalcon_Forms_Element, clear){ static PHP_METHOD(Phalcon_Forms_Element, __toString){ - PHALCON_MM_GROW(); - phalcon_call_method_key(return_value, this_ptr, "render", 229481155841157UL); + if (phalcon_call_method_params(return_value, this_ptr, SL("render"), 0, NULL, zend_inline_hash_func(SS("render")), 1 TSRMLS_CC) == FAILURE) { + if (EG(exception)) { + zval *e = EG(exception); + zval *m = zend_read_property(Z_OBJCE_P(e), e, SL("message"), 1 TSRMLS_CC); + + Z_ADDREF_P(m); + if (Z_TYPE_P(m) != IS_STRING) { + convert_to_string_ex(&m); + } + + zend_clear_exception(TSRMLS_C); + zend_error(E_ERROR, "%s", Z_STRVAL_P(m)); + zval_ptr_dtor(&m); + } + + return; + } + RETURN_MM(); } @@ -97268,6 +97282,9 @@ static void phalcon_tag_write_attributes(zval *code, zval *attributes TSRMLS_DC) PHALCON_OBS_VAR(escaper); phalcon_tag_get_escaper(&escaper, attributes TSRMLS_CC); + if (EG(exception)) { + RETURN_MM(); + } if (escaper) { for ( @@ -97658,6 +97675,9 @@ static PHP_METHOD(Phalcon_Tag, _inputField){ PHALCON_OBS_VAR(escaper); phalcon_tag_get_escaper(&escaper, params TSRMLS_CC); + if (EG(exception)) { + RETURN_MM(); + } phalcon_array_update_quick_string(¶ms, SS("type"), 210729590247UL, &type, PH_COPY | PH_SEPARATE); @@ -97999,6 +98019,9 @@ static PHP_METHOD(Phalcon_Tag, textArea){ PHALCON_OBS_VAR(escaper); phalcon_tag_get_escaper(&escaper, params TSRMLS_CC); + if (EG(exception)) { + RETURN_MM(); + } if (escaper) { PHALCON_INIT_VAR(escaped); diff --git a/build/safe/phalcon.c b/build/safe/phalcon.c index 6bf033a3628..fffb3ab8e3f 100644 --- a/build/safe/phalcon.c +++ b/build/safe/phalcon.c @@ -89117,13 +89117,11 @@ static PHP_METHOD(Phalcon_Cache_Backend_Xcache, save){ array_init(keys); } - if (!zend_is_true(keys)) { - phalcon_array_update_zval(&keys, last_key, &ttl, PH_COPY | PH_SEPARATE); - - PHALCON_INIT_VAR(zero); - ZVAL_LONG(zero, 0); - phalcon_call_func_p3_noret("xcache_set", special_key, keys, zero); - } + phalcon_array_update_zval(&keys, last_key, &ttl, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_VAR(zero); + ZVAL_LONG(zero, 0); + phalcon_call_func_p3_noret("xcache_set", special_key, keys, zero); } PHALCON_MM_RESTORE(); @@ -89158,7 +89156,7 @@ static PHP_METHOD(Phalcon_Cache_Backend_Xcache, delete){ if (Z_TYPE_P(keys) == IS_ARRAY) { PHALCON_INIT_VAR(zero); ZVAL_LONG(zero, 0); - phalcon_array_unset(&keys, special_key, PH_SEPARATE); + phalcon_array_unset(&keys, prefixed_key, PH_SEPARATE); phalcon_call_func_p3_noret("xcache_set", special_key, keys, zero); } @@ -90969,10 +90967,26 @@ static PHP_METHOD(Phalcon_Forms_Element, clear){ static PHP_METHOD(Phalcon_Forms_Element, __toString){ - PHALCON_MM_GROW(); - phalcon_call_method(return_value, this_ptr, "render"); + if (phalcon_call_method_params(return_value, this_ptr, SL("render"), 0, NULL, zend_inline_hash_func(SS("render")), 1 TSRMLS_CC) == FAILURE) { + if (EG(exception)) { + zval *e = EG(exception); + zval *m = zend_read_property(Z_OBJCE_P(e), e, SL("message"), 1 TSRMLS_CC); + + Z_ADDREF_P(m); + if (Z_TYPE_P(m) != IS_STRING) { + convert_to_string_ex(&m); + } + + zend_clear_exception(TSRMLS_C); + zend_error(E_ERROR, "%s", Z_STRVAL_P(m)); + zval_ptr_dtor(&m); + } + + return; + } + RETURN_MM(); } @@ -97268,6 +97282,9 @@ static void phalcon_tag_write_attributes(zval *code, zval *attributes TSRMLS_DC) PHALCON_OBS_VAR(escaper); phalcon_tag_get_escaper(&escaper, attributes TSRMLS_CC); + if (EG(exception)) { + RETURN_MM(); + } if (escaper) { for ( @@ -97658,6 +97675,9 @@ static PHP_METHOD(Phalcon_Tag, _inputField){ PHALCON_OBS_VAR(escaper); phalcon_tag_get_escaper(&escaper, params TSRMLS_CC); + if (EG(exception)) { + RETURN_MM(); + } phalcon_array_update_string(¶ms, SL("type"), &type, PH_COPY | PH_SEPARATE); @@ -97999,6 +98019,9 @@ static PHP_METHOD(Phalcon_Tag, textArea){ PHALCON_OBS_VAR(escaper); phalcon_tag_get_escaper(&escaper, params TSRMLS_CC); + if (EG(exception)) { + RETURN_MM(); + } if (escaper) { PHALCON_INIT_VAR(escaped); diff --git a/ext/cache/backend/xcache.c b/ext/cache/backend/xcache.c index 34f6603db34..928eef91443 100644 --- a/ext/cache/backend/xcache.c +++ b/ext/cache/backend/xcache.c @@ -275,13 +275,11 @@ PHP_METHOD(Phalcon_Cache_Backend_Xcache, save){ array_init(keys); } - if (!zend_is_true(keys)) { - phalcon_array_update_zval(&keys, last_key, &ttl, PH_COPY | PH_SEPARATE); - - PHALCON_INIT_VAR(zero); - ZVAL_LONG(zero, 0); - phalcon_call_func_p3_noret("xcache_set", special_key, keys, zero); - } + phalcon_array_update_zval(&keys, last_key, &ttl, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_VAR(zero); + ZVAL_LONG(zero, 0); + phalcon_call_func_p3_noret("xcache_set", special_key, keys, zero); } PHALCON_MM_RESTORE(); @@ -322,7 +320,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Xcache, delete){ if (Z_TYPE_P(keys) == IS_ARRAY) { PHALCON_INIT_VAR(zero); ZVAL_LONG(zero, 0); - phalcon_array_unset(&keys, special_key, PH_SEPARATE); + phalcon_array_unset(&keys, prefixed_key, PH_SEPARATE); phalcon_call_func_p3_noret("xcache_set", special_key, keys, zero); } diff --git a/ext/forms/element.c b/ext/forms/element.c index f2e4e3e01ea..3219bb4fc0c 100644 --- a/ext/forms/element.c +++ b/ext/forms/element.c @@ -824,10 +824,26 @@ PHP_METHOD(Phalcon_Forms_Element, clear){ */ PHP_METHOD(Phalcon_Forms_Element, __toString){ - PHALCON_MM_GROW(); - phalcon_call_method(return_value, this_ptr, "render"); + if (phalcon_call_method_params(return_value, this_ptr, SL("render"), 0, NULL, zend_inline_hash_func(SS("render")), 1 TSRMLS_CC) == FAILURE) { + if (EG(exception)) { + zval *e = EG(exception); + zval *m = zend_read_property(Z_OBJCE_P(e), e, SL("message"), 1 TSRMLS_CC); + + Z_ADDREF_P(m); + if (Z_TYPE_P(m) != IS_STRING) { + convert_to_string_ex(&m); + } + + zend_clear_exception(TSRMLS_C); + zend_error(E_ERROR, "%s", Z_STRVAL_P(m)); + zval_ptr_dtor(&m); + } + + return; + } + RETURN_MM(); } diff --git a/ext/tag.c b/ext/tag.c index e99ea48e256..958c2d36d33 100644 --- a/ext/tag.c +++ b/ext/tag.c @@ -119,6 +119,9 @@ static void phalcon_tag_write_attributes(zval *code, zval *attributes TSRMLS_DC) PHALCON_OBS_VAR(escaper); phalcon_tag_get_escaper(&escaper, attributes TSRMLS_CC); + if (EG(exception)) { + RETURN_MM(); + } if (escaper) { for ( @@ -629,6 +632,9 @@ PHP_METHOD(Phalcon_Tag, _inputField){ PHALCON_OBS_VAR(escaper); phalcon_tag_get_escaper(&escaper, params TSRMLS_CC); + if (EG(exception)) { + RETURN_MM(); + } phalcon_array_update_string(¶ms, SL("type"), &type, PH_COPY | PH_SEPARATE); @@ -1163,6 +1169,9 @@ PHP_METHOD(Phalcon_Tag, textArea){ PHALCON_OBS_VAR(escaper); phalcon_tag_get_escaper(&escaper, params TSRMLS_CC); + if (EG(exception)) { + RETURN_MM(); + } if (escaper) { PHALCON_INIT_VAR(escaped); diff --git a/ext/tests/issue-1413.phpt b/ext/tests/issue-1413.phpt new file mode 100644 index 00000000000..1da9cfcd5cf --- /dev/null +++ b/ext/tests/issue-1413.phpt @@ -0,0 +1,11 @@ +--TEST-- +Phalcon\Forms\Element::toString() throws exceptions - https://github.com/phalcon/cphalcon/issues/1413 +--SKIPIF-- + +--FILE-- + '&&&')); +echo $e, PHP_EOL; +?> +--EXPECTF-- +Fatal error: A dependency injector container is required to obtain the "escaper" service in %s on line %d diff --git a/unit-tests/CacheTest.php b/unit-tests/CacheTest.php index 2a33be4d89c..3f67ec71986 100644 --- a/unit-tests/CacheTest.php +++ b/unit-tests/CacheTest.php @@ -682,4 +682,32 @@ public function testDataXcache() $this->assertTrue($cache->delete('test-data')); } + + public function testXcacheQueryKeys() + { + $ready = $this->_prepareXcache(); + if (!$ready) { + return false; + } + + $frontCache = new Phalcon\Cache\Frontend\None(array( + 'lifetime' => 2 + )); + + $cache = new Phalcon\Cache\Backend\Xcache($frontCache); + + + $cache->delete('test-output'); + $cache->delete('test-data'); + + $cache->save('test-one', 'one'); + $cache->save('test-two', 'two'); + + //Query keys + $keys = $cache->queryKeys(); + $this->assertEquals($keys, array( + 0 => 'test-one', + 1 => 'test-two', + )); + } }