phanto          Mon Feb 10 15:59:11 2003 EDT

  Modified files:              
    /php4/ext/rpc       handler.h php_rpc.h rpc.c rpc.h rpc_proxy.c 
  Log:
  a bunch of fixes
  
Index: php4/ext/rpc/handler.h
diff -u php4/ext/rpc/handler.h:1.15 php4/ext/rpc/handler.h:1.16
--- php4/ext/rpc/handler.h:1.15 Sun Feb  9 16:37:40 2003
+++ php4/ext/rpc/handler.h      Mon Feb 10 15:59:10 2003
@@ -82,13 +82,13 @@
        int (*rpc_ctor)(rpc_string class_name, void **data, int num_args, zval 
**args[]);
        int (*rpc_dtor)(void *data);
        int (*rpc_describe)(rpc_string method_name, void *data, char **arg_types, 
unsigned char **ref_types);
-       int (*rpc_call)(rpc_string method_name, void **data, zval *return_value, int 
num_args, zval **args[]);
-       int (*rpc_get)(rpc_string property_name, zval *return_value, void **data);
-       int (*rpc_set)(rpc_string property_name, zval *value, void **data);
-       int (*rpc_compare)(void **data1, void **data2);
-       int (*rpc_has_property)(rpc_string property_name, void **data);
-       int (*rpc_unset_property)(rpc_string property_name, void **data);
-       int (*rpc_get_properties)(HashTable **properties, void **data);
+       int (*rpc_call)(rpc_string method_name, void *data, zval *return_value, int 
+num_args, zval **args[]);
+       int (*rpc_get)(rpc_string property_name, zval *return_value, void *data);
+       int (*rpc_set)(rpc_string property_name, zval *value, void *data);
+       int (*rpc_compare)(void *data1, void *data2);
+       int (*rpc_has_property)(rpc_string property_name, void *data);
+       int (*rpc_unset_property)(rpc_string property_name, void *data);
+       int (*rpc_get_properties)(HashTable **properties, void *data);
 } rpc_object_handlers;
 
 /* handler entry */
@@ -127,8 +127,17 @@
        zend_uint                               dummy;
 } rpc_proxy;
 
+
+ZEND_API ZEND_FUNCTION(rpc_load);
+ZEND_API ZEND_FUNCTION(rpc_call);
+ZEND_API ZEND_FUNCTION(rpc_set);
+ZEND_API ZEND_FUNCTION(rpc_get);
+ZEND_API ZEND_FUNCTION(rpc_singleton);
+ZEND_API ZEND_FUNCTION(rpc_poolable);
+
 ZEND_API rpc_register_layer(rpc_handler_entry *entry TSRMLS_DC);
-ZEND_API zval* _rpc_object_from_data(zval *z, zend_class_entry *ce, void *data, 
rpc_class_hash *class_hash TSRMLS_DC);
-#define rpc_object_from_data(z, layer, data, class_hash)  _rpc_object_from_data((z), 
layer##_class_entry, (data), (class_hash) TSRMLS_CC)
+ZEND_API zval* _rpc_object_from_data(zval *z, rpc_handler_entry *handler, void *data, 
+rpc_class_hash *class_hash);
+#define rpc_object_from_data(layer, data)  rpc_object_from_data_ex(NULL, layer, data, 
+NULL)
+#define rpc_object_from_data_ex(z, layer, data, class_hash)  
+_rpc_object_from_data((z), &layer##_handler_entry, (data), (class_hash))
 
 #endif /* HANDLER_H */
Index: php4/ext/rpc/php_rpc.h
diff -u php4/ext/rpc/php_rpc.h:1.9 php4/ext/rpc/php_rpc.h:1.10
--- php4/ext/rpc/php_rpc.h:1.9  Thu Jan 16 12:49:20 2003
+++ php4/ext/rpc/php_rpc.h      Mon Feb 10 15:59:10 2003
@@ -34,13 +34,6 @@
 ZEND_RSHUTDOWN_FUNCTION(rpc);
 ZEND_MINFO_FUNCTION(rpc);
 
-ZEND_API ZEND_FUNCTION(rpc_load);
-ZEND_API ZEND_FUNCTION(rpc_call);
-ZEND_API ZEND_FUNCTION(rpc_set);
-ZEND_API ZEND_FUNCTION(rpc_get);
-ZEND_API ZEND_FUNCTION(rpc_singleton);
-ZEND_API ZEND_FUNCTION(rpc_poolable);
-
 ZEND_API void rpc_error(int type, const char *format, ...);
 ZEND_API zend_object_value rpc_objects_new(zend_class_entry * TSRMLS_DC);
 
Index: php4/ext/rpc/rpc.c
diff -u php4/ext/rpc/rpc.c:1.21 php4/ext/rpc/rpc.c:1.22
--- php4/ext/rpc/rpc.c:1.21     Mon Feb 10 07:36:06 2003
+++ php4/ext/rpc/rpc.c  Mon Feb 10 15:59:10 2003
@@ -36,8 +36,10 @@
 static void rpc_objects_delete(void *, zend_object_handle TSRMLS_DC);
 static void rpc_ini_cb(void *arg TSRMLS_DC);
 
+static rpc_class_hash *rpc_class_hash_find(rpc_string *name);
+
 /* object handler */
-static zval* rpc_read(zval *, zval *, int  TSRMLS_DC);
+static zval* rpc_read(zval *, zval * TSRMLS_DC);
 static void rpc_write(zval *, zval *, zval * TSRMLS_DC);
 static zval** rpc_get_property(zval *, zval * TSRMLS_DC);
 static zval* rpc_get(zval * TSRMLS_DC);
@@ -283,7 +285,7 @@
        }
 }
 
