summaryrefslogtreecommitdiff
path: root/ext/spl
diff options
context:
space:
mode:
authorXinchen Hui <laruence@php.net>2012-05-24 23:20:21 +0800
committerXinchen Hui <laruence@php.net>2012-05-24 23:31:05 +0800
commitbde86a6639a661dcadb0ae4c3ce4cc8aca2a42b9 (patch)
tree19336350f59a9f4334c025194d94efa6af4e1be0 /ext/spl
parent85c777d2f1d5a12fac0100f4953d33a7380d0b03 (diff)
parent9205c4fd62a769b7db3d00eccdf2ea35b20dd87f (diff)
downloadphp-git-bde86a6639a661dcadb0ae4c3ce4cc8aca2a42b9.tar.gz
Fixed bug #62073
(Different ways of iterating over an SplMaxHeap result in in different keys)
Diffstat (limited to 'ext/spl')
-rw-r--r--ext/spl/spl_heap.c2
-rw-r--r--ext/spl/tests/bug62073.phpt22
-rw-r--r--ext/spl/tests/heap_005.phpt200
-rw-r--r--ext/spl/tests/heap_006.phpt200
-rw-r--r--ext/spl/tests/pqueue_001.phpt24
5 files changed, 235 insertions, 213 deletions
diff --git a/ext/spl/spl_heap.c b/ext/spl/spl_heap.c
index e2b8f75b0b..a0055f410d 100644
--- a/ext/spl/spl_heap.c
+++ b/ext/spl/spl_heap.c
@@ -950,7 +950,7 @@ static int spl_heap_it_get_current_key(zend_object_iterator *iter, char **str_ke
{
spl_heap_it *iterator = (spl_heap_it *)iter;
- *int_key = (ulong) iterator->object->heap->count;
+ *int_key = (ulong) iterator->object->heap->count - 1;
return HASH_KEY_IS_LONG;
}
/* }}} */
diff --git a/ext/spl/tests/bug62073.phpt b/ext/spl/tests/bug62073.phpt
new file mode 100644
index 0000000000..3bd355317f
--- /dev/null
+++ b/ext/spl/tests/bug62073.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Bug #62073 (different ways of iterating over an SplMaxHeap result in different keys)
+--FILE--
+<?php
+$heap = new SplMaxHeap();
+$heap->insert(42);
+foreach ($heap as $key => $value) {
+ var_dump($key);
+ var_dump($value);
+ break;
+}
+
+$heap = new SplMaxHeap();
+$heap->insert(42);
+var_dump($heap->key());
+var_dump($heap->current());
+?>
+--EXPECT--
+int(0)
+int(42)
+int(0)
+int(42)
diff --git a/ext/spl/tests/heap_005.phpt b/ext/spl/tests/heap_005.phpt
index 73daaf454a..1291cda770 100644
--- a/ext/spl/tests/heap_005.phpt
+++ b/ext/spl/tests/heap_005.phpt
@@ -18,104 +18,104 @@ foreach ($h as $k => $o) {
===DONE===
<?php exit(0); ?>
--EXPECTF--
-100 => 1
-99 => 2
-98 => 3
-97 => 4
-96 => 5
-95 => 6
-94 => 7
-93 => 8
-92 => 9
-91 => 10
-90 => 11
-89 => 12
-88 => 13
-87 => 14
-86 => 15
-85 => 16
-84 => 17
-83 => 18
-82 => 19
-81 => 20
-80 => 21
-79 => 22
-78 => 23
-77 => 24
-76 => 25
-75 => 26
-74 => 27
-73 => 28
-72 => 29
-71 => 30
-70 => 31
-69 => 32
-68 => 33
-67 => 34
-66 => 35
-65 => 36
-64 => 37
-63 => 38
-62 => 39
-61 => 40
-60 => 41
-59 => 42
-58 => 43
-57 => 44
-56 => 45
-55 => 46
-54 => 47
-53 => 48
-52 => 49
-51 => 50
-50 => 51
-49 => 52
-48 => 53
-47 => 54
-46 => 55
-45 => 56
-44 => 57
-43 => 58
-42 => 59
-41 => 60
-40 => 61
-39 => 62
-38 => 63
-37 => 64
-36 => 65
-35 => 66
-34 => 67
-33 => 68
-32 => 69
-31 => 70
-30 => 71
-29 => 72
-28 => 73
-27 => 74
-26 => 75
-25 => 76
-24 => 77
-23 => 78
-22 => 79
-21 => 80
-20 => 81
-19 => 82
-18 => 83
-17 => 84
-16 => 85
-15 => 86
-14 => 87
-13 => 88
-12 => 89
-11 => 90
-10 => 91
-9 => 92
-8 => 93
-7 => 94
-6 => 95
-5 => 96
-4 => 97
-3 => 98
-2 => 99
-1 => 100
+99 => 1
+98 => 2
+97 => 3
+96 => 4
+95 => 5
+94 => 6
+93 => 7
+92 => 8
+91 => 9
+90 => 10
+89 => 11
+88 => 12
+87 => 13
+86 => 14
+85 => 15
+84 => 16
+83 => 17
+82 => 18
+81 => 19
+80 => 20
+79 => 21
+78 => 22
+77 => 23
+76 => 24
+75 => 25
+74 => 26
+73 => 27
+72 => 28
+71 => 29
+70 => 30
+69 => 31
+68 => 32
+67 => 33
+66 => 34
+65 => 35
+64 => 36
+63 => 37
+62 => 38
+61 => 39
+60 => 40
+59 => 41
+58 => 42
+57 => 43
+56 => 44
+55 => 45
+54 => 46
+53 => 47
+52 => 48
+51 => 49
+50 => 50
+49 => 51
+48 => 52
+47 => 53
+46 => 54
+45 => 55
+44 => 56
+43 => 57
+42 => 58
+41 => 59
+40 => 60
+39 => 61
+38 => 62
+37 => 63
+36 => 64
+35 => 65
+34 => 66
+33 => 67
+32 => 68
+31 => 69
+30 => 70
+29 => 71
+28 => 72
+27 => 73
+26 => 74
+25 => 75
+24 => 76
+23 => 77
+22 => 78
+21 => 79
+20 => 80
+19 => 81
+18 => 82
+17 => 83
+16 => 84
+15 => 85
+14 => 86
+13 => 87
+12 => 88
+11 => 89
+10 => 90
+9 => 91
+8 => 92
+7 => 93
+6 => 94
+5 => 95
+4 => 96
+3 => 97
+2 => 98
+1 => 99
+0 => 100
===DONE===
diff --git a/ext/spl/tests/heap_006.phpt b/ext/spl/tests/heap_006.phpt
index 4422727d04..3218bdfb16 100644
--- a/ext/spl/tests/heap_006.phpt
+++ b/ext/spl/tests/heap_006.phpt
@@ -18,104 +18,104 @@ foreach ($h as $k => $o) {
===DONE===
<?php exit(0); ?>
--EXPECTF--
-100 => 100
-99 => 99
-98 => 98
-97 => 97
-96 => 96
-95 => 95
-94 => 94
-93 => 93
-92 => 92
-91 => 91
-90 => 90
-89 => 89
-88 => 88
-87 => 87
-86 => 86
-85 => 85
-84 => 84
-83 => 83
-82 => 82
-81 => 81
-80 => 80
-79 => 79
-78 => 78
-77 => 77
-76 => 76
-75 => 75
-74 => 74
-73 => 73
-72 => 72
-71 => 71
-70 => 70
-69 => 69
-68 => 68
-67 => 67
-66 => 66
-65 => 65
-64 => 64
-63 => 63
-62 => 62
-61 => 61
-60 => 60
-59 => 59
-58 => 58
-57 => 57
-56 => 56
-55 => 55
-54 => 54
-53 => 53
-52 => 52
-51 => 51
-50 => 50
-49 => 49
-48 => 48
-47 => 47
-46 => 46
-45 => 45
-44 => 44
-43 => 43
-42 => 42
-41 => 41
-40 => 40
-39 => 39
-38 => 38
-37 => 37
-36 => 36
-35 => 35
-34 => 34
-33 => 33
-32 => 32
-31 => 31
-30 => 30
-29 => 29
-28 => 28
-27 => 27
-26 => 26
-25 => 25
-24 => 24
-23 => 23
-22 => 22
-21 => 21
-20 => 20
-19 => 19
-18 => 18
-17 => 17
-16 => 16
-15 => 15
-14 => 14
-13 => 13
-12 => 12
-11 => 11
-10 => 10
-9 => 9
-8 => 8
-7 => 7
-6 => 6
-5 => 5
-4 => 4
-3 => 3
-2 => 2
-1 => 1
+99 => 100
+98 => 99
+97 => 98
+96 => 97
+95 => 96
+94 => 95
+93 => 94
+92 => 93
+91 => 92
+90 => 91
+89 => 90
+88 => 89
+87 => 88
+86 => 87
+85 => 86
+84 => 85
+83 => 84
+82 => 83
+81 => 82
+80 => 81
+79 => 80
+78 => 79
+77 => 78
+76 => 77
+75 => 76
+74 => 75
+73 => 74
+72 => 73
+71 => 72
+70 => 71
+69 => 70
+68 => 69
+67 => 68
+66 => 67
+65 => 66
+64 => 65
+63 => 64
+62 => 63
+61 => 62
+60 => 61
+59 => 60
+58 => 59
+57 => 58
+56 => 57
+55 => 56
+54 => 55
+53 => 54
+52 => 53
+51 => 52
+50 => 51
+49 => 50
+48 => 49
+47 => 48
+46 => 47
+45 => 46
+44 => 45
+43 => 44
+42 => 43
+41 => 42
+40 => 41
+39 => 40
+38 => 39
+37 => 38
+36 => 37
+35 => 36
+34 => 35
+33 => 34
+32 => 33
+31 => 32
+30 => 31
+29 => 30
+28 => 29
+27 => 28
+26 => 27
+25 => 26
+24 => 25
+23 => 24
+22 => 23
+21 => 22
+20 => 21
+19 => 20
+18 => 19
+17 => 18
+16 => 17
+15 => 16
+14 => 15
+13 => 14
+12 => 13
+11 => 12
+10 => 11
+9 => 10
+8 => 9
+7 => 8
+6 => 7
+5 => 6
+4 => 5
+3 => 4
+2 => 3
+1 => 2
+0 => 1
===DONE===
diff --git a/ext/spl/tests/pqueue_001.phpt b/ext/spl/tests/pqueue_001.phpt
index 9c299808f2..de164e549a 100644
--- a/ext/spl/tests/pqueue_001.phpt
+++ b/ext/spl/tests/pqueue_001.phpt
@@ -63,34 +63,34 @@ foreach ($pq3 as $k=>$v) {
<?php exit(0); ?>
--EXPECTF--
Exception: Can't extract from an empty heap
-3=>b
-2=>a
-1=>c
+2=>b
+1=>a
+0=>c
EXTR_BOTH
-3=>Array
+2=>Array
(
[data] => b
[priority] => 2
)
-2=>Array
+1=>Array
(
[data] => a
[priority] => 1
)
-1=>Array
+0=>Array
(
[data] => c
[priority] => 0
)
EXTR_DATA
-3=>b
-2=>a
-1=>c
+2=>b
+1=>a
+0=>c
EXTR_PRIORITY
-3=>2
-2=>1
-1=>0
+2=>2
+1=>1
+0=>0
===DONE===