summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorJulien Pauli <jpauli@php.net>2014-08-25 18:32:40 +0200
committerJulien Pauli <jpauli@php.net>2014-08-26 10:02:55 +0200
commit0686b4448d7382fcda4e03b8561eaf1b6d990644 (patch)
treebb135aa5079a803c82231a5646c74a5dc15c30d9 /ext
parent5d062b61607e79a989899af150bc5f3aae377afe (diff)
downloadphp-git-0686b4448d7382fcda4e03b8561eaf1b6d990644.tar.gz
implement #67886
Diffstat (limited to 'ext')
-rw-r--r--ext/spl/spl_heap.c38
-rw-r--r--ext/spl/tests/heap_corruption.phpt10
-rw-r--r--ext/spl/tests/spl_pq_top_basic.phpt6
3 files changed, 52 insertions, 2 deletions
diff --git a/ext/spl/spl_heap.c b/ext/spl/spl_heap.c
index b0f06ada69..97d95d2acf 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 284ee1db81..5e9dec7855 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 dcc1cbe4c0..14e0af51cb 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