X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-pq;a=blobdiff_plain;f=src%2Fphp_pqcopy.c;h=e94567945e8784088d7eb3bc7334f5c9cea29418;hp=2c4b626062d36b19ef33c7a34dadb3ef92bcb864;hb=8897b5a581a86279a2ee371784b6b7670c8b8cc1;hpb=6e28a8741be3fccdaca960e492c31bc26837a4ed diff --git a/src/php_pqcopy.c b/src/php_pqcopy.c index 2c4b626..e945679 100644 --- a/src/php_pqcopy.c +++ b/src/php_pqcopy.c @@ -35,7 +35,7 @@ static void php_pqcopy_object_free(zend_object *o) { php_pqcopy_object_t *obj = PHP_PQ_OBJ(NULL, o); #if DBG_GC - fprintf(stderr, "FREE copy(#%d) %p (conn(#%d): %p)\n", obj->zv.handle, obj, obj->intern->conn->zv.handle, obj->intern->conn); + fprintf(stderr, "FREE copy(#%d) %p (conn(#%d): %p)\n", obj->zo.handle, obj, obj->intern->conn->zo.handle, obj->intern->conn); #endif if (obj->intern) { efree(obj->intern->expression); @@ -44,26 +44,13 @@ static void php_pqcopy_object_free(zend_object *o) efree(obj->intern); obj->intern = NULL; } - zend_object_std_dtor(o); - efree(obj); + php_pq_object_dtor(o); } php_pqcopy_object_t *php_pqcopy_create_object_ex(zend_class_entry *ce, php_pqcopy_t *intern) { - php_pqcopy_object_t *o; - - o = ecalloc(1, sizeof(*o) + zend_object_properties_size(ce)); - zend_object_std_init(&o->zo, ce); - object_properties_init(&o->zo, ce); - o->prophandler = &php_pqcopy_object_prophandlers; - - if (intern) { - o->intern = intern; - } - - o->zo.handlers = &php_pqcopy_object_handlers; - - return o; + return php_pq_object_create(ce, intern, sizeof(php_pqcopy_object_t), + &php_pqcopy_object_handlers, &php_pqcopy_object_prophandlers); } static zend_object *php_pqcopy_create_object(zend_class_entry *class_type) @@ -78,6 +65,15 @@ static void php_pqcopy_object_read_connection(zval *object, void *o, zval *retur php_pq_object_to_zval(obj->intern->conn, return_value); } +static void php_pqcopy_object_gc_connection(zval *object, void *o, zval *return_value) +{ + php_pqcopy_object_t *obj = o; + zval zconn; + + php_pq_object_to_zval_no_addref(obj->intern->conn, &zconn); + add_next_index_zval(return_value, &zconn); +} + static void php_pqcopy_object_read_direction(zval *object, void *o, zval *return_value) { php_pqcopy_object_t *obj = o; @@ -145,7 +141,7 @@ static PHP_METHOD(pqcopy, __construct) { smart_str_appendl(&cmd, opt_str, opt_len); smart_str_0(&cmd); - res = PQexec(conn_obj->intern->conn, smart_str_v(&cmd)); + res = php_pq_exec(conn_obj->intern->conn, smart_str_v(&cmd)); if (!res) { throw_exce(EX_RUNTIME, "Failed to start %s (%s)", smart_str_v(&cmd), PHP_PQerrorMessage(obj->intern->conn->intern->conn)); @@ -159,7 +155,7 @@ static PHP_METHOD(pqcopy, __construct) { php_pq_object_addref(conn_obj); } - PHP_PQclear(res); + php_pqres_clear(res); } smart_str_free(&cmd); @@ -227,7 +223,7 @@ static PHP_METHOD(pqcopy, end) { throw_exce(EX_RUNTIME, "Failed to fetch COPY result (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn)); } else { php_pqres_success(res); - PHP_PQclear(res); + php_pqres_clear(res); } } @@ -245,7 +241,7 @@ static PHP_METHOD(pqcopy, get) { ZEND_RESULT_CODE rv; zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh); - rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zdata); + rv = zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zdata); zend_restore_error_handling(&zeh); if (SUCCESS == rv) { @@ -272,7 +268,7 @@ static PHP_METHOD(pqcopy, get) { throw_exce(EX_RUNTIME, "Failed to fetch COPY result (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn)); } else { php_pqres_success(res); - PHP_PQclear(res); + php_pqres_clear(res); RETVAL_FALSE; } break; @@ -297,7 +293,7 @@ static PHP_METHOD(pqcopy, get) { } static zend_function_entry php_pqcopy_methods[] = { - PHP_ME(pqcopy, __construct, ai_pqcopy_construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(pqcopy, __construct, ai_pqcopy_construct, ZEND_ACC_PUBLIC) PHP_ME(pqcopy, put, ai_pqcopy_put, ZEND_ACC_PUBLIC) PHP_ME(pqcopy, end, ai_pqcopy_end, ZEND_ACC_PUBLIC) PHP_ME(pqcopy, get, ai_pqcopy_get, ZEND_ACC_PUBLIC) @@ -326,15 +322,17 @@ PHP_MINIT_FUNCTION(pqcopy) php_pqcopy_object_handlers.write_property = php_pq_object_write_prop; php_pqcopy_object_handlers.clone_obj = NULL; php_pqcopy_object_handlers.get_property_ptr_ptr = NULL; - php_pqcopy_object_handlers.get_gc = NULL; + php_pqcopy_object_handlers.get_gc = php_pq_object_get_gc; php_pqcopy_object_handlers.get_properties = php_pq_object_properties; php_pqcopy_object_handlers.get_debug_info = php_pq_object_debug_info; - zend_hash_init(&php_pqcopy_object_prophandlers, 4, NULL, NULL, 1); + zend_hash_init(&php_pqcopy_object_prophandlers, 4, NULL, php_pq_object_prophandler_dtor, 1); zend_declare_property_null(php_pqcopy_class_entry, ZEND_STRL("connection"), ZEND_ACC_PUBLIC); ph.read = php_pqcopy_object_read_connection; + ph.gc = php_pqcopy_object_gc_connection; zend_hash_str_add_mem(&php_pqcopy_object_prophandlers, "connection", sizeof("connection")-1, (void *) &ph, sizeof(ph)); + ph.gc = NULL; zend_declare_property_null(php_pqcopy_class_entry, ZEND_STRL("expression"), ZEND_ACC_PUBLIC); ph.read = php_pqcopy_object_read_expression;