flush
authorMichael Wallner <mike@php.net>
Mon, 17 Aug 2015 08:19:30 +0000 (10:19 +0200)
committerMichael Wallner <mike@php.net>
Mon, 17 Aug 2015 08:19:30 +0000 (10:19 +0200)
30 files changed:
gen_travis_yml.php
php_pq.h
src/php_pq_callback.c
src/php_pq_callback.h
src/php_pq_misc.c
src/php_pq_misc.h
src/php_pq_module.c
src/php_pq_object.c
src/php_pq_object.h
src/php_pq_params.c
src/php_pq_params.h
src/php_pqcancel.c
src/php_pqcancel.h
src/php_pqconn.c
src/php_pqconn.h
src/php_pqconn_event.c
src/php_pqconn_event.h
src/php_pqcopy.c
src/php_pqcopy.h
src/php_pqcur.c
src/php_pqcur.h
src/php_pqexc.c
src/php_pqexc.h
src/php_pqlob.c
src/php_pqlob.h
src/php_pqres.c
src/php_pqres.h
src/php_pqstm.h
src/php_pqtxn.h
src/php_pqtypes.h

index 87b025d4372db6c623117bf56f371848be47f058..804dad0831e043da50c246692c679a724c7ed1d2 100755 (executable)
@@ -17,7 +17,7 @@ env:
 
 $gen = include "./travis/pecl/gen-matrix.php";
 $env = $gen([
-       "PHP" => ["5.4", "5.5", "5.6"],
+       "PHP" => ["master"],
        "enable_debug",
        "enable_maintainer_zts",
        "enable_json",
index 3b26130e390318d8bc5424a9da34935f5966a52c..cfdb095aeb3ecd23d33b813a78a289298b0d7199 100644 (file)
--- a/php_pq.h
+++ b/php_pq.h
@@ -14,7 +14,7 @@
 #ifndef PHP_PQ_H
 #define PHP_PQ_H
 
-#define PHP_PQ_VERSION "0.6.0RC2"
+#define PHP_PQ_VERSION "2.0.0dev"
 
 #ifdef PHP_WIN32
 #      define PHP_PQ_API __declspec(dllexport)
@@ -28,14 +28,20 @@ extern int pq_module_number;
 extern zend_module_entry pq_module_entry;
 #define phpext_pq_ptr &pq_module_entry
 
+ZEND_BEGIN_MODULE_GLOBALS(php_pq)
+       struct {
+               /* for ext-raphf */
+               zend_string *name;
+       } connection;
+ZEND_END_MODULE_GLOBALS(php_pq)
+
+ZEND_EXTERN_MODULE_GLOBALS(php_pq);
 
 #ifdef ZTS
-#      include "TSRM.h"
-#      define TSRMLS_DF(d) TSRMLS_D = (d)->ts
-#      define TSRMLS_CF(d) (d)->ts = TSRMLS_C
+#      include "TSRM/TSRM.h"
+#      define PHP_PQ_G ((zend_php_pq_globals *) (*((void ***) tsrm_get_ls_cache()))[TSRM_UNSHUFFLE_RSRC_ID(php_pq_globals_id)])
 #else
-#      define TSRMLS_DF(d)
-#      define TSRMLS_CF(d)
+#      define PHP_PQ_G (&php_pq_globals)
 #endif
 
 #endif /* PHP_PQ_H */
index 63f2edc4bab570523b133bcf027c1a4bb94e9b95..6b0213f8ac5ed744ce58c4a685d419bcb5fd5149 100644 (file)
@@ -29,8 +29,8 @@ void php_pq_callback_dtor(php_pq_callback_t *cb)
        if (cb->fci.size > 0) {
                zend_fcall_info_args_clear(&cb->fci, 1);
                zval_ptr_dtor(&cb->fci.function_name);
-               if (cb->fci.object_ptr) {
-                       zval_ptr_dtor(&cb->fci.object_ptr);
+               if (cb->fci.object) {
+                       zend_objects_store_del(cb->fci.object);
                }
                cb->fci.size = 0;
        }
@@ -38,34 +38,35 @@ void php_pq_callback_dtor(php_pq_callback_t *cb)
 
 void php_pq_callback_addref(php_pq_callback_t *cb)
 {
-       Z_ADDREF_P(cb->fci.function_name);
-       if (cb->fci.object_ptr) {
-               Z_ADDREF_P(cb->fci.object_ptr);
+       Z_TRY_ADDREF(cb->fci.function_name);
+       if (cb->fci.object) {
+               ++GC_REFCOUNT(cb->fci.object);
        }
 }
 
-zval *php_pq_callback_to_zval(php_pq_callback_t *cb)
+zval *php_pq_callback_to_zval(php_pq_callback_t *cb, zval *tmp)
 {
-       zval *zcb;
-
        php_pq_callback_addref(cb);
 
-       if (cb->fci.object_ptr) {
-               MAKE_STD_ZVAL(zcb);
-               array_init_size(zcb, 2);
-               add_next_index_zval(zcb, cb->fci.object_ptr);
-               add_next_index_zval(zcb, cb->fci.function_name);
-       } else {
-               zcb = cb->fci.function_name;
+       if (cb->fci.object) {
+               zval zo;
+
+               array_init_size(tmp, 2);
+               ZVAL_OBJ(&zo, cb->fci.object);
+               add_next_index_zval(tmp, &zo);
+               add_next_index_zval(tmp, &cb->fci.function_name);
+
+               return tmp;
        }
 
-       return zcb;
+       return &cb->fci.function_name;
 }
 
-zend_bool php_pq_callback_is_locked(php_pq_callback_t *cb TSRMLS_DC)
+zend_bool php_pq_callback_is_locked(php_pq_callback_t *cb)
 {
+       /* TODO: fixed in php7?
        if (cb->fci.size > 0 && Z_TYPE_P(cb->fci.function_name) == IS_OBJECT) {
-               const zend_function *closure = zend_get_closure_method_def(cb->fci.function_name TSRMLS_CC);
+               const zend_function *closure = zend_get_closure_method_def(cb->fci.function_name);
 
                if (closure->type == ZEND_USER_FUNCTION) {
                        zend_execute_data *ex = EG(current_execute_data);
@@ -78,6 +79,7 @@ zend_bool php_pq_callback_is_locked(php_pq_callback_t *cb TSRMLS_DC)
                        }
                }
        }
+       */
        return 0;
 }
 
index 2edf6d526bb54eac265e529d629983faee901ba8..23521a8bc780b3010326f4fb0b885d004d95310d 100644 (file)
@@ -23,9 +23,9 @@ typedef struct php_pq_callback {
 
 extern void php_pq_callback_dtor(php_pq_callback_t *cb);
 extern void php_pq_callback_addref(php_pq_callback_t *cb);
-extern zval *php_pq_callback_to_zval(php_pq_callback_t *cb);
-extern zend_bool php_pq_callback_is_locked(php_pq_callback_t *cb TSRMLS_DC);
-extern void php_pq_callback_recurse(php_pq_callback_t *old, php_pq_callback_t *new TSRMLS_DC);
+extern zval *php_pq_callback_to_zval(php_pq_callback_t *cb, zval *tmp);
+extern zend_bool php_pq_callback_is_locked(php_pq_callback_t *cb);
+extern void php_pq_callback_recurse(php_pq_callback_t *old, php_pq_callback_t *new);
 
 #endif
 
index a3db8bbcd52827c0f1258d4a841a77fa55975042..484d760ff085cb024a7ac505efa0a755aec7651e 100644 (file)
@@ -52,7 +52,7 @@ const char *php_pq_strmode(long mode)
        }
 }
 
-int php_pq_compare_index(const void *lptr, const void *rptr TSRMLS_DC)
+int php_pq_compare_index(const void *lptr, const void *rptr)
 {
        const Bucket *l = *(const Bucket **) lptr;
        const Bucket *r = *(const Bucket **) rptr;
@@ -72,13 +72,12 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqdt_to_string, 0, 0, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqdt, __toString)
 {
-       zval *rv = NULL;
+       zval rv, tmp;
 
-       zend_call_method_with_1_params(&getThis(), php_pqdt_class_entry, NULL, "format", &rv,
-                       zend_read_property(php_pqdt_class_entry, getThis(), ZEND_STRL("format"), 0 TSRMLS_CC));
-       if (rv) {
-               RETVAL_ZVAL(rv, 1, 1);
-       }
+       ZVAL_NULL(&rv);
+       zend_call_method_with_1_params(getThis(), php_pqdt_class_entry, NULL, "format", &rv,
+                       zend_read_property(php_pqdt_class_entry, getThis(), ZEND_STRL("format"), 0, &tmp));
+       RETVAL_ZVAL(&rv, 1, 1);
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_pqdt_create_from_format, 0, 0, 2)
@@ -94,12 +93,12 @@ static PHP_METHOD(pqdt, createFromFormat)
        zval *ztz = 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, "ss|O", &fmt_str, &fmt_len, &dt_str, &dt_len, &ztz, php_date_get_timezone_ce());
-       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(), "ss|O", &fmt_str, &fmt_len, &dt_str, &dt_len, &ztz, php_date_get_timezone_ce());
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqdt_from_string(return_value, fmt_str, dt_str, dt_len, "Y-m-d H:i:s.uO", ztz TSRMLS_CC);
+               php_pqdt_from_string(return_value, fmt_str, dt_str, dt_len, "Y-m-d H:i:s.uO", ztz);
        }
 }
 
@@ -110,54 +109,47 @@ static zend_function_entry php_pqdt_methods[] = {
        {0}
 };
 
