Merge branch 'v1.0.x'
[m6w6/ext-pq] / src / php_pqstm.c
index b82adcf..4eec3b8 100644 (file)
@@ -15,7 +15,7 @@
 #endif
 
 #include <php.h>
 #endif
 
 #include <php.h>
-#include <ext/standard/php_smart_str.h>
+#include <Zend/zend_smart_str.h>
 
 #include "php_pq.h"
 #include "php_pq_misc.h"
 
 #include "php_pq.h"
 #include "php_pq_misc.h"
@@ -29,7 +29,7 @@ zend_class_entry *php_pqstm_class_entry;
 static zend_object_handlers php_pqstm_object_handlers;
 static HashTable php_pqstm_object_prophandlers;
 
 static zend_object_handlers php_pqstm_object_handlers;
 static HashTable php_pqstm_object_prophandlers;
 
-static void php_pqstm_deallocate(php_pqstm_object_t *obj, zend_bool async, zend_bool silent TSRMLS_DC)
+static void php_pqstm_deallocate(php_pqstm_object_t *obj, zend_bool async, zend_bool silent)
 {
        if (obj->intern->allocated) {
                char *quoted_name = PQescapeIdentifier(obj->intern->conn->intern->conn, obj->intern->name, strlen(obj->intern->name));
 {
        if (obj->intern->allocated) {
                char *quoted_name = PQescapeIdentifier(obj->intern->conn->intern->conn, obj->intern->name, strlen(obj->intern->name));
@@ -42,19 +42,19 @@ static void php_pqstm_deallocate(php_pqstm_object_t *obj, zend_bool async, zend_
                        smart_str_0(&cmd);
 
                        if (async) {
                        smart_str_0(&cmd);
 
                        if (async) {
-                               if (PQsendQuery(obj->intern->conn->intern->conn, cmd.c)) {
+                               if (PQsendQuery(obj->intern->conn->intern->conn, smart_str_v(&cmd))) {
                                        obj->intern->conn->intern->poller = PQconsumeInput;
                                        obj->intern->conn->intern->poller = PQconsumeInput;
-                                       php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
+                                       php_pqconn_notify_listeners(obj->intern->conn);
                                } else if (!silent) {
                                } else if (!silent) {
-                                       throw_exce(EX_IO TSRMLS_CC, "Failed to deallocate statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+                                       throw_exce(EX_IO, "Failed to deallocate statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                                }
                        } else {
                                PGresult *res;
 
                                }
                        } else {
                                PGresult *res;
 
-                               if ((res = php_pq_exec(obj->intern->conn->intern->conn, cmd.c))) {
+                               if ((res = php_pq_exec(obj->intern->conn->intern->conn, smart_str_v(&cmd)))) {
                                        php_pqres_clear(res);
                                } else if (!silent) {
                                        php_pqres_clear(res);
                                } else if (!silent) {
-                                       throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to deallocate statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+                                       throw_exce(EX_RUNTIME, "Failed to deallocate statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                                }
                        }
 
                                }
                        }
 
@@ -66,17 +66,17 @@ static void php_pqstm_deallocate(php_pqstm_object_t *obj, zend_bool async, zend_
        }
 }
 
        }
 }
 
-static void php_pqstm_object_free(void *o TSRMLS_DC)
+static void php_pqstm_object_free(zend_object *o)
 {
 {
-       php_pqstm_object_t *obj = o;
+       php_pqstm_object_t *obj = PHP_PQ_OBJ(NULL, o);
 #if DBG_GC
 #if DBG_GC
-       fprintf(stderr, "FREE stm(#%d) %p (conn(#%d): %p)\n", obj->zv.handle, obj, obj->intern->conn->zv.handle, obj->intern->conn);
+       fprintf(stderr, "FREE stm(#%d) %p (conn(#%d): %p)\n", obj->zo.handle, obj, obj->intern->conn->zo.handle, obj->intern->conn);
 #endif
        if (obj->intern) {
                if (obj->intern->conn->intern) {
                        php_pq_callback_dtor(&obj->intern->conn->intern->onevent);
 #endif
        if (obj->intern) {
                if (obj->intern->conn->intern) {
                        php_pq_callback_dtor(&obj->intern->conn->intern->onevent);
-                       php_pqstm_deallocate(obj, 0, 1 TSRMLS_CC);
-                       php_pq_object_delref(obj->intern->conn TSRMLS_CC);
+                       php_pqstm_deallocate(obj, 0, 1);
+                       php_pq_object_delref(obj->intern->conn);
                }
                efree(obj->intern->name);
                efree(obj->intern->query);
                }
                efree(obj->intern->name);
                efree(obj->intern->query);
@@ -87,60 +87,51 @@ static void php_pqstm_object_free(void *o TSRMLS_DC)
                efree(obj->intern);
                obj->intern = NULL;
        }
                efree(obj->intern);
                obj->intern = NULL;
        }
-       zend_object_std_dtor((zend_object *) o TSRMLS_CC);
-       efree(obj);
+       php_pq_object_dtor(o);
 }
 
 }
 
-zend_object_value php_pqstm_create_object_ex(zend_class_entry *ce, php_pqstm_t *intern, php_pqstm_object_t **ptr TSRMLS_DC)
+php_pqstm_object_t *php_pqstm_create_object_ex(zend_class_entry *ce, php_pqstm_t *intern)
 {
 {
-       php_pqstm_object_t *o;
-
-       o = ecalloc(1, sizeof(*o));
-       zend_object_std_init((zend_object *) o, ce TSRMLS_CC);
-       object_properties_init((zend_object *) o, ce);
-       o->prophandler = &php_pqstm_object_prophandlers;
-
-       if (ptr) {
-               *ptr = o;
-       }
-
-       if (intern) {
-               o->intern = intern;
-       }
-
-       o->zv.handle = zend_objects_store_put((zend_object *) o, NULL, php_pqstm_object_free, NULL TSRMLS_CC);
-       o->zv.handlers = &php_pqstm_object_handlers;
+       return php_pq_object_create(ce, intern, sizeof(php_pqstm_object_t),
+                       &php_pqstm_object_handlers, &php_pqstm_object_prophandlers);
+}
 
 
-       return o->zv;
+static zend_object *php_pqstm_create_object(zend_class_entry *class_type)
+{
+       return &php_pqstm_create_object_ex(class_type, NULL)->zo;
 }
 
 }
 
-static zend_object_value php_pqstm_create_object(zend_class_entry *class_type TSRMLS_DC)
+static void php_pqstm_object_read_name(zval *object, void *o, zval *return_value)
 {
 {
-       return php_pqstm_create_object_ex(class_type, NULL, NULL TSRMLS_CC);
+       php_pqstm_object_t *obj = o;
+
+       RETVAL_STRING(obj->intern->name);
 }
 
 }
 
-static void php_pqstm_object_read_name(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqstm_object_read_connection(zval *object, void *o, zval *return_value)
 {
        php_pqstm_object_t *obj = o;
 
 {
        php_pqstm_object_t *obj = o;
 
-       RETVAL_STRING(obj->intern->name, 1);
+       php_pq_object_to_zval(obj->intern->conn, return_value);
 }
 
 }
 
-static void php_pqstm_object_read_connection(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqstm_object_gc_connection(zval *object, void *o, zval *return_value)
 {
        php_pqstm_object_t *obj = o;
 {
        php_pqstm_object_t *obj = o;
+       zval zconn;
 
 
-       php_pq_object_to_zval(obj->intern->conn, &return_value TSRMLS_CC);
+       php_pq_object_to_zval_no_addref(obj->intern->conn, &zconn);
+       add_next_index_zval(return_value, &zconn);
 }
 
 }
 
-static void php_pqstm_object_read_query(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqstm_object_read_query(zval *object, void *o, zval *return_value)
 {
        php_pqstm_object_t *obj = o;
 
 {
        php_pqstm_object_t *obj = o;
 
-       RETVAL_STRING(obj->intern->query, 1);
+       RETVAL_STRING(obj->intern->query);
 }
 
 }
 
-static void php_pqstm_object_read_types(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqstm_object_read_types(zval *object, void *o, zval *return_value)
 {
        int i;
        php_pqstm_object_t *obj = o;
 {
        int i;
        php_pqstm_object_t *obj = o;
@@ -151,11 +142,11 @@ static void php_pqstm_object_read_types(zval *object, void *o, zval *return_valu
        }
 }
 
        }
 }
 
-php_pqstm_t *php_pqstm_init(php_pqconn_object_t *conn, const char *name, const char *query, php_pq_params_t *params TSRMLS_DC)
+php_pqstm_t *php_pqstm_init(php_pqconn_object_t *conn, const char *name, const char *query, php_pq_params_t *params)
 {
        php_pqstm_t *stm = ecalloc(1, sizeof(*stm));
 
 {
        php_pqstm_t *stm = ecalloc(1, sizeof(*stm));
 
-       php_pq_object_addref(conn TSRMLS_CC);
+       php_pq_object_addref(conn);
        stm->conn = conn;
        stm->name = estrdup(name);
        stm->params = params;
        stm->conn = conn;
        stm->name = estrdup(name);
        stm->params = params;
@@ -178,33 +169,33 @@ static PHP_METHOD(pqstm, __construct) {
        zend_error_handling zeh;
        zval *zconn, *ztypes = NULL;
        char *name_str, *query_str;
        zend_error_handling zeh;
        zval *zconn, *ztypes = NULL;
        char *name_str, *query_str;
-       int name_len, *query_len;
+       size_t name_len, *query_len;
        zend_bool async = 0;
        ZEND_RESULT_CODE rv;
 
        zend_bool async = 0;
        ZEND_RESULT_CODE rv;
 
-       zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
-       rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Oss|a/!b", &zconn, php_pqconn_class_entry, &name_str, &name_len, &query_str, &query_len, &ztypes, &async);
-       zend_restore_error_handling(&zeh TSRMLS_CC);
+       zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
+       rv = zend_parse_parameters(ZEND_NUM_ARGS(), "Oss|a/!b", &zconn, php_pqconn_class_entry, &name_str, &name_len, &query_str, &query_len, &ztypes, &async);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
 
        if (SUCCESS == rv) {
-               php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-               php_pqconn_object_t *conn_obj = zend_object_store_get_object(zconn TSRMLS_CC);
+               php_pqstm_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
+               php_pqconn_object_t *conn_obj = PHP_PQ_OBJ(zconn, NULL);
 
                if (obj->intern) {
 
                if (obj->intern) {
-                       throw_exce(EX_BAD_METHODCALL TSRMLS_CC, "pq\\Statement already initialized");
+                       throw_exce(EX_BAD_METHODCALL, "pq\\Statement already initialized");
                } else if (!conn_obj->intern) {
                } else if (!conn_obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
                } else {
-                       php_pq_params_t *params = php_pq_params_init(&conn_obj->intern->converters, ztypes ? Z_ARRVAL_P(ztypes) : NULL, NULL TSRMLS_CC);
+                       php_pq_params_t *params = php_pq_params_init(&conn_obj->intern->converters, ztypes ? Z_ARRVAL_P(ztypes) : NULL, NULL);
 
                        if (async) {
 
                        if (async) {
-                               rv = php_pqconn_prepare_async(zconn, conn_obj, name_str, query_str, params TSRMLS_CC);
+                               rv = php_pqconn_prepare_async(zconn, conn_obj, name_str, query_str, params);
                        } else {
                        } else {
-                               rv = php_pqconn_prepare(zconn, conn_obj, name_str, query_str, params TSRMLS_CC);
+                               rv = php_pqconn_prepare(zconn, conn_obj, name_str, query_str, params);
                        }
 
                        if (SUCCESS == rv) {
                        }
 
                        if (SUCCESS == rv) {
-                               obj->intern = php_pqstm_init(conn_obj, name_str, query_str, params TSRMLS_CC);
+                               obj->intern = php_pqstm_init(conn_obj, name_str, query_str, params);
                        }
                }
        }
                        }
                }
        }
@@ -214,27 +205,26 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_bind, 0, 0, 2)
        ZEND_ARG_INFO(1, param_ref)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqstm, bind) {
        ZEND_ARG_INFO(1, param_ref)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqstm, bind) {
-       long param_no;
-       zval **param_ref;
+       zend_long param_no;
+       zval *param_ref;
        zend_error_handling zeh;
        ZEND_RESULT_CODE rv;
 
        zend_error_handling zeh;
        ZEND_RESULT_CODE rv;
 
-       zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
-       rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lZ", &param_no, &param_ref);
-       zend_restore_error_handling(&zeh TSRMLS_CC);
+       zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
+       rv = zend_parse_parameters(ZEND_NUM_ARGS(), "lz", &param_no, &param_ref);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
 
        if (SUCCESS == rv) {
-               php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqstm_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Statement not initialized");
                } else if (!obj->intern->allocated) {
                } else if (!obj->intern->allocated) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement has been deallocated");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Statement has been deallocated");
                } else {
                } else {
-                       SEPARATE_ZVAL_TO_MAKE_IS_REF(param_ref);
-                       Z_ADDREF_PP(param_ref);
-                       zend_hash_index_update(&obj->intern->bound, param_no, (void *) param_ref, sizeof(zval *), NULL);
-                       zend_hash_sort(&obj->intern->bound, zend_qsort, php_pq_compare_index, 0 TSRMLS_CC);
+                       Z_ADDREF_P(param_ref);
+                       zend_hash_index_update(&obj->intern->bound, param_no, param_ref);
+                       zend_hash_sort(&obj->intern->bound, php_pq_compare_index, 0);
                }
        }
 }
                }
        }
 }
@@ -247,17 +237,17 @@ static PHP_METHOD(pqstm, exec) {
        zval *zparams = NULL;
        ZEND_RESULT_CODE rv;
 
        zval *zparams = NULL;
        ZEND_RESULT_CODE rv;
 
-       zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
-       rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a/!", &zparams);
-       zend_restore_error_handling(&zeh TSRMLS_CC);
+       zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
+       rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|a/!", &zparams);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
 
        if (SUCCESS == rv) {
-               php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqstm_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Statement not initialized");
                } else if (!obj->intern->allocated) {
                } else if (!obj->intern->allocated) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement has been deallocated");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Statement has been deallocated");
                } else {
                        PGresult *res;
 
                } else {
                        PGresult *res;
 
@@ -266,10 +256,10 @@ static PHP_METHOD(pqstm, exec) {
                        php_pq_params_set_params(obj->intern->params, NULL);
 
                        if (!res) {
                        php_pq_params_set_params(obj->intern->params, NULL);
 
                        if (!res) {
-                               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to execute statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
-                       } else if (SUCCESS == php_pqres_success(res TSRMLS_CC)) {
-                               php_pq_object_to_zval_no_addref(PQresultInstanceData(res, php_pqconn_event), &return_value TSRMLS_CC);
-                               php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
+                               throw_exce(EX_RUNTIME, "Failed to execute statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+                       } else if (SUCCESS == php_pqres_success(res)) {
+                               php_pq_object_to_zval_no_addref(PQresultInstanceData(res, php_pqconn_event), return_value);
+                               php_pqconn_notify_listeners(obj->intern->conn);
                        }
                }
        }
                        }
                }
        }
