cvs: php4 /ext/rpc handler.h rpc.c

From: Date: Sun, 09 Feb 2003 21:37:40 +0000
Subject: cvs: php4 /ext/rpc handler.h rpc.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-18580@lists.php.net to get a copy of this message
wez Sun Feb 9 16:37:40 2003 EDT Modified files: /php4/ext/rpc handler.h rpc.c Log: Add get_class_name handler so that the current var_dump implementation does not segfault. Add a generic rpc_object_from_data() function for generating rpc objects from C code (as discussed with Harald). Index: php4/ext/rpc/handler.h diff -u php4/ext/rpc/handler.h:1.14 php4/ext/rpc/handler.h:1.15 --- php4/ext/rpc/handler.h:1.14 Thu Jan 16 12:49:20 2003 +++ php4/ext/rpc/handler.h Sun Feb 9 16:37:40 2003 @@ -128,5 +128,7 @@ } rpc_proxy; 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) #endif /* HANDLER_H */ Index: php4/ext/rpc/rpc.c diff -u php4/ext/rpc/rpc.c:1.18 php4/ext/rpc/rpc.c:1.19 --- php4/ext/rpc/rpc.c:1.18 Thu Jan 16 12:49:20 2003 +++ php4/ext/rpc/rpc.c Sun Feb 9 16:37:40 2003 @@ -48,6 +48,7 @@ static union _zend_function* rpc_get_method(zval *, char *, int TSRMLS_DC); static union _zend_function* rpc_get_constructor(zval * TSRMLS_DC); static zend_class_entry* rpc_get_class_entry(zval * TSRMLS_DC); +static int rpc_get_class_name(zval *object, char **class_name, zend_uint *class_name_len, int parent TSRMLS_DC); static int rpc_compare(zval *, zval * TSRMLS_DC); /**/ @@ -74,7 +75,7 @@ NULL, rpc_get_constructor, rpc_get_class_entry, - NULL, + rpc_get_class_name, rpc_compare }; @@ -409,6 +410,19 @@ return intern->ce; } +static int rpc_get_class_name(zval *object, char **class_name, zend_uint *class_name_len, int parent TSRMLS_DC) +{ + GET_INTERNAL(intern); + + if (parent) { + return FAILURE; + } else { + *class_name = intern->ce->name; + *class_name_len = intern->ce->name_length; + return SUCCESS; + } +} + static int rpc_compare(zval *object1, zval *object2 TSRMLS_DC) { /* FIXME */ @@ -581,7 +595,7 @@ retval = SUCCESS; } else { /* call the rpc ctor */ - retval = RPC_HT(intern)->rpc_ctor(*(rpc_string *)(class_hash), &(intern->data), num_args, args); + retval = RPC_HT(intern)->rpc_ctor(class_hash->name, &(intern->data), num_args, args); } } else { /* disable caching from now on */ @@ -788,7 +802,7 @@ zov->handlers = &rpc_handlers; /* set up the internal representation of our rpc instance */ - intern = (rpc_internal *) pemalloc(sizeof(rpc_internal), TRUE); + intern = (rpc_internal *) pecalloc(1, sizeof(rpc_internal), TRUE); intern->ce = class_type; intern->data = NULL; @@ -867,6 +881,45 @@ if (retval != SUCCESS) { /* TODO: exception here */ } +} + +ZEND_API zval* _rpc_object_from_data(zval *z, zend_class_entry *ce, void *data, rpc_class_hash *class_hash TSRMLS_DC) +{ + rpc_internal *intern; + + if (z == NULL) { + ALLOC_ZVAL(z); + } + + Z_TYPE_P(z) = IS_OBJECT; + z->value.obj = rpc_objects_new(ce TSRMLS_CC); + + if (GET_INTERNAL_EX(intern, z) != SUCCESS) { + /* TODO: exception */ + return NULL; + } + + intern->data = data; + + if (class_hash == NULL) { + class_hash = pemalloc(sizeof(rpc_class_hash), TRUE); + if (class_hash == NULL) { + /* TODO: exception */ + + return NULL; + } + /* 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; + } + + RPC_CLASS(intern) = class_hash; + + return z; }

« previous php.cvs (#18580) next »