Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve iterator fix #279

Merged
merged 3 commits into from
Feb 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions apc_iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ static apc_iterator_item_t* apc_iterator_item_ctor(apc_iterator_t *iterator, apc

array_init(&item->value);

item->key = slot->key.str;
item->key = zend_string_dup(slot->key.str, 0);

if (APC_ITER_TYPE & iterator->format) {
add_assoc_string_ex(&item->value, "type", sizeof("type")-1, "user");
}

if (APC_ITER_KEY & iterator->format) {
add_assoc_str(&item->value, "key", zend_string_dup(item->key, 0));
add_assoc_str(&item->value, "key", zend_string_copy(item->key));
}

if (APC_ITER_VALUE & iterator->format) {
Expand Down Expand Up @@ -100,6 +100,7 @@ static zend_object* apc_iterator_clone(zval *zobject) {

/* {{{ apc_iterator_item_dtor */
static void apc_iterator_item_dtor(apc_iterator_item_t *item) {
zend_string_release(item->key);
zval_ptr_dtor(&item->value);
efree(item);
}
Expand Down Expand Up @@ -456,7 +457,7 @@ PHP_METHOD(apc_iterator, key) {
item = apc_stack_get(iterator->stack, iterator->stack_idx);

if (item->key) {
RETURN_STR(zend_string_dup(item->key, 0));
RETURN_STR_COPY(item->key);
} else {
RETURN_LONG(iterator->key_idx);
}
Expand Down
2 changes: 0 additions & 2 deletions tests/apc_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ APC: apcu_store/fetch with strings
--INI--
apc.enabled=1
apc.enable_cli=1
apc.file_update_protection=0
--FILE--
<?php
$foo = 'hello world';
Expand All @@ -22,7 +21,6 @@ var_dump($bar);

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
string(11) "hello world"
string(11) "hello world"
Expand Down
2 changes: 0 additions & 2 deletions tests/apc_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ APC: apcu_store/fetch with objects
--INI--
apc.enabled=1
apc.enable_cli=1
apc.file_update_protection=0
--FILE--
<?php

Expand All @@ -21,7 +20,6 @@ var_dump($bar);

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
object(foo)#%d (0) {
}
Expand Down
2 changes: 0 additions & 2 deletions tests/apc_003b.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ APC: apcu_store/fetch with objects
--INI--
apc.enabled=1
apc.enable_cli=1
apc.file_update_protection=0
--FILE--
<?php

Expand Down Expand Up @@ -59,7 +58,6 @@ var_dump(apcu_fetch('baz'));

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
object(foo)#%d (0) {
}
Expand Down
2 changes: 0 additions & 2 deletions tests/apc_004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ APC: apcu_store/fetch with bools
--INI--
apc.enabled=1
apc.enable_cli=1
apc.file_update_protection=0
--FILE--
<?php

Expand All @@ -26,7 +25,6 @@ var_dump($success); /* false */

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
bool(false)
bool(false)
Expand Down
2 changes: 0 additions & 2 deletions tests/apc_005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ APC: apcu_store/fetch with arrays of objects
--INI--
apc.enabled=1
apc.enable_cli=1
apc.file_update_protection=0
--FILE--
<?php

Expand All @@ -21,7 +20,6 @@ var_dump($bar);

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
array(2) {
[0]=>
Expand Down
2 changes: 0 additions & 2 deletions tests/apc_005b.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ APC: apcu_store/fetch with arrays with duplicate object
--INI--
apc.enabled=1
apc.enable_cli=1
apc.file_update_protection=0
--FILE--
<?php

Expand All @@ -22,7 +21,6 @@ var_dump($foo);
var_dump($bar);
?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
array(2) {
[0]=>
Expand Down
2 changes: 0 additions & 2 deletions tests/apc_005c.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ APC: apcu_store/fetch with arrays with two object references
--INI--
apc.enabled=1
apc.enable_cli=1
apc.file_update_protection=0
--FILE--
<?php

Expand All @@ -24,7 +23,6 @@ $bar[0] = 'roh';
var_dump($bar);
?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
array(2) {
[0]=>
Expand Down
1 change: 0 additions & 1 deletion tests/apc_006.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ debug_zval_dump($x);

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
array(9) refcount(2){
[0]=>
Expand Down
1 change: 0 additions & 1 deletion tests/apc_006_php73.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ debug_zval_dump($x);

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
array(9) refcount(2){
[0]=>
Expand Down
2 changes: 0 additions & 2 deletions tests/apc_007.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ APC: apcu_inc/apcu_dec test
--INI--
apc.enabled=1
apc.enable_cli=1
apc.file_update_protection=0
--FILE--
<?php
apcu_store('foobar',2);
Expand All @@ -30,7 +29,6 @@ echo "pass by ref success ". $success . "\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
$foobar = 2
$foobar += 1 = 3
Expand Down
2 changes: 0 additions & 2 deletions tests/apc_008.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ APC: apcu_cas test
--INI--
apc.enabled=1
apc.enable_cli=1
apc.file_update_protection=0
--FILE--
<?php
apcu_store('foobar',2);
Expand All @@ -22,7 +21,6 @@ echo "\$perfection == 2 ? 1 : 2 = ".(apcu_cas('perfection', 2, 1)?"ok":"epic fai
echo "\$foobar = ".apcu_fetch("foobar")."\n";
?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
$foobar = 2
$foobar == 1 ? 2 : 1 = fail
Expand Down
2 changes: 0 additions & 2 deletions tests/apc_010.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ APC: apcu_store/fetch/add with array of key/value pairs.
--INI--
apc.enabled=1
apc.enable_cli=1
apc.file_update_protection=0
--FILE--
<?php

Expand All @@ -29,7 +28,6 @@ var_dump($cached_values);

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
array(0) {
}
Expand Down
2 changes: 0 additions & 2 deletions tests/apc_011.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ APC: apcu_fetch resets array pointers
--INI--
apc.enabled=1
apc.enable_cli=1
apc.file_update_protection=0
--FILE--
<?php
$items = array('bar', 'baz');
Expand All @@ -19,7 +18,6 @@ var_dump(current($back));

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
string(3) "bar"
string(3) "bar"
Expand Down
1 change: 0 additions & 1 deletion tests/apc_012.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ var_dump($j=apcu_fetch($key));
var_dump($i==$j);
?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
int(%d)
bool(true)
Expand Down
1 change: 0 additions & 1 deletion tests/apc_013_exists.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ var_dump(apcu_exists($kno));
var_dump(apcu_exists([$kyes, $kno]));
?>
===DONE===
<?php exit(0); ?>
--EXPECT--
bool(true)
bool(false)
Expand Down
1 change: 0 additions & 1 deletion tests/apc_014_store_ref.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ foreach($_items as $k => $v) {
var_dump(apcu_store($items));
?>
===DONE===
<?php exit(0); ?>
--EXPECT--
array(0) {
}
Expand Down
5 changes: 1 addition & 4 deletions tests/apc_099.phpt
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
--TEST--
APCU: apcu_fetch segfault
--SKIPIF--
<?php
require_once(dirname(__FILE__) . '/skipif.inc');
?>
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--INI--
apc.enabled=1
apc.enable_cli=1
apc.file_update_protection=0
--FILE--
<?php

Expand Down
1 change: 0 additions & 1 deletion tests/apc_entry_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var_dump($value, apcu_entry("test", function($key){
}));
?>
===DONE===
<?php exit(0); ?>
--EXPECT--
string(11) "Hello World"
string(11) "Hello World"
Expand Down
2 changes: 0 additions & 2 deletions tests/apc_inc_perf.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ APC: apcu_inc/apcu_dec performance test (gh#164)
--INI--
apc.enabled=1
apc.enable_cli=1
apc.file_update_protection=0
--FILE--
<?php
apcu_store('foobar', 1);
Expand All @@ -18,7 +17,6 @@ $t = microtime(true) - $t;
var_dump($t < 0.1 ? true : $t);
?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
int(1985229329)
int(1)
Expand Down
1 change: 0 additions & 1 deletion tests/iterator_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ ksort($keys);
var_dump($keys);
?>
===DONE===
<?php exit(0); ?>
--EXPECT--
array(41) {
["key0"]=>
Expand Down
2 changes: 0 additions & 2 deletions tests/iterator_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ APC: APCIterator regex
--INI--
apc.enabled=1
apc.enable_cli=1
apc.file_update_protection=0
--FILE--
<?php
$it = new APCuIterator('/key[0-9]0/');
Expand All @@ -21,7 +20,6 @@ var_dump($vals);

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
array(4) {
["key10"]=>
Expand Down
2 changes: 0 additions & 2 deletions tests/iterator_003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ APC: APCIterator chunk size
--INI--
apc.enabled=1
apc.enable_cli=1
apc.file_update_protection=0
--FILE--
<?php
$it = new APCuIterator(NULL, APC_ITER_ALL, 10);
Expand All @@ -21,7 +20,6 @@ var_dump($vals);

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
array(41) {
["key0"]=>
Expand Down
2 changes: 0 additions & 2 deletions tests/iterator_004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ APC: APCIterator regex & chunk size & list
--INI--
apc.enabled=1
apc.enable_cli=1
apc.file_update_protection=0
--FILE--
<?php
$it = new APCuIterator('/key[0-9]0/', APC_ITER_ALL, 1, APC_LIST_ACTIVE);
Expand All @@ -20,7 +19,6 @@ var_dump($vals);

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
array(4) {
["key10"]=>
Expand Down
1 change: 0 additions & 1 deletion tests/iterator_005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ var_dump($vals2);

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
array(0) {
}
Expand Down
1 change: 0 additions & 1 deletion tests/iterator_006.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ function print_it($it, $idx) {

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
IT #0
============================
Expand Down
2 changes: 0 additions & 2 deletions tests/iterator_008.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ APC: APCIterator array
--INI--
apc.enabled=1
apc.enable_cli=1
apc.file_update_protection=0
--FILE--
<?php
$it = new APCuIterator(['key1', 'key7', 'key9']);
Expand All @@ -21,7 +20,6 @@ var_dump($vals);

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
array(3) {
["key1"]=>
Expand Down
22 changes: 22 additions & 0 deletions tests/iterator_009.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
APC: APCIterator key invalidated between key() calls
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--INI--
apc.enabled=1
apc.enable_cli=1
--FILE--
<?php

apcu_store("foo", 0);
$it = new APCuIterator();
$it->rewind();
var_dump($it->key());
apcu_delete("foo");
apcu_store("bar", 0);
var_dump($it->key());

?>
--EXPECT--
string(3) "foo"
string(3) "foo"