@@ -285,17 +275,17 @@ static PHP_METHOD(pqstm, execAsync) {
        php_pq_callback_t resolver = {{0}};
        ZEND_RESULT_CODE rv;
 
        php_pq_callback_t resolver = {{0}};
        ZEND_RESULT_CODE rv;
 
-       zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
-       rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a/!f", &zparams, &resolver.fci, &resolver.fcc);
-       zend_restore_error_handling(&zeh TSRMLS_CC);
+       zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
+       rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|a/!f", &zparams, &resolver.fci, &resolver.fcc);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
 
        if (SUCCESS == rv) {
-               php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqstm_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Statement not initialized");
                } else if (!obj->intern->allocated) {
                } else if (!obj->intern->allocated) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement has been deallocated");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Statement has been deallocated");
                } else {
                        int rc;
 
                } else {
                        int rc;
 
@@ -304,17 +294,17 @@ static PHP_METHOD(pqstm, execAsync) {
                        php_pq_params_set_params(obj->intern->params, NULL);
 
                        if (!rc) {
                        php_pq_params_set_params(obj->intern->params, NULL);
 
                        if (!rc) {
-                               throw_exce(EX_IO TSRMLS_CC, "Failed to execute statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+                               throw_exce(EX_IO, "Failed to execute statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
 #if HAVE_PQSETSINGLEROWMODE
                        } else if (obj->intern->conn->intern->unbuffered && !PQsetSingleRowMode(obj->intern->conn->intern->conn)) {
 #if HAVE_PQSETSINGLEROWMODE
                        } else if (obj->intern->conn->intern->unbuffered && !PQsetSingleRowMode(obj->intern->conn->intern->conn)) {
-                               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to enable unbuffered mode (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+                               throw_exce(EX_RUNTIME, "Failed to enable unbuffered mode (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
 #endif
                        } else {
 #endif
                        } else {
-                               php_pq_callback_recurse(&obj->intern->conn->intern->onevent, &resolver TSRMLS_CC);
+                               php_pq_callback_recurse(&obj->intern->conn->intern->onevent, &resolver);
                                obj->intern->conn->intern->poller = PQconsumeInput;
                        }
 
                                obj->intern->conn->intern->poller = PQconsumeInput;
                        }
 
-                       php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
+                       php_pqconn_notify_listeners(obj->intern->conn);
                }
        }
 }
                }
        }
 }
