Back to index

php5  5.3.10
Classes | Defines | Typedefs | Functions | Variables
spl_fixedarray.c File Reference
#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"
#include "spl_exceptions.h"
#include "spl_iterators.h"

Go to the source code of this file.

Classes

struct  _spl_fixedarray
struct  _spl_fixedarray_object
struct  _spl_fixedarray_it

Defines

#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

Typedefs

typedef struct _spl_fixedarray spl_fixedarray
typedef struct
_spl_fixedarray_object 
spl_fixedarray_object
typedef struct _spl_fixedarray_it spl_fixedarray_it

Functions

static void spl_fixedarray_init (spl_fixedarray *array, long size TSRMLS_DC)
static void spl_fixedarray_resize (spl_fixedarray *array, long size TSRMLS_DC)
static void spl_fixedarray_copy (spl_fixedarray *to, spl_fixedarray *from TSRMLS_DC)
static HashTablespl_fixedarray_object_get_properties (zval *obj TSRMLS_DC)
static void spl_fixedarray_object_free_storage (void *object TSRMLS_DC)
zend_object_iterator * spl_fixedarray_get_iterator (zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC)
static zend_object_value spl_fixedarray_object_new_ex (zend_class_entry *class_type, spl_fixedarray_object **obj, zval *orig, int clone_orig TSRMLS_DC)
static zend_object_value spl_fixedarray_new (zend_class_entry *class_type TSRMLS_DC)
static zend_object_value spl_fixedarray_object_clone (zval *zobject TSRMLS_DC)
static zval ** spl_fixedarray_object_read_dimension_helper (spl_fixedarray_object *intern, zval *offset TSRMLS_DC)
static zval * spl_fixedarray_object_read_dimension (zval *object, zval *offset, int type TSRMLS_DC)
static void spl_fixedarray_object_write_dimension_helper (spl_fixedarray_object *intern, zval *offset, zval *value TSRMLS_DC)
static void spl_fixedarray_object_write_dimension (zval *object, zval *offset, zval *value TSRMLS_DC)
static void spl_fixedarray_object_unset_dimension_helper (spl_fixedarray_object *intern, zval *offset TSRMLS_DC)
static void spl_fixedarray_object_unset_dimension (zval *object, zval *offset TSRMLS_DC)
static int spl_fixedarray_object_has_dimension_helper (spl_fixedarray_object *intern, zval *offset, int check_empty TSRMLS_DC)
static int spl_fixedarray_object_has_dimension (zval *object, zval *offset, int check_empty TSRMLS_DC)
static int spl_fixedarray_object_count_elements (zval *object, long *count TSRMLS_DC)
 SPL_METHOD (SplFixedArray, __construct)
 SPL_METHOD (SplFixedArray, count)
 SPL_METHOD (SplFixedArray, toArray)
 SPL_METHOD (SplFixedArray, fromArray)
 SPL_METHOD (SplFixedArray, getSize)
 SPL_METHOD (SplFixedArray, setSize)
 SPL_METHOD (SplFixedArray, offsetExists)
 SPL_METHOD (SplFixedArray, offsetGet)
 SPL_METHOD (SplFixedArray, offsetSet)
 SPL_METHOD (SplFixedArray, offsetUnset)
static void spl_fixedarray_it_dtor (zend_object_iterator *iter TSRMLS_DC)
static void spl_fixedarray_it_rewind (zend_object_iterator *iter TSRMLS_DC)
static int spl_fixedarray_it_valid (zend_object_iterator *iter TSRMLS_DC)
static void spl_fixedarray_it_get_current_data (zend_object_iterator *iter, zval ***data TSRMLS_DC)
static int spl_fixedarray_it_get_current_key (zend_object_iterator *iter, char **str_key, uint *str_key_len, ulong *int_key TSRMLS_DC)
static void spl_fixedarray_it_move_forward (zend_object_iterator *iter TSRMLS_DC)
 SPL_METHOD (SplFixedArray, key)
 SPL_METHOD (SplFixedArray, next)
 SPL_METHOD (SplFixedArray, valid)
 SPL_METHOD (SplFixedArray, rewind)
 SPL_METHOD (SplFixedArray, current)
 PHP_MINIT_FUNCTION (spl_fixedarray)

Variables

zend_object_handlers spl_handler_SplFixedArray
PHPAPI zend_class_entry * spl_ce_SplFixedArray
zend_object_iterator_funcs spl_fixedarray_it_funcs
static zend_function_entry spl_funcs_SplFixedArray []

Class Documentation

struct _spl_fixedarray

Definition at line 45 of file spl_fixedarray.c.

