com php-src: implement #67886: NEWS ext/spl/spl_heap.c ex t/spl/tests/heap_corruption.phpt ext/spl/tests/spl_pq _top_basic.phpt
| From: | JulienPauli | Date: | Tue, 26 Aug 2014 08:02:55 +0000 |
| Subject: | com php-src: implement #67886: NEWS ext/spl/spl_heap.c ex t/spl/tests/heap_corruption.phpt ext/spl/tests/spl_pq _top_basic.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-81116@lists.php.net to get a copy of this message | ||
Commit: 0686b4448d7382fcda4e03b8561eaf1b6d990644
Author: Julien Pauli <jpauli@php.net> Mon, 25 Aug 2014 18:32:40 +0200
Parents: 5d062b61607e79a989899af150bc5f3aae377afe
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=0686b4448d7382fcda4e03b8561eaf1b6d990644
Log:
implement #67886
Bugs:
https://bugs.php.net/67886
Changed paths:
M NEWS
M ext/spl/spl_heap.c
M ext/spl/tests/heap_corruption.phpt
M ext/spl/tests/spl_pq_top_basic.phpt
Diff:
diff --git a/NEWS b/NEWS
index 16d8b26..74dd688 100644
--- a/NEWS
+++ b/NEWS
@@ -34,4 +34,8 @@ PHP NEWS
- Session:
. Fixed bug #67694 (Regression in session_regenerate_id()). (Tjerk)
+- SPL:
+ . Implemented #67886 (SplPriorityQueue/SplHeap doesn't expose extractFlags
+ nor curruption state). (Julien)
+
<<< NOTE: Insert NEWS from last stable release here prior to actual release! >>>
diff --git a/ext/spl/spl_heap.c b/ext/spl/spl_heap.c
index b0f06ad..97d95d2 100644
--- a/ext/spl/spl_heap.c
+++ b/ext/spl/spl_heap.c
@@ -761,7 +761,8 @@ SPL_METHOD(SplPriorityQueue, top)
}
/* }}} */
-/* {{{ proto int SplPriorityQueue::setIteratorMode($flags)
+
+/* {{{ proto int SplPriorityQueue::setExtractFlags($flags)
Set the flags of extraction*/
SPL_METHOD(SplPriorityQueue, setExtractFlags)
{
@@ -780,6 +781,22 @@ SPL_METHOD(SplPriorityQueue, setExtractFlags)
}
/* }}} */
+/* {{{ proto int SplPriorityQueue::getExtractFlags()
+ Get the flags of extraction*/
+SPL_METHOD(SplPriorityQueue, getExtractFlags)
+{
+ spl_heap_object *intern;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ intern = Z_SPLHEAP_P(getThis());
+
+ RETURN_LONG(intern->flags);
+}
+/* }}} */
+
/* {{{ proto int SplHeap::recoverFromCorruption()
Recover from a corrupted state*/
SPL_METHOD(SplHeap, recoverFromCorruption)
@@ -798,6 +815,22 @@ SPL_METHOD(SplHeap, recoverFromCorruption)
}
/* }}} */
+/* {{{ proto int SplHeap::isCorrupted()
+ Tells if the heap is in a corrupted state*/
+SPL_METHOD(SplHeap, isCorrupted)
+{
+ spl_heap_object *intern;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ intern = Z_SPLHEAP_P(getThis());
+
+ RETURN_BOOL(intern->heap->flags & SPL_HEAP_CORRUPTED);
+}
+/* }}} */
+
/* {{{ proto bool SplPriorityQueue::compare(mixed $a, mixed $b)
compare the priorities */
SPL_METHOD(SplPriorityQueue, compare)
@@ -1158,6 +1191,7 @@ static const zend_function_entry spl_funcs_SplPriorityQueue[] = {
SPL_ME(SplPriorityQueue, compare, arginfo_heap_compare, ZEND_ACC_PUBLIC)
SPL_ME(SplPriorityQueue, insert, arginfo_pqueue_insert, ZEND_ACC_PUBLIC)
SPL_ME(SplPriorityQueue, setExtractFlags, arginfo_pqueue_setflags, ZEND_ACC_PUBLIC)
+ SPL_ME(SplPriorityQueue, getExtractFlags, arginfo_splheap_void, ZEND_ACC_PUBLIC)
SPL_ME(SplPriorityQueue, top, arginfo_splheap_void, ZEND_ACC_PUBLIC)
SPL_ME(SplPriorityQueue, extract, arginfo_splheap_void, ZEND_ACC_PUBLIC)
SPL_ME(SplHeap, count, arginfo_splheap_void, ZEND_ACC_PUBLIC)
@@ -1168,6 +1202,7 @@ static const zend_function_entry spl_funcs_SplPriorityQueue[] = {
SPL_ME(SplHeap, next, arginfo_splheap_void, ZEND_ACC_PUBLIC)
SPL_ME(SplHeap, valid, arginfo_splheap_void, ZEND_ACC_PUBLIC)
SPL_ME(SplHeap, recoverFromCorruption, arginfo_splheap_void, ZEND_ACC_PUBLIC)
+ SPL_ME(SplHeap, isCorrupted, arginfo_splheap_void, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL}
};
@@ -1183,6 +1218,7 @@ static const zend_function_entry spl_funcs_SplHeap[] = {
SPL_ME(SplHeap, next, arginfo_splheap_void, ZEND_ACC_PUBLIC)
SPL_ME(SplHeap, valid, arginfo_splheap_void, ZEND_ACC_PUBLIC)
SPL_ME(SplHeap, recoverFromCorruption, arginfo_splheap_void, ZEND_ACC_PUBLIC)
+ SPL_ME(SplHeap, isCorrupted, arginfo_splheap_void, ZEND_ACC_PUBLIC)
ZEND_FENTRY(compare, NULL, NULL, ZEND_ACC_PROTECTED|ZEND_ACC_ABSTRACT)
{NULL, NULL, NULL}
};
diff --git a/ext/spl/tests/heap_corruption.phpt b/ext/spl/tests/heap_corruption.phpt
index 284ee1d..5e9dec7 100644
--- a/ext/spl/tests/heap_corruption.phpt
+++ b/ext/spl/tests/heap_corruption.phpt
@@ -42,6 +42,8 @@ $heap->insert(4);
$heap->allow_compare = false;
+var_dump($heap->isCorrupted());
+
try {
$heap->extract();
}
@@ -56,7 +58,13 @@ catch (Exception $e) {
echo "Corruption Exception: " . $e->getMessage() . PHP_EOL;
}
+var_dump($heap->isCorrupted());
+$heap->recoverFromCorruption();
+var_dump($heap->isCorrupted());
?>
--EXPECT--
+bool(false)
Compare Exception: Compare exception
-Corruption Exception: Heap is corrupted, heap properties are no longer ensured.
\ No newline at end of file
+Corruption Exception: Heap is corrupted, heap properties are no longer ensured.
+bool(true)
+bool(false)
\ No newline at end of file
diff --git a/ext/spl/tests/spl_pq_top_basic.phpt b/ext/spl/tests/spl_pq_top_basic.phpt
index dcc1cbe..14e0af5 100644
--- a/ext/spl/tests/spl_pq_top_basic.phpt
+++ b/ext/spl/tests/spl_pq_top_basic.phpt
@@ -8,6 +8,8 @@ Nathaniel McHugh nat@fishtrap.co.uk
$priorityQueue = new SplPriorityQueue();
+var_dump($priorityQueue->getExtractFlags());
+
$priorityQueue->insert("a", 1);
$priorityQueue->insert("b", 2);
$priorityQueue->insert("c", 0);
@@ -16,6 +18,8 @@ echo "EXTR DEFAULT",PHP_EOL;
echo "value: ",$priorityQueue->top(),PHP_EOL;
$priorityQueue->setExtractFlags(SplPriorityQueue::EXTR_PRIORITY);
+var_dump($priorityQueue->getExtractFlags() & SplPriorityQueue::EXTR_PRIORITY);
+
echo "EXTR_PRIORITY",PHP_EOL;
echo "priority: ",$priorityQueue->top(),PHP_EOL;
@@ -28,8 +32,10 @@ $priorityQueue->setExtractFlags(SplPriorityQueue::EXTR_DATA);
echo "value: ",$priorityQueue->top(),PHP_EOL;
?>
--EXPECT--
+int(1)
EXTR DEFAULT
value: b
+int(2)
EXTR_PRIORITY
priority: 2
EXTR_BOTH