-zval *php_pqdt_from_string(zval *zv, char *input_fmt, char *dt_str, size_t dt_len, char *output_fmt, zval *ztimezone TSRMLS_DC)
+zval *php_pqdt_from_string(zval *zv, char *input_fmt, char *dt_str, size_t dt_len, char *output_fmt, zval *ztimezone)
 {
        php_date_obj *dobj;
 
-       if (!zv) {
-               MAKE_STD_ZVAL(zv);
-       }
-
-       php_date_instantiate(php_pqdt_class_entry, zv TSRMLS_CC);
-       dobj = zend_object_store_get_object(zv TSRMLS_CC);
-       if (!php_date_initialize(dobj, dt_str, dt_len, input_fmt, ztimezone, 1 TSRMLS_CC)) {
+       php_date_instantiate(php_pqdt_class_entry, zv);
+       dobj = php_date_obj_from_obj(Z_OBJ_P(zv));
+       if (!php_date_initialize(dobj, dt_str, dt_len, input_fmt, ztimezone, 1)) {
                zval_dtor(zv);
                ZVAL_NULL(zv);
        } else if (output_fmt) {
-               zend_update_property_string(php_pqdt_class_entry, zv, ZEND_STRL("format"), output_fmt TSRMLS_CC);
+               zend_update_property_string(php_pqdt_class_entry, zv, ZEND_STRL("format"), output_fmt);
        }
 
        return zv;
 }
 
-void php_pqdt_to_string(zval *zdt, const char *format, char **str_buf, size_t *str_len TSRMLS_DC)
+zend_string *php_pqdt_to_string(zval *zdt, const char *format)
 {
        zval rv;
 
-       INIT_PZVAL(&rv);
        ZVAL_NULL(&rv);
 
        if (Z_OBJ_HT_P(zdt)->cast_object
-       &&      SUCCESS == Z_OBJ_HT_P(zdt)->cast_object(zdt, &rv, IS_STRING TSRMLS_CC)
+       &&      SUCCESS == Z_OBJ_HT_P(zdt)->cast_object(zdt, &rv, IS_STRING)
        ) {
-               *str_len = Z_STRLEN(rv);
-               *str_buf = Z_STRVAL(rv);
-       } else if (instanceof_function(Z_OBJCE_P(zdt), php_date_get_date_ce() TSRMLS_CC)) {
-               zval *rv = NULL, *zfmt;
-
-               MAKE_STD_ZVAL(zfmt);
-               ZVAL_STRING(zfmt, format, 1);
-               zend_call_method_with_1_params(&zdt, Z_OBJCE_P(zdt), NULL, "format", &rv, zfmt);
+               return Z_STR(rv);
+       } else if (instanceof_function(Z_OBJCE_P(zdt), php_date_get_date_ce())) {
+               zval rv, zfmt;
+
+               ZVAL_NULL(&rv);
+               ZVAL_STRING(&zfmt, format);
+               zend_call_method_with_1_params(zdt, Z_OBJCE_P(zdt), NULL, "format", &rv, &zfmt);
                zval_ptr_dtor(&zfmt);
 
-               if (rv) {
-                       if (Z_TYPE_P(rv) == IS_STRING) {
-                               *str_len = Z_STRLEN_P(rv);
-                               *str_buf = estrndup(Z_STRVAL_P(rv), *str_len);
-                       }
-                       zval_ptr_dtor(&rv);
+               if (Z_TYPE(rv) == IS_STRING) {
+                       return Z_STR(rv);
                }
+               zval_ptr_dtor(&rv);
        }
+
+       return NULL;
 }
 
 zend_class_entry *php_pqconv_class_entry;
@@ -185,27 +177,27 @@ zend_function_entry php_pqconv_methods[] = {
 
 PHP_MINIT_FUNCTION(pq_misc)
 {
-       zend_class_entry **json, ce = {0};
+       zend_class_entry *json, ce = {0};
 
        INIT_NS_CLASS_ENTRY(ce, "pq", "Converter", php_pqconv_methods);
-       php_pqconv_class_entry = zend_register_internal_interface(&ce TSRMLS_CC);
+       php_pqconv_class_entry = zend_register_internal_interface(&ce);
 
        memset(&ce, 0, sizeof(ce));
        INIT_NS_CLASS_ENTRY(ce ,"pq", "DateTime", php_pqdt_methods);
-       php_pqdt_class_entry = zend_register_internal_class_ex(&ce, php_date_get_date_ce(), "DateTime" TSRMLS_CC);
+       php_pqdt_class_entry = zend_register_internal_class_ex(&ce, php_date_get_date_ce());
 
-       zend_declare_property_stringl(php_pqdt_class_entry, ZEND_STRL("format"), ZEND_STRL("Y-m-d H:i:s.uO"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_stringl(php_pqdt_class_entry, ZEND_STRL("format"), ZEND_STRL("Y-m-d H:i:s.uO"), ZEND_ACC_PUBLIC);
 
        /* stop reading this file right here! */
-       if (SUCCESS == zend_hash_find(CG(class_table), ZEND_STRS("jsonserializable"), (void *) &json)) {
-               zend_class_implements(php_pqdt_class_entry TSRMLS_CC, 1, *json);
+       if ((json = zend_hash_str_find_ptr(CG(class_table), ZEND_STRL("jsonserializable")))) {
+               zend_class_implements(php_pqdt_class_entry, 1, json);
        }
 
        return SUCCESS;
 }
 
 typedef struct _HashTableList {
-       HashTable ht;
+       zval arr;
        struct _HashTableList *parent;
 } HashTableList;
 
@@ -213,9 +205,6 @@ typedef struct _ArrayParserState {
        const char *ptr, *end;
        HashTableList *list;
        php_pqres_t *res;
-#ifdef ZTS
-       void ***ts;
-#endif
        Oid typ;
        unsigned quotes:1;
        unsigned escaped:1;
@@ -224,7 +213,6 @@ typedef struct _ArrayParserState {
 static char caa(ArrayParserState *a, const char *any, unsigned advance)
 {
        const char *p = any;
-       TSRMLS_FETCH_FROM_CTX(a->ts);
 
        do {
                if (*p == *a->ptr) {
@@ -233,38 +221,31 @@ static char caa(ArrayParserState *a, const char *any, unsigned advance)
                }
        } while (*++p);
 
-       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse array: expected one of '%s', got '%c'", any, *a->ptr); \
+       php_error_docref(NULL, E_WARNING, "Failed to parse array: expected one of '%s', got '%c'", any, *a->ptr); \
        return 0;
 }
 
 static ZEND_RESULT_CODE add_element(ArrayParserState *a, const char *start)
 {
-       zval *zelem;
-       size_t el_len = a->ptr - start;
-       char *el_str = estrndup(start, el_len);
-       TSRMLS_FETCH_FROM_CTX(a->ts);
+       zval zelem;
+       zend_string *zstr = zend_string_init(start, a->ptr - start, 0);
 
        if (a->quotes) {
-               int tmp_len = el_len;
-
-               php_stripslashes(el_str, &tmp_len TSRMLS_CC);
-               el_len = tmp_len;
-       } else if ((a->ptr - start == 4) && !strncmp(start, "NULL", 4)) {
-               efree(el_str);
-               el_str = NULL;
-               el_len = 0;
-       }
-
-       if (!el_str) {
-               MAKE_STD_ZVAL(zelem);
-               ZVAL_NULL(zelem);
+               php_stripslashes(zstr);
+               ZVAL_STR(&zelem, zstr);
+       } else if (!zend_string_equals_literal(zstr, "NULL")) {
+               ZVAL_STR(&zelem, zstr);
        } else {
-               zelem = php_pqres_typed_zval(a->res, el_str, el_len, a->typ TSRMLS_CC);
+               zend_string_release(zstr);
+               ZVAL_NULL(&zelem);
+       }
 
-               efree(el_str);
+       if (!ZVAL_IS_NULL(&zelem)) {
+               php_pqres_typed_zval(a->res, a->typ, &zelem);
        }
 
-       return zend_hash_next_index_insert(&a->list->ht, &zelem, sizeof(zval *), NULL);
+       add_next_index_zval(&a->list->arr, &zelem);
+       return SUCCESS;
 }
 
 static ZEND_RESULT_CODE parse_array(ArrayParserState *a);
@@ -272,7 +253,6 @@ static ZEND_RESULT_CODE parse_array(ArrayParserState *a);
 static ZEND_RESULT_CODE parse_element(ArrayParserState *a, char delim)
 {
        const char *el;
-       TSRMLS_FETCH_FROM_CTX(a->ts);
 
        switch (*a->ptr) {
        case '{':
@@ -301,7 +281,7 @@ static ZEND_RESULT_CODE parse_element(ArrayParserState *a, char delim)
                                ++a->ptr;
                                return SUCCESS;
                        } else {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse element, unexpected quote: '%.*s'", (int) (a->ptr - el), el);
+                               php_error_docref(NULL, E_WARNING, "Failed to parse element, unexpected quote: '%.*s'", (int) (a->ptr - el), el);
                                return FAILURE;
                        }
                        break;
@@ -321,14 +301,13 @@ static ZEND_RESULT_CODE parse_element(ArrayParserState *a, char delim)
                }
        }
 
-       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse element, reached end of input");
+       php_error_docref(NULL, E_WARNING, "Failed to parse element, reached end of input");
        return FAILURE;
 }
 
 static ZEND_RESULT_CODE parse_elements(ArrayParserState *a)
 {
        char delims[] = {'}', PHP_PQ_DELIM_OF_ARRAY(a->typ), 0};
-       TSRMLS_FETCH_FROM_CTX(a->ts);
 
        while (SUCCESS == parse_element(a, delims[1])) {
                switch (caa(a, delims, 0)) {
@@ -340,7 +319,7 @@ static ZEND_RESULT_CODE parse_elements(ArrayParserState *a)
 
                default:
                        if (!*++a->ptr) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse elements, reached end of input");
+                               php_error_docref(NULL, E_WARNING, "Failed to parse elements, reached end of input");
                                return FAILURE;
                        }
                        break;
@@ -359,17 +338,10 @@ static ZEND_RESULT_CODE parse_array(ArrayParserState *a)
        }
 
        list = ecalloc(1, sizeof(*list));
-       ZEND_INIT_SYMTABLE(&list->ht);
+       ZVAL_NEW_ARR(&list->arr);
 
        if (a->list) {
-               zval *zcur;
-
-               MAKE_STD_ZVAL(zcur);
-               Z_TYPE_P(zcur) = IS_ARRAY;
-               Z_ARRVAL_P(zcur) = &list->ht;
-
-               zend_hash_next_index_insert(&a->list->ht, &zcur, sizeof(zval *), NULL);
-
+               add_next_index_zval(&a->list->arr, &list->arr);
                list->parent = a->list;
        }
        a->list = list;
@@ -393,7 +365,6 @@ HashTable *php_pq_parse_array(php_pqres_t *res, const char *val_str, size_t val_
 {
        HashTable *ht = NULL;
        ArrayParserState a = {0};
-       TSRMLS_SET_CTX(a.ts);
 
        a.typ = typ;
        a.ptr = val_str;
@@ -404,7 +375,7 @@ HashTable *php_pq_parse_array(php_pqres_t *res, const char *val_str, size_t val_
                while (a.list) {
                        HashTableList *l = a.list->parent;
 
-                       zend_hash_destroy(&a.list->ht);
+                       zval_dtor(&a.list->arr);
                        efree(a.list);
                        a.list = l;
                }
@@ -412,11 +383,11 @@ HashTable *php_pq_parse_array(php_pqres_t *res, const char *val_str, size_t val_
        }
 
        if (*a.ptr) {
-               php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Trailing input: '%s'", a.ptr);
+               php_error_docref(NULL, E_NOTICE, "Trailing input: '%s'", a.ptr);
        }
 
        do {
-               ht = &a.list->ht;
+               ht = Z_ARRVAL(a.list->arr);
        } while ((a.list = a.list->parent));
 
        return ht;
index 9fc086a21c40add13532f0ea881bd869ac32ff8c..937d7ad574d58b70f44aade326f602eeb2d33163 100644 (file)
@@ -27,12 +27,10 @@ typedef enum {
 
 #include "php_pqres.h"
 
-/* TSRM morony */
-#if PHP_VERSION_ID >= 50700
-#      define z_is_true(z) zend_is_true(z TSRMLS_CC)
-#else
-#      define z_is_true zend_is_true
-#endif
+#define z_is_true zend_is_true
+#define smart_str_s(ss) (ss)->s
+#define smart_str_v(ss) (ss)->s->val
+#define smart_str_l(ss) (ss)->s->len
 
 /* trim LF from EOL */
 extern char *php_pq_rtrim(char *e);
@@ -41,18 +39,18 @@ extern char *php_pq_rtrim(char *e);
 extern const char *php_pq_strmode(long mode);
 
 /* compare array index */
-extern int php_pq_compare_index(const void *lptr, const void *rptr TSRMLS_DC);
+extern int php_pq_compare_index(const void *lptr, const void *rptr);
 
 #define PHP_PQerrorMessage(c) php_pq_rtrim(PQerrorMessage((c)))
 #define PHP_PQresultErrorMessage(r) php_pq_rtrim(PQresultErrorMessage((r)))
 
 extern zend_class_entry *php_pqdt_class_entry;
-extern zval *php_pqdt_from_string(zval *zv, char *input_fmt, char *dt_str, size_t dt_len, char *output_fmt, zval *ztimezone TSRMLS_DC);
-extern void php_pqdt_to_string(zval *zdt, const char *format, char **str_buf, size_t *str_len TSRMLS_DC);
+extern zval *php_pqdt_from_string(zval *zv, char *input_fmt, char *dt_str, size_t dt_len, char *output_fmt, zval *ztimezone);
+extern zend_string *php_pqdt_to_string(zval *zdt, const char *format);
 
 extern zend_class_entry *php_pqconv_class_entry;
 
-extern HashTable *php_pq_parse_array(php_pqres_t *res, const char *val_str, size_t val_len, Oid typ TSRMLS_DC);
+extern HashTable *php_pq_parse_array(php_pqres_t *res, const char *val_str, size_t val_len, Oid typ);
 
 
 extern PHP_MINIT_FUNCTION(pq_misc);
index 989b7c8f5d11d701e653f7f5348b5b956c45ed61..53ec94c3c6b19aa193a360bdc5ae4d19ec959eca 100644 (file)
 #include "php_pqtxn.h"
 #include "php_pqtypes.h"
 
+ZEND_DECLARE_MODULE_GLOBALS(php_pq);
+
+static void php_pq_globals_init_once(zend_php_pq_globals *G)
+{
+       memset(G, 0, sizeof(*G));
+}
+
 #define PHP_MINIT_CALL(i) do { \
-       if (SUCCESS != PHP_MINIT(i)(type, module_number TSRMLS_CC)) { \
+       if (SUCCESS != PHP_MINIT(i)(type, module_number)) { \
                return FAILURE; \
        } \
 } while(0)
 
 static PHP_MINIT_FUNCTION(pq)
 {
+       ZEND_INIT_MODULE_GLOBALS(php_pq, php_pq_globals_init_once, NULL);
+
        PHP_MINIT_CALL(pq_misc);
        PHP_MINIT_CALL(pqexc);
 
@@ -56,19 +65,17 @@ static PHP_MINIT_FUNCTION(pq)
        PHP_MINIT_CALL(pqcopy);
        PHP_MINIT_CALL(pqlob);
 
-       return php_persistent_handle_provide(ZEND_STRL("pq\\Connection"), php_pqconn_get_resource_factory_ops(), NULL, NULL TSRMLS_CC);
+       return SUCCESS;
 }
 
 #define PHP_MSHUT_CALL(i) do { \
-       if (SUCCESS != PHP_MSHUTDOWN(i)(type, module_number TSRMLS_CC)) { \
+       if (SUCCESS != PHP_MSHUTDOWN(i)(type, module_number)) { \
                return FAILURE; \
        } \
 } while(0)
 
 static PHP_MSHUTDOWN_FUNCTION(pq)
 {
-       php_persistent_handle_cleanup(ZEND_STRL("pq\\Connection"), NULL, 0 TSRMLS_CC);
-
        PHP_MSHUT_CALL(pqlob);
        PHP_MSHUT_CALL(pqcopy);
        PHP_MSHUT_CALL(pqcur);
index f362060804fae79602242d9d90b2fbdd74832bda..bfab4101402fb98bdd50bd7aadeb0804ddf94dea 100644 (file)
 
 #include "php_pq_object.h"
 
-void php_pq_object_to_zval(void *o, zval **zv TSRMLS_DC)
+void php_pq_object_to_zval(void *o, zval *zv)
 {
        php_pq_object_t *obj = o;
 
-       if (!*zv) {
-               MAKE_STD_ZVAL(*zv);
-       }
-
-       zend_objects_store_add_ref_by_handle(obj->zv.handle TSRMLS_CC);
-
-       (*zv)->type = IS_OBJECT;
-       (*zv)->value.obj = obj->zv;
+       ZVAL_OBJ(zv, &obj->zo);
+       Z_ADDREF_P(zv);
 }
 
-void php_pq_object_to_zval_no_addref(void *o, zval **zv TSRMLS_DC)
+void php_pq_object_to_zval_no_addref(void *o, zval *zv)
 {
        php_pq_object_t *obj = o;
 
-       if (!*zv) {
-               MAKE_STD_ZVAL(*zv);
-       }
-
-       /* no add ref */
-
-       (*zv)->type = IS_OBJECT;
-       (*zv)->value.obj = obj->zv;
+       ZVAL_OBJ(zv, &obj->zo);
 }
 
-void php_pq_object_addref(void *o TSRMLS_DC)
+void php_pq_object_addref(void *o)
 {
        php_pq_object_t *obj = o;
-       zend_objects_store_add_ref_by_handle(obj->zv.handle TSRMLS_CC);
+       ++GC_REFCOUNT(&obj->zo);
 }
 
 void php_pq_object_delref(void *o TSRMLS_DC)
 {
        php_pq_object_t *obj = o;
-       zend_objects_store_del_ref_by_handle_ex(obj->zv.handle, obj->zv.handlers TSRMLS_CC);
+       zend_objects_store_del(&obj->zo);
 }
 
 struct apply_pi_to_ht_arg {
@@ -65,21 +52,21 @@ struct apply_pi_to_ht_arg {
        unsigned addref:1;
 };
 
-static int apply_pi_to_ht(void *p, void *a TSRMLS_DC)
+static int apply_pi_to_ht(zval *p, void *a)
 {
-       zend_property_info *pi = p;
+       zend_property_info *pi = Z_PTR_P(p);
        struct apply_pi_to_ht_arg *arg = a;
-       zval *property = zend_read_property(arg->pq_obj->zo.ce, arg->object, pi->name, pi->name_length, 0 TSRMLS_CC);
+       zval tmp_prop, *property = zend_read_property(arg->pq_obj->zo.ce, arg->object, pi->name->val, pi->name->len, 0, &tmp_prop);
 
        if (arg->addref) {
-               Z_ADDREF_P(property);
+               Z_TRY_ADDREF_P(property);
        }
-       zend_hash_update(arg->ht, pi->name, pi->name_length + 1, (void *) &property, sizeof(zval *), NULL);
+       zend_hash_update(arg->ht, pi->name, property);
 
        return ZEND_HASH_APPLY_KEEP;
 }
 
-HashTable *php_pq_object_debug_info(zval *object, int *temp TSRMLS_DC)
+HashTable *php_pq_object_debug_info(zval *object, int *temp)
 {
        struct apply_pi_to_ht_arg arg = {NULL};
 
@@ -88,24 +75,24 @@ HashTable *php_pq_object_debug_info(zval *object, int *temp TSRMLS_DC)
        ZEND_INIT_SYMTABLE(arg.ht);
 
        arg.object = object;
-       arg.pq_obj = zend_object_store_get_object(object TSRMLS_CC);
+       arg.pq_obj = PHP_PQ_OBJ(object, NULL);
        arg.addref = 1;
 
-       zend_hash_apply_with_argument(&arg.pq_obj->zo.ce->properties_info, apply_pi_to_ht, &arg TSRMLS_CC);
+       zend_hash_apply_with_argument(&arg.pq_obj->zo.ce->properties_info, apply_pi_to_ht, &arg);
 
        return arg.ht;
 }
 
-HashTable *php_pq_object_properties(zval *object TSRMLS_DC)
+HashTable *php_pq_object_properties(zval *object)
 {
        struct apply_pi_to_ht_arg arg = {NULL};
 
-       arg.ht = zend_get_std_object_handlers()->get_properties(object TSRMLS_CC);
+       arg.ht = zend_get_std_object_handlers()->get_properties(object);
        arg.object = object;
-       arg.pq_obj = zend_object_store_get_object(object TSRMLS_CC);
+       arg.pq_obj = PHP_PQ_OBJ(object, NULL);
        arg.addref = 1;
 
-       zend_hash_apply_with_argument(&arg.pq_obj->zo.ce->properties_info, apply_pi_to_ht, &arg TSRMLS_CC);
+       zend_hash_apply_with_argument(&arg.pq_obj->zo.ce->properties_info, apply_pi_to_ht, &arg);
 
        return arg.ht;
 }
@@ -118,45 +105,42 @@ zend_class_entry *ancestor(zend_class_entry *ce)
        return ce;
 }
 
-zval *php_pq_object_read_prop(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC)
+zval *php_pq_object_read_prop(zval *object, zval *member, int type, void **cache_slot, zval *tmp)
 {
-       php_pq_object_t *obj = zend_object_store_get_object(object TSRMLS_CC);
+       php_pq_object_t *obj = PHP_PQ_OBJ(object, NULL);
        php_pq_object_prophandler_t *handler;
        zval *return_value = NULL;
 
        if (!obj->intern) {
                php_error(E_RECOVERABLE_ERROR, "%s not initialized", ancestor(obj->zo.ce)->name);
-               return_value = zend_get_std_object_handlers()->read_property(object, member, type, key TSRMLS_CC);
-       } else if ((SUCCESS != zend_hash_find(obj->prophandler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void *) &handler)) || !handler->read) {
-               return_value = zend_get_std_object_handlers()->read_property(object, member, type, key TSRMLS_CC);
+               return_value = zend_get_std_object_handlers()->read_property(object, member, type, cache_slot, tmp);
+       } else if (!(handler= zend_hash_find_ptr(obj->prophandler, Z_STR_P(member))) || !handler->read) {
+               return_value = zend_get_std_object_handlers()->read_property(object, member, type, cache_slot, tmp);
        } else if (type != BP_VAR_R) {
-               php_error(E_WARNING, "Cannot access %s properties by reference or array key/index", ancestor(obj->zo.ce)->name);
-               return_value = zend_get_std_object_handlers()->read_property(object, member, type, key TSRMLS_CC);
+               php_error(E_WARNING, "Cannot access %s properties by reference or array key/index", ancestor(obj->zo.ce)->name->val);
+               return_value = zend_get_std_object_handlers()->read_property(object, member, type, cache_slot, tmp);
        } else {
-               ALLOC_ZVAL(return_value);
-               Z_SET_REFCOUNT_P(return_value, 0);
-               Z_UNSET_ISREF_P(return_value);
-
-               handler->read(object, obj, return_value TSRMLS_CC);
+               return_value = tmp;
+               handler->read(object, obj, return_value);
        }
 
        return return_value;
 }
 
-void php_pq_object_write_prop(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC)
+void php_pq_object_write_prop(zval *object, zval *member, zval *value, void **cache_slot)
 {
-       php_pq_object_t *obj = zend_object_store_get_object(object TSRMLS_CC);
+       php_pq_object_t *obj = PHP_PQ_OBJ(object, NULL);
        php_pq_object_prophandler_t *handler;
 
        if (!obj->intern) {
-               php_error(E_RECOVERABLE_ERROR, "%s not initialized", ancestor(obj->zo.ce)->name);
-               zend_get_std_object_handlers()->write_property(object, member, value, key TSRMLS_CC);
-       } else if (SUCCESS == zend_hash_find(obj->prophandler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void *) &handler)) {
+               php_error(E_RECOVERABLE_ERROR, "%s not initialized", ancestor(obj->zo.ce)->name->val);
+               zend_get_std_object_handlers()->write_property(object, member, value, cache_slot);
+       } else if ((handler = zend_hash_find_ptr(obj->prophandler, Z_STR_P(member)))) {
                if (handler->write) {
-                       handler->write(object, obj, value TSRMLS_CC);
+                       handler->write(object, obj, value);
                }
        } else {
-               zend_get_std_object_handlers()->write_property(object, member, value, key TSRMLS_CC);
+               zend_get_std_object_handlers()->write_property(object, member, value, cache_slot);
        }
 }
 
index d26fb7b6972aacda51e950ad1004b4789eda119d..47ccbbfa925ed33b2dda1af50092bf447d440f5d 100644 (file)
 #define PHP_PQ_OBJECT_H
 
 typedef struct php_pq_object {
-       zend_object zo;
-       zend_object_value zv;
-       HashTable *prophandler;
        void *intern;
+       HashTable *prophandler;
+       zend_object zo;
 } php_pq_object_t;
 
-typedef void (*php_pq_object_prophandler_func_t)(zval *object, void *o, zval *return_value TSRMLS_DC);
+static inline void *PHP_PQ_OBJ(zval *zv, zend_object *zo) {
+       if (zv) {
+               zo = Z_OBJ_P(zv);
+       }
+       return (void *) (((char *) zo) - zo->handlers->offset);
+}
+
+typedef void (*php_pq_object_prophandler_func_t)(zval *object, void *o, zval *return_value);
 
 typedef struct php_pq_object_prophandler {
        php_pq_object_prophandler_func_t read;
        php_pq_object_prophandler_func_t write;
 } php_pq_object_prophandler_t;
 
-extern void php_pq_object_to_zval(void *o, zval **zv TSRMLS_DC);
-extern void php_pq_object_to_zval_no_addref(void *o, zval **zv TSRMLS_DC);
-extern void php_pq_object_addref(void *o TSRMLS_DC);
-extern void php_pq_object_delref(void *o TSRMLS_DC);
-extern HashTable *php_pq_object_debug_info(zval *object, int *temp TSRMLS_DC);
-extern HashTable *php_pq_object_properties(zval *object TSRMLS_DC);
+extern void php_pq_object_to_zval(void *o, zval *zv);
+extern void php_pq_object_to_zval_no_addref(void *o, zval *zv);
+extern void php_pq_object_addref(void *o);
+extern void php_pq_object_delref(void *o);
+extern HashTable *php_pq_object_debug_info(zval *object, int *temp);
+extern HashTable *php_pq_object_properties(zval *object);
 extern zend_class_entry *ancestor(zend_class_entry *ce);
-extern zval *php_pq_object_read_prop(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC);
-extern void php_pq_object_write_prop(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC);
+extern zval *php_pq_object_read_prop(zval *object, zval *member, int type, void **cache_slot, zval *tmp);
+extern void php_pq_object_write_prop(zval *object, zval *member, zval *value, void **cache_slot);
 
 #endif
 
index 1ae7dd654ad1a54fb674b306c449ebc16436ea62..ead7fac8d720398b6c46c2fc5b70f706eb2af43d 100644 (file)
 
 #include <php.h>
 #include <ext/standard/php_string.h>
-#include <ext/standard/php_smart_str.h>
 #if PHP_PQ_HAVE_PHP_JSON_H
 #include <php_json.h> /* we've added the include directory to INCLUDES */
 #endif
 
+#include <Zend/zend_smart_str.h>
 #include <Zend/zend_interfaces.h>
 
 #include <libpq-fe.h>
 void php_pq_params_set_type_conv(php_pq_params_t *p, HashTable *conv)
 {
        zend_hash_clean(&p->type.conv);
-       zend_hash_copy(&p->type.conv, conv, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
+       zend_hash_copy(&p->type.conv, conv, (copy_ctor_func_t) zval_add_ref);
 }
 
-static int apply_to_oid(void *p, void *arg TSRMLS_DC)
+static int apply_to_oid(zval *ztype, void *arg)
 {
        Oid **types = arg;
-       zval **ztype = p;
 
-       if (Z_TYPE_PP(ztype) != IS_LONG) {
-               convert_to_long_ex(ztype);
-       }
-
-       **types = Z_LVAL_PP(ztype);
+       **types = zval_get_long(ztype);
        ++*types;
 
-       if (*ztype != *(zval **)p) {
-               zval_ptr_dtor(ztype);
-       }
        return ZEND_HASH_APPLY_KEEP;
 }
 
 unsigned php_pq_params_set_type_oids(php_pq_params_t *p, HashTable *oids)
 {
        p->type.count = oids ? zend_hash_num_elements(oids) : 0;
-       TSRMLS_DF(p);
 
        if (p->type.oids) {
                efree(p->type.oids);
@@ -68,7 +59,7 @@ unsigned php_pq_params_set_type_oids(php_pq_params_t *p, HashTable *oids)
                Oid *ptr = ecalloc(p->type.count + 1, sizeof(*p->type.oids));
                /* +1 for when less types than params are specified */
                p->type.oids = ptr;
-               zend_hash_apply_with_argument(oids, apply_to_oid, &ptr TSRMLS_CC);
+               zend_hash_apply_with_argument(oids, apply_to_oid, &ptr);
        }
        return p->type.count;
 }
@@ -82,9 +73,8 @@ unsigned php_pq_params_add_type_oid(php_pq_params_t *p, Oid type)
 }
 
 
-static zval *object_param_to_string(php_pq_params_t *p, zval *zobj, Oid type TSRMLS_DC)
+static zend_string *object_param_to_string(php_pq_params_t *p, zval *zobj, Oid type)
 {
-       zval *return_value = NULL;
        smart_str str = {0};
 
        switch (type) {
@@ -93,40 +83,25 @@ static zval *object_param_to_string(php_pq_params_t *p, zval *zobj, Oid type TSR
        case PHP_PQ_OID_JSONB:
 #      endif
        case PHP_PQ_OID_JSON:
-               php_json_encode(&str, zobj, PHP_JSON_UNESCAPED_UNICODE TSRMLS_CC);
+               php_json_encode(&str, zobj, PHP_JSON_UNESCAPED_UNICODE);
                smart_str_0(&str);
-               break;
+               return str.s;
 #endif
 
        case PHP_PQ_OID_DATE:
-               php_pqdt_to_string(zobj, "Y-m-d", &str.c, &str.len TSRMLS_CC);
-               break;
+               return php_pqdt_to_string(zobj, "Y-m-d");
 
        case PHP_PQ_OID_ABSTIME:
-               php_pqdt_to_string(zobj, "Y-m-d H:i:s", &str.c, &str.len TSRMLS_CC);
-               break;
+               return php_pqdt_to_string(zobj, "Y-m-d H:i:s");
 
        case PHP_PQ_OID_TIMESTAMP:
-               php_pqdt_to_string(zobj, "Y-m-d H:i:s.u", &str.c, &str.len TSRMLS_CC);
-               break;
+               return php_pqdt_to_string(zobj, "Y-m-d H:i:s.u");
 
        case PHP_PQ_OID_TIMESTAMPTZ:
-               php_pqdt_to_string(zobj, "Y-m-d H:i:s.uO", &str.c, &str.len TSRMLS_CC);
-               break;
-
-       default:
-               MAKE_STD_ZVAL(return_value);
-               MAKE_COPY_ZVAL(&zobj, return_value);
-               convert_to_string(return_value);
-               break;
+               return php_pqdt_to_string(zobj, "Y-m-d H:i:s.uO");
        }
 
-       if (str.c) {
-               MAKE_STD_ZVAL(return_value);
-               RETVAL_STRINGL(str.c, str.len, 0);
-       }
-
-       return return_value;
+       return zval_get_string(zobj);
 }
 
 struct apply_to_param_from_array_arg {
@@ -135,54 +110,48 @@ struct apply_to_param_from_array_arg {
        smart_str *buffer;
        Oid type;
        char delim;
-       zval **zconv;
+       zval *zconv;
 };
 
-static int apply_to_param_from_array(void *ptr, void *arg_ptr TSRMLS_DC)
+static int apply_to_param_from_array(zval *zparam, void *arg_ptr)
 {
        struct apply_to_param_from_array_arg subarg, *arg = arg_ptr;
-       zval *ztmp, **zparam = ptr, *zcopy = *zparam;
        char *tmp;
        size_t len;
-       int tmp_len;
+       zend_string *str;
 
        if (arg->index++) {
                smart_str_appendc(arg->buffer, arg->delim);
        }
 
        if (arg->zconv) {
-               zval *ztype, *rv = NULL;
-
-               MAKE_STD_ZVAL(ztype);
-               ZVAL_LONG(ztype, arg->type);
-               zend_call_method_with_2_params(arg->zconv, NULL, NULL, "converttostring", &rv, zcopy, ztype);
-               zval_ptr_dtor(&ztype);
-
-               if (rv) {
-                       convert_to_string(rv);
-                       zcopy = rv;
-               } else {
-                       return ZEND_HASH_APPLY_STOP;
-               }
+               zval ztype, rv;
 
+               ZVAL_LONG(&ztype, arg->type);
+               zend_call_method_with_2_params(arg->zconv, NULL, NULL, "converttostring", &rv, zparam, &ztype);
+               str = zval_get_string(&rv);
                goto append_string;
 
        } else {
-               switch (Z_TYPE_P(zcopy)) {
+               switch (Z_TYPE_P(zparam)) {
                case IS_NULL:
                        smart_str_appends(arg->buffer, "NULL");
                        break;
 
-               case IS_BOOL:
-                       smart_str_appends(arg->buffer, Z_BVAL_P(zcopy) ? "t" : "f");
+               case IS_TRUE:
+                       smart_str_appends(arg->buffer, "t");
+                       break;
+
+               case IS_FALSE:
+                       smart_str_appends(arg->buffer, "f");
                        break;
 
                case IS_LONG:
-                       smart_str_append_long(arg->buffer, Z_LVAL_P(zcopy));
+                       smart_str_append_long(arg->buffer, Z_LVAL_P(zparam));
                        break;
 
                case IS_DOUBLE:
-                       len = spprintf(&tmp, 0, "%F", Z_DVAL_P(zcopy));
+                       len = spprintf(&tmp, 0, "%F", Z_DVAL_P(zparam));
                        smart_str_appendl(arg->buffer, tmp, len);
                        efree(tmp);
                        break;
@@ -191,29 +160,24 @@ static int apply_to_param_from_array(void *ptr, void *arg_ptr TSRMLS_DC)
                        subarg = *arg;
                        subarg.index = 0;
                        smart_str_appendc(arg->buffer, '{');
-                       zend_hash_apply_with_argument(Z_ARRVAL_P(zcopy), apply_to_param_from_array, &subarg TSRMLS_CC);
+                       zend_hash_apply_with_argument(Z_ARRVAL_P(zparam), apply_to_param_from_array, &subarg);
                        smart_str_appendc(arg->buffer, '}');
                        break;
 
                case IS_OBJECT:
-                       if ((ztmp = object_param_to_string(arg->params, zcopy, arg->type TSRMLS_CC))) {
-                               zcopy = ztmp;
+                       if ((str = object_param_to_string(arg->params, zparam, arg->type))) {
+                               goto append_string;
                        }
                        /* no break */
                default:
-                       SEPARATE_ZVAL(&zcopy);
-                       convert_to_string(zcopy);
+                       str = zval_get_string(zparam);
 
                        append_string:
-                       tmp = php_addslashes(Z_STRVAL_P(zcopy), Z_STRLEN_P(zcopy), &tmp_len, 0 TSRMLS_CC);
+                       str = php_addslashes(str, 1);
                        smart_str_appendc(arg->buffer, '"');
-                       smart_str_appendl(arg->buffer, tmp, tmp_len);
+                       smart_str_appendl(arg->buffer, str->val, str->len);
                        smart_str_appendc(arg->buffer, '"');
-
-                       if (zcopy != *zparam) {
-                               zval_ptr_dtor(&zcopy);
-                       }
-                       efree(tmp);
+                       zend_string_release(str);
                        break;
                }
        }
@@ -221,9 +185,8 @@ static int apply_to_param_from_array(void *ptr, void *arg_ptr TSRMLS_DC)
        return ZEND_HASH_APPLY_KEEP;
 }
 
-static zval *array_param_to_string(php_pq_params_t *p, zval *zarr, Oid type TSRMLS_DC)
+static zend_string *array_param_to_string(php_pq_params_t *p, zval *zarr, Oid type)
 {
-       zval *zcopy, *return_value;
        smart_str s = {0};
        struct apply_to_param_from_array_arg arg = {NULL};
 
@@ -233,8 +196,7 @@ static zval *array_param_to_string(php_pq_params_t *p, zval *zarr, Oid type TSRM
        case PHP_PQ_OID_JSONB:
 #      endif
        case PHP_PQ_OID_JSON:
-               php_json_encode(&s, zarr, PHP_JSON_UNESCAPED_UNICODE TSRMLS_CC);
-               smart_str_0(&s);
+               php_json_encode(&s, zarr, PHP_JSON_UNESCAPED_UNICODE);
                break;
 #endif
 
@@ -243,90 +205,76 @@ static zval *array_param_to_string(php_pq_params_t *p, zval *zarr, Oid type TSRM
                arg.buffer = &s;
                arg.type = PHP_PQ_TYPE_OF_ARRAY(type);
                arg.delim = PHP_PQ_DELIM_OF_ARRAY(type);
-               zend_hash_index_find(&p->type.conv, PHP_PQ_TYPE_OF_ARRAY(type), (void *) &arg.zconv);
+               arg.zconv = zend_hash_index_find(&p->type.conv, PHP_PQ_TYPE_OF_ARRAY(type));
                smart_str_appendc(arg.buffer, '{');
-               MAKE_STD_ZVAL(zcopy);
-               MAKE_COPY_ZVAL(&zarr, zcopy);
-               zend_hash_apply_with_argument(Z_ARRVAL_P(zcopy), apply_to_param_from_array, &arg TSRMLS_CC);
-               zval_ptr_dtor(&zcopy);
+               SEPARATE_ZVAL(zarr);
+               zend_hash_apply_with_argument(Z_ARRVAL_P(zarr), apply_to_param_from_array, &arg);
+               zval_ptr_dtor(zarr);
                smart_str_appendc(arg.buffer, '}');
-               smart_str_0(&s);
                break;
        }
 
-       /* must not return NULL */
-       MAKE_STD_ZVAL(return_value);
-
-       if (s.c) {
-               RETVAL_STRINGL(s.c, s.len, 0);
-       } else {
-               RETVAL_EMPTY_STRING();
-       }
-
-       return return_value;
+       smart_str_0(&s);
+       return s.s;
 }
 
-static void php_pq_params_set_param(php_pq_params_t *p, unsigned index, zval **zpp)
+static void php_pq_params_set_param(php_pq_params_t *p, unsigned index, zval *zpp)
 {
-       zval **zconv = NULL;
+       zval *zconv = NULL;
        Oid type = p->type.count > index ? p->type.oids[index] : 0;
-       TSRMLS_DF(p);
-
-       if (type && SUCCESS == zend_hash_index_find(&p->type.conv, type, (void *) &zconv)) {
-               zval *ztype, *rv = NULL;
-
-               MAKE_STD_ZVAL(ztype);
-               ZVAL_LONG(ztype, type);
-               zend_call_method_with_2_params(zconv, NULL, NULL, "converttostring", &rv, *zpp, ztype);
-               zval_ptr_dtor(&ztype);
-               if (rv) {
-                       convert_to_string(rv);
-                       p->param.strings[index] = Z_STRVAL_P(rv);
-                       zend_hash_next_index_insert(&p->param.dtor, (void *) &rv, sizeof(zval *), NULL);
-               }
+
+       if (type && (zconv = zend_hash_index_find(&p->type.conv, type))) {
+               zval ztype, rv;
+
+               ZVAL_NULL(&rv);
+               ZVAL_LONG(&ztype, type);
+               zend_call_method_with_2_params(zconv, NULL, NULL, "converttostring", &rv, zpp, &ztype);
+               convert_to_string(&rv);
+               p->param.strings[index] = Z_STRVAL_P(&rv);
+               zend_hash_next_index_insert(&p->param.dtor, &rv);
        } else {
-               zval *tmp, *zcopy = *zpp;
+               zval tmp;
+               zend_string *str = NULL;
+               char tmp_str[64];
+               size_t tmp_len = 0;
 
-               switch (Z_TYPE_P(zcopy)) {
+               switch (Z_TYPE_P(zpp)) {
                case IS_NULL:
                        p->param.strings[index] = NULL;
                        return;
 
-               case IS_BOOL:
-                       p->param.strings[index] = Z_BVAL_P(zcopy) ? "t" : "f";
+               case IS_TRUE:
+                       p->param.strings[index] = "t";
+                       break;
+
+               case IS_FALSE:
+                       p->param.strings[index] = "f";
                        return;
 
                case IS_DOUBLE:
-                       MAKE_STD_ZVAL(zcopy);
-                       MAKE_COPY_ZVAL(zpp, zcopy);
-                       Z_TYPE_P(zcopy) = IS_STRING;
-                       Z_STRLEN_P(zcopy) = spprintf(&Z_STRVAL_P(zcopy), 0, "%F", Z_DVAL_PP(zpp));
+                       tmp_len = slprintf(tmp_str, sizeof(tmp_str), "%F", Z_DVAL_P(zpp));
+                       str = zend_string_init(tmp_str, tmp_len, 0);
                        break;
 
                case IS_ARRAY:
-                       MAKE_STD_ZVAL(zcopy);
-                       MAKE_COPY_ZVAL(zpp, zcopy);
-                       tmp = array_param_to_string(p, zcopy, type TSRMLS_CC);
-                       zval_ptr_dtor(&zcopy);
-                       zcopy = tmp;
+                       str = array_param_to_string(p, &tmp, type);
                        break;
 
                case IS_OBJECT:
-                       if ((tmp = object_param_to_string(p, zcopy, type TSRMLS_CC))) {
-                               zcopy = tmp;
+                       if ((str = object_param_to_string(p, zpp, type))) {
                                break;
                        }
                        /* no break */
 
                default:
-                       convert_to_string_ex(&zcopy);
+                       str = zval_get_string(zpp);
                        break;
                }
 
-               p->param.strings[index] = Z_STRVAL_P(zcopy);
-
-               if (zcopy != *zpp) {
-                       zend_hash_next_index_insert(&p->param.dtor, (void *) &zcopy, sizeof(zval *), NULL);
+               if (str) {
+                       ZVAL_STR(&tmp, str);
+                       p->param.strings[index] = Z_STRVAL(tmp);
+                       zend_hash_next_index_insert(&p->param.dtor, &tmp);
                }
        }
 }
@@ -336,11 +284,11 @@ struct apply_to_params_arg {
        unsigned index;
 };
 
-static int apply_to_params(void *zp, void *arg_ptr TSRMLS_DC)
+static int apply_to_params(zval *zp, void *arg_ptr)
 {
        struct apply_to_params_arg *arg = arg_ptr;
 
-       SEPARATE_ZVAL_IF_NOT_REF((zval **) zp);
+       SEPARATE_ZVAL_IF_NOT_REF(zp);
        php_pq_params_set_param(arg->params, arg->index++, zp);
        return ZEND_HASH_APPLY_KEEP;
 }
@@ -348,14 +296,13 @@ static int apply_to_params(void *zp, void *arg_ptr TSRMLS_DC)
 unsigned php_pq_params_add_param(php_pq_params_t *p, zval *param)
 {
        p->param.strings = safe_erealloc(p->param.strings, ++p->param.count, sizeof(*p->param.strings), 0);
-       php_pq_params_set_param(p, p->param.count-1, &param);
+       php_pq_params_set_param(p, p->param.count-1, param);
        return p->type.count;
 }
 
 unsigned php_pq_params_set_params(php_pq_params_t *p, HashTable *params)
 {
        p->param.count = params ? zend_hash_num_elements(params) : 0;
-       TSRMLS_DF(p);
 
        if (p->param.strings) {
                efree(p->param.strings);
@@ -365,7 +312,7 @@ unsigned php_pq_params_set_params(php_pq_params_t *p, HashTable *params)
        if (p->param.count) {
                struct apply_to_params_arg arg = {p, 0};
                p->param.strings = ecalloc(p->param.count, sizeof(*p->param.strings));
-               zend_hash_apply_with_argument(params, apply_to_params, &arg TSRMLS_CC);
+               zend_hash_apply_with_argument(params, apply_to_params, &arg);
        }
        return p->param.count;
 }
@@ -384,11 +331,10 @@ void php_pq_params_free(php_pq_params_t **p)
        }
 }
 
-php_pq_params_t *php_pq_params_init(HashTable *conv, HashTable *oids, HashTable *params TSRMLS_DC)
+php_pq_params_t *php_pq_params_init(HashTable *conv, HashTable *oids, HashTable *params)
 {
        php_pq_params_t *p = ecalloc(1, sizeof(*p));
 
-       TSRMLS_CF(p);
        zend_hash_init(&p->type.conv, 0, NULL, ZVAL_PTR_DTOR, 0);
        zend_hash_init(&p->param.dtor, 0, NULL, ZVAL_PTR_DTOR, 0);
 
index fe5d9c6f344b31ff6212efda8fc7afffc9a38799..f94cd9ccd951ac9d020ed1abf9cc5ccc0f6e1fc9 100644 (file)
@@ -24,12 +24,9 @@ typedef struct php_pq_params {
                unsigned count;
                char **strings;
        } param;
-#ifdef ZTS
-       void ***ts;
-#endif
 } php_pq_params_t;
 
-extern php_pq_params_t *php_pq_params_init(HashTable *conv, HashTable *oids, HashTable *params TSRMLS_DC);
+extern php_pq_params_t *php_pq_params_init(HashTable *conv, HashTable *oids, HashTable *params);
 extern void php_pq_params_free(php_pq_params_t **p);
 extern unsigned php_pq_params_set_params(php_pq_params_t *p, HashTable *params);
 extern unsigned php_pq_params_set_type_oids(php_pq_params_t *p, HashTable *oids);
index 9711190c8686daf73be9e75aff94fcddea5a88a4..7105363fdb8af87ff212476137f77e1764d5a2e2 100644 (file)
@@ -28,55 +28,50 @@ zend_class_entry *php_pqcancel_class_entry;
 static zend_object_handlers php_pqcancel_object_handlers;
 static HashTable php_pqcancel_object_prophandlers;
 
-static void php_pqcancel_object_free(void *o TSRMLS_DC)
+static void php_pqcancel_object_free(zend_object *o)
 {
-       php_pqcancel_object_t *obj = o;
+       php_pqcancel_object_t *obj = PHP_PQ_OBJ(NULL, o);
 #if DBG_GC
        fprintf(stderr, "FREE cancel(#%d) %p (conn(#%d): %p)\n", obj->zv.handle, obj, obj->intern->conn->zv.handle, obj->intern->conn);
 #endif
        if (obj->intern) {
                PQfreeCancel(obj->intern->cancel);
-               php_pq_object_delref(obj->intern->conn TSRMLS_CC);
+               php_pq_object_delref(obj->intern->conn);
                efree(obj->intern);
                obj->intern = NULL;
        }
-       zend_object_std_dtor((zend_object *) o TSRMLS_CC);
+       zend_object_std_dtor(o);
        efree(obj);
 }
 
-zend_object_value php_pqcancel_create_object_ex(zend_class_entry *ce, php_pqcancel_t *intern, php_pqcancel_object_t **ptr TSRMLS_DC)
+php_pqcancel_object_t *php_pqcancel_create_object_ex(zend_class_entry *ce, php_pqcancel_t *intern)
 {
        php_pqcancel_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 = 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_pqcancel_object_prophandlers;
 
-       if (ptr) {
-               *ptr = o;
-       }
-
        if (intern) {
                o->intern = intern;
        }
 
-       o->zv.handle = zend_objects_store_put((zend_object *) o, NULL, php_pqcancel_object_free, NULL TSRMLS_CC);
-       o->zv.handlers = &php_pqcancel_object_handlers;
+       o->zo.handlers = &php_pqcancel_object_handlers;
 
-       return o->zv;
+       return o;
 }
 
-static zend_object_value php_pqcancel_create_object(zend_class_entry *class_type TSRMLS_DC)
+static zend_object *php_pqcancel_create_object(zend_class_entry *class_type TSRMLS_DC)
 {
-       return php_pqcancel_create_object_ex(class_type, NULL, NULL TSRMLS_CC);
+       return &php_pqcancel_create_object_ex(class_type, NULL)->zo;
 }
 
-static void php_pqcancel_object_read_connection(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqcancel_object_read_connection(zval *object, void *o, zval *return_value)
 {
        php_pqcancel_object_t *obj = o;
 
-       php_pq_object_to_zval(obj->intern->conn, &return_value TSRMLS_CC);
+       php_pq_object_to_zval(obj->intern->conn, return_value);
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_pqcancel_construct, 0, 0, 1)
@@ -87,26 +82,26 @@ static PHP_METHOD(pqcancel, __construct) {
        zval *zconn;
        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, "O", &zconn, php_pqconn_class_entry);
-       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(), "O", &zconn, php_pqconn_class_entry);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqconn_object_t *conn_obj = zend_object_store_get_object(zconn TSRMLS_CC);
+               php_pqconn_object_t *conn_obj = PHP_PQ_OBJ(zconn, NULL);
 
                if (!conn_obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
                        PGcancel *cancel = PQgetCancel(conn_obj->intern->conn);
 
                        if (!cancel) {
-                               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to acquire cancel (%s)", PHP_PQerrorMessage(conn_obj->intern->conn));
+                               throw_exce(EX_RUNTIME, "Failed to acquire cancel (%s)", PHP_PQerrorMessage(conn_obj->intern->conn));
                        } else {
-                               php_pqcancel_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+                               php_pqcancel_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                                obj->intern = ecalloc(1, sizeof(*obj->intern));
                                obj->intern->cancel = cancel;
-                               php_pq_object_addref(conn_obj TSRMLS_CC);
+                               php_pq_object_addref(conn_obj);
                                obj->intern->conn = conn_obj;
                        }
                }
@@ -119,20 +114,20 @@ static PHP_METHOD(pqcancel, cancel) {
        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();
-       zend_restore_error_handling(&zeh TSRMLS_CC);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqcancel_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqcancel_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Cancel not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Cancel not initialized");
                } else {
                        char err[256] = {0};
 
                        if (!PQcancel(obj->intern->cancel, err, sizeof(err))) {
-                               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to request cancellation (%s)", err);
+                               throw_exce(EX_RUNTIME, "Failed to request cancellation (%s)", err);
                        }
                }
        }
@@ -156,10 +151,12 @@ PHP_MINIT_FUNCTION(pqcancel)
        php_pq_object_prophandler_t ph = {0};
 
        INIT_NS_CLASS_ENTRY(ce, "pq", "Cancel", php_pqcancel_methods);
-       php_pqcancel_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
+       php_pqcancel_class_entry = zend_register_internal_class_ex(&ce, NULL);
        php_pqcancel_class_entry->create_object = php_pqcancel_create_object;
 
        memcpy(&php_pqcancel_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+       php_pqcancel_object_handlers.offset = XtOffsetOf(php_pqcancel_object_t, zo);
+       php_pqcancel_object_handlers.free_obj = php_pqcancel_object_free;
        php_pqcancel_object_handlers.read_property = php_pq_object_read_prop;
        php_pqcancel_object_handlers.write_property = php_pq_object_write_prop;
        php_pqcancel_object_handlers.clone_obj = NULL;
@@ -172,7 +169,7 @@ PHP_MINIT_FUNCTION(pqcancel)
 
        zend_declare_property_null(php_pqcancel_class_entry, ZEND_STRL("connection"), ZEND_ACC_PUBLIC TSRMLS_CC);
        ph.read = php_pqcancel_object_read_connection;
-       zend_hash_add(&php_pqcancel_object_prophandlers, "connection", sizeof("connection"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqcancel_object_prophandlers, ZEND_STRL("connection"), (void *) &ph, sizeof(ph));
 
        return SUCCESS;
 }
index ad9fb6460360f9d92a60d44e4bb296a460f8e52a..8bbd7a951ed64bd9e5559b244f3b595879e428bc 100644 (file)
@@ -22,14 +22,13 @@ typedef struct php_pqcancel {
 } php_pqcancel_t;
 
 typedef struct php_pqcancel_object {
-       zend_object zo;
-       zend_object_value zv;
-       HashTable *prophandler;
        php_pqcancel_t *intern;
+       HashTable *prophandler;
+       zend_object zo;
 } php_pqcancel_object_t;
 
 extern zend_class_entry *php_pqcancel_class_entry;
-extern zend_object_value php_pqcancel_create_object_ex(zend_class_entry *ce, php_pqcancel_t *intern, php_pqcancel_object_t **ptr TSRMLS_DC);
+extern php_pqcancel_object_t *php_pqcancel_create_object_ex(zend_class_entry *ce, php_pqcancel_t *intern);
 
 extern PHP_MINIT_FUNCTION(pqcancel);
 extern PHP_MSHUTDOWN_FUNCTION(pqcancel);
index e753c7c736b8bdcb663237f1ca70a840280c8297..3e4aed88bf2354208ad76991d2a6cf3b295940dd 100644 (file)
@@ -15,9 +15,7 @@
 #endif
 
 #include <php.h>
-
-#define SMART_STR_PREALLOC 256
-#include <ext/standard/php_smart_str.h>
+#include <Zend/zend_smart_str.h>
 
 #include <libpq-events.h>
 #include <fnmatch.h>
@@ -53,29 +51,29 @@ static ulong php_pqconn_add_eventhandler(php_pqconn_object_t *obj, const char *t
        ulong h;
        HashTable *evhs;
 
-       if (SUCCESS != zend_hash_find(&obj->intern->eventhandlers, type_str, type_len + 1, (void *) &evhs)) {
+       if (!(evhs = zend_hash_str_find_ptr(&obj->intern->eventhandlers, type_str, type_len))) {
                HashTable evh;
 
                zend_hash_init(&evh, 1, NULL, (dtor_func_t) php_pq_callback_dtor, 0);
-               zend_hash_add(&obj->intern->eventhandlers, type_str, type_len + 1, (void *) &evh, sizeof(evh), (void *) &evhs);
+               evhs = zend_hash_str_add_mem(&obj->intern->eventhandlers, type_str, type_len, (void *) &evh, sizeof(evh));
        }
 
        php_pq_callback_addref(cb);
        h = zend_hash_next_free_element(evhs);
-       zend_hash_index_update(evhs, h, (void *) cb, sizeof(*cb), NULL);
+       zend_hash_index_update_ptr(evhs, h, (void *) cb);
 
        return h;
 }
 
-static void php_pqconn_object_free(void *o TSRMLS_DC)
+static void php_pqconn_object_free(zend_object *o)
 {
-       php_pqconn_object_t *obj = o;
+       php_pqconn_object_t *obj = PHP_PQ_OBJ(NULL, o);
 #if DBG_GC
        fprintf(stderr, "FREE conn(#%d) %p\n", obj->zv.handle, obj);
 #endif
        if (obj->intern) {
                php_pq_callback_dtor(&obj->intern->onevent);
-               php_resource_factory_handle_dtor(&obj->intern->factory, obj->intern->conn TSRMLS_CC);
+               php_resource_factory_handle_dtor(&obj->intern->factory, obj->intern->conn);
                php_resource_factory_dtor(&obj->intern->factory);
                zend_hash_destroy(&obj->intern->listeners);
                zend_hash_destroy(&obj->intern->converters);
@@ -83,80 +81,72 @@ static void php_pqconn_object_free(void *o TSRMLS_DC)
                efree(obj->intern);
                obj->intern = NULL;
        }
-       zend_object_std_dtor((zend_object *) o TSRMLS_CC);
+       zend_object_std_dtor(o);
        efree(obj);
 }
 
 
-zend_object_value php_pqconn_create_object_ex(zend_class_entry *ce, php_pqconn_t *intern, php_pqconn_object_t **ptr TSRMLS_DC)
+php_pqconn_object_t *php_pqconn_create_object_ex(zend_class_entry *ce, php_pqconn_t *intern)
 {
        php_pqconn_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 = 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_pqconn_object_prophandlers;
 
-       if (ptr) {
-               *ptr = o;
-       }
-
        if (intern) {
                o->intern = intern;
        }
 
-       o->zv.handle = zend_objects_store_put((zend_object *) o, NULL, php_pqconn_object_free, NULL TSRMLS_CC);
-       o->zv.handlers = &php_pqconn_object_handlers;
+       o->zo.handlers = &php_pqconn_object_handlers;
 
-       return o->zv;
+       return o;
 }
 
-static zend_object_value php_pqconn_create_object(zend_class_entry *class_type TSRMLS_DC)
+static zend_object *php_pqconn_create_object(zend_class_entry *class_type)
 {
-       return php_pqconn_create_object_ex(class_type, NULL, NULL TSRMLS_CC);
+       return &php_pqconn_create_object_ex(class_type, NULL)->zo;
 }
 
-static void php_pqconn_object_read_status(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqconn_object_read_status(zval *object, void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
 
        RETVAL_LONG(PQstatus(obj->intern->conn));
 }
 
-static void php_pqconn_object_read_transaction_status(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqconn_object_read_transaction_status(zval *object, void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
 
        RETVAL_LONG(PQtransactionStatus(obj->intern->conn));
 }
 
-static void php_pqconn_object_read_error_message(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqconn_object_read_error_message(zval *object, void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
        char *error = PHP_PQerrorMessage(obj->intern->conn);
 
        if (error) {
-               RETVAL_STRING(error, 1);
+               RETVAL_STRING(error);
        } else {
                RETVAL_NULL();
        }
 }
 
-static int apply_notify_listener(void *p, void *arg TSRMLS_DC)
+static int apply_notify_listener(zval *p, void *arg)
 {
-       php_pq_callback_t *listener = p;
+       php_pq_callback_t *listener = Z_PTR_P(p);
        PGnotify *nfy = arg;
-       zval *zpid, *zchannel, *zmessage;
+       zval zpid, zchannel, zmessage;
 
-       MAKE_STD_ZVAL(zpid);
-       ZVAL_LONG(zpid, nfy->be_pid);
-       MAKE_STD_ZVAL(zchannel);
-       ZVAL_STRING(zchannel, nfy->relname, 1);
-       MAKE_STD_ZVAL(zmessage);
-       ZVAL_STRING(zmessage, nfy->extra, 1);
+       ZVAL_LONG(&zpid, nfy->be_pid);
+       ZVAL_STRING(&zchannel, nfy->relname);
+       ZVAL_STRING(&zmessage, nfy->extra);
 
-       zend_fcall_info_argn(&listener->fci TSRMLS_CC, 3, &zchannel, &zmessage, &zpid);
-       zend_fcall_info_call(&listener->fci, &listener->fcc, NULL, NULL TSRMLS_CC);
+       zend_fcall_info_argn(&listener->fci, 3, &zchannel, &zmessage, &zpid);
+       zend_fcall_info_call(&listener->fci, &listener->fcc, NULL, NULL);
 
        zval_ptr_dtor(&zchannel);
        zval_ptr_dtor(&zmessage);
@@ -165,144 +155,130 @@ static int apply_notify_listener(void *p, void *arg TSRMLS_DC)
        return ZEND_HASH_APPLY_KEEP;
 }
 
-static int apply_notify_listeners(void *p TSRMLS_DC, int argc, va_list argv, zend_hash_key *key)
+static int apply_notify_listeners(zval *p, int argc, va_list argv, zend_hash_key *key)
 {
-       HashTable *listeners = p;
+       HashTable *listeners = Z_ARRVAL_P(p);
        PGnotify *nfy = va_arg(argv, PGnotify *);
 
-       if (0 == fnmatch(key->arKey, nfy->relname, 0)) {
-               zend_hash_apply_with_argument(listeners, apply_notify_listener, nfy TSRMLS_CC);
+       if (0 == fnmatch(key->key->val, nfy->relname, 0)) {
+               zend_hash_apply_with_argument(listeners, apply_notify_listener, nfy);
        }
 
        return ZEND_HASH_APPLY_KEEP;
 }
 
-void php_pqconn_notify_listeners(php_pqconn_object_t *obj TSRMLS_DC)
+void php_pqconn_notify_listeners(php_pqconn_object_t *obj)
 {
        PGnotify *nfy;
 
        while ((nfy = PQnotifies(obj->intern->conn))) {
-               zend_hash_apply_with_arguments(&obj->intern->listeners TSRMLS_CC, apply_notify_listeners, 1, nfy);
+               zend_hash_apply_with_arguments(&obj->intern->listeners, apply_notify_listeners, 1, nfy);
                PQfreemem(nfy);
        }
 }
 
-static void php_pqconn_object_read_busy(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqconn_object_read_busy(zval *object, void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
 
        RETVAL_BOOL(PQisBusy(obj->intern->conn));
 }
 
-static void php_pqconn_object_read_encoding(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqconn_object_read_encoding(zval *object, void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
 
-       RETVAL_STRING(pg_encoding_to_char(PQclientEncoding(obj->intern->conn)), 1);
+       RETVAL_STRING(pg_encoding_to_char(PQclientEncoding(obj->intern->conn)));
 }
 
-static void php_pqconn_object_write_encoding(zval *object, void *o, zval *value TSRMLS_DC)
+static void php_pqconn_object_write_encoding(zval *object, void *o, zval *value)
 {
        php_pqconn_object_t *obj = o;
-       zval *zenc = value;
-
-       if (Z_TYPE_P(value) != IS_STRING) {
-               if (Z_REFCOUNT_P(value) > 1) {
-                       zval *tmp;
-                       MAKE_STD_ZVAL(tmp);
-                       ZVAL_ZVAL(tmp, zenc, 1, 0);
-                       convert_to_string(tmp);
-                       zenc = tmp;
-               } else {
-                       convert_to_string_ex(&zenc);
-               }
-       }
+       zend_string *zenc = zval_get_string(value);
 
-       if (0 > PQsetClientEncoding(obj->intern->conn, Z_STRVAL_P(zenc))) {
-               php_error(E_NOTICE, "Unrecognized encoding '%s'", Z_STRVAL_P(zenc));
+       if (0 > PQsetClientEncoding(obj->intern->conn, zenc->val)) {
+               php_error(E_NOTICE, "Unrecognized encoding '%s'", zenc->val);
        }
 
-       if (zenc != value) {
-               zval_ptr_dtor(&zenc);
-       }
+       zend_string_release(zenc);
 }
 
-static void php_pqconn_object_read_unbuffered(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqconn_object_read_unbuffered(zval *object, void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
 
        RETVAL_BOOL(obj->intern->unbuffered);
 }
 
-static void php_pqconn_object_write_unbuffered(zval *object, void *o, zval *value TSRMLS_DC)
+static void php_pqconn_object_write_unbuffered(zval *object, void *o, zval *value)
 {
        php_pqconn_object_t *obj = o;
 
        obj->intern->unbuffered = z_is_true(value);
 }
 
-static void php_pqconn_object_read_db(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqconn_object_read_db(zval *object, void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
        char *db = PQdb(obj->intern->conn);
 
        if (db) {
-               RETVAL_STRING(db, 1);
+               RETVAL_STRING(db);
        } else {
                RETVAL_EMPTY_STRING();
        }
 }
 
-static void php_pqconn_object_read_user(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqconn_object_read_user(zval *object, void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
        char *user = PQuser(obj->intern->conn);
 
        if (user) {
-               RETVAL_STRING(user, 1);
+               RETVAL_STRING(user);
        } else {
                RETVAL_EMPTY_STRING();
        }
 }
 
-static void php_pqconn_object_read_pass(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqconn_object_read_pass(zval *object, void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
        char *pass = PQpass(obj->intern->conn);
 
        if (pass) {
-               RETVAL_STRING(pass, 1);
+               RETVAL_STRING(pass);
        } else {
                RETVAL_EMPTY_STRING();
        }
 }
 
-static void php_pqconn_object_read_host(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqconn_object_read_host(zval *object, void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
        char *host = PQhost(obj->intern->conn);
 
        if (host) {
-               RETVAL_STRING(host, 1);
+               RETVAL_STRING(host);
        } else {
                RETVAL_EMPTY_STRING();
        }
 }
 
-static void php_pqconn_object_read_port(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqconn_object_read_port(zval *object, void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
        char *port = PQport(obj->intern->conn);
 
        if (port) {
-               RETVAL_STRING(port, 1);
+               RETVAL_STRING(port);
        } else {
                RETVAL_EMPTY_STRING();
        }
 }
 
 #if HAVE_PQCONNINFO
-static void php_pqconn_object_read_params(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqconn_object_read_params(zval *object, void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
        PQconninfoOption *ptr, *params = PQconninfo(obj->intern->conn);
@@ -312,7 +288,7 @@ static void php_pqconn_object_read_params(zval *object, void *o, zval *return_va
        if (params) {
                for (ptr = params; ptr->keyword; ++ptr) {
                        if (ptr->val) {
-                               add_assoc_string(return_value, ptr->keyword, ptr->val, 1);
+                               add_assoc_string(return_value, ptr->keyword, ptr->val);
                        } else {
                                add_assoc_null(return_value, ptr->keyword);
                        }
@@ -322,202 +298,148 @@ static void php_pqconn_object_read_params(zval *object, void *o, zval *return_va
 }
 #endif
 
-static void php_pqconn_object_read_options(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqconn_object_read_options(zval *object, void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
        char *options = PQoptions(obj->intern->conn);
 
        if (options) {
-               RETVAL_STRING(options, 1);
+               RETVAL_STRING(options);
        } else {
                RETVAL_EMPTY_STRING();
        }
 }
 
-static int apply_read_event_handler_ex(void *p, void *arg TSRMLS_DC)
+static int apply_read_event_handler_ex(zval *p, void *arg)
 {
        HashTable *rv = arg;
-       zval *zcb = php_pq_callback_to_zval(p);
+       zval zcb;
 
-       zend_hash_next_index_insert(rv, &zcb, sizeof(zval *), NULL);
+       zend_hash_next_index_insert(rv, php_pq_callback_to_zval(Z_PTR_P(p), &zcb));
 
        return ZEND_HASH_APPLY_KEEP;
 }
 
-static int apply_read_event_handlers(void *p TSRMLS_DC, int argc, va_list argv, zend_hash_key *key)
+static int apply_read_event_handlers(zval *p, int argc, va_list argv, zend_hash_key *key)
 {
-       HashTable *evhs = p, *rv = va_arg(argv, HashTable *);
-       zval *entry, **entry_ptr;
+       HashTable *evhs = Z_PTR_P(p), *rv = va_arg(argv, HashTable *);
+       zval entry, *entry_ptr;
 
-       MAKE_STD_ZVAL(entry);
-       array_init_size(entry, zend_hash_num_elements(evhs));
+       array_init_size(&entry, zend_hash_num_elements(evhs));
 
-       if (key->nKeyLength) {
-               zend_hash_add(rv, key->arKey, key->nKeyLength, &entry, sizeof(zval *), (void *) &entry_ptr);
+       if (key->key->len) {
+               entry_ptr = zend_hash_add(rv, key->key, &entry);
        } else {
-               zend_hash_index_update(rv, key->h, &entry, sizeof(zval *), (void *) &entry_ptr);
+               entry_ptr = zend_hash_index_update(rv, key->h, &entry);
        }
 
-       zend_hash_apply_with_argument(evhs, apply_read_event_handler_ex, Z_ARRVAL_PP(entry_ptr) TSRMLS_CC);
+       zend_hash_apply_with_argument(evhs, apply_read_event_handler_ex, Z_ARRVAL_P(entry_ptr));
 
        return ZEND_HASH_APPLY_KEEP;
 }
-static void php_pqconn_object_read_event_handlers(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqconn_object_read_event_handlers(zval *object, void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
 
        array_init(return_value);
-       zend_hash_apply_with_arguments(&obj->intern->eventhandlers TSRMLS_CC, apply_read_event_handlers, 1, Z_ARRVAL_P(return_value) TSRMLS_CC);
+       zend_hash_apply_with_arguments(&obj->intern->eventhandlers, apply_read_event_handlers, 1, Z_ARRVAL_P(return_value) TSRMLS_CC);
 }
 
-static void php_pqconn_object_read_def_fetch_type(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqconn_object_read_def_fetch_type(zval *object, void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
 
        RETVAL_LONG(obj->intern->default_fetch_type);
 }
-static void php_pqconn_object_write_def_fetch_type(zval *object, void *o, zval *value TSRMLS_DC)
+static void php_pqconn_object_write_def_fetch_type(zval *object, void *o, zval *value)
 {
        php_pqconn_object_t *obj = o;
-       zval *zft = value;
-
-       if (Z_TYPE_P(zft) != IS_LONG) {
-               if (Z_REFCOUNT_P(zft) > 1) {
-                       zval *tmp;
-                       MAKE_STD_ZVAL(tmp);
-                       ZVAL_ZVAL(tmp, zft, 1, 0);
-                       convert_to_long(tmp);
-                       zft = tmp;
-               } else {
-                       convert_to_long_ex(&zft);
-               }
-       }
 
-       obj->intern->default_fetch_type = Z_LVAL_P(zft) & 0x3; /* two bits only */
-
-       if (zft != value) {
-               zval_ptr_dtor(&zft);
-       }
+       obj->intern->default_fetch_type = zval_get_long(value) & 0x3; /* two bits only */
 }
 
-static void php_pqconn_object_read_def_txn_isolation(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqconn_object_read_def_txn_isolation(zval *object, void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
 
        RETVAL_LONG(obj->intern->default_txn_isolation);
 }
-static void php_pqconn_object_write_def_txn_isolation(zval *object, void *o, zval *value TSRMLS_DC)
+static void php_pqconn_object_write_def_txn_isolation(zval *object, void *o, zval *value)
 {
        php_pqconn_object_t *obj = o;
-       zval *zti = value;
-
-       if (Z_TYPE_P(zti) != IS_LONG) {
-               if (Z_REFCOUNT_P(zti) > 1) {
-                       zval *tmp;
-                       MAKE_STD_ZVAL(tmp);
-                       ZVAL_ZVAL(tmp, zti, 1, 0);
-                       convert_to_long(tmp);
-                       zti = tmp;
-               } else {
-                       convert_to_long_ex(&zti);
-               }
-       }
-
-       obj->intern->default_txn_isolation = Z_LVAL_P(zti) & 0x3; /* two bits only */
 
-       if (zti != value) {
-               zval_ptr_dtor(&zti);
-       }
+       obj->intern->default_txn_isolation = zval_get_long(value) & 0x3; /* two bits only */
 }
 
-static void php_pqconn_object_read_def_txn_readonly(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqconn_object_read_def_txn_readonly(zval *object, void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
 
        RETVAL_BOOL(obj->intern->default_txn_readonly);
 }
-static void php_pqconn_object_write_def_txn_readonly(zval *object, void *o, zval *value TSRMLS_DC)
+static void php_pqconn_object_write_def_txn_readonly(zval *object, void *o, zval *value)
 {
        php_pqconn_object_t *obj = o;
 
-       obj->intern->default_txn_readonly = zend_is_true(value);
+       obj->intern->default_txn_readonly = z_is_true(value);
 }
 
-static void php_pqconn_object_read_def_txn_deferrable(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqconn_object_read_def_txn_deferrable(zval *object, void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
 
        RETVAL_BOOL(obj->intern->default_txn_deferrable);
 }
-static void php_pqconn_object_write_def_txn_deferrable(zval *object, void *o, zval *value TSRMLS_DC)
+static void php_pqconn_object_write_def_txn_deferrable(zval *object, void *o, zval *value)
 {
        php_pqconn_object_t *obj = o;
 
        obj->intern->default_txn_deferrable = zend_is_true(value);
 }
 
-static void php_pqconn_object_read_def_auto_conv(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqconn_object_read_def_auto_conv(zval *object, void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
 
        RETVAL_LONG(obj->intern->default_auto_convert);
 }
-static void php_pqconn_object_write_def_auto_conv(zval*object, void *o, zval *value TSRMLS_DC)
+static void php_pqconn_object_write_def_auto_conv(zval*object, void *o, zval *value)
 {
        php_pqconn_object_t *obj = o;
-       zval *zac = value;
-
-       if (Z_TYPE_P(zac) != IS_LONG) {
-               if (Z_REFCOUNT_P(zac) > 1) {
-                       zval *tmp;
-                       MAKE_STD_ZVAL(tmp);
-                       ZVAL_ZVAL(tmp, zac, 1, 0);
-                       convert_to_long(tmp);
-                       zac = tmp;
-               } else {
-                       convert_to_long_ex(&zac);
-               }
-       }
-
-       obj->intern->default_auto_convert = Z_LVAL_P(zac) & PHP_PQRES_CONV_ALL;
 
-       if (zac != value) {
-               zval_ptr_dtor(&zac);
-       }
+       obj->intern->default_auto_convert = zval_get_long(value) & PHP_PQRES_CONV_ALL;
 }
 
-static ZEND_RESULT_CODE php_pqconn_update_socket(zval *this_ptr, php_pqconn_object_t *obj TSRMLS_DC)
+static ZEND_RESULT_CODE php_pqconn_update_socket(zval *zobj, php_pqconn_object_t *obj)
 {
-       zval *zsocket, zmember;
+       zval zsocket, zmember;
        php_stream *stream;
        ZEND_RESULT_CODE retval;
        int socket;
 
        if (!obj) {
-               obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               obj = PHP_PQ_OBJ(zobj, NULL);
        }
 
-       INIT_PZVAL(&zmember);
-       ZVAL_STRINGL(&zmember, "socket", sizeof("socket")-1, 0);
-       MAKE_STD_ZVAL(zsocket);
+       ZVAL_STRINGL(&zmember, "socket", sizeof("socket")-1);
 
        if ((CONNECTION_BAD != PQstatus(obj->intern->conn))
        &&      (-1 < (socket = PQsocket(obj->intern->conn)))
        &&      (stream = php_stream_fopen_from_fd(socket, "r+b", NULL))) {
                stream->flags |= PHP_STREAM_FLAG_NO_CLOSE;
-               php_stream_to_zval(stream, zsocket);
+               php_stream_to_zval(stream, &zsocket);
                retval = SUCCESS;
        } else {
-               ZVAL_NULL(zsocket);
+               ZVAL_NULL(&zsocket);
                retval = FAILURE;
        }
-       zend_get_std_object_handlers()->write_property(getThis(), &zmember, zsocket, NULL TSRMLS_CC);
+       zend_get_std_object_handlers()->write_property(zobj, &zmember, &zsocket, NULL);
        zval_ptr_dtor(&zsocket);
 
        return retval;
 }
 
-static void *php_pqconn_resource_factory_ctor(void *data, void *init_arg TSRMLS_DC)
+static void *php_pqconn_resource_factory_ctor(void *data, void *init_arg)
 {
        php_pqconn_resource_factory_data_t *o = init_arg;
        PGconn *conn = NULL;;
@@ -535,7 +457,7 @@ static void *php_pqconn_resource_factory_ctor(void *data, void *init_arg TSRMLS_
        return conn;
 }
 
-static void php_pqconn_resource_factory_dtor(void *opaque, void *handle TSRMLS_DC)
+static void php_pqconn_resource_factory_dtor(void *opaque, void *handle)
 {
        php_pqconn_event_data_t *evdata = PQinstanceData(handle, php_pqconn_event);
 
@@ -560,7 +482,7 @@ php_resource_factory_ops_t *php_pqconn_get_resource_factory_ops(void)
        return &php_pqconn_resource_factory_ops;
 }
 
-static void php_pqconn_wakeup(php_persistent_handle_factory_t *f, void **handle TSRMLS_DC)
+static void php_pqconn_wakeup(php_persistent_handle_factory_t *f, void **handle)
 {
        PGresult *res = PQexec(*handle, "");
        PHP_PQclear(res);
@@ -570,7 +492,7 @@ static void php_pqconn_wakeup(php_persistent_handle_factory_t *f, void **handle
        }
 }
 
-static inline PGresult *unlisten(PGconn *conn, const char *channel_str, size_t channel_len TSRMLS_DC)
+static inline PGresult *unlisten(PGconn *conn, const char *channel_str, size_t channel_len)
 {
        char *quoted_channel = PQescapeIdentifier(conn, channel_str, channel_len);
        PGresult *res = NULL;
@@ -582,7 +504,7 @@ static inline PGresult *unlisten(PGconn *conn, const char *channel_str, size_t c
                smart_str_appends(&cmd, quoted_channel);
                smart_str_0(&cmd);
 
-               res = PQexec(conn, cmd.c);
+               res = PQexec(conn, smart_str_v(&cmd));
 
                smart_str_free(&cmd);
                PQfreemem(quoted_channel);
@@ -591,10 +513,10 @@ static inline PGresult *unlisten(PGconn *conn, const char *channel_str, size_t c
        return res;
 }
 
-static int apply_unlisten(void *p TSRMLS_DC, int argc, va_list argv, zend_hash_key *key)
+static int apply_unlisten(zval *p, int argc, va_list argv, zend_hash_key *key)
 {
        php_pqconn_object_t *obj = va_arg(argv, php_pqconn_object_t *);
-       PGresult *res = unlisten(obj->intern->conn, key->arKey, key->nKeyLength - 1 TSRMLS_CC);
+       PGresult *res = unlisten(obj->intern->conn, key->key->val, key->key->len);
 
        if (res) {
                PHP_PQclear(res);
@@ -603,7 +525,7 @@ static int apply_unlisten(void *p TSRMLS_DC, int argc, va_list argv, zend_hash_k
        return ZEND_HASH_APPLY_REMOVE;
 }
 
-static void php_pqconn_retire(php_persistent_handle_factory_t *f, void **handle TSRMLS_DC)
+static void php_pqconn_retire(php_persistent_handle_factory_t *f, void **handle)
 {
        php_pqconn_event_data_t *evdata = PQinstanceData(*handle, php_pqconn_event);
        PGcancel *cancel;
@@ -643,7 +565,7 @@ static void php_pqconn_retire(php_persistent_handle_factory_t *f, void **handle
 
        if (evdata) {
                /* clean up notify listeners */
-               zend_hash_apply_with_arguments(&evdata->obj->intern->listeners TSRMLS_CC, apply_unlisten, 1, evdata->obj);
+               zend_hash_apply_with_arguments(&evdata->obj->intern->listeners, apply_unlisten, 1, evdata->obj);
 
                /* release instance data */
                efree(evdata);
@@ -657,34 +579,36 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(pqconn, __construct) {
        zend_error_handling zeh;
        char *dsn_str = "";
-       int dsn_len = 0;
-       long flags = 0;
+       size_t dsn_len = 0;
+       zend_long flags = 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, "|sl", &dsn_str, &dsn_len, &flags);
+       zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
+       rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|sl", &dsn_str, &dsn_len, &flags);
        zend_restore_error_handling(&zeh TSRMLS_CC);
 
        if (SUCCESS == rv) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (obj->intern) {
-                       throw_exce(EX_BAD_METHODCALL TSRMLS_CC, "pq\\Connection already initialized");
+                       throw_exce(EX_BAD_METHODCALL, "pq\\Connection already initialized");
                } else {
-                       php_pqconn_event_data_t *evdata =  php_pqconn_event_data_init(obj TSRMLS_CC);
+                       php_pqconn_event_data_t *evdata =  php_pqconn_event_data_init(obj);
                        php_pqconn_resource_factory_data_t rfdata = {dsn_str, flags};
 
                        obj->intern = ecalloc(1, sizeof(*obj->intern));
 
                        obj->intern->default_auto_convert = PHP_PQRES_CONV_ALL;
 
-                       zend_hash_init(&obj->intern->listeners, 0, NULL, (dtor_func_t) zend_hash_destroy, 0);
+                       zend_hash_init(&obj->intern->listeners, 0, NULL, ZVAL_PTR_DTOR, 0);
                        zend_hash_init(&obj->intern->converters, 0, NULL, ZVAL_PTR_DTOR, 0);
                        zend_hash_init(&obj->intern->eventhandlers, 0, NULL, (dtor_func_t) zend_hash_destroy, 0);
 
                        if (flags & PHP_PQCONN_PERSISTENT) {
-                               php_persistent_handle_factory_t *phf = php_persistent_handle_concede(NULL, ZEND_STRL("pq\\Connection"), dsn_str, dsn_len, php_pqconn_wakeup, php_pqconn_retire TSRMLS_CC);
+                               zend_string *dsn = zend_string_init(dsn_str, dsn_len, 0);
+                               php_persistent_handle_factory_t *phf = php_persistent_handle_concede(NULL, PHP_PQ_G->connection.name, dsn, php_pqconn_wakeup, php_pqconn_retire);
                                php_persistent_handle_resource_factory_init(&obj->intern->factory, phf);
+                               zend_string_release(dsn);
                        } else {
                                php_resource_factory_init(&obj->intern->factory, &php_pqconn_resource_factory_ops, NULL, NULL);
                        }
@@ -693,13 +617,13 @@ static PHP_METHOD(pqconn, __construct) {
                                obj->intern->poller = (int (*)(PGconn*)) PQconnectPoll;
                        }
 
-                       obj->intern->conn = php_resource_factory_handle_ctor(&obj->intern->factory, &rfdata TSRMLS_CC);
+                       obj->intern->conn = php_resource_factory_handle_ctor(&obj->intern->factory, &rfdata);
 
                        PQsetInstanceData(obj->intern->conn, php_pqconn_event, evdata);
                        PQsetNoticeReceiver(obj->intern->conn, php_pqconn_notice_recv, evdata);
 
-                       if (SUCCESS != php_pqconn_update_socket(getThis(), obj TSRMLS_CC)) {
-                               throw_exce(EX_CONNECTION_FAILED TSRMLS_CC, "Connection failed (%s)", PHP_PQerrorMessage(obj->intern->conn));
+                       if (SUCCESS != php_pqconn_update_socket(getThis(), obj)) {
+                               throw_exce(EX_CONNECTION_FAILED, "Connection failed (%s)", PHP_PQerrorMessage(obj->intern->conn));
                        }
                }
        }
@@ -711,23 +635,23 @@ static PHP_METHOD(pqconn, reset) {
        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();
-       zend_restore_error_handling(&zeh TSRMLS_CC);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
                        PQreset(obj->intern->conn);
 
                        if (CONNECTION_OK != PQstatus(obj->intern->conn)) {
-                               throw_exce(EX_CONNECTION_FAILED TSRMLS_CC, "Connection reset failed: (%s)", PHP_PQerrorMessage(obj->intern->conn));
+                               throw_exce(EX_CONNECTION_FAILED, "Connection reset failed: (%s)", PHP_PQerrorMessage(obj->intern->conn));
                        }
 
-                       php_pqconn_notify_listeners(obj TSRMLS_CC);
+                       php_pqconn_notify_listeners(obj);
                }
        }
 }
@@ -738,12 +662,12 @@ static PHP_METHOD(pqconn, resetAsync) {
        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();
-       zend_restore_error_handling(&zeh TSRMLS_CC);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
                        throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
@@ -754,7 +678,7 @@ static PHP_METHOD(pqconn, resetAsync) {
                                obj->intern->poller = (int (*)(PGconn*)) PQresetPoll;
                        }
 
-                       php_pqconn_notify_listeners(obj TSRMLS_CC);
+                       php_pqconn_notify_listeners(obj);
                }
        }
 }
@@ -766,23 +690,23 @@ static PHP_METHOD(pqconn, unlisten)
 {
        zend_error_handling zeh;
        char *channel_str;
-       int channel_len;
+       size_t channel_len;
        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, "s", &channel_str, &channel_len);
-       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(), "s", &channel_str, &channel_len);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
-               } else if (SUCCESS == zend_hash_del(&obj->intern->listeners, channel_str, channel_len + 1)) {
-                       PGresult *res = unlisten(obj->intern->conn, channel_str, channel_len TSRMLS_CC);
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
+               } else if (SUCCESS == zend_hash_str_del(&obj->intern->listeners, channel_str, channel_len)) {
+                       PGresult *res = unlisten(obj->intern->conn, channel_str, channel_len);
 
                        if (res) {
-                               php_pqres_success(res TSRMLS_CC);
+                               php_pqres_success(res);
                                PHP_PQclear(res);
                        }
                }
@@ -795,23 +719,23 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(pqconn, unlistenAsync) {
        zend_error_handling zeh;
        char *channel_str;
-       int channel_len;
+       size_t channel_len;
        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, "s", &channel_str, &channel_len);
-       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(), "s", &channel_str, &channel_len);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
                        char *quoted_channel = PQescapeIdentifier(obj->intern->conn, channel_str, channel_len);
 
                        if (!quoted_channel) {
-                               throw_exce(EX_ESCAPE TSRMLS_CC, "Failed to escape channel identifier (%s)", PHP_PQerrorMessage(obj->intern->conn));
+                               throw_exce(EX_ESCAPE, "Failed to escape channel identifier (%s)", PHP_PQerrorMessage(obj->intern->conn));
                        } else {
                                smart_str cmd = {0};
 
@@ -819,33 +743,33 @@ static PHP_METHOD(pqconn, unlistenAsync) {
                                smart_str_appends(&cmd, quoted_channel);
                                smart_str_0(&cmd);
 
-                               if (!PQsendQuery(obj->intern->conn, cmd.c)) {
-                                       throw_exce(EX_IO TSRMLS_CC, "Failed to uninstall listener (%s)", PHP_PQerrorMessage(obj->intern->conn));
+                               if (!PQsendQuery(obj->intern->conn, smart_str_v(&cmd))) {
+                                       throw_exce(EX_IO, "Failed to uninstall listener (%s)", PHP_PQerrorMessage(obj->intern->conn));
                                } else {
                                        obj->intern->poller = PQconsumeInput;
-                                       zend_hash_del(&obj->intern->listeners, channel_str, channel_len + 1);
+                                       zend_hash_str_del(&obj->intern->listeners, channel_str, channel_len);
                                }
 
                                smart_str_free(&cmd);
                                PQfreemem(quoted_channel);
-                               php_pqconn_notify_listeners(obj TSRMLS_CC);
+                               php_pqconn_notify_listeners(obj);
                        }
                }
        }
 }
 
-static void php_pqconn_add_listener(php_pqconn_object_t *obj, const char *channel_str, size_t channel_len, php_pq_callback_t *listener TSRMLS_DC)
+static void php_pqconn_add_listener(php_pqconn_object_t *obj, const char *channel_str, size_t channel_len, php_pq_callback_t *listener)
 {
-       HashTable ht, *existing_listeners;
+       zval *existing, tmp;
 
        php_pq_callback_addref(listener);
 
-       if (SUCCESS == zend_hash_find(&obj->intern->listeners, channel_str, channel_len + 1, (void *) &existing_listeners)) {
-               zend_hash_next_index_insert(existing_listeners, (void *) listener, sizeof(*listener), NULL);
+       if ((existing = zend_hash_str_find(&obj->intern->listeners, channel_str, channel_len))) {
+               zend_hash_next_index_insert_mem(Z_ARRVAL_P(existing), (void *) listener, sizeof(*listener));
        } else {
-               zend_hash_init(&ht, 1, NULL, (dtor_func_t) php_pq_callback_dtor, 0);
-               zend_hash_next_index_insert(&ht, (void *) listener, sizeof(*listener), NULL);
-               zend_hash_add(&obj->intern->listeners, channel_str, channel_len + 1, (void *) &ht, sizeof(HashTable), NULL);
+               ZVAL_NEW_ARR(&tmp);
+               zend_hash_next_index_insert_mem(Z_ARRVAL(tmp), (void *) listener, sizeof(*listener));
+               zend_hash_str_add(&obj->intern->listeners, channel_str, channel_len, &tmp);
        }
 }
 
@@ -856,24 +780,24 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(pqconn, listen) {
        zend_error_handling zeh;
        char *channel_str = NULL;
-       int channel_len = 0;
+       size_t channel_len = 0;
        php_pq_callback_t listener = {{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, "sf", &channel_str, &channel_len, &listener.fci, &listener.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(), "sf", &channel_str, &channel_len, &listener.fci, &listener.fcc);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
                        char *quoted_channel = PQescapeIdentifier(obj->intern->conn, channel_str, channel_len);
 
                        if (!quoted_channel) {
-                               throw_exce(EX_ESCAPE TSRMLS_CC, "Failed to escape channel identifier (%s)", PHP_PQerrorMessage(obj->intern->conn));
+                               throw_exce(EX_ESCAPE, "Failed to escape channel identifier (%s)", PHP_PQerrorMessage(obj->intern->conn));
                        } else {
                                PGresult *res;
                                smart_str cmd = {0};
@@ -882,22 +806,22 @@ static PHP_METHOD(pqconn, listen) {
                                smart_str_appends(&cmd, quoted_channel);
                                smart_str_0(&cmd);
 
-                               res = PQexec(obj->intern->conn, cmd.c);
+                               res = PQexec(obj->intern->conn, smart_str_v(&cmd));
 
                                smart_str_free(&cmd);
                                PQfreemem(quoted_channel);
 
                                if (!res) {
-                                       throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to install listener (%s)", PHP_PQerrorMessage(obj->intern->conn));
+                                       throw_exce(EX_RUNTIME, "Failed to install listener (%s)", PHP_PQerrorMessage(obj->intern->conn));
                                } else {
-                                       if (SUCCESS == php_pqres_success(res TSRMLS_CC)) {
+                                       if (SUCCESS == php_pqres_success(res)) {
                                                obj->intern->poller = PQconsumeInput;
-                                               php_pqconn_add_listener(obj, channel_str, channel_len, &listener TSRMLS_CC);
+                                               php_pqconn_add_listener(obj, channel_str, channel_len, &listener);
                                        }
                                        PHP_PQclear(res);
                                }
 
-                               php_pqconn_notify_listeners(obj TSRMLS_CC);
+                               php_pqconn_notify_listeners(obj);
                        }
                }
        }
@@ -910,16 +834,16 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(pqconn, listenAsync) {
        zend_error_handling zeh;
        char *channel_str = NULL;
-       int channel_len = 0;
+       size_t channel_len = 0;
        php_pq_callback_t listener = {{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, "sf", &channel_str, &channel_len, &listener.fci, &listener.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(), "sf", &channel_str, &channel_len, &listener.fci, &listener.fcc);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
                        throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
@@ -935,16 +859,16 @@ static PHP_METHOD(pqconn, listenAsync) {
                                smart_str_appends(&cmd, quoted_channel);
                                smart_str_0(&cmd);
 
-                               if (!PQsendQuery(obj->intern->conn, cmd.c)) {
-                                       throw_exce(EX_IO TSRMLS_CC, "Failed to install listener (%s)", PHP_PQerrorMessage(obj->intern->conn));
+                               if (!PQsendQuery(obj->intern->conn, smart_str_v(&cmd))) {
+                                       throw_exce(EX_IO, "Failed to install listener (%s)", PHP_PQerrorMessage(obj->intern->conn));
                                } else {
                                        obj->intern->poller = PQconsumeInput;
-                                       php_pqconn_add_listener(obj, channel_str, channel_len, &listener TSRMLS_CC);
+                                       php_pqconn_add_listener(obj, channel_str, channel_len, &listener);
                                }
 
                                smart_str_free(&cmd);
                                PQfreemem(quoted_channel);
-                               php_pqconn_notify_listeners(obj TSRMLS_CC);
+                               php_pqconn_notify_listeners(obj);
                        }
                }
        }
@@ -957,18 +881,18 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(pqconn, notify) {
        zend_error_handling zeh;
        char *channel_str, *message_str;
-       int channel_len, message_len;
+       size_t channel_len, message_len;
        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, "ss", &channel_str, &channel_len, &message_str, &message_len);
-       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(), "ss", &channel_str, &channel_len, &message_str, &message_len);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
                        PGresult *res;
                        char *params[2] = {channel_str, message_str};
@@ -976,13 +900,13 @@ static PHP_METHOD(pqconn, notify) {
                        res = PQexecParams(obj->intern->conn, "select pg_notify($1, $2)", 2, NULL, (const char *const*) params, NULL, NULL, 0);
 
                        if (!res) {
-                               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to notify listeners (%s)", PHP_PQerrorMessage(obj->intern->conn));
+                               throw_exce(EX_RUNTIME, "Failed to notify listeners (%s)", PHP_PQerrorMessage(obj->intern->conn));
                        } else {
-                               php_pqres_success(res TSRMLS_CC);
+                               php_pqres_success(res);
                                PHP_PQclear(res);
                        }
 
-                       php_pqconn_notify_listeners(obj TSRMLS_CC);
+                       php_pqconn_notify_listeners(obj);
                }
        }
 }
@@ -994,28 +918,28 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(pqconn, notifyAsync) {
        zend_error_handling zeh;
        char *channel_str, *message_str;
-       int channel_len, message_len;
+       size_t channel_len, message_len;
        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, "ss", &channel_str, &channel_len, &message_str, &message_len);
-       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(), "ss", &channel_str, &channel_len, &message_str, &message_len);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
                        char *params[2] = {channel_str, message_str};
 
                        if (!PQsendQueryParams(obj->intern->conn, "select pg_notify($1, $2)", 2, NULL, (const char *const*) params, NULL, NULL, 0)) {
-                               throw_exce(EX_IO TSRMLS_CC, "Failed to notify listeners (%s)", PHP_PQerrorMessage(obj->intern->conn));
+                               throw_exce(EX_IO, "Failed to notify listeners (%s)", PHP_PQerrorMessage(obj->intern->conn));
                        } else {
                                obj->intern->poller = PQconsumeInput;
                        }
 
-                       php_pqconn_notify_listeners(obj TSRMLS_CC);
+                       php_pqconn_notify_listeners(obj);
                }
        }
 }
@@ -1026,24 +950,24 @@ static PHP_METHOD(pqconn, poll) {
        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();
-       zend_restore_error_handling(&zeh TSRMLS_CC);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else if (!obj->intern->poller) {
-                       throw_exce(EX_RUNTIME TSRMLS_CC, "No asynchronous operation active");
+                       throw_exce(EX_RUNTIME, "No asynchronous operation active");
                } else {
                        if (obj->intern->poller == PQconsumeInput) {
                                RETVAL_LONG(obj->intern->poller(obj->intern->conn) * PGRES_POLLING_OK);
                        } else {
                                RETVAL_LONG(obj->intern->poller(obj->intern->conn));
                        }
-                       php_pqconn_notify_listeners(obj TSRMLS_CC);
+                       php_pqconn_notify_listeners(obj);
                }
        }
 }
@@ -1054,30 +978,30 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(pqconn, exec) {
        zend_error_handling zeh;
        char *query_str;
-       int query_len;
+       size_t query_len;
        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, "s", &query_str, &query_len);
-       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(), "s", &query_str, &query_len);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
                        PGresult *res = PQexec(obj->intern->conn, query_str);
 
                        if (!res) {
-                               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to execute query (%s)", PHP_PQerrorMessage(obj->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);
+                               throw_exce(EX_RUNTIME, "Failed to execute query (%s)", PHP_PQerrorMessage(obj->intern->conn));
+                       } else if (SUCCESS == php_pqres_success(res)) {
+                               php_pq_object_to_zval_no_addref(PQresultInstanceData(res, php_pqconn_event), return_value);
                        } else {
                                PHP_PQclear(res);
                        }
 
-                       php_pqconn_notify_listeners(obj TSRMLS_CC);
+                       php_pqconn_notify_listeners(obj);
                }
        }
 }
@@ -1088,25 +1012,25 @@ static PHP_METHOD(pqconn, getResult) {
        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();
-       zend_restore_error_handling(&zeh TSRMLS_CC);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
                        PGresult *res = PQgetResult(obj->intern->conn);
 
                        if (!res) {
                                RETVAL_NULL();
                        } else {
-                               php_pq_object_to_zval_no_addref(PQresultInstanceData(res, php_pqconn_event), &return_value TSRMLS_CC);
+                               php_pq_object_to_zval_no_addref(PQresultInstanceData(res, php_pqconn_event), return_value);
                        }
 
-                       php_pqconn_notify_listeners(obj TSRMLS_CC);
+                       php_pqconn_notify_listeners(obj);
                }
        }
 }
@@ -1119,28 +1043,28 @@ static PHP_METHOD(pqconn, execAsync) {
        zend_error_handling zeh;
        php_pq_callback_t resolver = {{0}};
        char *query_str;
-       int query_len;
+       size_t query_len;
        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, "s|f", &query_str, &query_len, &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(), "s|f", &query_str, &query_len, &resolver.fci, &resolver.fcc);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else if (!PQsendQuery(obj->intern->conn, query_str)) {
-                       throw_exce(EX_IO TSRMLS_CC, "Failed to execute query (%s)", PHP_PQerrorMessage(obj->intern->conn));
+                       throw_exce(EX_IO, "Failed to execute query (%s)", PHP_PQerrorMessage(obj->intern->conn));
 #if HAVE_PQSETSINGLEROWMODE
                } else if (obj->intern->unbuffered && !PQsetSingleRowMode(obj->intern->conn)) {
-                       throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to enable unbuffered mode (%s)", PHP_PQerrorMessage(obj->intern->conn));
+                       throw_exce(EX_RUNTIME, "Failed to enable unbuffered mode (%s)", PHP_PQerrorMessage(obj->intern->conn));
 #endif
                } else {
-                       php_pq_callback_recurse(&obj->intern->onevent, &resolver TSRMLS_CC);
+                       php_pq_callback_recurse(&obj->intern->onevent, &resolver);
                        obj->intern->poller = PQconsumeInput;
-                       php_pqconn_notify_listeners(obj TSRMLS_CC);
+                       php_pqconn_notify_listeners(obj);
                }
        }
 }
@@ -1153,38 +1077,38 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(pqconn, execParams) {
        zend_error_handling zeh;
        char *query_str;
-       int query_len;
+       size_t query_len;
        zval *zparams;
        zval *ztypes = 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, "sa/|a/!", &query_str, &query_len, &zparams, &ztypes);
-       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(), "sa/|a/!", &query_str, &query_len, &zparams, &ztypes);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
                        PGresult *res;
                        php_pq_params_t *params;
 
-                       params = php_pq_params_init(&obj->intern->converters, ztypes ? Z_ARRVAL_P(ztypes) : NULL, Z_ARRVAL_P(zparams) TSRMLS_CC);
+                       params = php_pq_params_init(&obj->intern->converters, ztypes ? Z_ARRVAL_P(ztypes) : NULL, Z_ARRVAL_P(zparams));
                        res = PQexecParams(obj->intern->conn, query_str, params->param.count, params->type.oids, (const char *const*) params->param.strings, NULL, NULL, 0);
                        php_pq_params_free(&params);
 
                        if (!res) {
-                               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to execute query (%s)", PHP_PQerrorMessage(obj->intern->conn));
+                               throw_exce(EX_RUNTIME, "Failed to execute query (%s)", PHP_PQerrorMessage(obj->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);
+                               if (SUCCESS == php_pqres_success(res)) {
+                                       php_pq_object_to_zval_no_addref(PQresultInstanceData(res, php_pqconn_event), return_value);
                                } else {
                                        PHP_PQclear(res);
                                }
 
-                               php_pqconn_notify_listeners(obj TSRMLS_CC);
+                               php_pqconn_notify_listeners(obj);
                        }
                }
        }
@@ -1200,62 +1124,62 @@ static PHP_METHOD(pqconn, execParamsAsync) {
        zend_error_handling zeh;
        php_pq_callback_t resolver = {{0}};
        char *query_str;
-       int query_len;
+       size_t query_len;
        zval *zparams;
        zval *ztypes = 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, "sa/|a/!f", &query_str, &query_len, &zparams, &ztypes, &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(), "sa/|a/!f", &query_str, &query_len, &zparams, &ztypes, &resolver.fci, &resolver.fcc);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
                        int rc;
                        php_pq_params_t *params;
 
-                       params = php_pq_params_init(&obj->intern->converters, ztypes ? Z_ARRVAL_P(ztypes) : NULL, Z_ARRVAL_P(zparams) TSRMLS_CC);
+                       params = php_pq_params_init(&obj->intern->converters, ztypes ? Z_ARRVAL_P(ztypes) : NULL, Z_ARRVAL_P(zparams));
                        rc = PQsendQueryParams(obj->intern->conn, query_str, params->param.count, params->type.oids, (const char *const*) params->param.strings, NULL, NULL, 0);
                        php_pq_params_free(&params);
 
                        if (!rc) {
-                               throw_exce(EX_IO TSRMLS_CC, "Failed to execute query (%s)", PHP_PQerrorMessage(obj->intern->conn));
+                               throw_exce(EX_IO, "Failed to execute query (%s)", PHP_PQerrorMessage(obj->intern->conn));
 #if HAVE_PQSETSINGLEROWMODE
                        } else if (obj->intern->unbuffered && !PQsetSingleRowMode(obj->intern->conn)) {
-                               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to enable unbuffered mode (%s)", PHP_PQerrorMessage(obj->intern->conn));
+                               throw_exce(EX_RUNTIME, "Failed to enable unbuffered mode (%s)", PHP_PQerrorMessage(obj->intern->conn));
 #endif
                        } else {
-                               php_pq_callback_recurse(&obj->intern->onevent, &resolver TSRMLS_CC);
+                               php_pq_callback_recurse(&obj->intern->onevent, &resolver);
                                obj->intern->poller = PQconsumeInput;
-                               php_pqconn_notify_listeners(obj TSRMLS_CC);
+                               php_pqconn_notify_listeners(obj);
                        }
                }
        }
-       zend_restore_error_handling(&zeh TSRMLS_CC);
+       zend_restore_error_handling(&zeh);
 }
 
-ZEND_RESULT_CODE php_pqconn_prepare(zval *object, php_pqconn_object_t *obj, const char *name, const char *query, php_pq_params_t *params TSRMLS_DC)
+ZEND_RESULT_CODE php_pqconn_prepare(zval *object, php_pqconn_object_t *obj, const char *name, const char *query, php_pq_params_t *params)
 {
        PGresult *res;
        ZEND_RESULT_CODE rv;
 
        if (!obj) {
-               obj = zend_object_store_get_object(object TSRMLS_CC);
+               obj = PHP_PQ_OBJ(object, NULL);
        }
 
        res = PQprepare(obj->intern->conn, name, query, params->type.count, params->type.oids);
 
        if (!res) {
                rv = FAILURE;
-               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to prepare statement (%s)", PHP_PQerrorMessage(obj->intern->conn));
+               throw_exce(EX_RUNTIME, "Failed to prepare statement (%s)", PHP_PQerrorMessage(obj->intern->conn));
        } else {
-               rv = php_pqres_success(res TSRMLS_CC);
+               rv = php_pqres_success(res);
                PHP_PQclear(res);
-               php_pqconn_notify_listeners(obj TSRMLS_CC);
+               php_pqconn_notify_listeners(obj);
        }
 
        return rv;
@@ -1270,28 +1194,27 @@ static PHP_METHOD(pqconn, prepare) {
        zend_error_handling zeh;
        zval *ztypes = NULL;
        char *name_str, *query_str;
-       int name_len, *query_len;
+       size_t name_len, *query_len;
        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, "ss|a/!", &name_str, &name_len, &query_str, &query_len, &ztypes);
-       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(), "ss|a/!", &name_str, &name_len, &query_str, &query_len, &ztypes);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
-                       php_pq_params_t *params = php_pq_params_init(&obj->intern->converters, ztypes ? Z_ARRVAL_P(ztypes) : NULL, NULL TSRMLS_CC);
+                       php_pq_params_t *params = php_pq_params_init(&obj->intern->converters, ztypes ? Z_ARRVAL_P(ztypes) : NULL, NULL);
 
-                       if (SUCCESS != php_pqconn_prepare(getThis(), obj, name_str, query_str, params TSRMLS_CC)) {
+                       if (SUCCESS != php_pqconn_prepare(getThis(), obj, name_str, query_str, params)) {
                                php_pq_params_free(&params);
                        } else {
-                               php_pqstm_t *stm = php_pqstm_init(obj, name_str, query_str, params TSRMLS_CC);
+                               php_pqstm_t *stm = php_pqstm_init(obj, name_str, query_str, params);
 
-                               return_value->type = IS_OBJECT;
-                               return_value->value.obj = php_pqstm_create_object_ex(php_pqstm_class_entry, stm, NULL TSRMLS_CC);
+                               RETVAL_OBJ(&php_pqstm_create_object_ex(php_pqstm_class_entry, stm)->zo);
                        }
                }
        }
@@ -1302,16 +1225,16 @@ ZEND_RESULT_CODE php_pqconn_prepare_async(zval *object, php_pqconn_object_t *obj
        ZEND_RESULT_CODE rv;
 
        if (!obj) {
-               obj = zend_object_store_get_object(object TSRMLS_CC);
+               obj = PHP_PQ_OBJ(object, NULL);
        }
 
        if (!PQsendPrepare(obj->intern->conn, name, query, params->type.count, params->type.oids)) {
                rv = FAILURE;
-               throw_exce(EX_IO TSRMLS_CC, "Failed to prepare statement (%s)", PHP_PQerrorMessage(obj->intern->conn));
+               throw_exce(EX_IO, "Failed to prepare statement (%s)", PHP_PQerrorMessage(obj->intern->conn));
        } else {
                rv = SUCCESS;
                obj->intern->poller = PQconsumeInput;
-               php_pqconn_notify_listeners(obj TSRMLS_CC);
+               php_pqconn_notify_listeners(obj);
        }
 
        return rv;
@@ -1326,51 +1249,50 @@ static PHP_METHOD(pqconn, prepareAsync) {
        zend_error_handling zeh;
        zval *ztypes = NULL;
        char *name_str, *query_str;
-       int name_len, *query_len;
+       size_t name_len, *query_len;
        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, "ss|a/!", &name_str, &name_len, &query_str, &query_len, &ztypes);
-       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(), "ss|a/!", &name_str, &name_len, &query_str, &query_len, &ztypes);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
-                       php_pq_params_t *params = php_pq_params_init(&obj->intern->converters, ztypes ? Z_ARRVAL_P(ztypes) : NULL, NULL TSRMLS_CC);
+                       php_pq_params_t *params = php_pq_params_init(&obj->intern->converters, ztypes ? Z_ARRVAL_P(ztypes) : NULL, NULL);
 
-                       if (SUCCESS != php_pqconn_prepare_async(getThis(), obj, name_str, query_str, params TSRMLS_CC)) {
+                       if (SUCCESS != php_pqconn_prepare_async(getThis(), obj, name_str, query_str, params)) {
                                php_pq_params_free(&params);
                        } else {
-                               php_pqstm_t *stm = php_pqstm_init(obj, name_str, query_str, params TSRMLS_CC);
+                               php_pqstm_t *stm = php_pqstm_init(obj, name_str, query_str, params);
 
-                               return_value->type = IS_OBJECT;
-                               return_value->value.obj = php_pqstm_create_object_ex(php_pqstm_class_entry, stm, NULL TSRMLS_CC);
+                               RETVAL_OBJ(&php_pqstm_create_object_ex(php_pqstm_class_entry, stm)->zo);
                        }
                }
        }
 }
 
-ZEND_RESULT_CODE php_pqconn_declare(zval *object, php_pqconn_object_t *obj, const char *decl TSRMLS_DC)
+ZEND_RESULT_CODE php_pqconn_declare(zval *object, php_pqconn_object_t *obj, const char *decl)
 {
        PGresult *res;
        ZEND_RESULT_CODE rv;
 
        if (!obj) {
-               obj = zend_object_store_get_object(object TSRMLS_CC);
+               obj = PHP_PQ_OBJ(object, NULL);
        }
 
        res = PQexec(obj->intern->conn, decl);
 
        if (!res) {
                rv = FAILURE;
-               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to declare cursor (%s)", PHP_PQerrorMessage(obj->intern->conn));
+               throw_exce(EX_RUNTIME, "Failed to declare cursor (%s)", PHP_PQerrorMessage(obj->intern->conn));
        } else {
-               rv = php_pqres_success(res TSRMLS_CC);
+               rv = php_pqres_success(res);
                PHP_PQclear(res);
-               php_pqconn_notify_listeners(obj TSRMLS_CC);
+               php_pqconn_notify_listeners(obj);
        }
 
        return rv;
@@ -1384,50 +1306,49 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(pqconn, declare) {
        zend_error_handling zeh;
        char *name_str, *query_str;
-       int name_len, query_len;
-       long flags;
+       size_t name_len, query_len;
+       zend_long flags;
        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, "sls", &name_str, &name_len, &flags, &query_str, &query_len);
-       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(), "sls", &name_str, &name_len, &flags, &query_str, &query_len);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
                        int query_offset;
                        char *decl = php_pqcur_declare_str(name_str, name_len, flags, query_str, query_len, &query_offset);
 
-                       if (SUCCESS != php_pqconn_declare(getThis(), obj, decl TSRMLS_CC)) {
+                       if (SUCCESS != php_pqconn_declare(getThis(), obj, decl)) {
                                efree(decl);
                        } else {
-                               php_pqcur_t *cur = php_pqcur_init(obj, name_str, decl, query_offset, flags TSRMLS_CC);
+                               php_pqcur_t *cur = php_pqcur_init(obj, name_str, decl, query_offset, flags);
 
-                               return_value->type = IS_OBJECT;
-                               return_value->value.obj = php_pqcur_create_object_ex(php_pqcur_class_entry, cur, NULL TSRMLS_CC);
+                               RETVAL_OBJ(&php_pqcur_create_object_ex(php_pqcur_class_entry, cur)->zo);
                        }
                }
        }
 }
 
-ZEND_RESULT_CODE php_pqconn_declare_async(zval *object, php_pqconn_object_t *obj, const char *decl TSRMLS_DC)
+ZEND_RESULT_CODE php_pqconn_declare_async(zval *object, php_pqconn_object_t *obj, const char *decl)
 {
        ZEND_RESULT_CODE rv;
 
        if (!obj) {
-               obj = zend_object_store_get_object(object TSRMLS_CC);
+               obj = PHP_PQ_OBJ(object, NULL);
        }
 
        if (!PQsendQuery(obj->intern->conn, decl)) {
                rv = FAILURE;
-               throw_exce(EX_IO TSRMLS_CC, "Failed to declare cursor (%s)", PHP_PQerrorMessage(obj->intern->conn));
+               throw_exce(EX_IO, "Failed to declare cursor (%s)", PHP_PQerrorMessage(obj->intern->conn));
        } else {
                rv = SUCCESS;
                obj->intern->poller = PQconsumeInput;
-               php_pqconn_notify_listeners(obj TSRMLS_CC);
+               php_pqconn_notify_listeners(obj);
        }
 
        return rv;
@@ -1441,30 +1362,29 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(pqconn, declareAsync) {
        zend_error_handling zeh;
        char *name_str, *query_str;
-       int name_len, query_len;
-       long flags;
+       size_t name_len, query_len;
+       zend_long flags;
        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, "sls", &name_str, &name_len, &flags, &query_str, &query_len);
-       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(), "sls", &name_str, &name_len, &flags, &query_str, &query_len);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
                        int query_offset;
                        char *decl = php_pqcur_declare_str(name_str, name_len, flags, query_str, query_len, &query_offset);
 
-                       if (SUCCESS != php_pqconn_declare_async(getThis(), obj, decl TSRMLS_CC)) {
+                       if (SUCCESS != php_pqconn_declare_async(getThis(), obj, decl)) {
                                efree(decl);
                        } else {
-                               php_pqcur_t *cur = php_pqcur_init(obj, name_str, decl, query_offset, flags TSRMLS_CC);
+                               php_pqcur_t *cur = php_pqcur_init(obj, name_str, decl, query_offset, flags);
 
-                               return_value->type = IS_OBJECT;
-                               return_value->value.obj = php_pqcur_create_object_ex(php_pqcur_class_entry, cur, NULL TSRMLS_CC);
+                               RETVAL_OBJ(&php_pqcur_create_object_ex(php_pqcur_class_entry, cur)->zo);
                        }
                }
        }
@@ -1475,21 +1395,21 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_quote, 0, 0, 1)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqconn, quote) {
        char *str;
-       int len;
+       size_t len;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &len)) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &str, &len)) {
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
                        char *quoted = PQescapeLiteral(obj->intern->conn, str, len);
 
                        if (!quoted) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to quote string (%s)", PHP_PQerrorMessage(obj->intern->conn));
+                               php_error_docref(NULL, E_WARNING, "Failed to quote string (%s)", PHP_PQerrorMessage(obj->intern->conn));
                                RETVAL_FALSE;
                        } else {
-                               RETVAL_STRING(quoted, 1);
+                               RETVAL_STRING(quoted);
                                PQfreemem(quoted);
                        }
                }
@@ -1501,21 +1421,21 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_quote_name, 0, 0, 1)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqconn, quoteName) {
        char *str;
-       int len;
+       size_t len;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &len)) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &str, &len)) {
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
                        char *quoted = PQescapeIdentifier(obj->intern->conn, str, len);
 
                        if (!quoted) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to quote name (%s)", PHP_PQerrorMessage(obj->intern->conn));
+                               php_error_docref(NULL, E_WARNING, "Failed to quote name (%s)", PHP_PQerrorMessage(obj->intern->conn));
                                RETVAL_FALSE;
                        } else {
-                               RETVAL_STRING(quoted, 1);
+                               RETVAL_STRING(quoted);
                                PQfreemem(quoted);
                        }
                }
@@ -1529,20 +1449,20 @@ static PHP_METHOD(pqconn, escapeBytea) {
        char *str;
        int len;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &len)) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &str, &len)) {
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
                        size_t escaped_len;
                        char *escaped_str = (char *) PQescapeByteaConn(obj->intern->conn, (unsigned char *) str, len, &escaped_len);
 
                        if (!escaped_str) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to escape bytea (%s)", PHP_PQerrorMessage(obj->intern->conn));
+                               php_error_docref(NULL, E_WARNING, "Failed to escape bytea (%s)", PHP_PQerrorMessage(obj->intern->conn));
                                RETVAL_FALSE;
                        } else {
-                               RETVAL_STRINGL(escaped_str, escaped_len - 1, 1);
+                               RETVAL_STRINGL(escaped_str, escaped_len - 1);
                                PQfreemem(escaped_str);
                        }
                }
@@ -1554,34 +1474,34 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_unescape_bytea, 0, 0, 1)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqconn, unescapeBytea) {
        char *str;
-       int len;
+       size_t len;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &len)) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &str, &len)) {
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
                        size_t unescaped_len;
                        char *unescaped_str = (char *) PQunescapeBytea((unsigned char *)str, &unescaped_len);
 
                        if (!unescaped_str) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to unescape bytea (%s)", PHP_PQerrorMessage(obj->intern->conn));
+                               php_error_docref(NULL, E_WARNING, "Failed to unescape bytea (%s)", PHP_PQerrorMessage(obj->intern->conn));
                                RETVAL_FALSE;
                        } else {
-                               RETVAL_STRINGL(unescaped_str, unescaped_len, 1);
+                               RETVAL_STRINGL(unescaped_str, unescaped_len);
                                PQfreemem(unescaped_str);
                        }
                }
        }
 }
 