Class Members
zval ** elements
long size
struct _spl_fixedarray_object

Definition at line 51 of file spl_fixedarray.c.

Collaboration diagram for _spl_fixedarray_object:
Class Members
spl_fixedarray * array
zend_class_entry * ce_get_iterator
int current
int flags
zend_function * fptr_count
zend_function * fptr_offset_del
zend_function * fptr_offset_get
zend_function * fptr_offset_has
zend_function * fptr_offset_set
zval * retval
zend_object std
struct _spl_fixedarray_it

Definition at line 66 of file spl_fixedarray.c.

Collaboration diagram for _spl_fixedarray_it:
Class Members
zend_user_iterator intern
spl_fixedarray_object * object

Define Documentation

#define SPL_FIXEDARRAY_OVERLOADED_CURRENT   0x0008

Definition at line 75 of file spl_fixedarray.c.

#define SPL_FIXEDARRAY_OVERLOADED_KEY   0x0004

Definition at line 74 of file spl_fixedarray.c.

#define SPL_FIXEDARRAY_OVERLOADED_NEXT   0x0010

Definition at line 76 of file spl_fixedarray.c.

#define SPL_FIXEDARRAY_OVERLOADED_REWIND   0x0001

Definition at line 72 of file spl_fixedarray.c.

#define SPL_FIXEDARRAY_OVERLOADED_VALID   0x0002

Definition at line 73 of file spl_fixedarray.c.


Typedef Documentation


Function Documentation

static void spl_fixedarray_copy ( spl_fixedarray to,
spl_fixedarray *from  TSRMLS_DC 
) [static]

Definition at line 136 of file spl_fixedarray.c.

{
       int i;
       for (i = 0; i < from->size; i++) {
              if (from->elements[i]) {
                     Z_ADDREF_P(from->elements[i]);
                     to->elements[i] = from->elements[i];
              } else {
                     to->elements[i] = NULL;
              }
       }
}

Here is the caller graph for this function:

zend_object_iterator * spl_fixedarray_get_iterator ( zend_class_entry *  ce,
zval *  object,
int by_ref  TSRMLS_DC 
)

Definition at line 1012 of file spl_fixedarray.c.

{
       spl_fixedarray_it      *iterator;
       spl_fixedarray_object  *fixedarray_object = (spl_fixedarray_object*)zend_object_store_get_object(object TSRMLS_CC);

       if (by_ref) {
              zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0 TSRMLS_CC);
              return NULL;
       }

       Z_ADDREF_P(object);

       iterator                     = emalloc(sizeof(spl_fixedarray_it));
       iterator->intern.it.data     = (void*)object;
       iterator->intern.it.funcs    = &spl_fixedarray_it_funcs;
       iterator->intern.ce          = ce;
       iterator->intern.value       = NULL;
       iterator->object             = fixedarray_object;

       return (zend_object_iterator*)iterator;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void spl_fixedarray_init ( spl_fixedarray array,
long size  TSRMLS_DC 
) [static]

Definition at line 78 of file spl_fixedarray.c.

{
       if (size > 0) {
              array->size = 0; /* reset size in case ecalloc() fails */
              array->elements = ecalloc(size, sizeof(zval *));
              array->size = size;
       } else {
              array->elements = NULL;
              array->size = 0;
       }
}

Here is the caller graph for this function:

static void spl_fixedarray_it_dtor ( zend_object_iterator *iter  TSRMLS_DC) [static]

Definition at line 828 of file spl_fixedarray.c.

{
       spl_fixedarray_it  *iterator = (spl_fixedarray_it *)iter;

       zend_user_it_invalidate_current(iter TSRMLS_CC);
       zval_ptr_dtor((zval**)&iterator->intern.it.data);

       efree(iterator);
}

Here is the call graph for this function:

static void spl_fixedarray_it_get_current_data ( zend_object_iterator *  iter,
zval ***data  TSRMLS_DC 
) [static]

Definition at line 869 of file spl_fixedarray.c.

{
       zval                  *zindex;
       spl_fixedarray_it     *iterator = (spl_fixedarray_it *)iter;
       spl_fixedarray_object *intern   = iterator->object;

       if (intern->flags & SPL_FIXEDARRAY_OVERLOADED_CURRENT) {
              zend_user_it_get_current_data(iter, data TSRMLS_CC);
       } else {
              ALLOC_INIT_ZVAL(zindex);
              ZVAL_LONG(zindex, iterator->object->current);

              *data = spl_fixedarray_object_read_dimension_helper(intern, zindex TSRMLS_CC);

              if (*data == NULL) {
                     *data = &EG(uninitialized_zval_ptr);
              }

              zval_ptr_dtor(&zindex);
       }
}