-static zval* rpc_read(zval *object, zval *member, int type TSRMLS_DC)
+static zval* rpc_read(zval *object, zval *member TSRMLS_DC)
 {
        zval *return_value;
        GET_INTERNAL(intern);
@@ -439,7 +441,6 @@
        zend_uint num_args = ZEND_NUM_ARGS();
        zend_class_entry overloaded_class_entry;
        rpc_class_hash *class_hash;
-       rpc_class_hash **class_hash_find = NULL;
        rpc_internal *intern;
        rpc_string hash_val, class_val;
        int retval, append = 0;
@@ -493,16 +494,10 @@
                                GET_SIGNATURE(intern, class_val.str, class_val.len, 
hash_val, num_args, arg_types);
 
                                /* check if already hashed */   
-                               if (zend_ts_hash_find(&classes, hash_val.str, 
hash_val.len + 1, (void **) &class_hash_find) != SUCCESS) {
-                                       class_hash = pemalloc(sizeof(rpc_class_hash), 
TRUE);
+                               if ((class_hash = rpc_class_hash_find(&hash_val)) == 
+NULL) {
+                                       rpc_class_hash **class_hash_find;
 
-                                       /* set up the cache */
-                                       zend_ts_hash_init(&(class_hash->methods), 0, 
NULL, rpc_string_dtor, TRUE);
-                                       zend_ts_hash_init(&(class_hash->properties), 
0, NULL, rpc_string_dtor, TRUE);
-                                       class_hash->handlers = intern->handlers;
-                                       class_hash->singleton = FALSE;
-                                       class_hash->poolable = FALSE;
-                                       class_hash->data = NULL;
+                                       ALLOC_CLASS_HASH(class_hash, intern->handlers);
 
                                        /* do hashing */
                                        if (RPC_HT(intern)->rpc_hash(class_val, 
(rpc_string *)(class_hash), NULL, num_args, arg_types, CLASS) != SUCCESS) {
@@ -524,8 +519,8 @@
                                         * also track all instaces in a llist for 
destruction later on, because there might be duplicate entries in
                                         * the hashtable and we can't determine if a 
pointer references to an already freed element
                                         */
-                                       zend_ts_hash_add(&classes, hash_val.str, 
hash_val.len + 1, &class_hash, sizeof(rpc_class_hash *), (void **) &class_hash_find);
                                        tsrm_mutex_lock(classes.mx_writer);
+                                       zend_ts_hash_add(&classes, hash_val.str, 
+hash_val.len + 1, &class_hash, sizeof(rpc_class_hash *), (void **) &class_hash_find);
                                        zend_llist_add_element(&classes_list, 
class_hash_find);
                                        tsrm_mutex_unlock(classes.mx_writer);
 
@@ -537,7 +532,6 @@
                                                zend_ts_hash_index_update(&classes, 
class_hash->name.len, &class_hash, sizeof(rpc_class_hash *), NULL);
                                        }
                                } else {
-                                       class_hash = *class_hash_find;
                                        intern->ce = class_hash->ce;
                                }
 
@@ -551,19 +545,11 @@
                }
        } else {
                /* integer classname (hashcode) */
-               if (zend_ts_hash_index_find(&classes, class_val.len, (void**) 
&class_hash_find) != SUCCESS) {
-                       class_hash = pemalloc(sizeof(rpc_class_hash), TRUE);
+               if ((class_hash = rpc_class_hash_find(&hash_val)) == NULL) {
+                       ALLOC_CLASS_HASH(class_hash, intern->handlers);
 
-                       /* set up the cache */
                        class_hash->name.str = NULL;
                        class_hash->name.len = class_val.len;
-                       class_hash->handlers = intern->handlers;
-                       class_hash->singleton = FALSE;
-                       class_hash->poolable = FALSE;
-                       class_hash->data = NULL;
-
-                       zend_ts_hash_init(&(class_hash->methods), 0, NULL, 
rpc_string_dtor, TRUE);
-                       zend_ts_hash_init(&(class_hash->properties), 0, NULL, 
rpc_string_dtor, TRUE);
 
                        /* overload class entry */
                        RPC_HT(intern)->rpc_name(class_val, &class_val, NULL, CLASS);
@@ -575,7 +561,6 @@
                        /* register int hashcode, we don't know more */
                        zend_ts_hash_index_update(&classes, class_hash->name.len, 
&class_hash, sizeof(rpc_class_hash *), NULL);
                } else {
-                       class_hash = *class_hash_find;
                        intern->ce = class_hash->ce;
                }
        }
@@ -686,9 +671,10 @@
                /* actually this should not be neccesary, but who knows :)
                 * considering possible thread implementations in future php versions
                 * and srm it is better to do concurrency checks
+                * DEPRECATE THIS !
                 */
                tsrm_mutex_lock(intern->mx_handler);
-               retval = RPC_HT(intern)->rpc_call(*method_hash, &(intern->data), 
return_value, num_args, args);
+               retval = RPC_HT(intern)->rpc_call(*method_hash, intern->data, 
+return_value, num_args, args);
                tsrm_mutex_unlock(intern->mx_handler);
        }
 
