From: Julien Pauli Date: Mon, 25 Aug 2014 16:32:40 +0000 (+0200) Subject: implement #67886 X-Git-Tag: PRE_PHP7_REMOVALS~309 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0686b4448d7382fcda4e03b8561eaf1b6d990644;p=php implement #67886 --- diff --git a/NEWS b/NEWS index 16d8b26b2d..74dd688838 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 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