typedef struct _spl_dllist_it spl_dllist_it;
struct _spl_dllist_object {
- zend_object std;
spl_ptr_llist *llist;
int traverse_position;
spl_ptr_llist_element *traverse_pointer;
zend_function *fptr_count;
zend_class_entry *ce_get_iterator;
HashTable *debug_info;
+ zend_object std;
};
/* define an overloaded iterator structure */
int flags;
};
+static inline spl_dllist_object *spl_dllist_from_obj(zend_object *obj) /* {{{ */ {
+ return (spl_dllist_object*)((char*)(obj) - XtOffsetOf(spl_dllist_object, std));
+}
+/* }}} */
+
+#define Z_SPLDLLIST_P(zv) spl_dllist_from_obj(Z_OBJ_P((zv)))
+
/* {{{ spl_ptr_llist */
static void spl_ptr_llist_zval_dtor(spl_ptr_llist_element *elem TSRMLS_DC) { /* {{{ */
if (!ZVAL_IS_UNDEF(&elem->data)) {
static void spl_dllist_object_free_storage(zend_object *object TSRMLS_DC) /* {{{ */
{
- spl_dllist_object *intern = (spl_dllist_object *)object;
+ spl_dllist_object *intern = spl_dllist_from_obj(object);
zval tmp;
zend_object_std_dtor(&intern->std TSRMLS_CC);
efree(intern->debug_info);
}
- efree(object);
+ efree(intern);
}
/* }}} */
zend_class_entry *parent = class_type;
int inherited = 0;
- intern = ecalloc(1, sizeof(spl_dllist_object));
+ intern = ecalloc(1, sizeof(spl_dllist_object) + sizeof(zval) * (parent->default_properties_count - 1));
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*)Z_OBJ_P(orig);
+ spl_dllist_object *other = Z_SPLDLLIST_P(orig);
intern->ce_get_iterator = other->ce_get_iterator;
if (clone_orig) {
static int spl_dllist_object_count_elements(zval *object, long *count TSRMLS_DC) /* {{{ */
{
- spl_dllist_object *intern = (spl_dllist_object*)Z_OBJ_P(object);
+ spl_dllist_object *intern = Z_SPLDLLIST_P(object);
if (intern->fptr_count) {
zval rv;
static HashTable* spl_dllist_object_get_debug_info(zval *obj, int *is_temp TSRMLS_DC) /* {{{{ */
{
- spl_dllist_object *intern = (spl_dllist_object*)Z_OBJ_P(obj);
+ spl_dllist_object *intern = Z_SPLDLLIST_P(obj);
spl_ptr_llist_element *current = intern->llist->head, *next;
zval tmp, dllist_array;
zend_string *pnstr;
SEPARATE_ARG_IF_REF(value);
- intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ intern = Z_SPLDLLIST_P(getThis());
spl_ptr_llist_push(intern->llist, value TSRMLS_CC);
RETURN_TRUE;
SEPARATE_ARG_IF_REF(value);
- intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ intern = Z_SPLDLLIST_P(getThis());
spl_ptr_llist_unshift(intern->llist, value TSRMLS_CC);
RETURN_TRUE;
return;
}
- intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ intern = Z_SPLDLLIST_P(getThis());
spl_ptr_llist_pop(intern->llist, return_value TSRMLS_CC);
if (ZVAL_IS_UNDEF(return_value)) {
return;
}
- intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ intern = Z_SPLDLLIST_P(getThis());
spl_ptr_llist_shift(intern->llist, return_value TSRMLS_CC);
if (ZVAL_IS_UNDEF(return_value)) {
return;
}
- intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ intern = Z_SPLDLLIST_P(getThis());
value = spl_ptr_llist_last(intern->llist);
if (value == NULL || ZVAL_IS_UNDEF(value)) {
return;
}
- intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ intern = Z_SPLDLLIST_P(getThis());
value = spl_ptr_llist_first(intern->llist);
if (value == NULL || ZVAL_IS_UNDEF(value)) {
SPL_METHOD(SplDoublyLinkedList, count)
{
long count;
- spl_dllist_object *intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ spl_dllist_object *intern = Z_SPLDLLIST_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
return;
}
- intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ intern = Z_SPLDLLIST_P(getThis());
if (intern->flags & SPL_DLLIST_IT_FIX
&& (intern->flags & SPL_DLLIST_IT_LIFO) != (value & SPL_DLLIST_IT_LIFO)) {
return;
}
- intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ intern = Z_SPLDLLIST_P(getThis());
RETURN_LONG(intern->flags);
}
return;
}
- intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ intern = Z_SPLDLLIST_P(getThis());
index = spl_offset_convert_to_long(zindex TSRMLS_CC);
RETURN_BOOL(index >= 0 && index < intern->llist->count);
return;
}
- intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ intern = Z_SPLDLLIST_P(getThis());
index = spl_offset_convert_to_long(zindex TSRMLS_CC);
if (index < 0 || index >= intern->llist->count) {
}
SEPARATE_ARG_IF_REF(value);
- intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ intern = Z_SPLDLLIST_P(getThis());
if (Z_TYPE_P(zindex) == IS_NULL) {
/* $obj[] = ... */
return;
}
- intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ intern = Z_SPLDLLIST_P(getThis());
index = spl_offset_convert_to_long(zindex TSRMLS_CC);
llist = intern->llist;
static void spl_dllist_it_rewind(zend_object_iterator *iter TSRMLS_DC) /* {{{ */
{
spl_dllist_it *iterator = (spl_dllist_it *)iter;
- spl_dllist_object *object = (spl_dllist_object*)Z_OBJ(iter->data);
+ spl_dllist_object *object = Z_SPLDLLIST_P(&iter->data);
spl_ptr_llist *llist = object->llist;
spl_dllist_it_helper_rewind(&iterator->traverse_pointer, &iterator->traverse_position, llist, object->flags TSRMLS_CC);
static void spl_dllist_it_move_forward(zend_object_iterator *iter TSRMLS_DC) /* {{{ */
{
spl_dllist_it *iterator = (spl_dllist_it *)iter;
- spl_dllist_object *object = (spl_dllist_object*)Z_OBJ(iter->data);
+ spl_dllist_object *object = Z_SPLDLLIST_P(&iter->data);
zend_user_it_invalidate_current(iter TSRMLS_CC);
Return current array key */
SPL_METHOD(SplDoublyLinkedList, key)
{
- spl_dllist_object *intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ spl_dllist_object *intern = Z_SPLDLLIST_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
Move to next entry */
SPL_METHOD(SplDoublyLinkedList, prev)
{
- spl_dllist_object *intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ spl_dllist_object *intern = Z_SPLDLLIST_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
Move to next entry */
SPL_METHOD(SplDoublyLinkedList, next)
{
- spl_dllist_object *intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ spl_dllist_object *intern = Z_SPLDLLIST_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
Check whether the datastructure contains more entries */
SPL_METHOD(SplDoublyLinkedList, valid)
{
- spl_dllist_object *intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ spl_dllist_object *intern = Z_SPLDLLIST_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
Rewind the datastructure back to the start */
SPL_METHOD(SplDoublyLinkedList, rewind)
{
- spl_dllist_object *intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ spl_dllist_object *intern = Z_SPLDLLIST_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
Return current datastructure entry */
SPL_METHOD(SplDoublyLinkedList, current)
{
- spl_dllist_object *intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ spl_dllist_object *intern = Z_SPLDLLIST_P(getThis());
spl_ptr_llist_element *element = intern->traverse_pointer;
if (zend_parse_parameters_none() == FAILURE) {
Serializes storage */
SPL_METHOD(SplDoublyLinkedList, serialize)
{
- spl_dllist_object *intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ spl_dllist_object *intern = Z_SPLDLLIST_P(getThis());
smart_str buf = {0};
spl_ptr_llist_element *current = intern->llist->head, *next;
zval flags;
Unserializes storage */
SPL_METHOD(SplDoublyLinkedList, unserialize)
{
- spl_dllist_object *intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ spl_dllist_object *intern = Z_SPLDLLIST_P(getThis());
zval flags, elem;
char *buf;
int buf_len;
return;
}
- intern = (spl_dllist_object*)Z_OBJ_P(getThis());
+ intern = Z_SPLDLLIST_P(getThis());
index = spl_offset_convert_to_long(zindex TSRMLS_CC);
if (index < 0 || index > intern->llist->count) {
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*)Z_OBJ_P(object);
+ spl_dllist_object *dllist_object = Z_SPLDLLIST_P(object);
if (by_ref) {
zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0 TSRMLS_CC);