Back to index

php5  5.3.10
Classes | Defines | Typedefs | Functions
zend_objects_API.h File Reference
#include "zend.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _zend_object_store_bucket
union  _zend_object_store_bucket::_store_bucket
struct  _zend_object_store_bucket::_store_bucket::_store_object
struct  _zend_objects_store
struct  _zend_object_store_bucket::_store_bucket.free_list

Defines

#define ZEND_OBJECTS_STORE_HANDLERS   zend_objects_store_add_ref, zend_objects_store_del_ref, zend_objects_store_clone_obj

Typedefs

typedef void(* zend_objects_store_dtor_t )(void *object, zend_object_handle handle TSRMLS_DC)
typedef void(* zend_objects_free_object_storage_t )(void *object TSRMLS_DC)
typedef void(* zend_objects_store_clone_t )(void *object, void **object_clone TSRMLS_DC)
typedef struct
_zend_object_store_bucket 
zend_object_store_bucket
typedef struct _zend_objects_store zend_objects_store

Functions

ZEND_API void zend_objects_store_init (zend_objects_store *objects, zend_uint init_size)
ZEND_API void zend_objects_store_call_destructors (zend_objects_store *objects TSRMLS_DC)
ZEND_API void zend_objects_store_mark_destructed (zend_objects_store *objects TSRMLS_DC)
ZEND_API void zend_objects_store_destroy (zend_objects_store *objects)
ZEND_API zend_object_handle zend_objects_store_put (void *object, zend_objects_store_dtor_t dtor, zend_objects_free_object_storage_t storage, zend_objects_store_clone_t clone TSRMLS_DC)
ZEND_API void zend_objects_store_add_ref (zval *object TSRMLS_DC)
ZEND_API void zend_objects_store_del_ref (zval *object TSRMLS_DC)
ZEND_API void zend_objects_store_add_ref_by_handle (zend_object_handle handle TSRMLS_DC)
ZEND_API void zend_objects_store_del_ref_by_handle_ex (zend_object_handle handle, const zend_object_handlers *handlers TSRMLS_DC)
static void zend_objects_store_del_ref_by_handle (zend_object_handle handle TSRMLS_DC)
ZEND_API zend_uint zend_objects_store_get_refcount (zval *object TSRMLS_DC)
ZEND_API zend_object_value zend_objects_store_clone_obj (zval *object TSRMLS_DC)
ZEND_API void * zend_object_store_get_object (const zval *object TSRMLS_DC)
ZEND_API void * zend_object_store_get_object_by_handle (zend_object_handle handle TSRMLS_DC)
ZEND_API void zend_object_store_set_object (zval *zobject, void *object TSRMLS_DC)
ZEND_API void zend_object_store_ctor_failed (zval *zobject TSRMLS_DC)
ZEND_API void zend_objects_store_free_object_storage (zend_objects_store *objects TSRMLS_DC)
ZEND_API zval * zend_object_create_proxy (zval *object, zval *member TSRMLS_DC)
ZEND_API zend_object_handlers * zend_get_std_object_handlers (void)

Class Documentation

struct _zend_object_store_bucket

Definition at line 31 of file zend_objects_API.h.

Collaboration diagram for _zend_object_store_bucket:
Class Members
union _store_bucket bucket
zend_bool destructor_called
zend_bool valid
union _zend_object_store_bucket::_store_bucket

Definition at line 34 of file zend_objects_API.h.

Collaboration diagram for _zend_object_store_bucket::_store_bucket:
Class Members
struct _store_bucket free_list
struct _store_object obj
struct _zend_object_store_bucket::_store_bucket::_store_object

Definition at line 35 of file zend_objects_API.h.

Collaboration diagram for _zend_object_store_bucket::_store_bucket::_store_object:
Class Members
gc_root_buffer * buffered
zend_objects_store_clone_t clone
zend_objects_store_dtor_t dtor
zend_objects_free_object_storage_t free_storage
const zend_object_handlers * handlers
void * object
zend_uint refcount
struct _zend_objects_store

Definition at line 50 of file zend_objects_API.h.

Collaboration diagram for _zend_objects_store:
Class Members
int free_list_head
zend_object_store_bucket * object_buckets
zend_uint size
zend_uint top
struct _zend_object_store_bucket::_store_bucket.free_list

Definition at line 44 of file zend_objects_API.h.

Class Members
int next

Define Documentation

Definition at line 84 of file zend_objects_API.h.


Typedef Documentation

typedef void(* zend_objects_free_object_storage_t)(void *object TSRMLS_DC)