@@ -789,9 +775,10 @@
 ZEND_API void rpc_error(int type, const char *format, ...)
 {
        va_list args;
+       TSRMLS_FETCH();
 
        va_start(args, format);
-       zend_error(type, format, args);
+       zend_error_cb(type, zend_get_executed_filename(TSRMLS_C), 
+zend_get_executed_lineno(TSRMLS_C), format, args);
        va_end(args);
 }
 
@@ -808,7 +795,6 @@
 
        intern->ce = class_type;
        intern->data = NULL;
-       intern->function_table.hash = intern->ce->function_table;       
        intern->function_table.reader = 0;
        intern->function_table.mx_reader = tsrm_mutex_alloc();
        intern->function_table.mx_writer = tsrm_mutex_alloc();
@@ -885,16 +871,37 @@
        }
 }
 
-ZEND_API zval* _rpc_object_from_data(zval *z, zend_class_entry *ce, void *data, 
rpc_class_hash *class_hash TSRMLS_DC)
+static rpc_class_hash *rpc_class_hash_find(rpc_string *name)
+{
+       rpc_class_hash **class_hash_find = NULL;
+
+       if (name->str == NULL) {
+               /* int value */
+               if (zend_ts_hash_index_find(&classes, name->len, (void**) 
+&class_hash_find) != SUCCESS) {
+                       return NULL;
+               }
+       } else {
+               /* string value */
+               if (zend_ts_hash_find(&classes, name->str, name->len + 1, (void **) 
+&class_hash_find) != SUCCESS) {
+                       return NULL;
+               }
+       }
+
+       return *class_hash_find;
+}
+
+ZEND_API zval* _rpc_object_from_data(zval *z, rpc_handler_entry *handler, void *data, 
+rpc_class_hash *class_hash)
 {
        rpc_internal *intern;
+       rpc_string name = {NULL, 0};
+       TSRMLS_FETCH();
 
        if (z == NULL) {
                ALLOC_ZVAL(z);
        }
 
        Z_TYPE_P(z) = IS_OBJECT;
-       z->value.obj = rpc_objects_new(ce TSRMLS_CC);
+       z->value.obj = rpc_objects_new(*(handler->ce) TSRMLS_CC);
        
        if (GET_INTERNAL_EX(intern, z) != SUCCESS) {
                /* TODO: exception */
@@ -904,24 +911,21 @@
        intern->data = data;
 
        if (class_hash == NULL) {
-               class_hash = pemalloc(sizeof(rpc_class_hash), TRUE);
-               if (class_hash == NULL) {
-                       /* TODO: exception */
+               if (handler->handlers->rpc_name(name, &name, data, CLASS) == SUCCESS) {
+                       class_hash = rpc_class_hash_find(&name);
+               } else {
+                       ALLOC_CLASS_HASH(class_hash, intern->handlers);
 
-                       return NULL;
+                       if (class_hash == NULL) {
+                               /* TODO: exception */
+                               return NULL;
+                       }
+                   
+                       /* Copy the function table hash for this object, so that it is 
+separated
+                    * from the "global" table */
+                   zend_ts_hash_init(&(intern->function_table), 0, NULL, NULL, TRUE);
+                   zend_hash_copy(&intern->function_table.hash, 
+&((*(handler->ce))->function_table), NULL, NULL, 0);
                }
-               /* set up the cache */
-               zend_ts_hash_init(&(class_hash->methods), 0, NULL, rpc_string_dtor, 
TRUE);
-               zend_ts_hash_init(&(class_hash->properties), 0, NULL, rpc_string_dtor, 
TRUE);
-               class_hash->handlers = intern->handlers;
-               class_hash->singleton = FALSE;
-               class_hash->poolable = FALSE;
-               class_hash->data = NULL;
-
-               /* Copy the function table hash for this object, so that it is 
separated
-                * from the "global" table */
-               zend_ts_hash_init(&intern->function_table, 0, NULL, NULL, TRUE);
-               zend_hash_copy(&intern->function_table.hash, &ce->function_table, 
NULL, NULL, 0);
        }
 
        RPC_CLASS(intern) = class_hash;
Index: php4/ext/rpc/rpc.h
diff -u php4/ext/rpc/rpc.h:1.12 php4/ext/rpc/rpc.h:1.13
--- php4/ext/rpc/rpc.h:1.12     Thu Jan 16 12:49:20 2003
+++ php4/ext/rpc/rpc.h  Mon Feb 10 15:59:10 2003
@@ -123,4 +123,15 @@
                                                efree(arg_types);                      
                                                                                       
                                          \
                                                efree(hash_val.str);
 
+#define ALLOC_CLASS_HASH(_class_hash, _handlers) \
+               if (_class_hash = pemalloc(sizeof(rpc_class_hash), TRUE)) { \
+                       /* set up the cache */ \
+                       zend_ts_hash_init(&(_class_hash->methods), 0, NULL, 
+rpc_string_dtor, TRUE); \
+                       zend_ts_hash_init(&(_class_hash->properties), 0, NULL, 
+rpc_string_dtor, TRUE); \
+                       _class_hash->singleton = FALSE; \
+                       _class_hash->poolable = FALSE; \
+                       _class_hash->data = NULL; \
+                       _class_hash->handlers = _handlers; \
+               }
+
 #endif
Index: php4/ext/rpc/rpc_proxy.c
diff -u php4/ext/rpc/rpc_proxy.c:1.7 php4/ext/rpc/rpc_proxy.c:1.8
--- php4/ext/rpc/rpc_proxy.c:1.7        Sun Feb  9 16:35:30 2003
+++ php4/ext/rpc/rpc_proxy.c    Mon Feb 10 15:59:10 2003
@@ -26,7 +26,7 @@
 static void rpc_proxy_del_ref(zval * TSRMLS_DC);
 static void rpc_proxy_delete(zval * TSRMLS_DC);
 static zend_object_value rpc_proxy_clone(zval * TSRMLS_DC);
-static zval* rpc_proxy_read(zval *, zval *, int  TSRMLS_DC);
+static zval* rpc_proxy_read(zval *, zval * TSRMLS_DC);
 static void rpc_proxy_write(zval *, zval *, zval * TSRMLS_DC);
 static zval** rpc_proxy_get_property(zval *, zval * TSRMLS_DC);
 static zval* rpc_proxy_get(zval * TSRMLS_DC);
@@ -82,7 +82,7 @@
 {
 }
 
-static zval* rpc_proxy_read(zval *object, zval *member, int type TSRMLS_DC)
+static zval* rpc_proxy_read(zval *object, zval *member TSRMLS_DC)
 {
        return NULL;
 }

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to