@@ -325,24 +315,24 @@ static PHP_METHOD(pqstm, desc) {
        zend_error_handling zeh;
        ZEND_RESULT_CODE rv;
 
        zend_error_handling zeh;
        ZEND_RESULT_CODE rv;
 
-       zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
+       zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
        rv = zend_parse_parameters_none();
        rv = zend_parse_parameters_none();
-       zend_restore_error_handling(&zeh TSRMLS_CC);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
 
        if (SUCCESS == rv) {
-               php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqstm_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Statement not initialized");
                } else if (!obj->intern->allocated) {
                } else if (!obj->intern->allocated) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement has been deallocated");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Statement has been deallocated");
                } else {
                        PGresult *res = PQdescribePrepared(obj->intern->conn->intern->conn, obj->intern->name);
 
                        if (!res) {
                } else {
                        PGresult *res = PQdescribePrepared(obj->intern->conn->intern->conn, obj->intern->name);
 
                        if (!res) {
-                               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to describe statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+                               throw_exce(EX_RUNTIME, "Failed to describe statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                        } else {
                        } else {
-                               if (SUCCESS == php_pqres_success(res TSRMLS_CC)) {
+                               if (SUCCESS == php_pqres_success(res)) {
                                        int p, params;
 
                                        array_init(return_value);
                                        int p, params;
 
                                        array_init(return_value);
@@ -351,7 +341,7 @@ static PHP_METHOD(pqstm, desc) {
                                        }
                                }
                                php_pqres_clear(res);
                                        }
                                }
                                php_pqres_clear(res);
-                               php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
+                               php_pqconn_notify_listeners(obj->intern->conn);
                        }
                }
        }
                        }
                }
        }