Definition at line 28 of file zend_objects_API.h.

typedef void(* zend_objects_store_clone_t)(void *object, void **object_clone TSRMLS_DC)

Definition at line 29 of file zend_objects_API.h.

typedef void(* zend_objects_store_dtor_t)(void *object, zend_object_handle handle TSRMLS_DC)

Definition at line 27 of file zend_objects_API.h.


Function Documentation

ZEND_API zend_object_handlers* zend_get_std_object_handlers ( void  )

Definition at line 375 of file zend_objects_API.c.

{
       return &std_object_handlers;
}

Here is the caller graph for this function:

ZEND_API zval* zend_object_create_proxy ( zval *  object,
zval *member  TSRMLS_DC 
)

Definition at line 333 of file zend_objects_API.c.

Here is the call graph for this function:

ZEND_API void zend_object_store_ctor_failed ( zval *zobject  TSRMLS_DC)

Definition at line 299 of file zend_objects_API.c.

{
       zend_object_handle handle = Z_OBJ_HANDLE_P(zobject);
       zend_object_store_bucket *obj_bucket = &EG(objects_store).object_buckets[handle];
       
       obj_bucket->bucket.obj.handlers = Z_OBJ_HT_P(zobject);;
       obj_bucket->destructor_called = 1;
}

Here is the caller graph for this function:

ZEND_API void* zend_object_store_get_object ( const zval *object  TSRMLS_DC)

Definition at line 278 of file zend_objects_API.c.

{
       return EG(objects_store).object_buckets[handle].bucket.obj.object;
}

Here is the caller graph for this function:

ZEND_API void zend_object_store_set_object ( zval *  zobject,
void *object  TSRMLS_DC 
)

Definition at line 290 of file zend_objects_API.c.

{
       zend_object_handle handle = Z_OBJ_HANDLE_P(zobject);

       EG(objects_store).object_buckets[handle].bucket.obj.object = object;
}

Here is the caller graph for this function:

ZEND_API void zend_objects_store_add_ref ( zval *object  TSRMLS_DC)

Definition at line 142 of file zend_objects_API.c.

{
       zend_object_handle handle = Z_OBJ_HANDLE_P(object);

       EG(objects_store).object_buckets[handle].bucket.obj.refcount++;
#if ZEND_DEBUG_OBJECTS
       fprintf(stderr, "Increased refcount of object id #%d\n", handle);
#endif
}

Here is the caller graph for this function:

Definition at line 155 of file zend_objects_API.c.

{
       EG(objects_store).object_buckets[handle].bucket.obj.refcount++;
}

Definition at line 45 of file zend_objects_API.c.

{
       zend_uint i = 1;

       for (i = 1; i < objects->top ; i++) {
              if (objects->object_buckets[i].valid) {
                     struct _store_object *obj = &objects->object_buckets[i].bucket.obj;

                     if (!objects->object_buckets[i].destructor_called) {
                            objects->object_buckets[i].destructor_called = 1;
                            if (obj->dtor && obj->object) {
                                   obj->refcount++;
                                   obj->dtor(obj->object, i TSRMLS_CC);
                                   obj = &objects->object_buckets[i].bucket.obj;
                                   obj->refcount--;
                            }
                     }
              }
       }
}

Here is the caller graph for this function:

ZEND_API void zend_objects_store_del_ref ( zval *object  TSRMLS_DC)
static void zend_objects_store_del_ref_by_handle ( zend_object_handle handle  TSRMLS_DC) [inline, static]

Definition at line 71 of file zend_objects_API.h.

Here is the call graph for this function:

ZEND_API void zend_objects_store_del_ref_by_handle_ex ( zend_object_handle  handle,
const zend_object_handlers *handlers  TSRMLS_DC 
)

Definition at line 181 of file zend_objects_API.c.

