diff options
author | Harald Radi <phanto@php.net> | 2002-03-15 13:10:35 +0000 |
---|---|---|
committer | Harald Radi <phanto@php.net> | 2002-03-15 13:10:35 +0000 |
commit | 720c40dd4e7ce4b2aa9c84a327b29c0ab23c7be9 (patch) | |
tree | 241bb21117a4ae99949a6fbcfe444cde98ddd705 | |
parent | 2e597b8dc8a6fff997a0ccc27f206afad3f18b19 (diff) | |
download | php-git-720c40dd4e7ce4b2aa9c84a327b29c0ab23c7be9.tar.gz |
fixed HashTable allocation
-rw-r--r-- | ext/rpc/handler.h | 8 | ||||
-rw-r--r-- | ext/rpc/php_rpc.h | 1 | ||||
-rw-r--r-- | ext/rpc/rpc.c | 128 | ||||
-rw-r--r-- | ext/rpc/rpc.h | 11 |
4 files changed, 129 insertions, 19 deletions
diff --git a/ext/rpc/handler.h b/ext/rpc/handler.h index cb13c90a49..02c0b5e83c 100644 --- a/ext/rpc/handler.h +++ b/ext/rpc/handler.h @@ -11,6 +11,7 @@ #define RPC_REGISTER_HANDLERS(layer) zend_class_entry layer##_class_entry; \ rpc_object_handlers layer##object_handlers; + typedef struct _rpc_object_handlers { int i; } rpc_object_handlers; @@ -22,4 +23,11 @@ typedef struct _rpc_handler_entry { zend_class_entry *ce; } rpc_handler_entry; +typedef struct _rpc_internal { + zend_class_entry *ce; + rpc_object_handlers **handlers; + void *data; + int refcount; +} rpc_internal; + #endif /* HANDLER_H */
\ No newline at end of file diff --git a/ext/rpc/php_rpc.h b/ext/rpc/php_rpc.h index a989772a4b..e0ae67f89e 100644 --- a/ext/rpc/php_rpc.h +++ b/ext/rpc/php_rpc.h @@ -23,6 +23,7 @@ PHP_MINFO_FUNCTION(rpc); ZEND_BEGIN_MODULE_GLOBALS(rpc) zend_object_handle handle; HashTable *instance; + HashTable *handlers; ZEND_END_MODULE_GLOBALS(rpc) #ifdef ZTS diff --git a/ext/rpc/rpc.c b/ext/rpc/rpc.c index 2d9c515695..4327f359f9 100644 --- a/ext/rpc/rpc.c +++ b/ext/rpc/rpc.c @@ -7,10 +7,14 @@ #include "ext/standard/info.h" #include "php_rpc.h" +#include "rpc.h" #include "layer.h" ZEND_DECLARE_MODULE_GLOBALS(rpc) +static void rpc_globals_ctor(zend_rpc_globals *rpc_globals TSRMLS_DC); +static void rpc_instance_dtor(void *pDest); +static void rpc_handlers_dtor(void *pDest); static zend_object_value rpc_create_object(zend_class_entry *class_type TSRMLS_DC); /* object handler */ @@ -34,9 +38,8 @@ static int rpc_get_classname(zval *object, char **class_name, zend_uint *class_n static int rpc_compare(zval *object1, zval *object2 TSRMLS_DC); /**/ -ZEND_FUNCTION(rpc_ctor); +ZEND_FUNCTION(CONSTRUCTOR); -static int le_rpc; static zend_object_handlers rpc_handlers = { rpc_add_ref, rpc_del_ref, @@ -81,6 +84,8 @@ zend_module_entry rpc_module_entry = { }; /* }}} */ +static HashTable *instance; + #ifdef COMPILE_DL_RPC ZEND_GET_MODULE(rpc) #endif @@ -92,12 +97,16 @@ PHP_INI_BEGIN() PHP_INI_END() /* }}} */ -/* {{{ php_rpc_init_globals - */ -static void php_rpc_init_globals(zend_rpc_globals *rpc_globals) +static void rpc_globals_ctor(zend_rpc_globals *rpc_globals TSRMLS_DC) { + RPC_G(handle) = 0; + + RPC_G(handlers) = (HashTable *) pemalloc(sizeof(HashTable), TRUE); + RPC_G(instance) = (HashTable *) pemalloc(sizeof(HashTable), TRUE); + + zend_hash_init(RPC_G(handlers), 0, NULL, NULL, TRUE); + zend_hash_init(RPC_G(instance), 0, NULL, rpc_instance_dtor, TRUE); } -/* }}} */ /* {{{ PHP_MINIT_FUNCTION */ @@ -105,13 +114,9 @@ PHP_MINIT_FUNCTION(rpc) { int i; - ZEND_INIT_MODULE_GLOBALS(rpc, php_rpc_init_globals, NULL); + ZEND_INIT_MODULE_GLOBALS(rpc, rpc_globals_ctor, NULL); REGISTER_INI_ENTRIES(); - RPC_G(handle) = 0; - ALLOC_HASHTABLE(RPC_G(instance)); - zend_hash_init(RPC_G(instance), 0, NULL, ZVAL_PTR_DTOR, 0); - for (i=0; i < (sizeof(handler_entries) / sizeof(rpc_handler_entry)); i++) { handler_entries[i].rpc_handler_init(); @@ -125,6 +130,7 @@ PHP_MINIT_FUNCTION(rpc) handler_entries[i].ce->create_object = rpc_create_object; zend_register_internal_class(handler_entries[i].ce TSRMLS_CC); + zend_hash_add(RPC_G(handlers), handler_entries[i].name, strlen(handler_entries[i].name), &(handler_entries[i].handlers), sizeof(rpc_object_handlers *), NULL); } return SUCCESS; @@ -135,6 +141,9 @@ PHP_MINIT_FUNCTION(rpc) */ PHP_MSHUTDOWN_FUNCTION(rpc) { + zend_hash_destroy(RPC_G(handlers)); + zend_hash_destroy(RPC_G(instance)); + UNREGISTER_INI_ENTRIES(); return SUCCESS; } @@ -152,99 +161,180 @@ PHP_MINFO_FUNCTION(rpc) } /* }}} */ +static void rpc_instance_dtor(void *pDest) +{ + rpc_internal **intern; + + intern = (rpc_internal **) pDest; + + /* destruct intern */ +} + static zend_object_value rpc_create_object(zend_class_entry *class_type TSRMLS_DC) { zend_object_value *zov; + rpc_internal *intern; - zov = (zend_object_value*) emalloc(sizeof(zend_object_value)); + zov = (zend_object_value*) pemalloc(sizeof(zend_object_value), TRUE); + intern = (rpc_internal *) pemalloc(sizeof(rpc_internal), TRUE); + zov->handle = RPC_G(handle)++; zov->handlers = &rpc_handlers; - zend_hash_index_update_or_next_insert(RPC_G(instance), zov->handle, class_type, sizeof(zend_class_entry),NULL, HASH_ADD); + intern->ce = class_type; + intern->refcount = 0; + intern->data = NULL; + zend_hash_find(RPC_G(handlers), class_type->name, class_type->name_length, (void **) &(intern->handlers)); + + zend_hash_index_update_or_next_insert(RPC_G(instance), zov->handle, &intern, sizeof(rpc_internal *), NULL, HASH_ADD); return *zov; } +/**/ static void rpc_add_ref(zval *object) { + ZVAL_ADDREF(object); } static void rpc_del_ref(zval *object) { + if (ZVAL_REFCOUNT(object) > 0) { + ZVAL_DELREF(object); + } + + if (ZVAL_REFCOUNT(object) == 0) { + rpc_delete(object); + } } static void rpc_delete(zval *object) { + TSRMLS_FETCH(); + GET_INTERNAL(intern); + + rpc_instance_dtor(intern); } static zend_object_value rpc_clone(zval *object) { +// TSRMLS_FETCH(); +// GET_INTERNAL(intern); + + /* FIXME */ + return object->value.obj; } static zval* rpc_read(zval *object, zval *member, int type TSRMLS_DC) { +// GET_INTERNAL(intern); + + /* FIXME */ + return NULL; } static void rpc_write(zval *object, zval *member, zval *value TSRMLS_DC) { +// GET_INTERNAL(intern); } static zval** rpc_get_property(zval *object, zval *member TSRMLS_DC) { +// GET_INTERNAL(intern); + + /* FIXME */ + return NULL; } static zval **rpc_get_property_zval(zval *object, zval *member TSRMLS_DC) { +// GET_INTERNAL(intern); + + /* FIXME */ + return NULL; } static zval* rpc_get(zval *property TSRMLS_DC) { +// GET_INTERNAL(intern); + + /* FIXME */ + return NULL; } static void rpc_set(zval **property, zval *value TSRMLS_DC) { +// GET_INTERNAL(intern); } static int rpc_has_property(zval *object, zval *member, int check_empty TSRMLS_DC) { +// GET_INTERNAL(intern); + + /* FIXME */ + return FAILURE; } static void rpc_unset_property(zval *object, zval *member TSRMLS_DC) { +// GET_INTERNAL(intern); } static HashTable* rpc_get_properties(zval *object TSRMLS_DC) { +// GET_INTERNAL(intern); + + /* FIXME */ + return NULL; } static union _zend_function* rpc_get_method(zval *object, char *method, int method_len TSRMLS_DC) { +// GET_INTERNAL(intern); + + /* FIXME */ + return NULL; } static int rpc_call(char *method, INTERNAL_FUNCTION_PARAMETERS) { - zval *object = getThis(); +// zval *object = getThis(); +// GET_INTERNAL(intern); + + return SUCCESS; } static union _zend_function* rpc_get_constructor(zval *object TSRMLS_DC) { - zend_function *rpc_ctor; + zend_internal_function *rpc_ctor; + GET_INTERNAL(intern); - rpc_ctor = (zend_function *) emalloc(sizeof(zend_function)); + rpc_ctor = (zend_internal_function *) emalloc(sizeof(zend_internal_function)); - rpc_ctor->common.function_name = "__construct"; - zend_hash_index_find(RPC_G(instance), object->value.obj.handle, &(rpc_ctor->common.scope)); + rpc_ctor->type = ZEND_INTERNAL_FUNCTION; + rpc_ctor->scope = (*intern)->ce; + rpc_ctor->handler = CONSTRUCTOR_FN; - return rpc_ctor; + return (zend_function *) rpc_ctor; } static int rpc_get_classname(zval *object, char **class_name, zend_uint *class_name_len, int parent TSRMLS_DC) { +// GET_INTERNAL(intern); + + /* FIXME */ + return FAILURE; } static int rpc_compare(zval *object1, zval *object2 TSRMLS_DC) { + /* FIXME */ + return FAILURE; +} + +ZEND_FUNCTION(CONSTRUCTOR) +{ } /* diff --git a/ext/rpc/rpc.h b/ext/rpc/rpc.h new file mode 100644 index 0000000000..2d1b0f7697 --- /dev/null +++ b/ext/rpc/rpc.h @@ -0,0 +1,11 @@ +#ifndef RPC_H +#define RPC_H + +#define CONSTRUCTOR __construct +#define CONSTRUCTOR_FN ZEND_FN(__construct) + +#define GET_INTERNAL(intern) GET_INTERNAL_EX(intern, object) +#define GET_INTERNAL_EX(intern, object) rpc_internal **intern; \ + zend_hash_index_find(RPC_G(instance), object->value.obj.handle, (void **) &intern); + +#endif
\ No newline at end of file |