X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-pq;a=blobdiff_plain;f=src%2Fphp_pqconn_event.c;h=8cdb761b317afa69348c0c1d8ef049738684d0ce;hp=f509c573867bdf17f742bca499cb045f97897abb;hb=c753ebfed3a4b21409cfa46212fd2c55227c809f;hpb=88440266c0a9fa8354688b5ed0d2a6cc3bf04db5 diff --git a/src/php_pqconn_event.c b/src/php_pqconn_event.c index f509c57..8cdb761 100644 --- a/src/php_pqconn_event.c +++ b/src/php_pqconn_event.c @@ -24,17 +24,17 @@ #include "php_pqconn_event.h" #include "php_pqres.h" -static int apply_event(void *p, void *a TSRMLS_DC) +static int apply_event(zval *p, void *a) { - php_pq_callback_t *cb = p; + php_pq_callback_t *cb = Z_PTR_P(p); zval *args = a; - zval *retval = NULL; + zval rv; - zend_fcall_info_args(&cb->fci, args TSRMLS_CC); - zend_fcall_info_call(&cb->fci, &cb->fcc, &retval, NULL TSRMLS_CC); - if (retval) { - zval_ptr_dtor(&retval); - } + ZVAL_NULL(&rv); + zend_fcall_info_args(&cb->fci, args); + zend_fcall_info_call(&cb->fci, &cb->fcc, &rv, NULL); + zend_fcall_info_args_clear(&cb->fci, 0); + zval_ptr_dtor(&rv); return ZEND_HASH_APPLY_KEEP; } @@ -44,17 +44,15 @@ static void php_pqconn_event_connreset(PGEventConnReset *event) php_pqconn_event_data_t *data = PQinstanceData(event->conn, php_pqconn_event); if (data) { - HashTable *evhs; - TSRMLS_DF(data); + zval *zevhs; - if (SUCCESS == zend_hash_find(&data->obj->intern->eventhandlers, ZEND_STRS("reset"), (void *) &evhs)) { - zval *args, *connection = NULL; + if ((zevhs = zend_hash_str_find(&data->obj->intern->eventhandlers, ZEND_STRL("reset")))) { + zval args, connection; - MAKE_STD_ZVAL(args); - array_init(args); - php_pq_object_to_zval(data->obj, &connection TSRMLS_CC); - add_next_index_zval(args, connection); - zend_hash_apply_with_argument(evhs, apply_event, args TSRMLS_CC); + array_init(&args); + php_pq_object_to_zval(data->obj, &connection); + add_next_index_zval(&args, &connection); + zend_hash_apply_with_argument(Z_ARRVAL_P(zevhs), apply_event, &args); zval_ptr_dtor(&args); } } @@ -65,33 +63,29 @@ static void php_pqconn_event_resultcreate(PGEventResultCreate *event) php_pqconn_event_data_t *data = PQinstanceData(event->conn, php_pqconn_event); if (data) { - php_pqres_object_t *obj; - HashTable *evhs; - TSRMLS_DF(data); - - php_pqres_init_instance_data(event->result, data->obj, &obj TSRMLS_CC); + php_pqres_object_t *obj = php_pqres_init_instance_data(event->result, data->obj); + zval *zevhs; /* event listener */ - if (SUCCESS == zend_hash_find(&data->obj->intern->eventhandlers, ZEND_STRS("result"), (void *) &evhs)) { - zval *args, *connection = NULL, *res = NULL; - - MAKE_STD_ZVAL(args); - array_init(args); - php_pq_object_to_zval(data->obj, &connection TSRMLS_CC); - add_next_index_zval(args, connection); - php_pq_object_to_zval(obj, &res TSRMLS_CC); - add_next_index_zval(args, res); - zend_hash_apply_with_argument(evhs, apply_event, args TSRMLS_CC); + if ((zevhs = zend_hash_str_find(&data->obj->intern->eventhandlers, ZEND_STRL("result")))) { + zval args, connection, res; + + array_init(&args); + php_pq_object_to_zval(data->obj, &connection); + add_next_index_zval(&args, &connection); + php_pq_object_to_zval(obj, &res); + add_next_index_zval(&args, &res); + zend_hash_apply_with_argument(Z_ARRVAL_P(zevhs), apply_event, &args); zval_ptr_dtor(&args); } /* async callback */ - if (data->obj->intern->onevent.fci.size > 0) { - zval *res = NULL; + if (php_pq_callback_is_enabled(&data->obj->intern->onevent)) { + zval res; - php_pq_object_to_zval(obj, &res TSRMLS_CC); - zend_fcall_info_argn(&data->obj->intern->onevent.fci TSRMLS_CC, 1, &res); - zend_fcall_info_call(&data->obj->intern->onevent.fci, &data->obj->intern->onevent.fcc, NULL, NULL TSRMLS_CC); + php_pq_object_to_zval(obj, &res); + zend_fcall_info_argn(&data->obj->intern->onevent.fci, 1, &res); + zend_fcall_info_call(&data->obj->intern->onevent.fci, &data->obj->intern->onevent.fcc, NULL, NULL); zval_ptr_dtor(&res); } @@ -104,6 +98,8 @@ static void php_pqconn_event_resultdestroy(PGEventResultDestroy *event) if (obj) { obj->intern->res = NULL; + assert(GC_REFCOUNT(&obj->zo)); + php_pq_object_delref(obj); } } @@ -126,12 +122,12 @@ int php_pqconn_event(PGEventId id, void *e, void *data) return 1; } -php_pqconn_event_data_t *php_pqconn_event_data_init(php_pqconn_object_t *obj TSRMLS_DC) +php_pqconn_event_data_t *php_pqconn_event_data_init(php_pqconn_object_t *obj) { php_pqconn_event_data_t *data = emalloc(sizeof(*data)); data->obj = obj; - TSRMLS_CF(data); + data->res = NULL; return data; } @@ -141,18 +137,16 @@ void php_pqconn_notice_recv(void *p, const PGresult *res) php_pqconn_event_data_t *data = p; if (data) { - HashTable *evhs; - TSRMLS_DF(data); - - if (SUCCESS == zend_hash_find(&data->obj->intern->eventhandlers, ZEND_STRS("notice"), (void *) &evhs)) { - zval *args, *connection = NULL; - - MAKE_STD_ZVAL(args); - array_init(args); - php_pq_object_to_zval(data->obj, &connection TSRMLS_CC); - add_next_index_zval(args, connection); - add_next_index_string(args, PHP_PQresultErrorMessage(res), 1); - zend_hash_apply_with_argument(evhs, apply_event, args TSRMLS_CC); + zval *zevhs; + + if ((zevhs = zend_hash_str_find(&data->obj->intern->eventhandlers, ZEND_STRL("notice")))) { + zval args, connection; + + array_init(&args); + php_pq_object_to_zval(data->obj, &connection); + add_next_index_zval(&args, &connection); + add_next_index_string(&args, PHP_PQresultErrorMessage(res)); + zend_hash_apply_with_argument(Z_ARRVAL_P(zevhs), apply_event, &args); zval_ptr_dtor(&args); } }