-ZEND_RESULT_CODE php_pqconn_start_transaction(zval *zconn, php_pqconn_object_t *conn_obj, long isolation, zend_bool readonly, zend_bool deferrable TSRMLS_DC)
+ZEND_RESULT_CODE php_pqconn_start_transaction(zval *zconn, php_pqconn_object_t *conn_obj, long isolation, zend_bool readonly, zend_bool deferrable)
 {
        ZEND_RESULT_CODE rv = FAILURE;
 
        if (!conn_obj) {
-               conn_obj = zend_object_store_get_object(zconn TSRMLS_CC);
+               conn_obj = PHP_PQ_OBJ(zconn, NULL);
        }
 
        if (!conn_obj->intern) {
@@ -1600,14 +1520,14 @@ ZEND_RESULT_CODE php_pqconn_start_transaction(zval *zconn, php_pqconn_object_t *
                smart_str_appends(&cmd, " DEFERRABLE");
                smart_str_0(&cmd);
 
-               res = PQexec(conn_obj->intern->conn, cmd.c);
+               res = PQexec(conn_obj->intern->conn, smart_str_v(&cmd));
 
                if (!res) {
-                       throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to start transaction (%s)", PHP_PQerrorMessage(conn_obj->intern->conn));
+                       throw_exce(EX_RUNTIME, "Failed to start transaction (%s)", PHP_PQerrorMessage(conn_obj->intern->conn));
                } else {
-                       rv = php_pqres_success(res TSRMLS_CC);
+                       rv = php_pqres_success(res);
                        PHP_PQclear(res);
-                       php_pqconn_notify_listeners(conn_obj TSRMLS_CC);
+                       php_pqconn_notify_listeners(conn_obj);
                }
 
                smart_str_free(&cmd);
@@ -1616,16 +1536,16 @@ ZEND_RESULT_CODE php_pqconn_start_transaction(zval *zconn, php_pqconn_object_t *
        return rv;
 }
 
-ZEND_RESULT_CODE php_pqconn_start_transaction_async(zval *zconn, php_pqconn_object_t *conn_obj, long isolation, zend_bool readonly, zend_bool deferrable TSRMLS_DC)
+ZEND_RESULT_CODE php_pqconn_start_transaction_async(zval *zconn, php_pqconn_object_t *conn_obj, long isolation, zend_bool readonly, zend_bool deferrable)
 {
        ZEND_RESULT_CODE rv = FAILURE;
 
        if (!conn_obj) {
-               conn_obj = zend_object_store_get_object(zconn TSRMLS_CC);
+               conn_obj = PHP_PQ_OBJ(zconn, NULL);
        }
 
        if (!conn_obj->intern) {
-               throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+               throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
        } else {
                smart_str cmd = {0};
                const char *il = php_pq_isolation_level(&isolation);
@@ -1639,12 +1559,12 @@ ZEND_RESULT_CODE php_pqconn_start_transaction_async(zval *zconn, php_pqconn_obje
                smart_str_appends(&cmd, " DEFERRABLE");
                smart_str_0(&cmd);
 
-               if (!PQsendQuery(conn_obj->intern->conn, cmd.c)) {
-                       throw_exce(EX_IO TSRMLS_CC, "Failed to start transaction (%s)", PHP_PQerrorMessage(conn_obj->intern->conn));
+               if (!PQsendQuery(conn_obj->intern->conn, smart_str_v(&cmd))) {
+                       throw_exce(EX_IO, "Failed to start transaction (%s)", PHP_PQerrorMessage(conn_obj->intern->conn));
                } else {
                        rv = SUCCESS;
                        conn_obj->intern->poller = PQconsumeInput;
-                       php_pqconn_notify_listeners(conn_obj TSRMLS_CC);
+                       php_pqconn_notify_listeners(conn_obj);
                }
 
                smart_str_free(&cmd);
@@ -1660,31 +1580,30 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_start_transaction, 0, 0, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqconn, startTransaction) {
        zend_error_handling zeh;
-       php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-       long isolation = obj->intern ? obj->intern->default_txn_isolation : PHP_PQTXN_READ_COMMITTED;
+       php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
+       zend_long isolation = obj->intern ? obj->intern->default_txn_isolation : PHP_PQTXN_READ_COMMITTED;
        zend_bool readonly = obj->intern ? obj->intern->default_txn_readonly : 0;
        zend_bool deferrable = obj->intern ? obj->intern->default_txn_deferrable : 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, "|lbb", &isolation, &readonly, &deferrable);
-       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(), "|lbb", &isolation, &readonly, &deferrable);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               rv = php_pqconn_start_transaction(getThis(), obj, isolation, readonly, deferrable TSRMLS_CC);
+               rv = php_pqconn_start_transaction(getThis(), obj, isolation, readonly, deferrable);
 
                if (SUCCESS == rv) {
                        php_pqtxn_t *txn = ecalloc(1, sizeof(*txn));
 
-                       php_pq_object_addref(obj TSRMLS_CC);
+                       php_pq_object_addref(obj);
                        txn->conn = obj;
                        txn->open = 1;
                        txn->isolation = isolation;
                        txn->readonly = readonly;
                        txn->deferrable = deferrable;
 
-                       return_value->type = IS_OBJECT;
-                       return_value->value.obj = php_pqtxn_create_object_ex(php_pqtxn_class_entry, txn, NULL TSRMLS_CC);
+                       RETVAL_OBJ(&php_pqtxn_create_object_ex(php_pqtxn_class_entry, txn)->zo);
                }
        }
 }
@@ -1696,31 +1615,30 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_start_transaction_async, 0, 0, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqconn, startTransactionAsync) {
        zend_error_handling zeh;
-       php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-       long isolation = obj->intern ? obj->intern->default_txn_isolation : PHP_PQTXN_READ_COMMITTED;
+       php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
+       zend_long isolation = obj->intern ? obj->intern->default_txn_isolation : PHP_PQTXN_READ_COMMITTED;
        zend_bool readonly = obj->intern ? obj->intern->default_txn_readonly : 0;
        zend_bool deferrable = obj->intern ? obj->intern->default_txn_deferrable : 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, "|lbb", &isolation, &readonly, &deferrable);
-       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(), "|lbb", &isolation, &readonly, &deferrable);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               rv = php_pqconn_start_transaction_async(getThis(), obj, isolation, readonly, deferrable TSRMLS_CC);
+               rv = php_pqconn_start_transaction_async(getThis(), obj, isolation, readonly, deferrable);
 
                if (SUCCESS == rv) {
                        php_pqtxn_t *txn = ecalloc(1, sizeof(*txn));
 
-                       php_pq_object_addref(obj TSRMLS_CC);
+                       php_pq_object_addref(obj);
                        txn->conn = obj;
                        txn->open = 1;
                        txn->isolation = isolation;
                        txn->readonly = readonly;
                        txn->deferrable = deferrable;
 
-                       return_value->type = IS_OBJECT;
-                       return_value->value.obj = php_pqtxn_create_object_ex(php_pqtxn_class_entry, txn, NULL TSRMLS_CC);
+                       RETVAL_OBJ(&php_pqtxn_create_object_ex(php_pqtxn_class_entry, txn)->zo);
                }
        }
 }