@@ -365,23 +355,23 @@ static PHP_METHOD(pqstm, descAsync) {
        php_pq_callback_t resolver = {{0}};
        ZEND_RESULT_CODE rv;
 
        php_pq_callback_t resolver = {{0}};
        ZEND_RESULT_CODE rv;
 
-       zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
-       rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f", &resolver.fci, &resolver.fcc);
-       zend_restore_error_handling(&zeh TSRMLS_CC);
+       zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
+       rv = zend_parse_parameters(ZEND_NUM_ARGS(), "f", &resolver.fci, &resolver.fcc);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
 
        if (SUCCESS == rv) {
-               php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqstm_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Statement not initialized");
                } else if (!obj->intern->allocated) {
                } else if (!obj->intern->allocated) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement has been deallocated");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Statement has been deallocated");
                } else if (!PQsendDescribePrepared(obj->intern->conn->intern->conn, obj->intern->name)) {
                } else if (!PQsendDescribePrepared(obj->intern->conn->intern->conn, obj->intern->name)) {
-                       throw_exce(EX_IO TSRMLS_CC, "Failed to describe statement: %s", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+                       throw_exce(EX_IO, "Failed to describe statement: %s", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                } else {
                } else {
-                       php_pq_callback_recurse(&obj->intern->conn->intern->onevent, &resolver TSRMLS_CC);
+                       php_pq_callback_recurse(&obj->intern->conn->intern->onevent, &resolver);
                        obj->intern->conn->intern->poller = PQconsumeInput;
                        obj->intern->conn->intern->poller = PQconsumeInput;
-                       php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
+                       php_pqconn_notify_listeners(obj->intern->conn);
                }
        }
 }
                }
        }
 }