Here is the call graph for this function:

static int spl_fixedarray_it_get_current_key ( zend_object_iterator *  iter,
char **  str_key,
uint str_key_len,
ulong *int_key  TSRMLS_DC 
) [static]

Definition at line 892 of file spl_fixedarray.c.

{
       spl_fixedarray_it     *iterator = (spl_fixedarray_it *)iter;
       spl_fixedarray_object *intern   = iterator->object;

       if (intern->flags & SPL_FIXEDARRAY_OVERLOADED_KEY) {
              return zend_user_it_get_current_key(iter, str_key, str_key_len, int_key TSRMLS_CC);
       } else {
              *int_key = (ulong) iterator->object->current;
              return HASH_KEY_IS_LONG;
       }

}

Here is the call graph for this function:

static void spl_fixedarray_it_move_forward ( zend_object_iterator *iter  TSRMLS_DC) [static]

Definition at line 907 of file spl_fixedarray.c.

Here is the call graph for this function:

static void spl_fixedarray_it_rewind ( zend_object_iterator *iter  TSRMLS_DC) [static]

Definition at line 839 of file spl_fixedarray.c.

{
       spl_fixedarray_it     *iterator = (spl_fixedarray_it *)iter;
       spl_fixedarray_object *intern   = iterator->object;

       if (intern->flags & SPL_FIXEDARRAY_OVERLOADED_REWIND) {
              zend_user_it_rewind(iter TSRMLS_CC);
       } else {
              iterator->object->current = 0;
       }
}

Here is the call graph for this function:

static int spl_fixedarray_it_valid ( zend_object_iterator *iter  TSRMLS_DC) [static]

Definition at line 852 of file spl_fixedarray.c.

{
       spl_fixedarray_it     *iterator = (spl_fixedarray_it *)iter;
       spl_fixedarray_object *intern   = iterator->object;

       if (intern->flags & SPL_FIXEDARRAY_OVERLOADED_VALID) {
              return zend_user_it_valid(iter TSRMLS_CC);
       }

       if (iterator->object->current >= 0 && iterator->object->array && iterator->object->current < iterator->object->array->size) {
              return SUCCESS;
       }

       return FAILURE;
}

Here is the call graph for this function:

static zend_object_value spl_fixedarray_new ( zend_class_entry *class_type  TSRMLS_DC) [static]

Definition at line 298 of file spl_fixedarray.c.