@@ -1731,11 +1649,11 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(pqconn, trace) {
        zval *zstream = NULL;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r!", &zstream)) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|r!", &zstream)) {
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
                        if (!zstream) {
                                PQuntrace(obj->intern->conn);
@@ -1744,7 +1662,7 @@ static PHP_METHOD(pqconn, trace) {
                                FILE *fp;
                                php_stream *stream = NULL;
 
-                               php_stream_from_zval(stream, &zstream);
+                               php_stream_from_zval(stream, zstream);
 
                                if (SUCCESS != php_stream_cast(stream, PHP_STREAM_AS_STDIO, (void *) &fp, REPORT_ERRORS)) {
                                        RETVAL_FALSE;
@@ -1763,21 +1681,20 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_off, 0, 0, 1)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqconn, off) {
        zend_error_handling zeh;
-       char *type_str;
-       int type_len;
+       zend_string *type;
        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, "s", &type_str, &type_len);
-       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(), "S", &type);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
-                       RETURN_BOOL(SUCCESS == zend_hash_del(&obj->intern->eventhandlers, type_str, type_len + 1));
+                       RETURN_BOOL(SUCCESS == zend_hash_del(&obj->intern->eventhandlers, type));
                }
        }
 }
@@ -1789,48 +1706,42 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(pqconn, on) {
        zend_error_handling zeh;
        char *type_str;
-       int type_len;
+       size_t type_len;
        php_pq_callback_t cb = {{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, "sf", &type_str, &type_len, &cb.fci, &cb.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(), "sf", &type_str, &type_len, &cb.fci, &cb.fcc);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
                        throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
                } else {
-                       php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-
-                       RETVAL_LONG(php_pqconn_add_eventhandler(obj, type_str, type_len, &cb TSRMLS_CC));
+                       RETVAL_LONG(php_pqconn_add_eventhandler(obj, type_str, type_len, &cb));
                }
        }
 }
 
 struct apply_set_converter_arg {
        HashTable *ht;
-       zval **zconv;
+       zval *zconv;
        unsigned add:1;
 };
 
