#define zend_hash_move_backwards(ht) \
zend_hash_move_backwards_ex(ht, NULL)
#define zend_hash_get_current_key(ht, str_index, num_index, duplicate) \
- zend_hash_get_current_key_ex(ht, str_index, NULL, num_index, duplicate, NULL)
+ zend_hash_get_current_key_ex(ht, str_index, num_index, duplicate, NULL)
#define zend_hash_get_current_key_zval(ht, key) \
zend_hash_get_current_key_zval_ex(ht, key, NULL)
#define zend_hash_get_current_key_type(ht) \
struct _spl_ptr_llist_element *prev;
struct _spl_ptr_llist_element *next;
int rc;
- void *data;
+ zval data;
} spl_ptr_llist_element;
typedef void (*spl_ptr_llist_dtor_func)(spl_ptr_llist_element * TSRMLS_DC);
spl_ptr_llist *llist;
int traverse_position;
spl_ptr_llist_element *traverse_pointer;
- zval *retval;
+ zval retval;
int flags;
zend_function *fptr_offset_get;
zend_function *fptr_offset_set;
/* {{{ spl_ptr_llist */
static void spl_ptr_llist_zval_dtor(spl_ptr_llist_element *elem TSRMLS_DC) { /* {{{ */
- if (elem->data) {
- zval_ptr_dtor((zval **)&elem->data);
+ if (!ZVAL_IS_UNDEF(&elem->data)) {
+ zval_ptr_dtor(&elem->data);
+ ZVAL_UNDEF(&elem->data);
}
}
/* }}} */
static void spl_ptr_llist_zval_ctor(spl_ptr_llist_element *elem TSRMLS_DC) { /* {{{ */
- Z_ADDREF_P((zval *)elem->data);
+ Z_ADDREF_P(&elem->data);
}
/* }}} */
}
/* }}} */
-static void spl_ptr_llist_unshift(spl_ptr_llist *llist, void *data TSRMLS_DC) /* {{{ */
+static void spl_ptr_llist_unshift(spl_ptr_llist *llist, zval *data TSRMLS_DC) /* {{{ */
{
spl_ptr_llist_element *elem = emalloc(sizeof(spl_ptr_llist_element));
- elem->data = data;
elem->rc = 1;
elem->prev = NULL;
elem->next = llist->head;
+ ZVAL_COPY_VALUE(&elem->data, data);
if (llist->head) {
llist->head->prev = elem;
}
/* }}} */
-static void spl_ptr_llist_push(spl_ptr_llist *llist, void *data TSRMLS_DC) /* {{{ */
+static void spl_ptr_llist_push(spl_ptr_llist *llist, zval *data TSRMLS_DC) /* {{{ */
{
spl_ptr_llist_element *elem = emalloc(sizeof(spl_ptr_llist_element));
- elem->data = data;
elem->rc = 1;
elem->prev = llist->tail;
elem->next = NULL;
+ ZVAL_COPY_VALUE(&elem->data, data);
if (llist->tail) {
llist->tail->next = elem;
}
/* }}} */
-static void *spl_ptr_llist_pop(spl_ptr_llist *llist TSRMLS_DC) /* {{{ */
+static void spl_ptr_llist_pop(spl_ptr_llist *llist, zval *ret TSRMLS_DC) /* {{{ */
{
- void *data;
spl_ptr_llist_element *tail = llist->tail;
if (tail == NULL) {
- return NULL;
+ ZVAL_UNDEF(ret);
+ return;
}
if (tail->prev) {
llist->tail = tail->prev;
llist->count--;
- data = tail->data;
+ ZVAL_COPY(ret, &tail->data);
if (llist->dtor) {
llist->dtor(tail TSRMLS_CC);
}
- tail->data = NULL;
+ ZVAL_UNDEF(&tail->data);
SPL_LLIST_DELREF(tail);
-
- return data;
}
/* }}} */
-static void *spl_ptr_llist_last(spl_ptr_llist *llist) /* {{{ */
+static zval *spl_ptr_llist_last(spl_ptr_llist *llist) /* {{{ */
{
spl_ptr_llist_element *tail = llist->tail;
if (tail == NULL) {
return NULL;
} else {
- return tail->data;
+ return &tail->data;
}
}
/* }}} */
-static void *spl_ptr_llist_first(spl_ptr_llist *llist) /* {{{ */
+static zval *spl_ptr_llist_first(spl_ptr_llist *llist) /* {{{ */
{
spl_ptr_llist_element *head = llist->head;
if (head == NULL) {
return NULL;
} else {
- return head->data;
+ return &head->data;
}
}
/* }}} */
-static void *spl_ptr_llist_shift(spl_ptr_llist *llist TSRMLS_DC) /* {{{ */
+static void spl_ptr_llist_shift(spl_ptr_llist *llist, zval *ret TSRMLS_DC) /* {{{ */
{
- void *data;
spl_ptr_llist_element *head = llist->head;
if (head == NULL) {
- return NULL;
+ ZVAL_UNDEF(ret);
+ return;
}
if (head->next) {
llist->head = head->next;
llist->count--;
- data = head->data;
+ ZVAL_COPY(ret, &head->data);
if (llist->dtor) {
llist->dtor(head TSRMLS_CC);
}
- head->data = NULL;
+ ZVAL_UNDEF(&head->data);
SPL_LLIST_DELREF(head);
-
- return data;
}
/* }}} */
while (current) {
next = current->next;
+ /*!! FIXME
if (ctor) {
ctor(current TSRMLS_CC);
}
+ */
- spl_ptr_llist_push(to, current->data TSRMLS_CC);
+ spl_ptr_llist_push(to, ¤t->data TSRMLS_CC);
current = next;
}
/* }}} */
-static void spl_dllist_object_free_storage(void *object TSRMLS_DC) /* {{{ */
+static void spl_dllist_object_free_storage(zend_object *object TSRMLS_DC) /* {{{ */
{
spl_dllist_object *intern = (spl_dllist_object *)object;
- zval *tmp = NULL;
+ zval tmp;
zend_object_std_dtor(&intern->std TSRMLS_CC);
- while(intern->llist->count > 0) {
- tmp = (zval *)spl_ptr_llist_pop(intern->llist TSRMLS_CC);
+ while (intern->llist->count > 0) {
+ spl_ptr_llist_pop(intern->llist, &tmp TSRMLS_CC);
zval_ptr_dtor(&tmp);
}
zend_object_iterator *spl_dllist_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC);
-static zend_object_value spl_dllist_object_new_ex(zend_class_entry *class_type, spl_dllist_object **obj, zval *orig, int clone_orig TSRMLS_DC) /* {{{ */
+static zend_object *spl_dllist_object_new_ex(zend_class_entry *class_type, zval *orig, int clone_orig TSRMLS_DC) /* {{{ */
{
- zend_object_value retval = {0};
spl_dllist_object *intern;
zend_class_entry *parent = class_type;
int inherited = 0;
intern = ecalloc(1, sizeof(spl_dllist_object));
- *obj = intern;
- ALLOC_INIT_ZVAL(intern->retval);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
intern->debug_info = NULL;
if (orig) {
- spl_dllist_object *other = (spl_dllist_object*)zend_object_store_get_object(orig TSRMLS_CC);
+ spl_dllist_object *other = (spl_dllist_object*)Z_OBJ_P(orig);
intern->ce_get_iterator = other->ce_get_iterator;
if (clone_orig) {
while (parent) {
if (parent == spl_ce_SplStack) {
intern->flags |= (SPL_DLLIST_IT_FIX | SPL_DLLIST_IT_LIFO);
- retval.handlers = &spl_handler_SplDoublyLinkedList;
+ intern->std.handlers = &spl_handler_SplDoublyLinkedList;
} else if (parent == spl_ce_SplQueue) {
intern->flags |= SPL_DLLIST_IT_FIX;
- retval.handlers = &spl_handler_SplDoublyLinkedList;
+ intern->std.handlers = &spl_handler_SplDoublyLinkedList;
}
if (parent == spl_ce_SplDoublyLinkedList) {
- retval.handlers = &spl_handler_SplDoublyLinkedList;
+ intern->std.handlers = &spl_handler_SplDoublyLinkedList;
break;
}
inherited = 1;
}
- retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, spl_dllist_object_free_storage, NULL TSRMLS_CC);
+ zend_objects_store_put(&intern->std);
if (!parent) { /* this must never happen */
php_error_docref(NULL TSRMLS_CC, E_COMPILE_ERROR, "Internal compiler error, Class is not child of SplDoublyLinkedList");
}
if (inherited) {
- zend_hash_find(&class_type->function_table, "offsetget", sizeof("offsetget"), (void **) &intern->fptr_offset_get);
+ intern->fptr_offset_get = zend_hash_str_find_ptr(&class_type->function_table, "offsetget", sizeof("offsetget") - 1);
if (intern->fptr_offset_get->common.scope == parent) {
intern->fptr_offset_get = NULL;
}
- zend_hash_find(&class_type->function_table, "offsetset", sizeof("offsetset"), (void **) &intern->fptr_offset_set);
+ intern->fptr_offset_set = zend_hash_str_find_ptr(&class_type->function_table, "offsetset", sizeof("offsetset") - 1);
if (intern->fptr_offset_set->common.scope == parent) {
intern->fptr_offset_set = NULL;
}
- zend_hash_find(&class_type->function_table, "offsetexists", sizeof("offsetexists"), (void **) &intern->fptr_offset_has);
+ intern->fptr_offset_has = zend_hash_str_find_ptr(&class_type->function_table, "offsetexists", sizeof("offsetexists") - 1);
if (intern->fptr_offset_has->common.scope == parent) {
intern->fptr_offset_has = NULL;
}
- zend_hash_find(&class_type->function_table, "offsetunset", sizeof("offsetunset"), (void **) &intern->fptr_offset_del);
+ intern->fptr_offset_del = zend_hash_str_find_ptr(&class_type->function_table, "offsetunset", sizeof("offsetunset") - 1);
if (intern->fptr_offset_del->common.scope == parent) {
intern->fptr_offset_del = NULL;
}
- zend_hash_find(&class_type->function_table, "count", sizeof("count"), (void **) &intern->fptr_count);
+ intern->fptr_count = zend_hash_str_find_ptr(&class_type->function_table, "count", sizeof("count") - 1);
if (intern->fptr_count->common.scope == parent) {
intern->fptr_count = NULL;
}
}
- return retval;
+ return &intern->std;
}
/* }}} */
-static zend_object_value spl_dllist_object_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
+static zend_object *spl_dllist_object_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
- spl_dllist_object *tmp;
- return spl_dllist_object_new_ex(class_type, &tmp, NULL, 0 TSRMLS_CC);
+ return spl_dllist_object_new_ex(class_type, NULL, 0 TSRMLS_CC);
}
/* }}} */
-static zend_object_value spl_dllist_object_clone(zval *zobject TSRMLS_DC) /* {{{ */
+static zend_object *spl_dllist_object_clone(zval *zobject TSRMLS_DC) /* {{{ */
{
- zend_object_value new_obj_val;
zend_object *old_object;
zend_object *new_object;
- zend_object_handle handle = Z_OBJ_HANDLE_P(zobject);
- spl_dllist_object *intern;
- old_object = zend_objects_get_address(zobject TSRMLS_CC);
- new_obj_val = spl_dllist_object_new_ex(old_object->ce, &intern, zobject, 1 TSRMLS_CC);
- new_object = &intern->std;
+ old_object = Z_OBJ_P(zobject);
+ new_object = spl_dllist_object_new_ex(old_object->ce, zobject, 1 TSRMLS_CC);
- zend_objects_clone_members(new_object, new_obj_val, old_object, handle TSRMLS_CC);
+ zend_objects_clone_members(new_object, old_object TSRMLS_CC);
- return new_obj_val;
+ return new_object;
}
/* }}} */
static int spl_dllist_object_count_elements(zval *object, long *count TSRMLS_DC) /* {{{ */
{
- spl_dllist_object *intern = (spl_dllist_object*)zend_object_store_get_object(object TSRMLS_CC);
+ spl_dllist_object *intern = (spl_dllist_object*)Z_OBJ_P(object);
if (intern->fptr_count) {
- zval *rv;
- zend_call_method_with_0_params(&object, intern->std.ce, &intern->fptr_count, "count", &rv);
- if (rv) {
+ zval rv;
+ zend_call_method_with_0_params(object, intern->std.ce, &intern->fptr_count, "count", &rv);
+ if (!ZVAL_IS_UNDEF(&rv)) {
zval_ptr_dtor(&intern->retval);
- MAKE_STD_ZVAL(intern->retval);
- ZVAL_ZVAL(intern->retval, rv, 1, 1);
- convert_to_long(intern->retval);
- *count = (long) Z_LVAL_P(intern->retval);
+ ZVAL_ZVAL(&intern->retval, &rv, 0, 0);
+ convert_to_long(&intern->retval);
+ *count = (long) Z_LVAL(intern->retval);
return SUCCESS;
}
*count = 0;
static HashTable* spl_dllist_object_get_debug_info(zval *obj, int *is_temp TSRMLS_DC) /* {{{{ */
{
- spl_dllist_object *intern = (spl_dllist_object*)zend_object_store_get_object(obj TSRMLS_CC);
+ spl_dllist_object *intern = (spl_dllist_object*)Z_OBJ_P(obj);
spl_ptr_llist_element *current = intern->llist->head, *next;
- zval *tmp, zrv, *dllist_array;
+ zval tmp, dllist_array;
char *pnstr;
int pnlen;
int i = 0;
}
if (intern->debug_info->nApplyCount == 0) {
- INIT_PZVAL(&zrv);
- Z_ARRVAL(zrv) = intern->debug_info;
if (!intern->std.properties) {
rebuild_object_properties(&intern->std);
}
- zend_hash_copy(intern->debug_info, 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);
pnstr = spl_gen_private_prop_name(spl_ce_SplDoublyLinkedList, "flags", sizeof("flags")-1, &pnlen TSRMLS_CC);
- add_assoc_long_ex(&zrv, pnstr, pnlen+1, intern->flags);
+ ZVAL_LONG(&tmp, intern->flags);
+ zend_hash_str_add(intern->debug_info, pnstr, pnlen, &tmp);
efree(pnstr);
- ALLOC_INIT_ZVAL(dllist_array);
- array_init(dllist_array);
+ array_init(&dllist_array);
while (current) {
next = current->next;
- add_index_zval(dllist_array, i, (zval *)current->data);
- Z_ADDREF_P(current->data);
+ add_index_zval(&dllist_array, i, ¤t->data);
+ Z_ADDREF_P(¤t->data);
i++;
current = next;
}
pnstr = spl_gen_private_prop_name(spl_ce_SplDoublyLinkedList, "dllist", sizeof("dllist")-1, &pnlen TSRMLS_CC);
- add_assoc_zval_ex(&zrv, pnstr, pnlen+1, dllist_array);
+ zend_hash_str_add(intern->debug_info, pnstr, pnlen, &dllist_array);
efree(pnstr);
}
}
/* }}}} */
-/* {{{ proto bool SplDoublyLinkedList::push(mixed $value) U
+/* {{{ proto bool SplDoublyLinkedList::push(mixed $value)
Push $value on the SplDoublyLinkedList */
SPL_METHOD(SplDoublyLinkedList, push)
{
SEPARATE_ARG_IF_REF(value);
- intern = (spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ intern = (spl_dllist_object*)Z_OBJ_P(getThis());
spl_ptr_llist_push(intern->llist, value TSRMLS_CC);
RETURN_TRUE;
}
/* }}} */
-/* {{{ proto bool SplDoublyLinkedList::unshift(mixed $value) U
+/* {{{ proto bool SplDoublyLinkedList::unshift(mixed $value)
Unshift $value on the SplDoublyLinkedList */
SPL_METHOD(SplDoublyLinkedList, unshift)
{
SEPARATE_ARG_IF_REF(value);
- intern = (spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ intern = (spl_dllist_object*)Z_OBJ_P(getThis());
spl_ptr_llist_unshift(intern->llist, value TSRMLS_CC);
RETURN_TRUE;
}
/* }}} */
-/* {{{ proto mixed SplDoublyLinkedList::pop() U
+/* {{{ proto mixed SplDoublyLinkedList::pop()
Pop an element out of the SplDoublyLinkedList */
SPL_METHOD(SplDoublyLinkedList, pop)
{
- zval *value;
spl_dllist_object *intern;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
- intern = (spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- value = (zval *)spl_ptr_llist_pop(intern->llist TSRMLS_CC);
+ intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ spl_ptr_llist_pop(intern->llist, return_value TSRMLS_CC);
- if (value == NULL) {
+ if (ZVAL_IS_UNDEF(return_value)) {
zend_throw_exception(spl_ce_RuntimeException, "Can't pop from an empty datastructure", 0 TSRMLS_CC);
- return;
+ RETURN_NULL();
}
-
- RETURN_ZVAL(value, 1, 1);
}
/* }}} */
-/* {{{ proto mixed SplDoublyLinkedList::shift() U
+/* {{{ proto mixed SplDoublyLinkedList::shift()
Shift an element out of the SplDoublyLinkedList */
SPL_METHOD(SplDoublyLinkedList, shift)
{
- zval *value;
spl_dllist_object *intern;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
- intern = (spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- value = (zval *)spl_ptr_llist_shift(intern->llist TSRMLS_CC);
+ intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ spl_ptr_llist_shift(intern->llist, return_value TSRMLS_CC);
- if (value == NULL) {
+ if (ZVAL_IS_UNDEF(return_value)) {
zend_throw_exception(spl_ce_RuntimeException, "Can't shift from an empty datastructure", 0 TSRMLS_CC);
- return;
+ RETURN_NULL();
}
-
- RETURN_ZVAL(value, 1, 1);
}
/* }}} */
-/* {{{ proto mixed SplDoublyLinkedList::top() U
+/* {{{ proto mixed SplDoublyLinkedList::top()
Peek at the top element of the SplDoublyLinkedList */
SPL_METHOD(SplDoublyLinkedList, top)
{
return;
}
- intern = (spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- value = (zval *)spl_ptr_llist_last(intern->llist);
+ intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ value = spl_ptr_llist_last(intern->llist);
- if (value == NULL) {
+ if (value == NULL || ZVAL_IS_UNDEF(value)) {
zend_throw_exception(spl_ce_RuntimeException, "Can't peek at an empty datastructure", 0 TSRMLS_CC);
return;
}
}
/* }}} */
-/* {{{ proto mixed SplDoublyLinkedList::bottom() U
+/* {{{ proto mixed SplDoublyLinkedList::bottom()
Peek at the bottom element of the SplDoublyLinkedList */
SPL_METHOD(SplDoublyLinkedList, bottom)
{
return;
}
- intern = (spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- value = (zval *)spl_ptr_llist_first(intern->llist);
+ intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ value = spl_ptr_llist_first(intern->llist);
- if (value == NULL) {
+ if (value == NULL || ZVAL_IS_UNDEF(value)) {
zend_throw_exception(spl_ce_RuntimeException, "Can't peek at an empty datastructure", 0 TSRMLS_CC);
return;
}
}
/* }}} */
-/* {{{ proto int SplDoublyLinkedList::count() U
+/* {{{ proto int SplDoublyLinkedList::count()
Return the number of elements in the datastructure. */
SPL_METHOD(SplDoublyLinkedList, count)
{
long count;
- spl_dllist_object *intern = (spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_dllist_object *intern = (spl_dllist_object*)Z_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
/* }}} */
-/* {{{ proto int SplDoublyLinkedList::isEmpty() U
+/* {{{ proto int SplDoublyLinkedList::isEmpty()
Return true if the SplDoublyLinkedList is empty. */
SPL_METHOD(SplDoublyLinkedList, isEmpty)
{
}
spl_dllist_object_count_elements(getThis(), &count TSRMLS_CC);
- RETURN_BOOL(count==0);
+ RETURN_BOOL(count == 0);
}
/* }}} */
-/* {{{ proto int SplDoublyLinkedList::setIteratorMode($flags) U
+/* {{{ proto int SplDoublyLinkedList::setIteratorMode($flags)
Set the mode of iteration */
SPL_METHOD(SplDoublyLinkedList, setIteratorMode)
{
return;
}
- intern = (spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ intern = (spl_dllist_object*)Z_OBJ_P(getThis());
if (intern->flags & SPL_DLLIST_IT_FIX
&& (intern->flags & SPL_DLLIST_IT_LIFO) != (value & SPL_DLLIST_IT_LIFO)) {
}
/* }}} */
-/* {{{ proto int SplDoublyLinkedList::getIteratorMode() U
+/* {{{ proto int SplDoublyLinkedList::getIteratorMode()
Return the mode of iteration */
SPL_METHOD(SplDoublyLinkedList, getIteratorMode)
{
return;
}
- intern = (spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ intern = (spl_dllist_object*)Z_OBJ_P(getThis());
RETURN_LONG(intern->flags);
}
/* }}} */
-/* {{{ proto bool SplDoublyLinkedList::offsetExists(mixed $index) U
+/* {{{ proto bool SplDoublyLinkedList::offsetExists(mixed $index)
Returns whether the requested $index exists. */
SPL_METHOD(SplDoublyLinkedList, offsetExists)
{
return;
}
- intern = (spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ intern = (spl_dllist_object*)Z_OBJ_P(getThis());
index = spl_offset_convert_to_long(zindex TSRMLS_CC);
RETURN_BOOL(index >= 0 && index < intern->llist->count);
} /* }}} */
-/* {{{ proto mixed SplDoublyLinkedList::offsetGet(mixed $index) U
+/* {{{ proto mixed SplDoublyLinkedList::offsetGet(mixed $index)
Returns the value at the specified $index. */
SPL_METHOD(SplDoublyLinkedList, offsetGet)
{
- zval *zindex, *value;
+ zval *zindex;
long index;
spl_dllist_object *intern;
spl_ptr_llist_element *element;
return;
}
- intern = (spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ intern = (spl_dllist_object*)Z_OBJ_P(getThis());
index = spl_offset_convert_to_long(zindex TSRMLS_CC);
if (index < 0 || index >= intern->llist->count) {
element = spl_ptr_llist_offset(intern->llist, index, intern->flags & SPL_DLLIST_IT_LIFO);
if (element != NULL) {
- value = (zval *)element->data;
- RETURN_ZVAL(value, 1, 0);
+ RETURN_ZVAL(&element->data, 1, 0);
} else {
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0 TSRMLS_CC);
return;
}
} /* }}} */
-/* {{{ proto void SplDoublyLinkedList::offsetSet(mixed $index, mixed $newval) U
+/* {{{ proto void SplDoublyLinkedList::offsetSet(mixed $index, mixed $newval)
Sets the value at the specified $index to $newval. */
SPL_METHOD(SplDoublyLinkedList, offsetSet)
{
}
SEPARATE_ARG_IF_REF(value);
- intern = (spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ intern = (spl_dllist_object*)Z_OBJ_P(getThis());
if (Z_TYPE_P(zindex) == IS_NULL) {
/* $obj[] = ... */
index = spl_offset_convert_to_long(zindex TSRMLS_CC);
if (index < 0 || index >= intern->llist->count) {
- zval_ptr_dtor(&value);
+ zval_ptr_dtor(value);
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0 TSRMLS_CC);
return;
}
/* the element is replaced, delref the old one as in
* SplDoublyLinkedList::pop() */
- zval_ptr_dtor((zval **)&element->data);
- element->data = value;
+ zval_ptr_dtor(&element->data);
+ ZVAL_COPY_VALUE(&element->data, value);
/* new element, call ctor as in spl_ptr_llist_push */
if (intern->llist->ctor) {
intern->llist->ctor(element TSRMLS_CC);
}
} else {
- zval_ptr_dtor(&value);
+ zval_ptr_dtor(value);
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0 TSRMLS_CC);
return;
}
}
} /* }}} */
-/* {{{ proto void SplDoublyLinkedList::offsetUnset(mixed $index) U
+/* {{{ proto void SplDoublyLinkedList::offsetUnset(mixed $index)
Unsets the value at the specified $index. */
SPL_METHOD(SplDoublyLinkedList, offsetUnset)
{
return;
}
- intern = (spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ intern = (spl_dllist_object*)Z_OBJ_P(getThis());
index = spl_offset_convert_to_long(zindex TSRMLS_CC);
llist = intern->llist;
llist->dtor(element TSRMLS_CC);
}
- zval_ptr_dtor((zval **)&element->data);
- element->data = NULL;
+ zval_ptr_dtor(&element->data);
+ ZVAL_UNDEF(&element->data);
SPL_LLIST_DELREF(element);
} else {
SPL_LLIST_CHECK_DELREF(iterator->traverse_pointer);
zend_user_it_invalidate_current(iter TSRMLS_CC);
- zval_ptr_dtor((zval**)&iterator->intern.it.data);
+ zval_ptr_dtor(iterator->intern.it.data);
efree(iterator);
}
(*traverse_position_ptr)--;
if (flags & SPL_DLLIST_IT_DELETE) {
- zval *prev = (zval *)spl_ptr_llist_pop(llist TSRMLS_CC);
+ zval prev;
+ spl_ptr_llist_pop(llist, &prev TSRMLS_CC);
- if (prev) {
- zval_ptr_dtor((zval **)&prev);
- }
+ zval_ptr_dtor(&prev);
}
} else {
*traverse_pointer_ptr = old->next;
if (flags & SPL_DLLIST_IT_DELETE) {
- zval *prev = (zval *)spl_ptr_llist_shift(llist TSRMLS_CC);
+ zval prev;
+ spl_ptr_llist_shift(llist, &prev TSRMLS_CC);
- if (prev) {
- zval_ptr_dtor((zval **)&prev);
- }
+ zval_ptr_dtor(&prev);
} else {
(*traverse_position_ptr)++;
}
}
/* }}} */
-static void spl_dllist_it_get_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC) /* {{{ */
+static zval *spl_dllist_it_get_current_data(zend_object_iterator *iter TSRMLS_DC) /* {{{ */
{
spl_dllist_it *iterator = (spl_dllist_it *)iter;
spl_ptr_llist_element *element = iterator->traverse_pointer;
- if (element == NULL || element->data == NULL) {
- *data = NULL;
- } else {
- *data = (zval **)&element->data;
+ if (element == NULL || ZVAL_IS_UNDEF(&element->data)) {
+ return NULL;
}
+
+ return &element->data;
}
/* }}} */
}
/* }}} */
-/* {{{ proto int SplDoublyLinkedList::key() U
+/* {{{ proto int SplDoublyLinkedList::key()
Return current array key */
SPL_METHOD(SplDoublyLinkedList, key)
{
- spl_dllist_object *intern = (spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_dllist_object *intern = (spl_dllist_object*)Z_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
/* }}} */
-/* {{{ proto void SplDoublyLinkedList::prev() U
+/* {{{ proto void SplDoublyLinkedList::prev()
Move to next entry */
SPL_METHOD(SplDoublyLinkedList, prev)
{
- spl_dllist_object *intern = (spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_dllist_object *intern = (spl_dllist_object*)Z_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
/* }}} */
-/* {{{ proto void SplDoublyLinkedList::next() U
+/* {{{ proto void SplDoublyLinkedList::next()
Move to next entry */
SPL_METHOD(SplDoublyLinkedList, next)
{
- spl_dllist_object *intern = (spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_dllist_object *intern = (spl_dllist_object*)Z_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
/* }}} */
-/* {{{ proto bool SplDoublyLinkedList::valid() U
+/* {{{ proto bool SplDoublyLinkedList::valid()
Check whether the datastructure contains more entries */
SPL_METHOD(SplDoublyLinkedList, valid)
{
- spl_dllist_object *intern = (spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_dllist_object *intern = (spl_dllist_object*)Z_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
/* }}} */
-/* {{{ proto void SplDoublyLinkedList::rewind() U
+/* {{{ proto void SplDoublyLinkedList::rewind()
Rewind the datastructure back to the start */
SPL_METHOD(SplDoublyLinkedList, rewind)
{
- spl_dllist_object *intern = (spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_dllist_object *intern = (spl_dllist_object*)Z_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
/* }}} */
-/* {{{ proto mixed|NULL SplDoublyLinkedList::current() U
+/* {{{ proto mixed|NULL SplDoublyLinkedList::current()
Return current datastructure entry */
SPL_METHOD(SplDoublyLinkedList, current)
{
- spl_dllist_object *intern = (spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_dllist_object *intern = (spl_dllist_object*)Z_OBJ_P(getThis());
spl_ptr_llist_element *element = intern->traverse_pointer;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
- if (element == NULL || element->data == NULL) {
+ if (element == NULL || ZVAL_IS_UNDEF(&element->data)) {
RETURN_NULL();
} else {
- zval *data = (zval *)element->data;
- RETURN_ZVAL(data, 1, 0);
+ RETURN_ZVAL(&element->data, 1, 0);
}
}
/* }}} */
+
/* {{{ proto string SplDoublyLinkedList::serialize()
Serializes storage */
SPL_METHOD(SplDoublyLinkedList, serialize)
{
- spl_dllist_object *intern = (spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_dllist_object *intern = (spl_dllist_object*)Z_OBJ_P(getThis());
smart_str buf = {0};
spl_ptr_llist_element *current = intern->llist->head, *next;
- zval *flags;
+ zval flags;
php_serialize_data_t var_hash;
if (zend_parse_parameters_none() == FAILURE) {
PHP_VAR_SERIALIZE_INIT(var_hash);
/* flags */
- MAKE_STD_ZVAL(flags);
- ZVAL_LONG(flags, intern->flags);
+ ZVAL_LONG(&flags, intern->flags);
php_var_serialize(&buf, &flags, &var_hash TSRMLS_CC);
zval_ptr_dtor(&flags);
smart_str_appendc(&buf, ':');
next = current->next;
- php_var_serialize(&buf, (zval **)¤t->data, &var_hash TSRMLS_CC);
+ php_var_serialize(&buf, ¤t->data, &var_hash TSRMLS_CC);
current = next;
}
PHP_VAR_SERIALIZE_DESTROY(var_hash);
if (buf.c) {
- RETURN_STRINGL(buf.c, buf.len, 0);
+ RETVAL_STRINGL(buf.c, buf.len);
+ smart_str_free(&buf);
+ return;
} else {
RETURN_NULL();
}
Unserializes storage */
SPL_METHOD(SplDoublyLinkedList, unserialize)
{
- spl_dllist_object *intern = (spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- zval *flags, *elem;
+ spl_dllist_object *intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ zval flags, elem;
char *buf;
int buf_len;
const unsigned char *p, *s;
PHP_VAR_UNSERIALIZE_INIT(var_hash);
/* flags */
- ALLOC_INIT_ZVAL(flags);
- if (!php_var_unserialize(&flags, &p, s + buf_len, &var_hash TSRMLS_CC) || Z_TYPE_P(flags) != IS_LONG) {
+ if (!php_var_unserialize(&flags, &p, s + buf_len, &var_hash TSRMLS_CC)) {
+ goto error;
+ }
+
+ if (Z_TYPE(flags) != IS_LONG) {
zval_ptr_dtor(&flags);
goto error;
}
- intern->flags = Z_LVAL_P(flags);
+
+ intern->flags = Z_LVAL(flags);
zval_ptr_dtor(&flags);
/* elements */
while(*p == ':') {
++p;
- ALLOC_INIT_ZVAL(elem);
if (!php_var_unserialize(&elem, &p, s + buf_len, &var_hash TSRMLS_CC)) {
- zval_ptr_dtor(&elem);
goto error;
}
- spl_ptr_llist_push(intern->llist, elem TSRMLS_CC);
+ spl_ptr_llist_push(intern->llist, &elem TSRMLS_CC);
+ zval_ptr_dtor(&elem);
}
if (*p != '\0') {
} /* }}} */
-/* {{{ proto void SplDoublyLinkedList::add(mixed $index, mixed $newval) U
+/* {{{ proto void SplDoublyLinkedList::add(mixed $index, mixed $newval)
Inserts a new entry before the specified $index consisting of $newval. */
SPL_METHOD(SplDoublyLinkedList, add)
{
return;
}
- intern = (spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ intern = (spl_dllist_object*)Z_OBJ_P(getThis());
index = spl_offset_convert_to_long(zindex TSRMLS_CC);
if (index < 0 || index > intern->llist->count) {
/* Get the element we want to insert before */
element = spl_ptr_llist_offset(intern->llist, index, intern->flags & SPL_DLLIST_IT_LIFO);
- elem->data = value;
+ ZVAL_COPY_VALUE(&elem->data, value);
elem->rc = 1;
/* connect to the neighbours */
elem->next = element;
}
} /* }}} */
-
-/* iterator handler table */
+/* {{{ iterator handler table */
zend_object_iterator_funcs spl_dllist_it_funcs = {
spl_dllist_it_dtor,
spl_dllist_it_valid,
spl_dllist_it_get_current_key,
spl_dllist_it_move_forward,
spl_dllist_it_rewind
-};
+}; /* }}} */
zend_object_iterator *spl_dllist_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC) /* {{{ */
{
spl_dllist_it *iterator;
- spl_dllist_object *dllist_object = (spl_dllist_object*)zend_object_store_get_object(object TSRMLS_CC);
+ spl_dllist_object *dllist_object = (spl_dllist_object*)Z_OBJ_P(object);
if (by_ref) {
zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0 TSRMLS_CC);
REGISTER_SPL_STD_CLASS_EX(SplDoublyLinkedList, spl_dllist_object_new, spl_funcs_SplDoublyLinkedList);
memcpy(&spl_handler_SplDoublyLinkedList, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
- spl_handler_SplDoublyLinkedList.clone_obj = spl_dllist_object_clone;
+ spl_handler_SplDoublyLinkedList.clone_obj = spl_dllist_object_clone;
spl_handler_SplDoublyLinkedList.count_elements = spl_dllist_object_count_elements;
spl_handler_SplDoublyLinkedList.get_debug_info = spl_dllist_object_get_debug_info;
+ spl_handler_SplDoublyLinkedList.dtor_obj = zend_objects_destroy_object;
+ spl_handler_SplDoublyLinkedList.free_obj = spl_dllist_object_free_storage;
REGISTER_SPL_CLASS_CONST_LONG(SplDoublyLinkedList, "IT_MODE_LIFO", SPL_DLLIST_IT_LIFO);
REGISTER_SPL_CLASS_CONST_LONG(SplDoublyLinkedList, "IT_MODE_FIFO", 0);
return SUCCESS;
}
/* }}} */
+
/*
* Local variables:
* tab-width: 4
typedef struct _spl_fixedarray { /* {{{ */
long size;
- zval **elements;
+ zval *elements;
} spl_fixedarray;
/* }}} */
typedef struct _spl_fixedarray_object { /* {{{ */
zend_object std;
- spl_fixedarray *array;
- zval *retval;
+ spl_fixedarray *array;
+ zval retval;
zend_function *fptr_offset_get;
zend_function *fptr_offset_set;
zend_function *fptr_offset_has;
{
if (size > 0) {
array->size = 0; /* reset size in case ecalloc() fails */
- array->elements = ecalloc(size, sizeof(zval *));
+ array->elements = ecalloc(size, sizeof(zval));
array->size = size;
} else {
array->elements = NULL;
long i;
for (i = 0; i < array->size; i++) {
- if (array->elements[i]) {
- zval_ptr_dtor(&(array->elements[i]));
- }
+ zval_ptr_dtor(&(array->elements[i]));
}
if (array->elements) {
array->elements = NULL;
}
} else if (size > array->size) {
- array->elements = erealloc(array->elements, sizeof(zval *) * size);
- memset(array->elements + array->size, '\0', sizeof(zval *) * (size - array->size));
+ array->elements = erealloc(array->elements, sizeof(zval) * size);
+ memset(array->elements + array->size, '\0', sizeof(zval) * (size - array->size));
} else { /* size < array->size */
long i;
for (i = size; i < array->size; i++) {
- if (array->elements[i]) {
- zval_ptr_dtor(&(array->elements[i]));
- }
+ zval_ptr_dtor(&(array->elements[i]));
}
- array->elements = erealloc(array->elements, sizeof(zval *) * size);
+ array->elements = erealloc(array->elements, sizeof(zval) * size);
}
array->size = size;
{
int i;
for (i = 0; i < from->size; i++) {
- if (from->elements[i]) {
- Z_ADDREF_P(from->elements[i]);
- to->elements[i] = from->elements[i];
- } else {
- to->elements[i] = NULL;
- }
+ ZVAL_COPY(&to->elements[i], &from->elements[i]);
}
}
/* }}} */
-static HashTable* spl_fixedarray_object_get_gc(zval *obj, zval ***table, int *n TSRMLS_DC) /* {{{{ */
+static HashTable* spl_fixedarray_object_get_gc(zval *obj, zval **table, int *n TSRMLS_DC) /* {{{{ */
{
- spl_fixedarray_object *intern = (spl_fixedarray_object*)zend_object_store_get_object(obj TSRMLS_CC);
+ spl_fixedarray_object *intern = (spl_fixedarray_object*)Z_OBJ_P(obj);
HashTable *ht = zend_std_get_properties(obj TSRMLS_CC);
if (intern->array) {
static HashTable* spl_fixedarray_object_get_properties(zval *obj TSRMLS_DC) /* {{{{ */
{
- spl_fixedarray_object *intern = (spl_fixedarray_object*)zend_object_store_get_object(obj TSRMLS_CC);
+ spl_fixedarray_object *intern = (spl_fixedarray_object*)Z_OBJ_P(obj);
HashTable *ht = zend_std_get_properties(obj TSRMLS_CC);
int i = 0;
int j = zend_hash_num_elements(ht);
for (i = 0; i < intern->array->size; i++) {
- if (intern->array->elements[i]) {
- zend_hash_index_update(ht, i, (void *)&intern->array->elements[i], sizeof(zval *), NULL);
- Z_ADDREF_P(intern->array->elements[i]);
+ if (!ZVAL_IS_UNDEF(&intern->array->elements[i])) {
+ zend_hash_index_update(ht, i, &intern->array->elements[i]);
+ Z_ADDREF_P(&intern->array->elements[i]);
} else {
- zend_hash_index_update(ht, i, (void *)&EG(uninitialized_zval_ptr), sizeof(zval *), NULL);
- Z_ADDREF_P(EG(uninitialized_zval_ptr));
+ zend_hash_index_update(ht, i, &EG(uninitialized_zval));
+ Z_ADDREF_P(&EG(uninitialized_zval));
}
}
if (j > intern->array->size) {
}
/* }}}} */
-static void spl_fixedarray_object_free_storage(void *object TSRMLS_DC) /* {{{ */
+static void spl_fixedarray_object_free_storage(zend_object *object TSRMLS_DC) /* {{{ */
{
spl_fixedarray_object *intern = (spl_fixedarray_object *)object;
long i;
if (intern->array) {
for (i = 0; i < intern->array->size; i++) {
- if (intern->array->elements[i]) {
- zval_ptr_dtor(&(intern->array->elements[i]));
- }
+ zval_ptr_dtor(&(intern->array->elements[i]));
}
if (intern->array->size > 0 && intern->array->elements) {
zend_object_iterator *spl_fixedarray_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC);
-static zend_object_value spl_fixedarray_object_new_ex(zend_class_entry *class_type, spl_fixedarray_object **obj, zval *orig, int clone_orig TSRMLS_DC) /* {{{ */
+static zend_object *spl_fixedarray_object_new_ex(zend_class_entry *class_type, zval *orig, int clone_orig TSRMLS_DC) /* {{{ */
{
- zend_object_value retval;
spl_fixedarray_object *intern;
zend_class_entry *parent = class_type;
int inherited = 0;
intern = ecalloc(1, sizeof(spl_fixedarray_object));
- *obj = intern;
- ALLOC_INIT_ZVAL(intern->retval);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
intern->flags = 0;
if (orig && clone_orig) {
- spl_fixedarray_object *other = (spl_fixedarray_object*)zend_object_store_get_object(orig TSRMLS_CC);
+ spl_fixedarray_object *other = (spl_fixedarray_object*)Z_OBJ_P(orig);
intern->ce_get_iterator = other->ce_get_iterator;
if (!other->array) {
/* leave a empty object, will be dtor later by CLONE handler */
while (parent) {
if (parent == spl_ce_SplFixedArray) {
- retval.handlers = &spl_handler_SplFixedArray;
+ intern->std.handlers = &spl_handler_SplFixedArray;
class_type->get_iterator = spl_fixedarray_get_iterator;
break;
}
inherited = 1;
}
- retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, spl_fixedarray_object_free_storage, NULL TSRMLS_CC);
+ zend_objects_store_put(&intern->std);
if (!parent) { /* this must never happen */
php_error_docref(NULL TSRMLS_CC, E_COMPILE_ERROR, "Internal compiler error, Class is not child of SplFixedArray");
}
+
if (!class_type->iterator_funcs.zf_current) {
- zend_hash_find(&class_type->function_table, "rewind", sizeof("rewind"), (void **) &class_type->iterator_funcs.zf_rewind);
- zend_hash_find(&class_type->function_table, "valid", sizeof("valid"), (void **) &class_type->iterator_funcs.zf_valid);
- zend_hash_find(&class_type->function_table, "key", sizeof("key"), (void **) &class_type->iterator_funcs.zf_key);
- zend_hash_find(&class_type->function_table, "current", sizeof("current"), (void **) &class_type->iterator_funcs.zf_current);
- zend_hash_find(&class_type->function_table, "next", sizeof("next"), (void **) &class_type->iterator_funcs.zf_next);
+ class_type->iterator_funcs.zf_rewind = zend_hash_str_find_ptr(&class_type->function_table, "rewind", sizeof("rewind") - 1);
+ class_type->iterator_funcs.zf_valid = zend_hash_str_find_ptr(&class_type->function_table, "valid", sizeof("valid") - 1);
+ class_type->iterator_funcs.zf_key = zend_hash_str_find_ptr(&class_type->function_table, "key", sizeof("key") - 1);
+ class_type->iterator_funcs.zf_current = zend_hash_str_find_ptr(&class_type->function_table, "current", sizeof("current") - 1);
+ class_type->iterator_funcs.zf_next = zend_hash_str_find_ptr(&class_type->function_table, "next", sizeof("next") - 1);
}
if (inherited) {
if (class_type->iterator_funcs.zf_rewind->common.scope != parent) {
intern->flags |= SPL_FIXEDARRAY_OVERLOADED_NEXT;
}
- zend_hash_find(&class_type->function_table, "offsetget", sizeof("offsetget"), (void **) &intern->fptr_offset_get);
+ intern->fptr_offset_get = zend_hash_str_find_ptr(&class_type->function_table, "offsetget", sizeof("offsetget") - 1);
if (intern->fptr_offset_get->common.scope == parent) {
intern->fptr_offset_get = NULL;
}
- zend_hash_find(&class_type->function_table, "offsetset", sizeof("offsetset"), (void **) &intern->fptr_offset_set);
+ intern->fptr_offset_set = zend_hash_str_find_ptr(&class_type->function_table, "offsetset", sizeof("offsetset") - 1);
if (intern->fptr_offset_set->common.scope == parent) {
intern->fptr_offset_set = NULL;
}
- zend_hash_find(&class_type->function_table, "offsetexists", sizeof("offsetexists"), (void **) &intern->fptr_offset_has);
+ intern->fptr_offset_has = zend_hash_str_find_ptr(&class_type->function_table, "offsetexists", sizeof("offsetexists") - 1);
if (intern->fptr_offset_has->common.scope == parent) {
intern->fptr_offset_has = NULL;
}
- zend_hash_find(&class_type->function_table, "offsetunset", sizeof("offsetunset"), (void **) &intern->fptr_offset_del);
+ intern->fptr_offset_del = zend_hash_str_find_ptr(&class_type->function_table, "offsetunset", sizeof("offsetunset") - 1);
if (intern->fptr_offset_del->common.scope == parent) {
intern->fptr_offset_del = NULL;
}
- zend_hash_find(&class_type->function_table, "count", sizeof("count"), (void **) &intern->fptr_count);
+ intern->fptr_count = zend_hash_str_find_ptr(&class_type->function_table, "count", sizeof("count") - 1);
if (intern->fptr_count->common.scope == parent) {
intern->fptr_count = NULL;
}
}
- return retval;
+ return &intern->std;
}
/* }}} */
-static zend_object_value spl_fixedarray_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
+static zend_object *spl_fixedarray_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
- spl_fixedarray_object *tmp;
- return spl_fixedarray_object_new_ex(class_type, &tmp, NULL, 0 TSRMLS_CC);
+ return spl_fixedarray_object_new_ex(class_type, NULL, 0 TSRMLS_CC);
}
/* }}} */
-static zend_object_value spl_fixedarray_object_clone(zval *zobject TSRMLS_DC) /* {{{ */
+static zend_object *spl_fixedarray_object_clone(zval *zobject TSRMLS_DC) /* {{{ */
{
- zend_object_value new_obj_val;
- zend_object *old_object;
- zend_object *new_object;
- zend_object_handle handle = Z_OBJ_HANDLE_P(zobject);
- spl_fixedarray_object *intern;
+ zend_object *old_object;
+ zend_object *new_object;
- old_object = zend_objects_get_address(zobject TSRMLS_CC);
- new_obj_val = spl_fixedarray_object_new_ex(old_object->ce, &intern, zobject, 1 TSRMLS_CC);
- new_object = &intern->std;
+ old_object = Z_OBJ_P(zobject);
+ new_object = spl_fixedarray_object_new_ex(old_object->ce, zobject, 1 TSRMLS_CC);
- zend_objects_clone_members(new_object, new_obj_val, old_object, handle TSRMLS_CC);
+ zend_objects_clone_members(new_object, old_object TSRMLS_CC);
- return new_obj_val;
+ return new_object;
}
/* }}} */
-static inline zval **spl_fixedarray_object_read_dimension_helper(spl_fixedarray_object *intern, zval *offset TSRMLS_DC) /* {{{ */
+static inline zval *spl_fixedarray_object_read_dimension_helper(spl_fixedarray_object *intern, zval *offset TSRMLS_DC) /* {{{ */
{
long index;
if (index < 0 || intern->array == NULL || index >= intern->array->size) {
zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0 TSRMLS_CC);
return NULL;
- } else if(!intern->array->elements[index]) {
+ } else if (ZVAL_IS_UNDEF(&intern->array->elements[index])) {
return NULL;
} else {
return &intern->array->elements[index];
static zval *spl_fixedarray_object_read_dimension(zval *object, zval *offset, int type TSRMLS_DC) /* {{{ */
{
spl_fixedarray_object *intern;
- zval **retval;
+ zval *retval;
- intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);
+ intern = (spl_fixedarray_object*)Z_OBJ_P(object);
if (intern->fptr_offset_get) {
- zval *rv;
+ zval tmp, rv;
if (!offset) {
- ALLOC_INIT_ZVAL(offset);
+ ZVAL_UNDEF(&tmp);
+ offset = &tmp;
} else {
SEPARATE_ARG_IF_REF(offset);
}
- zend_call_method_with_1_params(&object, intern->std.ce, &intern->fptr_offset_get, "offsetGet", &rv, offset);
- zval_ptr_dtor(&offset);
- if (rv) {
+ zend_call_method_with_1_params(object, intern->std.ce, &intern->fptr_offset_get, "offsetGet", &rv, offset);
+ zval_ptr_dtor(offset);
+ if (!ZVAL_IS_UNDEF(&rv)) {
zval_ptr_dtor(&intern->retval);
- MAKE_STD_ZVAL(intern->retval);
- ZVAL_ZVAL(intern->retval, rv, 1, 1);
- return intern->retval;
+ ZVAL_ZVAL(&intern->retval, &rv, 0, 0);
+ return &intern->retval;
}
- return EG(uninitialized_zval_ptr);
+ return &EG(uninitialized_zval);
}
- retval = spl_fixedarray_object_read_dimension_helper(intern, offset TSRMLS_CC);
- if (retval) {
- return *retval;
- }
- return NULL;
+ return spl_fixedarray_object_read_dimension_helper(intern, offset TSRMLS_CC);
}
/* }}} */
zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0 TSRMLS_CC);
return;
} else {
- if (intern->array->elements[index]) {
+ if (!ZVAL_IS_UNDEF(&intern->array->elements[index])) {
zval_ptr_dtor(&(intern->array->elements[index]));
}
SEPARATE_ARG_IF_REF(value);
- intern->array->elements[index] = value;
+ ZVAL_COPY_VALUE(&intern->array->elements[index], value);
}
}
/* }}} */
{
spl_fixedarray_object *intern;
- intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);
+ intern = (spl_fixedarray_object *)Z_OBJ_P(object);
if (intern->fptr_offset_set) {
+ zval tmp;
if (!offset) {
- ALLOC_INIT_ZVAL(offset);
+ ZVAL_UNDEF(&tmp);
+ offset = &tmp;
} else {
SEPARATE_ARG_IF_REF(offset);
}
SEPARATE_ARG_IF_REF(value);
- zend_call_method_with_2_params(&object, intern->std.ce, &intern->fptr_offset_set, "offsetSet", NULL, offset, value);
- zval_ptr_dtor(&value);
- zval_ptr_dtor(&offset);
+ zend_call_method_with_2_params(object, intern->std.ce, &intern->fptr_offset_set, "offsetSet", NULL, offset, value);
+ zval_ptr_dtor(value);
+ zval_ptr_dtor(offset);
return;
}
zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0 TSRMLS_CC);
return;
} else {
- if (intern->array->elements[index]) {
- zval_ptr_dtor(&(intern->array->elements[index]));
- }
- intern->array->elements[index] = NULL;
+ zval_ptr_dtor(&(intern->array->elements[index]));
+ ZVAL_UNDEF(&intern->array->elements[index]);
}
}
/* }}} */
{
spl_fixedarray_object *intern;
- intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);
+ intern = (spl_fixedarray_object *)Z_OBJ_P(object);
if (intern->fptr_offset_del) {
SEPARATE_ARG_IF_REF(offset);
- zend_call_method_with_1_params(&object, intern->std.ce, &intern->fptr_offset_del, "offsetUnset", NULL, offset);
- zval_ptr_dtor(&offset);
+ zend_call_method_with_1_params(object, intern->std.ce, &intern->fptr_offset_del, "offsetUnset", NULL, offset);
+ zval_ptr_dtor(offset);
return;
}
if (index < 0 || intern->array == NULL || index >= intern->array->size) {
retval = 0;
} else {
- if (!intern->array->elements[index]) {
+ if (ZVAL_IS_UNDEF(&intern->array->elements[index])) {
retval = 0;
} else if (check_empty) {
- if (zend_is_true(intern->array->elements[index] TSRMLS_CC)) {
+ if (zend_is_true(&intern->array->elements[index] TSRMLS_CC)) {
retval = 1;
} else {
retval = 0;
{
spl_fixedarray_object *intern;
- intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);
+ intern = (spl_fixedarray_object*)Z_OBJ_P(object);
if (intern->fptr_offset_get) {
- zval *rv;
+ zval rv;
SEPARATE_ARG_IF_REF(offset);
- zend_call_method_with_1_params(&object, intern->std.ce, &intern->fptr_offset_has, "offsetExists", &rv, offset);
- zval_ptr_dtor(&offset);
- if (rv) {
+ zend_call_method_with_1_params(object, intern->std.ce, &intern->fptr_offset_has, "offsetExists", &rv, offset);
+ zval_ptr_dtor(offset);
+ if (!ZVAL_IS_UNDEF(&rv)) {
zval_ptr_dtor(&intern->retval);
- MAKE_STD_ZVAL(intern->retval);
- ZVAL_ZVAL(intern->retval, rv, 1, 1);
- return zend_is_true(intern->retval TSRMLS_CC);
+ ZVAL_ZVAL(&intern->retval, &rv, 0, 0);
+ return zend_is_true(&intern->retval TSRMLS_CC);
}
return 0;
}
{
spl_fixedarray_object *intern;
- intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);
+ intern = (spl_fixedarray_object*)Z_OBJ_P(object);
if (intern->fptr_count) {
- zval *rv;
- zend_call_method_with_0_params(&object, intern->std.ce, &intern->fptr_count, "count", &rv);
- if (rv) {
+ zval rv;
+ zend_call_method_with_0_params(object, intern->std.ce, &intern->fptr_count, "count", &rv);
+ if (!ZVAL_IS_UNDEF(&rv)) {
zval_ptr_dtor(&intern->retval);
- MAKE_STD_ZVAL(intern->retval);
- ZVAL_ZVAL(intern->retval, rv, 1, 1);
- convert_to_long(intern->retval);
- *count = (long) Z_LVAL_P(intern->retval);
+ ZVAL_ZVAL(&intern->retval, &rv, 0, 0);
+ convert_to_long(&intern->retval);
+ *count = (long) Z_LVAL(intern->retval);
return SUCCESS;
}
} else if (intern->array) {
return;
}
- intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);
+ intern = (spl_fixedarray_object*)Z_OBJ_P(object);
if (intern->array) {
/* called __construct() twice, bail out */
*/
SPL_METHOD(SplFixedArray, __wakeup)
{
- spl_fixedarray_object *intern = (spl_fixedarray_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_fixedarray_object *intern = (spl_fixedarray_object*)Z_OBJ_P(getThis());
HashPosition ptr;
HashTable *intern_ht = zend_std_get_properties(getThis() TSRMLS_CC);
- zval **data;
+ zval *data;
if (zend_parse_parameters_none() == FAILURE) {
return;
intern->array = emalloc(sizeof(spl_fixedarray));
spl_fixedarray_init(intern->array, size TSRMLS_CC);
- for (zend_hash_internal_pointer_reset_ex(intern_ht, &ptr); zend_hash_get_current_data_ex(intern_ht, (void **) &data, &ptr) == SUCCESS; zend_hash_move_forward_ex(intern_ht, &ptr)) {
+ for (zend_hash_internal_pointer_reset_ex(intern_ht, &ptr); (data = zend_hash_get_current_data_ex(intern_ht, &ptr)) != NULL; zend_hash_move_forward_ex(intern_ht, &ptr)) {
Z_ADDREF_PP(data);
- intern->array->elements[index++] = *data;
+ ZVAL_COPY_VALUE(&intern->array->elements[index++], data);
}
/* Remove the unserialised properties, since we now have the elements
return;
}
- intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);
+ intern = (spl_fixedarray_object*)Z_OBJ_P(object);
if (intern->array) {
RETURN_LONG(intern->array->size);
}
return;
}
- intern = (spl_fixedarray_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
+ intern = (spl_fixedarray_object*)Z_OBJ_P(getThis());
array_init(return_value);
if (intern->array) {
int i = 0;
for (; i < intern->array->size; i++) {
- if (intern->array->elements[i]) {
- zend_hash_index_update(Z_ARRVAL_P(return_value), i, (void *)&intern->array->elements[i], sizeof(zval *), NULL);
- Z_ADDREF_P(intern->array->elements[i]);
+ if (!ZVAL_IS_UNDEF(&intern->array->elements[i])) {
+ zend_hash_index_update(Z_ARRVAL_P(return_value), i, &intern->array->elements[i]);
+ Z_ADDREF_P(&intern->array->elements[i]);
} else {
- zend_hash_index_update(Z_ARRVAL_P(return_value), i, (void *)&EG(uninitialized_zval_ptr), sizeof(zval *), NULL);
- Z_ADDREF_P(EG(uninitialized_zval_ptr));
+ zend_hash_index_update(Z_ARRVAL_P(return_value), i, &EG(uninitialized_zval));
+ Z_ADDREF_P(&EG(uninitialized_zval));
}
}
}
return;
}
- array = ecalloc(1, sizeof(*array));
+ array = ecalloc(1, sizeof(spl_fixedarray));
num = zend_hash_num_elements(Z_ARRVAL_P(data));
if (num > 0 && save_indexes) {
- zval **element, *value;
- char *str_index;
+ zval *element;
+ zend_string *str_index;
ulong num_index, max_index = 0;
long tmp;
for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(data));
- zend_hash_get_current_data(Z_ARRVAL_P(data), (void **) &element) == SUCCESS;
+ (element = zend_hash_get_current_data(Z_ARRVAL_P(data))) != NULL;
zend_hash_move_forward(Z_ARRVAL_P(data))
) {
if (zend_hash_get_current_key(Z_ARRVAL_P(data), &str_index, &num_index, 0) != HASH_KEY_IS_LONG || (long)num_index < 0) {
spl_fixedarray_init(array, tmp TSRMLS_CC);
for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(data));
- zend_hash_get_current_data(Z_ARRVAL_P(data), (void **) &element) == SUCCESS;
+ (element = zend_hash_get_current_data(Z_ARRVAL_P(data))) != NULL;
zend_hash_move_forward(Z_ARRVAL_P(data))
) {
zend_hash_get_current_key(Z_ARRVAL_P(data), &str_index, &num_index, 0);
- value = *element;
- SEPARATE_ARG_IF_REF(value);
- array->elements[num_index] = value;
+ SEPARATE_ARG_IF_REF(element);
+ ZVAL_COPY_VALUE(&array->elements[num_index], element);
}
} else if (num > 0 && !save_indexes) {
- zval **element, *value;
+ zval *element;
long i = 0;
spl_fixedarray_init(array, num TSRMLS_CC);
for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(data));
- zend_hash_get_current_data(Z_ARRVAL_P(data), (void **) &element) == SUCCESS;
+ (element = zend_hash_get_current_data(Z_ARRVAL_P(data))) != NULL;
zend_hash_move_forward(Z_ARRVAL_P(data))
) {
- value = *element;
-
- SEPARATE_ARG_IF_REF(value);
- array->elements[i] = value;
+ SEPARATE_ARG_IF_REF(element);
+ ZVAL_COPY_VALUE(&array->elements[i], element);
i++;
}
} else {
object_init_ex(return_value, spl_ce_SplFixedArray);
Z_TYPE_P(return_value) = IS_OBJECT;
- intern = (spl_fixedarray_object *)zend_object_store_get_object(return_value TSRMLS_CC);
+ intern = (spl_fixedarray_object *)Z_OBJ_P(return_value);
intern->array = array;
}
/* }}} */
return;
}
- intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);
+ intern = (spl_fixedarray_object*)Z_OBJ_P(object);
if (intern->array) {
RETURN_LONG(intern->array->size);
}
return;
}
- intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);
+ intern = (spl_fixedarray_object*)Z_OBJ_P(object);
if (!intern->array) {
intern->array = ecalloc(1, sizeof(spl_fixedarray));
}
return;
}
- intern = (spl_fixedarray_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
+ intern = (spl_fixedarray_object*)Z_OBJ_P(getThis());
RETURN_BOOL(spl_fixedarray_object_has_dimension_helper(intern, zindex, 0 TSRMLS_CC));
} /* }}} */
Returns the value at the specified $index. */
SPL_METHOD(SplFixedArray, offsetGet)
{
- zval *zindex, **value_pp;
+ zval *zindex, *value;
spl_fixedarray_object *intern;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zindex) == FAILURE) {
return;
}
- intern = (spl_fixedarray_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
- value_pp = spl_fixedarray_object_read_dimension_helper(intern, zindex TSRMLS_CC);
+ intern = (spl_fixedarray_object*)Z_OBJ_P(getThis());
+ value = spl_fixedarray_object_read_dimension_helper(intern, zindex TSRMLS_CC);
- if (value_pp) {
- RETURN_ZVAL(*value_pp, 1, 0);
+ if (value) {
+ RETURN_ZVAL(value, 1, 0);
}
RETURN_NULL();
} /* }}} */
return;
}
- intern = (spl_fixedarray_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
+ intern = (spl_fixedarray_object*)Z_OBJ_P(getThis());
spl_fixedarray_object_write_dimension_helper(intern, zindex, value TSRMLS_CC);
} /* }}} */
return;
}
- intern = (spl_fixedarray_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
+ intern = (spl_fixedarray_object*)Z_OBJ_P(getThis());
spl_fixedarray_object_unset_dimension_helper(intern, zindex TSRMLS_CC);
} /* }}} */
spl_fixedarray_it *iterator = (spl_fixedarray_it *)iter;
zend_user_it_invalidate_current(iter TSRMLS_CC);
- zval_ptr_dtor((zval**)&iterator->intern.it.data);
+ zval_ptr_dtor(iterator->intern.it.data);
efree(iterator);
}
}
/* }}} */
-static void spl_fixedarray_it_get_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC) /* {{{ */
+static zval *spl_fixedarray_it_get_current_data(zend_object_iterator *iter TSRMLS_DC) /* {{{ */
{
- zval *zindex;
- spl_fixedarray_it *iterator = (spl_fixedarray_it *)iter;
+ zval zindex;
+ spl_fixedarray_it *iterator = (spl_fixedarray_it *)iter;
spl_fixedarray_object *intern = iterator->object;
if (intern->flags & SPL_FIXEDARRAY_OVERLOADED_CURRENT) {
- zend_user_it_get_current_data(iter, data TSRMLS_CC);
+ return zend_user_it_get_current_data(iter TSRMLS_CC);
} else {
- ALLOC_INIT_ZVAL(zindex);
- ZVAL_LONG(zindex, iterator->object->current);
-
- *data = spl_fixedarray_object_read_dimension_helper(intern, zindex TSRMLS_CC);
+ zval *data;
- if (*data == NULL) {
- *data = &EG(uninitialized_zval_ptr);
- }
+ ZVAL_LONG(&zindex, iterator->object->current);
+ data = spl_fixedarray_object_read_dimension_helper(intern, &zindex TSRMLS_CC);
zval_ptr_dtor(&zindex);
+
+ if (data == NULL) {
+ data = &EG(uninitialized_zval);
+ }
+ return data;
}
}
/* }}} */
static void spl_fixedarray_it_get_current_key(zend_object_iterator *iter, zval *key TSRMLS_DC) /* {{{ */
{
- spl_fixedarray_it *iterator = (spl_fixedarray_it *)iter;
+ spl_fixedarray_it *iterator = (spl_fixedarray_it *)iter;
spl_fixedarray_object *intern = iterator->object;
if (intern->flags & SPL_FIXEDARRAY_OVERLOADED_KEY) {
}
/* }}} */
-/* {{{ proto int SplFixedArray::key() U
+/* {{{ proto int SplFixedArray::key()
Return current array key */
SPL_METHOD(SplFixedArray, key)
{
- spl_fixedarray_object *intern = (spl_fixedarray_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_fixedarray_object *intern = (spl_fixedarray_object*)Z_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
/* }}} */
-/* {{{ proto void SplFixedArray::next() U
+/* {{{ proto void SplFixedArray::next()
Move to next entry */
SPL_METHOD(SplFixedArray, next)
{
- spl_fixedarray_object *intern = (spl_fixedarray_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_fixedarray_object *intern = (spl_fixedarray_object*)Z_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
/* }}} */
-/* {{{ proto bool SplFixedArray::valid() U
+/* {{{ proto bool SplFixedArray::valid()
Check whether the datastructure contains more entries */
SPL_METHOD(SplFixedArray, valid)
{
- spl_fixedarray_object *intern = (spl_fixedarray_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_fixedarray_object *intern = (spl_fixedarray_object*)Z_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
/* }}} */
-/* {{{ proto void SplFixedArray::rewind() U
+/* {{{ proto void SplFixedArray::rewind()
Rewind the datastructure back to the start */
SPL_METHOD(SplFixedArray, rewind)
{
- spl_fixedarray_object *intern = (spl_fixedarray_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_fixedarray_object *intern = (spl_fixedarray_object*)Z_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
/* }}} */
-/* {{{ proto mixed|NULL SplFixedArray::current() U
+/* {{{ proto mixed|NULL SplFixedArray::current()
Return current datastructure entry */
SPL_METHOD(SplFixedArray, current)
{
- zval *zindex, **value_pp;
- spl_fixedarray_object *intern = (spl_fixedarray_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ zval zindex, *value;
+ spl_fixedarray_object *intern = (spl_fixedarray_object*)Z_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
- ALLOC_INIT_ZVAL(zindex);
- ZVAL_LONG(zindex, intern->current);
+ ZVAL_LONG(&zindex, intern->current);
- value_pp = spl_fixedarray_object_read_dimension_helper(intern, zindex TSRMLS_CC);
+ value = spl_fixedarray_object_read_dimension_helper(intern, &zindex TSRMLS_CC);
zval_ptr_dtor(&zindex);
- if (value_pp) {
- RETURN_ZVAL(*value_pp, 1, 0);
+ if (value) {
+ RETURN_ZVAL(value, 1, 0);
}
RETURN_NULL();
}
zend_object_iterator *spl_fixedarray_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC) /* {{{ */
{
spl_fixedarray_it *iterator;
- spl_fixedarray_object *fixedarray_object = (spl_fixedarray_object*)zend_object_store_get_object(object TSRMLS_CC);
+ spl_fixedarray_object *fixedarray_object = (spl_fixedarray_object*)Z_OBJ_P(object);
if (by_ref) {
zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0 TSRMLS_CC);
Z_ADDREF_P(object);
- iterator = emalloc(sizeof(spl_fixedarray_it));
- iterator->intern.it.data = (void*)object;
- iterator->intern.it.funcs = &spl_fixedarray_it_funcs;
- iterator->intern.ce = ce;
- iterator->intern.value = NULL;
- iterator->object = fixedarray_object;
+ iterator = emalloc(sizeof(spl_fixedarray_it));
+ iterator->intern.it.data = object;
+ iterator->intern.it.funcs = &spl_fixedarray_it_funcs;
+ iterator->intern.ce = ce;
+ iterator->intern.value = NULL;
+ iterator->object = fixedarray_object;
return (zend_object_iterator*)iterator;
}
spl_handler_SplFixedArray.count_elements = spl_fixedarray_object_count_elements;
spl_handler_SplFixedArray.get_properties = spl_fixedarray_object_get_properties;
spl_handler_SplFixedArray.get_gc = spl_fixedarray_object_get_gc;
+ spl_handler_SplFixedArray.dtor_obj = zend_objects_destroy_object;
+ spl_handler_SplFixedArray.free_obj = spl_fixedarray_object_free_storage;
REGISTER_SPL_IMPLEMENTS(SplFixedArray, Iterator);
REGISTER_SPL_IMPLEMENTS(SplFixedArray, ArrayAccess);
PHPAPI zend_class_entry *spl_ce_SplMinHeap;
PHPAPI zend_class_entry *spl_ce_SplPriorityQueue;
-typedef void *spl_ptr_heap_element;
-typedef void (*spl_ptr_heap_dtor_func)(spl_ptr_heap_element TSRMLS_DC);
-typedef void (*spl_ptr_heap_ctor_func)(spl_ptr_heap_element TSRMLS_DC);
-typedef int (*spl_ptr_heap_cmp_func)(spl_ptr_heap_element, spl_ptr_heap_element, void* TSRMLS_DC);
+typedef void (*spl_ptr_heap_dtor_func)(zval * TSRMLS_DC);
+typedef void (*spl_ptr_heap_ctor_func)(zval * TSRMLS_DC);
+typedef int (*spl_ptr_heap_cmp_func)(zval *, zval *, zval * TSRMLS_DC);
typedef struct _spl_ptr_heap {
- spl_ptr_heap_element *elements;
+ zval *elements;
spl_ptr_heap_ctor_func ctor;
spl_ptr_heap_dtor_func dtor;
spl_ptr_heap_cmp_func cmp;
struct _spl_heap_object {
zend_object std;
spl_ptr_heap *heap;
- zval *retval;
+ zval retval;
int flags;
zend_class_entry *ce_get_iterator;
zend_function *fptr_cmp;
spl_heap_object *object;
};
-/* {{{ spl_ptr_heap */
-static void spl_ptr_heap_zval_dtor(spl_ptr_heap_element elem TSRMLS_DC) { /* {{{ */
- if (elem) {
- zval_ptr_dtor((zval **)&elem);
+static void spl_ptr_heap_zval_dtor(zval *elem TSRMLS_DC) { /* {{{ */
+ if (!ZVAL_IS_UNDEF(elem)) {
+ zval_ptr_dtor(elem);
}
}
/* }}} */
-static void spl_ptr_heap_zval_ctor(spl_ptr_heap_element elem TSRMLS_DC) { /* {{{ */
- Z_ADDREF_P((zval *)elem);
+static void spl_ptr_heap_zval_ctor(zval *elem TSRMLS_DC) { /* {{{ */
+ Z_ADDREF_P(elem);
}
/* }}} */
static int spl_ptr_heap_cmp_cb_helper(zval *object, spl_heap_object *heap_object, zval *a, zval *b, long *result TSRMLS_DC) { /* {{{ */
- zval *result_p = NULL;
+ zval zresult;
- zend_call_method_with_2_params(&object, heap_object->std.ce, &heap_object->fptr_cmp, "compare", &result_p, a, b);
+ zend_call_method_with_2_params(object, heap_object->std.ce, &heap_object->fptr_cmp, "compare", &zresult, a, b);
- if (EG(exception)) {
- return FAILURE;
- }
+ if (EG(exception)) {
+ return FAILURE;
+ }
- convert_to_long(result_p);
- *result = Z_LVAL_P(result_p);
+ convert_to_long(&zresult);
+ *result = Z_LVAL(zresult);
- zval_ptr_dtor(&result_p);
+ zval_ptr_dtor(&zresult);
- return SUCCESS;
+ return SUCCESS;
}
/* }}} */
-static zval **spl_pqueue_extract_helper(zval **value, int flags) /* {{{ */
+static zval *spl_pqueue_extract_helper(zval *value, int flags) /* {{{ */
{
if ((flags & SPL_PQUEUE_EXTR_BOTH) == SPL_PQUEUE_EXTR_BOTH) {
return value;
} else if ((flags & SPL_PQUEUE_EXTR_BOTH) > 0) {
if ((flags & SPL_PQUEUE_EXTR_DATA) == SPL_PQUEUE_EXTR_DATA) {
- zval **data;
- if (zend_hash_find(Z_ARRVAL_PP(value), "data", sizeof("data"), (void **) &data) == SUCCESS) {
+ zval *data;
+ if ((data = zend_hash_str_find(Z_ARRVAL_P(value), "data", sizeof("data") - 1)) != NULL) {
return data;
}
} else {
- zval **priority;
- if (zend_hash_find(Z_ARRVAL_PP(value), "priority", sizeof("priority"), (void **) &priority) == SUCCESS) {
+ zval *priority;
+ if ((priority = zend_hash_str_find(Z_ARRVAL_P(value), "priority", sizeof("priority") - 1)) != NULL) {
return priority;
}
}
}
/* }}} */
-static int spl_ptr_heap_zval_max_cmp(spl_ptr_heap_element a, spl_ptr_heap_element b, void* object TSRMLS_DC) { /* {{{ */
+static int spl_ptr_heap_zval_max_cmp(zval *a, zval *b, zval *object TSRMLS_DC) { /* {{{ */
zval result;
if (EG(exception)) {
}
if (object) {
- spl_heap_object *heap_object = (spl_heap_object*)zend_object_store_get_object((zval *)object TSRMLS_CC);
+ spl_heap_object *heap_object = (spl_heap_object*)Z_OBJ_P(object);
if (heap_object->fptr_cmp) {
long lval = 0;
- if (spl_ptr_heap_cmp_cb_helper((zval *)object, heap_object, (zval *)a, (zval *)b, &lval TSRMLS_CC) == FAILURE) {
+ if (spl_ptr_heap_cmp_cb_helper(object, heap_object, a, b, &lval TSRMLS_CC) == FAILURE) {
/* exception or call failure */
return 0;
}
}
}
- INIT_ZVAL(result);
- compare_function(&result, (zval *)a, (zval *)b TSRMLS_CC);
+ compare_function(&result, a, b TSRMLS_CC);
return Z_LVAL(result);
}
/* }}} */
-static int spl_ptr_heap_zval_min_cmp(spl_ptr_heap_element a, spl_ptr_heap_element b, void* object TSRMLS_DC) { /* {{{ */
+static int spl_ptr_heap_zval_min_cmp(zval *a, zval *b, zval* object TSRMLS_DC) { /* {{{ */
zval result;
if (EG(exception)) {
}
if (object) {
- spl_heap_object *heap_object = (spl_heap_object*)zend_object_store_get_object((zval *)object TSRMLS_CC);
+ spl_heap_object *heap_object = (spl_heap_object*)Z_OBJ_P(object);
if (heap_object->fptr_cmp) {
long lval = 0;
if (spl_ptr_heap_cmp_cb_helper((zval *)object, heap_object, (zval *)a, (zval *)b, &lval TSRMLS_CC) == FAILURE) {
}
}
- INIT_ZVAL(result);
- compare_function(&result, (zval *)b, (zval *)a TSRMLS_CC);
+ compare_function(&result, b, a TSRMLS_CC);
return Z_LVAL(result);
}
/* }}} */
-static int spl_ptr_pqueue_zval_cmp(spl_ptr_heap_element a, spl_ptr_heap_element b, void* object TSRMLS_DC) { /* {{{ */
+static int spl_ptr_pqueue_zval_cmp(zval *a, zval *b, zval *object TSRMLS_DC) { /* {{{ */
zval result;
- zval **a_priority_pp = spl_pqueue_extract_helper((zval **)&a, SPL_PQUEUE_EXTR_PRIORITY);
- zval **b_priority_pp = spl_pqueue_extract_helper((zval **)&b, SPL_PQUEUE_EXTR_PRIORITY);
+ zval *a_priority_p = spl_pqueue_extract_helper(a, SPL_PQUEUE_EXTR_PRIORITY);
+ zval *b_priority_p = spl_pqueue_extract_helper(b, SPL_PQUEUE_EXTR_PRIORITY);
- if ((!a_priority_pp) || (!b_priority_pp)) {
+ if ((!a_priority_p) || (!b_priority_p)) {
zend_error(E_RECOVERABLE_ERROR, "Unable to extract from the PriorityQueue node");
return 0;
}
+
if (EG(exception)) {
return 0;
}
if (object) {
- spl_heap_object *heap_object = (spl_heap_object*)zend_object_store_get_object(object TSRMLS_CC);
+ spl_heap_object *heap_object = (spl_heap_object*)Z_OBJ_P(object);
if (heap_object->fptr_cmp) {
long lval = 0;
- if (spl_ptr_heap_cmp_cb_helper((zval *)object, heap_object, *a_priority_pp, *b_priority_pp, &lval TSRMLS_CC) == FAILURE) {
+ if (spl_ptr_heap_cmp_cb_helper((zval *)object, heap_object, a_priority_p, b_priority_p, &lval TSRMLS_CC) == FAILURE) {
/* exception or call failure */
return 0;
}
}
}
- INIT_ZVAL(result);
- compare_function(&result, *a_priority_pp, *b_priority_pp TSRMLS_CC);
+ compare_function(&result, a_priority_p, b_priority_p TSRMLS_CC);
return Z_LVAL(result);
}
/* }}} */
heap->dtor = dtor;
heap->ctor = ctor;
heap->cmp = cmp;
- heap->elements = safe_emalloc(sizeof(spl_ptr_heap_element), PTR_HEAP_BLOCK_SIZE, 0);
+ heap->elements = ecalloc(PTR_HEAP_BLOCK_SIZE, sizeof(zval));
heap->max_size = PTR_HEAP_BLOCK_SIZE;
heap->count = 0;
heap->flags = 0;
}
/* }}} */
-static void spl_ptr_heap_insert(spl_ptr_heap *heap, spl_ptr_heap_element elem, void *cmp_userdata TSRMLS_DC) { /* {{{ */
+static void spl_ptr_heap_insert(spl_ptr_heap *heap, zval *elem, void *cmp_userdata TSRMLS_DC) { /* {{{ */
int i;
if (heap->count+1 > heap->max_size) {
/* we need to allocate more memory */
- heap->elements = (void **) safe_erealloc(heap->elements, sizeof(spl_ptr_heap_element), (heap->max_size), (sizeof(spl_ptr_heap_element) * (heap->max_size)));
heap->max_size *= 2;
+ heap->elements = erealloc(heap->elements, heap->max_size * sizeof(zval));
+ memset(heap->elements + heap->max_size/2 * sizeof(zval), 0, heap->max_size/2 * sizeof(zval));
}
heap->ctor(elem TSRMLS_CC);
/* sifting up */
- for(i = heap->count++; i > 0 && heap->cmp(heap->elements[(i-1)/2], elem, cmp_userdata TSRMLS_CC) < 0; i = (i-1)/2) {
+ for(i = heap->count++; i > 0 && heap->cmp(&heap->elements[(i-1)/2], elem, cmp_userdata TSRMLS_CC) < 0; i = (i-1)/2) {
heap->elements[i] = heap->elements[(i-1)/2];
}
heap->flags |= SPL_HEAP_CORRUPTED;
}
- heap->elements[i] = elem;
+ ZVAL_COPY_VALUE(&heap->elements[i], elem);
}
/* }}} */
-static spl_ptr_heap_element spl_ptr_heap_top(spl_ptr_heap *heap) { /* {{{ */
+static zval *spl_ptr_heap_top(spl_ptr_heap *heap) { /* {{{ */
if (heap->count == 0) {
return NULL;
}
- return heap->elements[0];
+ return ZVAL_IS_UNDEF(&heap->elements[0])? NULL : &heap->elements[0];
}
/* }}} */
-static spl_ptr_heap_element spl_ptr_heap_delete_top(spl_ptr_heap *heap, void *cmp_userdata TSRMLS_DC) { /* {{{ */
+static zval *spl_ptr_heap_delete_top(spl_ptr_heap *heap, void *cmp_userdata TSRMLS_DC) { /* {{{ */
int i, j;
const int limit = (heap->count-1)/2;
- spl_ptr_heap_element top;
- spl_ptr_heap_element bottom;
+ zval *top, *bottom;
if (heap->count == 0) {
return NULL;
}
- top = heap->elements[0];
- bottom = heap->elements[--heap->count];
+ top = &heap->elements[0];
+ bottom = &heap->elements[--heap->count];
- for( i = 0; i < limit; i = j)
- {
+ for (i = 0; i < limit; i = j) {
/* Find smaller child */
- j = i*2+1;
- if(j != heap->count && heap->cmp(heap->elements[j+1], heap->elements[j], cmp_userdata TSRMLS_CC) > 0) {
+ j = i * 2 + 1;
+ if(j != heap->count && heap->cmp(&heap->elements[j+1], &heap->elements[j], cmp_userdata TSRMLS_CC) > 0) {
j++; /* next child is bigger */
}
/* swap elements between two levels */
- if(heap->cmp(bottom, heap->elements[j], cmp_userdata TSRMLS_CC) < 0) {
+ if(heap->cmp(bottom, &heap->elements[j], cmp_userdata TSRMLS_CC) < 0) {
heap->elements[i] = heap->elements[j];
} else {
break;
heap->flags |= SPL_HEAP_CORRUPTED;
}
- heap->elements[i] = bottom;
+ ZVAL_COPY_VALUE(&heap->elements[i], bottom);
heap->dtor(top TSRMLS_CC);
- return top;
+ return ZVAL_IS_UNDEF(top)? NULL : top;
}
/* }}} */
heap->count = from->count;
heap->flags = from->flags;
- heap->elements = safe_emalloc(sizeof(spl_ptr_heap_element),from->max_size,0);
- memcpy(heap->elements, from->elements, sizeof(spl_ptr_heap_element)*from->max_size);
+ heap->elements = safe_emalloc(sizeof(zval), from->max_size, 0);
+ memcpy(heap->elements, from->elements, sizeof(zval)*from->max_size);
for (i=0; i < heap->count; ++i) {
- heap->ctor(heap->elements[i] TSRMLS_CC);
+ heap->ctor(&heap->elements[i] TSRMLS_CC);
}
return heap;
int i;
for (i=0; i < heap->count; ++i) {
- heap->dtor(heap->elements[i] TSRMLS_CC);
+ heap->dtor(&heap->elements[i]);
}
efree(heap->elements);
zend_object_iterator *spl_heap_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC);
-static void spl_heap_object_free_storage(void *object TSRMLS_DC) /* {{{ */
+static void spl_heap_object_free_storage(zend_object *object TSRMLS_DC) /* {{{ */
{
int i;
spl_heap_object *intern = (spl_heap_object *)object;
zend_object_std_dtor(&intern->std TSRMLS_CC);
for (i = 0; i < intern->heap->count; ++i) {
- if (intern->heap->elements[i]) {
- zval_ptr_dtor((zval **)&intern->heap->elements[i]);
+ if (!ZVAL_IS_UNDEF(&intern->heap->elements[i])) {
+ zval_ptr_dtor(&intern->heap->elements[i]);
}
}
}
/* }}} */
-static zend_object_value spl_heap_object_new_ex(zend_class_entry *class_type, spl_heap_object **obj, zval *orig, int clone_orig TSRMLS_DC) /* {{{ */
+static zend_object *spl_heap_object_new_ex(zend_class_entry *class_type, zval *orig, int clone_orig TSRMLS_DC) /* {{{ */
{
- zend_object_value retval;
spl_heap_object *intern;
zend_class_entry *parent = class_type;
int inherited = 0;
intern = ecalloc(1, sizeof(spl_heap_object));
- *obj = intern;
- ALLOC_INIT_ZVAL(intern->retval);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
intern->debug_info = NULL;
if (orig) {
- spl_heap_object *other = (spl_heap_object*)zend_object_store_get_object(orig TSRMLS_CC);
+ spl_heap_object *other = (spl_heap_object*)Z_OBJ_P(orig);
intern->ce_get_iterator = other->ce_get_iterator;
if (clone_orig) {
int i;
intern->heap = spl_ptr_heap_clone(other->heap TSRMLS_CC);
for (i = 0; i < intern->heap->count; ++i) {
- if (intern->heap->elements[i]) {
- Z_ADDREF_P((zval *)intern->heap->elements[i]);
+ if (!ZVAL_IS_UNDEF(&intern->heap->elements[i])) {
+ Z_ADDREF_P(&intern->heap->elements[i]);
}
}
} else {
intern->heap = spl_ptr_heap_init(spl_ptr_heap_zval_max_cmp, spl_ptr_heap_zval_ctor, spl_ptr_heap_zval_dtor);
}
- retval.handlers = &spl_handler_SplHeap;
+ intern->std.handlers = &spl_handler_SplHeap;
while (parent) {
if (parent == spl_ce_SplPriorityQueue) {
intern->heap->cmp = spl_ptr_pqueue_zval_cmp;
- intern->flags = SPL_PQUEUE_EXTR_DATA;
- retval.handlers = &spl_handler_SplPriorityQueue;
+ intern->flags = SPL_PQUEUE_EXTR_DATA;
+ intern->std.handlers = &spl_handler_SplPriorityQueue;
break;
}
inherited = 1;
}
- retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, spl_heap_object_free_storage, NULL TSRMLS_CC);
+ zend_objects_store_put(&intern->std);
if (!parent) { /* this must never happen */
php_error_docref(NULL TSRMLS_CC, E_COMPILE_ERROR, "Internal compiler error, Class is not child of SplHeap");
}
if (inherited) {
- zend_hash_find(&class_type->function_table, "compare", sizeof("compare"), (void **) &intern->fptr_cmp);
+ intern->fptr_cmp = zend_hash_str_find_ptr(&class_type->function_table, "compare", sizeof("compare") - 1);
if (intern->fptr_cmp->common.scope == parent) {
intern->fptr_cmp = NULL;
}
- zend_hash_find(&class_type->function_table, "count", sizeof("count"), (void **) &intern->fptr_count);
+ intern->fptr_count = zend_hash_str_find_ptr(&class_type->function_table, "count", sizeof("count") - 1);
if (intern->fptr_count->common.scope == parent) {
intern->fptr_count = NULL;
}
}
- return retval;
+ return &intern->std;
}
/* }}} */
-static zend_object_value spl_heap_object_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
+static zend_object *spl_heap_object_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
- spl_heap_object *tmp;
- return spl_heap_object_new_ex(class_type, &tmp, NULL, 0 TSRMLS_CC);
+ return spl_heap_object_new_ex(class_type, NULL, 0 TSRMLS_CC);
}
/* }}} */
-static zend_object_value spl_heap_object_clone(zval *zobject TSRMLS_DC) /* {{{ */
+static zend_object *spl_heap_object_clone(zval *zobject TSRMLS_DC) /* {{{ */
{
- zend_object_value new_obj_val;
zend_object *old_object;
zend_object *new_object;
- zend_object_handle handle = Z_OBJ_HANDLE_P(zobject);
- spl_heap_object *intern;
- old_object = zend_objects_get_address(zobject TSRMLS_CC);
- new_obj_val = spl_heap_object_new_ex(old_object->ce, &intern, zobject, 1 TSRMLS_CC);
- new_object = &intern->std;
+ old_object = Z_OBJ_P(zobject);
+ new_object = spl_heap_object_new_ex(old_object->ce, zobject, 1 TSRMLS_CC);
- zend_objects_clone_members(new_object, new_obj_val, old_object, handle TSRMLS_CC);
+ zend_objects_clone_members(new_object, old_object TSRMLS_CC);
- return new_obj_val;
+ return new_object;
}
/* }}} */
static int spl_heap_object_count_elements(zval *object, long *count TSRMLS_DC) /* {{{ */
{
- spl_heap_object *intern = (spl_heap_object*)zend_object_store_get_object(object TSRMLS_CC);
+ spl_heap_object *intern = (spl_heap_object*)Z_OBJ_P(object);
if (intern->fptr_count) {
- zval *rv;
- zend_call_method_with_0_params(&object, intern->std.ce, &intern->fptr_count, "count", &rv);
- if (rv) {
+ zval rv;
+ zend_call_method_with_0_params(object, intern->std.ce, &intern->fptr_count, "count", &rv);
+ if (!ZVAL_IS_UNDEF(&rv)) {
zval_ptr_dtor(&intern->retval);
- MAKE_STD_ZVAL(intern->retval);
- ZVAL_ZVAL(intern->retval, rv, 1, 1);
- convert_to_long(intern->retval);
- *count = (long) Z_LVAL_P(intern->retval);
+ ZVAL_ZVAL(&intern->retval, &rv, 0, 0);
+ convert_to_long(&intern->retval);
+ *count = (long) Z_LVAL(intern->retval);
return SUCCESS;
}
*count = 0;
/* }}} */
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);
- zval *tmp, zrv, *heap_array;
+ spl_heap_object *intern = (spl_heap_object*)Z_OBJ_P(obj);
+ zval tmp, heap_array;
char *pnstr;
int pnlen;
int i;
}
if (intern->debug_info->nApplyCount == 0) {
- INIT_PZVAL(&zrv);
- Z_ARRVAL(zrv) = intern->debug_info;
- zend_hash_copy(intern->debug_info, 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);
pnstr = spl_gen_private_prop_name(ce, "flags", sizeof("flags")-1, &pnlen TSRMLS_CC);
- add_assoc_long_ex(&zrv, pnstr, pnlen+1, intern->flags);
+ ZVAL_LONG(&tmp, intern->flags);
+ zend_hash_str_update(intern->debug_info, pnstr, pnlen, &tmp);
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);
+ ZVAL_BOOL(&tmp, intern->heap->flags&SPL_HEAP_CORRUPTED);
+ zend_hash_str_update(intern->debug_info, pnstr, pnlen, &tmp);
efree(pnstr);
- ALLOC_INIT_ZVAL(heap_array);
- array_init(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]);
+ add_index_zval(&heap_array, i, &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);
+ zend_hash_str_update(intern->debug_info, pnstr, pnlen, &heap_array);
efree(pnstr);
}
}
/* }}} */
-/* {{{ proto int SplHeap::count() U
+/* {{{ proto int SplHeap::count()
Return the number of elements in the heap. */
SPL_METHOD(SplHeap, count)
{
long count;
- spl_heap_object *intern = (spl_heap_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_heap_object *intern = (spl_heap_object*)Z_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
/* }}} */
-/* {{{ proto int SplHeap::isEmpty() U
+/* {{{ proto int SplHeap::isEmpty()
Return true if the heap is empty. */
SPL_METHOD(SplHeap, isEmpty)
{
- spl_heap_object *intern = (spl_heap_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_heap_object *intern = (spl_heap_object*)Z_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
- RETURN_BOOL(spl_ptr_heap_count(intern->heap)==0);
+ RETURN_BOOL(spl_ptr_heap_count(intern->heap) == 0);
}
/* }}} */
-/* {{{ proto bool SplHeap::insert(mixed $value) U
+/* {{{ proto bool SplHeap::insert(mixed $value)
Push $value on the heap */
SPL_METHOD(SplHeap, insert)
{
return;
}
- intern = (spl_heap_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ intern = (spl_heap_object*)Z_OBJ_P(getThis());
if (intern->heap->flags & SPL_HEAP_CORRUPTED) {
zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0 TSRMLS_CC);
}
/* }}} */
-/* {{{ proto mixed SplHeap::extract() U
+/* {{{ proto mixed SplHeap::extract()
extract the element out of the top of the heap */
SPL_METHOD(SplHeap, extract)
{
return;
}
- intern = (spl_heap_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ intern = (spl_heap_object*)Z_OBJ_P(getThis());
if (intern->heap->flags & SPL_HEAP_CORRUPTED) {
zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0 TSRMLS_CC);
return;
}
- value = (zval *)spl_ptr_heap_delete_top(intern->heap, getThis() TSRMLS_CC);
+ value = (zval *)spl_ptr_heap_delete_top(intern->heap, getThis() TSRMLS_CC);
if (!value) {
zend_throw_exception(spl_ce_RuntimeException, "Can't extract from an empty heap", 0 TSRMLS_CC);
}
/* }}} */
-/* {{{ proto bool SplPriorityQueue::insert(mixed $value, mixed $priority) U
+/* {{{ proto bool SplPriorityQueue::insert(mixed $value, mixed $priority)
Push $value with the priority $priodiry on the priorityqueue */
SPL_METHOD(SplPriorityQueue, insert)
{
- zval *data, *priority, *elem;
+ zval *data, *priority, elem;
spl_heap_object *intern;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &data, &priority) == FAILURE) {
return;
}
- intern = (spl_heap_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ intern = (spl_heap_object*)Z_OBJ_P(getThis());
if (intern->heap->flags & SPL_HEAP_CORRUPTED) {
zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0 TSRMLS_CC);
SEPARATE_ARG_IF_REF(data);
SEPARATE_ARG_IF_REF(priority);
- ALLOC_INIT_ZVAL(elem);
+ array_init(&elem);
+ add_assoc_zval_ex(&elem, "data", sizeof("data") - 1, data);
+ add_assoc_zval_ex(&elem, "priority", sizeof("priority") - 1, priority);
- array_init(elem);
- add_assoc_zval_ex(elem, "data", sizeof("data"), data);
- add_assoc_zval_ex(elem, "priority", sizeof("priority"), priority);
-
- spl_ptr_heap_insert(intern->heap, elem, getThis() TSRMLS_CC);
+ spl_ptr_heap_insert(intern->heap, &elem, getThis() TSRMLS_CC);
RETURN_TRUE;
}
/* }}} */
-/* {{{ proto mixed SplPriorityQueue::extract() U
+/* {{{ proto mixed SplPriorityQueue::extract()
extract the element out of the top of the priority queue */
SPL_METHOD(SplPriorityQueue, extract)
{
- zval *value, *value_out, **value_out_pp;
+ zval *value, *value_out;
spl_heap_object *intern;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
- intern = (spl_heap_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ intern = (spl_heap_object*)Z_OBJ_P(getThis());
if (intern->heap->flags & SPL_HEAP_CORRUPTED) {
zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0 TSRMLS_CC);
return;
}
- value = (zval *)spl_ptr_heap_delete_top(intern->heap, getThis() TSRMLS_CC);
+ value = spl_ptr_heap_delete_top(intern->heap, getThis() TSRMLS_CC);
- if (!value) {
+ if (!value || ZVAL_IS_UNDEF(value)) {
zend_throw_exception(spl_ce_RuntimeException, "Can't extract from an empty heap", 0 TSRMLS_CC);
return;
}
- value_out_pp = spl_pqueue_extract_helper(&value, intern->flags);
+ value_out = spl_pqueue_extract_helper(value, intern->flags);
-
- if (!value_out_pp) {
+ if (!value_out) {
zend_error(E_RECOVERABLE_ERROR, "Unable to extract from the PriorityQueue node");
- zval_ptr_dtor(&value);
+ zval_ptr_dtor(value);
return;
}
- value_out = *value_out_pp;
-
Z_ADDREF_P(value_out);
- zval_ptr_dtor(&value);
+ zval_ptr_dtor(value);
RETURN_ZVAL(value_out, 1, 1);
}
/* }}} */
-/* {{{ proto mixed SplPriorityQueue::top() U
+/* {{{ proto mixed SplPriorityQueue::top()
Peek at the top element of the priority queue */
SPL_METHOD(SplPriorityQueue, top)
{
- zval *value, **value_out;
+ zval *value, *value_out;
spl_heap_object *intern;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
- intern = (spl_heap_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ intern = (spl_heap_object*)Z_OBJ_P(getThis());
if (intern->heap->flags & SPL_HEAP_CORRUPTED) {
zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0 TSRMLS_CC);
return;
}
- value = (zval *)spl_ptr_heap_top(intern->heap);
+ value = spl_ptr_heap_top(intern->heap);
if (!value) {
zend_throw_exception(spl_ce_RuntimeException, "Can't peek at an empty heap", 0 TSRMLS_CC);
return;
}
- value_out = spl_pqueue_extract_helper(&value, intern->flags);
+ value_out = spl_pqueue_extract_helper(value, intern->flags);
if (!value_out) {
zend_error(E_RECOVERABLE_ERROR, "Unable to extract from the PriorityQueue node");
return;
}
- RETURN_ZVAL(*value_out, 1, 0);
+ RETURN_ZVAL(value_out, 1, 0);
}
/* }}} */
-/* {{{ proto int SplPriorityQueue::setIteratorMode($flags) U
+/* {{{ proto int SplPriorityQueue::setIteratorMode($flags)
Set the flags of extraction*/
SPL_METHOD(SplPriorityQueue, setExtractFlags)
{
return;
}
- intern = (spl_heap_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ intern = (spl_heap_object*)Z_OBJ_P(getThis());
intern->flags = value & SPL_PQUEUE_EXTR_MASK;
}
/* }}} */
-/* {{{ proto int SplHeap::recoverFromCorruption() U
+/* {{{ proto int SplHeap::recoverFromCorruption()
Recover from a corrupted state*/
SPL_METHOD(SplHeap, recoverFromCorruption)
{
return;
}
- intern = (spl_heap_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ intern = (spl_heap_object*)Z_OBJ_P(getThis());
intern->heap->flags = intern->heap->flags & ~SPL_HEAP_CORRUPTED;
}
/* }}} */
-/* {{{ proto bool SplPriorityQueue::compare(mixed $a, mixed $b) U
+/* {{{ proto bool SplPriorityQueue::compare(mixed $a, mixed $b)
compare the priorities */
SPL_METHOD(SplPriorityQueue, compare)
{
}
/* }}} */
-/* {{{ proto mixed SplHeap::top() U
+/* {{{ proto mixed SplHeap::top()
Peek at the top element of the heap */
SPL_METHOD(SplHeap, top)
{
return;
}
- intern = (spl_heap_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ intern = (spl_heap_object*)Z_OBJ_P(getThis());
if (intern->heap->flags & SPL_HEAP_CORRUPTED) {
zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0 TSRMLS_CC);
return;
}
- value = (zval *)spl_ptr_heap_top(intern->heap);
+ value = spl_ptr_heap_top(intern->heap);
if (!value) {
zend_throw_exception(spl_ce_RuntimeException, "Can't peek at an empty heap", 0 TSRMLS_CC);
}
/* }}} */
-/* {{{ proto bool SplMinHeap::compare(mixed $a, mixed $b) U
+/* {{{ proto bool SplMinHeap::compare(mixed $a, mixed $b)
compare the values */
SPL_METHOD(SplMinHeap, compare)
{
}
/* }}} */
-/* {{{ proto bool SplMaxHeap::compare(mixed $a, mixed $b) U
+/* {{{ proto bool SplMaxHeap::compare(mixed $a, mixed $b)
compare the values */
SPL_METHOD(SplMaxHeap, compare)
{
spl_heap_it *iterator = (spl_heap_it *)iter;
zend_user_it_invalidate_current(iter TSRMLS_CC);
- zval_ptr_dtor((zval**)&iterator->intern.it.data);
+ zval_ptr_dtor(iterator->intern.it.data);
efree(iterator);
}
}
/* }}} */
-static void spl_heap_it_get_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC) /* {{{ */
+static zval *spl_heap_it_get_current_data(zend_object_iterator *iter TSRMLS_DC) /* {{{ */
{
- spl_heap_it *iterator = (spl_heap_it *)iter;
- zval **element = (zval **)&iterator->object->heap->elements[0];
+ spl_heap_it *iterator = (spl_heap_it *)iter;
+ zval *element = &iterator->object->heap->elements[0];
if (iterator->object->heap->flags & SPL_HEAP_CORRUPTED) {
zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0 TSRMLS_CC);
return;
}
- if (iterator->object->heap->count == 0 || !*element) {
- *data = NULL;
+ if (iterator->object->heap->count == 0 || ZVAL_IS_UNDEF(element)) {
+ return NULL;
} else {
- *data = element;
+ return element;
}
}
/* }}} */
-static void spl_pqueue_it_get_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC) /* {{{ */
+static zval *spl_pqueue_it_get_current_data(zend_object_iterator *iter TSRMLS_DC) /* {{{ */
{
spl_heap_it *iterator = (spl_heap_it *)iter;
- zval **element = (zval **)&iterator->object->heap->elements[0];
+ zval *element = &iterator->object->heap->elements[0];
if (iterator->object->heap->flags & SPL_HEAP_CORRUPTED) {
zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0 TSRMLS_CC);
return;
}
- if (iterator->object->heap->count == 0 || !*element) {
- *data = NULL;
+ if (iterator->object->heap->count == 0 || ZVAL_IS_UNDEF(element)) {
+ return NULL;
} else {
- *data = spl_pqueue_extract_helper(element, iterator->object->flags);
- if (!*data) {
+ zval *data = spl_pqueue_extract_helper(element, iterator->object->flags);
+ if (!data) {
zend_error(E_RECOVERABLE_ERROR, "Unable to extract from the PriorityQueue node");
}
+ return data;
}
}
/* }}} */
static void spl_heap_it_move_forward(zend_object_iterator *iter TSRMLS_DC) /* {{{ */
{
- zval *object = (zval*)((zend_user_iterator *)iter)->it.data;
- spl_heap_it *iterator = (spl_heap_it *)iter;
- spl_ptr_heap_element elem;
+ zval *object = (zval*)((zend_user_iterator *)iter)->it.data;
+ spl_heap_it *iterator = (spl_heap_it *)iter;
+ zval *elem;
if (iterator->object->heap->flags & SPL_HEAP_CORRUPTED) {
zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0 TSRMLS_CC);
elem = spl_ptr_heap_delete_top(iterator->object->heap, object TSRMLS_CC);
if (elem != NULL) {
- zval_ptr_dtor((zval **)&elem);
+ zval_ptr_dtor(elem);
}
zend_user_it_invalidate_current(iter TSRMLS_CC);
}
/* }}} */
-/* {{{ proto int SplHeap::key() U
+/* {{{ proto int SplHeap::key()
Return current array key */
SPL_METHOD(SplHeap, key)
{
- spl_heap_object *intern = (spl_heap_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_heap_object *intern = (spl_heap_object*)Z_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
/* }}} */
-/* {{{ proto void SplHeap::next() U
+/* {{{ proto void SplHeap::next()
Move to next entry */
SPL_METHOD(SplHeap, next)
{
- spl_heap_object *intern = (spl_heap_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- spl_ptr_heap_element elem = spl_ptr_heap_delete_top(intern->heap, getThis() TSRMLS_CC);
+ spl_heap_object *intern = (spl_heap_object*)Z_OBJ_P(getThis());
+ zval *elem = spl_ptr_heap_delete_top(intern->heap, getThis() TSRMLS_CC);
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if (elem != NULL) {
- zval_ptr_dtor((zval **)&elem);
+ zval_ptr_dtor(elem);
}
}
/* }}} */
-/* {{{ proto bool SplHeap::valid() U
+/* {{{ proto bool SplHeap::valid()
Check whether the datastructure contains more entries */
SPL_METHOD(SplHeap, valid)
{
- spl_heap_object *intern = (spl_heap_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_heap_object *intern = (spl_heap_object*)Z_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
/* }}} */
-/* {{{ proto void SplHeap::rewind() U
+/* {{{ proto void SplHeap::rewind()
Rewind the datastructure back to the start */
SPL_METHOD(SplHeap, rewind)
{
}
/* }}} */
-/* {{{ proto mixed|NULL SplHeap::current() U
+/* {{{ proto mixed|NULL SplHeap::current()
Return current datastructure entry */
SPL_METHOD(SplHeap, current)
{
- spl_heap_object *intern = (spl_heap_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- zval *element = (zval *)intern->heap->elements[0];
+ spl_heap_object *intern = (spl_heap_object*)Z_OBJ_P(getThis());
+ zval *element = &intern->heap->elements[0];
if (zend_parse_parameters_none() == FAILURE) {
return;
}
- if (!intern->heap->count || !element) {
+ if (!intern->heap->count || ZVAL_IS_UNDEF(element)) {
RETURN_NULL();
} else {
RETURN_ZVAL(element, 1, 0);
}
/* }}} */
-/* {{{ proto mixed|NULL SplPriorityQueue::current() U
+/* {{{ proto mixed|NULL SplPriorityQueue::current()
Return current datastructure entry */
SPL_METHOD(SplPriorityQueue, current)
{
- spl_heap_object *intern = (spl_heap_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- zval **element = (zval **)&intern->heap->elements[0];
+ spl_heap_object *intern = (spl_heap_object*)Z_OBJ_P(getThis());
+ zval *element = &intern->heap->elements[0];
if (zend_parse_parameters_none() == FAILURE) {
return;
}
- if (!intern->heap->count || !*element) {
+ if (!intern->heap->count || ZVAL_IS_UNDEF(element)) {
RETURN_NULL();
} else {
- zval **data = spl_pqueue_extract_helper(element, intern->flags);
+ zval *data = spl_pqueue_extract_helper(element, intern->flags);
if (!data) {
zend_error(E_RECOVERABLE_ERROR, "Unable to extract from the PriorityQueue node");
RETURN_NULL();
}
- RETURN_ZVAL(*data, 1, 0);
+ RETURN_ZVAL(data, 1, 0);
}
}
/* }}} */
zend_object_iterator *spl_heap_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC) /* {{{ */
{
spl_heap_it *iterator;
- spl_heap_object *heap_object = (spl_heap_object*)zend_object_store_get_object(object TSRMLS_CC);
+ spl_heap_object *heap_object = (spl_heap_object*)Z_OBJ_P(object);
if (by_ref) {
zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0 TSRMLS_CC);
zend_object_iterator *spl_pqueue_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC) /* {{{ */
{
spl_heap_it *iterator;
- spl_heap_object *heap_object = (spl_heap_object*)zend_object_store_get_object(object TSRMLS_CC);
+ spl_heap_object *heap_object = (spl_heap_object*)Z_OBJ_P(object);
if (by_ref) {
zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0 TSRMLS_CC);
spl_handler_SplHeap.clone_obj = spl_heap_object_clone;
spl_handler_SplHeap.count_elements = spl_heap_object_count_elements;
spl_handler_SplHeap.get_debug_info = spl_heap_object_get_debug_info;
+ spl_handler_SplHeap.dtor_obj = zend_objects_destroy_object;
+ spl_handler_SplHeap.free_obj = spl_heap_object_free_storage;
REGISTER_SPL_IMPLEMENTS(SplHeap, Iterator);
REGISTER_SPL_IMPLEMENTS(SplHeap, Countable);