{
       spl_fixedarray_object *tmp;
       return spl_fixedarray_object_new_ex(class_type, &tmp, NULL, 0 TSRMLS_CC);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static zend_object_value spl_fixedarray_object_clone ( zval *zobject  TSRMLS_DC) [static]

Definition at line 305 of file spl_fixedarray.c.

{
       zend_object_value      new_obj_val;
       zend_object           *old_object;
       zend_object           *new_object;
       zend_object_handle     handle = Z_OBJ_HANDLE_P(zobject);
       spl_fixedarray_object  *intern;

       old_object  = zend_objects_get_address(zobject TSRMLS_CC);
       new_obj_val = spl_fixedarray_object_new_ex(old_object->ce, &intern, zobject, 1 TSRMLS_CC);
       new_object  = &intern->std;

       zend_objects_clone_members(new_object, new_obj_val, old_object, handle TSRMLS_CC);

       return new_obj_val;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int spl_fixedarray_object_count_elements ( zval *  object,
long *count  TSRMLS_DC 
) [static]

Definition at line 527 of file spl_fixedarray.c.

{
       spl_fixedarray_object *intern;
       
       intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);
       if (intern->fptr_count) {
              zval *rv;
              zend_call_method_with_0_params(&object, intern->std.ce, &intern->fptr_count, "count", &rv);
              if (rv) {
                     zval_ptr_dtor(&intern->retval);
                     MAKE_STD_ZVAL(intern->retval);
                     ZVAL_ZVAL(intern->retval, rv, 1, 1);
                     convert_to_long(intern->retval);
                     *count = (long) Z_LVAL_P(intern->retval);
                     return SUCCESS;
              }
       } else if (intern->array) {
              *count = intern->array->size;
              return SUCCESS;
       }

       *count = 0;
       return SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void spl_fixedarray_object_free_storage ( void *object  TSRMLS_DC) [static]

Definition at line 178 of file spl_fixedarray.c.

{
       spl_fixedarray_object *intern = (spl_fixedarray_object *)object;
       long i;

       if (intern->array) {
              for (i = 0; i < intern->array->size; i++) {
                     if (intern->array->elements[i]) {
                            zval_ptr_dtor(&(intern->array->elements[i]));
                     }
              }

              if (intern->array->size > 0 && intern->array->elements) {
                     efree(intern->array->elements);
              }
              efree(intern->array);
       }

       zend_object_std_dtor(&intern->std TSRMLS_CC);
       zval_ptr_dtor(&intern->retval);

       efree(object);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static HashTable* spl_fixedarray_object_get_properties ( zval *obj  TSRMLS_DC) [static]

Definition at line 150 of file spl_fixedarray.c.

{
       spl_fixedarray_object *intern  = (spl_fixedarray_object*)zend_object_store_get_object(obj TSRMLS_CC);
       int  i = 0;

       if (intern->array && !GC_G(gc_active)) {
              int j = zend_hash_num_elements(intern->std.properties);

              for (i = 0; i < intern->array->size; i++) {
                     if (intern->array->elements[i]) {
                            zend_hash_index_update(intern->std.properties, i, (void *)&intern->array->elements[i], sizeof(zval *), NULL);
                            Z_ADDREF_P(intern->array->elements[i]);
                     } else {
                            zend_hash_index_update(intern->std.properties, i, (void *)&EG(uninitialized_zval_ptr), sizeof(zval *), NULL);
                            Z_ADDREF_P(EG(uninitialized_zval_ptr));
                     }
              }
              if (j > intern->array->size) {
                     for (i = intern->array->size; i < j; ++i) {
                            zend_hash_index_del(intern->std.properties, i);
                     }
              }
       }

       return intern->std.properties;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int spl_fixedarray_object_has_dimension ( zval *  object,
zval *  offset,
int check_empty  TSRMLS_DC 
) [static]

Definition at line 503 of file spl_fixedarray.c.

{
       spl_fixedarray_object *intern;

       intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);

       if (intern->fptr_offset_get) {
              zval *rv;
              SEPARATE_ARG_IF_REF(offset);
              zend_call_method_with_1_params(&object, intern->std.ce, &intern->fptr_offset_has, "offsetExists", &rv, offset);
              zval_ptr_dtor(&offset);
              if (rv) {
                     zval_ptr_dtor(&intern->retval);
                     MAKE_STD_ZVAL(intern->retval);
                     ZVAL_ZVAL(intern->retval, rv, 1, 1);
                     return zend_is_true(intern->retval);
              }
              return 0;
       }

       return spl_fixedarray_object_has_dimension_helper(intern, offset, check_empty TSRMLS_CC);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int spl_fixedarray_object_has_dimension_helper ( spl_fixedarray_object intern,
zval *  offset,
int check_empty  TSRMLS_DC 
) [inline, static]

Definition at line 472 of file spl_fixedarray.c.

{
       long index;
       int retval;
       
       if (Z_TYPE_P(offset) != IS_LONG) {
              index = spl_offset_convert_to_long(offset TSRMLS_CC);
       } else {
              index = Z_LVAL_P(offset);
       }
       
       if (index < 0 || intern->array == NULL || index >= intern->array->size) {
              retval = 0;
       } else {
              if (!intern->array->elements[index]) {
                     retval = 0;
              } else if (check_empty) {
                     if (zend_is_true(intern->array->elements[index])) {
                            retval = 1;
                     } else {
                            retval = 0;
                     }
              } else { /* != NULL and !check_empty */
                     retval = 1;
              }
       }

       return retval;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static zend_object_value spl_fixedarray_object_new_ex ( zend_class_entry *  class_type,
spl_fixedarray_object **  obj,
zval *  orig,
int clone_orig  TSRMLS_DC 
) [static]

Definition at line 205 of file spl_fixedarray.c.

{
       zend_object_value     retval;
       spl_fixedarray_object *intern;
       zval                 *tmp;
       zend_class_entry     *parent = class_type;
       int                   inherited = 0;

       intern = ecalloc(1, sizeof(spl_fixedarray_object));
       *obj = intern;
       ALLOC_INIT_ZVAL(intern->retval);

       zend_object_std_init(&intern->std, class_type TSRMLS_CC);
       zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));

       intern->current = 0;
       intern->flags = 0;

       if (orig && clone_orig) {
              spl_fixedarray_object *other = (spl_fixedarray_object*)zend_object_store_get_object(orig TSRMLS_CC);
              intern->ce_get_iterator = other->ce_get_iterator;

              intern->array = emalloc(sizeof(spl_fixedarray));
              spl_fixedarray_init(intern->array, other->array->size TSRMLS_CC);
              spl_fixedarray_copy(intern->array, other->array TSRMLS_CC);
       }

       while (parent) {
              if (parent == spl_ce_SplFixedArray) {
                     retval.handlers = &spl_handler_SplFixedArray;
                     class_type->get_iterator = spl_fixedarray_get_iterator;
                     break;
              }

              parent = parent->parent;
              inherited = 1;
       }

       retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, spl_fixedarray_object_free_storage, NULL TSRMLS_CC);

       if (!parent) { /* this must never happen */
              php_error_docref(NULL TSRMLS_CC, E_COMPILE_ERROR, "Internal compiler error, Class is not child of SplFixedArray");
       }
       if (!class_type->iterator_funcs.zf_current) {
              zend_hash_find(&class_type->function_table, "rewind",  sizeof("rewind"),  (void **) &class_type->iterator_funcs.zf_rewind);
              zend_hash_find(&class_type->function_table, "valid",   sizeof("valid"),   (void **) &class_type->iterator_funcs.zf_valid);
              zend_hash_find(&class_type->function_table, "key",     sizeof("key"),     (void **) &class_type->iterator_funcs.zf_key);
              zend_hash_find(&class_type->function_table, "current", sizeof("current"), (void **) &class_type->iterator_funcs.zf_current);
              zend_hash_find(&class_type->function_table, "next",    sizeof("next"),    (void **) &class_type->iterator_funcs.zf_next);
       }
       if (inherited) {
              if (class_type->iterator_funcs.zf_rewind->common.scope  != parent) { 
                     intern->flags |= SPL_FIXEDARRAY_OVERLOADED_REWIND;
              }
              if (class_type->iterator_funcs.zf_valid->common.scope   != parent) { 
                     intern->flags |= SPL_FIXEDARRAY_OVERLOADED_VALID;
              }
              if (class_type->iterator_funcs.zf_key->common.scope     != parent) { 
                     intern->flags |= SPL_FIXEDARRAY_OVERLOADED_KEY;
              }
              if (class_type->iterator_funcs.zf_current->common.scope != parent) { 
                     intern->flags |= SPL_FIXEDARRAY_OVERLOADED_CURRENT;
              }
              if (class_type->iterator_funcs.zf_next->common.scope    != parent) { 
                     intern->flags |= SPL_FIXEDARRAY_OVERLOADED_NEXT;
              }

              zend_hash_find(&class_type->function_table, "offsetget",    sizeof("offsetget"),    (void **) &intern->fptr_offset_get);
              if (intern->fptr_offset_get->common.scope == parent) {
                     intern->fptr_offset_get = NULL;
              }
              zend_hash_find(&class_type->function_table, "offsetset",    sizeof("offsetset"),    (void **) &intern->fptr_offset_set);
              if (intern->fptr_offset_set->common.scope == parent) {
                     intern->fptr_offset_set = NULL;
              }
              zend_hash_find(&class_type->function_table, "offsetexists", sizeof("offsetexists"), (void **) &intern->fptr_offset_has);
              if (intern->fptr_offset_has->common.scope == parent) {
                     intern->fptr_offset_has = NULL;
              }
              zend_hash_find(&class_type->function_table, "offsetunset",  sizeof("offsetunset"),  (void **) &intern->fptr_offset_del);
              if (intern->fptr_offset_del->common.scope == parent) {
                     intern->fptr_offset_del = NULL;
              }
              zend_hash_find(&class_type->function_table, "count",        sizeof("count"),        (void **) &intern->fptr_count);
              if (intern->fptr_count->common.scope == parent) {
                     intern->fptr_count = NULL;
              }
       }

       return retval;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static zval* spl_fixedarray_object_read_dimension ( zval *  object,
zval *  offset,
int type  TSRMLS_DC 
) [static]

Definition at line 351 of file spl_fixedarray.c.

{
       spl_fixedarray_object *intern;
       zval **retval;

       intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);

       if (intern->fptr_offset_get) {
              zval *rv;
              SEPARATE_ARG_IF_REF(offset);
              zend_call_method_with_1_params(&object, intern->std.ce, &intern->fptr_offset_get, "offsetGet", &rv, offset);
              zval_ptr_dtor(&offset);
              if (rv) {
                     zval_ptr_dtor(&intern->retval);
                     MAKE_STD_ZVAL(intern->retval);
                     ZVAL_ZVAL(intern->retval, rv, 1, 1);
                     return intern->retval;
              }
              return EG(uninitialized_zval_ptr);
       }

       retval = spl_fixedarray_object_read_dimension_helper(intern, offset TSRMLS_CC);
       if (retval) {
              return *retval;
       }
       return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static zval** spl_fixedarray_object_read_dimension_helper ( spl_fixedarray_object intern,
zval *offset  TSRMLS_DC 
) [inline, static]

Definition at line 323 of file spl_fixedarray.c.

{
       long index;

       /* we have to return NULL on error here to avoid memleak because of 
        * ZE duplicating uninitialized_zval_ptr */
       if (!offset) {
              zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0 TSRMLS_CC);
              return NULL;
       }

       if (Z_TYPE_P(offset) != IS_LONG) {
              index = spl_offset_convert_to_long(offset TSRMLS_CC);
       } else {
              index = Z_LVAL_P(offset);
       }
       
       if (index < 0 || intern->array == NULL || index >= intern->array->size) {
              zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0 TSRMLS_CC);
              return NULL;
       } else if(!intern->array->elements[index]) {
              return NULL;
       } else {
              return &intern->array->elements[index];
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void spl_fixedarray_object_unset_dimension ( zval *  object,
zval *offset  TSRMLS_DC 
) [static]

Definition at line 454 of file spl_fixedarray.c.

{
       spl_fixedarray_object *intern;

       intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);

       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);
              return;
       }

       spl_fixedarray_object_unset_dimension_helper(intern, offset TSRMLS_CC);

}