-static int apply_set_converter(void *p, void *a TSRMLS_DC)
+static int apply_set_converter(zval *zoid, void *a)
 {
-       zval *tmp, **zoid = p;
+       zend_long oid = zval_get_long(zoid);
        struct apply_set_converter_arg *arg = a;
 
-       tmp = *zoid;
-       Z_ADDREF_P(tmp);
-       convert_to_long_ex(&tmp);
        if (arg->add) {
-               Z_ADDREF_PP(arg->zconv);
-               zend_hash_index_update(arg->ht, Z_LVAL_P(tmp), arg->zconv, sizeof(zval *), NULL);
+               Z_ADDREF_P(arg->zconv);
+               zend_hash_index_update(arg->ht, oid, arg->zconv);
        } else {
-               zend_hash_index_del(arg->ht, Z_LVAL_P(tmp));
+               zend_hash_index_del(arg->ht, oid);
        }
-       zval_ptr_dtor(&tmp);
 
        return ZEND_HASH_APPLY_KEEP;
 }
@@ -1843,29 +1754,29 @@ static PHP_METHOD(pqconn, setConverter) {
        zend_error_handling zeh;
        zval *zcnv;
 
-       zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
-       rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zcnv, php_pqconv_class_entry);
-       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(), "O", &zcnv, php_pqconv_class_entry);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
-                       zval *tmp, *zoids = NULL;
+                       zval tmp, zoids;
                        struct apply_set_converter_arg arg = {NULL};
 
-                       zend_call_method_with_0_params(&zcnv, NULL, NULL, "converttypes", &zoids);
-                       tmp = zoids;
-                       Z_ADDREF_P(tmp);
-                       convert_to_array_ex(&tmp);
+                       ZVAL_NULL(&zoids);
+                       zend_call_method_with_0_params(zcnv, NULL, NULL, "converttypes", &zoids);
+                       ZVAL_DUP(&tmp, &zoids);
+                       convert_to_array(&tmp);
 
                        arg.ht = &obj->intern->converters;
-                       arg.zconv = &zcnv;
+                       arg.zconv = zcnv;
                        arg.add = 1;
 
-                       zend_hash_apply_with_argument(Z_ARRVAL_P(tmp), apply_set_converter, &arg TSRMLS_CC);
+                       zend_hash_apply_with_argument(Z_ARRVAL(tmp), apply_set_converter, &arg);
 
                        zval_ptr_dtor(&tmp);
                        zval_ptr_dtor(&zoids);
@@ -1881,29 +1792,29 @@ static PHP_METHOD(pqconn, unsetConverter) {
        zend_error_handling zeh;
        zval *zcnv;
 
-       zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
-       rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zcnv, php_pqconv_class_entry);
-       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(), "O", &zcnv, php_pqconv_class_entry);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
-                       zval *tmp, *zoids = NULL;
+                       zval tmp, zoids;
                        struct apply_set_converter_arg arg = {NULL};
 
-                       zend_call_method_with_0_params(&zcnv, NULL, NULL, "converttypes", &zoids);
-                       tmp = zoids;
-                       Z_ADDREF_P(tmp);
-                       convert_to_array_ex(&tmp);
+                       ZVAL_NULL(&zoids);
+                       zend_call_method_with_0_params(zcnv, NULL, NULL, "converttypes", &zoids);
+                       ZVAL_DUP(&tmp, &zoids);
+                       convert_to_array(&tmp);
 
                        arg.ht = &obj->intern->converters;
-                       arg.zconv = &zcnv;
+                       arg.zconv = zcnv;
                        arg.add = 0;
 
-                       zend_hash_apply_with_argument(Z_ARRVAL_P(tmp), apply_set_converter, &arg TSRMLS_CC);
+                       zend_hash_apply_with_argument(Z_ARRVAL(tmp), apply_set_converter, &arg);
 
                        zval_ptr_dtor(&tmp);
                        zval_ptr_dtor(&zoids);
@@ -1947,6 +1858,8 @@ static zend_function_entry php_pqconn_methods[] = {
 
 PHP_MSHUTDOWN_FUNCTION(pqconn)
 {
+       php_persistent_handle_cleanup(PHP_PQ_G->connection.name, NULL);
+       zend_string_release(PHP_PQ_G->connection.name);
        zend_hash_destroy(&php_pqconn_object_prophandlers);
        return SUCCESS;
 }
@@ -1957,10 +1870,12 @@ PHP_MINIT_FUNCTION(pqconn)
        php_pq_object_prophandler_t ph = {0};
 
        INIT_NS_CLASS_ENTRY(ce, "pq", "Connection", php_pqconn_methods);
-       php_pqconn_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
+       php_pqconn_class_entry = zend_register_internal_class_ex(&ce, NULL);
        php_pqconn_class_entry->create_object = php_pqconn_create_object;
 
        memcpy(&php_pqconn_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+       php_pqconn_object_handlers.offset = XtOffsetOf(php_pqconn_object_t, zo);
+       php_pqconn_object_handlers.free_obj = php_pqconn_object_free;
        php_pqconn_object_handlers.read_property = php_pq_object_read_prop;
        php_pqconn_object_handlers.write_property = php_pq_object_write_prop;
        php_pqconn_object_handlers.clone_obj = NULL;
@@ -1971,130 +1886,132 @@ PHP_MINIT_FUNCTION(pqconn)
 
        zend_hash_init(&php_pqconn_object_prophandlers, 20, NULL, NULL, 1);
 
-       zend_declare_property_long(php_pqconn_class_entry, ZEND_STRL("status"), CONNECTION_BAD, ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_long(php_pqconn_class_entry, ZEND_STRL("status"), CONNECTION_BAD, ZEND_ACC_PUBLIC);
        ph.read = php_pqconn_object_read_status;
-       zend_hash_add(&php_pqconn_object_prophandlers, "status", sizeof("status"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "status", sizeof("status")-1, (void *) &ph, sizeof(ph));
 
-       zend_declare_property_long(php_pqconn_class_entry, ZEND_STRL("transactionStatus"), PQTRANS_UNKNOWN, ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_long(php_pqconn_class_entry, ZEND_STRL("transactionStatus"), PQTRANS_UNKNOWN, ZEND_ACC_PUBLIC);
        ph.read = php_pqconn_object_read_transaction_status;
-       zend_hash_add(&php_pqconn_object_prophandlers, "transactionStatus", sizeof("transactionStatus"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "transactionStatus", sizeof("transactionStatus")-1, (void *) &ph, sizeof(ph));
 
-       zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("socket"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("socket"), ZEND_ACC_PUBLIC);
        ph.read = NULL; /* forward to std prophandler */
-       zend_hash_add(&php_pqconn_object_prophandlers, "socket", sizeof("socket"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "socket", sizeof("socket")-1, (void *) &ph, sizeof(ph));
 
-       zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("errorMessage"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("errorMessage"), ZEND_ACC_PUBLIC);
        ph.read = php_pqconn_object_read_error_message;
-       zend_hash_add(&php_pqconn_object_prophandlers, "errorMessage", sizeof("errorMessage"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "errorMessage", sizeof("errorMessage")-1, (void *) &ph, sizeof(ph));
 
-       zend_declare_property_bool(php_pqconn_class_entry, ZEND_STRL("busy"), 0, ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_bool(php_pqconn_class_entry, ZEND_STRL("busy"), 0, ZEND_ACC_PUBLIC);
        ph.read = php_pqconn_object_read_busy;
-       zend_hash_add(&php_pqconn_object_prophandlers, "busy", sizeof("busy"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "busy", sizeof("busy")-1, (void *) &ph, sizeof(ph));
 
-       zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("encoding"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("encoding"), ZEND_ACC_PUBLIC);
        ph.read = php_pqconn_object_read_encoding;
        ph.write = php_pqconn_object_write_encoding;
-       zend_hash_add(&php_pqconn_object_prophandlers, "encoding", sizeof("encoding"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "encoding", sizeof("encoding")-1, (void *) &ph, sizeof(ph));
        ph.write = NULL;
 
-       zend_declare_property_bool(php_pqconn_class_entry, ZEND_STRL("unbuffered"), 0, ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_bool(php_pqconn_class_entry, ZEND_STRL("unbuffered"), 0, ZEND_ACC_PUBLIC);
        ph.read = php_pqconn_object_read_unbuffered;
        ph.write = php_pqconn_object_write_unbuffered;
-       zend_hash_add(&php_pqconn_object_prophandlers, "unbuffered", sizeof("unbuffered"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "unbuffered", sizeof("unbuffered")-1, (void *) &ph, sizeof(ph));
        ph.write = NULL;
 
-       zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("db"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("db"), ZEND_ACC_PUBLIC);
        ph.read = php_pqconn_object_read_db;
-       zend_hash_add(&php_pqconn_object_prophandlers, "db", sizeof("db"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "db", sizeof("db")-1, (void *) &ph, sizeof(ph));
 
-       zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("user"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("user"), ZEND_ACC_PUBLIC);
        ph.read = php_pqconn_object_read_user;
-       zend_hash_add(&php_pqconn_object_prophandlers, "user", sizeof("user"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "user", sizeof("user")-1, (void *) &ph, sizeof(ph));
 
-       zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("pass"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("pass"), ZEND_ACC_PUBLIC);
        ph.read = php_pqconn_object_read_pass;
-       zend_hash_add(&php_pqconn_object_prophandlers, "pass", sizeof("pass"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "pass", sizeof("pass")-1, (void *) &ph, sizeof(ph));
 
-       zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("host"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("host"), ZEND_ACC_PUBLIC);
        ph.read = php_pqconn_object_read_host;
-       zend_hash_add(&php_pqconn_object_prophandlers, "host", sizeof("host"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "host", sizeof("host")-1, (void *) &ph, sizeof(ph));
 
-       zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("port"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("port"), ZEND_ACC_PUBLIC);
        ph.read = php_pqconn_object_read_port;
-       zend_hash_add(&php_pqconn_object_prophandlers, "port", sizeof("port"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "port", sizeof("port")-1, (void *) &ph, sizeof(ph));
 
 #if HAVE_PQCONNINFO
-       zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("params"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("params"), ZEND_ACC_PUBLIC);
        ph.read = php_pqconn_object_read_params;
-       zend_hash_add(&php_pqconn_object_prophandlers, "params", sizeof("params"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "params", sizeof("params")-1, (void *) &ph, sizeof(ph));
 #endif
 
-       zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("options"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("options"), ZEND_ACC_PUBLIC);
        ph.read = php_pqconn_object_read_options;
-       zend_hash_add(&php_pqconn_object_prophandlers, "options", sizeof("options"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "options", sizeof("options")-1, (void *) &ph, sizeof(ph));
 
-       zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("eventHandlers"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("eventHandlers"), ZEND_ACC_PUBLIC);
        ph.read = php_pqconn_object_read_event_handlers;
-       zend_hash_add(&php_pqconn_object_prophandlers, "eventHandlers", sizeof("eventHandlers"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "eventHandlers", sizeof("eventHandlers")-1, (void *) &ph, sizeof(ph));
 
-       zend_declare_property_long(php_pqconn_class_entry, ZEND_STRL("defaultFetchType"), 0, ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_long(php_pqconn_class_entry, ZEND_STRL("defaultFetchType"), 0, ZEND_ACC_PUBLIC);
        ph.read = php_pqconn_object_read_def_fetch_type;
        ph.write = php_pqconn_object_write_def_fetch_type;
-       zend_hash_add(&php_pqconn_object_prophandlers, "defaultFetchType", sizeof("defaultFetchType"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "defaultFetchType", sizeof("defaultFetchType")-1, (void *) &ph, sizeof(ph));
        ph.write = NULL;
 
-       zend_declare_property_long(php_pqconn_class_entry, ZEND_STRL("defaultTransactionIsolation"), 0, ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_long(php_pqconn_class_entry, ZEND_STRL("defaultTransactionIsolation"), 0, ZEND_ACC_PUBLIC);
        ph.read = php_pqconn_object_read_def_txn_isolation;
        ph.write = php_pqconn_object_write_def_txn_isolation;
-       zend_hash_add(&php_pqconn_object_prophandlers, "defaultTransactionIsolation", sizeof("defaultTransactionIsolation"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "defaultTransactionIsolation", sizeof("defaultTransactionIsolation")-1, (void *) &ph, sizeof(ph));
        ph.write = NULL;
 
-       zend_declare_property_bool(php_pqconn_class_entry, ZEND_STRL("defaultTransactionReadonly"), 0, ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_bool(php_pqconn_class_entry, ZEND_STRL("defaultTransactionReadonly"), 0, ZEND_ACC_PUBLIC);
        ph.read = php_pqconn_object_read_def_txn_readonly;
        ph.write = php_pqconn_object_write_def_txn_readonly;
-       zend_hash_add(&php_pqconn_object_prophandlers, "defaultTransactionReadonly", sizeof("defaultTransactionReadonly"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "defaultTransactionReadonly", sizeof("defaultTransactionReadonly")-1, (void *) &ph, sizeof(ph));
        ph.write = NULL;
 
        zend_declare_property_bool(php_pqconn_class_entry, ZEND_STRL("defaultTransactionDeferrable"), 0, ZEND_ACC_PUBLIC TSRMLS_CC);
        ph.read = php_pqconn_object_read_def_txn_deferrable;
        ph.write = php_pqconn_object_write_def_txn_deferrable;
-       zend_hash_add(&php_pqconn_object_prophandlers, "defaultTransactionDeferrable", sizeof("defaultTransactionDeferrable"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "defaultTransactionDeferrable", sizeof("defaultTransactionDeferrable")-1, (void *) &ph, sizeof(ph));
        ph.write = NULL;
 
-       zend_declare_property_long(php_pqconn_class_entry, ZEND_STRL("defaultAutoConvert"), PHP_PQRES_CONV_ALL, ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_long(php_pqconn_class_entry, ZEND_STRL("defaultAutoConvert"), PHP_PQRES_CONV_ALL, ZEND_ACC_PUBLIC);
        ph.read = php_pqconn_object_read_def_auto_conv;
        ph.write = php_pqconn_object_write_def_auto_conv;
-       zend_hash_add(&php_pqconn_object_prophandlers, "defaultAutoConvert", sizeof("defaultAutoConvert"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "defaultAutoConvert", sizeof("defaultAutoConvert")-1, (void *) &ph, sizeof(ph));
        ph.write = NULL;
 
-       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("OK"), CONNECTION_OK TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("BAD"), CONNECTION_BAD TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("STARTED"), CONNECTION_STARTED TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("MADE"), CONNECTION_MADE TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("AWAITING_RESPONSE"), CONNECTION_AWAITING_RESPONSE TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("AUTH_OK"), CONNECTION_AUTH_OK TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("SSL_STARTUP"), CONNECTION_SSL_STARTUP TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("SETENV"), CONNECTION_SETENV TSRMLS_CC);
-
-       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("TRANS_IDLE"), PQTRANS_IDLE TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("TRANS_ACTIVE"), PQTRANS_ACTIVE TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("TRANS_INTRANS"), PQTRANS_INTRANS TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("TRANS_INERROR"), PQTRANS_INERROR TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("TRANS_UNKNOWN"), PQTRANS_UNKNOWN TSRMLS_CC);
-
-       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("POLLING_FAILED"), PGRES_POLLING_FAILED TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("POLLING_READING"), PGRES_POLLING_READING TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("POLLING_WRITING"), PGRES_POLLING_WRITING TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("POLLING_OK"), PGRES_POLLING_OK TSRMLS_CC);
-
-       zend_declare_class_constant_stringl(php_pqconn_class_entry, ZEND_STRL("EVENT_NOTICE"), ZEND_STRL("notice") TSRMLS_CC);
-       zend_declare_class_constant_stringl(php_pqconn_class_entry, ZEND_STRL("EVENT_RESULT"), ZEND_STRL("result") TSRMLS_CC);
-       zend_declare_class_constant_stringl(php_pqconn_class_entry, ZEND_STRL("EVENT_RESET"), ZEND_STRL("reset") TSRMLS_CC);
-
-       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("ASYNC"), 0x1 TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("PERSISTENT"), 0x2 TSRMLS_CC);
+       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("OK"), CONNECTION_OK);
+       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("BAD"), CONNECTION_BAD);
+       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("STARTED"), CONNECTION_STARTED);
+       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("MADE"), CONNECTION_MADE);
+       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("AWAITING_RESPONSE"), CONNECTION_AWAITING_RESPONSE);
+       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("AUTH_OK"), CONNECTION_AUTH_OK);
+       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("SSL_STARTUP"), CONNECTION_SSL_STARTUP);
+       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("SETENV"), CONNECTION_SETENV);
 
-       return SUCCESS;
+       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("TRANS_IDLE"), PQTRANS_IDLE);
+       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("TRANS_ACTIVE"), PQTRANS_ACTIVE);
+       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("TRANS_INTRANS"), PQTRANS_INTRANS);
+       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("TRANS_INERROR"), PQTRANS_INERROR);
+       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("TRANS_UNKNOWN"), PQTRANS_UNKNOWN);
+
+       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("POLLING_FAILED"), PGRES_POLLING_FAILED);
+       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("POLLING_READING"), PGRES_POLLING_READING);
+       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("POLLING_WRITING"), PGRES_POLLING_WRITING);
+       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("POLLING_OK"), PGRES_POLLING_OK);
+
+       zend_declare_class_constant_stringl(php_pqconn_class_entry, ZEND_STRL("EVENT_NOTICE"), ZEND_STRL("notice"));
+       zend_declare_class_constant_stringl(php_pqconn_class_entry, ZEND_STRL("EVENT_RESULT"), ZEND_STRL("result"));
+       zend_declare_class_constant_stringl(php_pqconn_class_entry, ZEND_STRL("EVENT_RESET"), ZEND_STRL("reset"));
+
+       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("ASYNC"), 0x1);
+       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("PERSISTENT"), 0x2);
+
+       PHP_PQ_G->connection.name = zend_string_init(ZEND_STRL("pq\\Connection"), 1);
+
+       return php_persistent_handle_provide(PHP_PQ_G->connection.name, php_pqconn_get_resource_factory_ops(), NULL, NULL);
 }
 
 /*
index 03ad9c88d5265133a66ed96f36b54e3d53e35b60..0514e0a6cda6447ce0e9e46964f746adf318c12a 100644 (file)
@@ -38,28 +38,27 @@ typedef struct php_pqconn {
 } php_pqconn_t;
 
 typedef struct php_pqconn_object {
-       zend_object zo;
-       zend_object_value zv;
-       HashTable *prophandler;
        php_pqconn_t *intern;
+       HashTable *prophandler;
+       zend_object zo;
 } php_pqconn_object_t;
 
 typedef struct php_pqconn_resource_factory_data {
        char *dsn;
-       long flags;
+       ulong flags;
 } php_pqconn_resource_factory_data_t;
 
 extern php_resource_factory_ops_t *php_pqconn_get_resource_factory_ops(void);
 
 extern zend_class_entry *php_pqconn_class_entry;
-extern zend_object_value php_pqconn_create_object_ex(zend_class_entry *ce, php_pqconn_t *intern, php_pqconn_object_t **ptr TSRMLS_DC);
-extern void php_pqconn_notify_listeners(php_pqconn_object_t *obj TSRMLS_DC);
-extern ZEND_RESULT_CODE php_pqconn_prepare(zval *object, php_pqconn_object_t *obj, const char *name, const char *query, php_pq_params_t *params TSRMLS_DC);
-extern ZEND_RESULT_CODE php_pqconn_prepare_async(zval *object, php_pqconn_object_t *obj, const char *name, const char *query, php_pq_params_t *params TSRMLS_DC);
-extern ZEND_RESULT_CODE php_pqconn_start_transaction(zval *zconn, php_pqconn_object_t *conn_obj, long isolation, zend_bool readonly, zend_bool deferrable TSRMLS_DC);
-extern ZEND_RESULT_CODE php_pqconn_start_transaction_async(zval *zconn, php_pqconn_object_t *conn_obj, long isolation, zend_bool readonly, zend_bool deferrable TSRMLS_DC);
-extern ZEND_RESULT_CODE php_pqconn_declare(zval *object, php_pqconn_object_t *obj, const char *decl TSRMLS_DC);
-extern ZEND_RESULT_CODE php_pqconn_declare_async(zval *object, php_pqconn_object_t *obj, const char *decl TSRMLS_DC);
+extern php_pqconn_object_t *php_pqconn_create_object_ex(zend_class_entry *ce, php_pqconn_t *intern);
+extern void php_pqconn_notify_listeners(php_pqconn_object_t *obj);
+extern ZEND_RESULT_CODE php_pqconn_prepare(zval *object, php_pqconn_object_t *obj, const char *name, const char *query, php_pq_params_t *params);
+extern ZEND_RESULT_CODE php_pqconn_prepare_async(zval *object, php_pqconn_object_t *obj, const char *name, const char *query, php_pq_params_t *params);
+extern ZEND_RESULT_CODE php_pqconn_start_transaction(zval *zconn, php_pqconn_object_t *conn_obj, long isolation, zend_bool readonly, zend_bool deferrable);
+extern ZEND_RESULT_CODE php_pqconn_start_transaction_async(zval *zconn, php_pqconn_object_t *conn_obj, long isolation, zend_bool readonly, zend_bool deferrable);
+extern ZEND_RESULT_CODE php_pqconn_declare(zval *object, php_pqconn_object_t *obj, const char *decl);
+extern ZEND_RESULT_CODE php_pqconn_declare_async(zval *object, php_pqconn_object_t *obj, const char *decl);
 
 extern PHP_MINIT_FUNCTION(pqconn);
 extern PHP_MSHUTDOWN_FUNCTION(pqconn);
index f509c573867bdf17f742bca499cb045f97897abb..07fb173295dc44fdb5a0323dfe98b477e5bf35a1 100644 (file)
 #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);
+       zval_ptr_dtor(&rv);
 
        return ZEND_HASH_APPLY_KEEP;
 }
@@ -45,16 +44,14 @@ static void php_pqconn_event_connreset(PGEventConnReset *event)
 
        if (data) {
                HashTable *evhs;
-               TSRMLS_DF(data);
 
-               if (SUCCESS == zend_hash_find(&data->obj->intern->eventhandlers, ZEND_STRS("reset"), (void *) &evhs)) {
-                       zval *args, *connection = NULL;
+               if ((evhs = zend_hash_str_find_ptr(&data->obj->intern->eventhandlers, ZEND_STRS("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(evhs, apply_event, &args);
                        zval_ptr_dtor(&args);
                }
        }
@@ -67,31 +64,29 @@ static void php_pqconn_event_resultcreate(PGEventResultCreate *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_init_instance_data(event->result, data->obj, &obj);
 
                /* 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 ((evhs = zend_hash_str_find_ptr(&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(evhs, apply_event, &args);
                        zval_ptr_dtor(&args);
                }
 
                /* async callback */
                if (data->obj->intern->onevent.fci.size > 0) {
-                       zval *res = NULL;
+                       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);
                }
 
@@ -126,12 +121,11 @@ 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);
 
        return data;
 }
@@ -142,17 +136,15 @@ void php_pqconn_notice_recv(void *p, const PGresult *res)
 
        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;
+               if ((evhs = zend_hash_str_find_ptr(&data->obj->intern->eventhandlers, ZEND_STRL("notice")))) {
+                       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);
-                       add_next_index_string(args, PHP_PQresultErrorMessage(res), 1);
-                       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);
+                       add_next_index_string(&args, PHP_PQresultErrorMessage(res));
+                       zend_hash_apply_with_argument(evhs, apply_event, &args);
                        zval_ptr_dtor(&args);
                }
        }
