]> granicus.if.org Git - php/commitdiff
fixed HashTable allocation
authorHarald Radi <phanto@php.net>
Fri, 15 Mar 2002 13:10:35 +0000 (13:10 +0000)
committerHarald Radi <phanto@php.net>
Fri, 15 Mar 2002 13:10:35 +0000 (13:10 +0000)
ext/rpc/handler.h
ext/rpc/php_rpc.h
ext/rpc/rpc.c
ext/rpc/rpc.h [new file with mode: 0644]

index cb13c90a494379dd983ef4270c170144b0a3994a..02c0b5e83ca87fa76a05ac6e7d755515b400791c 100644 (file)
@@ -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
index a989772a4bd9f4610f6ca0016354d4c45673e779..e0ae67f89e9f0ac1d141430dcfb57b80dc2c6bd1 100644 (file)
@@ -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
index 2d9c51569511419510e2993df264cec8079d6905..4327f359f9194e8b8530d7e74217f16cd594e41f 100644 (file)
@@ -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,98 +161,179 @@ 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 (file)
index 0000000..2d1b0f7
--- /dev/null
@@ -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