Here is the call graph for this function:

Here is the caller graph for this function:

static void spl_fixedarray_object_unset_dimension_helper ( spl_fixedarray_object intern,
zval *offset  TSRMLS_DC 
) [inline, static]

Definition at line 432 of file spl_fixedarray.c.

{
       long index;
       
       if (Z_TYPE_P(offset) != IS_LONG) {
              index = spl_offset_convert_to_long(offset TSRMLS_CC);
       } else {
              index = Z_LVAL_P(offset);
       }
       
       if (index < 0 || intern->array == NULL || index >= intern->array->size) {
              zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0 TSRMLS_CC);
              return;
       } else {
              if (intern->array->elements[index]) {
                     zval_ptr_dtor(&(intern->array->elements[index]));
              }
              intern->array->elements[index] = NULL;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void spl_fixedarray_object_write_dimension ( zval *  object,
zval *  offset,
zval *value  TSRMLS_DC 
) [static]

Definition at line 409 of file spl_fixedarray.c.

{
       spl_fixedarray_object *intern;

       intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);

       if (intern->fptr_offset_set) {
              if (!offset) {
                     ALLOC_INIT_ZVAL(offset);
              } else {
                     SEPARATE_ARG_IF_REF(offset);
              }
              SEPARATE_ARG_IF_REF(value);
              zend_call_method_with_2_params(&object, intern->std.ce, &intern->fptr_offset_set, "offsetSet", NULL, offset, value);
              zval_ptr_dtor(&value);
              zval_ptr_dtor(&offset);
              return;
       }

       spl_fixedarray_object_write_dimension_helper(intern, offset, value TSRMLS_CC);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void spl_fixedarray_object_write_dimension_helper ( spl_fixedarray_object intern,
zval *  offset,
zval *value  TSRMLS_DC 
) [inline, static]

Definition at line 380 of file spl_fixedarray.c.

{
       long index;

       if (!offset) {
              /* '$array[] = value' syntax is not supported */
              zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0 TSRMLS_CC);
              return;
       }

       if (Z_TYPE_P(offset) != IS_LONG) {
              index = spl_offset_convert_to_long(offset TSRMLS_CC);
       } else {
              index = Z_LVAL_P(offset);
       }

       if (index < 0 || intern->array == NULL || index >= intern->array->size) {
              zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0 TSRMLS_CC);
              return;
       } else {
              if (intern->array->elements[index]) {
                     zval_ptr_dtor(&(intern->array->elements[index]));
              }
              SEPARATE_ARG_IF_REF(value);
              intern->array->elements[index] = value;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void spl_fixedarray_resize ( spl_fixedarray array,
long size  TSRMLS_DC 
) [static]

Definition at line 91 of file spl_fixedarray.c.

{
       if (size == array->size) {
              /* nothing to do */
              return;
       }

       /* first initialization */
       if (array->size == 0) {
              spl_fixedarray_init(array, size TSRMLS_CC);
              return;
       }

       /* clearing the array */
       if (size == 0) {
              long i;

              for (i = 0; i < array->size; i++) {
                     if (array->elements[i]) {
                            zval_ptr_dtor(&(array->elements[i]));
                     }
              }

              if (array->elements) {
                     efree(array->elements);
                     array->elements = NULL;
              }
       } else if (size > array->size) {
              array->elements = erealloc(array->elements, sizeof(zval *) * size);
              memset(array->elements + array->size, '\0', sizeof(zval *) * (size - array->size));
       } else { /* size < array->size */
              long i;

              for (i = size; i < array->size; i++) {
                     if (array->elements[i]) {
                            zval_ptr_dtor(&(array->elements[i]));
                     }
              }
              array->elements = erealloc(array->elements, sizeof(zval *) * size);
       }

       array->size = size;
}

Here is the call graph for this function:

Here is the caller graph for this function:

SPL_METHOD ( SplFixedArray  ,
__construct   
)

Definition at line 555 of file spl_fixedarray.c.

{
       zval *object = getThis();
       spl_fixedarray_object *intern;
       long size = 0;

       if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &size)) {
              return;
       }

       if (size < 0) {
              zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "array size cannot be less than zero");
              return;
       }

       intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);

       if (intern->array) {
              /* called __construct() twice, bail out */
              return;
       }

       intern->array = emalloc(sizeof(spl_fixedarray));
       spl_fixedarray_init(intern->array, size TSRMLS_CC);
}

