summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWez Furlong <wez@php.net>2003-02-09 21:37:41 +0000
committerWez Furlong <wez@php.net>2003-02-09 21:37:41 +0000
commit9ef5cc7ef95674fe1bd35023df1832cf443af109 (patch)
tree9382c1066392d1d126089593d8ff558c040af599
parent47922a69965a47dfa4c32438267b9156dc3f7b0d (diff)
downloadphp-git-9ef5cc7ef95674fe1bd35023df1832cf443af109.tar.gz
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).
-rw-r--r--ext/rpc/handler.h2
-rw-r--r--ext/rpc/rpc.c59
2 files changed, 58 insertions, 3 deletions
diff --git a/ext/rpc/handler.h b/ext/rpc/handler.h
index ef39c0eac0..132fcc2b89 100644
--- a/ext/rpc/handler.h
+++ b/ext/rpc/handler.h
@@ -128,5 +128,7 @@ typedef struct _rpc_proxy {
} 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 */ \ No newline at end of file
diff --git a/ext/rpc/rpc.c b/ext/rpc/rpc.c
index ef52d95457..d6d9aa02be 100644
--- a/ext/rpc/rpc.c
+++ b/ext/rpc/rpc.c
@@ -48,6 +48,7 @@ static HashTable* rpc_get_properties(zval * TSRMLS_DC);
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 @@ static zend_object_handlers rpc_handlers = {
NULL,
rpc_get_constructor,
rpc_get_class_entry,
- NULL,
+ rpc_get_class_name,
rpc_compare
};
@@ -409,6 +410,19 @@ static zend_class_entry* rpc_get_class_entry(zval *object TSRMLS_DC)
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 @@ ZEND_API ZEND_FUNCTION(rpc_load)
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 @@ ZEND_API zend_object_value rpc_objects_new(zend_class_entry *class_type TSRMLS_D
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;
@@ -869,6 +883,45 @@ static void rpc_internal_set(rpc_internal *intern, char *property, zend_uint pro
}
}
+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;
+}
+
/*
* Local variables: