2008-01-15 17:38:15 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2014-09-20 00:33:14 +08:00
|
|
|
| PHP Version 7 |
|
2008-01-15 17:38:15 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2018-01-02 12:57:58 +08:00
|
|
|
| Copyright (c) 1997-2018 The PHP Group |
|
2008-01-15 17:38:15 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available through the world-wide-web at the following url: |
|
|
|
|
| http://www.php.net/license/3_01.txt |
|
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Etienne Kneuss <colder@php.net> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "php.h"
|
|
|
|
#include "zend_exceptions.h"
|
|
|
|
#include "zend_hash.h"
|
|
|
|
|
|
|
|
#include "php_spl.h"
|
2011-07-13 05:43:17 +08:00
|
|
|
#include "ext/standard/info.h"
|
|
|
|
#include "ext/standard/php_var.h"
|
2014-09-21 04:42:02 +08:00
|
|
|
#include "zend_smart_str.h"
|
2008-01-15 17:38:15 +08:00
|
|
|
#include "spl_functions.h"
|
|
|
|
#include "spl_engine.h"
|
|
|
|
#include "spl_iterators.h"
|
|
|
|
#include "spl_dllist.h"
|
|
|
|
#include "spl_exceptions.h"
|
|
|
|
|
|
|
|
zend_object_handlers spl_handler_SplDoublyLinkedList;
|
|
|
|
PHPAPI zend_class_entry *spl_ce_SplDoublyLinkedList;
|
|
|
|
PHPAPI zend_class_entry *spl_ce_SplQueue;
|
|
|
|
PHPAPI zend_class_entry *spl_ce_SplStack;
|
|
|
|
|
2008-01-20 21:26:03 +08:00
|
|
|
#define SPL_LLIST_DELREF(elem) if(!--(elem)->rc) { \
|
2008-01-15 17:38:15 +08:00
|
|
|
efree(elem); \
|
|
|
|
}
|
|
|
|
|
2008-01-20 21:26:03 +08:00
|
|
|
#define SPL_LLIST_CHECK_DELREF(elem) if((elem) && !--(elem)->rc) { \
|
2008-01-15 17:38:15 +08:00
|
|
|
efree(elem); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SPL_LLIST_ADDREF(elem) (elem)->rc++
|
|
|
|
#define SPL_LLIST_CHECK_ADDREF(elem) if(elem) (elem)->rc++
|
|
|
|
|
|
|
|
#define SPL_DLLIST_IT_DELETE 0x00000001 /* Delete flag makes the iterator delete the current element on next */
|
|
|
|
#define SPL_DLLIST_IT_LIFO 0x00000002 /* LIFO flag makes the iterator traverse the structure as a LastInFirstOut */
|
|
|
|
#define SPL_DLLIST_IT_MASK 0x00000003 /* Mask to isolate flags related to iterators */
|
|
|
|
#define SPL_DLLIST_IT_FIX 0x00000004 /* Backward/Forward bit is fixed */
|
|
|
|
|
|
|
|
#ifdef accept
|
|
|
|
#undef accept
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct _spl_ptr_llist_element {
|
|
|
|
struct _spl_ptr_llist_element *prev;
|
|
|
|
struct _spl_ptr_llist_element *next;
|
|
|
|
int rc;
|
2014-02-16 22:15:54 +08:00
|
|
|
zval data;
|
2008-01-15 17:38:15 +08:00
|
|
|
} spl_ptr_llist_element;
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
typedef void (*spl_ptr_llist_dtor_func)(spl_ptr_llist_element *);
|
|
|
|
typedef void (*spl_ptr_llist_ctor_func)(spl_ptr_llist_element *);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
|
|
|
typedef struct _spl_ptr_llist {
|
|
|
|
spl_ptr_llist_element *head;
|
|
|
|
spl_ptr_llist_element *tail;
|
|
|
|
spl_ptr_llist_dtor_func dtor;
|
2008-01-23 03:55:31 +08:00
|
|
|
spl_ptr_llist_ctor_func ctor;
|
2008-01-15 17:38:15 +08:00
|
|
|
int count;
|
|
|
|
} spl_ptr_llist;
|
|
|
|
|
|
|
|
typedef struct _spl_dllist_object spl_dllist_object;
|
|
|
|
typedef struct _spl_dllist_it spl_dllist_it;
|
|
|
|
|
|
|
|
struct _spl_dllist_object {
|
|
|
|
spl_ptr_llist *llist;
|
|
|
|
int traverse_position;
|
|
|
|
spl_ptr_llist_element *traverse_pointer;
|
|
|
|
int flags;
|
|
|
|
zend_function *fptr_offset_get;
|
|
|
|
zend_function *fptr_offset_set;
|
|
|
|
zend_function *fptr_offset_has;
|
|
|
|
zend_function *fptr_offset_del;
|
2008-07-07 07:45:56 +08:00
|
|
|
zend_function *fptr_count;
|
2008-01-15 17:38:15 +08:00
|
|
|
zend_class_entry *ce_get_iterator;
|
2015-04-16 21:13:15 +08:00
|
|
|
zval *gc_data;
|
|
|
|
int gc_data_count;
|
2014-03-15 14:44:50 +08:00
|
|
|
zend_object std;
|
2008-01-15 17:38:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* define an overloaded iterator structure */
|
|
|
|
struct _spl_dllist_it {
|
|
|
|
zend_user_iterator intern;
|
|
|
|
spl_ptr_llist_element *traverse_pointer;
|
2014-09-17 15:10:26 +08:00
|
|
|
int traverse_position;
|
2008-01-15 17:38:15 +08:00
|
|
|
int flags;
|
|
|
|
};
|
|
|
|
|
2014-03-15 14:44:50 +08:00
|
|
|
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)))
|
|
|
|
|
2008-01-15 17:38:15 +08:00
|
|
|
/* {{{ spl_ptr_llist */
|
2014-12-14 06:06:14 +08:00
|
|
|
static void spl_ptr_llist_zval_dtor(spl_ptr_llist_element *elem) { /* {{{ */
|
2014-05-03 16:06:27 +08:00
|
|
|
if (!Z_ISUNDEF(elem->data)) {
|
2014-02-16 22:15:54 +08:00
|
|
|
zval_ptr_dtor(&elem->data);
|
|
|
|
ZVAL_UNDEF(&elem->data);
|
2008-01-20 21:26:03 +08:00
|
|
|
}
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void spl_ptr_llist_zval_ctor(spl_ptr_llist_element *elem) { /* {{{ */
|
2014-02-27 22:50:31 +08:00
|
|
|
if (Z_REFCOUNTED(elem->data)) {
|
2014-02-28 22:44:50 +08:00
|
|
|
Z_ADDREF(elem->data);
|
2014-02-27 22:50:31 +08:00
|
|
|
}
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2008-01-23 03:55:31 +08:00
|
|
|
static spl_ptr_llist *spl_ptr_llist_init(spl_ptr_llist_ctor_func ctor, spl_ptr_llist_dtor_func dtor) /* {{{ */
|
2008-01-15 17:38:15 +08:00
|
|
|
{
|
|
|
|
spl_ptr_llist *llist = emalloc(sizeof(spl_ptr_llist));
|
|
|
|
|
|
|
|
llist->head = NULL;
|
|
|
|
llist->tail = NULL;
|
|
|
|
llist->count = 0;
|
|
|
|
llist->dtor = dtor;
|
2008-01-23 03:55:31 +08:00
|
|
|
llist->ctor = ctor;
|
2008-01-15 17:38:15 +08:00
|
|
|
|
|
|
|
return llist;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-08-26 01:24:55 +08:00
|
|
|
static zend_long spl_ptr_llist_count(spl_ptr_llist *llist) /* {{{ */
|
2008-01-15 17:38:15 +08:00
|
|
|
{
|
2014-08-26 01:24:55 +08:00
|
|
|
return (zend_long)llist->count;
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void spl_ptr_llist_destroy(spl_ptr_llist *llist) /* {{{ */
|
2008-01-15 17:38:15 +08:00
|
|
|
{
|
|
|
|
spl_ptr_llist_element *current = llist->head, *next;
|
|
|
|
spl_ptr_llist_dtor_func dtor = llist->dtor;
|
|
|
|
|
|
|
|
while (current) {
|
|
|
|
next = current->next;
|
2016-03-10 15:43:22 +08:00
|
|
|
if (dtor) {
|
2014-12-14 06:06:14 +08:00
|
|
|
dtor(current);
|
2008-01-20 21:26:03 +08:00
|
|
|
}
|
|
|
|
SPL_LLIST_DELREF(current);
|
2008-01-15 17:38:15 +08:00
|
|
|
current = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
efree(llist);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-08-26 01:24:55 +08:00
|
|
|
static spl_ptr_llist_element *spl_ptr_llist_offset(spl_ptr_llist *llist, zend_long offset, int backward) /* {{{ */
|
2008-01-15 17:38:15 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
spl_ptr_llist_element *current;
|
2008-01-15 23:46:20 +08:00
|
|
|
int pos = 0;
|
2008-01-15 17:38:15 +08:00
|
|
|
|
|
|
|
if (backward) {
|
|
|
|
current = llist->tail;
|
|
|
|
} else {
|
|
|
|
current = llist->head;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (current && pos < offset) {
|
|
|
|
pos++;
|
|
|
|
if (backward) {
|
|
|
|
current = current->prev;
|
|
|
|
} else {
|
|
|
|
current = current->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return current;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void spl_ptr_llist_unshift(spl_ptr_llist *llist, zval *data) /* {{{ */
|
2008-01-15 17:38:15 +08:00
|
|
|
{
|
|
|
|
spl_ptr_llist_element *elem = emalloc(sizeof(spl_ptr_llist_element));
|
|
|
|
|
|
|
|
elem->rc = 1;
|
|
|
|
elem->prev = NULL;
|
|
|
|
elem->next = llist->head;
|
2014-02-16 22:15:54 +08:00
|
|
|
ZVAL_COPY_VALUE(&elem->data, data);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
|
|
|
if (llist->head) {
|
|
|
|
llist->head->prev = elem;
|
|
|
|
} else {
|
|
|
|
llist->tail = elem;
|
|
|
|
}
|
|
|
|
|
|
|
|
llist->head = elem;
|
|
|
|
llist->count++;
|
2008-01-23 03:55:31 +08:00
|
|
|
|
|
|
|
if (llist->ctor) {
|
2014-12-14 06:06:14 +08:00
|
|
|
llist->ctor(elem);
|
2008-01-23 03:55:31 +08:00
|
|
|
}
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void spl_ptr_llist_push(spl_ptr_llist *llist, zval *data) /* {{{ */
|
2008-01-15 17:38:15 +08:00
|
|
|
{
|
|
|
|
spl_ptr_llist_element *elem = emalloc(sizeof(spl_ptr_llist_element));
|
|
|
|
|
|
|
|
elem->rc = 1;
|
|
|
|
elem->prev = llist->tail;
|
|
|
|
elem->next = NULL;
|
2014-02-16 22:15:54 +08:00
|
|
|
ZVAL_COPY_VALUE(&elem->data, data);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
|
|
|
if (llist->tail) {
|
|
|
|
llist->tail->next = elem;
|
|
|
|
} else {
|
|
|
|
llist->head = elem;
|
|
|
|
}
|
|
|
|
|
|
|
|
llist->tail = elem;
|
|
|
|
llist->count++;
|
2008-01-23 03:55:31 +08:00
|
|
|
|
|
|
|
if (llist->ctor) {
|
2014-12-14 06:06:14 +08:00
|
|
|
llist->ctor(elem);
|
2008-01-23 03:55:31 +08:00
|
|
|
}
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void spl_ptr_llist_pop(spl_ptr_llist *llist, zval *ret) /* {{{ */
|
2008-01-15 17:38:15 +08:00
|
|
|
{
|
|
|
|
spl_ptr_llist_element *tail = llist->tail;
|
|
|
|
|
|
|
|
if (tail == NULL) {
|
2014-02-16 22:15:54 +08:00
|
|
|
ZVAL_UNDEF(ret);
|
|
|
|
return;
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tail->prev) {
|
|
|
|
tail->prev->next = NULL;
|
|
|
|
} else {
|
|
|
|
llist->head = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
llist->tail = tail->prev;
|
|
|
|
llist->count--;
|
2014-02-16 22:15:54 +08:00
|
|
|
ZVAL_COPY(ret, &tail->data);
|
2008-01-23 03:55:31 +08:00
|
|
|
|
2020-01-23 21:19:20 +08:00
|
|
|
tail->prev = NULL;
|
2008-01-23 03:55:31 +08:00
|
|
|
if (llist->dtor) {
|
2014-12-14 06:06:14 +08:00
|
|
|
llist->dtor(tail);
|
2008-01-23 03:55:31 +08:00
|
|
|
}
|
|
|
|
|
2014-02-16 22:15:54 +08:00
|
|
|
ZVAL_UNDEF(&tail->data);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2008-01-20 21:26:03 +08:00
|
|
|
SPL_LLIST_DELREF(tail);
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-02-16 22:15:54 +08:00
|
|
|
static zval *spl_ptr_llist_last(spl_ptr_llist *llist) /* {{{ */
|
2008-01-15 17:38:15 +08:00
|
|
|
{
|
|
|
|
spl_ptr_llist_element *tail = llist->tail;
|
|
|
|
|
|
|
|
if (tail == NULL) {
|
|
|
|
return NULL;
|
|
|
|
} else {
|
2014-02-16 22:15:54 +08:00
|
|
|
return &tail->data;
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-02-16 22:15:54 +08:00
|
|
|
static zval *spl_ptr_llist_first(spl_ptr_llist *llist) /* {{{ */
|
2008-01-15 17:38:15 +08:00
|
|
|
{
|
|
|
|
spl_ptr_llist_element *head = llist->head;
|
|
|
|
|
|
|
|
if (head == NULL) {
|
|
|
|
return NULL;
|
|
|
|
} else {
|
2014-02-16 22:15:54 +08:00
|
|
|
return &head->data;
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void spl_ptr_llist_shift(spl_ptr_llist *llist, zval *ret) /* {{{ */
|
2008-01-15 17:38:15 +08:00
|
|
|
{
|
|
|
|
spl_ptr_llist_element *head = llist->head;
|
|
|
|
|
|
|
|
if (head == NULL) {
|
2014-02-16 22:15:54 +08:00
|
|
|
ZVAL_UNDEF(ret);
|
|
|
|
return;
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (head->next) {
|
|
|
|
head->next->prev = NULL;
|
|
|
|
} else {
|
|
|
|
llist->tail = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
llist->head = head->next;
|
|
|
|
llist->count--;
|
2014-02-16 22:15:54 +08:00
|
|
|
ZVAL_COPY(ret, &head->data);
|
2008-01-23 03:55:31 +08:00
|
|
|
|
2020-01-23 21:19:20 +08:00
|
|
|
head->next = NULL;
|
2008-01-23 03:55:31 +08:00
|
|
|
if (llist->dtor) {
|
2014-12-14 06:06:14 +08:00
|
|
|
llist->dtor(head);
|
2008-01-23 03:55:31 +08:00
|
|
|
}
|
2014-02-16 22:15:54 +08:00
|
|
|
ZVAL_UNDEF(&head->data);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2008-01-20 21:26:03 +08:00
|
|
|
SPL_LLIST_DELREF(head);
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void spl_ptr_llist_copy(spl_ptr_llist *from, spl_ptr_llist *to) /* {{{ */
|
2008-01-15 17:38:15 +08:00
|
|
|
{
|
2014-02-18 17:42:46 +08:00
|
|
|
spl_ptr_llist_element *current = from->head, *next;
|
2014-04-22 21:46:34 +08:00
|
|
|
//??? spl_ptr_llist_ctor_func ctor = from->ctor;
|
2008-01-15 17:38:15 +08:00
|
|
|
|
|
|
|
while (current) {
|
|
|
|
next = current->next;
|
2008-01-23 03:55:31 +08:00
|
|
|
|
2014-04-22 21:46:34 +08:00
|
|
|
/*??? FIXME
|
2008-01-15 17:38:15 +08:00
|
|
|
if (ctor) {
|
2014-12-14 06:06:14 +08:00
|
|
|
ctor(current);
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
2014-02-16 22:15:54 +08:00
|
|
|
*/
|
2008-01-23 03:55:31 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
spl_ptr_llist_push(to, ¤t->data);
|
2008-01-15 17:38:15 +08:00
|
|
|
current = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void spl_dllist_object_free_storage(zend_object *object) /* {{{ */
|
2008-02-11 21:59:23 +08:00
|
|
|
{
|
2014-03-15 14:44:50 +08:00
|
|
|
spl_dllist_object *intern = spl_dllist_from_obj(object);
|
2014-02-16 22:15:54 +08:00
|
|
|
zval tmp;
|
2008-02-11 21:59:23 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_object_std_dtor(&intern->std);
|
2008-02-11 21:59:23 +08:00
|
|
|
|
2014-02-16 22:15:54 +08:00
|
|
|
while (intern->llist->count > 0) {
|
2014-12-14 06:06:14 +08:00
|
|
|
spl_ptr_llist_pop(intern->llist, &tmp);
|
2008-02-11 21:59:23 +08:00
|
|
|
zval_ptr_dtor(&tmp);
|
|
|
|
}
|
|
|
|
|
2015-04-16 21:13:15 +08:00
|
|
|
if (intern->gc_data != NULL) {
|
|
|
|
efree(intern->gc_data);
|
|
|
|
};
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
spl_ptr_llist_destroy(intern->llist);
|
2009-06-17 21:27:09 +08:00
|
|
|
SPL_LLIST_CHECK_DELREF(intern->traverse_pointer);
|
2008-02-11 21:59:23 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_object_iterator *spl_dllist_get_iterator(zend_class_entry *ce, zval *object, int by_ref);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static zend_object *spl_dllist_object_new_ex(zend_class_entry *class_type, zval *orig, int clone_orig) /* {{{ */
|
2008-01-15 17:38:15 +08:00
|
|
|
{
|
|
|
|
spl_dllist_object *intern;
|
|
|
|
zend_class_entry *parent = class_type;
|
|
|
|
int inherited = 0;
|
|
|
|
|
2017-11-25 23:07:51 +08:00
|
|
|
intern = zend_object_alloc(sizeof(spl_dllist_object), parent);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_object_std_init(&intern->std, class_type);
|
2010-05-24 22:11:39 +08:00
|
|
|
object_properties_init(&intern->std, class_type);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
|
|
|
intern->flags = 0;
|
|
|
|
intern->traverse_position = 0;
|
|
|
|
|
|
|
|
if (orig) {
|
2014-03-15 14:44:50 +08:00
|
|
|
spl_dllist_object *other = Z_SPLDLLIST_P(orig);
|
2008-01-15 17:38:15 +08:00
|
|
|
intern->ce_get_iterator = other->ce_get_iterator;
|
|
|
|
|
|
|
|
if (clone_orig) {
|
2008-01-23 03:55:31 +08:00
|
|
|
intern->llist = (spl_ptr_llist *)spl_ptr_llist_init(other->llist->ctor, other->llist->dtor);
|
2014-12-14 06:06:14 +08:00
|
|
|
spl_ptr_llist_copy(other->llist, intern->llist);
|
2008-01-15 17:38:15 +08:00
|
|
|
intern->traverse_pointer = intern->llist->head;
|
2009-08-03 05:21:46 +08:00
|
|
|
SPL_LLIST_CHECK_ADDREF(intern->traverse_pointer);
|
2008-01-15 17:38:15 +08:00
|
|
|
} else {
|
|
|
|
intern->llist = other->llist;
|
|
|
|
intern->traverse_pointer = intern->llist->head;
|
|
|
|
SPL_LLIST_CHECK_ADDREF(intern->traverse_pointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
intern->flags = other->flags;
|
|
|
|
} else {
|
2008-01-23 03:55:31 +08:00
|
|
|
intern->llist = (spl_ptr_llist *)spl_ptr_llist_init(spl_ptr_llist_zval_ctor, spl_ptr_llist_zval_dtor);
|
2008-01-15 17:38:15 +08:00
|
|
|
intern->traverse_pointer = intern->llist->head;
|
|
|
|
SPL_LLIST_CHECK_ADDREF(intern->traverse_pointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (parent) {
|
|
|
|
if (parent == spl_ce_SplStack) {
|
|
|
|
intern->flags |= (SPL_DLLIST_IT_FIX | SPL_DLLIST_IT_LIFO);
|
2014-02-16 22:15:54 +08:00
|
|
|
intern->std.handlers = &spl_handler_SplDoublyLinkedList;
|
2008-01-15 17:38:15 +08:00
|
|
|
} else if (parent == spl_ce_SplQueue) {
|
|
|
|
intern->flags |= SPL_DLLIST_IT_FIX;
|
2014-02-16 22:15:54 +08:00
|
|
|
intern->std.handlers = &spl_handler_SplDoublyLinkedList;
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
2008-01-23 03:55:31 +08:00
|
|
|
|
2008-01-15 17:38:15 +08:00
|
|
|
if (parent == spl_ce_SplDoublyLinkedList) {
|
2014-02-16 22:15:54 +08:00
|
|
|
intern->std.handlers = &spl_handler_SplDoublyLinkedList;
|
2008-01-15 17:38:15 +08:00
|
|
|
break;
|
|
|
|
}
|
2008-01-23 03:55:31 +08:00
|
|
|
|
2008-01-15 17:38:15 +08:00
|
|
|
parent = parent->parent;
|
|
|
|
inherited = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!parent) { /* this must never happen */
|
2014-12-14 06:06:14 +08:00
|
|
|
php_error_docref(NULL, E_COMPILE_ERROR, "Internal compiler error, Class is not child of SplDoublyLinkedList");
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
if (inherited) {
|
2014-02-16 22:15:54 +08:00
|
|
|
intern->fptr_offset_get = zend_hash_str_find_ptr(&class_type->function_table, "offsetget", sizeof("offsetget") - 1);
|
2008-01-15 17:38:15 +08:00
|
|
|
if (intern->fptr_offset_get->common.scope == parent) {
|
|
|
|
intern->fptr_offset_get = NULL;
|
|
|
|
}
|
2014-02-16 22:15:54 +08:00
|
|
|
intern->fptr_offset_set = zend_hash_str_find_ptr(&class_type->function_table, "offsetset", sizeof("offsetset") - 1);
|
2008-01-15 17:38:15 +08:00
|
|
|
if (intern->fptr_offset_set->common.scope == parent) {
|
|
|
|
intern->fptr_offset_set = NULL;
|
|
|
|
}
|
2014-02-16 22:15:54 +08:00
|
|
|
intern->fptr_offset_has = zend_hash_str_find_ptr(&class_type->function_table, "offsetexists", sizeof("offsetexists") - 1);
|
2008-01-15 17:38:15 +08:00
|
|
|
if (intern->fptr_offset_has->common.scope == parent) {
|
|
|
|
intern->fptr_offset_has = NULL;
|
|
|
|
}
|
2014-02-16 22:15:54 +08:00
|
|
|
intern->fptr_offset_del = zend_hash_str_find_ptr(&class_type->function_table, "offsetunset", sizeof("offsetunset") - 1);
|
2008-01-15 17:38:15 +08:00
|
|
|
if (intern->fptr_offset_del->common.scope == parent) {
|
|
|
|
intern->fptr_offset_del = NULL;
|
|
|
|
}
|
2014-02-16 22:15:54 +08:00
|
|
|
intern->fptr_count = zend_hash_str_find_ptr(&class_type->function_table, "count", sizeof("count") - 1);
|
2008-07-07 07:45:56 +08:00
|
|
|
if (intern->fptr_count->common.scope == parent) {
|
|
|
|
intern->fptr_count = NULL;
|
|
|
|
}
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
|
2014-02-16 22:15:54 +08:00
|
|
|
return &intern->std;
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static zend_object *spl_dllist_object_new(zend_class_entry *class_type) /* {{{ */
|
2008-01-15 17:38:15 +08:00
|
|
|
{
|
2014-12-14 06:06:14 +08:00
|
|
|
return spl_dllist_object_new_ex(class_type, NULL, 0);
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static zend_object *spl_dllist_object_clone(zval *zobject) /* {{{ */
|
2008-01-15 17:38:15 +08:00
|
|
|
{
|
|
|
|
zend_object *old_object;
|
|
|
|
zend_object *new_object;
|
|
|
|
|
2014-02-16 22:15:54 +08:00
|
|
|
old_object = Z_OBJ_P(zobject);
|
2014-12-14 06:06:14 +08:00
|
|
|
new_object = spl_dllist_object_new_ex(old_object->ce, zobject, 1);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_objects_clone_members(new_object, old_object);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2014-02-16 22:15:54 +08:00
|
|
|
return new_object;
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static int spl_dllist_object_count_elements(zval *object, zend_long *count) /* {{{ */
|
2008-01-15 17:38:15 +08:00
|
|
|
{
|
2014-03-15 14:44:50 +08:00
|
|
|
spl_dllist_object *intern = Z_SPLDLLIST_P(object);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2008-07-07 07:45:56 +08:00
|
|
|
if (intern->fptr_count) {
|
2014-02-16 22:15:54 +08:00
|
|
|
zval rv;
|
|
|
|
zend_call_method_with_0_params(object, intern->std.ce, &intern->fptr_count, "count", &rv);
|
2014-05-03 16:06:27 +08:00
|
|
|
if (!Z_ISUNDEF(rv)) {
|
2014-10-10 21:32:04 +08:00
|
|
|
*count = zval_get_long(&rv);
|
|
|
|
zval_ptr_dtor(&rv);
|
2008-07-07 07:45:56 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
*count = 0;
|
|
|
|
return FAILURE;
|
|
|
|
}
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2008-07-07 07:45:56 +08:00
|
|
|
*count = spl_ptr_llist_count(intern->llist);
|
2008-01-15 17:38:15 +08:00
|
|
|
return SUCCESS;
|
2015-01-03 17:22:58 +08:00
|
|
|
}
|
2008-01-15 17:38:15 +08:00
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static HashTable* spl_dllist_object_get_debug_info(zval *obj, int *is_temp) /* {{{{ */
|
2008-02-19 08:04:20 +08:00
|
|
|
{
|
2014-03-15 14:44:50 +08:00
|
|
|
spl_dllist_object *intern = Z_SPLDLLIST_P(obj);
|
2008-02-19 08:04:20 +08:00
|
|
|
spl_ptr_llist_element *current = intern->llist->head, *next;
|
2014-02-16 22:15:54 +08:00
|
|
|
zval tmp, dllist_array;
|
2014-02-17 21:59:18 +08:00
|
|
|
zend_string *pnstr;
|
2009-08-14 06:07:05 +08:00
|
|
|
int i = 0;
|
2015-04-16 03:07:34 +08:00
|
|
|
HashTable *debug_info;
|
|
|
|
*is_temp = 1;
|
2008-02-19 08:04:20 +08:00
|
|
|
|
2015-04-16 03:07:34 +08:00
|
|
|
if (!intern->std.properties) {
|
|
|
|
rebuild_object_properties(&intern->std);
|
2009-08-14 06:07:05 +08:00
|
|
|
}
|
2008-02-19 08:04:20 +08:00
|
|
|
|
2017-09-20 07:25:56 +08:00
|
|
|
debug_info = zend_new_array(1);
|
2015-04-16 03:07:34 +08:00
|
|
|
zend_hash_copy(debug_info, intern->std.properties, (copy_ctor_func_t) zval_add_ref);
|
2008-02-19 08:04:20 +08:00
|
|
|
|
2015-04-16 03:07:34 +08:00
|
|
|
pnstr = spl_gen_private_prop_name(spl_ce_SplDoublyLinkedList, "flags", sizeof("flags")-1);
|
|
|
|
ZVAL_LONG(&tmp, intern->flags);
|
|
|
|
zend_hash_add(debug_info, pnstr, &tmp);
|
2018-05-28 21:27:12 +08:00
|
|
|
zend_string_release_ex(pnstr, 0);
|
2008-02-19 08:04:20 +08:00
|
|
|
|
2015-04-16 03:07:34 +08:00
|
|
|
array_init(&dllist_array);
|
2008-02-19 08:04:20 +08:00
|
|
|
|
2015-04-16 03:07:34 +08:00
|
|
|
while (current) {
|
|
|
|
next = current->next;
|
2008-02-19 08:04:20 +08:00
|
|
|
|
2015-04-16 03:07:34 +08:00
|
|
|
add_index_zval(&dllist_array, i, ¤t->data);
|
|
|
|
if (Z_REFCOUNTED(current->data)) {
|
|
|
|
Z_ADDREF(current->data);
|
2009-08-14 06:07:05 +08:00
|
|
|
}
|
2015-04-16 03:07:34 +08:00
|
|
|
i++;
|
2008-02-19 08:04:20 +08:00
|
|
|
|
2015-04-16 03:07:34 +08:00
|
|
|
current = next;
|
2009-08-14 06:07:05 +08:00
|
|
|
}
|
2008-02-19 08:04:20 +08:00
|
|
|
|
2015-04-16 03:07:34 +08:00
|
|
|
pnstr = spl_gen_private_prop_name(spl_ce_SplDoublyLinkedList, "dllist", sizeof("dllist")-1);
|
|
|
|
zend_hash_add(debug_info, pnstr, &dllist_array);
|
2018-05-28 21:27:12 +08:00
|
|
|
zend_string_release_ex(pnstr, 0);
|
2015-04-16 03:07:34 +08:00
|
|
|
|
|
|
|
return debug_info;
|
2008-02-19 08:04:20 +08:00
|
|
|
}
|
|
|
|
/* }}}} */
|
|
|
|
|
2015-04-16 21:13:15 +08:00
|
|
|
static HashTable *spl_dllist_object_get_gc(zval *obj, zval **gc_data, int *gc_data_count) /* {{{ */
|
|
|
|
{
|
|
|
|
spl_dllist_object *intern = Z_SPLDLLIST_P(obj);
|
|
|
|
spl_ptr_llist_element *current = intern->llist->head;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
if (intern->gc_data_count < intern->llist->count) {
|
|
|
|
intern->gc_data_count = intern->llist->count;
|
|
|
|
intern->gc_data = safe_erealloc(intern->gc_data, intern->gc_data_count, sizeof(zval), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (current) {
|
|
|
|
ZVAL_COPY_VALUE(&intern->gc_data[i++], ¤t->data);
|
|
|
|
current = current->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
*gc_data = intern->gc_data;
|
|
|
|
*gc_data_count = i;
|
|
|
|
return zend_std_get_properties(obj);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2015-06-24 05:46:07 +08:00
|
|
|
/* {{{ proto bool SplDoublyLinkedList::push(mixed value)
|
2008-01-15 17:38:15 +08:00
|
|
|
Push $value on the SplDoublyLinkedList */
|
|
|
|
SPL_METHOD(SplDoublyLinkedList, push)
|
|
|
|
{
|
|
|
|
zval *value;
|
2008-01-15 23:46:20 +08:00
|
|
|
spl_dllist_object *intern;
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &value) == FAILURE) {
|
2008-01-15 17:38:15 +08:00
|
|
|
return;
|
|
|
|
}
|
2008-01-23 03:55:31 +08:00
|
|
|
|
2014-03-15 14:44:50 +08:00
|
|
|
intern = Z_SPLDLLIST_P(getThis());
|
2014-12-14 06:06:14 +08:00
|
|
|
spl_ptr_llist_push(intern->llist, value);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
|
|
|
RETURN_TRUE;
|
2015-01-03 17:22:58 +08:00
|
|
|
}
|
2008-01-15 17:38:15 +08:00
|
|
|
/* }}} */
|
|
|
|
|
2015-06-24 05:46:07 +08:00
|
|
|
/* {{{ proto bool SplDoublyLinkedList::unshift(mixed value)
|
2008-01-15 17:38:15 +08:00
|
|
|
Unshift $value on the SplDoublyLinkedList */
|
|
|
|
SPL_METHOD(SplDoublyLinkedList, unshift)
|
|
|
|
{
|
|
|
|
zval *value;
|
2008-01-15 23:46:20 +08:00
|
|
|
spl_dllist_object *intern;
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &value) == FAILURE) {
|
2008-01-15 17:38:15 +08:00
|
|
|
return;
|
|
|
|
}
|
2008-01-23 03:55:31 +08:00
|
|
|
|
2014-03-15 14:44:50 +08:00
|
|
|
intern = Z_SPLDLLIST_P(getThis());
|
2014-12-14 06:06:14 +08:00
|
|
|
spl_ptr_llist_unshift(intern->llist, value);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-02-16 22:15:54 +08:00
|
|
|
/* {{{ proto mixed SplDoublyLinkedList::pop()
|
2008-01-23 03:55:31 +08:00
|
|
|
Pop an element out of the SplDoublyLinkedList */
|
2008-01-15 17:38:15 +08:00
|
|
|
SPL_METHOD(SplDoublyLinkedList, pop)
|
|
|
|
{
|
2008-01-15 23:46:20 +08:00
|
|
|
spl_dllist_object *intern;
|
|
|
|
|
2013-10-12 00:32:40 +08:00
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
2008-01-15 17:38:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-15 14:44:50 +08:00
|
|
|
intern = Z_SPLDLLIST_P(getThis());
|
2014-12-14 06:06:14 +08:00
|
|
|
spl_ptr_llist_pop(intern->llist, return_value);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2014-05-03 16:06:27 +08:00
|
|
|
if (Z_ISUNDEF_P(return_value)) {
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_throw_exception(spl_ce_RuntimeException, "Can't pop from an empty datastructure", 0);
|
2014-02-16 22:15:54 +08:00
|
|
|
RETURN_NULL();
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
}
|
2008-01-15 17:38:15 +08:00
|
|
|
/* }}} */
|
|
|
|
|
2014-02-16 22:15:54 +08:00
|
|
|
/* {{{ proto mixed SplDoublyLinkedList::shift()
|
2008-01-23 03:55:31 +08:00
|
|
|
Shift an element out of the SplDoublyLinkedList */
|
2008-01-15 17:38:15 +08:00
|
|
|
SPL_METHOD(SplDoublyLinkedList, shift)
|
|
|
|
{
|
2008-01-15 23:46:20 +08:00
|
|
|
spl_dllist_object *intern;
|
|
|
|
|
2013-10-12 00:32:40 +08:00
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
2008-01-15 17:38:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-15 14:44:50 +08:00
|
|
|
intern = Z_SPLDLLIST_P(getThis());
|
2014-12-14 06:06:14 +08:00
|
|
|
spl_ptr_llist_shift(intern->llist, return_value);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2014-05-03 16:06:27 +08:00
|
|
|
if (Z_ISUNDEF_P(return_value)) {
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_throw_exception(spl_ce_RuntimeException, "Can't shift from an empty datastructure", 0);
|
2014-02-16 22:15:54 +08:00
|
|
|
RETURN_NULL();
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
}
|
2008-01-15 17:38:15 +08:00
|
|
|
/* }}} */
|
|
|
|
|
2014-02-16 22:15:54 +08:00
|
|
|
/* {{{ proto mixed SplDoublyLinkedList::top()
|
2008-01-23 03:55:31 +08:00
|
|
|
Peek at the top element of the SplDoublyLinkedList */
|
2008-01-15 17:38:15 +08:00
|
|
|
SPL_METHOD(SplDoublyLinkedList, top)
|
|
|
|
{
|
|
|
|
zval *value;
|
2008-01-15 23:46:20 +08:00
|
|
|
spl_dllist_object *intern;
|
|
|
|
|
2013-10-12 00:32:40 +08:00
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
2008-01-15 17:38:15 +08:00
|
|
|
return;
|
|
|
|
}
|
2008-01-23 03:55:31 +08:00
|
|
|
|
2014-03-15 14:44:50 +08:00
|
|
|
intern = Z_SPLDLLIST_P(getThis());
|
2014-02-16 22:15:54 +08:00
|
|
|
value = spl_ptr_llist_last(intern->llist);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2014-05-03 16:06:27 +08:00
|
|
|
if (value == NULL || Z_ISUNDEF_P(value)) {
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_throw_exception(spl_ce_RuntimeException, "Can't peek at an empty datastructure", 0);
|
2008-01-15 17:38:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-09 17:46:46 +08:00
|
|
|
ZVAL_COPY_DEREF(return_value, value);
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-02-16 22:15:54 +08:00
|
|
|
/* {{{ proto mixed SplDoublyLinkedList::bottom()
|
2008-01-23 03:55:31 +08:00
|
|
|
Peek at the bottom element of the SplDoublyLinkedList */
|
2008-01-15 17:38:15 +08:00
|
|
|
SPL_METHOD(SplDoublyLinkedList, bottom)
|
|
|
|
{
|
|
|
|
zval *value;
|
2008-01-15 23:46:20 +08:00
|
|
|
spl_dllist_object *intern;
|
|
|
|
|
2013-10-12 00:32:40 +08:00
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
2008-01-15 17:38:15 +08:00
|
|
|
return;
|
|
|
|
}
|
2008-01-23 03:55:31 +08:00
|
|
|
|
2014-03-15 14:44:50 +08:00
|
|
|
intern = Z_SPLDLLIST_P(getThis());
|
2014-02-16 22:15:54 +08:00
|
|
|
value = spl_ptr_llist_first(intern->llist);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2014-05-03 16:06:27 +08:00
|
|
|
if (value == NULL || Z_ISUNDEF_P(value)) {
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_throw_exception(spl_ce_RuntimeException, "Can't peek at an empty datastructure", 0);
|
2008-01-15 17:38:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-09 17:46:46 +08:00
|
|
|
ZVAL_COPY_DEREF(return_value, value);
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-02-16 22:15:54 +08:00
|
|
|
/* {{{ proto int SplDoublyLinkedList::count()
|
2008-01-15 17:38:15 +08:00
|
|
|
Return the number of elements in the datastructure. */
|
|
|
|
SPL_METHOD(SplDoublyLinkedList, count)
|
|
|
|
{
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_long count;
|
2014-03-15 14:44:50 +08:00
|
|
|
spl_dllist_object *intern = Z_SPLDLLIST_P(getThis());
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2013-10-12 00:32:40 +08:00
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
2008-01-15 17:38:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-07 07:45:56 +08:00
|
|
|
count = spl_ptr_llist_count(intern->llist);
|
2014-08-26 01:24:55 +08:00
|
|
|
RETURN_LONG(count);
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-02-16 22:15:54 +08:00
|
|
|
/* {{{ proto int SplDoublyLinkedList::isEmpty()
|
2008-01-23 03:55:31 +08:00
|
|
|
Return true if the SplDoublyLinkedList is empty. */
|
2008-01-15 17:38:15 +08:00
|
|
|
SPL_METHOD(SplDoublyLinkedList, isEmpty)
|
|
|
|
{
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_long count;
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2013-10-12 00:32:40 +08:00
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
2008-01-15 17:38:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
spl_dllist_object_count_elements(getThis(), &count);
|
2014-02-16 22:15:54 +08:00
|
|
|
RETURN_BOOL(count == 0);
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2015-06-24 05:46:07 +08:00
|
|
|
/* {{{ proto int SplDoublyLinkedList::setIteratorMode(int flags)
|
2008-01-15 17:38:15 +08:00
|
|
|
Set the mode of iteration */
|
|
|
|
SPL_METHOD(SplDoublyLinkedList, setIteratorMode)
|
|
|
|
{
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_long value;
|
2008-01-15 23:46:20 +08:00
|
|
|
spl_dllist_object *intern;
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &value) == FAILURE) {
|
2008-01-15 17:38:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-15 14:44:50 +08:00
|
|
|
intern = Z_SPLDLLIST_P(getThis());
|
2008-01-15 17:38:15 +08:00
|
|
|
|
|
|
|
if (intern->flags & SPL_DLLIST_IT_FIX
|
|
|
|
&& (intern->flags & SPL_DLLIST_IT_LIFO) != (value & SPL_DLLIST_IT_LIFO)) {
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_throw_exception(spl_ce_RuntimeException, "Iterators' LIFO/FIFO modes for SplStack/SplQueue objects are frozen", 0);
|
2008-01-15 17:38:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-24 17:19:05 +08:00
|
|
|
intern->flags = (value & SPL_DLLIST_IT_MASK) | (intern->flags & SPL_DLLIST_IT_FIX);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2014-08-26 01:24:55 +08:00
|
|
|
RETURN_LONG(intern->flags);
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-02-16 22:15:54 +08:00
|
|
|
/* {{{ proto int SplDoublyLinkedList::getIteratorMode()
|
2008-01-15 17:38:15 +08:00
|
|
|
Return the mode of iteration */
|
|
|
|
SPL_METHOD(SplDoublyLinkedList, getIteratorMode)
|
|
|
|
{
|
2008-01-15 23:46:20 +08:00
|
|
|
spl_dllist_object *intern;
|
|
|
|
|
2013-10-12 00:32:40 +08:00
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
2008-01-15 17:38:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-15 14:44:50 +08:00
|
|
|
intern = Z_SPLDLLIST_P(getThis());
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2014-08-26 01:24:55 +08:00
|
|
|
RETURN_LONG(intern->flags);
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2015-06-24 05:46:07 +08:00
|
|
|
/* {{{ proto bool SplDoublyLinkedList::offsetExists(mixed index)
|
2008-01-15 17:38:15 +08:00
|
|
|
Returns whether the requested $index exists. */
|
|
|
|
SPL_METHOD(SplDoublyLinkedList, offsetExists)
|
|
|
|
{
|
|
|
|
zval *zindex;
|
|
|
|
spl_dllist_object *intern;
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_long index;
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zindex) == FAILURE) {
|
2008-01-15 17:38:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-15 14:44:50 +08:00
|
|
|
intern = Z_SPLDLLIST_P(getThis());
|
2014-12-14 06:06:14 +08:00
|
|
|
index = spl_offset_convert_to_long(zindex);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
|
|
|
RETURN_BOOL(index >= 0 && index < intern->llist->count);
|
|
|
|
} /* }}} */
|
|
|
|
|
2015-06-24 05:46:07 +08:00
|
|
|
/* {{{ proto mixed SplDoublyLinkedList::offsetGet(mixed index)
|
2008-01-15 17:38:15 +08:00
|
|
|
Returns the value at the specified $index. */
|
|
|
|
SPL_METHOD(SplDoublyLinkedList, offsetGet)
|
|
|
|
{
|
2014-02-16 22:15:54 +08:00
|
|
|
zval *zindex;
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_long index;
|
2008-01-15 17:38:15 +08:00
|
|
|
spl_dllist_object *intern;
|
|
|
|
spl_ptr_llist_element *element;
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zindex) == FAILURE) {
|
2008-01-15 17:38:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-15 14:44:50 +08:00
|
|
|
intern = Z_SPLDLLIST_P(getThis());
|
2014-12-14 06:06:14 +08:00
|
|
|
index = spl_offset_convert_to_long(zindex);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2013-03-19 05:01:42 +08:00
|
|
|
if (index < 0 || index >= intern->llist->count) {
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0);
|
2008-01-15 17:38:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
element = spl_ptr_llist_offset(intern->llist, index, intern->flags & SPL_DLLIST_IT_LIFO);
|
|
|
|
|
|
|
|
if (element != NULL) {
|
2015-07-01 07:05:21 +08:00
|
|
|
zval *value = &element->data;
|
|
|
|
|
2018-07-09 17:46:46 +08:00
|
|
|
ZVAL_COPY_DEREF(return_value, value);
|
2008-01-15 17:38:15 +08:00
|
|
|
} else {
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0);
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
} /* }}} */
|
|
|
|
|
2015-06-24 05:46:07 +08:00
|
|
|
/* {{{ proto void SplDoublyLinkedList::offsetSet(mixed index, mixed newval)
|
2008-01-15 17:38:15 +08:00
|
|
|
Sets the value at the specified $index to $newval. */
|
|
|
|
SPL_METHOD(SplDoublyLinkedList, offsetSet)
|
|
|
|
{
|
|
|
|
zval *zindex, *value;
|
|
|
|
spl_dllist_object *intern;
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &zindex, &value) == FAILURE) {
|
2008-01-15 17:38:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-15 14:44:50 +08:00
|
|
|
intern = Z_SPLDLLIST_P(getThis());
|
2008-01-15 17:38:15 +08:00
|
|
|
|
|
|
|
if (Z_TYPE_P(zindex) == IS_NULL) {
|
|
|
|
/* $obj[] = ... */
|
2014-12-14 06:06:14 +08:00
|
|
|
spl_ptr_llist_push(intern->llist, value);
|
2008-01-15 17:38:15 +08:00
|
|
|
} else {
|
|
|
|
/* $obj[$foo] = ... */
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_long index;
|
2008-01-15 17:38:15 +08:00
|
|
|
spl_ptr_llist_element *element;
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
index = spl_offset_convert_to_long(zindex);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
|
|
|
if (index < 0 || index >= intern->llist->count) {
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0);
|
2008-01-15 17:38:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
element = spl_ptr_llist_offset(intern->llist, index, intern->flags & SPL_DLLIST_IT_LIFO);
|
|
|
|
|
|
|
|
if (element != NULL) {
|
2008-01-23 03:55:31 +08:00
|
|
|
/* call dtor on the old element as in spl_ptr_llist_pop */
|
2008-01-15 17:38:15 +08:00
|
|
|
if (intern->llist->dtor) {
|
2014-12-14 06:06:14 +08:00
|
|
|
intern->llist->dtor(element);
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
2008-01-23 03:55:31 +08:00
|
|
|
|
|
|
|
/* the element is replaced, delref the old one as in
|
|
|
|
* SplDoublyLinkedList::pop() */
|
2014-02-16 22:15:54 +08:00
|
|
|
zval_ptr_dtor(&element->data);
|
|
|
|
ZVAL_COPY_VALUE(&element->data, value);
|
2008-01-23 03:55:31 +08:00
|
|
|
|
|
|
|
/* new element, call ctor as in spl_ptr_llist_push */
|
|
|
|
if (intern->llist->ctor) {
|
2014-12-14 06:06:14 +08:00
|
|
|
intern->llist->ctor(element);
|
2008-01-23 03:55:31 +08:00
|
|
|
}
|
2008-01-15 17:38:15 +08:00
|
|
|
} else {
|
2014-02-16 22:15:54 +08:00
|
|
|
zval_ptr_dtor(value);
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0);
|
2008-01-15 17:38:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} /* }}} */
|
|
|
|
|
2015-06-24 05:46:07 +08:00
|
|
|
/* {{{ proto void SplDoublyLinkedList::offsetUnset(mixed index)
|
2008-01-15 17:38:15 +08:00
|
|
|
Unsets the value at the specified $index. */
|
|
|
|
SPL_METHOD(SplDoublyLinkedList, offsetUnset)
|
|
|
|
{
|
|
|
|
zval *zindex;
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_long index;
|
2008-01-15 17:38:15 +08:00
|
|
|
spl_dllist_object *intern;
|
|
|
|
spl_ptr_llist_element *element;
|
|
|
|
spl_ptr_llist *llist;
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zindex) == FAILURE) {
|
2008-01-15 17:38:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-15 14:44:50 +08:00
|
|
|
intern = Z_SPLDLLIST_P(getThis());
|
2014-12-14 06:06:14 +08:00
|
|
|
index = spl_offset_convert_to_long(zindex);
|
2013-03-19 05:01:42 +08:00
|
|
|
llist = intern->llist;
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2013-03-19 05:01:42 +08:00
|
|
|
if (index < 0 || index >= intern->llist->count) {
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_throw_exception(spl_ce_OutOfRangeException, "Offset out of range", 0);
|
2008-01-15 17:38:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
element = spl_ptr_llist_offset(intern->llist, index, intern->flags & SPL_DLLIST_IT_LIFO);
|
|
|
|
|
|
|
|
if (element != NULL) {
|
|
|
|
/* connect the neightbors */
|
|
|
|
if (element->prev) {
|
|
|
|
element->prev->next = element->next;
|
|
|
|
}
|
2008-01-23 03:55:31 +08:00
|
|
|
|
2008-01-15 17:38:15 +08:00
|
|
|
if (element->next) {
|
|
|
|
element->next->prev = element->prev;
|
|
|
|
}
|
2008-01-23 03:55:31 +08:00
|
|
|
|
2008-01-15 17:38:15 +08:00
|
|
|
/* take care of head/tail */
|
|
|
|
if (element == llist->head) {
|
|
|
|
llist->head = element->next;
|
|
|
|
}
|
2008-01-23 03:55:31 +08:00
|
|
|
|
2008-01-15 17:38:15 +08:00
|
|
|
if (element == llist->tail) {
|
|
|
|
llist->tail = element->prev;
|
|
|
|
}
|
2008-01-23 03:55:31 +08:00
|
|
|
|
2008-01-15 17:38:15 +08:00
|
|
|
/* finally, delete the element */
|
|
|
|
llist->count--;
|
2008-01-20 21:26:03 +08:00
|
|
|
|
|
|
|
if(llist->dtor) {
|
2014-12-14 06:06:14 +08:00
|
|
|
llist->dtor(element);
|
2008-01-20 21:26:03 +08:00
|
|
|
}
|
2008-01-23 03:55:31 +08:00
|
|
|
|
2014-07-02 17:45:09 +08:00
|
|
|
if (intern->traverse_pointer == element) {
|
|
|
|
SPL_LLIST_DELREF(element);
|
|
|
|
intern->traverse_pointer = NULL;
|
|
|
|
}
|
2014-02-16 22:15:54 +08:00
|
|
|
zval_ptr_dtor(&element->data);
|
|
|
|
ZVAL_UNDEF(&element->data);
|
2008-01-23 03:55:31 +08:00
|
|
|
|
2008-01-20 21:26:03 +08:00
|
|
|
SPL_LLIST_DELREF(element);
|
2008-01-15 17:38:15 +08:00
|
|
|
} else {
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0);
|
2008-01-15 17:38:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} /* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void spl_dllist_it_dtor(zend_object_iterator *iter) /* {{{ */
|
2008-01-15 17:38:15 +08:00
|
|
|
{
|
|
|
|
spl_dllist_it *iterator = (spl_dllist_it *)iter;
|
|
|
|
|
2008-01-20 21:26:03 +08:00
|
|
|
SPL_LLIST_CHECK_DELREF(iterator->traverse_pointer);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_user_it_invalidate_current(iter);
|
2014-02-27 19:19:02 +08:00
|
|
|
zval_ptr_dtor(&iterator->intern.it.data);
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void spl_dllist_it_helper_rewind(spl_ptr_llist_element **traverse_pointer_ptr, int *traverse_position_ptr, spl_ptr_llist *llist, int flags) /* {{{ */
|
2008-01-27 07:04:43 +08:00
|
|
|
{
|
|
|
|
SPL_LLIST_CHECK_DELREF(*traverse_pointer_ptr);
|
|
|
|
|
|
|
|
if (flags & SPL_DLLIST_IT_LIFO) {
|
|
|
|
*traverse_position_ptr = llist->count-1;
|
|
|
|
*traverse_pointer_ptr = llist->tail;
|
|
|
|
} else {
|
|
|
|
*traverse_position_ptr = 0;
|
|
|
|
*traverse_pointer_ptr = llist->head;
|
|
|
|
}
|
|
|
|
|
|
|
|
SPL_LLIST_CHECK_ADDREF(*traverse_pointer_ptr);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void spl_dllist_it_helper_move_forward(spl_ptr_llist_element **traverse_pointer_ptr, int *traverse_position_ptr, spl_ptr_llist *llist, int flags) /* {{{ */
|
2008-01-27 07:04:43 +08:00
|
|
|
{
|
|
|
|
if (*traverse_pointer_ptr) {
|
|
|
|
spl_ptr_llist_element *old = *traverse_pointer_ptr;
|
|
|
|
|
|
|
|
if (flags & SPL_DLLIST_IT_LIFO) {
|
|
|
|
*traverse_pointer_ptr = old->prev;
|
|
|
|
(*traverse_position_ptr)--;
|
|
|
|
|
|
|
|
if (flags & SPL_DLLIST_IT_DELETE) {
|
2014-02-16 22:15:54 +08:00
|
|
|
zval prev;
|
2014-12-14 06:06:14 +08:00
|
|
|
spl_ptr_llist_pop(llist, &prev);
|
2008-01-27 07:04:43 +08:00
|
|
|
|
2014-02-16 22:15:54 +08:00
|
|
|
zval_ptr_dtor(&prev);
|
2008-01-27 07:04:43 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*traverse_pointer_ptr = old->next;
|
|
|
|
|
|
|
|
if (flags & SPL_DLLIST_IT_DELETE) {
|
2014-02-16 22:15:54 +08:00
|
|
|
zval prev;
|
2014-12-14 06:06:14 +08:00
|
|
|
spl_ptr_llist_shift(llist, &prev);
|
2008-01-27 07:04:43 +08:00
|
|
|
|
2014-02-16 22:15:54 +08:00
|
|
|
zval_ptr_dtor(&prev);
|
2008-01-27 21:59:51 +08:00
|
|
|
} else {
|
|
|
|
(*traverse_position_ptr)++;
|
2008-01-27 07:04:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SPL_LLIST_DELREF(old);
|
|
|
|
SPL_LLIST_CHECK_ADDREF(*traverse_pointer_ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void spl_dllist_it_rewind(zend_object_iterator *iter) /* {{{ */
|
2008-01-27 07:04:43 +08:00
|
|
|
{
|
2014-02-27 19:19:02 +08:00
|
|
|
spl_dllist_it *iterator = (spl_dllist_it *)iter;
|
2014-03-15 14:44:50 +08:00
|
|
|
spl_dllist_object *object = Z_SPLDLLIST_P(&iter->data);
|
2014-02-27 19:19:02 +08:00
|
|
|
spl_ptr_llist *llist = object->llist;
|
2008-01-27 07:04:43 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
spl_dllist_it_helper_rewind(&iterator->traverse_pointer, &iterator->traverse_position, llist, object->flags);
|
2008-01-27 07:04:43 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static int spl_dllist_it_valid(zend_object_iterator *iter) /* {{{ */
|
2008-01-15 17:38:15 +08:00
|
|
|
{
|
|
|
|
spl_dllist_it *iterator = (spl_dllist_it *)iter;
|
|
|
|
spl_ptr_llist_element *element = iterator->traverse_pointer;
|
|
|
|
|
|
|
|
return (element != NULL ? SUCCESS : FAILURE);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static zval *spl_dllist_it_get_current_data(zend_object_iterator *iter) /* {{{ */
|
2008-01-15 17:38:15 +08:00
|
|
|
{
|
|
|
|
spl_dllist_it *iterator = (spl_dllist_it *)iter;
|
|
|
|
spl_ptr_llist_element *element = iterator->traverse_pointer;
|
|
|
|
|
2014-05-03 16:06:27 +08:00
|
|
|
if (element == NULL || Z_ISUNDEF(element->data)) {
|
2014-02-16 22:15:54 +08:00
|
|
|
return NULL;
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
2014-02-16 22:15:54 +08:00
|
|
|
|
|
|
|
return &element->data;
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void spl_dllist_it_get_current_key(zend_object_iterator *iter, zval *key) /* {{{ */
|
2008-01-15 17:38:15 +08:00
|
|
|
{
|
|
|
|
spl_dllist_it *iterator = (spl_dllist_it *)iter;
|
|
|
|
|
2014-08-26 01:24:55 +08:00
|
|
|
ZVAL_LONG(key, iterator->traverse_position);
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void spl_dllist_it_move_forward(zend_object_iterator *iter) /* {{{ */
|
2008-01-15 17:38:15 +08:00
|
|
|
{
|
2014-02-27 19:19:02 +08:00
|
|
|
spl_dllist_it *iterator = (spl_dllist_it *)iter;
|
2014-03-15 14:44:50 +08:00
|
|
|
spl_dllist_object *object = Z_SPLDLLIST_P(&iter->data);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_user_it_invalidate_current(iter);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
spl_dllist_it_helper_move_forward(&iterator->traverse_pointer, &iterator->traverse_position, object->llist, object->flags);
|
2008-01-27 07:04:43 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2014-02-16 22:15:54 +08:00
|
|
|
/* {{{ proto int SplDoublyLinkedList::key()
|
2008-01-27 07:04:43 +08:00
|
|
|
Return current array key */
|
|
|
|
SPL_METHOD(SplDoublyLinkedList, key)
|
|
|
|
{
|
2014-03-15 14:44:50 +08:00
|
|
|
spl_dllist_object *intern = Z_SPLDLLIST_P(getThis());
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2010-11-15 02:40:08 +08:00
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2008-01-23 03:55:31 +08:00
|
|
|
|
2014-08-26 01:24:55 +08:00
|
|
|
RETURN_LONG(intern->traverse_position);
|
2008-01-27 07:04:43 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
2008-01-23 03:55:31 +08:00
|
|
|
|
2014-02-16 22:15:54 +08:00
|
|
|
/* {{{ proto void SplDoublyLinkedList::prev()
|
2009-06-17 21:27:09 +08:00
|
|
|
Move to next entry */
|
|
|
|
SPL_METHOD(SplDoublyLinkedList, prev)
|
|
|
|
{
|
2014-03-15 14:44:50 +08:00
|
|
|
spl_dllist_object *intern = Z_SPLDLLIST_P(getThis());
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2010-11-15 02:40:08 +08:00
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2009-06-17 21:27:09 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
spl_dllist_it_helper_move_forward(&intern->traverse_pointer, &intern->traverse_position, intern->llist, intern->flags ^ SPL_DLLIST_IT_LIFO);
|
2009-06-17 21:27:09 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-02-16 22:15:54 +08:00
|
|
|
/* {{{ proto void SplDoublyLinkedList::next()
|
2008-01-27 07:04:43 +08:00
|
|
|
Move to next entry */
|
|
|
|
SPL_METHOD(SplDoublyLinkedList, next)
|
|
|
|
{
|
2014-03-15 14:44:50 +08:00
|
|
|
spl_dllist_object *intern = Z_SPLDLLIST_P(getThis());
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2010-11-15 02:40:08 +08:00
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2008-01-23 03:55:31 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
spl_dllist_it_helper_move_forward(&intern->traverse_pointer, &intern->traverse_position, intern->llist, intern->flags);
|
2008-01-27 07:04:43 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
2008-01-23 03:55:31 +08:00
|
|
|
|
2014-02-16 22:15:54 +08:00
|
|
|
/* {{{ proto bool SplDoublyLinkedList::valid()
|
2008-01-27 07:04:43 +08:00
|
|
|
Check whether the datastructure contains more entries */
|
|
|
|
SPL_METHOD(SplDoublyLinkedList, valid)
|
|
|
|
{
|
2014-03-15 14:44:50 +08:00
|
|
|
spl_dllist_object *intern = Z_SPLDLLIST_P(getThis());
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2010-11-15 02:40:08 +08:00
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2008-01-27 07:04:43 +08:00
|
|
|
RETURN_BOOL(intern->traverse_pointer != NULL);
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-02-16 22:15:54 +08:00
|
|
|
/* {{{ proto void SplDoublyLinkedList::rewind()
|
2008-01-27 07:04:43 +08:00
|
|
|
Rewind the datastructure back to the start */
|
|
|
|
SPL_METHOD(SplDoublyLinkedList, rewind)
|
2008-01-15 17:38:15 +08:00
|
|
|
{
|
2014-03-15 14:44:50 +08:00
|
|
|
spl_dllist_object *intern = Z_SPLDLLIST_P(getThis());
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2010-11-15 02:40:08 +08:00
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
spl_dllist_it_helper_rewind(&intern->traverse_pointer, &intern->traverse_position, intern->llist, intern->flags);
|
2008-01-27 07:04:43 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
2008-01-23 03:55:31 +08:00
|
|
|
|
2014-02-16 22:15:54 +08:00
|
|
|
/* {{{ proto mixed|NULL SplDoublyLinkedList::current()
|
2008-01-27 07:04:43 +08:00
|
|
|
Return current datastructure entry */
|
|
|
|
SPL_METHOD(SplDoublyLinkedList, current)
|
|
|
|
{
|
2014-03-15 14:44:50 +08:00
|
|
|
spl_dllist_object *intern = Z_SPLDLLIST_P(getThis());
|
2008-01-27 07:04:43 +08:00
|
|
|
spl_ptr_llist_element *element = intern->traverse_pointer;
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2010-11-15 02:40:08 +08:00
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2008-01-27 07:04:43 +08:00
|
|
|
|
2014-05-03 16:06:27 +08:00
|
|
|
if (element == NULL || Z_ISUNDEF(element->data)) {
|
2008-01-27 07:04:43 +08:00
|
|
|
RETURN_NULL();
|
2008-01-15 17:38:15 +08:00
|
|
|
} else {
|
2015-07-01 07:05:21 +08:00
|
|
|
zval *value = &element->data;
|
|
|
|
|
2018-07-09 17:46:46 +08:00
|
|
|
ZVAL_COPY_DEREF(return_value, value);
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
2014-02-16 22:15:54 +08:00
|
|
|
|
2011-07-13 05:43:17 +08:00
|
|
|
/* {{{ proto string SplDoublyLinkedList::serialize()
|
|
|
|
Serializes storage */
|
|
|
|
SPL_METHOD(SplDoublyLinkedList, serialize)
|
|
|
|
{
|
2014-03-15 14:44:50 +08:00
|
|
|
spl_dllist_object *intern = Z_SPLDLLIST_P(getThis());
|
2011-07-13 05:43:17 +08:00
|
|
|
smart_str buf = {0};
|
|
|
|
spl_ptr_llist_element *current = intern->llist->head, *next;
|
2014-02-16 22:15:54 +08:00
|
|
|
zval flags;
|
2011-07-13 05:43:17 +08:00
|
|
|
php_serialize_data_t var_hash;
|
|
|
|
|
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PHP_VAR_SERIALIZE_INIT(var_hash);
|
|
|
|
|
|
|
|
/* flags */
|
2014-08-26 01:24:55 +08:00
|
|
|
ZVAL_LONG(&flags, intern->flags);
|
2014-12-14 06:06:14 +08:00
|
|
|
php_var_serialize(&buf, &flags, &var_hash);
|
2011-07-13 05:43:17 +08:00
|
|
|
|
|
|
|
/* elements */
|
|
|
|
while (current) {
|
|
|
|
smart_str_appendc(&buf, ':');
|
|
|
|
next = current->next;
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
php_var_serialize(&buf, ¤t->data, &var_hash);
|
2011-07-13 05:43:17 +08:00
|
|
|
|
|
|
|
current = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
smart_str_0(&buf);
|
|
|
|
|
|
|
|
/* done */
|
|
|
|
PHP_VAR_SERIALIZE_DESTROY(var_hash);
|
|
|
|
|
2014-02-18 17:42:46 +08:00
|
|
|
if (buf.s) {
|
2015-03-12 21:53:51 +08:00
|
|
|
RETURN_NEW_STR(buf.s);
|
2011-07-13 05:43:17 +08:00
|
|
|
} else {
|
|
|
|
RETURN_NULL();
|
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2011-07-13 05:43:17 +08:00
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto void SplDoublyLinkedList::unserialize(string serialized)
|
|
|
|
Unserializes storage */
|
|
|
|
SPL_METHOD(SplDoublyLinkedList, unserialize)
|
|
|
|
{
|
2014-03-15 14:44:50 +08:00
|
|
|
spl_dllist_object *intern = Z_SPLDLLIST_P(getThis());
|
2015-08-05 14:41:00 +08:00
|
|
|
zval *flags, *elem;
|
2011-07-13 05:43:17 +08:00
|
|
|
char *buf;
|
2014-08-27 21:31:48 +08:00
|
|
|
size_t buf_len;
|
2011-07-13 05:43:17 +08:00
|
|
|
const unsigned char *p, *s;
|
|
|
|
php_unserialize_data_t var_hash;
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &buf, &buf_len) == FAILURE) {
|
2011-07-13 05:43:17 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buf_len == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
s = p = (const unsigned char*)buf;
|
|
|
|
PHP_VAR_UNSERIALIZE_INIT(var_hash);
|
|
|
|
|
|
|
|
/* flags */
|
2015-08-05 14:41:00 +08:00
|
|
|
flags = var_tmp_var(&var_hash);
|
|
|
|
if (!php_var_unserialize(flags, &p, s + buf_len, &var_hash) || Z_TYPE_P(flags) != IS_LONG) {
|
2014-02-16 22:15:54 +08:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2015-08-05 14:41:00 +08:00
|
|
|
intern->flags = (int)Z_LVAL_P(flags);
|
2011-07-13 05:43:17 +08:00
|
|
|
|
|
|
|
/* elements */
|
|
|
|
while(*p == ':') {
|
|
|
|
++p;
|
2015-08-05 14:41:00 +08:00
|
|
|
elem = var_tmp_var(&var_hash);
|
|
|
|
if (!php_var_unserialize(elem, &p, s + buf_len, &var_hash)) {
|
2011-07-13 05:43:17 +08:00
|
|
|
goto error;
|
|
|
|
}
|
2015-09-02 03:40:10 +08:00
|
|
|
var_push_dtor(&var_hash, elem);
|
2011-07-13 05:43:17 +08:00
|
|
|
|
2015-08-05 14:41:00 +08:00
|
|
|
spl_ptr_llist_push(intern->llist, elem);
|
2011-07-13 05:43:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*p != '\0') {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
|
2016-06-21 21:00:37 +08:00
|
|
|
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Error at offset %zd of %zd bytes", ((char*)p - buf), buf_len);
|
2011-07-13 05:43:17 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
} /* }}} */
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2015-06-24 05:46:07 +08:00
|
|
|
/* {{{ proto void SplDoublyLinkedList::add(mixed index, mixed newval)
|
2013-03-19 05:01:42 +08:00
|
|
|
Inserts a new entry before the specified $index consisting of $newval. */
|
|
|
|
SPL_METHOD(SplDoublyLinkedList, add)
|
|
|
|
{
|
|
|
|
zval *zindex, *value;
|
|
|
|
spl_dllist_object *intern;
|
|
|
|
spl_ptr_llist_element *element;
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_long index;
|
2013-03-19 05:01:42 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &zindex, &value) == FAILURE) {
|
2013-03-19 05:01:42 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-15 14:44:50 +08:00
|
|
|
intern = Z_SPLDLLIST_P(getThis());
|
2014-12-14 06:06:14 +08:00
|
|
|
index = spl_offset_convert_to_long(zindex);
|
2013-03-19 05:01:42 +08:00
|
|
|
|
|
|
|
if (index < 0 || index > intern->llist->count) {
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0);
|
2013-03-19 05:01:42 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-02 12:13:35 +08:00
|
|
|
Z_TRY_ADDREF_P(value);
|
2013-03-19 05:01:42 +08:00
|
|
|
if (index == intern->llist->count) {
|
|
|
|
/* If index is the last entry+1 then we do a push because we're not inserting before any entry */
|
2014-12-14 06:06:14 +08:00
|
|
|
spl_ptr_llist_push(intern->llist, value);
|
2013-03-19 05:01:42 +08:00
|
|
|
} else {
|
|
|
|
/* Create the new element we want to insert */
|
|
|
|
spl_ptr_llist_element *elem = emalloc(sizeof(spl_ptr_llist_element));
|
|
|
|
|
2013-03-19 22:13:27 +08:00
|
|
|
/* Get the element we want to insert before */
|
|
|
|
element = spl_ptr_llist_offset(intern->llist, index, intern->flags & SPL_DLLIST_IT_LIFO);
|
|
|
|
|
2014-02-16 22:15:54 +08:00
|
|
|
ZVAL_COPY_VALUE(&elem->data, value);
|
2013-03-19 05:01:42 +08:00
|
|
|
elem->rc = 1;
|
|
|
|
/* connect to the neighbours */
|
|
|
|
elem->next = element;
|
|
|
|
elem->prev = element->prev;
|
|
|
|
|
|
|
|
/* connect the neighbours to this new element */
|
|
|
|
if (elem->prev == NULL) {
|
|
|
|
intern->llist->head = elem;
|
|
|
|
} else {
|
|
|
|
element->prev->next = elem;
|
|
|
|
}
|
|
|
|
element->prev = elem;
|
|
|
|
|
|
|
|
intern->llist->count++;
|
|
|
|
|
|
|
|
if (intern->llist->ctor) {
|
2014-12-14 06:06:14 +08:00
|
|
|
intern->llist->ctor(elem);
|
2013-03-19 05:01:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} /* }}} */
|
|
|
|
|
2014-02-16 22:15:54 +08:00
|
|
|
/* {{{ iterator handler table */
|
2017-12-14 19:21:22 +08:00
|
|
|
static const zend_object_iterator_funcs spl_dllist_it_funcs = {
|
2008-01-15 17:38:15 +08:00
|
|
|
spl_dllist_it_dtor,
|
|
|
|
spl_dllist_it_valid,
|
|
|
|
spl_dllist_it_get_current_data,
|
|
|
|
spl_dllist_it_get_current_key,
|
|
|
|
spl_dllist_it_move_forward,
|
2016-06-22 05:40:50 +08:00
|
|
|
spl_dllist_it_rewind,
|
|
|
|
NULL
|
2014-02-16 22:15:54 +08:00
|
|
|
}; /* }}} */
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_object_iterator *spl_dllist_get_iterator(zend_class_entry *ce, zval *object, int by_ref) /* {{{ */
|
2008-01-15 17:38:15 +08:00
|
|
|
{
|
2014-02-27 19:19:02 +08:00
|
|
|
spl_dllist_it *iterator;
|
2014-03-15 14:44:50 +08:00
|
|
|
spl_dllist_object *dllist_object = Z_SPLDLLIST_P(object);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
|
|
|
if (by_ref) {
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0);
|
2008-01-15 17:38:15 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-02-27 19:19:02 +08:00
|
|
|
iterator = emalloc(sizeof(spl_dllist_it));
|
2014-02-26 19:01:08 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_iterator_init((zend_object_iterator*)iterator);
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2014-02-27 19:19:02 +08:00
|
|
|
ZVAL_COPY(&iterator->intern.it.data, object);
|
2008-02-11 21:59:23 +08:00
|
|
|
iterator->intern.it.funcs = &spl_dllist_it_funcs;
|
|
|
|
iterator->intern.ce = ce;
|
2008-01-15 17:38:15 +08:00
|
|
|
iterator->traverse_position = dllist_object->traverse_position;
|
|
|
|
iterator->traverse_pointer = dllist_object->traverse_pointer;
|
|
|
|
iterator->flags = dllist_object->flags & SPL_DLLIST_IT_MASK;
|
2014-02-27 19:19:02 +08:00
|
|
|
ZVAL_UNDEF(&iterator->intern.value);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
|
|
|
SPL_LLIST_CHECK_ADDREF(iterator->traverse_pointer);
|
|
|
|
|
2014-02-27 19:19:02 +08:00
|
|
|
return &iterator->intern.it;
|
2008-01-15 17:38:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* Function/Class/Method definitions */
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_dllist_setiteratormode, 0)
|
|
|
|
ZEND_ARG_INFO(0, flags)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_dllist_push, 0)
|
|
|
|
ZEND_ARG_INFO(0, value)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_dllist_offsetGet, 0, 0, 1)
|
|
|
|
ZEND_ARG_INFO(0, index)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_dllist_offsetSet, 0, 0, 2)
|
|
|
|
ZEND_ARG_INFO(0, index)
|
|
|
|
ZEND_ARG_INFO(0, newval)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
2009-07-05 04:31:27 +08:00
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_dllist_void, 0)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
2011-07-13 05:43:17 +08:00
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_dllist_serialized, 0)
|
|
|
|
ZEND_ARG_INFO(0, serialized)
|
|
|
|
ZEND_END_ARG_INFO();
|
|
|
|
|
2008-01-15 17:38:15 +08:00
|
|
|
static const zend_function_entry spl_funcs_SplQueue[] = {
|
|
|
|
SPL_MA(SplQueue, enqueue, SplDoublyLinkedList, push, arginfo_dllist_push, ZEND_ACC_PUBLIC)
|
2009-07-05 04:31:27 +08:00
|
|
|
SPL_MA(SplQueue, dequeue, SplDoublyLinkedList, shift, arginfo_dllist_void, ZEND_ACC_PUBLIC)
|
2011-07-25 19:35:02 +08:00
|
|
|
PHP_FE_END
|
2008-01-15 17:38:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static const zend_function_entry spl_funcs_SplDoublyLinkedList[] = {
|
2009-07-05 04:31:27 +08:00
|
|
|
SPL_ME(SplDoublyLinkedList, pop, arginfo_dllist_void, ZEND_ACC_PUBLIC)
|
|
|
|
SPL_ME(SplDoublyLinkedList, shift, arginfo_dllist_void, ZEND_ACC_PUBLIC)
|
2008-01-15 17:38:15 +08:00
|
|
|
SPL_ME(SplDoublyLinkedList, push, arginfo_dllist_push, ZEND_ACC_PUBLIC)
|
|
|
|
SPL_ME(SplDoublyLinkedList, unshift, arginfo_dllist_push, ZEND_ACC_PUBLIC)
|
2009-07-05 04:31:27 +08:00
|
|
|
SPL_ME(SplDoublyLinkedList, top, arginfo_dllist_void, ZEND_ACC_PUBLIC)
|
|
|
|
SPL_ME(SplDoublyLinkedList, bottom, arginfo_dllist_void, ZEND_ACC_PUBLIC)
|
|
|
|
SPL_ME(SplDoublyLinkedList, isEmpty, arginfo_dllist_void, ZEND_ACC_PUBLIC)
|
2008-01-15 17:38:15 +08:00
|
|
|
SPL_ME(SplDoublyLinkedList, setIteratorMode, arginfo_dllist_setiteratormode, ZEND_ACC_PUBLIC)
|
2009-07-05 04:31:27 +08:00
|
|
|
SPL_ME(SplDoublyLinkedList, getIteratorMode, arginfo_dllist_void, ZEND_ACC_PUBLIC)
|
2011-07-13 05:43:17 +08:00
|
|
|
/* Countable */
|
|
|
|
SPL_ME(SplDoublyLinkedList, count, arginfo_dllist_void, ZEND_ACC_PUBLIC)
|
|
|
|
/* ArrayAccess */
|
2008-01-15 17:38:15 +08:00
|
|
|
SPL_ME(SplDoublyLinkedList, offsetExists, arginfo_dllist_offsetGet, ZEND_ACC_PUBLIC)
|
|
|
|
SPL_ME(SplDoublyLinkedList, offsetGet, arginfo_dllist_offsetGet, ZEND_ACC_PUBLIC)
|
|
|
|
SPL_ME(SplDoublyLinkedList, offsetSet, arginfo_dllist_offsetSet, ZEND_ACC_PUBLIC)
|
|
|
|
SPL_ME(SplDoublyLinkedList, offsetUnset, arginfo_dllist_offsetGet, ZEND_ACC_PUBLIC)
|
2013-03-19 05:01:42 +08:00
|
|
|
|
|
|
|
SPL_ME(SplDoublyLinkedList, add, arginfo_dllist_offsetSet, ZEND_ACC_PUBLIC)
|
|
|
|
|
2011-07-13 05:43:17 +08:00
|
|
|
/* Iterator */
|
2009-07-05 04:31:27 +08:00
|
|
|
SPL_ME(SplDoublyLinkedList, rewind, arginfo_dllist_void, ZEND_ACC_PUBLIC)
|
|
|
|
SPL_ME(SplDoublyLinkedList, current, arginfo_dllist_void, ZEND_ACC_PUBLIC)
|
|
|
|
SPL_ME(SplDoublyLinkedList, key, arginfo_dllist_void, ZEND_ACC_PUBLIC)
|
|
|
|
SPL_ME(SplDoublyLinkedList, next, arginfo_dllist_void, ZEND_ACC_PUBLIC)
|
|
|
|
SPL_ME(SplDoublyLinkedList, prev, arginfo_dllist_void, ZEND_ACC_PUBLIC)
|
|
|
|
SPL_ME(SplDoublyLinkedList, valid, arginfo_dllist_void, ZEND_ACC_PUBLIC)
|
2011-07-13 05:43:17 +08:00
|
|
|
/* Serializable */
|
|
|
|
SPL_ME(SplDoublyLinkedList, unserialize, arginfo_dllist_serialized, ZEND_ACC_PUBLIC)
|
|
|
|
SPL_ME(SplDoublyLinkedList, serialize, arginfo_dllist_void, ZEND_ACC_PUBLIC)
|
2011-07-25 19:35:02 +08:00
|
|
|
PHP_FE_END
|
2008-01-15 17:38:15 +08:00
|
|
|
};
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
PHP_MINIT_FUNCTION(spl_dllist) /* {{{ */
|
|
|
|
{
|
|
|
|
REGISTER_SPL_STD_CLASS_EX(SplDoublyLinkedList, spl_dllist_object_new, spl_funcs_SplDoublyLinkedList);
|
2018-05-31 16:57:22 +08:00
|
|
|
memcpy(&spl_handler_SplDoublyLinkedList, &std_object_handlers, sizeof(zend_object_handlers));
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2014-04-09 05:50:15 +08:00
|
|
|
spl_handler_SplDoublyLinkedList.offset = XtOffsetOf(spl_dllist_object, std);
|
2014-02-16 22:15:54 +08:00
|
|
|
spl_handler_SplDoublyLinkedList.clone_obj = spl_dllist_object_clone;
|
2008-01-15 17:38:15 +08:00
|
|
|
spl_handler_SplDoublyLinkedList.count_elements = spl_dllist_object_count_elements;
|
2008-02-19 08:04:20 +08:00
|
|
|
spl_handler_SplDoublyLinkedList.get_debug_info = spl_dllist_object_get_debug_info;
|
2015-04-16 21:13:15 +08:00
|
|
|
spl_handler_SplDoublyLinkedList.get_gc = spl_dllist_object_get_gc;
|
2014-02-16 22:15:54 +08:00
|
|
|
spl_handler_SplDoublyLinkedList.dtor_obj = zend_objects_destroy_object;
|
|
|
|
spl_handler_SplDoublyLinkedList.free_obj = spl_dllist_object_free_storage;
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2014-08-26 01:24:55 +08:00
|
|
|
REGISTER_SPL_CLASS_CONST_LONG(SplDoublyLinkedList, "IT_MODE_LIFO", SPL_DLLIST_IT_LIFO);
|
|
|
|
REGISTER_SPL_CLASS_CONST_LONG(SplDoublyLinkedList, "IT_MODE_FIFO", 0);
|
|
|
|
REGISTER_SPL_CLASS_CONST_LONG(SplDoublyLinkedList, "IT_MODE_DELETE",SPL_DLLIST_IT_DELETE);
|
|
|
|
REGISTER_SPL_CLASS_CONST_LONG(SplDoublyLinkedList, "IT_MODE_KEEP", 0);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
2008-01-27 07:04:43 +08:00
|
|
|
REGISTER_SPL_IMPLEMENTS(SplDoublyLinkedList, Iterator);
|
2008-01-15 17:38:15 +08:00
|
|
|
REGISTER_SPL_IMPLEMENTS(SplDoublyLinkedList, Countable);
|
|
|
|
REGISTER_SPL_IMPLEMENTS(SplDoublyLinkedList, ArrayAccess);
|
2011-07-13 05:43:17 +08:00
|
|
|
REGISTER_SPL_IMPLEMENTS(SplDoublyLinkedList, Serializable);
|
2008-01-15 17:38:15 +08:00
|
|
|
|
|
|
|
spl_ce_SplDoublyLinkedList->get_iterator = spl_dllist_get_iterator;
|
|
|
|
|
|
|
|
REGISTER_SPL_SUB_CLASS_EX(SplQueue, SplDoublyLinkedList, spl_dllist_object_new, spl_funcs_SplQueue);
|
|
|
|
REGISTER_SPL_SUB_CLASS_EX(SplStack, SplDoublyLinkedList, spl_dllist_object_new, NULL);
|
|
|
|
|
2008-06-07 07:53:43 +08:00
|
|
|
spl_ce_SplQueue->get_iterator = spl_dllist_get_iterator;
|
|
|
|
spl_ce_SplStack->get_iterator = spl_dllist_get_iterator;
|
|
|
|
|
2008-01-15 17:38:15 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
/* }}} */
|
2014-02-16 22:15:54 +08:00
|
|
|
|
2008-01-15 17:38:15 +08:00
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
|
|
|
* vim600: fdm=marker
|
|
|
|
* vim: noet sw=4 ts=4
|
|
|
|
*/
|