Here is the call graph for this function:

SPL_METHOD ( SplFixedArray  ,
count   
)

Definition at line 584 of file spl_fixedarray.c.

{
       zval *object = getThis();
       spl_fixedarray_object *intern;

       if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "")) {
              return;
       }

       intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);
       if (intern->array) {
              RETURN_LONG(intern->array->size);
       }
       RETURN_LONG(0);
}

Here is the call graph for this function:

SPL_METHOD ( SplFixedArray  ,
toArray   
)

Definition at line 603 of file spl_fixedarray.c.

{
       spl_fixedarray_object *intern;
       zval *ret, *tmp;
       HashTable *ret_ht, *obj_ht;

       if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "")) {
              return;
       }

       intern = (spl_fixedarray_object *)zend_object_store_get_object(getThis() TSRMLS_CC);

       ALLOC_HASHTABLE(ret_ht);
       zend_hash_init(ret_ht, 0, NULL, ZVAL_PTR_DTOR, 0);
       ALLOC_INIT_ZVAL(ret);
       Z_TYPE_P(ret) = IS_ARRAY;
       obj_ht = spl_fixedarray_object_get_properties(getThis() TSRMLS_CC);
       zend_hash_copy(ret_ht, obj_ht, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
       Z_ARRVAL_P(ret) = ret_ht;

       RETURN_ZVAL(ret, 1, 1);
}

