From: Michael Wallner Date: Tue, 22 Feb 2005 12:01:18 +0000 (+0000) Subject: * do the dtor dance the right way X-Git-Tag: RELEASE_0_5_1~6 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=2414448a15f7a9959dc41749dd938b6770843f0c;p=m6w6%2Fext-http * do the dtor dance the right way --- diff --git a/http.c b/http.c index 2e6e593..e174ba1 100644 --- a/http.c +++ b/http.c @@ -161,14 +161,16 @@ function_entry http_functions[] = { MAKE_STD_ZVAL(__tmp); \ array_init(__tmp); \ SET_PROP(o, n, __tmp); \ - o->n = __tmp; \ } -# define FREE_PARR(p) \ - if (p) { \ - zval_dtor(p); \ - FREE_ZVAL(p); \ - (p) = NULL; \ +# define FREE_PARR(o, p) \ + { \ + zval *__tmp = NULL; \ + if (__tmp = GET_PROP(o, p)) { \ + zval_dtor(__tmp); \ + FREE_ZVAL(__tmp); \ + __tmp = NULL; \ + } \ } /* {{{ HTTPi */ @@ -736,10 +738,6 @@ static zend_object_handlers httpi_request_object_handlers; typedef struct { zend_object zo; CURL *ch; - - zval *options; - zval *responseInfo; - zval *responseData; } httpi_request_object; #define httpi_request_declare_default_properties(ce) _httpi_request_declare_default_properties(ce TSRMLS_CC) @@ -760,14 +758,14 @@ static inline void _httpi_request_declare_default_properties(zend_class_entry *c #define httpi_request_destroy_object _httpi_request_destroy_object void _httpi_request_destroy_object(void *object, zend_object_handle handle TSRMLS_DC) { - httpi_request_object *o = object; - zend_objects_destroy_object(object, handle TSRMLS_CC); +} - FREE_PARR(o->options); - FREE_PARR(o->responseInfo); - FREE_PARR(o->responseData); - +#define httpi_request_free_object _httpi_request_free_object +void _httpi_request_free_object(zend_object /* void */ *object TSRMLS_DC) +{ + httpi_request_object *o = (httpi_request_object *) object; + if (OBJ_PROP(o)) { zend_hash_destroy(OBJ_PROP(o)); FREE_HASHTABLE(OBJ_PROP(o)); @@ -793,7 +791,7 @@ zend_object_value _httpi_request_new_object(zend_class_entry *ce TSRMLS_DC) zend_hash_init(OBJ_PROP(o), 0, NULL, ZVAL_PTR_DTOR, 0); zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); - ov.handle = zend_objects_store_put(o, httpi_request_destroy_object, NULL, NULL TSRMLS_CC); + ov.handle = zend_objects_store_put(o, httpi_request_destroy_object, httpi_request_free_object, NULL TSRMLS_CC); ov.handlers = &httpi_request_object_handlers; return ov; @@ -864,29 +862,20 @@ PHP_METHOD(HTTPi_Request, __construct) } /* }}} */ +/* {{{ proto void HTTPi_Request::__destruct() + * + */ PHP_METHOD(HTTPi_Request, __destruct) { - zval *opts, *info, *resp; getObject(httpi_request_object, obj); - - /* - * this never happens ??? - */ - - fprintf(stderr, "\n\n\nYAY, DESTRUCTOR CALLED!\n\n\n"); - - opts = GET_PROP(obj, options); - zval_dtor(opts); - FREE_ZVAL(opts); - - info = GET_PROP(obj, responseInfo); - zval_dtor(info); - FREE_ZVAL(info); - - resp = GET_PROP(obj, responseData); - zval_dtor(resp); - FREE_ZVAL(resp); + + NO_ARGS; + + FREE_PARR(obj, options); + FREE_PARR(obj, responseInfo); + FREE_PARR(obj, responseData); } +/* }}} */ /* {{{ proto bool HTTPi_Request::setOptions(array options) *