php-src/ext/spl/spl_fixedarray.c

1113 lines
30 KiB
C
Raw Normal View History

2008-06-06 23:53:43 +00:00
/*
+----------------------------------------------------------------------+
2014-09-19 16:33:14 +00:00
| PHP Version 7 |
2008-06-06 23:53:43 +00:00
+----------------------------------------------------------------------+
2017-01-04 17:23:42 +00:00
| Copyright (c) 1997-2017 The PHP Group |
2008-06-06 23:53:43 +00: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. |
+----------------------------------------------------------------------+
| Author: Antony Dovgal <tony@daylessday.org> |
| Etienne Kneuss <colder@php.net> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "zend_exceptions.h"
#include "php_spl.h"
#include "spl_functions.h"
#include "spl_engine.h"
#include "spl_fixedarray.h"
2008-06-06 23:53:43 +00:00
#include "spl_exceptions.h"
#include "spl_iterators.h"
zend_object_handlers spl_handler_SplFixedArray;
PHPAPI zend_class_entry *spl_ce_SplFixedArray;
2008-06-06 23:53:43 +00:00
#ifdef COMPILE_DL_SPL_FIXEDARRAY
ZEND_GET_MODULE(spl_fixedarray)
2008-06-06 23:53:43 +00:00
#endif
typedef struct _spl_fixedarray { /* {{{ */
2014-08-25 17:24:55 +00:00
zend_long size;
zval *elements;
} spl_fixedarray;
2008-06-06 23:53:43 +00:00
/* }}} */
typedef struct _spl_fixedarray_object { /* {{{ */
2016-08-04 15:35:14 +00:00
spl_fixedarray array;
2008-06-06 23:53:43 +00:00
zend_function *fptr_offset_get;
zend_function *fptr_offset_set;
zend_function *fptr_offset_has;
zend_function *fptr_offset_del;
zend_function *fptr_count;
2008-06-06 23:53:43 +00:00
int current;
int flags;
2008-06-06 23:53:43 +00:00
zend_class_entry *ce_get_iterator;
zend_object std;
} spl_fixedarray_object;
2008-06-06 23:53:43 +00:00
/* }}} */
typedef struct _spl_fixedarray_it { /* {{{ */
2008-06-06 23:53:43 +00:00
zend_user_iterator intern;
} spl_fixedarray_it;
2008-06-06 23:53:43 +00:00
/* }}} */
#define SPL_FIXEDARRAY_OVERLOADED_REWIND 0x0001
#define SPL_FIXEDARRAY_OVERLOADED_VALID 0x0002
#define SPL_FIXEDARRAY_OVERLOADED_KEY 0x0004
#define SPL_FIXEDARRAY_OVERLOADED_CURRENT 0x0008
#define SPL_FIXEDARRAY_OVERLOADED_NEXT 0x0010
static inline spl_fixedarray_object *spl_fixed_array_from_obj(zend_object *obj) /* {{{ */ {
return (spl_fixedarray_object*)((char*)(obj) - XtOffsetOf(spl_fixedarray_object, std));
}
/* }}} */
#define Z_SPLFIXEDARRAY_P(zv) spl_fixed_array_from_obj(Z_OBJ_P((zv)))
2014-12-13 22:06:14 +00:00
static void spl_fixedarray_init(spl_fixedarray *array, zend_long size) /* {{{ */
2008-06-06 23:53:43 +00:00
{
if (size > 0) {
2008-06-12 12:40:13 +00:00
array->size = 0; /* reset size in case ecalloc() fails */
array->elements = ecalloc(size, sizeof(zval));
2008-06-06 23:53:43 +00:00
array->size = size;
} else {
array->elements = NULL;
array->size = 0;
}
}
/* }}} */
2014-12-13 22:06:14 +00:00
static void spl_fixedarray_resize(spl_fixedarray *array, zend_long size) /* {{{ */
2008-06-06 23:53:43 +00:00
{
if (size == array->size) {
/* nothing to do */
return;
}
/* first initialization */
if (array->size == 0) {
2014-12-13 22:06:14 +00:00
spl_fixedarray_init(array, size);
2008-06-06 23:53:43 +00:00
return;
}
/* clearing the array */
if (size == 0) {
2014-08-25 17:24:55 +00:00
zend_long i;
2008-06-06 23:53:43 +00:00
for (i = 0; i < array->size; i++) {
zval_ptr_dtor(&(array->elements[i]));
2008-06-06 23:53:43 +00:00
}
if (array->elements) {
efree(array->elements);
2008-06-07 14:09:06 +00:00
array->elements = NULL;
2008-06-06 23:53:43 +00:00
}
} else if (size > array->size) {
array->elements = safe_erealloc(array->elements, size, sizeof(zval), 0);
memset(array->elements + array->size, '\0', sizeof(zval) * (size - array->size));
2008-06-06 23:53:43 +00:00
} else { /* size < array->size */
2014-08-25 17:24:55 +00:00
zend_long i;
2008-06-06 23:53:43 +00:00
for (i = size; i < array->size; i++) {
zval_ptr_dtor(&(array->elements[i]));
2008-06-06 23:53:43 +00:00
}
array->elements = erealloc(array->elements, sizeof(zval) * size);
2008-06-06 23:53:43 +00:00
}
array->size = size;
}
/* }}} */
2014-12-13 22:06:14 +00:00
static void spl_fixedarray_copy(spl_fixedarray *to, spl_fixedarray *from) /* {{{ */
2008-06-06 23:53:43 +00:00
{
int i;
for (i = 0; i < from->size; i++) {
ZVAL_COPY(&to->elements[i], &from->elements[i]);
2008-06-06 23:53:43 +00:00
}
}
/* }}} */
2014-12-13 22:06:14 +00:00
static HashTable* spl_fixedarray_object_get_gc(zval *obj, zval **table, int *n) /* {{{{ */
{
2014-03-15 05:12:55 +00:00
spl_fixedarray_object *intern = Z_SPLFIXEDARRAY_P(obj);
2014-12-13 22:06:14 +00:00
HashTable *ht = zend_std_get_properties(obj);
2016-08-04 15:35:14 +00:00
*table = intern->array.elements;
*n = (int)intern->array.size;
return ht;
}
/* }}}} */
2014-12-13 22:06:14 +00:00
static HashTable* spl_fixedarray_object_get_properties(zval *obj) /* {{{{ */
2008-06-09 17:29:23 +00:00
{
2014-03-15 05:12:55 +00:00
spl_fixedarray_object *intern = Z_SPLFIXEDARRAY_P(obj);
2014-12-13 22:06:14 +00:00
HashTable *ht = zend_std_get_properties(obj);
2014-10-28 19:12:20 +00:00
zend_long i = 0;
2008-06-09 17:29:23 +00:00
2016-08-04 15:35:14 +00:00
if (intern->array.size > 0) {
2014-10-28 19:12:20 +00:00
zend_long j = zend_hash_num_elements(ht);
2016-08-04 15:35:14 +00:00
for (i = 0; i < intern->array.size; i++) {
if (!Z_ISUNDEF(intern->array.elements[i])) {
zend_hash_index_update(ht, i, &intern->array.elements[i]);
2017-11-02 04:13:35 +00:00
Z_TRY_ADDREF(intern->array.elements[i]);
2008-06-09 17:29:23 +00:00
} else {
zend_hash_index_update(ht, i, &EG(uninitialized_zval));
2008-06-09 17:29:23 +00:00
}
}
2016-08-04 15:35:14 +00:00
if (j > intern->array.size) {
for (i = intern->array.size; i < j; ++i) {
zend_hash_index_del(ht, i);
}
}
2008-06-09 17:29:23 +00:00
}
return ht;
2008-06-09 17:29:23 +00:00
}
/* }}}} */
2014-12-13 22:06:14 +00:00
static void spl_fixedarray_object_free_storage(zend_object *object) /* {{{ */
2008-06-06 23:53:43 +00:00
{
spl_fixedarray_object *intern = spl_fixed_array_from_obj(object);
2014-08-25 17:24:55 +00:00
zend_long i;
2008-06-06 23:53:43 +00:00
2016-08-04 15:35:14 +00:00
if (intern->array.size > 0) {
for (i = 0; i < intern->array.size; i++) {
zval_ptr_dtor(&(intern->array.elements[i]));
2008-06-06 23:53:43 +00:00
}
2016-08-04 15:35:14 +00:00
if (intern->array.size > 0 && intern->array.elements) {
efree(intern->array.elements);
2008-06-07 14:09:06 +00:00
}
2008-06-06 23:53:43 +00:00
}
2014-12-13 22:06:14 +00:00
zend_object_std_dtor(&intern->std);
2008-06-06 23:53:43 +00:00
}
/* }}} */
2014-12-13 22:06:14 +00:00
zend_object_iterator *spl_fixedarray_get_iterator(zend_class_entry *ce, zval *object, int by_ref);
2008-06-06 23:53:43 +00:00
2014-12-13 22:06:14 +00:00
static zend_object *spl_fixedarray_object_new_ex(zend_class_entry *class_type, zval *orig, int clone_orig) /* {{{ */
2008-06-06 23:53:43 +00:00
{
spl_fixedarray_object *intern;
2008-06-06 23:53:43 +00:00
zend_class_entry *parent = class_type;
int inherited = 0;
intern = zend_object_alloc(sizeof(spl_fixedarray_object), parent);
2008-06-06 23:53:43 +00:00
2014-12-13 22:06:14 +00:00
zend_object_std_init(&intern->std, class_type);
object_properties_init(&intern->std, class_type);
2008-06-06 23:53:43 +00:00
intern->current = 0;
intern->flags = 0;
2008-06-06 23:53:43 +00:00
if (orig && clone_orig) {
spl_fixedarray_object *other = Z_SPLFIXEDARRAY_P(orig);
2008-06-06 23:53:43 +00:00
intern->ce_get_iterator = other->ce_get_iterator;
2016-08-04 15:35:14 +00:00
spl_fixedarray_init(&intern->array, other->array.size);
spl_fixedarray_copy(&intern->array, &other->array);
2008-06-06 23:53:43 +00:00
}
while (parent) {
if (parent == spl_ce_SplFixedArray) {
intern->std.handlers = &spl_handler_SplFixedArray;
class_type->get_iterator = spl_fixedarray_get_iterator;
2008-06-06 23:53:43 +00:00
break;
}
parent = parent->parent;
inherited = 1;
}
if (!parent) { /* this must never happen */
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_COMPILE_ERROR, "Internal compiler error, Class is not child of SplFixedArray");
2008-06-06 23:53:43 +00:00
}
if (!class_type->iterator_funcs.zf_current) {
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);
}
2008-06-06 23:53:43 +00:00
if (inherited) {
2015-01-03 09:22:58 +00:00
if (class_type->iterator_funcs.zf_rewind->common.scope != parent) {
intern->flags |= SPL_FIXEDARRAY_OVERLOADED_REWIND;
}
2015-01-03 09:22:58 +00:00
if (class_type->iterator_funcs.zf_valid->common.scope != parent) {
intern->flags |= SPL_FIXEDARRAY_OVERLOADED_VALID;
}
2015-01-03 09:22:58 +00:00
if (class_type->iterator_funcs.zf_key->common.scope != parent) {
intern->flags |= SPL_FIXEDARRAY_OVERLOADED_KEY;
}
2015-01-03 09:22:58 +00:00
if (class_type->iterator_funcs.zf_current->common.scope != parent) {
intern->flags |= SPL_FIXEDARRAY_OVERLOADED_CURRENT;
}
2015-01-03 09:22:58 +00:00
if (class_type->iterator_funcs.zf_next->common.scope != parent) {
intern->flags |= SPL_FIXEDARRAY_OVERLOADED_NEXT;
}
intern->fptr_offset_get = zend_hash_str_find_ptr(&class_type->function_table, "offsetget", sizeof("offsetget") - 1);
2008-06-06 23:53:43 +00:00
if (intern->fptr_offset_get->common.scope == parent) {
intern->fptr_offset_get = NULL;
}
intern->fptr_offset_set = zend_hash_str_find_ptr(&class_type->function_table, "offsetset", sizeof("offsetset") - 1);
2008-06-06 23:53:43 +00:00
if (intern->fptr_offset_set->common.scope == parent) {
intern->fptr_offset_set = NULL;
}
intern->fptr_offset_has = zend_hash_str_find_ptr(&class_type->function_table, "offsetexists", sizeof("offsetexists") - 1);
2008-06-06 23:53:43 +00:00
if (intern->fptr_offset_has->common.scope == parent) {
intern->fptr_offset_has = NULL;
}
intern->fptr_offset_del = zend_hash_str_find_ptr(&class_type->function_table, "offsetunset", sizeof("offsetunset") - 1);
2008-06-06 23:53:43 +00:00
if (intern->fptr_offset_del->common.scope == parent) {
intern->fptr_offset_del = NULL;
}
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;
}
2008-06-06 23:53:43 +00:00
}
return &intern->std;
2008-06-06 23:53:43 +00:00
}
/* }}} */
2014-12-13 22:06:14 +00:00
static zend_object *spl_fixedarray_new(zend_class_entry *class_type) /* {{{ */
2008-06-06 23:53:43 +00:00
{
2014-12-13 22:06:14 +00:00
return spl_fixedarray_object_new_ex(class_type, NULL, 0);
2008-06-06 23:53:43 +00:00
}
/* }}} */
2014-12-13 22:06:14 +00:00
static zend_object *spl_fixedarray_object_clone(zval *zobject) /* {{{ */
2008-06-06 23:53:43 +00:00
{
zend_object *old_object;
zend_object *new_object;
2008-06-06 23:53:43 +00:00
old_object = Z_OBJ_P(zobject);
2014-12-13 22:06:14 +00:00
new_object = spl_fixedarray_object_new_ex(old_object->ce, zobject, 1);
2008-06-06 23:53:43 +00:00
2014-12-13 22:06:14 +00:00
zend_objects_clone_members(new_object, old_object);
2008-06-06 23:53:43 +00:00
return new_object;
2008-06-06 23:53:43 +00:00
}
/* }}} */
2014-12-13 22:06:14 +00:00
static inline zval *spl_fixedarray_object_read_dimension_helper(spl_fixedarray_object *intern, zval *offset) /* {{{ */
2008-06-06 23:53:43 +00:00
{
2014-08-25 17:24:55 +00:00
zend_long index;
2008-06-06 23:53:43 +00:00
2015-01-03 09:22:58 +00:00
/* we have to return NULL on error here to avoid memleak because of
2008-06-07 14:09:06 +00:00
* ZE duplicating uninitialized_zval_ptr */
if (!offset) {
2014-12-13 22:06:14 +00:00
zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0);
2008-06-07 14:09:06 +00:00
return NULL;
}
2014-08-25 17:24:55 +00:00
if (Z_TYPE_P(offset) != IS_LONG) {
2014-12-13 22:06:14 +00:00
index = spl_offset_convert_to_long(offset);
} else {
2014-08-25 17:24:55 +00:00
index = Z_LVAL_P(offset);
}
2015-01-03 09:22:58 +00:00
2016-08-04 15:35:14 +00:00
if (index < 0 || index >= intern->array.size) {
2014-12-13 22:06:14 +00:00
zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0);
2008-06-07 14:09:06 +00:00
return NULL;
2016-08-04 15:35:14 +00:00
} else if (Z_ISUNDEF(intern->array.elements[index])) {
2008-06-07 14:09:06 +00:00
return NULL;
2008-06-06 23:53:43 +00:00
} else {
2016-08-04 15:35:14 +00:00
return &intern->array.elements[index];
2008-06-06 23:53:43 +00:00
}
}
/* }}} */
2014-12-13 22:06:14 +00:00
static zval *spl_fixedarray_object_read_dimension(zval *object, zval *offset, int type, zval *rv) /* {{{ */
2008-06-06 23:53:43 +00:00
{
spl_fixedarray_object *intern;
2008-06-06 23:53:43 +00:00
intern = Z_SPLFIXEDARRAY_P(object);
2008-06-06 23:53:43 +00:00
2017-05-24 16:00:48 +00:00
if (type == BP_VAR_IS && intern->fptr_offset_has) {
SEPARATE_ARG_IF_REF(offset);
zend_call_method_with_1_params(object, intern->std.ce, &intern->fptr_offset_has, "offsetexists", rv, offset);
if (UNEXPECTED(Z_ISUNDEF_P(rv))) {
zval_ptr_dtor(offset);
return NULL;
}
if (!i_zend_is_true(rv)) {
zval_ptr_dtor(offset);
zval_ptr_dtor(rv);
return &EG(uninitialized_zval);
}
zval_ptr_dtor(rv);
}
2008-06-06 23:53:43 +00:00
if (intern->fptr_offset_get) {
zval tmp;
if (!offset) {
ZVAL_NULL(&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 (!Z_ISUNDEF_P(rv)) {
return rv;
2008-06-06 23:53:43 +00:00
}
return &EG(uninitialized_zval);
2008-06-06 23:53:43 +00:00
}
2014-12-13 22:06:14 +00:00
return spl_fixedarray_object_read_dimension_helper(intern, offset);
2008-06-06 23:53:43 +00:00
}
/* }}} */
2014-12-13 22:06:14 +00:00
static inline void spl_fixedarray_object_write_dimension_helper(spl_fixedarray_object *intern, zval *offset, zval *value) /* {{{ */
2008-06-06 23:53:43 +00:00
{
2014-08-25 17:24:55 +00:00
zend_long index;
2008-06-06 23:53:43 +00:00
2008-06-07 12:47:04 +00:00
if (!offset) {
/* '$array[] = value' syntax is not supported */
2014-12-13 22:06:14 +00:00
zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0);
2008-06-07 12:47:04 +00:00
return;
}
2014-08-25 17:24:55 +00:00
if (Z_TYPE_P(offset) != IS_LONG) {
2014-12-13 22:06:14 +00:00
index = spl_offset_convert_to_long(offset);
} else {
2014-08-25 17:24:55 +00:00
index = Z_LVAL_P(offset);
}
2008-06-06 23:53:43 +00:00
2016-08-04 15:35:14 +00:00
if (index < 0 || index >= intern->array.size) {
2014-12-13 22:06:14 +00:00
zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0);
2008-06-06 23:53:43 +00:00
return;
} else {
2016-08-04 15:35:14 +00:00
if (!Z_ISUNDEF(intern->array.elements[index])) {
zval_ptr_dtor(&(intern->array.elements[index]));
2008-06-06 23:53:43 +00:00
}
ZVAL_DEREF(value);
2016-08-04 15:35:14 +00:00
ZVAL_COPY(&intern->array.elements[index], value);
2008-06-06 23:53:43 +00:00
}
}
/* }}} */
2014-12-13 22:06:14 +00:00
static void spl_fixedarray_object_write_dimension(zval *object, zval *offset, zval *value) /* {{{ */
2008-06-06 23:53:43 +00:00
{
spl_fixedarray_object *intern;
2016-04-28 14:40:28 +00:00
zval tmp;
2008-06-06 23:53:43 +00:00
intern = Z_SPLFIXEDARRAY_P(object);
2008-06-06 23:53:43 +00:00
if (intern->fptr_offset_set) {
if (!offset) {
ZVAL_NULL(&tmp);
offset = &tmp;
} else {
SEPARATE_ARG_IF_REF(offset);
}
2008-06-06 23:53:43 +00:00
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);
2008-06-06 23:53:43 +00:00
return;
}
2014-12-13 22:06:14 +00:00
spl_fixedarray_object_write_dimension_helper(intern, offset, value);
2008-06-06 23:53:43 +00:00
}
/* }}} */
2014-12-13 22:06:14 +00:00
static inline void spl_fixedarray_object_unset_dimension_helper(spl_fixedarray_object *intern, zval *offset) /* {{{ */
2008-06-06 23:53:43 +00:00
{
2014-08-25 17:24:55 +00:00
zend_long index;
2015-01-03 09:22:58 +00:00
2014-08-25 17:24:55 +00:00
if (Z_TYPE_P(offset) != IS_LONG) {
2014-12-13 22:06:14 +00:00
index = spl_offset_convert_to_long(offset);
} else {
2014-08-25 17:24:55 +00:00
index = Z_LVAL_P(offset);
}
2015-01-03 09:22:58 +00:00
2016-08-04 15:35:14 +00:00
if (index < 0 || index >= intern->array.size) {
2014-12-13 22:06:14 +00:00
zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0);
2008-06-06 23:53:43 +00:00
return;
} else {
2016-08-04 15:35:14 +00:00
zval_ptr_dtor(&(intern->array.elements[index]));
ZVAL_UNDEF(&intern->array.elements[index]);
2008-06-06 23:53:43 +00:00
}
}
/* }}} */
2014-12-13 22:06:14 +00:00
static void spl_fixedarray_object_unset_dimension(zval *object, zval *offset) /* {{{ */
2008-06-06 23:53:43 +00:00
{
spl_fixedarray_object *intern;
2008-06-06 23:53:43 +00:00
intern = Z_SPLFIXEDARRAY_P(object);
2008-06-06 23:53:43 +00:00
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);
2008-06-06 23:53:43 +00:00
return;
}
2014-12-13 22:06:14 +00:00
spl_fixedarray_object_unset_dimension_helper(intern, offset);
2008-06-06 23:53:43 +00:00
}
/* }}} */
2014-12-13 22:06:14 +00:00
static inline int spl_fixedarray_object_has_dimension_helper(spl_fixedarray_object *intern, zval *offset, int check_empty) /* {{{ */
2008-06-06 23:53:43 +00:00
{
2014-08-25 17:24:55 +00:00
zend_long index;
2008-06-06 23:53:43 +00:00
int retval;
2015-01-03 09:22:58 +00:00
2014-08-25 17:24:55 +00:00
if (Z_TYPE_P(offset) != IS_LONG) {
2014-12-13 22:06:14 +00:00
index = spl_offset_convert_to_long(offset);
} else {
2014-08-25 17:24:55 +00:00
index = Z_LVAL_P(offset);
}
2015-01-03 09:22:58 +00:00
2016-08-04 15:35:14 +00:00
if (index < 0 || index >= intern->array.size) {
2008-06-06 23:53:43 +00:00
retval = 0;
} else {
2016-08-04 15:35:14 +00:00
if (Z_ISUNDEF(intern->array.elements[index])) {
2008-06-06 23:53:43 +00:00
retval = 0;
} else if (check_empty) {
2016-08-04 15:35:14 +00:00
if (zend_is_true(&intern->array.elements[index])) {
2008-06-06 23:53:43 +00:00
retval = 1;
} else {
retval = 0;
}
} else { /* != NULL and !check_empty */
retval = 1;
}
}
return retval;
}
/* }}} */
2014-12-13 22:06:14 +00:00
static int spl_fixedarray_object_has_dimension(zval *object, zval *offset, int check_empty) /* {{{ */
2008-06-06 23:53:43 +00:00
{
spl_fixedarray_object *intern;
2008-06-06 23:53:43 +00:00
intern = Z_SPLFIXEDARRAY_P(object);
2008-06-06 23:53:43 +00:00
if (intern->fptr_offset_has) {
zval rv;
2008-06-06 23:53:43 +00:00
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 (!Z_ISUNDEF(rv)) {
zend_bool result = zend_is_true(&rv);
zval_ptr_dtor(&rv);
return result;
2008-06-06 23:53:43 +00:00
}
return 0;
}
2014-12-13 22:06:14 +00:00
return spl_fixedarray_object_has_dimension_helper(intern, offset, check_empty);
2008-06-06 23:53:43 +00:00
}
/* }}} */
2014-12-13 22:06:14 +00:00
static int spl_fixedarray_object_count_elements(zval *object, zend_long *count) /* {{{ */
2008-06-06 23:53:43 +00:00
{
spl_fixedarray_object *intern;
2015-01-03 09:22:58 +00:00
intern = Z_SPLFIXEDARRAY_P(object);
if (intern->fptr_count) {
zval rv;
zend_call_method_with_0_params(object, intern->std.ce, &intern->fptr_count, "count", &rv);
if (!Z_ISUNDEF(rv)) {
*count = zval_get_long(&rv);
zval_ptr_dtor(&rv);
2016-08-04 15:35:14 +00:00
} else {
*count = 0;
}
2016-08-04 15:35:14 +00:00
} else {
*count = intern->array.size;
2008-06-07 21:36:13 +00:00
}
2008-06-06 23:53:43 +00:00
return SUCCESS;
}
/* }}} */
/* {{{ proto void SplFixedArray::__construct([int size])
2008-06-06 23:53:43 +00:00
*/
SPL_METHOD(SplFixedArray, __construct)
2008-06-06 23:53:43 +00:00
{
zval *object = getThis();
spl_fixedarray_object *intern;
2014-08-25 17:24:55 +00:00
zend_long size = 0;
2008-06-06 23:53:43 +00:00
if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|l", &size) == FAILURE) {
2008-06-06 23:53:43 +00:00
return;
}
if (size < 0) {
2014-12-13 22:06:14 +00:00
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "array size cannot be less than zero");
2008-06-06 23:53:43 +00:00
return;
}
intern = Z_SPLFIXEDARRAY_P(object);
2008-06-06 23:53:43 +00:00
2016-08-04 15:35:14 +00:00
if (intern->array.size > 0) {
2008-06-06 23:53:43 +00:00
/* called __construct() twice, bail out */
return;
}
2016-08-04 15:35:14 +00:00
spl_fixedarray_init(&intern->array, size);
2008-06-06 23:53:43 +00:00
}
/* }}} */
/* {{{ proto void SplFixedArray::__wakeup()
*/
SPL_METHOD(SplFixedArray, __wakeup)
{
spl_fixedarray_object *intern = Z_SPLFIXEDARRAY_P(getThis());
2014-12-13 22:06:14 +00:00
HashTable *intern_ht = zend_std_get_properties(getThis());
zval *data;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
2016-08-04 15:35:14 +00:00
if (intern->array.size == 0) {
int index = 0;
int size = zend_hash_num_elements(intern_ht);
2016-08-04 15:35:14 +00:00
spl_fixedarray_init(&intern->array, size);
2014-05-19 02:39:28 +00:00
ZEND_HASH_FOREACH_VAL(intern_ht, data) {
2017-11-02 04:13:35 +00:00
ZVAL_COPY(&intern->array.elements[index], data);
2014-05-19 02:39:28 +00:00
index++;
} ZEND_HASH_FOREACH_END();
/* Remove the unserialised properties, since we now have the elements
* within the spl_fixedarray_object structure. */
zend_hash_clean(intern_ht);
}
}
/* }}} */
/* {{{ proto int SplFixedArray::count(void)
2008-06-06 23:53:43 +00:00
*/
SPL_METHOD(SplFixedArray, count)
2008-06-06 23:53:43 +00:00
{
zval *object = getThis();
spl_fixedarray_object *intern;
2008-06-06 23:53:43 +00:00
if (zend_parse_parameters_none() == FAILURE) {
2008-06-06 23:53:43 +00:00
return;
}
intern = Z_SPLFIXEDARRAY_P(object);
2016-08-04 15:35:14 +00:00
RETURN_LONG(intern->array.size);
2008-06-06 23:53:43 +00:00
}
/* }}} */
/* {{{ proto object SplFixedArray::toArray()
*/
SPL_METHOD(SplFixedArray, toArray)
{
spl_fixedarray_object *intern;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
intern = Z_SPLFIXEDARRAY_P(getThis());
2016-08-04 15:35:14 +00:00
if (intern->array.size > 0) {
int i = 0;
array_init(return_value);
2016-08-04 15:35:14 +00:00
for (; i < intern->array.size; i++) {
if (!Z_ISUNDEF(intern->array.elements[i])) {
zend_hash_index_update(Z_ARRVAL_P(return_value), i, &intern->array.elements[i]);
2017-11-02 04:13:35 +00:00
Z_TRY_ADDREF(intern->array.elements[i]);
} else {
zend_hash_index_update(Z_ARRVAL_P(return_value), i, &EG(uninitialized_zval));
}
}
} else {
ZVAL_EMPTY_ARRAY(return_value);
}
}
/* }}} */
/* {{{ proto object SplFixedArray::fromArray(array data[, bool save_indexes])
*/
SPL_METHOD(SplFixedArray, fromArray)
{
zval *data;
2016-08-04 15:35:14 +00:00
spl_fixedarray array;
spl_fixedarray_object *intern;
int num;
zend_bool save_indexes = 1;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|b", &data, &save_indexes) == FAILURE) {
return;
}
num = zend_hash_num_elements(Z_ARRVAL_P(data));
2015-01-03 09:22:58 +00:00
if (num > 0 && save_indexes) {
zval *element;
zend_string *str_index;
2014-08-25 17:24:55 +00:00
zend_ulong num_index, max_index = 0;
zend_long tmp;
2014-05-19 02:39:28 +00:00
ZEND_HASH_FOREACH_KEY(Z_ARRVAL_P(data), num_index, str_index) {
2014-08-25 17:24:55 +00:00
if (str_index != NULL || (zend_long)num_index < 0) {
2014-12-13 22:06:14 +00:00
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "array must contain only positive integer keys");
return;
}
if (num_index > max_index) {
max_index = num_index;
}
2014-05-19 02:39:28 +00:00
} ZEND_HASH_FOREACH_END();
tmp = max_index + 1;
if (tmp <= 0) {
2014-12-13 22:06:14 +00:00
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "integer overflow detected");
return;
}
2016-08-04 15:35:14 +00:00
spl_fixedarray_init(&array, tmp);
2014-05-19 02:39:28 +00:00
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(data), num_index, str_index, element) {
ZVAL_DEREF(element);
2016-08-04 15:35:14 +00:00
ZVAL_COPY(&array.elements[num_index], element);
2014-05-19 02:39:28 +00:00
} ZEND_HASH_FOREACH_END();
} else if (num > 0 && !save_indexes) {
zval *element;
2014-08-25 17:24:55 +00:00
zend_long i = 0;
2015-01-03 09:22:58 +00:00
2016-08-04 15:35:14 +00:00
spl_fixedarray_init(&array, num);
2015-01-03 09:22:58 +00:00
2014-05-19 02:39:28 +00:00
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(data), element) {
ZVAL_DEREF(element);
2016-08-04 15:35:14 +00:00
ZVAL_COPY(&array.elements[i], element);
i++;
2014-05-19 02:39:28 +00:00
} ZEND_HASH_FOREACH_END();
} else {
2016-08-04 15:35:14 +00:00
spl_fixedarray_init(&array, 0);
}
object_init_ex(return_value, spl_ce_SplFixedArray);
intern = Z_SPLFIXEDARRAY_P(return_value);
intern->array = array;
}
/* }}} */
/* {{{ proto int SplFixedArray::getSize(void)
2008-06-06 23:53:43 +00:00
*/
SPL_METHOD(SplFixedArray, getSize)
2008-06-06 23:53:43 +00:00
{
zval *object = getThis();
spl_fixedarray_object *intern;
2008-06-06 23:53:43 +00:00
if (zend_parse_parameters_none() == FAILURE) {
2008-06-06 23:53:43 +00:00
return;
}
intern = Z_SPLFIXEDARRAY_P(object);
2016-08-04 15:35:14 +00:00
RETURN_LONG(intern->array.size);
2008-06-06 23:53:43 +00:00
}
/* }}} */
/* {{{ proto bool SplFixedArray::setSize(int size)
2008-06-06 23:53:43 +00:00
*/
SPL_METHOD(SplFixedArray, setSize)
2008-06-06 23:53:43 +00:00
{
zval *object = getThis();
spl_fixedarray_object *intern;
2014-08-25 17:24:55 +00:00
zend_long size;
2008-06-06 23:53:43 +00:00
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &size) == FAILURE) {
2008-06-06 23:53:43 +00:00
return;
}
if (size < 0) {
2014-12-13 22:06:14 +00:00
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "array size cannot be less than zero");
2008-06-06 23:53:43 +00:00
return;
}
intern = Z_SPLFIXEDARRAY_P(object);
2008-06-07 21:36:13 +00:00
2016-08-04 15:35:14 +00:00
spl_fixedarray_resize(&intern->array, size);
2008-06-06 23:53:43 +00:00
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool SplFixedArray::offsetExists(mixed $index)
2008-06-06 23:53:43 +00:00
Returns whether the requested $index exists. */
SPL_METHOD(SplFixedArray, offsetExists)
2008-06-06 23:53:43 +00:00
{
zval *zindex;
spl_fixedarray_object *intern;
2008-06-06 23:53:43 +00:00
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zindex) == FAILURE) {
2008-06-06 23:53:43 +00:00
return;
}
intern = Z_SPLFIXEDARRAY_P(getThis());
2008-06-06 23:53:43 +00:00
2014-12-13 22:06:14 +00:00
RETURN_BOOL(spl_fixedarray_object_has_dimension_helper(intern, zindex, 0));
2008-06-06 23:53:43 +00:00
} /* }}} */
/* {{{ proto mixed SplFixedArray::offsetGet(mixed $index)
2008-06-06 23:53:43 +00:00
Returns the value at the specified $index. */
SPL_METHOD(SplFixedArray, offsetGet)
2008-06-06 23:53:43 +00:00
{
zval *zindex, *value;
spl_fixedarray_object *intern;
2008-06-06 23:53:43 +00:00
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zindex) == FAILURE) {
2008-06-06 23:53:43 +00:00
return;
}
intern = Z_SPLFIXEDARRAY_P(getThis());
2014-12-13 22:06:14 +00:00
value = spl_fixedarray_object_read_dimension_helper(intern, zindex);
2008-06-06 23:53:43 +00:00
if (value) {
ZVAL_DEREF(value);
ZVAL_COPY(return_value, value);
} else {
RETURN_NULL();
2008-06-07 14:09:06 +00:00
}
2008-06-06 23:53:43 +00:00
} /* }}} */
/* {{{ proto void SplFixedArray::offsetSet(mixed $index, mixed $newval)
2008-06-06 23:53:43 +00:00
Sets the value at the specified $index to $newval. */
SPL_METHOD(SplFixedArray, offsetSet)
2008-06-06 23:53:43 +00:00
{
zval *zindex, *value;
spl_fixedarray_object *intern;
2008-06-06 23:53:43 +00:00
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &zindex, &value) == FAILURE) {
2008-06-06 23:53:43 +00:00
return;
}
intern = Z_SPLFIXEDARRAY_P(getThis());
2014-12-13 22:06:14 +00:00
spl_fixedarray_object_write_dimension_helper(intern, zindex, value);
2008-06-06 23:53:43 +00:00
} /* }}} */
/* {{{ proto void SplFixedArray::offsetUnset(mixed $index)
2008-06-06 23:53:43 +00:00
Unsets the value at the specified $index. */
SPL_METHOD(SplFixedArray, offsetUnset)
2008-06-06 23:53:43 +00:00
{
zval *zindex;
spl_fixedarray_object *intern;
2008-06-06 23:53:43 +00:00
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zindex) == FAILURE) {
2008-06-06 23:53:43 +00:00
return;
}
intern = Z_SPLFIXEDARRAY_P(getThis());
2014-12-13 22:06:14 +00:00
spl_fixedarray_object_unset_dimension_helper(intern, zindex);
2008-06-06 23:53:43 +00:00
} /* }}} */
2014-12-13 22:06:14 +00:00
static void spl_fixedarray_it_dtor(zend_object_iterator *iter) /* {{{ */
2008-06-06 23:53:43 +00:00
{
spl_fixedarray_it *iterator = (spl_fixedarray_it *)iter;
2008-06-06 23:53:43 +00:00
2014-12-13 22:06:14 +00:00
zend_user_it_invalidate_current(iter);
zval_ptr_dtor(&iterator->intern.it.data);
2008-06-06 23:53:43 +00:00
}
/* }}} */
2014-12-13 22:06:14 +00:00
static void spl_fixedarray_it_rewind(zend_object_iterator *iter) /* {{{ */
2008-06-06 23:53:43 +00:00
{
2014-03-15 05:18:32 +00:00
spl_fixedarray_object *object = Z_SPLFIXEDARRAY_P(&iter->data);
2008-06-06 23:53:43 +00:00
if (object->flags & SPL_FIXEDARRAY_OVERLOADED_REWIND) {
2014-12-13 22:06:14 +00:00
zend_user_it_rewind(iter);
} else {
object->current = 0;
2008-06-06 23:53:43 +00:00
}
}
/* }}} */
2014-12-13 22:06:14 +00:00
static int spl_fixedarray_it_valid(zend_object_iterator *iter) /* {{{ */
2008-06-06 23:53:43 +00:00
{
2014-03-15 05:18:32 +00:00
spl_fixedarray_object *object = Z_SPLFIXEDARRAY_P(&iter->data);
2008-06-06 23:53:43 +00:00
if (object->flags & SPL_FIXEDARRAY_OVERLOADED_VALID) {
2014-12-13 22:06:14 +00:00
return zend_user_it_valid(iter);
2008-06-06 23:53:43 +00:00
}
2016-08-04 15:35:14 +00:00
if (object->current >= 0 && object->current < object->array.size) {
2008-06-06 23:53:43 +00:00
return SUCCESS;
}
return FAILURE;
}
/* }}} */
2014-12-13 22:06:14 +00:00
static zval *spl_fixedarray_it_get_current_data(zend_object_iterator *iter) /* {{{ */
2008-06-06 23:53:43 +00:00
{
zval zindex;
2014-03-15 05:18:32 +00:00
spl_fixedarray_object *object = Z_SPLFIXEDARRAY_P(&iter->data);
2008-06-06 23:53:43 +00:00
if (object->flags & SPL_FIXEDARRAY_OVERLOADED_CURRENT) {
2014-12-13 22:06:14 +00:00
return zend_user_it_get_current_data(iter);
} else {
zval *data;
2008-06-06 23:53:43 +00:00
2014-08-25 17:24:55 +00:00
ZVAL_LONG(&zindex, object->current);
2008-06-06 23:53:43 +00:00
2014-12-13 22:06:14 +00:00
data = spl_fixedarray_object_read_dimension_helper(object, &zindex);
zval_ptr_dtor(&zindex);
if (data == NULL) {
data = &EG(uninitialized_zval);
}
return data;
2008-06-07 14:09:06 +00:00
}
2008-06-06 23:53:43 +00:00
}
/* }}} */
2014-12-13 22:06:14 +00:00
static void spl_fixedarray_it_get_current_key(zend_object_iterator *iter, zval *key) /* {{{ */
2008-06-06 23:53:43 +00:00
{
2014-03-15 05:18:32 +00:00
spl_fixedarray_object *object = Z_SPLFIXEDARRAY_P(&iter->data);
2008-06-06 23:53:43 +00:00
if (object->flags & SPL_FIXEDARRAY_OVERLOADED_KEY) {
2014-12-13 22:06:14 +00:00
zend_user_it_get_current_key(iter, key);
2008-06-06 23:53:43 +00:00
} else {
2014-08-25 17:24:55 +00:00
ZVAL_LONG(key, object->current);
2008-06-06 23:53:43 +00:00
}
}
/* }}} */
2014-12-13 22:06:14 +00:00
static void spl_fixedarray_it_move_forward(zend_object_iterator *iter) /* {{{ */
2008-06-06 23:53:43 +00:00
{
2014-03-15 05:18:32 +00:00
spl_fixedarray_object *object = Z_SPLFIXEDARRAY_P(&iter->data);
2008-06-06 23:53:43 +00:00
if (object->flags & SPL_FIXEDARRAY_OVERLOADED_NEXT) {
2014-12-13 22:06:14 +00:00
zend_user_it_move_forward(iter);
} else {
2014-12-13 22:06:14 +00:00
zend_user_it_invalidate_current(iter);
object->current++;
2008-06-06 23:53:43 +00:00
}
}
/* }}} */
/* {{{ proto int SplFixedArray::key()
2008-06-06 23:53:43 +00:00
Return current array key */
SPL_METHOD(SplFixedArray, key)
2008-06-06 23:53:43 +00:00
{
spl_fixedarray_object *intern = Z_SPLFIXEDARRAY_P(getThis());
2015-01-03 09:22:58 +00:00
2009-05-23 15:14:15 +00:00
if (zend_parse_parameters_none() == FAILURE) {
return;
}
2008-06-06 23:53:43 +00:00
2014-08-25 17:24:55 +00:00
RETURN_LONG(intern->current);
2008-06-06 23:53:43 +00:00
}
/* }}} */
/* {{{ proto void SplFixedArray::next()
2008-06-06 23:53:43 +00:00
Move to next entry */
SPL_METHOD(SplFixedArray, next)
2008-06-06 23:53:43 +00:00
{
spl_fixedarray_object *intern = Z_SPLFIXEDARRAY_P(getThis());
2015-01-03 09:22:58 +00:00
2009-05-23 15:14:15 +00:00
if (zend_parse_parameters_none() == FAILURE) {
return;
}
2008-06-06 23:53:43 +00:00
intern->current++;
}
/* }}} */
/* {{{ proto bool SplFixedArray::valid()
2008-06-06 23:53:43 +00:00
Check whether the datastructure contains more entries */
SPL_METHOD(SplFixedArray, valid)
2008-06-06 23:53:43 +00:00
{
spl_fixedarray_object *intern = Z_SPLFIXEDARRAY_P(getThis());
2015-01-03 09:22:58 +00:00
2009-05-23 15:14:15 +00:00
if (zend_parse_parameters_none() == FAILURE) {
return;
}
2008-06-06 23:53:43 +00:00
2016-08-04 15:35:14 +00:00
RETURN_BOOL(intern->current >= 0 && intern->current < intern->array.size);
2008-06-06 23:53:43 +00:00
}
/* }}} */
/* {{{ proto void SplFixedArray::rewind()
2008-06-06 23:53:43 +00:00
Rewind the datastructure back to the start */
SPL_METHOD(SplFixedArray, rewind)
2008-06-06 23:53:43 +00:00
{
spl_fixedarray_object *intern = Z_SPLFIXEDARRAY_P(getThis());
2015-01-03 09:22:58 +00:00
2009-05-23 15:14:15 +00:00
if (zend_parse_parameters_none() == FAILURE) {
return;
}
2008-06-06 23:53:43 +00:00
intern->current = 0;
}
/* }}} */
/* {{{ proto mixed|NULL SplFixedArray::current()
2008-06-06 23:53:43 +00:00
Return current datastructure entry */
SPL_METHOD(SplFixedArray, current)
2008-06-06 23:53:43 +00:00
{
zval zindex, *value;
spl_fixedarray_object *intern = Z_SPLFIXEDARRAY_P(getThis());
2015-01-03 09:22:58 +00:00
2009-05-23 15:14:15 +00:00
if (zend_parse_parameters_none() == FAILURE) {
return;
}
2008-06-06 23:53:43 +00:00
2014-08-25 17:24:55 +00:00
ZVAL_LONG(&zindex, intern->current);
2008-06-06 23:53:43 +00:00
2014-12-13 22:06:14 +00:00
value = spl_fixedarray_object_read_dimension_helper(intern, &zindex);
2008-06-06 23:53:43 +00:00
zval_ptr_dtor(&zindex);
if (value) {
ZVAL_DEREF(value);
ZVAL_COPY(return_value, value);
} else {
RETURN_NULL();
2008-06-07 14:09:06 +00:00
}
2008-06-06 23:53:43 +00:00
}
/* }}} */
/* iterator handler table */
static const zend_object_iterator_funcs spl_fixedarray_it_funcs = {
spl_fixedarray_it_dtor,
spl_fixedarray_it_valid,
spl_fixedarray_it_get_current_data,
spl_fixedarray_it_get_current_key,
spl_fixedarray_it_move_forward,
2016-06-21 21:40:50 +00:00
spl_fixedarray_it_rewind,
NULL
2008-06-06 23:53:43 +00:00
};
2014-12-13 22:06:14 +00:00
zend_object_iterator *spl_fixedarray_get_iterator(zend_class_entry *ce, zval *object, int by_ref) /* {{{ */
2008-06-06 23:53:43 +00:00
{
2014-03-15 05:18:32 +00:00
spl_fixedarray_it *iterator;
2008-06-06 23:53:43 +00:00
if (by_ref) {
2014-12-13 22:06:14 +00:00
zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0);
2008-06-06 23:53:43 +00:00
return NULL;
}
iterator = emalloc(sizeof(spl_fixedarray_it));
2014-12-13 22:06:14 +00:00
zend_iterator_init((zend_object_iterator*)iterator);
2015-01-03 09:22:58 +00:00
ZVAL_COPY(&iterator->intern.it.data, object);
iterator->intern.it.funcs = &spl_fixedarray_it_funcs;
iterator->intern.ce = ce;
ZVAL_UNDEF(&iterator->intern.value);
2008-06-06 23:53:43 +00:00
return &iterator->intern.it;
2008-06-06 23:53:43 +00:00
}
/* }}} */
ZEND_BEGIN_ARG_INFO_EX(arginfo_splfixedarray_construct, 0, 0, 0)
ZEND_ARG_INFO(0, size)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_fixedarray_offsetGet, 0, 0, 1)
2008-06-06 23:53:43 +00:00
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_fixedarray_offsetSet, 0, 0, 2)
2008-06-06 23:53:43 +00:00
ZEND_ARG_INFO(0, index)
ZEND_ARG_INFO(0, newval)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_fixedarray_setSize, 0)
2008-06-06 23:53:43 +00:00
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_fixedarray_fromArray, 0, 0, 1)
ZEND_ARG_INFO(0, data)
ZEND_ARG_INFO(0, save_indexes)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_splfixedarray_void, 0)
ZEND_END_ARG_INFO()
static zend_function_entry spl_funcs_SplFixedArray[] = { /* {{{ */
SPL_ME(SplFixedArray, __construct, arginfo_splfixedarray_construct,ZEND_ACC_PUBLIC)
SPL_ME(SplFixedArray, __wakeup, arginfo_splfixedarray_void, ZEND_ACC_PUBLIC)
SPL_ME(SplFixedArray, count, arginfo_splfixedarray_void, ZEND_ACC_PUBLIC)
SPL_ME(SplFixedArray, toArray, arginfo_splfixedarray_void, ZEND_ACC_PUBLIC)
SPL_ME(SplFixedArray, fromArray, arginfo_fixedarray_fromArray, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
SPL_ME(SplFixedArray, getSize, arginfo_splfixedarray_void, ZEND_ACC_PUBLIC)
SPL_ME(SplFixedArray, setSize, arginfo_fixedarray_setSize, ZEND_ACC_PUBLIC)
SPL_ME(SplFixedArray, offsetExists, arginfo_fixedarray_offsetGet, ZEND_ACC_PUBLIC)
SPL_ME(SplFixedArray, offsetGet, arginfo_fixedarray_offsetGet, ZEND_ACC_PUBLIC)
SPL_ME(SplFixedArray, offsetSet, arginfo_fixedarray_offsetSet, ZEND_ACC_PUBLIC)
SPL_ME(SplFixedArray, offsetUnset, arginfo_fixedarray_offsetGet, ZEND_ACC_PUBLIC)
SPL_ME(SplFixedArray, rewind, arginfo_splfixedarray_void, ZEND_ACC_PUBLIC)
SPL_ME(SplFixedArray, current, arginfo_splfixedarray_void, ZEND_ACC_PUBLIC)
SPL_ME(SplFixedArray, key, arginfo_splfixedarray_void, ZEND_ACC_PUBLIC)
SPL_ME(SplFixedArray, next, arginfo_splfixedarray_void, ZEND_ACC_PUBLIC)
SPL_ME(SplFixedArray, valid, arginfo_splfixedarray_void, ZEND_ACC_PUBLIC)
2011-07-25 11:35:02 +00:00
PHP_FE_END
2008-06-06 23:53:43 +00:00
};
/* }}} */
/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(spl_fixedarray)
2008-06-06 23:53:43 +00:00
{
REGISTER_SPL_STD_CLASS_EX(SplFixedArray, spl_fixedarray_new, spl_funcs_SplFixedArray);
memcpy(&spl_handler_SplFixedArray, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
2008-06-06 23:53:43 +00:00
spl_handler_SplFixedArray.offset = XtOffsetOf(spl_fixedarray_object, std);
spl_handler_SplFixedArray.clone_obj = spl_fixedarray_object_clone;
spl_handler_SplFixedArray.read_dimension = spl_fixedarray_object_read_dimension;
spl_handler_SplFixedArray.write_dimension = spl_fixedarray_object_write_dimension;
spl_handler_SplFixedArray.unset_dimension = spl_fixedarray_object_unset_dimension;
spl_handler_SplFixedArray.has_dimension = spl_fixedarray_object_has_dimension;
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;
2008-06-06 23:53:43 +00:00
REGISTER_SPL_IMPLEMENTS(SplFixedArray, Iterator);
REGISTER_SPL_IMPLEMENTS(SplFixedArray, ArrayAccess);
REGISTER_SPL_IMPLEMENTS(SplFixedArray, Countable);
2008-06-06 23:53:43 +00:00
spl_ce_SplFixedArray->get_iterator = spl_fixedarray_get_iterator;
2008-06-06 23:53:43 +00:00
return SUCCESS;
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/