Here is the call graph for this function:

SPL_METHOD ( SplFixedArray  ,
fromArray   
)

Definition at line 629 of file spl_fixedarray.c.

{
       zval *data;
       spl_fixedarray *array;
       spl_fixedarray_object *intern;
       int num;
       zend_bool save_indexes = 1;

       if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|b", &data, &save_indexes)) {
              return;
       }

       array = ecalloc(1, sizeof(*array));
       num = zend_hash_num_elements(Z_ARRVAL_P(data));
       
       if (num > 0 && save_indexes) {
              zval **element, *value;
              char *str_index;
              ulong num_index, max_index = 0;
              long tmp;

              for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(data));
                     zend_hash_get_current_data(Z_ARRVAL_P(data), (void **) &element) == SUCCESS;
                     zend_hash_move_forward(Z_ARRVAL_P(data))
                     ) {
                     if (zend_hash_get_current_key(Z_ARRVAL_P(data), &str_index, &num_index, 0) != HASH_KEY_IS_LONG || (long)num_index < 0) {
                            efree(array);
                            zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "array must contain only positive integer keys");
                            return;
                     }

                     if (num_index > max_index) {
                            max_index = num_index;
                     }
              }

              tmp = max_index + 1;
              if (tmp <= 0) {
                     efree(array);
                     zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "integer overflow detected");
                     return;
              }
              spl_fixedarray_init(array, tmp TSRMLS_CC);

              for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(data));
                     zend_hash_get_current_data(Z_ARRVAL_P(data), (void **) &element) == SUCCESS;
                     zend_hash_move_forward(Z_ARRVAL_P(data))
                     ) {
                     
                     zend_hash_get_current_key(Z_ARRVAL_P(data), &str_index, &num_index, 0);
                     value = *element;

                     SEPARATE_ARG_IF_REF(value);
                     array->elements[num_index] = value;
              }

       } else if (num > 0 && !save_indexes) {
              zval **element, *value;
              long i = 0;
              
              spl_fixedarray_init(array, num TSRMLS_CC);
              
              for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(data));
                     zend_hash_get_current_data(Z_ARRVAL_P(data), (void **) &element) == SUCCESS;
                     zend_hash_move_forward(Z_ARRVAL_P(data))
                     ) {
                     
                     value = *element;

                     SEPARATE_ARG_IF_REF(value);
                     array->elements[i] = value;
                     i++;
              }
       } else {
              spl_fixedarray_init(array, 0 TSRMLS_CC);
       }

       object_init_ex(return_value, spl_ce_SplFixedArray);
       Z_TYPE_P(return_value) = IS_OBJECT;

       intern = (spl_fixedarray_object *)zend_object_store_get_object(return_value TSRMLS_CC);
       intern->array = array;
}

