From 28daebffca6fa52be88db000763c09a373450180 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 27 May 2012 15:36:03 +0900 Subject: [PATCH] use ZVAL_RESOURCE macro --- php_uv.c | 33 +++++++++++++++++++++------------ php_uv.h | 1 + 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/php_uv.c b/php_uv.c index fbd09a7..e029da8 100644 --- a/php_uv.c +++ b/php_uv.c @@ -29,7 +29,13 @@ void php_uv_init(TSRMLS_D); void static destruct_uv(zend_rsrc_list_entry *rsrc TSRMLS_DC) { + int base_id = -1; php_uv_t *obj = (php_uv_t *)rsrc->ptr; + if (obj->in_free) { + return; + } + + obj->in_free = 1; if (obj->read_cb) { zval_ptr_dtor(&obj->read_cb); @@ -47,11 +53,20 @@ void static destruct_uv(zend_rsrc_list_entry *rsrc TSRMLS_DC) zval_ptr_dtor(&obj->listen_cb); obj->listen_cb = NULL; } - + if (obj->resource_id) { + base_id = obj->resource_id; + obj->resource_id = NULL; + } + if (obj) { fprintf(stderr, "close"); efree(obj); + obj = NULL; } + if (base_id) { + zend_list_delete(base_id); + } + } @@ -185,8 +200,7 @@ static void php_uv_write_cb(uv_write_t* req, int status) ZVAL_LONG(stat, status); MAKE_STD_ZVAL(client); - client->value.lval = uv->resource_id; - client->type = IS_RESOURCE; + ZVAL_RESOURCE(client, uv->resource_id); params[0] = &stat; params[1] = &client; @@ -273,8 +287,7 @@ static void php_uv_listen_cb(uv_stream_t* server, int status) fci.retval_ptr_ptr = &retval_ptr; MAKE_STD_ZVAL(svr); - svr->value.lval = uv->resource_id; - svr->type = IS_RESOURCE; + ZVAL_RESOURCE(svr, uv->resource_id); params[0] = &svr; @@ -315,8 +328,7 @@ static void php_uv_read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) zval *rsc; MAKE_STD_ZVAL(rsc); - rsc->value.lval = uv->resource_id; - rsc->type = IS_RESOURCE; + ZVAL_RESOURCE(rsc, uv->resource_id); params[0] = &buffer; params[1] = &rsc; @@ -359,8 +371,7 @@ static void php_uv_close_cb(uv_handle_t *handle) fci.retval_ptr_ptr = &retval_ptr; MAKE_STD_ZVAL(h); - h->value.lval = uv->resource_id; - h->type = IS_RESOURCE; + ZVAL_RESOURCE(h, uv->resource_id); params[0] = &h; @@ -505,9 +516,7 @@ static void php_uv_timer_cb(uv_timer_t *handle, int status) MAKE_STD_ZVAL(stat); ZVAL_LONG(stat, status); MAKE_STD_ZVAL(client); - - client->value.lval = uv->resource_id; - client->type = IS_RESOURCE; + ZVAL_RESOURCE(client, uv->resource_id); params[0] = &stat; params[1] = &client; diff --git a/php_uv.h b/php_uv.h index daff860..1aa5a63 100644 --- a/php_uv.h +++ b/php_uv.h @@ -24,6 +24,7 @@ extern zend_module_entry uv_module_entry; extern zend_class_entry *uv_class_entry; typedef struct { + int in_free; int resource_id; union { uv_tcp_t tcp;