{
       struct _store_object *obj;
       int failure = 0;

       if (!EG(objects_store).object_buckets) {
              return;
       }

       obj = &EG(objects_store).object_buckets[handle].bucket.obj;

       /*     Make sure we hold a reference count during the destructor call
              otherwise, when the destructor ends the storage might be freed
              when the refcount reaches 0 a second time
        */
       if (EG(objects_store).object_buckets[handle].valid) {
              if (obj->refcount == 1) {
                     if (!EG(objects_store).object_buckets[handle].destructor_called) {
                            EG(objects_store).object_buckets[handle].destructor_called = 1;

                            if (obj->dtor) {
                                   if (handlers && !obj->handlers) {
                                          obj->handlers = handlers;
                                   }
                                   zend_try {
                                          obj->dtor(obj->object, handle TSRMLS_CC);
                                   } zend_catch {
                                          failure = 1;
                                   } zend_end_try();
                            }
                     }
                     
                     /* re-read the object from the object store as the store might have been reallocated in the dtor */
                     obj = &EG(objects_store).object_buckets[handle].bucket.obj;

                     if (obj->refcount == 1) {
                            GC_REMOVE_ZOBJ_FROM_BUFFER(obj);
                            if (obj->free_storage) {
                                   zend_try {
                                          obj->free_storage(obj->object TSRMLS_CC);
                                   } zend_catch {
                                          failure = 1;
                                   } zend_end_try();
                            }
                            ZEND_OBJECTS_STORE_ADD_TO_FREE_LIST();
                     }
              }
       }

       obj->refcount--;

#if ZEND_DEBUG_OBJECTS
       if (obj->refcount == 0) {
              fprintf(stderr, "Deallocated object id #%d\n", handle);
       } else {
              fprintf(stderr, "Decreased refcount of object id #%d\n", handle);
       }
#endif
       if (failure) {
              zend_bailout();
       }
}

Here is the caller graph for this function:

Definition at line 39 of file zend_objects_API.c.

{
       efree(objects->object_buckets);
       objects->object_buckets = NULL;
}

Here is the caller graph for this function:

Definition at line 80 of file zend_objects_API.c.

{
       zend_uint i = 1;

       for (i = 1; i < objects->top ; i++) {
              if (objects->object_buckets[i].valid) {
                     struct _store_object *obj = &objects->object_buckets[i].bucket.obj;

                     GC_REMOVE_ZOBJ_FROM_BUFFER(obj);

                     objects->object_buckets[i].valid = 0;
                     if (obj->free_storage) {
                            obj->free_storage(obj->object TSRMLS_CC);
                     }
                     /* Not adding to free list as we are shutting down anyway */
              }
       }
}

Here is the caller graph for this function:

ZEND_API zend_uint zend_objects_store_get_refcount ( zval *object  TSRMLS_DC)

Definition at line 135 of file zend_objects_API.c.

{
       zend_object_handle handle = Z_OBJ_HANDLE_P(object);

       return EG(objects_store).object_buckets[handle].bucket.obj.refcount;
}
ZEND_API void zend_objects_store_init ( zend_objects_store objects,
zend_uint  init_size 
)

Definition at line 30 of file zend_objects_API.c.

{
       objects->object_buckets = (zend_object_store_bucket *) emalloc(init_size * sizeof(zend_object_store_bucket));
       objects->top = 1; /* Skip 0 so that handles are true */
       objects->size = init_size;
       objects->free_list_head = -1;
       memset(&objects->object_buckets[0], 0, sizeof(zend_object_store_bucket));
}

Here is the caller graph for this function:

Definition at line 66 of file zend_objects_API.c.

{
       zend_uint i;

       if (!objects->object_buckets) {
              return;
       }
       for (i = 1; i < objects->top ; i++) {
              if (objects->object_buckets[i].valid) {
                     objects->object_buckets[i].destructor_called = 1;
              }
       }
}

Here is the caller graph for this function:

Definition at line 102 of file zend_objects_API.c.

{
       zend_object_handle handle;
       struct _store_object *obj;

       if (EG(objects_store).free_list_head != -1) {
              handle = EG(objects_store).free_list_head;
              EG(objects_store).free_list_head = EG(objects_store).object_buckets[handle].bucket.free_list.next;
       } else {
              if (EG(objects_store).top == EG(objects_store).size) {
                     EG(objects_store).size <<= 1;
                     EG(objects_store).object_buckets = (zend_object_store_bucket *) erealloc(EG(objects_store).object_buckets, EG(objects_store).size * sizeof(zend_object_store_bucket));
              }
              handle = EG(objects_store).top++;
       }
       obj = &EG(objects_store).object_buckets[handle].bucket.obj;
       EG(objects_store).object_buckets[handle].destructor_called = 0;
       EG(objects_store).object_buckets[handle].valid = 1;

       obj->refcount = 1;
       GC_OBJ_INIT(obj);
       obj->object = object;
       obj->dtor = dtor?dtor:(zend_objects_store_dtor_t)zend_objects_destroy_object;
       obj->free_storage = free_storage;
       obj->clone = clone;
       obj->handlers = NULL;

#if ZEND_DEBUG_OBJECTS
       fprintf(stderr, "Allocated object id #%d\n", handle);
#endif
       return handle;
}

Here is the call graph for this function: