summaryrefslogtreecommitdiff
path: root/ext/spl/spl_heap.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/spl/spl_heap.c')
-rw-r--r--ext/spl/spl_heap.c106
1 files changed, 60 insertions, 46 deletions
diff --git a/ext/spl/spl_heap.c b/ext/spl/spl_heap.c
index ad6d0c933..550b9efce 100644
--- a/ext/spl/spl_heap.c
+++ b/ext/spl/spl_heap.c
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: spl_heap.c,v 1.1.2.13 2008/12/31 11:15:43 sebastian Exp $ */
+/* $Id: spl_heap.c 287266 2009-08-13 22:07:05Z colder $ */
#ifdef HAVE_CONFIG_H
# include "config.h"
@@ -76,6 +76,7 @@ struct _spl_heap_object {
zend_class_entry *ce_get_iterator;
zend_function *fptr_cmp;
zend_function *fptr_count;
+ HashTable *debug_info;
};
/* define an overloaded iterator structure */
@@ -370,6 +371,12 @@ static void spl_heap_object_free_storage(void *object TSRMLS_DC) /* {{{ */
spl_ptr_heap_destroy(intern->heap TSRMLS_CC);
zval_ptr_dtor(&intern->retval);
+
+ if (intern->debug_info != NULL) {
+ zend_hash_destroy(intern->debug_info);
+ efree(intern->debug_info);
+ }
+
efree(object);
}
/* }}} */
@@ -389,8 +396,9 @@ static zend_object_value spl_heap_object_new_ex(zend_class_entry *class_type, sp
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
- intern->flags = 0;
- intern->fptr_cmp = NULL;
+ intern->flags = 0;
+ intern->fptr_cmp = NULL;
+ intern->debug_info = NULL;
if (orig) {
spl_heap_object *other = (spl_heap_object*)zend_object_store_get_object(orig TSRMLS_CC);
@@ -514,43 +522,46 @@ static int spl_heap_object_count_elements(zval *object, long *count TSRMLS_DC) /
static HashTable* spl_heap_object_get_debug_info_helper(zend_class_entry *ce, zval *obj, int *is_temp TSRMLS_DC) { /* {{{ */
spl_heap_object *intern = (spl_heap_object*)zend_object_store_get_object(obj TSRMLS_CC);
- HashTable *rv;
zval *tmp, zrv, *heap_array;
char *pnstr;
int pnlen;
int i;
- *is_temp = 1;
+ *is_temp = 0;
- ALLOC_HASHTABLE(rv);
- ZEND_INIT_SYMTABLE_EX(rv, zend_hash_num_elements(intern->std.properties) + 1, 0);
+ if (intern->debug_info == NULL) {
+ ALLOC_HASHTABLE(intern->debug_info);
+ ZEND_INIT_SYMTABLE_EX(intern->debug_info, zend_hash_num_elements(intern->std.properties) + 1, 0);
+ }
- INIT_PZVAL(&zrv);
- Z_ARRVAL(zrv) = rv;
+ if (intern->debug_info->nApplyCount == 0) {
+ INIT_PZVAL(&zrv);
+ Z_ARRVAL(zrv) = intern->debug_info;
- zend_hash_copy(rv, intern->std.properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
+ zend_hash_copy(intern->debug_info, intern->std.properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
- pnstr = spl_gen_private_prop_name(ce, "flags", sizeof("flags")-1, &pnlen TSRMLS_CC);
- add_assoc_long_ex(&zrv, pnstr, pnlen+1, intern->flags);
- efree(pnstr);
+ pnstr = spl_gen_private_prop_name(ce, "flags", sizeof("flags")-1, &pnlen TSRMLS_CC);
+ add_assoc_long_ex(&zrv, pnstr, pnlen+1, intern->flags);
+ efree(pnstr);
- pnstr = spl_gen_private_prop_name(ce, "isCorrupted", sizeof("isCorrupted")-1, &pnlen TSRMLS_CC);
- add_assoc_bool_ex(&zrv, pnstr, pnlen+1, intern->heap->flags&SPL_HEAP_CORRUPTED);
- efree(pnstr);
+ pnstr = spl_gen_private_prop_name(ce, "isCorrupted", sizeof("isCorrupted")-1, &pnlen TSRMLS_CC);
+ add_assoc_bool_ex(&zrv, pnstr, pnlen+1, intern->heap->flags&SPL_HEAP_CORRUPTED);
+ efree(pnstr);
- ALLOC_INIT_ZVAL(heap_array);
- array_init(heap_array);
+ ALLOC_INIT_ZVAL(heap_array);
+ array_init(heap_array);
- for (i = 0; i < intern->heap->count; ++i) {
- add_index_zval(heap_array, i, (zval *)intern->heap->elements[i]);
- Z_ADDREF_P(intern->heap->elements[i]);
- }
+ for (i = 0; i < intern->heap->count; ++i) {
+ add_index_zval(heap_array, i, (zval *)intern->heap->elements[i]);
+ Z_ADDREF_P(intern->heap->elements[i]);
+ }
- pnstr = spl_gen_private_prop_name(ce, "heap", sizeof("heap")-1, &pnlen TSRMLS_CC);
- add_assoc_zval_ex(&zrv, pnstr, pnlen+1, heap_array);
- efree(pnstr);
+ pnstr = spl_gen_private_prop_name(ce, "heap", sizeof("heap")-1, &pnlen TSRMLS_CC);
+ add_assoc_zval_ex(&zrv, pnstr, pnlen+1, heap_array);
+ efree(pnstr);
+ }
- return rv;
+ return intern->debug_info;
}
/* }}} */
@@ -1128,6 +1139,9 @@ ZEND_BEGIN_ARG_INFO(arginfo_pqueue_setflags, 0)
ZEND_ARG_INFO(0, flags)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO(arginfo_splheap_void, 0)
+ZEND_END_ARG_INFO()
+
static const zend_function_entry spl_funcs_SplMinHeap[] = {
SPL_ME(SplMinHeap, compare, arginfo_heap_compare, ZEND_ACC_PROTECTED)
{NULL, NULL, NULL}
@@ -1141,31 +1155,31 @@ 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, top, NULL, ZEND_ACC_PUBLIC)
- SPL_ME(SplPriorityQueue, extract, NULL, ZEND_ACC_PUBLIC)
- SPL_ME(SplHeap, count, NULL, ZEND_ACC_PUBLIC)
- SPL_ME(SplHeap, isEmpty, NULL, ZEND_ACC_PUBLIC)
- SPL_ME(SplHeap, rewind, NULL, ZEND_ACC_PUBLIC)
- SPL_ME(SplPriorityQueue, current, NULL, ZEND_ACC_PUBLIC)
- SPL_ME(SplHeap, key, NULL, ZEND_ACC_PUBLIC)
- SPL_ME(SplHeap, next, NULL, ZEND_ACC_PUBLIC)
- SPL_ME(SplHeap, valid, NULL, ZEND_ACC_PUBLIC)
- SPL_ME(SplHeap, recoverFromCorruption, NULL, 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)
+ SPL_ME(SplHeap, isEmpty, arginfo_splheap_void, ZEND_ACC_PUBLIC)
+ SPL_ME(SplHeap, rewind, arginfo_splheap_void, ZEND_ACC_PUBLIC)
+ SPL_ME(SplPriorityQueue, current, arginfo_splheap_void, ZEND_ACC_PUBLIC)
+ SPL_ME(SplHeap, key, arginfo_splheap_void, ZEND_ACC_PUBLIC)
+ 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)
{NULL, NULL, NULL}
};
static const zend_function_entry spl_funcs_SplHeap[] = {
- SPL_ME(SplHeap, extract, NULL, ZEND_ACC_PUBLIC)
+ SPL_ME(SplHeap, extract, arginfo_splheap_void, ZEND_ACC_PUBLIC)
SPL_ME(SplHeap, insert, arginfo_heap_insert, ZEND_ACC_PUBLIC)
- SPL_ME(SplHeap, top, NULL, ZEND_ACC_PUBLIC)
- SPL_ME(SplHeap, count, NULL, ZEND_ACC_PUBLIC)
- SPL_ME(SplHeap, isEmpty, NULL, ZEND_ACC_PUBLIC)
- SPL_ME(SplHeap, rewind, NULL, ZEND_ACC_PUBLIC)
- SPL_ME(SplHeap, current, NULL, ZEND_ACC_PUBLIC)
- SPL_ME(SplHeap, key, NULL, ZEND_ACC_PUBLIC)
- SPL_ME(SplHeap, next, NULL, ZEND_ACC_PUBLIC)
- SPL_ME(SplHeap, valid, NULL, ZEND_ACC_PUBLIC)
- SPL_ME(SplHeap, recoverFromCorruption, NULL, ZEND_ACC_PUBLIC)
+ SPL_ME(SplHeap, top, arginfo_splheap_void, ZEND_ACC_PUBLIC)
+ SPL_ME(SplHeap, count, arginfo_splheap_void, ZEND_ACC_PUBLIC)
+ SPL_ME(SplHeap, isEmpty, arginfo_splheap_void, ZEND_ACC_PUBLIC)
+ SPL_ME(SplHeap, rewind, arginfo_splheap_void, ZEND_ACC_PUBLIC)
+ SPL_ME(SplHeap, current, arginfo_splheap_void, ZEND_ACC_PUBLIC)
+ SPL_ME(SplHeap, key, arginfo_splheap_void, ZEND_ACC_PUBLIC)
+ 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)
ZEND_FENTRY(compare, NULL, NULL, ZEND_ACC_PROTECTED|ZEND_ACC_ABSTRACT)
{NULL, NULL, NULL}
};