index df4afca760bd9ca3ef8e8f89989fe0d60cd21ed4..f8aa4abfc91d2b60f438c050426960e796f69219 100644 (file)
 
 typedef struct php_pqconn_event_data {
        php_pqconn_object_t *obj;
-#ifdef ZTS
-       void ***ts;
-#endif
 } php_pqconn_event_data_t;
 
-extern php_pqconn_event_data_t *php_pqconn_event_data_init(php_pqconn_object_t *obj TSRMLS_DC);
+extern php_pqconn_event_data_t *php_pqconn_event_data_init(php_pqconn_object_t *obj);
 extern void php_pqconn_notice_recv(void *p, const PGresult *res);
 extern void php_pqconn_notice_ignore(void *p, const PGresult *res);
 extern int php_pqconn_event(PGEventId id, void *e, void *data);
index 32e20bac26c269ad09a43fc549b28c53987a0d80..2c4b626062d36b19ef33c7a34dadb3ef92bcb864 100644 (file)
@@ -15,7 +15,7 @@
 #endif
 
 #include <php.h>
-#include <ext/standard/php_smart_str.h>
+#include <Zend/zend_smart_str.h>
 
 #include <libpq-events.h>
 
@@ -31,77 +31,72 @@ zend_class_entry *php_pqcopy_class_entry;
 static zend_object_handlers php_pqcopy_object_handlers;
 static HashTable php_pqcopy_object_prophandlers;
 
-static void php_pqcopy_object_free(void *o TSRMLS_DC)
+static void php_pqcopy_object_free(zend_object *o)
 {
-       php_pqcopy_object_t *obj = 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);
 #endif
        if (obj->intern) {
                efree(obj->intern->expression);
                efree(obj->intern->options);
-               php_pq_object_delref(obj->intern->conn TSRMLS_CC);
+               php_pq_object_delref(obj->intern->conn);
                efree(obj->intern);
                obj->intern = NULL;
        }
-       zend_object_std_dtor((zend_object *) o TSRMLS_CC);
+       zend_object_std_dtor(o);
        efree(obj);
 }
 
-zend_object_value php_pqcopy_create_object_ex(zend_class_entry *ce, php_pqcopy_t *intern, php_pqcopy_object_t **ptr TSRMLS_DC)
+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_std_init((zend_object *) o, ce TSRMLS_CC);
-       object_properties_init((zend_object *) o, ce);
+       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 (ptr) {
-               *ptr = o;
-       }
-
        if (intern) {
                o->intern = intern;
        }
 
-       o->zv.handle = zend_objects_store_put((zend_object *) o, NULL, php_pqcopy_object_free, NULL TSRMLS_CC);
-       o->zv.handlers = &php_pqcopy_object_handlers;
+       o->zo.handlers = &php_pqcopy_object_handlers;
 
-       return o->zv;
+       return o;
 }
 
-static zend_object_value php_pqcopy_create_object(zend_class_entry *class_type TSRMLS_DC)
+static zend_object *php_pqcopy_create_object(zend_class_entry *class_type)
 {
-       return php_pqcopy_create_object_ex(class_type, NULL, NULL TSRMLS_CC);
+       return &php_pqcopy_create_object_ex(class_type, NULL)->zo;
 }
 