@@ -391,17 +381,17 @@ static zend_always_inline void php_pqstm_deallocate_handler(INTERNAL_FUNCTION_PA
        zend_error_handling zeh;
        ZEND_RESULT_CODE rv;
 
        zend_error_handling zeh;
        ZEND_RESULT_CODE rv;
 
-       zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
+       zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
        rv = zend_parse_parameters_none();
        rv = zend_parse_parameters_none();
-       zend_restore_error_handling(&zeh TSRMLS_CC);
+       zend_restore_error_handling(&zeh);
 
        if (rv == SUCCESS) {
 
        if (rv == SUCCESS) {
-               php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqstm_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Statement not initialized");
                } else {
                } else {
-                       php_pqstm_deallocate(obj, async, 0 TSRMLS_CC);
+                       php_pqstm_deallocate(obj, async, 0);
                }
        }
 }
                }
        }
 }
@@ -425,20 +415,20 @@ static zend_always_inline void php_pqstm_prepare_handler(INTERNAL_FUNCTION_PARAM
        zend_error_handling zeh;
        ZEND_RESULT_CODE rv;
 
        zend_error_handling zeh;
        ZEND_RESULT_CODE rv;
 
-       zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
+       zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
        rv = zend_parse_parameters_none();
        rv = zend_parse_parameters_none();
-       zend_restore_error_handling(&zeh TSRMLS_CC);
+       zend_restore_error_handling(&zeh);
 
        if (rv == SUCCESS) {
 
        if (rv == SUCCESS) {
-               php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqstm_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Statement not initialized");
                } else if (!obj->intern->allocated) {
                        if (async) {
                } else if (!obj->intern->allocated) {
                        if (async) {
-                               rv = php_pqconn_prepare_async(NULL, obj->intern->conn, obj->intern->name, obj->intern->query, obj->intern->params TSRMLS_CC);
+                               rv = php_pqconn_prepare_async(NULL, obj->intern->conn, obj->intern->name, obj->intern->query, obj->intern->params);
                        } else {
                        } else {
-                               rv = php_pqconn_prepare(NULL, obj->intern->conn, obj->intern->name, obj->intern->query, obj->intern->params TSRMLS_CC);
+                               rv = php_pqconn_prepare(NULL, obj->intern->conn, obj->intern->name, obj->intern->query, obj->intern->params);
                        }
 
                        if (SUCCESS == rv) {
                        }
 
                        if (SUCCESS == rv) {
@@ -488,35 +478,39 @@ PHP_MINIT_FUNCTION(pqstm)
        php_pq_object_prophandler_t ph = {0};
 
        INIT_NS_CLASS_ENTRY(ce, "pq", "Statement", php_pqstm_methods);
        php_pq_object_prophandler_t ph = {0};
 
        INIT_NS_CLASS_ENTRY(ce, "pq", "Statement", php_pqstm_methods);
-       php_pqstm_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
+       php_pqstm_class_entry = zend_register_internal_class_ex(&ce, NULL);
        php_pqstm_class_entry->create_object = php_pqstm_create_object;
 
        memcpy(&php_pqstm_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
        php_pqstm_class_entry->create_object = php_pqstm_create_object;
 
        memcpy(&php_pqstm_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+       php_pqstm_object_handlers.offset = XtOffsetOf(php_pqstm_object_t, zo);
+       php_pqstm_object_handlers.free_obj = php_pqstm_object_free;
        php_pqstm_object_handlers.read_property = php_pq_object_read_prop;
        php_pqstm_object_handlers.write_property = php_pq_object_write_prop;
        php_pqstm_object_handlers.clone_obj = NULL;
        php_pqstm_object_handlers.get_property_ptr_ptr = NULL;
        php_pqstm_object_handlers.read_property = php_pq_object_read_prop;
        php_pqstm_object_handlers.write_property = php_pq_object_write_prop;
        php_pqstm_object_handlers.clone_obj = NULL;
        php_pqstm_object_handlers.get_property_ptr_ptr = NULL;
-       php_pqstm_object_handlers.get_gc = NULL;
+       php_pqstm_object_handlers.get_gc = php_pq_object_get_gc;
        php_pqstm_object_handlers.get_properties = php_pq_object_properties;
        php_pqstm_object_handlers.get_debug_info = php_pq_object_debug_info;
 
        php_pqstm_object_handlers.get_properties = php_pq_object_properties;
        php_pqstm_object_handlers.get_debug_info = php_pq_object_debug_info;
 
-       zend_hash_init(&php_pqstm_object_prophandlers, 2, NULL, NULL, 1);
+       zend_hash_init(&php_pqstm_object_prophandlers, 4, NULL, php_pq_object_prophandler_dtor, 1);
 
 
-       zend_declare_property_null(php_pqstm_class_entry, ZEND_STRL("name"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_null(php_pqstm_class_entry, ZEND_STRL("name"), ZEND_ACC_PUBLIC);
        ph.read = php_pqstm_object_read_name;
        ph.read = php_pqstm_object_read_name;
-       zend_hash_add(&php_pqstm_object_prophandlers, "name", sizeof("name"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqstm_object_prophandlers, "name", sizeof("name")-1, (void *) &ph, sizeof(ph));
 
 
-       zend_declare_property_null(php_pqstm_class_entry, ZEND_STRL("connection"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_null(php_pqstm_class_entry, ZEND_STRL("connection"), ZEND_ACC_PUBLIC);
        ph.read = php_pqstm_object_read_connection;
        ph.read = php_pqstm_object_read_connection;
-       zend_hash_add(&php_pqstm_object_prophandlers, "connection", sizeof("connection"), (void *) &ph, sizeof(ph), NULL);
+       ph.gc = php_pqstm_object_gc_connection;
+       zend_hash_str_add_mem(&php_pqstm_object_prophandlers, "connection", sizeof("connection")-1, (void *) &ph, sizeof(ph));
+       ph.gc = NULL;
 
 
-       zend_declare_property_null(php_pqstm_class_entry, ZEND_STRL("query"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_null(php_pqstm_class_entry, ZEND_STRL("query"), ZEND_ACC_PUBLIC);
        ph.read = php_pqstm_object_read_query;
        ph.read = php_pqstm_object_read_query;
-       zend_hash_add(&php_pqstm_object_prophandlers, "query", sizeof("query"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqstm_object_prophandlers, "query", sizeof("query")-1, (void *) &ph, sizeof(ph));
 
 
-       zend_declare_property_null(php_pqstm_class_entry, ZEND_STRL("types"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_null(php_pqstm_class_entry, ZEND_STRL("types"), ZEND_ACC_PUBLIC);
        ph.read = php_pqstm_object_read_types;
        ph.read = php_pqstm_object_read_types;
-       zend_hash_add(&php_pqstm_object_prophandlers, "types", sizeof("types"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqstm_object_prophandlers, "types", sizeof("types")-1, (void *) &ph, sizeof(ph));
 
        return SUCCESS;
 }
 
        return SUCCESS;
 }