Here is the call graph for this function:

SPL_METHOD ( SplFixedArray  ,
getSize   
)

Definition at line 716 of file spl_fixedarray.c.

{
       zval *object = getThis();
       spl_fixedarray_object *intern;

       if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "")) {
              return;
       }

       intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);
       if (intern->array) {
              RETURN_LONG(intern->array->size);
       }
       RETURN_LONG(0);
}

Here is the call graph for this function:

SPL_METHOD ( SplFixedArray  ,
setSize   
)

Definition at line 735 of file spl_fixedarray.c.

{
       zval *object = getThis();
       spl_fixedarray_object *intern;
       long size;

       if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &size)) {
              return;
       }

       if (size < 0) {
              zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "array size cannot be less than zero");
              return;
       }

       intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);
       if (!intern->array) {
              intern->array = ecalloc(1, sizeof(spl_fixedarray));
       }

       spl_fixedarray_resize(intern->array, size TSRMLS_CC);
       RETURN_TRUE;
}

Here is the call graph for this function:

SPL_METHOD ( SplFixedArray  ,
offsetExists   
)

Definition at line 762 of file spl_fixedarray.c.

Here is the call graph for this function:

SPL_METHOD ( SplFixedArray  ,
offsetGet   
)

Definition at line 778 of file spl_fixedarray.c.

{
       zval                  *zindex, **value_pp;
       spl_fixedarray_object  *intern;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zindex) == FAILURE) {
              return;
       }

       intern    = (spl_fixedarray_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
       value_pp  = spl_fixedarray_object_read_dimension_helper(intern, zindex TSRMLS_CC);

       if (value_pp) {
              RETURN_ZVAL(*value_pp, 1, 0);
       }
       RETURN_NULL();
} /* }}} */

Here is the call graph for this function:

SPL_METHOD ( SplFixedArray  ,
offsetSet   
)

Definition at line 798 of file spl_fixedarray.c.

{
       zval                  *zindex, *value;
       spl_fixedarray_object  *intern;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &zindex, &value) == FAILURE) {
              return;
       }

       intern = (spl_fixedarray_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
       spl_fixedarray_object_write_dimension_helper(intern, zindex, value TSRMLS_CC);

} /* }}} */

Here is the call graph for this function:

SPL_METHOD ( SplFixedArray  ,
offsetUnset   
)

Definition at line 814 of file spl_fixedarray.c.

Here is the call graph for this function:

SPL_METHOD ( SplFixedArray  ,
key   
)

Definition at line 923 of file spl_fixedarray.c.

Here is the call graph for this function:

SPL_METHOD ( SplFixedArray  ,
next   
)

Definition at line 937 of file spl_fixedarray.c.

Here is the call graph for this function:

SPL_METHOD ( SplFixedArray  ,
valid   
)

Definition at line 951 of file spl_fixedarray.c.

Here is the call graph for this function:

SPL_METHOD ( SplFixedArray  ,
rewind   
)

Definition at line 965 of file spl_fixedarray.c.

Here is the call graph for this function:

SPL_METHOD ( SplFixedArray  ,
current   
)

Definition at line 979 of file spl_fixedarray.c.

{
       zval                 *zindex, **value_pp;
       spl_fixedarray_object *intern  = (spl_fixedarray_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
       
       if (zend_parse_parameters_none() == FAILURE) {
              return;
       }

       ALLOC_INIT_ZVAL(zindex);
       ZVAL_LONG(zindex, intern->current);

       value_pp  = spl_fixedarray_object_read_dimension_helper(intern, zindex TSRMLS_CC);

       zval_ptr_dtor(&zindex);

       if (value_pp) {
              RETURN_ZVAL(*value_pp, 1, 0);
       }
       RETURN_NULL();
}

Here is the call graph for this function:


Variable Documentation

PHPAPI zend_class_entry* spl_ce_SplFixedArray

Definition at line 39 of file spl_fixedarray.c.

Initial value:

Definition at line 1060 of file spl_fixedarray.c.

zend_object_handlers spl_handler_SplFixedArray

Definition at line 38 of file spl_fixedarray.c.