-static void php_pqcopy_object_read_connection(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqcopy_object_read_connection(zval *object, void *o, zval *return_value)
 {
        php_pqcopy_object_t *obj = o;
 
-       php_pq_object_to_zval(obj->intern->conn, &return_value TSRMLS_CC);
+       php_pq_object_to_zval(obj->intern->conn, return_value);
 }
 
-static void php_pqcopy_object_read_direction(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqcopy_object_read_direction(zval *object, void *o, zval *return_value)
 {
        php_pqcopy_object_t *obj = o;
 
        RETVAL_LONG(obj->intern->direction);
 }
 
-static void php_pqcopy_object_read_expression(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqcopy_object_read_expression(zval *object, void *o, zval *return_value)
 {
        php_pqcopy_object_t *obj = o;
 
-       RETURN_STRING(obj->intern->expression, 1);
+       RETURN_STRING(obj->intern->expression);
 }
 
-static void php_pqcopy_object_read_options(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqcopy_object_read_options(zval *object, void *o, zval *return_value)
 {
        php_pqcopy_object_t *obj = o;
 
-       RETURN_STRING(obj->intern->options, 1);
+       RETURN_STRING(obj->intern->options);
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_pqcopy_construct, 0, 0, 3)
@@ -114,21 +109,21 @@ static PHP_METHOD(pqcopy, __construct) {
        zend_error_handling zeh;
        zval *zconn;
        char *expr_str, *opt_str = "";
-       int expr_len, opt_len = 0;
-       long direction;
+       size_t expr_len, opt_len = 0;
+       zend_long direction;
        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, "Osl|s", &zconn, php_pqconn_class_entry, &expr_str, &expr_len, &direction, &opt_str, &opt_len);
-       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(), "Osl|s", &zconn, php_pqconn_class_entry, &expr_str, &expr_len, &direction, &opt_str, &opt_len);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqconn_object_t *conn_obj = zend_object_store_get_object(zconn TSRMLS_CC);
+               php_pqconn_object_t *conn_obj = PHP_PQ_OBJ(zconn, NULL);
 
                if (!conn_obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
-                       php_pqcopy_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+                       php_pqcopy_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
                        smart_str cmd = {0};
                        PGresult *res;
 
@@ -143,32 +138,32 @@ static PHP_METHOD(pqcopy, __construct) {
                                smart_str_appends(&cmd, " TO STDOUT ");
                                break;
                        default:
-                               throw_exce(EX_RUNTIME TSRMLS_CC, "Invalid COPY direction, expected one of FROM_STDIN (%d) TO_STDOUT (%d), got %ld", PHP_PQCOPY_FROM_STDIN, PHP_PQCOPY_TO_STDOUT, direction);
+                               throw_exce(EX_RUNTIME, "Invalid COPY direction, expected one of FROM_STDIN (%d) TO_STDOUT (%d), got %ld", PHP_PQCOPY_FROM_STDIN, PHP_PQCOPY_TO_STDOUT, direction);
                                smart_str_free(&cmd);
                                return;
                        }
                        smart_str_appendl(&cmd, opt_str, opt_len);
                        smart_str_0(&cmd);
 
-                       res = PQexec(conn_obj->intern->conn, cmd.c);
+                       res = PQexec(conn_obj->intern->conn, smart_str_v(&cmd));
 
                        if (!res) {
-                               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to start %s (%s)", cmd.c, PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+                               throw_exce(EX_RUNTIME, "Failed to start %s (%s)", smart_str_v(&cmd), PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                        } else {
-                               if (SUCCESS == php_pqres_success(res TSRMLS_CC)) {
+                               if (SUCCESS == php_pqres_success(res)) {
                                        obj->intern = ecalloc(1, sizeof(*obj->intern));
                                        obj->intern->direction = direction;
                                        obj->intern->expression = estrdup(expr_str);
                                        obj->intern->options = estrdup(opt_str);
                                        obj->intern->conn = conn_obj;
-                                       php_pq_object_addref(conn_obj TSRMLS_CC);
+                                       php_pq_object_addref(conn_obj);
                                }
 
                                PHP_PQclear(res);
                        }
 
                        smart_str_free(&cmd);
-                       php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
+                       php_pqconn_notify_listeners(obj->intern->conn);
                }
        }
 }
@@ -179,25 +174,25 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(pqcopy, put) {
        zend_error_handling zeh;
        char *data_str;
-       int data_len;
+       size_t data_len;
        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, "s", &data_str, &data_len);
-       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(), "s", &data_str, &data_len);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqcopy_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqcopy_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\COPY not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\COPY not initialized");
                } else if (obj->intern->direction != PHP_PQCOPY_FROM_STDIN) {
-                       throw_exce(EX_BAD_METHODCALL TSRMLS_CC, "pq\\COPY was not initialized with FROM_STDIN");
+                       throw_exce(EX_BAD_METHODCALL, "pq\\COPY was not initialized with FROM_STDIN");
                } else {
                        if (1 != PQputCopyData(obj->intern->conn->intern->conn, data_str, data_len)) {
-                               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to put COPY data (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+                               throw_exce(EX_RUNTIME, "Failed to put COPY data (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                        }
-                       php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
+                       php_pqconn_notify_listeners(obj->intern->conn);
                }
        }
 }
@@ -208,35 +203,35 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(pqcopy, end) {
        zend_error_handling zeh;
        char *error_str = NULL;
-       int error_len = 0;
+       size_t error_len = 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, "|s!", &error_str, &error_len);
-       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(), "|s!", &error_str, &error_len);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqcopy_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqcopy_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\COPY not intitialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\COPY not intitialized");
                } else if (obj->intern->direction != PHP_PQCOPY_FROM_STDIN) {
-                       throw_exce(EX_BAD_METHODCALL TSRMLS_CC, "pq\\COPY was not intitialized with FROM_STDIN");
+                       throw_exce(EX_BAD_METHODCALL, "pq\\COPY was not intitialized with FROM_STDIN");
                } else {
                        if (1 != PQputCopyEnd(obj->intern->conn->intern->conn, error_str)) {
-                               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to end COPY (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+                               throw_exce(EX_RUNTIME, "Failed to end COPY (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                        } else {
                                PGresult *res = PQgetResult(obj->intern->conn->intern->conn);
 
                                if (!res) {
-                                       throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to fetch COPY result (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+                                       throw_exce(EX_RUNTIME, "Failed to fetch COPY result (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                                } else {
-                                       php_pqres_success(res TSRMLS_CC);
+                                       php_pqres_success(res);
                                        PHP_PQclear(res);
                                }
                        }
 
-                       php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
+                       php_pqconn_notify_listeners(obj->intern->conn);
                }
        }
 }
@@ -249,17 +244,17 @@ static PHP_METHOD(pqcopy, get) {
        zval *zdata;
        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(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zdata);
-       zend_restore_error_handling(&zeh TSRMLS_CC);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqcopy_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqcopy_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\COPY not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\COPY not initialized");
                } else if (obj->intern->direction != PHP_PQCOPY_TO_STDOUT) {
-                       throw_exce(EX_RUNTIME TSRMLS_CC, "pq\\COPY was not intialized with TO_STDOUT");
+                       throw_exce(EX_RUNTIME, "pq\\COPY was not intialized with TO_STDOUT");
                } else {
                        PGresult *res;
                        char *buffer = NULL;
@@ -267,25 +262,26 @@ static PHP_METHOD(pqcopy, get) {
 
                        switch (bytes) {
                        case -2:
-                               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to fetch COPY data (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+                               throw_exce(EX_RUNTIME, "Failed to fetch COPY data (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                                break;
 
                        case -1:
                                res = PQgetResult(obj->intern->conn->intern->conn);
 
                                if (!res) {
-                                       throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to fetch COPY result (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+                                       throw_exce(EX_RUNTIME, "Failed to fetch COPY result (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                                } else {
-                                       php_pqres_success(res TSRMLS_CC);
+                                       php_pqres_success(res);
                                        PHP_PQclear(res);
                                        RETVAL_FALSE;
                                }
                                break;
 
                        default:
+                               ZVAL_DEREF(zdata);
                                zval_dtor(zdata);
                                if (buffer) {
-                                       ZVAL_STRINGL(zdata, buffer, bytes, 1);
+                                       ZVAL_STRINGL(zdata, buffer, bytes);
                                } else {
                                        ZVAL_EMPTY_STRING(zdata);
                                }
@@ -320,10 +316,12 @@ PHP_MINIT_FUNCTION(pqcopy)
        php_pq_object_prophandler_t ph = {0};
 
        INIT_NS_CLASS_ENTRY(ce, "pq", "COPY", php_pqcopy_methods);
-       php_pqcopy_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
+       php_pqcopy_class_entry = zend_register_internal_class_ex(&ce, NULL);
        php_pqcopy_class_entry->create_object = php_pqcopy_create_object;
 
        memcpy(&php_pqcopy_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+       php_pqcopy_object_handlers.offset = XtOffsetOf(php_pqcopy_object_t, zo);
+       php_pqcopy_object_handlers.free_obj = php_pqcopy_object_free;
        php_pqcopy_object_handlers.read_property = php_pq_object_read_prop;
        php_pqcopy_object_handlers.write_property = php_pq_object_write_prop;
        php_pqcopy_object_handlers.clone_obj = NULL;
@@ -334,24 +332,24 @@ PHP_MINIT_FUNCTION(pqcopy)
 
        zend_hash_init(&php_pqcopy_object_prophandlers, 4, NULL, NULL, 1);
 
-       zend_declare_property_null(php_pqcopy_class_entry, ZEND_STRL("connection"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_null(php_pqcopy_class_entry, ZEND_STRL("connection"), ZEND_ACC_PUBLIC);
        ph.read = php_pqcopy_object_read_connection;
-       zend_hash_add(&php_pqcopy_object_prophandlers, "connection", sizeof("connection"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqcopy_object_prophandlers, "connection", sizeof("connection")-1, (void *) &ph, sizeof(ph));
 
-       zend_declare_property_null(php_pqcopy_class_entry, ZEND_STRL("expression"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_null(php_pqcopy_class_entry, ZEND_STRL("expression"), ZEND_ACC_PUBLIC);
        ph.read = php_pqcopy_object_read_expression;
-       zend_hash_add(&php_pqcopy_object_prophandlers, "expression", sizeof("expression"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqcopy_object_prophandlers, "expression", sizeof("expression")-1, (void *) &ph, sizeof(ph));
 
-       zend_declare_property_null(php_pqcopy_class_entry, ZEND_STRL("direction"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_null(php_pqcopy_class_entry, ZEND_STRL("direction"), ZEND_ACC_PUBLIC);
        ph.read = php_pqcopy_object_read_direction;
-       zend_hash_add(&php_pqcopy_object_prophandlers, "direction", sizeof("direction"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqcopy_object_prophandlers, "direction", sizeof("direction")-1, (void *) &ph, sizeof(ph));
 
-       zend_declare_property_null(php_pqcopy_class_entry, ZEND_STRL("options"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_null(php_pqcopy_class_entry, ZEND_STRL("options"), ZEND_ACC_PUBLIC);
        ph.read = php_pqcopy_object_read_options;
-       zend_hash_add(&php_pqcopy_object_prophandlers, "options", sizeof("options"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqcopy_object_prophandlers, "options", sizeof("options")-1, (void *) &ph, sizeof(ph));
 
-       zend_declare_class_constant_long(php_pqcopy_class_entry, ZEND_STRL("FROM_STDIN"), PHP_PQCOPY_FROM_STDIN TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqcopy_class_entry, ZEND_STRL("TO_STDOUT"), PHP_PQCOPY_TO_STDOUT TSRMLS_CC);
+       zend_declare_class_constant_long(php_pqcopy_class_entry, ZEND_STRL("FROM_STDIN"), PHP_PQCOPY_FROM_STDIN);
+       zend_declare_class_constant_long(php_pqcopy_class_entry, ZEND_STRL("TO_STDOUT"), PHP_PQCOPY_TO_STDOUT);
 
        return SUCCESS;
 }
index 130a1f29ebd1bbc3eb04ae32cf799216d18feb50..dbac9a39906766b915406582721942fcaab40aa7 100644 (file)
@@ -35,14 +35,13 @@ typedef struct php_pqcopy {
 } php_pqcopy_t;
 
 typedef struct php_pqcopy_object {
-       zend_object zo;
-       zend_object_value zv;
-       HashTable *prophandler;
        php_pqcopy_t *intern;
+       HashTable *prophandler;
+       zend_object zo;
 } php_pqcopy_object_t;
 
 extern zend_class_entry *php_pqcopy_class_entry;
-extern zend_object_value php_pqcopy_create_object_ex(zend_class_entry *ce, php_pqcopy_t *intern, php_pqcopy_object_t **ptr TSRMLS_DC);
+extern php_pqcopy_object_t *php_pqcopy_create_object_ex(zend_class_entry *ce, php_pqcopy_t *intern);
 
 extern PHP_MINIT_FUNCTION(pqcopy);
 extern PHP_MSHUTDOWN_FUNCTION(pqcopy);
index 58ffd866c65128bfedf3d433cfbded2f2fb296cf..be6443d4fe6715c607bfff64818b6dbc44199a58 100644 (file)
@@ -15,7 +15,7 @@
 #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"
@@ -29,7 +29,7 @@ zend_class_entry *php_pqcur_class_entry;
 static zend_object_handlers php_pqcur_object_handlers;
 static HashTable php_pqcur_object_prophandlers;
 
-static void cur_close(php_pqcur_object_t *obj, zend_bool async, zend_bool silent TSRMLS_DC)
+static void cur_close(php_pqcur_object_t *obj, zend_bool async, zend_bool silent)
 {
        if (obj->intern->open && obj->intern->conn->intern) {
                PGresult *res;
@@ -40,17 +40,17 @@ static void cur_close(php_pqcur_object_t *obj, zend_bool async, zend_bool silent
                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;
-                               php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
+                               php_pqconn_notify_listeners(obj->intern->conn);
                        } else if (!silent) {
-                               throw_exce(EX_IO TSRMLS_CC, "Failed to close cursor (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+                               throw_exce(EX_IO, "Failed to close cursor (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                        }
                } else {
-                       if ((res = PQexec(obj->intern->conn->intern->conn, cmd.c))) {
+                       if ((res = PQexec(obj->intern->conn->intern->conn, smart_str_v(&cmd)))) {
                                PHP_PQclear(res);
                        } else if (!silent) {
-                               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to close cursor (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+                               throw_exce(EX_RUNTIME, "Failed to close cursor (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                        }
                }
 
@@ -65,27 +65,27 @@ static void cur_open(INTERNAL_FUNCTION_PARAMETERS, zend_bool async)
        ZEND_RESULT_CODE rv;
        php_pqcur_object_t *obj;
 
-       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();
-       zend_restore_error_handling(&zeh TSRMLS_CC);
+       zend_restore_error_handling(&zeh);
 
        if (rv == FAILURE) {
                return;
        }
 
-       obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+       obj = PHP_PQ_OBJ(getThis(), NULL);
 
        if (!obj->intern) {
-               throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Cursor not initialized");
+               throw_exce(EX_UNINITIALIZED, "pq\\Cursor not initialized");
                return;
        } else if (obj->intern->open) {
                return;
        }
 
        if (async) {
-               rv = php_pqconn_declare_async(NULL, obj->intern->conn, obj->intern->decl TSRMLS_CC);
+               rv = php_pqconn_declare_async(NULL, obj->intern->conn, obj->intern->decl);
        } else {
-               rv = php_pqconn_declare(NULL, obj->intern->conn, obj->intern->decl TSRMLS_CC);
+               rv = php_pqconn_declare(NULL, obj->intern->conn, obj->intern->decl);
        }
 
        if (rv == SUCCESS) {
@@ -96,20 +96,20 @@ static void cur_open(INTERNAL_FUNCTION_PARAMETERS, zend_bool async)
 static void cur_fetch_or_move(INTERNAL_FUNCTION_PARAMETERS, const char *action, zend_bool async)
 {
        char *spec_str = "1";
-       int spec_len = 1;
+       size_t spec_len = 1;
        ZEND_RESULT_CODE rv;
        php_pq_callback_t resolver = {{0}};
        zend_error_handling zeh;
 
-       zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
-       rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, async ? "|sf" : "|s", &spec_str, &spec_len, &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(), async ? "|sf" : "|s", &spec_str, &spec_len, &resolver.fci, &resolver.fcc);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqcur_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqcur_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Cursor not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Cursor not initialized");
                } else {
                        smart_str cmd = {0};
 
@@ -120,102 +120,97 @@ static void cur_fetch_or_move(INTERNAL_FUNCTION_PARAMETERS, const char *action,
                        smart_str_0(&cmd);
 
                        if (async) {
-                               int rc = PQsendQuery(obj->intern->conn->intern->conn, cmd.c);
+                               int rc = PQsendQuery(obj->intern->conn->intern->conn, smart_str_v(&cmd));
 
                                if (!rc) {
-                                       throw_exce(EX_IO TSRMLS_CC, "Failed to %s cursor (%s)", *action == 'f' ? "fetch from" : "move in", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+                                       throw_exce(EX_IO, "Failed to %s cursor (%s)", *action == 'f' ? "fetch from" : "move in", PHP_PQerrorMessage(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 {
-                                       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;
                                }
                        } else {
-                               PGresult *res = PQexec(obj->intern->conn->intern->conn, cmd.c);
+                               PGresult *res = PQexec(obj->intern->conn->intern->conn, smart_str_v(&cmd));
 
                                if (!res) {
-                                       throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to %s cursor (%s)", *action == 'f' ? "fetch from" : "move in", 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);
+                                       throw_exce(EX_RUNTIME, "Failed to %s cursor (%s)", *action == 'f' ? "fetch from" : "move in", 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);
 
                                }
                        }
                        smart_str_free(&cmd);
-                       php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
+                       php_pqconn_notify_listeners(obj->intern->conn);
                }
        }
 }
 
-static void php_pqcur_object_free(void *o TSRMLS_DC)
+static void php_pqcur_object_free(zend_object *o)
 {
-       php_pqcur_object_t *obj = o;
+       php_pqcur_object_t *obj = PHP_PQ_OBJ(NULL, o);
 #if DBG_GC
        fprintf(stderr, "FREE cur(#%d) %p (conn: %p)\n", obj->zv.handle, obj, obj->intern->conn);
 #endif
        if (obj->intern) {
-               cur_close(obj, 0, 1 TSRMLS_CC);
-               php_pq_object_delref(obj->intern->conn TSRMLS_CC);
+               cur_close(obj, 0, 1);
+               php_pq_object_delref(obj->intern->conn);
                efree(obj->intern->decl);
                efree(obj->intern->name);
                efree(obj->intern);
                obj->intern = NULL;
        }
-       zend_object_std_dtor((zend_object *) o TSRMLS_CC);
+       zend_object_std_dtor(o);
        efree(obj);
 }
 
-zend_object_value php_pqcur_create_object_ex(zend_class_entry *ce, php_pqcur_t *intern, php_pqcur_object_t **ptr TSRMLS_DC)
+php_pqcur_object_t *php_pqcur_create_object_ex(zend_class_entry *ce, php_pqcur_t *intern)
 {
        php_pqcur_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 = 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_pqcur_object_prophandlers;
 
-       if (ptr) {
-               *ptr = o;
-       }
-
        if (intern) {
                o->intern = intern;
        }
 
-       o->zv.handle = zend_objects_store_put((zend_object *) o, NULL, php_pqcur_object_free, NULL TSRMLS_CC);
-       o->zv.handlers = &php_pqcur_object_handlers;
+       o->zo.handlers = &php_pqcur_object_handlers;
 
-       return o->zv;
+       return o;
 }
 
-static zend_object_value php_pqcur_create_object(zend_class_entry *class_type TSRMLS_DC)
+static zend_object *php_pqcur_create_object(zend_class_entry *class_type)
 {
-       return php_pqcur_create_object_ex(class_type, NULL, NULL TSRMLS_CC);
+       return &php_pqcur_create_object_ex(class_type, NULL)->zo;
 }
 
-static void php_pqcur_object_read_name(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqcur_object_read_name(zval *object, void *o, zval *return_value)
 {
        php_pqcur_object_t *obj = o;
 
-       RETVAL_STRING(obj->intern->name, 1);
+       RETVAL_STRING(obj->intern->name);
 }
 
-static void php_pqcur_object_read_connection(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqcur_object_read_connection(zval *object, void *o, zval *return_value)
 {
        php_pqcur_object_t *obj = o;
 
-       php_pq_object_to_zval(obj->intern->conn, &return_value TSRMLS_CC);
+       php_pq_object_to_zval(obj->intern->conn, return_value);
 }
 
-static void php_pqcur_object_read_query(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqcur_object_read_query(zval *object, void *o, zval *return_value)
 {
        php_pqcur_object_t *obj = o;
 
-       RETVAL_STRING(obj->intern->decl + obj->intern->query_offset, 1);
+       RETVAL_STRING(obj->intern->decl + obj->intern->query_offset);
 }
 
-static void php_pqcur_object_read_flags(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqcur_object_read_flags(zval *object, void *o, zval *return_value)
 {
        php_pqcur_object_t *obj = o;
 
@@ -254,11 +249,11 @@ char *php_pqcur_declare_str(const char *name_str, size_t name_len, unsigned flag
        return decl_str;
 }
 
-php_pqcur_t *php_pqcur_init(php_pqconn_object_t *conn, const char *name, char *decl, int query_offset, long flags TSRMLS_DC)
+php_pqcur_t *php_pqcur_init(php_pqconn_object_t *conn, const char *name, char *decl, int query_offset, long flags)
 {
        php_pqcur_t *cur = ecalloc(1, sizeof(*cur));
 
-       php_pq_object_addref(conn TSRMLS_CC);
+       php_pq_object_addref(conn);
        cur->conn = conn;
        cur->name = estrdup(name);
        cur->decl = decl;
@@ -279,38 +274,38 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(pqcur, __construct) {
        zend_error_handling zeh;
        char *name_str, *query_str;
-       int name_len, query_len;
-       long flags;
+       size_t name_len, query_len;
+       zend_long flags;
        zval *zconn;
        ZEND_RESULT_CODE rv;
        zend_bool async = 0;
 
-       zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
-       rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Osls|b", &zconn, php_pqconn_class_entry, &name_str, &name_len, &flags, &query_str, &query_len, &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(), "Osls|b", &zconn, php_pqconn_class_entry, &name_str, &name_len, &flags, &query_str, &query_len, &async);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqcur_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_pqcur_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
+               php_pqconn_object_t *conn_obj = PHP_PQ_OBJ(zconn, NULL);
 
                if (obj->intern) {
-                       throw_exce(EX_BAD_METHODCALL TSRMLS_CC, "pq\\Cursor already initialized");
+                       throw_exce(EX_BAD_METHODCALL, "pq\\Cursor already initialized");
                } if (!conn_obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
                        int query_offset;
                        char *decl = php_pqcur_declare_str(name_str, name_len, flags, query_str, query_len, &query_offset);
 
                        if (async) {
-                               rv = php_pqconn_declare_async(zconn, conn_obj, decl TSRMLS_CC);
+                               rv = php_pqconn_declare_async(zconn, conn_obj, decl);
                        } else {
-                               rv = php_pqconn_declare(zconn, conn_obj, decl TSRMLS_CC);
+                               rv = php_pqconn_declare(zconn, conn_obj, decl);
                        }
 
                        if (SUCCESS != rv) {
                                efree(decl);
                        } else {
-                               obj->intern = php_pqcur_init(conn_obj, name_str, decl, query_offset, flags TSRMLS_CC);
+                               obj->intern = php_pqcur_init(conn_obj, name_str, decl, query_offset, flags);
                        }
                }
        }
@@ -337,17 +332,17 @@ static PHP_METHOD(pqcur, close)
        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();
-       zend_restore_error_handling(&zeh TSRMLS_CC);
+       zend_restore_error_handling(&zeh);
 
        if (rv == SUCCESS) {
-               php_pqcur_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqcur_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Cursor not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Cursor not initialized");
                } else {
-                       cur_close(obj, 0, 0 TSRMLS_CC);
+                       cur_close(obj, 0, 0);
                }
        }
 }
@@ -359,17 +354,17 @@ static PHP_METHOD(pqcur, closeAsync)
        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();
-       zend_restore_error_handling(&zeh TSRMLS_CC);
+       zend_restore_error_handling(&zeh);
 
        if (rv == SUCCESS) {
-               php_pqcur_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqcur_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Cursor not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Cursor not initialized");
                } else {
-                       cur_close(obj, 1, 0 TSRMLS_CC);
+                       cur_close(obj, 1, 0);
                }
        }
 }
@@ -411,7 +406,7 @@ static PHP_METHOD(pqcur, moveAsync)
 static zend_function_entry php_pqcur_methods[] = {
        PHP_ME(pqcur, __construct, ai_pqcur___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
        PHP_ME(pqcur, open, ai_pqcur_open, ZEND_ACC_PUBLIC)
-       PHP_ME(pqcur, openAsync, ai_pqcur_open, ZEND_ACC_PUBLIC)
+       PHP_ME(pqcur, openAsync, ai_pqcur_openAsync, ZEND_ACC_PUBLIC)
        PHP_ME(pqcur, close, ai_pqcur_close, ZEND_ACC_PUBLIC)
        PHP_ME(pqcur, closeAsync, ai_pqcur_closeAsync, ZEND_ACC_PUBLIC)
        PHP_ME(pqcur, fetch, ai_pqcur_fetch, ZEND_ACC_PUBLIC)
@@ -433,10 +428,12 @@ PHP_MINIT_FUNCTION(pqcur)
        php_pq_object_prophandler_t ph = {0};
 
        INIT_NS_CLASS_ENTRY(ce, "pq", "Cursor", php_pqcur_methods);
-       php_pqcur_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
+       php_pqcur_class_entry = zend_register_internal_class_ex(&ce, NULL);
        php_pqcur_class_entry->create_object = php_pqcur_create_object;
 
        memcpy(&php_pqcur_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+       php_pqcur_object_handlers.offset = XtOffsetOf(php_pqcur_object_t, zo);
+       php_pqcur_object_handlers.free_obj = php_pqcur_object_free;
        php_pqcur_object_handlers.read_property = php_pq_object_read_prop;
        php_pqcur_object_handlers.write_property = php_pq_object_write_prop;
        php_pqcur_object_handlers.clone_obj = NULL;
@@ -447,27 +444,27 @@ PHP_MINIT_FUNCTION(pqcur)
 
        zend_hash_init(&php_pqcur_object_prophandlers, 4, NULL, NULL, 1);
 
-       zend_declare_class_constant_long(php_pqcur_class_entry, ZEND_STRL("BINARY"), PHP_PQ_DECLARE_BINARY TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqcur_class_entry, ZEND_STRL("INSENSITIVE"), PHP_PQ_DECLARE_INSENSITIVE TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqcur_class_entry, ZEND_STRL("WITH_HOLD"), PHP_PQ_DECLARE_WITH_HOLD TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqcur_class_entry, ZEND_STRL("SCROLL"), PHP_PQ_DECLARE_SCROLL TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqcur_class_entry, ZEND_STRL("NO_SCROLL"), PHP_PQ_DECLARE_NO_SCROLL TSRMLS_CC);
+       zend_declare_class_constant_long(php_pqcur_class_entry, ZEND_STRL("BINARY"), PHP_PQ_DECLARE_BINARY);
+       zend_declare_class_constant_long(php_pqcur_class_entry, ZEND_STRL("INSENSITIVE"), PHP_PQ_DECLARE_INSENSITIVE);
+       zend_declare_class_constant_long(php_pqcur_class_entry, ZEND_STRL("WITH_HOLD"), PHP_PQ_DECLARE_WITH_HOLD);
+       zend_declare_class_constant_long(php_pqcur_class_entry, ZEND_STRL("SCROLL"), PHP_PQ_DECLARE_SCROLL);
+       zend_declare_class_constant_long(php_pqcur_class_entry, ZEND_STRL("NO_SCROLL"), PHP_PQ_DECLARE_NO_SCROLL);
 
-       zend_declare_property_null(php_pqcur_class_entry, ZEND_STRL("name"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_null(php_pqcur_class_entry, ZEND_STRL("name"), ZEND_ACC_PUBLIC);
        ph.read = php_pqcur_object_read_name;
-       zend_hash_add(&php_pqcur_object_prophandlers, "name", sizeof("name"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqcur_object_prophandlers, "name", sizeof("name")-1, (void *) &ph, sizeof(ph));
 
-       zend_declare_property_null(php_pqcur_class_entry, ZEND_STRL("connection"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_null(php_pqcur_class_entry, ZEND_STRL("connection"), ZEND_ACC_PUBLIC);
        ph.read = php_pqcur_object_read_connection;
-       zend_hash_add(&php_pqcur_object_prophandlers, "connection", sizeof("connection"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqcur_object_prophandlers, "connection", sizeof("connection")-1, (void *) &ph, sizeof(ph));
 
-       zend_declare_property_null(php_pqcur_class_entry, ZEND_STRL("query"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_null(php_pqcur_class_entry, ZEND_STRL("query"), ZEND_ACC_PUBLIC);
        ph.read = php_pqcur_object_read_query;
-       zend_hash_add(&php_pqcur_object_prophandlers, "query", sizeof("query"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqcur_object_prophandlers, "query", sizeof("query")-1, (void *) &ph, sizeof(ph));
 
        zend_declare_property_null(php_pqcur_class_entry, ZEND_STRL("flags"), ZEND_ACC_PUBLIC TSRMLS_CC);
        ph.read = php_pqcur_object_read_flags;
-       zend_hash_add(&php_pqcur_object_prophandlers, "flags", sizeof("flags"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqcur_object_prophandlers, "flags", sizeof("flags")-1, (void *) &ph, sizeof(ph));
 
        return SUCCESS;
 }
index b12e0a137041d0b47c9a4b970714e47b4acd3c33..ea4353a47138b7b9933947d53a81de7b254f572a 100644 (file)
@@ -32,17 +32,16 @@ typedef struct php_pqcur {
 } php_pqcur_t;
 
 typedef struct php_pqcur_object {
-       zend_object zo;
-       zend_object_value zv;
-       HashTable *prophandler;
        php_pqcur_t *intern;
+       HashTable *prophandler;
+       zend_object zo;
 } php_pqcur_object_t;
 
 extern zend_class_entry *php_pqcur_class_entry;
-extern zend_object_value php_pqcur_create_object_ex(zend_class_entry *ce, php_pqcur_t *intern, php_pqcur_object_t **ptr TSRMLS_DC);
+extern php_pqcur_object_t *php_pqcur_create_object_ex(zend_class_entry *ce, php_pqcur_t *intern);
 
 extern char *php_pqcur_declare_str(const char *name_str, size_t name_len, unsigned flags, const char *query_str, size_t query_len, int *query_offset);
-extern php_pqcur_t *php_pqcur_init(php_pqconn_object_t *conn, const char *name, char *decl, int query_offset, long flags TSRMLS_DC);
+extern php_pqcur_t *php_pqcur_init(php_pqconn_object_t *conn, const char *name, char *decl, int query_offset, long flags);
 
 extern PHP_MINIT_FUNCTION(pqcur);
 extern PHP_MSHUTDOWN_FUNCTION(pqcur);
index d67a3ffe92b052cedbc56e14b0b0b755834b69d4..63aa9d3d3e116d4938ed1987fb2058c7bd84d1f7 100644 (file)
@@ -53,7 +53,7 @@ zend_class_entry *exce(php_pqexc_type_t type)
        }
 }
 
-zval *throw_exce(php_pqexc_type_t type TSRMLS_DC, const char *fmt, ...)
+zval *throw_exce(php_pqexc_type_t type, const char *fmt, ...)
 {
        char *msg;
        zval *zexc;
@@ -63,7 +63,7 @@ zval *throw_exce(php_pqexc_type_t type TSRMLS_DC, const char *fmt, ...)
        vspprintf(&msg, 0, fmt, argv);
        va_end(argv);
 
-       zexc = zend_throw_exception(exce(type), msg, type TSRMLS_CC);
+       zexc = zend_throw_exception(exce(type), msg, type);
        efree(msg);
 
        return zexc;
@@ -74,38 +74,38 @@ PHP_MINIT_FUNCTION(pqexc)
        zend_class_entry ce = {0};
 
        INIT_NS_CLASS_ENTRY(ce, "pq", "Exception", php_pqexc_methods);
-       php_pqexc_interface_class_entry = zend_register_internal_interface(&ce TSRMLS_CC);
-
-       zend_declare_class_constant_long(php_pqexc_interface_class_entry, ZEND_STRL("INVALID_ARGUMENT"), EX_INVALID_ARGUMENT TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqexc_interface_class_entry, ZEND_STRL("RUNTIME"), EX_RUNTIME TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqexc_interface_class_entry, ZEND_STRL("CONNECTION_FAILED"), EX_CONNECTION_FAILED TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqexc_interface_class_entry, ZEND_STRL("IO"), EX_IO TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqexc_interface_class_entry, ZEND_STRL("ESCAPE"), EX_ESCAPE TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqexc_interface_class_entry, ZEND_STRL("BAD_METHODCALL"), EX_BAD_METHODCALL TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqexc_interface_class_entry, ZEND_STRL("UNINITIALIZED"), EX_UNINITIALIZED TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqexc_interface_class_entry, ZEND_STRL("DOMAIN"), EX_DOMAIN TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqexc_interface_class_entry, ZEND_STRL("SQL"), EX_SQL TSRMLS_CC);
+       php_pqexc_interface_class_entry = zend_register_internal_interface(&ce);
+
+       zend_declare_class_constant_long(php_pqexc_interface_class_entry, ZEND_STRL("INVALID_ARGUMENT"), EX_INVALID_ARGUMENT);
+       zend_declare_class_constant_long(php_pqexc_interface_class_entry, ZEND_STRL("RUNTIME"), EX_RUNTIME);
+       zend_declare_class_constant_long(php_pqexc_interface_class_entry, ZEND_STRL("CONNECTION_FAILED"), EX_CONNECTION_FAILED);
+       zend_declare_class_constant_long(php_pqexc_interface_class_entry, ZEND_STRL("IO"), EX_IO);
+       zend_declare_class_constant_long(php_pqexc_interface_class_entry, ZEND_STRL("ESCAPE"), EX_ESCAPE);
+       zend_declare_class_constant_long(php_pqexc_interface_class_entry, ZEND_STRL("BAD_METHODCALL"), EX_BAD_METHODCALL);
+       zend_declare_class_constant_long(php_pqexc_interface_class_entry, ZEND_STRL("UNINITIALIZED"), EX_UNINITIALIZED);
+       zend_declare_class_constant_long(php_pqexc_interface_class_entry, ZEND_STRL("DOMAIN"), EX_DOMAIN);
+       zend_declare_class_constant_long(php_pqexc_interface_class_entry, ZEND_STRL("SQL"), EX_SQL);
 
        memset(&ce, 0, sizeof(ce));
        INIT_NS_CLASS_ENTRY(ce, "pq\\Exception", "InvalidArgumentException", php_pqexc_methods);
-       php_pqexc_invalid_argument_class_entry = zend_register_internal_class_ex(&ce, spl_ce_InvalidArgumentException, "InvalidArgumentException" TSRMLS_CC);
-       zend_class_implements(php_pqexc_invalid_argument_class_entry TSRMLS_CC, 1, php_pqexc_interface_class_entry);
+       php_pqexc_invalid_argument_class_entry = zend_register_internal_class_ex(&ce, spl_ce_InvalidArgumentException);
+       zend_class_implements(php_pqexc_invalid_argument_class_entry, 1, php_pqexc_interface_class_entry);
 
        memset(&ce, 0, sizeof(ce));
        INIT_NS_CLASS_ENTRY(ce, "pq\\Exception", "RuntimeException", php_pqexc_methods);
-       php_pqexc_runtime_class_entry = zend_register_internal_class_ex(&ce, spl_ce_RuntimeException, "RuntimeException" TSRMLS_CC);
-       zend_class_implements(php_pqexc_runtime_class_entry TSRMLS_CC, 1, php_pqexc_interface_class_entry);
+       php_pqexc_runtime_class_entry = zend_register_internal_class_ex(&ce, spl_ce_RuntimeException);
+       zend_class_implements(php_pqexc_runtime_class_entry, 1, php_pqexc_interface_class_entry);
 
        memset(&ce, 0, sizeof(ce));
        INIT_NS_CLASS_ENTRY(ce, "pq\\Exception", "BadMethodCallException", php_pqexc_methods);
-       php_pqexc_bad_methodcall_class_entry = zend_register_internal_class_ex(&ce, spl_ce_BadMethodCallException, "BadMethodCallException" TSRMLS_CC);
-       zend_class_implements(php_pqexc_bad_methodcall_class_entry TSRMLS_CC, 1, php_pqexc_interface_class_entry);
+       php_pqexc_bad_methodcall_class_entry = zend_register_internal_class_ex(&ce, spl_ce_BadMethodCallException);
+       zend_class_implements(php_pqexc_bad_methodcall_class_entry, 1, php_pqexc_interface_class_entry);
 
        memset(&ce, 0, sizeof(ce));
        INIT_NS_CLASS_ENTRY(ce, "pq\\Exception", "DomainException", php_pqexc_methods);
-       php_pqexc_domain_class_entry = zend_register_internal_class_ex(&ce, spl_ce_DomainException, "DomainException" TSRMLS_CC);
+       php_pqexc_domain_class_entry = zend_register_internal_class_ex(&ce, spl_ce_DomainException);
        zend_class_implements(php_pqexc_domain_class_entry TSRMLS_CC, 1, php_pqexc_interface_class_entry);
-       zend_declare_property_null(php_pqexc_domain_class_entry, ZEND_STRL("sqlstate"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_null(php_pqexc_domain_class_entry, ZEND_STRL("sqlstate"), ZEND_ACC_PUBLIC);
 
        return SUCCESS;
 }
index c5847daaf11f84ac7d4b8d1408d9fed96481c0dd..de1be0f6acb6325ee0c246b4adab10fe3af2403b 100644 (file)
@@ -27,7 +27,7 @@ typedef enum php_pqexc_type {
 } php_pqexc_type_t;
 
 extern zend_class_entry *exce(php_pqexc_type_t type);
-extern zval *throw_exce(php_pqexc_type_t type TSRMLS_DC, const char *fmt, ...);
+extern zval *throw_exce(php_pqexc_type_t type, const char *fmt, ...);
 
 extern PHP_MINIT_FUNCTION(pqexc);
 
index 1c6e7b71bd499f7e7cb96aa27e548873f9acc99a..51494720ab6b3df9d3dc021976d87b1ce71b0b38 100644 (file)
@@ -28,9 +28,9 @@ zend_class_entry *php_pqlob_class_entry;
 static zend_object_handlers php_pqlob_object_handlers;
 static HashTable php_pqlob_object_prophandlers;
 
-static void php_pqlob_object_free(void *o TSRMLS_DC)
+static void php_pqlob_object_free(zend_object *o)
 {
-       php_pqlob_object_t *obj = o;
+       php_pqlob_object_t *obj = PHP_PQ_OBJ(NULL, o);
 #if DBG_GC
        fprintf(stderr, "FREE lob(#%d) %p (txn(#%d): %p)\n", obj->zv.handle, obj, obj->intern->txn->zv.handle, obj->intern->txn);
 #endif
@@ -40,74 +40,68 @@ static void php_pqlob_object_free(void *o TSRMLS_DC)
                }
                /* invalidate the stream */
                if (obj->intern->stream) {
-                       zend_list_delete(obj->intern->stream);
-                       obj->intern->stream = 0;
+                       zend_list_delete(obj->intern->stream->res);
+                       obj->intern->stream = NULL;
                }
-               php_pq_object_delref(obj->intern->txn TSRMLS_CC);
+               php_pq_object_delref(obj->intern->txn);
                efree(obj->intern);
                obj->intern = NULL;
        }
-       zend_object_std_dtor((zend_object *) o TSRMLS_CC);
+       zend_object_std_dtor(o);
        efree(obj);
 }
 
-zend_object_value php_pqlob_create_object_ex(zend_class_entry *ce, php_pqlob_t *intern, php_pqlob_object_t **ptr TSRMLS_DC)
+php_pqlob_object_t *php_pqlob_create_object_ex(zend_class_entry *ce, php_pqlob_t *intern)
 {
        php_pqlob_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 = 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_pqlob_object_prophandlers;
 
-       if (ptr) {
-               *ptr = o;
-       }
-
        if (intern) {
                o->intern = intern;
        }
 
-       o->zv.handle = zend_objects_store_put((zend_object *) o, NULL, php_pqlob_object_free, NULL TSRMLS_CC);
-       o->zv.handlers = &php_pqlob_object_handlers;
+       o->zo.handlers = &php_pqlob_object_handlers;
 
-       return o->zv;
+       return o;
 }
 
-static zend_object_value php_pqlob_create_object(zend_class_entry *class_type TSRMLS_DC)
+static zend_object *php_pqlob_create_object(zend_class_entry *class_type)
 {
-       return php_pqlob_create_object_ex(class_type, NULL, NULL TSRMLS_CC);
+       return &php_pqlob_create_object_ex(class_type, NULL)->zo;
 }
 
-static void php_pqlob_object_read_transaction(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqlob_object_read_transaction(zval *object, void *o, zval *return_value)
 {
        php_pqlob_object_t *obj = o;
 
-       php_pq_object_to_zval(obj->intern->txn, &return_value TSRMLS_CC);
+       php_pq_object_to_zval(obj->intern->txn, return_value);
 }
 
-static void php_pqlob_object_read_oid(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqlob_object_read_oid(zval *object, void *o, zval *return_value)
 {
        php_pqlob_object_t *obj = o;
 
        RETVAL_LONG(obj->intern->loid);
 }
 
-static void php_pqlob_object_update_stream(zval *this_ptr, php_pqlob_object_t *obj, zval **zstream TSRMLS_DC);
+static void php_pqlob_object_update_stream(zval *this_ptr, php_pqlob_object_t *obj, zval *zstream);
 
-static void php_pqlob_object_read_stream(zval *object, void *o, zval *return_value TSRMLS_DC)
+static void php_pqlob_object_read_stream(zval *object, void *o, zval *return_value)
 {
        php_pqlob_object_t *obj = o;
+       zval zstream;
 
        if (!obj->intern->stream) {
-               zval *zstream;
-
-               php_pqlob_object_update_stream(object, obj, &zstream TSRMLS_CC);
-               RETVAL_ZVAL(zstream, 1, 1);
+               php_pqlob_object_update_stream(object, obj, &zstream);
        } else {
-               RETVAL_RESOURCE(obj->intern->stream);
-               zend_list_addref(obj->intern->stream);
+               php_stream_to_zval(obj->intern->stream, &zstream);
        }
+
+       RETVAL_ZVAL(&zstream, 1, 1);
 }
 
 static size_t php_pqlob_stream_write(php_stream *stream, const char *buffer, size_t length TSRMLS_DC)
@@ -201,30 +195,20 @@ static php_stream_ops php_pqlob_stream_ops = {
        NULL, /* set_option */
 };
 
-static void php_pqlob_object_update_stream(zval *this_ptr, php_pqlob_object_t *obj, zval **zstream_ptr TSRMLS_DC)
+static void php_pqlob_object_update_stream(zval *zpqlob, php_pqlob_object_t *obj, zval *zstream)
 {
-       zval *zstream, zmember;
-       php_stream *stream;
+       zval zmember;
 
-       INIT_PZVAL(&zmember);
-       ZVAL_STRINGL(&zmember, "stream", sizeof("stream")-1, 0);
+       ZVAL_STRINGL(&zmember, "stream", sizeof("stream")-1);
 
-       MAKE_STD_ZVAL(zstream);
        if (!obj) {
-               obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               obj = PHP_PQ_OBJ(zpqlob, NULL);
        }
-       stream = php_stream_alloc(&php_pqlob_stream_ops, obj, NULL, "r+b");
-       stream->flags |= PHP_STREAM_FLAG_NO_FCLOSE;
-       zend_list_addref(obj->intern->stream = stream->rsrc_id);
-       php_stream_to_zval(stream, zstream);
-
-       zend_get_std_object_handlers()->write_property(getThis(), &zmember, zstream, NULL TSRMLS_CC);
+       obj->intern->stream = php_stream_alloc(&php_pqlob_stream_ops, obj, NULL, "r+b");
+       obj->intern->stream->flags |= PHP_STREAM_FLAG_NO_FCLOSE;
+       php_stream_to_zval(obj->intern->stream, zstream);
 
-       if (zstream_ptr) {
-               *zstream_ptr = zstream;
-       } else {
-               zval_ptr_dtor(&zstream);
-       }
+       zend_get_std_object_handlers()->write_property(zpqlob, &zmember, zstream, NULL);
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_pqlob_construct, 0, 0, 1)
@@ -235,45 +219,45 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(pqlob, __construct) {
        zend_error_handling zeh;
        zval *ztxn;
-       long mode = INV_WRITE|INV_READ, loid = InvalidOid;
+       zend_long mode = INV_WRITE|INV_READ, loid = InvalidOid;
        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, "O|ll", &ztxn, php_pqtxn_class_entry, &loid, &mode);
-       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(), "O|ll", &ztxn, php_pqtxn_class_entry, &loid, &mode);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqlob_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-               php_pqtxn_object_t *txn_obj = zend_object_store_get_object(ztxn TSRMLS_CC);
+               php_pqlob_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
+               php_pqtxn_object_t *txn_obj = PHP_PQ_OBJ(ztxn, NULL);
 
                if (obj->intern) {
-                       throw_exce(EX_BAD_METHODCALL TSRMLS_CC, "pq\\LOB already initialized");
+                       throw_exce(EX_BAD_METHODCALL, "pq\\LOB already initialized");
                } else if (!txn_obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\Transaction not initialized");
                } else if (!txn_obj->intern->open) {
-                       throw_exce(EX_RUNTIME TSRMLS_CC, "pq\\Transation already closed");
+                       throw_exce(EX_RUNTIME, "pq\\Transation already closed");
                } else {
                        if (loid == InvalidOid) {
                                loid = lo_creat(txn_obj->intern->conn->intern->conn, mode);
                        }
 
                        if (loid == InvalidOid) {
-                               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to create large object with mode '%s' (%s)", php_pq_strmode(mode), PHP_PQerrorMessage(txn_obj->intern->conn->intern->conn));
+                               throw_exce(EX_RUNTIME, "Failed to create large object with mode '%s' (%s)", php_pq_strmode(mode), PHP_PQerrorMessage(txn_obj->intern->conn->intern->conn));
                        } else {
                                int lofd = lo_open(txn_obj->intern->conn->intern->conn, loid, mode);
 
                                if (lofd < 0) {
-                                       throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to open large object with oid=%u with mode '%s' (%s)", loid, php_pq_strmode(mode), PHP_PQerrorMessage(txn_obj->intern->conn->intern->conn));
+                                       throw_exce(EX_RUNTIME, "Failed to open large object with oid=%u with mode '%s' (%s)", loid, php_pq_strmode(mode), PHP_PQerrorMessage(txn_obj->intern->conn->intern->conn));
                                } else {
                                        obj->intern = ecalloc(1, sizeof(*obj->intern));
                                        obj->intern->lofd = lofd;
                                        obj->intern->loid = loid;
-                                       php_pq_object_addref(txn_obj TSRMLS_CC);
+                                       php_pq_object_addref(txn_obj);
                                        obj->intern->txn = txn_obj;
                                }
                        }
 
-                       php_pqconn_notify_listeners(txn_obj->intern->conn TSRMLS_CC);
+                       php_pqconn_notify_listeners(txn_obj->intern->conn);
                }
        }
 }
@@ -284,28 +268,28 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(pqlob, write) {
        zend_error_handling zeh;
        char *data_str;
-       int data_len;
+       size_t data_len;
        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, "s", &data_str, &data_len);
-       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(), "s", &data_str, &data_len);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqlob_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqlob_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\LOB not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\LOB not initialized");
                } else {
                        int written = lo_write(obj->intern->txn->intern->conn->intern->conn, obj->intern->lofd, data_str, data_len);
 
                        if (written < 0) {
-                               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to write to LOB with oid=%u (%s)", obj->intern->loid, PHP_PQerrorMessage(obj->intern->txn->intern->conn->intern->conn));
+                               throw_exce(EX_RUNTIME, "Failed to write to LOB with oid=%u (%s)", obj->intern->loid, PHP_PQerrorMessage(obj->intern->txn->intern->conn->intern->conn));
                        } else {
                                RETVAL_LONG(written);
                        }
 
-                       php_pqconn_notify_listeners(obj->intern->txn->intern->conn TSRMLS_CC);
+                       php_pqconn_notify_listeners(obj->intern->txn->intern->conn);
                }
        }
 }
@@ -316,36 +300,37 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqlob_read, 0, 0, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqlob, read) {
        zend_error_handling zeh;
-       long length = 0x1000;
+       zend_long length = 0x1000;
        zval *zread = 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, "|lz!", &length, &zread);
-       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!", &length, &zread);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqlob_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqlob_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\LOB not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\LOB not initialized");
                } else {
-                       char *buffer = emalloc(length + 1);
-                       int read = lo_read(obj->intern->txn->intern->conn->intern->conn, obj->intern->lofd, buffer, length);
+                       zend_string *buffer = zend_string_alloc(length, 0);
+                       int read = lo_read(obj->intern->txn->intern->conn->intern->conn, obj->intern->lofd, &buffer->val[0], length);
 
                        if (read < 0) {
-                               efree(buffer);
-                               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to read from LOB with oid=%d (%s)", obj->intern->loid, PHP_PQerrorMessage(obj->intern->txn->intern->conn->intern->conn));
+                               zend_string_release(buffer);
+                               throw_exce(EX_RUNTIME, "Failed to read from LOB with oid=%d (%s)", obj->intern->loid, PHP_PQerrorMessage(obj->intern->txn->intern->conn->intern->conn));
                        } else {
                                if (zread) {
+                                       ZVAL_DEREF(zread);
                                        zval_dtor(zread);
                                        ZVAL_LONG(zread, read);
                                }
-                               buffer[read] = '\0';
-                               RETVAL_STRINGL(buffer, read, 0);
+                               buffer->val[buffer->len = read] = '\0';
+                               RETVAL_STR(buffer);
                        }
 
-                       php_pqconn_notify_listeners(obj->intern->txn->intern->conn TSRMLS_CC);
+                       php_pqconn_notify_listeners(obj->intern->txn->intern->conn);
                }
        }
 }
@@ -356,28 +341,28 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqlob_seek, 0, 0, 1)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqlob, seek) {
        zend_error_handling zeh;
-       long offset, whence = SEEK_SET;
+       zend_long offset, whence = SEEK_SET;
        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, "l|l", &offset, &whence);
-       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(), "l|l", &offset, &whence);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqlob_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqlob_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\LOB not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\LOB not initialized");
                } else {
                        int position = lo_lseek(obj->intern->txn->intern->conn->intern->conn, obj->intern->lofd, offset, whence);
 
                        if (position < 0) {
-                               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to seek offset in LOB with oid=%d (%s)", obj->intern->loid,    PHP_PQerrorMessage(obj->intern->txn->intern->conn->intern->conn));
+                               throw_exce(EX_RUNTIME, "Failed to seek offset in LOB with oid=%d (%s)", obj->intern->loid,      PHP_PQerrorMessage(obj->intern->txn->intern->conn->intern->conn));
                        } else {
                                RETVAL_LONG(position);
                        }
 
-                       php_pqconn_notify_listeners(obj->intern->txn->intern->conn TSRMLS_CC);
+                       php_pqconn_notify_listeners(obj->intern->txn->intern->conn);
                }
        }
 }
@@ -388,25 +373,25 @@ static PHP_METHOD(pqlob, tell) {
        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();
-       zend_restore_error_handling(&zeh TSRMLS_CC);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqlob_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqlob_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\LOB not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\LOB not initialized");
                } else {
                        int position = lo_tell(obj->intern->txn->intern->conn->intern->conn, obj->intern->lofd);
 
                        if (position < 0) {
-                               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to tell offset in LOB with oid=%d (%s)", obj->intern->loid, PHP_PQerrorMessage(obj->intern->txn->intern->conn->intern->conn));
+                               throw_exce(EX_RUNTIME, "Failed to tell offset in LOB with oid=%d (%s)", obj->intern->loid, PHP_PQerrorMessage(obj->intern->txn->intern->conn->intern->conn));
                        } else {
                                RETVAL_LONG(position);
                        }
 
-                       php_pqconn_notify_listeners(obj->intern->txn->intern->conn TSRMLS_CC);
+                       php_pqconn_notify_listeners(obj->intern->txn->intern->conn);
                }
        }
 }
@@ -416,26 +401,26 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqlob_truncate, 0, 0, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqlob, truncate) {
        zend_error_handling zeh;
-       long length = 0;
+       zend_long length = 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, "|l", &length);
-       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(), "|l", &length);
+       zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               php_pqlob_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_pqlob_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 
                if (!obj->intern) {
-                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\LOB not initialized");
+                       throw_exce(EX_UNINITIALIZED, "pq\\LOB not initialized");
                } else {
                        int rc = lo_truncate(obj->intern->txn->intern->conn->intern->conn, obj->intern->lofd, length);
 
                        if (rc != 0) {
-                               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to truncate LOB with oid=%d (%s)", obj->intern->loid, PHP_PQerrorMessage(obj->intern->txn->intern->conn->intern->conn));
+                               throw_exce(EX_RUNTIME, "Failed to truncate LOB with oid=%d (%s)", obj->intern->loid, PHP_PQerrorMessage(obj->intern->txn->intern->conn->intern->conn));
                        }
 
-                       php_pqconn_notify_listeners(obj->intern->txn->intern->conn TSRMLS_CC);
+                       php_pqconn_notify_listeners(obj->intern->txn->intern->conn);
                }
        }
 }
@@ -462,10 +447,12 @@ PHP_MINIT_FUNCTION(pqlob)
        php_pq_object_prophandler_t ph = {0};
 
        INIT_NS_CLASS_ENTRY(ce, "pq", "LOB", php_pqlob_methods);
-       php_pqlob_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
+       php_pqlob_class_entry = zend_register_internal_class_ex(&ce, NULL);
        php_pqlob_class_entry->create_object = php_pqlob_create_object;
 
        memcpy(&php_pqlob_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+       php_pqlob_object_handlers.offset = XtOffsetOf(php_pqlob_object_t, zo);
+       php_pqlob_object_handlers.free_obj = php_pqlob_object_free;
        php_pqlob_object_handlers.read_property = php_pq_object_read_prop;
        php_pqlob_object_handlers.write_property = php_pq_object_write_prop;
        php_pqlob_object_handlers.clone_obj = NULL;
@@ -476,22 +463,22 @@ PHP_MINIT_FUNCTION(pqlob)
 
        zend_hash_init(&php_pqlob_object_prophandlers, 3, NULL, NULL, 1);
 
-       zend_declare_property_null(php_pqlob_class_entry, ZEND_STRL("transaction"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_null(php_pqlob_class_entry, ZEND_STRL("transaction"), ZEND_ACC_PUBLIC);
        ph.read = php_pqlob_object_read_transaction;
-       zend_hash_add(&php_pqlob_object_prophandlers, "transaction", sizeof("transaction"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqlob_object_prophandlers, "transaction", sizeof("transaction")-1, (void *) &ph, sizeof(ph));
 
-       zend_declare_property_long(php_pqlob_class_entry, ZEND_STRL("oid"), InvalidOid, ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_long(php_pqlob_class_entry, ZEND_STRL("oid"), InvalidOid, ZEND_ACC_PUBLIC);
        ph.read = php_pqlob_object_read_oid;
-       zend_hash_add(&php_pqlob_object_prophandlers, "oid", sizeof("oid"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqlob_object_prophandlers, "oid", sizeof("oid"), (void *) &ph, sizeof(ph));
 
-       zend_declare_property_null(php_pqlob_class_entry, ZEND_STRL("stream"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_null(php_pqlob_class_entry, ZEND_STRL("stream"), ZEND_ACC_PUBLIC);
        ph.read = php_pqlob_object_read_stream;
-       zend_hash_add(&php_pqlob_object_prophandlers, "stream", sizeof("stream"), (void *) &ph, sizeof(ph), NULL);
+       zend_hash_str_add_mem(&php_pqlob_object_prophandlers, "stream", sizeof("stream"), (void *) &ph, sizeof(ph));
 
-       zend_declare_class_constant_long(php_pqlob_class_entry, ZEND_STRL("INVALID_OID"), InvalidOid TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqlob_class_entry, ZEND_STRL("R"), INV_READ TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqlob_class_entry, ZEND_STRL("W"), INV_WRITE TSRMLS_CC);
-       zend_declare_class_constant_long(php_pqlob_class_entry, ZEND_STRL("RW"), INV_READ|INV_WRITE TSRMLS_CC);
+       zend_declare_class_constant_long(php_pqlob_class_entry, ZEND_STRL("INVALID_OID"), InvalidOid);
+       zend_declare_class_constant_long(php_pqlob_class_entry, ZEND_STRL("R"), INV_READ);
+       zend_declare_class_constant_long(php_pqlob_class_entry, ZEND_STRL("W"), INV_WRITE);
+       zend_declare_class_constant_long(php_pqlob_class_entry, ZEND_STRL("RW"), INV_READ|INV_WRITE);
 
        return SUCCESS;
 }
index 98c8a9497ad5aea00b9670b3dee97f87514bbf08..c56049de045e12a45d7d2bc8b9a65f3607adc26e 100644 (file)
 typedef struct php_pqlob {
        int lofd;
        Oid loid;
-       int stream;
+       php_stream *stream;
        php_pqtxn_object_t *txn;
 } php_pqlob_t;
 
 typedef struct php_pqlob_object {
-       zend_object zo;
-       zend_object_value zv;
-       HashTable *prophandler;
        php_pqlob_t *intern;
+       HashTable *prophandler;
+       zend_object zo;
 } php_pqlob_object_t;
 
 extern zend_class_entry *php_pqlob_class_entry;
-extern zend_object_value php_pqlob_create_object_ex(zend_class_entry *ce, php_pqlob_t *intern, php_pqlob_object_t **ptr TSRMLS_DC);
+extern php_pqlob_object_t *php_pqlob_create_object_ex(zend_class_entry *ce, php_pqlob_t *intern);
 
 extern PHP_MINIT_FUNCTION(pqlob);
 extern PHP_MSHUTDOWN_FUNCTION(pqlob);
index 6e1fa681090aa1f476f1362e6b26e80ae277d03c..b83ee973f1275d1de87c368bce12a7f0ba387dc0 100644 (file)
@@ -36,48 +36,35 @@ static zend_object_handlers php_pqres_object_handlers;
 static HashTable php_pqres_object_prophandlers;
 static zend_object_iterator_funcs php_pqres_iterator_funcs;
 
-static zend_object_iterator *php_pqres_iterator_init(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC)
+static zend_object_iterator *php_pqres_iterator_init(zend_class_entry *ce, zval *object, int by_ref)
 {
        php_pqres_iterator_t *iter;
-       zval *prop, *zfetch_type;
+       zval tmp, *zfetch_type;
 
        iter = ecalloc(1, sizeof(*iter));
        iter->zi.funcs = &php_pqres_iterator_funcs;
-       iter->zi.data = zend_object_store_get_object(object TSRMLS_CC);
-       zend_objects_store_add_ref(object TSRMLS_CC);
+       iter->zi.data = PHP_PQ_OBJ(object, NULL);
+       php_pq_object_addref(iter->zi.data);
 
-       zfetch_type = prop = zend_read_property(ce, object, ZEND_STRL("fetchType"), 0 TSRMLS_CC);
-       if (Z_TYPE_P(zfetch_type) != IS_LONG) {
-               convert_to_long_ex(&zfetch_type);
-       }
-       iter->fetch_type = Z_LVAL_P(zfetch_type);
-       if (zfetch_type != prop) {
-               zval_ptr_dtor(&zfetch_type);
-       }
-       if (Z_REFCOUNT_P(prop)) {
-               zval_ptr_dtor(&prop);
-       } else {
-               zval_dtor(prop);
-               FREE_ZVAL(prop);
-       }
+       zfetch_type = zend_read_property(ce, object, ZEND_STRL("fetchType"), 0, &tmp);
+       iter->fetch_type = zval_get_long(zfetch_type);
 
        return (zend_object_iterator *) iter;
 }
 
-static void php_pqres_iterator_dtor(zend_object_iterator *i TSRMLS_DC)
+static void php_pqres_iterator_dtor(zend_object_iterator *i)
 {
        php_pqres_iterator_t *iter = (php_pqres_iterator_t *) i;
        php_pqres_object_t *obj = i->data;
 
-       if (iter->current_val) {
+       if (!Z_IS_UNDEF(&iter->current_val)) {
                zval_ptr_dtor(&iter->current_val);
-               iter->current_val = NULL;
        }
-       zend_objects_store_del_ref_by_handle_ex(obj->zv.handle, obj->zv.handlers TSRMLS_CC);
+       php_pq_object_delref(obj);
        efree(iter);
 }
 
-static ZEND_RESULT_CODE php_pqres_iterator_valid(zend_object_iterator *i TSRMLS_DC)
+static ZEND_RESULT_CODE php_pqres_iterator_valid(zend_object_iterator *i)
 {
        php_pqres_iterator_t *iter = (php_pqres_iterator_t *) i;
        php_pqres_object_t *obj = i->data;
@@ -101,35 +88,33 @@ static ZEND_RESULT_CODE php_pqres_iterator_valid(zend_object_iterator *i TSRMLS_
 #define PHP_PQRES_JSON_OPTIONS(res) \
        (php_pqres_fetch_type(res) != PHP_PQRES_FETCH_OBJECT ? PHP_JSON_OBJECT_AS_ARRAY:0)
 
-zval *php_pqres_typed_zval(php_pqres_t *res, char *val, size_t len, Oid typ TSRMLS_DC)
+zval *php_pqres_typed_zval(php_pqres_t *res, Oid typ, zval *zv)
 {
-       zval *zv, **zconv;
+       zval *zconv;
+       HashTable *ht;
+       zend_string *str;
 
-       MAKE_STD_ZVAL(zv);
+       if ((zconv = zend_hash_index_find(&res->converters, typ))) {
+               zval ztype, rv;
 
-       if (SUCCESS == zend_hash_index_find(&res->converters, typ, (void *) &zconv)) {
-               zval *ztype, *tmp = NULL;
+               ZVAL_NULL(&rv);
+               ZVAL_LONG(&ztype, typ);
+               zend_call_method_with_2_params(zconv, NULL, NULL, "convertfromstring", &rv, zv, &ztype);
 
-               MAKE_STD_ZVAL(ztype);
-               ZVAL_LONG(ztype, typ);
-               ZVAL_STRINGL(zv, val, len, 1);
-               zend_call_method_with_2_params(zconv, NULL, NULL, "convertfromstring", &tmp, zv, ztype);
-               zval_ptr_dtor(&ztype);
-
-               if (tmp) {
-                       zval_ptr_dtor(&zv);
-                       zv = tmp;
-               }
+               ZVAL_ZVAL(&rv, zv, 1, 1);
 
                return zv;
        }
 
+       str = zval_get_string(zv);
+       zval_ptr_dtor(zv);
+
        switch (typ) {
        case PHP_PQ_OID_BOOL:
                if (!(res->auto_convert & PHP_PQRES_CONV_BOOL)) {
                        goto noconversion;
                }
-               ZVAL_BOOL(zv, *val == 't');
+               ZVAL_BOOL(zv, *str->val == 't');
                break;
 
        case PHP_PQ_OID_INT8:
@@ -145,7 +130,7 @@ zval *php_pqres_typed_zval(php_pqres_t *res, char *val, size_t len, Oid typ TSRM
                        long lval;
                        double dval;
 
-                       switch (is_numeric_string(val, len, &lval, &dval, 0)) {
+                       switch (is_numeric_str_function(str, &lval, &dval)) {
                                case IS_LONG:
                                        ZVAL_LONG(zv, lval);
                                        break;
@@ -163,35 +148,35 @@ zval *php_pqres_typed_zval(php_pqres_t *res, char *val, size_t len, Oid typ TSRM
                if (!(res->auto_convert & PHP_PQRES_CONV_FLOAT)) {
                        goto noconversion;
                }
-               ZVAL_DOUBLE(zv, zend_strtod(val, NULL));
+               ZVAL_DOUBLE(zv, zend_strtod(str->val, NULL));
                break;
 
        case PHP_PQ_OID_DATE:
                if (!(res->auto_convert & PHP_PQRES_CONV_DATETIME)) {
                        goto noconversion;
                }
-               php_pqdt_from_string(zv, NULL, val, len, "Y-m-d", NULL TSRMLS_CC);
+               php_pqdt_from_string(zv, NULL, str->val, str->len, "Y-m-d", NULL);
                break;
 
        case PHP_PQ_OID_ABSTIME:
                if (!(res->auto_convert & PHP_PQRES_CONV_DATETIME)) {
                        goto noconversion;
                }
-               php_pqdt_from_string(zv, NULL, val, len, "Y-m-d H:i:s", NULL TSRMLS_CC);
+               php_pqdt_from_string(zv, NULL, str->val, str->len, "Y-m-d H:i:s", NULL);
                break;
 
        case PHP_PQ_OID_TIMESTAMP:
                if (!(res->auto_convert & PHP_PQRES_CONV_DATETIME)) {
                        goto noconversion;
                }
-               php_pqdt_from_string(zv, NULL, val, len, "Y-m-d H:i:s.u", NULL TSRMLS_CC);
+               php_pqdt_from_string(zv, NULL, str->val, str->len, "Y-m-d H:i:s.u", NULL);
                break;
 
        case PHP_PQ_OID_TIMESTAMPTZ:
                if (!(res->auto_convert & PHP_PQRES_CONV_DATETIME)) {
                        goto noconversion;
                }
-               php_pqdt_from_string(zv, NULL, val, len, "Y-m-d H:i:s.uO", NULL TSRMLS_CC);
+               php_pqdt_from_string(zv, NULL, str->val, str->len, "Y-m-d H:i:s.uO", NULL);
                break;
 
 #if PHP_PQ_HAVE_PHP_JSON_H && defined(PHP_PQ_OID_JSON)
@@ -202,7 +187,7 @@ zval *php_pqres_typed_zval(php_pqres_t *res, char *val, size_t len, Oid typ TSRM
                if (!(res->auto_convert & PHP_PQRES_CONV_JSON)) {
                        goto noconversion;
                }
-               php_json_decode_ex(zv, val, len, PHP_PQRES_JSON_OPTIONS(res), 512 /* PHP_JSON_DEFAULT_DEPTH */ TSRMLS_CC);
+               php_json_decode_ex(zv, str->val, str->len, PHP_PQRES_JSON_OPTIONS(res), 512 /* PHP_JSON_DEFAULT_DEPTH */);
                break;
 #endif
 
@@ -210,33 +195,35 @@ zval *php_pqres_typed_zval(php_pqres_t *res, char *val, size_t len, Oid typ TSRM
                if (!(res->auto_convert & PHP_PQRES_CONV_ARRAY)) {
                        goto noconversion;
                }
-               if (PHP_PQ_TYPE_IS_ARRAY(typ) && (Z_ARRVAL_P(zv) = php_pq_parse_array(res, val, len, PHP_PQ_TYPE_OF_ARRAY(typ) TSRMLS_CC))) {
-                       Z_TYPE_P(zv) = IS_ARRAY;
+               if (PHP_PQ_TYPE_IS_ARRAY(typ) && (ht = php_pq_parse_array(res, str->val, str->len, PHP_PQ_TYPE_OF_ARRAY(typ)))) {
+                       ZVAL_ARR(zv, ht);
                } else {
-                       noconversion:
-                       ZVAL_STRINGL(zv, val, len, 1);
+                       goto noconversion;
                }
                break;
        }
 
+       zend_sring_release(str);
+       return zv;
+
+       noconversion:
+       ZVAL_STR(zv, str);
        return zv;
 }
 
-static inline zval *php_pqres_get_col(php_pqres_t *r, unsigned row, unsigned col TSRMLS_DC)
+static inline zval *php_pqres_get_col(php_pqres_t *r, unsigned row, unsigned col, zval *zv)
 {
-       zval *zv;
-
        if (PQgetisnull(r->res, row, col)) {
-               MAKE_STD_ZVAL(zv);
                ZVAL_NULL(zv);
        } else {
-               zv = php_pqres_typed_zval(r, PQgetvalue(r->res, row, col), PQgetlength(r->res, row, col), PQftype(r->res, col) TSRMLS_CC);
+               ZVAL_STRINGL(zv, PQgetvalue(r->res, row, col), PQgetlength(r->res, row, col));
+               zv = php_pqres_typed_zval(r, PQftype(r->res, col), zv);
        }
 
        return zv;
 }
 
-static inline void php_pqres_add_col_to_zval(php_pqres_t *r, unsigned row, unsigned col, php_pqres_fetch_t fetch_type, zval *data TSRMLS_DC)
+static inline void php_pqres_add_col_to_zval(php_pqres_t *r, unsigned row, unsigned col, php_pqres_fetch_t fetch_type, zval *data)
 {
        if (PQgetisnull(r->res, row, col)) {
                switch (fetch_type) {
@@ -253,51 +240,44 @@ static inline void php_pqres_add_col_to_zval(php_pqres_t *r, unsigned row, unsig
                        break;
                }
        } else {
-               zval *zv;
+               zval zv;
 
-               zv = php_pqres_typed_zval(r, PQgetvalue(r->res, row, col), PQgetlength(r->res, row, col), PQftype(r->res, col) TSRMLS_CC);
+               ZVAL_STRINGL(&zv, PQgetvalue(r->res, row, col), PQgetlength(r->res, row, col));
+               php_pqres_typed_zval(r, PQftype(r->res, col), &zv);
 
                switch (fetch_type) {
                case PHP_PQRES_FETCH_OBJECT:
-                       add_property_zval(data, PQfname(r->res, col), zv);
+                       add_property_zval(data, PQfname(r->res, col), &zv);
                        zval_ptr_dtor(&zv);
                        break;
 
                case PHP_PQRES_FETCH_ASSOC:
-                       add_assoc_zval(data, PQfname(r->res, col), zv);
+                       add_assoc_zval(data, PQfname(r->res, col), &zv);
                        break;
 
                case PHP_PQRES_FETCH_ARRAY:
-                       add_index_zval(data, col, zv);
+                       add_index_zval(data, col, &zv);
                        break;
                }
        }
 }
 
-zval *php_pqres_row_to_zval(PGresult *res, unsigned row, php_pqres_fetch_t fetch_type, zval **data_ptr TSRMLS_DC)
+zval *php_pqres_row_to_zval(PGresult *res, unsigned row, php_pqres_fetch_t fetch_type, zval *data)
 {
-       zval *data = NULL;
        int c, cols;
        php_pqres_object_t *res_obj = PQresultInstanceData(res, php_pqconn_event);
 
-       if (data_ptr) {
-               data = *data_ptr;
-       }
-       if (!data) {
-               MAKE_STD_ZVAL(data);
+       if (Z_TYPE_P(data) != IS_OBJECT && Z_TYPE_P(data) != IS_ARRAY) {
                if (PHP_PQRES_FETCH_OBJECT == fetch_type) {
                        object_init(data);
                } else {
                        array_init(data);
                }
-               if (data_ptr) {
-                       *data_ptr = data;
-               }
        }
 
        if (PQntuples(res) > row) {
                for (c = 0, cols = PQnfields(res); c < cols; ++c) {
-                       php_pqres_add_col_to_zval(res_obj->intern, row, c, fetch_type, data TSRMLS_CC);
+                       php_pqres_add_col_to_zval(res_obj->intern, row, c, fetch_type, data);
                }
        }
 
index f5f80bfa576ee07317753c4fc8b21b0f684bbb41..e0ed25ed7089c50a7c8c2c2e013783044bc4e624 100644 (file)
@@ -33,7 +33,7 @@ typedef enum php_pqres_fetch {
 
 typedef struct php_pqres_iterator {
        zend_object_iterator zi;
-       zval *current_val;
+       zval current_val;
        unsigned index;
        php_pqres_fetch_t fetch_type;
 } php_pqres_iterator_t;
@@ -48,16 +48,15 @@ typedef struct php_pqres {
 } php_pqres_t;
 
 typedef struct php_pqres_object {
-       zend_object zo;
-       zend_object_value zv;
-       HashTable *prophandler;
        php_pqres_t *intern;
+       HashTable *prophandler;
+       zend_object zo;
 } php_pqres_object_t;
 
-extern ZEND_RESULT_CODE php_pqres_success(PGresult *res TSRMLS_DC);
-extern void php_pqres_init_instance_data(PGresult *res, php_pqconn_object_t *obj, php_pqres_object_t **ptr TSRMLS_DC);
-extern zval *php_pqres_row_to_zval(PGresult *res, unsigned row, php_pqres_fetch_t fetch_type, zval **data_ptr TSRMLS_DC);
-extern zval *php_pqres_typed_zval(php_pqres_t *res, char *val, size_t len, Oid typ TSRMLS_DC);
+extern ZEND_RESULT_CODE php_pqres_success(PGresult *res);
+extern void php_pqres_init_instance_data(PGresult *res, php_pqconn_object_t *obj, php_pqres_object_t **ptr);
+extern zval *php_pqres_row_to_zval(PGresult *res, unsigned row, php_pqres_fetch_t fetch_type, zval **data_ptr);
+extern zval *php_pqres_typed_zval(php_pqres_t *res, Oid typ, zval *zv);
 extern php_pqres_fetch_t php_pqres_fetch_type(php_pqres_t *res);
 
 #include "php_pq_object.h"
@@ -65,14 +64,14 @@ extern php_pqres_fetch_t php_pqres_fetch_type(php_pqres_t *res);
 #define PHP_PQclear(_r) do { \
        php_pqres_object_t *_o = PQresultInstanceData((_r), php_pqconn_event); \
        if (_o) { \
-               php_pq_object_delref(_o TSRMLS_CC); \
+               php_pq_object_delref(_o); \
        } else { \
                PQclear(_r); \
        } \
 } while(0)
 
 extern zend_class_entry *php_pqres_class_entry;
-extern zend_object_value php_pqres_create_object_ex(zend_class_entry *ce, php_pqres_t *intern, php_pqres_object_t **ptr TSRMLS_DC);
+extern php_pqres_object_t *php_pqres_create_object_ex(zend_class_entry *ce, php_pqres_t *intern);
 
 extern PHP_MINIT_FUNCTION(pqres);
 extern PHP_MSHUTDOWN_FUNCTION(pqres);
index f5c59a6dbe0bde6dc74f2659911f6ad10e4c51b8..61afa429d9f22b63447114c27ea4383067f349fa 100644 (file)
@@ -26,15 +26,14 @@ typedef struct php_pqstm {
 } php_pqstm_t;
 
 typedef struct php_pqstm_object {
-       zend_object zo;
-       zend_object_value zv;
-       HashTable *prophandler;
        php_pqstm_t *intern;
+       HashTable *prophandler;
+       zend_object zo;
 } php_pqstm_object_t;
 
 extern zend_class_entry *php_pqstm_class_entry;
-extern zend_object_value php_pqstm_create_object_ex(zend_class_entry *ce, php_pqstm_t *intern, php_pqstm_object_t **ptr TSRMLS_DC);
-extern php_pqstm_t *php_pqstm_init(php_pqconn_object_t *conn, const char *name, const char *query, php_pq_params_t *params TSRMLS_DC);
+extern php_pqstm_object_t *php_pqstm_create_object_ex(zend_class_entry *ce, php_pqstm_t *intern);
+extern php_pqstm_t *php_pqstm_init(php_pqconn_object_t *conn, const char *name, const char *query, php_pq_params_t *params);
 
 extern PHP_MINIT_FUNCTION(pqstm);
 extern PHP_MSHUTDOWN_FUNCTION(pqstm);
index 0c8fd868deadb0013d8faf9257cf754b987615c2..4873d8ec56a5851023d1b975821b03bb7f1fc9fd 100644 (file)
@@ -32,16 +32,15 @@ typedef struct php_pqtxn {
 } php_pqtxn_t;
 
 typedef struct php_pqtxn_object {
-       zend_object zo;
-       zend_object_value zv;
-       HashTable *prophandler;
        php_pqtxn_t *intern;
+       HashTable *prophandler;
+       zend_object zo;
 } php_pqtxn_object_t;
 
 extern const char *php_pq_isolation_level(long *isolation);
 
 extern zend_class_entry *php_pqtxn_class_entry;
-extern zend_object_value php_pqtxn_create_object_ex(zend_class_entry *ce, php_pqtxn_t *intern, php_pqtxn_object_t **ptr TSRMLS_DC);
+extern php_pqtxn_object_t *php_pqtxn_create_object_ex(zend_class_entry *ce, php_pqtxn_t *intern);
 
 extern PHP_MINIT_FUNCTION(pqtxn);
 extern PHP_MSHUTDOWN_FUNCTION(pqtxn);
index 8a551b104b151c9bcc601d054e708fbc8f8e563f..1c5da1f2d1f6ad215db457bea96ec048e368a614 100644 (file)
@@ -22,14 +22,13 @@ typedef struct php_pqtypes {
 } php_pqtypes_t;
 
 typedef struct php_pqtypes_object {
-       zend_object zo;
-       zend_object_value zv;
-       HashTable *prophandler;
        php_pqtypes_t *intern;
+       HashTable *prophandler;
+       zend_object zo;
 } php_pqtypes_object_t;
 
 extern zend_class_entry *php_pqtypes_class_entry;
-extern zend_object_value php_pqtypes_create_object_ex(zend_class_entry *ce, php_pqtypes_t *intern, php_pqtypes_object_t **ptr TSRMLS_DC);
+extern php_pqtypes_object_t *php_pqtypes_create_object_ex(zend_class_entry *ce, php_pqtypes_t *intern);
 
 extern PHP_MINIT_FUNCTION(pqtypes);
 extern PHP_MSHUTDOWN_FUNCTION(pqtypes);