Merge branch 'v1.0.x'
authorMichael Wallner <mike@php.net>
Tue, 3 May 2016 13:02:54 +0000 (15:02 +0200)
committerMichael Wallner <mike@php.net>
Tue, 3 May 2016 13:02:54 +0000 (15:02 +0200)
1  2 
src/php_pq_misc.c
src/php_pq_misc.h
src/php_pqconn.c
src/php_pqcopy.c
src/php_pqcur.c
src/php_pqstm.c
src/php_pqtxn.c
src/php_pqtypes.c

diff --combined src/php_pq_misc.c
index 9eccae98df41b70315dba75362932001b5851fcd,ba591834fe6c6abc2a75aea16298d7fc424df29f..eb1ca97cdae75a4d3ef8df9e68f2063bb2dba604
  
  
  /* clear result object associated with a result handle */
- void php_pq_clear_res(PGresult *r) {
+ void php_pqres_clear(PGresult *r) {
        php_pq_object_t *o = PQresultInstanceData(r, php_pqconn_event);
  
        if (o) {
 -              TSRMLS_FETCH();
 -              php_pq_object_delref(o TSRMLS_CC);
 +              php_pq_object_delref(o);
        } else {
                PQclear(r);
        }
  }
  
  /* clear any asynchronous results */
- void php_pq_clear_conn(PGconn *conn) {
+ void php_pqconn_clear(PGconn *conn) {
        PGresult *r;
        php_pqconn_event_data_t *evdata = PQinstanceData(conn, php_pqconn_event);
  
        while ((r = PQgetResult(conn))) {
-               php_pq_clear_res(r);
+               php_pqres_clear(r);
        }
  
        if (evdata && evdata->obj) {
                if (php_pq_callback_is_enabled(&evdata->obj->intern->onevent)) {
 -                      TSRMLS_FETCH_FROM_CTX(evdata->ts);
 -
 -                      if (php_pq_callback_is_locked(&evdata->obj->intern->onevent TSRMLS_CC)) {
 -                              php_pq_callback_disable(&evdata->obj->intern->onevent TSRMLS_CC);
 +                      if (php_pq_callback_is_locked(&evdata->obj->intern->onevent)) {
 +                              php_pq_callback_disable(&evdata->obj->intern->onevent);
                        } else {
                                php_pq_callback_dtor(&evdata->obj->intern->onevent);
                        }
  
  /* safe wrappers to clear any asynchronous wrappers before querying synchronously */
  PGresult *php_pq_exec(PGconn *conn, const char *query) {
-       php_pq_clear_conn(conn);
+       php_pqconn_clear(conn);
        return PQexec(conn, query);
  }
  PGresult *php_pq_exec_params(PGconn *conn, const char *command, int nParams, const Oid *paramTypes, const char *const * paramValues, const int *paramLengths, const int *paramFormats, int resultFormat) {
-       php_pq_clear_conn(conn);
+       php_pqconn_clear(conn);
        return PQexecParams(conn, command, nParams, paramTypes, paramValues, paramLengths, paramFormats, resultFormat);
  }
  PGresult *php_pq_prepare(PGconn *conn, const char *stmtName, const char *query, int nParams, const Oid *paramTypes) {
-       php_pq_clear_conn(conn);
+       php_pqconn_clear(conn);
        return PQprepare(conn, stmtName, query, nParams, paramTypes);
  }
  PGresult *php_pq_exec_prepared(PGconn *conn, const char *stmtName, int nParams, const char *const * paramValues, const int *paramLengths, const int *paramFormats, int resultFormat) {
-       php_pq_clear_conn(conn);
+       php_pqconn_clear(conn);
        return PQexecPrepared(conn, stmtName, nParams, paramValues, paramLengths, paramFormats, resultFormat);
  }
  
@@@ -103,37 -106,33 +103,37 @@@ 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;
 +      zend_ulong l = ((const Bucket *) lptr)->h;
 +      zend_ulong r = ((const Bucket *) rptr)->h;
  
 -      if (l->h < r->h) {
 +      if (l < r) {
                return -1;
        }
 -      if (l->h > r->h) {
 +      if (l > r) {
                return 1;
        }
        return 0;
  }
  
 +void php_pq_hash_ptr_dtor(zval *p)
 +{
 +      efree(Z_PTR_P(p));
 +}
 +
  zend_class_entry *php_pqdt_class_entry;
  
  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)
@@@ -145,16 -144,16 +145,16 @@@ static PHP_METHOD(pqdt, createFromForma
  {
        zend_error_handling zeh;
        char *fmt_str, *dt_str;
 -      int fmt_len, dt_len;
 +      size_t fmt_len, dt_len;
        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);
        }
  }
  
@@@ -165,47 -164,54 +165,47 @@@ static zend_function_entry php_pqdt_met
        {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;
@@@ -233,27 -239,27 +233,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;
  
@@@ -261,6 -267,9 +261,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;
  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) {
                }
        } 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);
  static ZEND_RESULT_CODE parse_element(ArrayParserState *a, char delim)
  {
        const char *el;
 -      TSRMLS_FETCH_FROM_CTX(a->ts);
  
        switch (*a->ptr) {
        case '{':
                                ++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;
                }
        }
  
 -      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)) {
  
                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;
@@@ -394,10 -413,17 +394,10 @@@ static ZEND_RESULT_CODE parse_array(Arr
        }
  
        list = ecalloc(1, sizeof(*list));
 -      ZEND_INIT_SYMTABLE(&list->ht);
 +      array_init(&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;
                return FAILURE;
        }
  
 +      /* step one level back up */
        if (a->list->parent) {
 -              a->list = a->list->parent;
 +              HashTableList *l = a->list->parent;
 +
 +              efree(a->list);
 +              a->list = l;
        }
  
        return SUCCESS;
  }
  
 -HashTable *php_pq_parse_array(php_pqres_t *res, const char *val_str, size_t val_len, Oid typ TSRMLS_DC)
 +HashTable *php_pq_parse_array(php_pqres_t *res, const char *val_str, size_t val_len, Oid typ)
  {
        HashTable *ht = NULL;
        ArrayParserState a = {0};
 -      TSRMLS_SET_CTX(a.ts);
  
        a.typ = typ;
        a.ptr = val_str;
                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;
                }
        }
  
        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;
 -      } while ((a.list = a.list->parent));
 +      while (a.list) {
 +              HashTableList *l = a.list->parent;
 +
 +              ht = Z_ARRVAL(a.list->arr);
 +              efree(a.list);
 +              a.list = l;
 +      }
  
        return ht;
  }
diff --combined src/php_pq_misc.h
index 26ac0e15c027eae724ad8cce74a505412abf8a4d,eee535bf55589b6af3a81490f34e1e758c10a419..2fdb7e1432e76fc5832c90d965fcd4008f916885
  
  #include <libpq-fe.h>
  
 -#if PHP_VERSION_ID < 50500
 -#undef SUCCESS
 -#undef FAILURE
 -typedef enum {
 -      SUCCESS = 0,
 -      FAILURE = -1
 -} ZEND_RESULT_CODE;
 -#endif
 -
  #include "php_pqres.h"
  
 +#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
 +
  /* clear result object associated with a result handle */
- extern void php_pq_clear_res(PGresult *r);
+ extern void php_pqres_clear(PGresult *r);
  /* clear any asynchronous results */
- extern void php_pq_clear_conn(PGconn *conn);
+ extern void php_pqconn_clear(PGconn *conn);
  /* safe wrappers to clear any asynchronous wrappers before querying synchronously */
  extern PGresult *php_pq_exec(PGconn *conn, const char *query);
  extern PGresult *php_pq_exec_params(PGconn *conn, const char *command, int nParams, const Oid *paramTypes, const char *const * paramValues, const int *paramLengths, const int *paramFormats, int resultFormat);
  extern PGresult *php_pq_prepare(PGconn *conn, const char *stmtName, const char *query, int nParams, const Oid *paramTypes);
  extern PGresult *php_pq_exec_prepared(PGconn *conn, const char *stmtName, int nParams, const char *const * paramValues, const int *paramLengths, const int *paramFormats, int resultFormat);
  
 -/* 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
  
  /* trim LF from EOL */
  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);
 +
 +/* free zval ptr values (as hash dtor) */
 +extern void php_pq_hash_ptr_dtor(zval *p);
  
  #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);
diff --combined src/php_pqconn.c
index 07c907f59e117f5d80d81fff5c7b1045adbf93f5,1caf4d831d19cde25a0b193193c1f0c133f614f5..976e336a4bd9cf233ade70c77705fc51bf64e055
@@@ -15,7 -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>
@@@ -35,14 -37,8 +35,14 @@@ zend_class_entry *php_pqconn_class_entr
  static zend_object_handlers php_pqconn_object_handlers;
  static HashTable php_pqconn_object_prophandlers;
  
 +static void php_pq_callback_hash_dtor(zval *p)
 +{
 +      php_pq_callback_dtor(Z_PTR_P(p));
 +      efree(Z_PTR_P(p));
 +}
 +
  /*
 -static void php_pqconn_del_eventhandler(php_pqconn_object_t *obj, const char *type_str, size_t type_len, ulong id TSRMLS_DC)
 +static void php_pqconn_del_eventhandler(php_pqconn_object_t *obj, const char *type_str, size_t type_len, ulong id)
  {
        zval **evhs;
  
  }
  */
  
 -static ulong php_pqconn_add_eventhandler(php_pqconn_object_t *obj, const char *type_str, size_t type_len, php_pq_callback_t *cb TSRMLS_DC)
 +static zend_long php_pqconn_add_eventhandler(php_pqconn_object_t *obj, const char *type_str, size_t type_len, php_pq_callback_t *cb)
  {
 -      ulong h;
 -      HashTable *evhs;
 +      zend_long h;
 +      zval *zevhs;
 +
 +      if (!(zevhs = zend_hash_str_find(&obj->intern->eventhandlers, type_str, type_len))) {
 +              HashTable *evhs;
 +              zval tmp;
  
 -      if (SUCCESS != zend_hash_find(&obj->intern->eventhandlers, type_str, type_len + 1, (void *) &evhs)) {
 -              HashTable evh;
 +              ALLOC_HASHTABLE(evhs);
 +              zend_hash_init(evhs, 1, NULL, php_pq_callback_hash_dtor, 0);
  
 -              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);
 +              ZVAL_ARR(&tmp, evhs);
 +              zevhs = zend_hash_str_add(&obj->intern->eventhandlers, type_str, type_len, &tmp);
        }
  
        php_pq_callback_addref(cb);
 -      h = zend_hash_next_free_element(evhs);
 -      zend_hash_index_update(evhs, h, (void *) cb, sizeof(*cb), NULL);
 +      h = zend_hash_next_free_element(Z_ARRVAL_P(zevhs));
 +      zend_hash_index_update_mem(Z_ARRVAL_P(zevhs), h, (void *) cb, sizeof(*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);
 +      fprintf(stderr, "FREE conn(#%d) %p\n", obj->zo.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);
                efree(obj->intern);
                obj->intern = NULL;
        }
 -      zend_object_std_dtor((zend_object *) o TSRMLS_CC);
 -      efree(obj);
 +      php_pq_object_dtor(o);
  }
  
  
 -zend_object_value php_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->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;
 -
 -      return o->zv;
 +      return php_pq_object_create(ce, intern, sizeof(php_pqconn_object_t),
 +                      &php_pqconn_object_handlers, &php_pqconn_object_prophandlers);
  }
  
 -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);
 +      zend_fcall_info_args_clear(&listener->fci, 0);
  
        zval_ptr_dtor(&zchannel);
        zval_ptr_dtor(&zmessage);
        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);
        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);
                        }
  }
  #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_callback_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_callbacks(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_ARRVAL_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_callback_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_callbacks, 1, Z_ARRVAL_P(return_value));
  }
  
 -static void php_pqconn_object_read_def_fetch_type(zval *object, void *o, zval *return_value TSRMLS_DC)
 +static void php_pqconn_object_gc_event_handlers(zval *object, void *o, zval *return_value)
  {
        php_pqconn_object_t *obj = o;
 +      zval *evhs;
  
 -      RETVAL_LONG(obj->intern->default_fetch_type);
 +      ZEND_HASH_FOREACH_VAL(&obj->intern->eventhandlers, evhs)
 +      {
 +              zval *evh;
 +
 +              ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(evhs), evh)
 +              {
 +                      zval zcb;
 +
 +                      add_next_index_zval(return_value, php_pq_callback_to_zval_no_addref(Z_PTR_P(evh), &zcb));
 +              }
 +              ZEND_HASH_FOREACH_END();
 +      }
 +      ZEND_HASH_FOREACH_END();
  }
 -static void php_pqconn_object_write_def_fetch_type(zval *object, void *o, zval *value TSRMLS_DC)
 +
 +static void php_pqconn_object_read_listeners(zval *object, void *o, zval *return_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);
 +
 +      array_init(return_value);
 +      zend_hash_apply_with_arguments(&obj->intern->listeners, apply_read_callbacks, 1, Z_ARRVAL_P(return_value));
 +}
 +
 +static void php_pqconn_object_gc_listeners(zval *object, void *o, zval *return_value)
 +{
 +      php_pqconn_object_t *obj = o;
 +      zval *listeners;
 +
 +      ZEND_HASH_FOREACH_VAL(&obj->intern->listeners, listeners)
 +      {
 +              zval *listener;
 +
 +              ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(listeners), listener)
 +              {
 +                      zval zcb;
 +
 +                      add_next_index_zval(return_value, php_pq_callback_to_zval_no_addref(Z_PTR_P(listener), &zcb));
                }
 +              ZEND_HASH_FOREACH_END();
        }
 +      ZEND_HASH_FOREACH_END();
 +}
 +
 +static void php_pqconn_object_read_converters(zval *object, void *o, zval *return_value)
 +{
 +      php_pqconn_object_t *obj = o;
 +
 +      array_init(return_value);
 +      zend_hash_copy(Z_ARRVAL_P(return_value), &obj->intern->converters, zval_add_ref);
 +}
  
 -      obj->intern->default_fetch_type = Z_LVAL_P(zft) & 0x3; /* two bits only */
 +static void php_pqconn_object_gc_converters(zval *object, void *o, zval *return_value)
 +{
 +      php_pqconn_object_t *obj = o;
 +      zval *converter;
  
 -      if (zft != value) {
 -              zval_ptr_dtor(&zft);
 +      ZEND_HASH_FOREACH_VAL(&obj->intern->converters, converter)
 +      {
 +              add_next_index_zval(return_value, converter);
        }
 +      ZEND_HASH_FOREACH_END();
  }
  
 -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_fetch_type(zval *object, void *o, zval *return_value)
  {
        php_pqconn_object_t *obj = o;
  
 -      RETVAL_LONG(obj->intern->default_txn_isolation);
 +      RETVAL_LONG(obj->intern->default_fetch_type);
  }
 -static void php_pqconn_object_write_def_txn_isolation(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 *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 */
 +      obj->intern->default_fetch_type = zval_get_long(value) & 0x3; /* two bits only */
 +}
  
 -      if (zti != value) {
 -              zval_ptr_dtor(&zti);
 -      }
 +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)
 +{
 +      php_pqconn_object_t *obj = o;
 +
 +      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);
 +      zval_ptr_dtor(&zmember);
  
        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;;
        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);
  
@@@ -549,17 -560,17 +549,17 @@@ php_resource_factory_ops_t *php_pqconn_
        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_pq_clear_res(res);
+       php_pqres_clear(res);
  
        if (CONNECTION_OK != PQstatus(*handle)) {
                PQreset(*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;
                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);
        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_pq_clear_res(res);
+               php_pqres_clear(res);
        }
  
        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;
        }
        /* clean up async results */
        while ((res = PQgetResult(*handle))) {
-               php_pq_clear_res(res);
+               php_pqres_clear(res);
        }
  
        /* clean up transaction & session */
        }
  
        if (res) {
-               php_pq_clear_res(res);
+               php_pqres_clear(res);
        }
  
        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);
@@@ -646,36 -657,34 +646,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_restore_error_handling(&zeh TSRMLS_CC);
 +      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);
  
        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);
 +                      zend_hash_init(&obj->intern->eventhandlers, 0, NULL, ZVAL_PTR_DTOR, 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);
                        }
                                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));
                        }
                }
        }
@@@ -702,23 -711,23 +702,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);
                }
        }
  }
@@@ -729,23 -738,23 +729,23 @@@ 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");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
                } else {
                        if (!PQresetStart(obj->intern->conn)) {
 -                              throw_exce(EX_IO TSRMLS_CC, "Failed to start connection reset (%s)", PHP_PQerrorMessage(obj->intern->conn));
 +                              throw_exce(EX_IO, "Failed to start connection reset (%s)", PHP_PQerrorMessage(obj->intern->conn));
                        } else {
                                obj->intern->poller = (int (*)(PGconn*)) PQresetPoll;
                        }
  
 -                      php_pqconn_notify_listeners(obj TSRMLS_CC);
 +                      php_pqconn_notify_listeners(obj);
                }
        }
  }
@@@ -757,24 -766,24 +757,24 @@@ 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_pq_clear_res(res);
+                               php_pqres_clear(res);
                        }
                }
        }
@@@ -786,23 -795,23 +786,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};
  
                                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;
  
        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 tmp;
 +              HashTable *ht;
 +
 +              ALLOC_HASHTABLE(ht);
 +              zend_hash_init(ht, 0, NULL, php_pq_callback_hash_dtor, 0);
 +              zend_hash_next_index_insert_mem(ht, (void *) listener, sizeof(*listener));
 +
 +              ZVAL_ARR(&tmp, ht);
 +              zend_hash_str_add(&obj->intern->listeners, channel_str, channel_len, &tmp);
        }
  }
  
@@@ -853,24 -856,24 +853,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};
                                smart_str_appends(&cmd, quoted_channel);
                                smart_str_0(&cmd);
  
 -                              res = php_pq_exec(obj->intern->conn, cmd.c);
 +                              res = php_pq_exec(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_pq_clear_res(res);
+                                       php_pqres_clear(res);
                                }
  
 -                              php_pqconn_notify_listeners(obj TSRMLS_CC);
 +                              php_pqconn_notify_listeners(obj);
                        }
                }
        }
@@@ -907,24 -910,24 +907,24 @@@ 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");
 +                      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};
  
                                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);
                        }
                }
        }
@@@ -954,18 -957,18 +954,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};
                        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_pq_clear_res(res);
+                               php_pqres_clear(res);
                        }
  
 -                      php_pqconn_notify_listeners(obj TSRMLS_CC);
 +                      php_pqconn_notify_listeners(obj);
                }
        }
  }
@@@ -991,28 -994,28 +991,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);
                }
        }
  }
@@@ -1023,24 -1026,24 +1023,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);
                }
        }
  }
@@@ -1051,30 -1054,30 +1051,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 = php_pq_exec(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_pq_clear_res(res);
+                               php_pqres_clear(res);
                        }
  
 -                      php_pqconn_notify_listeners(obj TSRMLS_CC);
 +                      php_pqconn_notify_listeners(obj);
                }
        }
  }
@@@ -1085,25 -1088,25 +1085,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);
                }
        }
  }
@@@ -1116,28 -1119,28 +1116,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);
                }
        }
  }
@@@ -1150,38 -1153,38 +1150,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_pq_clear_res(res);
+                                       php_pqres_clear(res);
                                }
  
 -                              php_pqconn_notify_listeners(obj TSRMLS_CC);
 +                              php_pqconn_notify_listeners(obj);
                        }
                }
        }
@@@ -1197,62 -1200,62 +1197,62 @@@ static PHP_METHOD(pqconn, execParamsAsy
        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 = php_pq_prepare(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_pq_clear_res(res);
+               php_pqres_clear(res);
 -              php_pqconn_notify_listeners(obj TSRMLS_CC);
 +              php_pqconn_notify_listeners(obj);
        }
  
        return rv;
@@@ -1267,47 -1270,48 +1267,47 @@@ 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);
                        }
                }
        }
  }
  
 -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)
 +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)
  {
        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;
@@@ -1322,50 -1326,51 +1322,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 = php_pq_exec(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_pq_clear_res(res);
+               php_pqres_clear(res);
 -              php_pqconn_notify_listeners(obj TSRMLS_CC);
 +              php_pqconn_notify_listeners(obj);
        }
  
        return rv;
@@@ -1379,49 -1384,50 +1379,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;
@@@ -1435,29 -1441,30 +1435,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);
                        }
                }
        }
@@@ -1468,21 -1475,21 +1468,21 @@@ ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_quote
  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);
                        }
                }
@@@ -1494,21 -1501,21 +1494,21 @@@ ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_quote_
  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);
                        }
                }
@@@ -1522,20 -1529,20 +1522,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);
                        }
                }
@@@ -1547,38 -1554,38 +1547,38 @@@ ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_unesca
  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) {
 -              throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
 +              throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
        } else {
                PGresult *res;
                smart_str cmd = {0};
                smart_str_appends(&cmd, " DEFERRABLE");
                smart_str_0(&cmd);
  
 -              res = php_pq_exec(conn_obj->intern->conn, cmd.c);
 +              res = php_pq_exec(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_pq_clear_res(res);
+                       php_pqres_clear(res);
 -                      php_pqconn_notify_listeners(conn_obj TSRMLS_CC);
 +                      php_pqconn_notify_listeners(conn_obj);
                }
  
                smart_str_free(&cmd);
        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);
                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);
@@@ -1653,30 -1660,31 +1653,30 @@@ ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_start_
  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);
                }
        }
  }
@@@ -1688,30 -1696,31 +1688,30 @@@ ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_start_
  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);
                }
        }
  }
@@@ -1722,11 -1731,11 +1722,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);
                                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;
@@@ -1754,20 -1763,21 +1754,20 @@@ ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_off, 0
  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));
                }
        }
  }
@@@ -1779,42 -1789,48 +1779,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");
 +                      throw_exce(EX_UNINITIALIZED, "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;
  }
@@@ -1827,29 -1843,29 +1827,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);
@@@ -1865,29 -1881,29 +1865,29 @@@ static PHP_METHOD(pqconn, unsetConverte
        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);
@@@ -1931,8 -1947,6 +1931,8 @@@ static zend_function_entry php_pqconn_m
  
  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;
  }
@@@ -1943,162 -1957,144 +1943,162 @@@ 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;
        php_pqconn_object_handlers.get_property_ptr_ptr = NULL;
 -      php_pqconn_object_handlers.get_gc = NULL;
 +      php_pqconn_object_handlers.get_gc = php_pq_object_get_gc;
        php_pqconn_object_handlers.get_properties = php_pq_object_properties;
        php_pqconn_object_handlers.get_debug_info = php_pq_object_debug_info;
  
 -      zend_hash_init(&php_pqconn_object_prophandlers, 20, NULL, NULL, 1);
 +      zend_hash_init(&php_pqconn_object_prophandlers, 22, NULL, php_pq_object_prophandler_dtor, 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_declare_property_long(php_pqconn_class_entry, ZEND_STRL("defaultFetchType"), 0, ZEND_ACC_PUBLIC TSRMLS_CC);
 +      ph.gc = php_pqconn_object_gc_event_handlers;
 +      zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "eventHandlers", sizeof("eventHandlers")-1, (void *) &ph, sizeof(ph));
 +      ph.gc = NULL;
 +
 +      zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("listeners"), ZEND_ACC_PUBLIC);
 +      ph.read = php_pqconn_object_read_listeners;
 +      ph.gc = php_pqconn_object_gc_listeners;
 +      zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "listeners", sizeof("listeners")-1, (void *) &ph, sizeof(ph));
 +      ph.gc = NULL;
 +
 +      zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("converters"), ZEND_ACC_PUBLIC);
 +      ph.read = php_pqconn_object_read_converters;
 +      ph.gc = php_pqconn_object_gc_converters;
 +      zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "converters", sizeof("converters")-1, (void *) &ph, sizeof(ph));
 +      ph.gc = NULL;
 +
 +      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);
 +      zend_declare_property_bool(php_pqconn_class_entry, ZEND_STRL("defaultTransactionDeferrable"), 0, ZEND_ACC_PUBLIC);
        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);
  }
  
  /*
diff --combined src/php_pqcopy.c
index 1a6d37e1d42379463dd59962accfbb1b662d57af,c073798efde10630bdc7b6606a3457d15e02b413..1b3a3aa9212e6daca9eea49faaa8cc578f40ff5f
@@@ -15,7 -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,68 -31,77 +31,68 @@@ zend_class_entry *php_pqcopy_class_entr
  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);
 +      fprintf(stderr, "FREE copy(#%d) %p (conn(#%d): %p)\n", obj->zo.handle, obj, obj->intern->conn->zo.handle, obj->intern->conn);
  #endif
        if (obj->intern) {
                efree(obj->intern->expression);
                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);
 -      efree(obj);
 +      php_pq_object_dtor(o);
  }
  
 -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->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;
 +      return php_pq_object_create(ce, intern, sizeof(php_pqcopy_object_t),
 +                      &php_pqcopy_object_handlers, &php_pqcopy_object_prophandlers);
 +}
  
 -      return o->zv;
 +static zend_object *php_pqcopy_create_object(zend_class_entry *class_type)
 +{
 +      return &php_pqcopy_create_object_ex(class_type, NULL)->zo;
  }
  
 -static zend_object_value php_pqcopy_create_object(zend_class_entry *class_type TSRMLS_DC)
 +static void php_pqcopy_object_read_connection(zval *object, void *o, zval *return_value)
  {
 -      return php_pqcopy_create_object_ex(class_type, NULL, NULL TSRMLS_CC);
 +      php_pqcopy_object_t *obj = o;
 +
 +      php_pq_object_to_zval(obj->intern->conn, return_value);
  }
  
 -static void php_pqcopy_object_read_connection(zval *object, void *o, zval *return_value TSRMLS_DC)
 +static void php_pqcopy_object_gc_connection(zval *object, void *o, zval *return_value)
  {
        php_pqcopy_object_t *obj = o;
 +      zval zconn;
  
 -      php_pq_object_to_zval(obj->intern->conn, &return_value TSRMLS_CC);
 +      php_pq_object_to_zval_no_addref(obj->intern->conn, &zconn);
 +      add_next_index_zval(return_value, &zconn);
  }
  
 -static void php_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)
@@@ -105,21 -114,21 +105,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;
  
                                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 = php_pq_exec(conn_obj->intern->conn, cmd.c);
 +                      res = php_pq_exec(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_pq_clear_res(res);
+                               php_pqres_clear(res);
                        }
  
                        smart_str_free(&cmd);
 -                      php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
 +                      php_pqconn_notify_listeners(obj->intern->conn);
                }
        }
  }
@@@ -170,25 -179,25 +170,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);
                }
        }
  }
@@@ -199,35 -208,35 +199,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_pq_clear_res(res);
+                                       php_pqres_clear(res);
                                }
                        }
  
 -                      php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
 +                      php_pqconn_notify_listeners(obj->intern->conn);
                }
        }
  }
@@@ -240,17 -249,17 +240,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);
 -      rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zdata);
 -      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(), "z", &zdata);
 +      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;
  
                        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_pq_clear_res(res);
+                                       php_pqres_clear(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);
                                }
@@@ -312,42 -320,38 +312,42 @@@ 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;
        php_pqcopy_object_handlers.get_property_ptr_ptr = NULL;
 -      php_pqcopy_object_handlers.get_gc = NULL;
 +      php_pqcopy_object_handlers.get_gc = php_pq_object_get_gc;
        php_pqcopy_object_handlers.get_properties = php_pq_object_properties;
        php_pqcopy_object_handlers.get_debug_info = php_pq_object_debug_info;
  
 -      zend_hash_init(&php_pqcopy_object_prophandlers, 4, NULL, NULL, 1);
 +      zend_hash_init(&php_pqcopy_object_prophandlers, 4, NULL, php_pq_object_prophandler_dtor, 1);
  
 -      zend_declare_property_null(php_pqcopy_class_entry, ZEND_STRL("connection"), ZEND_ACC_PUBLIC 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);
 +      ph.gc = php_pqcopy_object_gc_connection;
 +      zend_hash_str_add_mem(&php_pqcopy_object_prophandlers, "connection", sizeof("connection")-1, (void *) &ph, sizeof(ph));
 +      ph.gc = NULL;
  
 -      zend_declare_property_null(php_pqcopy_class_entry, ZEND_STRL("expression"), ZEND_ACC_PUBLIC 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;
  }
diff --combined src/php_pqcur.c
index 4197cdf4109492774dffafadf2c7ed2fa1423a9c,e24c042915c695ea7626f6510761f45d791dd9eb..682b78aa01d8828bfd8a7823e46692cddc455907
@@@ -15,7 -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 +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;
                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 = php_pq_exec(obj->intern->conn->intern->conn, cmd.c))) {
 +                      if ((res = php_pq_exec(obj->intern->conn->intern->conn, smart_str_v(&cmd)))) {
-                               php_pq_clear_res(res);
+                               php_pqres_clear(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 +65,27 @@@ static void cur_open(INTERNAL_FUNCTION_
        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) {
  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};
  
                        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 = php_pq_exec(obj->intern->conn->intern->conn, cmd.c);
 +                              PGresult *res = php_pq_exec(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);
 +      fprintf(stderr, "FREE cur(#%d) %p (conn: %p)\n", obj->zo.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);
 -      efree(obj);
 +      php_pq_object_dtor(o);
  }
  
 -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->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;
 +      return php_pq_object_create(ce, intern, sizeof(php_pqcur_object_t),
 +                      &php_pqcur_object_handlers, &php_pqcur_object_prophandlers);
 +}
  
 -      return o->zv;
 +static zend_object *php_pqcur_create_object(zend_class_entry *class_type)
 +{
 +      return &php_pqcur_create_object_ex(class_type, NULL)->zo;
  }
  
 -static zend_object_value php_pqcur_create_object(zend_class_entry *class_type TSRMLS_DC)
 +static void php_pqcur_object_read_name(zval *object, void *o, zval *return_value)
  {
 -      return php_pqcur_create_object_ex(class_type, NULL, NULL TSRMLS_CC);
 +      php_pqcur_object_t *obj = o;
 +
 +      RETVAL_STRING(obj->intern->name);
  }
  
 -static void php_pqcur_object_read_name(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;
  
 -      RETVAL_STRING(obj->intern->name, 1);
 +      php_pq_object_to_zval(obj->intern->conn, return_value);
  }
  
 -static void php_pqcur_object_read_connection(zval *object, void *o, zval *return_value TSRMLS_DC)
 +static void php_pqcur_object_gc_connection(zval *object, void *o, zval *return_value)
  {
        php_pqcur_object_t *obj = o;
 +      zval zconn;
  
 -      php_pq_object_to_zval(obj->intern->conn, &return_value TSRMLS_CC);
 +      php_pq_object_to_zval_no_addref(obj->intern->conn, &zconn);
 +      add_next_index_zval(return_value, &zconn);
  }
  
 -static void php_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;
  
@@@ -245,11 -254,11 +245,11 @@@ char *php_pqcur_declare_str(const char 
        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;
@@@ -270,38 -279,38 +270,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);
                        }
                }
        }
@@@ -328,17 -337,17 +328,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);
                }
        }
  }
@@@ -350,17 -359,17 +350,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);
                }
        }
  }
@@@ -402,7 -411,7 +402,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)
@@@ -424,45 -433,41 +424,45 @@@ 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;
        php_pqcur_object_handlers.get_property_ptr_ptr = NULL;
 -      php_pqcur_object_handlers.get_gc = NULL;
 +      php_pqcur_object_handlers.get_gc = php_pq_object_get_gc;
        php_pqcur_object_handlers.get_properties = php_pq_object_properties;
        php_pqcur_object_handlers.get_debug_info = php_pq_object_debug_info;
  
 -      zend_hash_init(&php_pqcur_object_prophandlers, 4, NULL, NULL, 1);
 +      zend_hash_init(&php_pqcur_object_prophandlers, 4, NULL, php_pq_object_prophandler_dtor, 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);
 +      ph.gc = php_pqcur_object_gc_connection;
 +      zend_hash_str_add_mem(&php_pqcur_object_prophandlers, "connection", sizeof("connection")-1, (void *) &ph, sizeof(ph));
 +      ph.gc = NULL;
  
 -      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);
 +      zend_declare_property_null(php_pqcur_class_entry, ZEND_STRL("flags"), ZEND_ACC_PUBLIC);
        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;
  }
diff --combined src/php_pqstm.c
index fbab27e81037f9fe4d0f344b1669493da6086fb3,b82adcfbe96e4f17f144d8a76597f8d6364bb1a2..4eec3b8795fb965f69fe3de915c6c5503f4a2fca
@@@ -15,7 -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 +29,7 @@@ zend_class_entry *php_pqstm_class_entry
  static zend_object_handlers php_pqstm_object_handlers;
  static HashTable php_pqstm_object_prophandlers;
  
 -static void php_pqstm_deallocate(php_pqstm_object_t *obj, zend_bool async, zend_bool silent TSRMLS_DC)
 +static void php_pqstm_deallocate(php_pqstm_object_t *obj, zend_bool async, zend_bool silent)
  {
        if (obj->intern->allocated) {
                char *quoted_name = PQescapeIdentifier(obj->intern->conn->intern->conn, obj->intern->name, strlen(obj->intern->name));
                        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 deallocate statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
 +                                      throw_exce(EX_IO, "Failed to deallocate statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                                }
                        } else {
                                PGresult *res;
  
 -                              if ((res = php_pq_exec(obj->intern->conn->intern->conn, cmd.c))) {
 +                              if ((res = php_pq_exec(obj->intern->conn->intern->conn, smart_str_v(&cmd)))) {
-                                       php_pq_clear_res(res);
+                                       php_pqres_clear(res);
                                } else if (!silent) {
 -                                      throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to deallocate statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
 +                                      throw_exce(EX_RUNTIME, "Failed to deallocate statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                                }
                        }
  
        }
  }
  
 -static void php_pqstm_object_free(void *o TSRMLS_DC)
 +static void php_pqstm_object_free(zend_object *o)
  {
 -      php_pqstm_object_t *obj = o;
 +      php_pqstm_object_t *obj = PHP_PQ_OBJ(NULL, o);
  #if DBG_GC
 -      fprintf(stderr, "FREE stm(#%d) %p (conn(#%d): %p)\n", obj->zv.handle, obj, obj->intern->conn->zv.handle, obj->intern->conn);
 +      fprintf(stderr, "FREE stm(#%d) %p (conn(#%d): %p)\n", obj->zo.handle, obj, obj->intern->conn->zo.handle, obj->intern->conn);
  #endif
        if (obj->intern) {
                if (obj->intern->conn->intern) {
                        php_pq_callback_dtor(&obj->intern->conn->intern->onevent);
 -                      php_pqstm_deallocate(obj, 0, 1 TSRMLS_CC);
 -                      php_pq_object_delref(obj->intern->conn TSRMLS_CC);
 +                      php_pqstm_deallocate(obj, 0, 1);
 +                      php_pq_object_delref(obj->intern->conn);
                }
                efree(obj->intern->name);
                efree(obj->intern->query);
                efree(obj->intern);
                obj->intern = NULL;
        }
 -      zend_object_std_dtor((zend_object *) o TSRMLS_CC);
 -      efree(obj);
 +      php_pq_object_dtor(o);
  }
  
 -zend_object_value php_pqstm_create_object_ex(zend_class_entry *ce, php_pqstm_t *intern, php_pqstm_object_t **ptr TSRMLS_DC)
 +php_pqstm_object_t *php_pqstm_create_object_ex(zend_class_entry *ce, php_pqstm_t *intern)
  {
 -      php_pqstm_object_t *o;
 -
 -      o = ecalloc(1, sizeof(*o));
 -      zend_object_std_init((zend_object *) o, ce TSRMLS_CC);
 -      object_properties_init((zend_object *) o, ce);
 -      o->prophandler = &php_pqstm_object_prophandlers;
 -
 -      if (ptr) {
 -              *ptr = o;
 -      }
 -
 -      if (intern) {
 -              o->intern = intern;
 -      }
 -
 -      o->zv.handle = zend_objects_store_put((zend_object *) o, NULL, php_pqstm_object_free, NULL TSRMLS_CC);
 -      o->zv.handlers = &php_pqstm_object_handlers;
 +      return php_pq_object_create(ce, intern, sizeof(php_pqstm_object_t),
 +                      &php_pqstm_object_handlers, &php_pqstm_object_prophandlers);
 +}
  
 -      return o->zv;
 +static zend_object *php_pqstm_create_object(zend_class_entry *class_type)
 +{
 +      return &php_pqstm_create_object_ex(class_type, NULL)->zo;
  }
  
 -static zend_object_value php_pqstm_create_object(zend_class_entry *class_type TSRMLS_DC)
 +static void php_pqstm_object_read_name(zval *object, void *o, zval *return_value)
  {
 -      return php_pqstm_create_object_ex(class_type, NULL, NULL TSRMLS_CC);
 +      php_pqstm_object_t *obj = o;
 +
 +      RETVAL_STRING(obj->intern->name);
  }
  
 -static void php_pqstm_object_read_name(zval *object, void *o, zval *return_value TSRMLS_DC)
 +static void php_pqstm_object_read_connection(zval *object, void *o, zval *return_value)
  {
        php_pqstm_object_t *obj = o;
  
 -      RETVAL_STRING(obj->intern->name, 1);
 +      php_pq_object_to_zval(obj->intern->conn, return_value);
  }
  
 -static void php_pqstm_object_read_connection(zval *object, void *o, zval *return_value TSRMLS_DC)
 +static void php_pqstm_object_gc_connection(zval *object, void *o, zval *return_value)
  {
        php_pqstm_object_t *obj = o;
 +      zval zconn;
  
 -      php_pq_object_to_zval(obj->intern->conn, &return_value TSRMLS_CC);
 +      php_pq_object_to_zval_no_addref(obj->intern->conn, &zconn);
 +      add_next_index_zval(return_value, &zconn);
  }
  
 -static void php_pqstm_object_read_query(zval *object, void *o, zval *return_value TSRMLS_DC)
 +static void php_pqstm_object_read_query(zval *object, void *o, zval *return_value)
  {
        php_pqstm_object_t *obj = o;
  
 -      RETVAL_STRING(obj->intern->query, 1);
 +      RETVAL_STRING(obj->intern->query);
  }
  
 -static void php_pqstm_object_read_types(zval *object, void *o, zval *return_value TSRMLS_DC)
 +static void php_pqstm_object_read_types(zval *object, void *o, zval *return_value)
  {
        int i;
        php_pqstm_object_t *obj = o;
        }
  }
  
 -php_pqstm_t *php_pqstm_init(php_pqconn_object_t *conn, const char *name, const char *query, php_pq_params_t *params TSRMLS_DC)
 +php_pqstm_t *php_pqstm_init(php_pqconn_object_t *conn, const char *name, const char *query, php_pq_params_t *params)
  {
        php_pqstm_t *stm = ecalloc(1, sizeof(*stm));
  
 -      php_pq_object_addref(conn TSRMLS_CC);
 +      php_pq_object_addref(conn);
        stm->conn = conn;
        stm->name = estrdup(name);
        stm->params = params;
@@@ -169,33 -178,33 +169,33 @@@ static PHP_METHOD(pqstm, __construct) 
        zend_error_handling zeh;
        zval *zconn, *ztypes = NULL;
        char *name_str, *query_str;
 -      int name_len, *query_len;
 +      size_t name_len, *query_len;
        zend_bool async = 0;
        ZEND_RESULT_CODE rv;
  
 -      zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
 -      rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Oss|a/!b", &zconn, php_pqconn_class_entry, &name_str, &name_len, &query_str, &query_len, &ztypes, &async);
 -      zend_restore_error_handling(&zeh TSRMLS_CC);
 +      zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
 +      rv = zend_parse_parameters(ZEND_NUM_ARGS(), "Oss|a/!b", &zconn, php_pqconn_class_entry, &name_str, &name_len, &query_str, &query_len, &ztypes, &async);
 +      zend_restore_error_handling(&zeh);
  
        if (SUCCESS == rv) {
 -              php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 -              php_pqconn_object_t *conn_obj = zend_object_store_get_object(zconn TSRMLS_CC);
 +              php_pqstm_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
 +              php_pqconn_object_t *conn_obj = PHP_PQ_OBJ(zconn, NULL);
  
                if (obj->intern) {
 -                      throw_exce(EX_BAD_METHODCALL TSRMLS_CC, "pq\\Statement already initialized");
 +                      throw_exce(EX_BAD_METHODCALL, "pq\\Statement already initialized");
                } else if (!conn_obj->intern) {
 -                      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(&conn_obj->intern->converters, ztypes ? Z_ARRVAL_P(ztypes) : NULL, NULL TSRMLS_CC);
 +                      php_pq_params_t *params = php_pq_params_init(&conn_obj->intern->converters, ztypes ? Z_ARRVAL_P(ztypes) : NULL, NULL);
  
                        if (async) {
 -                              rv = php_pqconn_prepare_async(zconn, conn_obj, name_str, query_str, params TSRMLS_CC);
 +                              rv = php_pqconn_prepare_async(zconn, conn_obj, name_str, query_str, params);
                        } else {
 -                              rv = php_pqconn_prepare(zconn, conn_obj, name_str, query_str, params TSRMLS_CC);
 +                              rv = php_pqconn_prepare(zconn, conn_obj, name_str, query_str, params);
                        }
  
                        if (SUCCESS == rv) {
 -                              obj->intern = php_pqstm_init(conn_obj, name_str, query_str, params TSRMLS_CC);
 +                              obj->intern = php_pqstm_init(conn_obj, name_str, query_str, params);
                        }
                }
        }
@@@ -205,26 -214,27 +205,26 @@@ ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_bind, 0
        ZEND_ARG_INFO(1, param_ref)
  ZEND_END_ARG_INFO();
  static PHP_METHOD(pqstm, bind) {
 -      long param_no;
 -      zval **param_ref;
 +      zend_long param_no;
 +      zval *param_ref;
        zend_error_handling zeh;
        ZEND_RESULT_CODE rv;
  
 -      zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
 -      rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lZ", &param_no, &param_ref);
 -      zend_restore_error_handling(&zeh TSRMLS_CC);
 +      zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
 +      rv = zend_parse_parameters(ZEND_NUM_ARGS(), "lz", &param_no, &param_ref);
 +      zend_restore_error_handling(&zeh);
  
        if (SUCCESS == rv) {
 -              php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 +              php_pqstm_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
  
                if (!obj->intern) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Statement not initialized");
                } else if (!obj->intern->allocated) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement has been deallocated");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Statement has been deallocated");
                } else {
 -                      SEPARATE_ZVAL_TO_MAKE_IS_REF(param_ref);
 -                      Z_ADDREF_PP(param_ref);
 -                      zend_hash_index_update(&obj->intern->bound, param_no, (void *) param_ref, sizeof(zval *), NULL);
 -                      zend_hash_sort(&obj->intern->bound, zend_qsort, php_pq_compare_index, 0 TSRMLS_CC);
 +                      Z_ADDREF_P(param_ref);
 +                      zend_hash_index_update(&obj->intern->bound, param_no, param_ref);
 +                      zend_hash_sort(&obj->intern->bound, php_pq_compare_index, 0);
                }
        }
  }
@@@ -237,17 -247,17 +237,17 @@@ static PHP_METHOD(pqstm, exec) 
        zval *zparams = NULL;
        ZEND_RESULT_CODE rv;
  
 -      zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
 -      rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a/!", &zparams);
 -      zend_restore_error_handling(&zeh TSRMLS_CC);
 +      zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
 +      rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|a/!", &zparams);
 +      zend_restore_error_handling(&zeh);
  
        if (SUCCESS == rv) {
 -              php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 +              php_pqstm_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
  
                if (!obj->intern) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Statement not initialized");
                } else if (!obj->intern->allocated) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement has been deallocated");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Statement has been deallocated");
                } else {
                        PGresult *res;
  
                        php_pq_params_set_params(obj->intern->params, NULL);
  
                        if (!res) {
 -                              throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to execute statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
 -                      } else if (SUCCESS == php_pqres_success(res TSRMLS_CC)) {
 -                              php_pq_object_to_zval_no_addref(PQresultInstanceData(res, php_pqconn_event), &return_value TSRMLS_CC);
 -                              php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
 +                              throw_exce(EX_RUNTIME, "Failed to execute statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
 +                      } else if (SUCCESS == php_pqres_success(res)) {
 +                              php_pq_object_to_zval_no_addref(PQresultInstanceData(res, php_pqconn_event), return_value);
 +                              php_pqconn_notify_listeners(obj->intern->conn);
                        }
                }
        }
@@@ -275,17 -285,17 +275,17 @@@ static PHP_METHOD(pqstm, execAsync) 
        php_pq_callback_t resolver = {{0}};
        ZEND_RESULT_CODE rv;
  
 -      zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
 -      rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a/!f", &zparams, &resolver.fci, &resolver.fcc);
 -      zend_restore_error_handling(&zeh TSRMLS_CC);
 +      zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
 +      rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|a/!f", &zparams, &resolver.fci, &resolver.fcc);
 +      zend_restore_error_handling(&zeh);
  
        if (SUCCESS == rv) {
 -              php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 +              php_pqstm_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
  
                if (!obj->intern) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Statement not initialized");
                } else if (!obj->intern->allocated) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement has been deallocated");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Statement has been deallocated");
                } else {
                        int rc;
  
                        php_pq_params_set_params(obj->intern->params, NULL);
  
                        if (!rc) {
 -                              throw_exce(EX_IO TSRMLS_CC, "Failed to execute statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
 +                              throw_exce(EX_IO, "Failed to execute statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
  #if HAVE_PQSETSINGLEROWMODE
                        } else if (obj->intern->conn->intern->unbuffered && !PQsetSingleRowMode(obj->intern->conn->intern->conn)) {
 -                              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;
                        }
  
 -                      php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
 +                      php_pqconn_notify_listeners(obj->intern->conn);
                }
        }
  }
@@@ -315,24 -325,24 +315,24 @@@ static PHP_METHOD(pqstm, desc) 
        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_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 +              php_pqstm_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
  
                if (!obj->intern) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Statement not initialized");
                } else if (!obj->intern->allocated) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement has been deallocated");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Statement has been deallocated");
                } else {
                        PGresult *res = PQdescribePrepared(obj->intern->conn->intern->conn, obj->intern->name);
  
                        if (!res) {
 -                              throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to describe statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
 +                              throw_exce(EX_RUNTIME, "Failed to describe statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                        } else {
 -                              if (SUCCESS == php_pqres_success(res TSRMLS_CC)) {
 +                              if (SUCCESS == php_pqres_success(res)) {
                                        int p, params;
  
                                        array_init(return_value);
                                                add_next_index_long(return_value, PQparamtype(res, p));
                                        }
                                }
-                               php_pq_clear_res(res);
+                               php_pqres_clear(res);
 -                              php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
 +                              php_pqconn_notify_listeners(obj->intern->conn);
                        }
                }
        }
@@@ -355,23 -365,23 +355,23 @@@ static PHP_METHOD(pqstm, descAsync) 
        php_pq_callback_t resolver = {{0}};
        ZEND_RESULT_CODE rv;
  
 -      zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
 -      rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f", &resolver.fci, &resolver.fcc);
 -      zend_restore_error_handling(&zeh TSRMLS_CC);
 +      zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
 +      rv = zend_parse_parameters(ZEND_NUM_ARGS(), "f", &resolver.fci, &resolver.fcc);
 +      zend_restore_error_handling(&zeh);
  
        if (SUCCESS == rv) {
 -              php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 +              php_pqstm_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
  
                if (!obj->intern) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Statement not initialized");
                } else if (!obj->intern->allocated) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement has been deallocated");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Statement has been deallocated");
                } else if (!PQsendDescribePrepared(obj->intern->conn->intern->conn, obj->intern->name)) {
 -                      throw_exce(EX_IO TSRMLS_CC, "Failed to describe statement: %s", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
 +                      throw_exce(EX_IO, "Failed to describe statement: %s", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                } else {
 -                      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;
 -                      php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
 +                      php_pqconn_notify_listeners(obj->intern->conn);
                }
        }
  }
@@@ -381,17 -391,17 +381,17 @@@ static zend_always_inline void php_pqst
        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_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 +              php_pqstm_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
  
                if (!obj->intern) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Statement not initialized");
                } else {
 -                      php_pqstm_deallocate(obj, async, 0 TSRMLS_CC);
 +                      php_pqstm_deallocate(obj, async, 0);
                }
        }
  }
@@@ -415,20 -425,20 +415,20 @@@ static zend_always_inline void php_pqst
        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_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 +              php_pqstm_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
  
                if (!obj->intern) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Statement not initialized");
                } else if (!obj->intern->allocated) {
                        if (async) {
 -                              rv = php_pqconn_prepare_async(NULL, obj->intern->conn, obj->intern->name, obj->intern->query, obj->intern->params TSRMLS_CC);
 +                              rv = php_pqconn_prepare_async(NULL, obj->intern->conn, obj->intern->name, obj->intern->query, obj->intern->params);
                        } else {
 -                              rv = php_pqconn_prepare(NULL, obj->intern->conn, obj->intern->name, obj->intern->query, obj->intern->params TSRMLS_CC);
 +                              rv = php_pqconn_prepare(NULL, obj->intern->conn, obj->intern->name, obj->intern->query, obj->intern->params);
                        }
  
                        if (SUCCESS == rv) {
@@@ -478,39 -488,35 +478,39 @@@ PHP_MINIT_FUNCTION(pqstm
        php_pq_object_prophandler_t ph = {0};
  
        INIT_NS_CLASS_ENTRY(ce, "pq", "Statement", php_pqstm_methods);
 -      php_pqstm_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
 +      php_pqstm_class_entry = zend_register_internal_class_ex(&ce, NULL);
        php_pqstm_class_entry->create_object = php_pqstm_create_object;
  
        memcpy(&php_pqstm_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
 +      php_pqstm_object_handlers.offset = XtOffsetOf(php_pqstm_object_t, zo);
 +      php_pqstm_object_handlers.free_obj = php_pqstm_object_free;
        php_pqstm_object_handlers.read_property = php_pq_object_read_prop;
        php_pqstm_object_handlers.write_property = php_pq_object_write_prop;
        php_pqstm_object_handlers.clone_obj = NULL;
        php_pqstm_object_handlers.get_property_ptr_ptr = NULL;
 -      php_pqstm_object_handlers.get_gc = NULL;
 +      php_pqstm_object_handlers.get_gc = php_pq_object_get_gc;
        php_pqstm_object_handlers.get_properties = php_pq_object_properties;
        php_pqstm_object_handlers.get_debug_info = php_pq_object_debug_info;
  
 -      zend_hash_init(&php_pqstm_object_prophandlers, 2, NULL, NULL, 1);
 +      zend_hash_init(&php_pqstm_object_prophandlers, 4, NULL, php_pq_object_prophandler_dtor, 1);
  
 -      zend_declare_property_null(php_pqstm_class_entry, ZEND_STRL("name"), ZEND_ACC_PUBLIC TSRMLS_CC);
 +      zend_declare_property_null(php_pqstm_class_entry, ZEND_STRL("name"), ZEND_ACC_PUBLIC);
        ph.read = php_pqstm_object_read_name;
 -      zend_hash_add(&php_pqstm_object_prophandlers, "name", sizeof("name"), (void *) &ph, sizeof(ph), NULL);
 +      zend_hash_str_add_mem(&php_pqstm_object_prophandlers, "name", sizeof("name")-1, (void *) &ph, sizeof(ph));
  
 -      zend_declare_property_null(php_pqstm_class_entry, ZEND_STRL("connection"), ZEND_ACC_PUBLIC TSRMLS_CC);
 +      zend_declare_property_null(php_pqstm_class_entry, ZEND_STRL("connection"), ZEND_ACC_PUBLIC);
        ph.read = php_pqstm_object_read_connection;
 -      zend_hash_add(&php_pqstm_object_prophandlers, "connection", sizeof("connection"), (void *) &ph, sizeof(ph), NULL);
 +      ph.gc = php_pqstm_object_gc_connection;
 +      zend_hash_str_add_mem(&php_pqstm_object_prophandlers, "connection", sizeof("connection")-1, (void *) &ph, sizeof(ph));
 +      ph.gc = NULL;
  
 -      zend_declare_property_null(php_pqstm_class_entry, ZEND_STRL("query"), ZEND_ACC_PUBLIC TSRMLS_CC);
 +      zend_declare_property_null(php_pqstm_class_entry, ZEND_STRL("query"), ZEND_ACC_PUBLIC);
        ph.read = php_pqstm_object_read_query;
 -      zend_hash_add(&php_pqstm_object_prophandlers, "query", sizeof("query"), (void *) &ph, sizeof(ph), NULL);
 +      zend_hash_str_add_mem(&php_pqstm_object_prophandlers, "query", sizeof("query")-1, (void *) &ph, sizeof(ph));
  
 -      zend_declare_property_null(php_pqstm_class_entry, ZEND_STRL("types"), ZEND_ACC_PUBLIC TSRMLS_CC);
 +      zend_declare_property_null(php_pqstm_class_entry, ZEND_STRL("types"), ZEND_ACC_PUBLIC);
        ph.read = php_pqstm_object_read_types;
 -      zend_hash_add(&php_pqstm_object_prophandlers, "types", sizeof("types"), (void *) &ph, sizeof(ph), NULL);
 +      zend_hash_str_add_mem(&php_pqstm_object_prophandlers, "types", sizeof("types")-1, (void *) &ph, sizeof(ph));
  
        return SUCCESS;
  }
diff --combined src/php_pqtxn.c
index 7b57ebf1e843c44e3312abbf4243f642f5f73bd7,e90a2d8738313c6e4214eb808ab5c948c7d36d1b..9a97a8f9567a8ca390359c901e5f142cda145f80
@@@ -15,7 -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>
  #include <libpq/libpq-fs.h>
@@@ -47,82 -47,104 +47,82 @@@ const char *php_pq_isolation_level(lon
        }
  }
  
 -static void php_pqtxn_object_free(void *o TSRMLS_DC)
 +static void php_pqtxn_object_free(zend_object *o)
  {
 -      php_pqtxn_object_t *obj = o;
 +      php_pqtxn_object_t *obj = PHP_PQ_OBJ(NULL, o);
  #if DBG_GC
 -      fprintf(stderr, "FREE txn(#%d) %p (conn(#%d): %p)\n", obj->zv.handle, obj, obj->intern->conn->zv.handle, obj->intern->conn);
 +      fprintf(stderr, "FREE txn(#%d) %p (conn(#%d): %p)\n", obj->zo.handle, obj, obj->intern->conn->zo.handle, obj->intern->conn);
  #endif
        if (obj->intern) {
                if (obj->intern->open && obj->intern->conn->intern) {
                        PGresult *res = php_pq_exec(obj->intern->conn->intern->conn, "ROLLBACK");
  
                        if (res) {
-                               php_pq_clear_res(res);
+                               php_pqres_clear(res);
                        }
                }
 -              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);
 -      efree(obj);
 +      php_pq_object_dtor(o);
  }
  
 -zend_object_value php_pqtxn_create_object_ex(zend_class_entry *ce, php_pqtxn_t *intern, php_pqtxn_object_t **ptr TSRMLS_DC)
 +php_pqtxn_object_t *php_pqtxn_create_object_ex(zend_class_entry *ce, php_pqtxn_t *intern)
  {
 -      php_pqtxn_object_t *o;
 -
 -      o = ecalloc(1, sizeof(*o));
 -      zend_object_std_init((zend_object *) o, ce TSRMLS_CC);
 -      object_properties_init((zend_object *) o, ce);
 -      o->prophandler = &php_pqtxn_object_prophandlers;
 -
 -      if (ptr) {
 -              *ptr = o;
 -      }
 -
 -      if (intern) {
 -              o->intern = intern;
 -      }
 -
 -      o->zv.handle = zend_objects_store_put((zend_object *) o, NULL, php_pqtxn_object_free, NULL TSRMLS_CC);
 -      o->zv.handlers = &php_pqtxn_object_handlers;
 +      return php_pq_object_create(ce, intern, sizeof(php_pqtxn_object_t),
 +                      &php_pqtxn_object_handlers, &php_pqtxn_object_prophandlers);
 +}
  
 -      return o->zv;
 +static zend_object *php_pqtxn_create_object(zend_class_entry *class_type)
 +{
 +      return &php_pqtxn_create_object_ex(class_type, NULL)->zo;
  }
  
 -static zend_object_value php_pqtxn_create_object(zend_class_entry *class_type TSRMLS_DC)
 +static void php_pqtxn_object_read_connection(zval *object, void *o, zval *return_value)
  {
 -      return php_pqtxn_create_object_ex(class_type, NULL, NULL TSRMLS_CC);
 +      php_pqtxn_object_t *obj = o;
 +
 +      php_pq_object_to_zval(obj->intern->conn, return_value);
  }
  
 -static void php_pqtxn_object_read_connection(zval *object, void *o, zval *return_value TSRMLS_DC)
 +static void php_pqtxn_object_gc_connection(zval *object, void *o, zval *return_value)
  {
        php_pqtxn_object_t *obj = o;
 +      zval zconn;
  
 -      php_pq_object_to_zval(obj->intern->conn, &return_value TSRMLS_CC);
 +      php_pq_object_to_zval_no_addref(obj->intern->conn, &zconn);
 +      add_next_index_zval(return_value, &zconn);
  }
  
 -static void php_pqtxn_object_read_isolation(zval *object, void *o, zval *return_value TSRMLS_DC)
 +static void php_pqtxn_object_read_isolation(zval *object, void *o, zval *return_value)
  {
        php_pqtxn_object_t *obj = o;
  
        RETVAL_LONG(obj->intern->isolation);
  }
  
 -static void php_pqtxn_object_read_readonly(zval *object, void *o, zval *return_value TSRMLS_DC)
 +static void php_pqtxn_object_read_readonly(zval *object, void *o, zval *return_value)
  {
        php_pqtxn_object_t *obj = o;
  
        RETVAL_BOOL(obj->intern->readonly);
  }
  
 -static void php_pqtxn_object_read_deferrable(zval *object, void *o, zval *return_value TSRMLS_DC)
 +static void php_pqtxn_object_read_deferrable(zval *object, void *o, zval *return_value)
  {
        php_pqtxn_object_t *obj = o;
  
        RETVAL_BOOL(obj->intern->deferrable);
  }
  
 -static void php_pqtxn_object_write_isolation(zval *object, void *o, zval *value TSRMLS_DC)
 +static void php_pqtxn_object_write_isolation(zval *object, void *o, zval *value)
  {
        php_pqtxn_object_t *obj = o;
        php_pqtxn_isolation_t orig = obj->intern->isolation;
 -      zval *zisolation = value;
        PGresult *res;
  
 -      if (Z_TYPE_P(zisolation) != IS_LONG) {
 -              if (Z_REFCOUNT_P(value) > 1) {
 -                      zval *tmp;
 -                      MAKE_STD_ZVAL(tmp);
 -                      ZVAL_ZVAL(tmp, zisolation, 1, 0);
 -                      convert_to_long(tmp);
 -                      zisolation = tmp;
 -              } else {
 -                      convert_to_long_ex(&zisolation);
 -              }
 -      }
 -
 -      switch ((obj->intern->isolation = Z_LVAL_P(zisolation))) {
 +      switch ((obj->intern->isolation = zval_get_long(value))) {
        case PHP_PQTXN_READ_COMMITTED:
                res = php_pq_exec(obj->intern->conn->intern->conn, "SET TRANSACTION ISOLATION LEVEL READ COMMITED");
                break;
                break;
        }
  
 -      if (zisolation != value) {
 -              zval_ptr_dtor(&zisolation);
 -      }
 -
        if (res) {
 -              php_pqres_success(res TSRMLS_CC);
 +              php_pqres_success(res);
-               php_pq_clear_res(res);
+               php_pqres_clear(res);
        }
  }
  
 -static void php_pqtxn_object_write_readonly(zval *object, void *o, zval *value TSRMLS_DC)
 +static void php_pqtxn_object_write_readonly(zval *object, void *o, zval *value)
  {
        php_pqtxn_object_t *obj = o;
        PGresult *res;
        }
  
        if (res) {
 -              php_pqres_success(res TSRMLS_CC);
 +              php_pqres_success(res);
-               php_pq_clear_res(res);
+               php_pqres_clear(res);
        }
  }
  
 -static void php_pqtxn_object_write_deferrable(zval *object, void *o, zval *value TSRMLS_DC)
 +static void php_pqtxn_object_write_deferrable(zval *object, void *o, zval *value)
  {
        php_pqtxn_object_t *obj = o;
        PGresult *res;
        }
  
        if (res) {
 -              php_pqres_success(res TSRMLS_CC);
 +              php_pqres_success(res);
-               php_pq_clear_res(res);
+               php_pqres_clear(res);
        }
  }
  
@@@ -189,19 -215,19 +189,19 @@@ ZEND_END_ARG_INFO()
  static PHP_METHOD(pqtxn, __construct) {
        zend_error_handling zeh;
        zval *zconn;
 -      long isolation = PHP_PQTXN_READ_COMMITTED;
 +      zend_long isolation = PHP_PQTXN_READ_COMMITTED;
        zend_bool async = 0, readonly = 0, 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, "O|blbb", &zconn, php_pqconn_class_entry, &async, &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(), "O|blbb", &zconn, php_pqconn_class_entry, &async, &isolation, &readonly, &deferrable);
 +      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 {
  
                        switch (ZEND_NUM_ARGS()) {
                        }
  
                        if (async) {
 -                              rv = php_pqconn_start_transaction_async(zconn, conn_obj, isolation, readonly, deferrable TSRMLS_CC);
 +                              rv = php_pqconn_start_transaction_async(zconn, conn_obj, isolation, readonly, deferrable);
                        } else {
 -                              rv = php_pqconn_start_transaction(zconn, conn_obj, isolation, readonly, deferrable TSRMLS_CC);
 +                              rv = php_pqconn_start_transaction(zconn, conn_obj, isolation, readonly, deferrable);
                        }
  
                        if (SUCCESS == rv) {
 -                              php_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 +                              php_pqtxn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
  
                                obj->intern = ecalloc(1, sizeof(*obj->intern));
  
 -                              php_pq_object_addref(conn_obj TSRMLS_CC);
 +                              php_pq_object_addref(conn_obj);
                                obj->intern->conn = conn_obj;
                                obj->intern->open = 1;
                                obj->intern->isolation = isolation;
@@@ -245,17 -271,17 +245,17 @@@ static PHP_METHOD(pqtxn, savepoint) 
        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_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 +              php_pqtxn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
  
                if (!obj->intern) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Transaction not initialized");
                } else if (!obj->intern->open) {
 -                      throw_exce(EX_RUNTIME TSRMLS_CC, "pq\\Transaction already closed");
 +                      throw_exce(EX_RUNTIME, "pq\\Transaction already closed");
                } else {
                        PGresult *res;
                        smart_str cmd = {0};
                        smart_str_appends(&cmd, "\"");
                        smart_str_0(&cmd);
  
 -                      res = php_pq_exec(obj->intern->conn->intern->conn, cmd.c);
 +                      res = php_pq_exec(obj->intern->conn->intern->conn, smart_str_v(&cmd));
  
                        if (!res) {
 -                              throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to create %s (%s)", cmd.c, PHP_PQerrorMessage(obj->intern->conn->intern->conn));
 +                              throw_exce(EX_RUNTIME, "Failed to create %s (%s)", smart_str_v(&cmd), PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                        } else {
 -                              php_pqres_success(res TSRMLS_CC);
 +                              php_pqres_success(res);
-                               php_pq_clear_res(res);
+                               php_pqres_clear(res);
                        }
  
                        smart_str_free(&cmd);
@@@ -285,17 -311,17 +285,17 @@@ static PHP_METHOD(pqtxn, savepointAsync
        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_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 +              php_pqtxn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
  
                if (!obj->intern) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Transaction not initialized");
                } else if (!obj->intern->open) {
 -                      throw_exce(EX_RUNTIME TSRMLS_CC, "pq\\Transaction already closed");
 +                      throw_exce(EX_RUNTIME, "pq\\Transaction already closed");
                } else {
                        smart_str cmd = {0};
  
                        smart_str_appends(&cmd, "\"");
                        smart_str_0(&cmd);
  
 -                      if (!PQsendQuery(obj->intern->conn->intern->conn, cmd.c)) {
 -                              throw_exce(EX_IO TSRMLS_CC, "Failed to create %s (%s)", cmd.c, PHP_PQerrorMessage(obj->intern->conn->intern->conn));
 +                      if (!PQsendQuery(obj->intern->conn->intern->conn, smart_str_v(&cmd))) {
 +                              throw_exce(EX_IO, "Failed to create %s (%s)", smart_str_v(&cmd), PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                        }
  
                        smart_str_free(&cmd);
@@@ -319,23 -345,22 +319,23 @@@ static PHP_METHOD(pqtxn, commit) 
        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_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 +              php_pqtxn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
  
                if (!obj->intern) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transacation not initialized");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Transacation not initialized");
                } else if (!obj->intern->open) {
 -                      throw_exce(EX_RUNTIME TSRMLS_CC, "pq\\Transaction already closed");
 +                      throw_exce(EX_RUNTIME, "pq\\Transaction already closed");
                } else {
                        PGresult *res;
                        smart_str cmd = {0};
 +                      zend_bool just_release_sp = !!obj->intern->savepoint;
  
 -                      if (!obj->intern->savepoint) {
 +                      if (!just_release_sp) {
                                res = php_pq_exec(obj->intern->conn->intern->conn, "COMMIT");
                        } else {
                                smart_str_appends(&cmd, "RELEASE SAVEPOINT \"");
                                smart_str_appends(&cmd, "\"");
                                smart_str_0(&cmd);
  
 -                              res = php_pq_exec(obj->intern->conn->intern->conn, cmd.c);
 +                              res = php_pq_exec(obj->intern->conn->intern->conn, smart_str_v(&cmd));
                        }
  
                        if (!res) {
 -                              throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to %s (%s)", cmd.c ? cmd.c : "commit transaction", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
 +                              throw_exce(EX_RUNTIME, "Failed to %s (%s)", smart_str_l(&cmd) ? smart_str_v(&cmd) : "commit transaction", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                        } else {
 -                              if (SUCCESS == php_pqres_success(res TSRMLS_CC)) {
 -                                      if (!cmd.c) {
 +                              if (SUCCESS == php_pqres_success(res)) {
 +                                      if (!just_release_sp) {
                                                obj->intern->open = 0;
                                        }
                                }
-                               php_pq_clear_res(res);
+                               php_pqres_clear(res);
                        }
  
                        smart_str_free(&cmd);
 -                      php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
 +                      php_pqconn_notify_listeners(obj->intern->conn);
                }
        }
  }
@@@ -369,23 -394,22 +369,23 @@@ static PHP_METHOD(pqtxn, commitAsync) 
        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_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 +              php_pqtxn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
  
                if (!obj->intern) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Transaction not initialized");
                } else if (!obj->intern->open) {
 -                      throw_exce(EX_RUNTIME TSRMLS_CC, "pq\\Transaction already closed");
 +                      throw_exce(EX_RUNTIME, "pq\\Transaction already closed");
                } else {
                        int rc;
                        smart_str cmd = {0};
 +                      zend_bool just_release_sp = !!obj->intern->savepoint;
  
 -                      if (!obj->intern->savepoint) {
 +                      if (!just_release_sp) {
                                rc = PQsendQuery(obj->intern->conn->intern->conn, "COMMIT");
                        } else {
                                smart_str_appends(&cmd, "RELEASE SAVEPOINT \"");
                                smart_str_appends(&cmd, "\"");
                                smart_str_0(&cmd);
  
 -                              rc = PQsendQuery(obj->intern->conn->intern->conn, cmd.c);
 +                              rc = PQsendQuery(obj->intern->conn->intern->conn, smart_str_v(&cmd));
                        }
  
                        if (!rc) {
 -                              throw_exce(EX_IO TSRMLS_CC, "Failed to %s (%s)", cmd.c ? cmd.c : "commmit transaction", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
 +                              throw_exce(EX_IO, "Failed to %s (%s)", smart_str_l(&cmd) ? smart_str_v(&cmd) : "commmit transaction", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                        } else {
 -                              if (!cmd.c) {
 +                              if (!just_release_sp) {
                                        obj->intern->open = 0;
                                }
                                obj->intern->conn->intern->poller = PQconsumeInput;
 -                              php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
 +                              php_pqconn_notify_listeners(obj->intern->conn);
                        }
  
                        smart_str_free(&cmd);
@@@ -417,23 -441,22 +417,23 @@@ static PHP_METHOD(pqtxn, rollback) 
        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_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 +              php_pqtxn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
  
                if (!obj->intern) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Transaction not initialized");
                } else if (!obj->intern->open) {
 -                      throw_exce(EX_RUNTIME TSRMLS_CC, "pq\\Transaction already closed");
 +                      throw_exce(EX_RUNTIME, "pq\\Transaction already closed");
                } else {
                        PGresult *res;
                        smart_str cmd = {0};
 +                      zend_bool just_release_sp = !!obj->intern->savepoint;
  
 -                      if (!obj->intern->savepoint) {
 +                      if (!just_release_sp) {
                                res = php_pq_exec(obj->intern->conn->intern->conn, "ROLLBACK");
                        } else {
                                smart_str_appends(&cmd, "ROLLBACK TO SAVEPOINT \"");
                                smart_str_appends(&cmd, "\"");
                                smart_str_0(&cmd);
  
 -                              res = php_pq_exec(obj->intern->conn->intern->conn, cmd.c);
 +                              res = php_pq_exec(obj->intern->conn->intern->conn, smart_str_v(&cmd));
                        }
  
                        if (!res) {
 -                              throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to %s (%s)", cmd.c ? cmd.c : "rollback transaction", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
 +                              throw_exce(EX_RUNTIME, "Failed to %s (%s)", smart_str_l(&cmd) ? smart_str_v(&cmd) : "rollback transaction", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                        } else {
 -                              if (SUCCESS == php_pqres_success(res TSRMLS_CC)) {
 -                                      if (!cmd.c) {
 +                              if (SUCCESS == php_pqres_success(res)) {
 +                                      if (!just_release_sp) {
                                                obj->intern->open = 0;
                                        }
                                }
-                               php_pq_clear_res(res);
+                               php_pqres_clear(res);
                        }
  
                        smart_str_free(&cmd);
 -                      php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
 +                      php_pqconn_notify_listeners(obj->intern->conn);
                }
        }
  }
@@@ -467,23 -490,22 +467,23 @@@ static PHP_METHOD(pqtxn, rollbackAsync
        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_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 +              php_pqtxn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
  
                if (!obj->intern) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Transaction not initialized");
                } else if (!obj->intern->open) {
 -                      throw_exce(EX_RUNTIME TSRMLS_CC, "pq\\Transaction already closed");
 +                      throw_exce(EX_RUNTIME, "pq\\Transaction already closed");
                } else {
                        int rc;
                        smart_str cmd = {0};
 +                      zend_bool just_release_sp = !!obj->intern->savepoint;
  
 -                      if (!obj->intern->savepoint) {
 +                      if (!just_release_sp) {
                                rc = PQsendQuery(obj->intern->conn->intern->conn, "ROLLBACK");
                        } else {
                                smart_str_appends(&cmd, "ROLLBACK TO SAVEPOINT \"");
                                smart_str_appends(&cmd, "\"");
                                smart_str_0(&cmd);
  
 -                              rc = PQsendQuery(obj->intern->conn->intern->conn, cmd.c);
 +                              rc = PQsendQuery(obj->intern->conn->intern->conn, smart_str_v(&cmd));
                        }
  
                        if (!rc) {
 -                              throw_exce(EX_IO TSRMLS_CC, "Failed to %s (%s)", cmd.c ? cmd.c : "rollback transaction", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
 +                              throw_exce(EX_IO, "Failed to %s (%s)", smart_str_l(&cmd) ? smart_str_v(&cmd) : "rollback transaction", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                        } else {
 -                              if (!cmd.c) {
 +                              if (!just_release_sp) {
                                        obj->intern->open = 0;
                                }
                                obj->intern->conn->intern->poller = PQconsumeInput;
                        }
  
                        smart_str_free(&cmd);
 -                      php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
 +                      php_pqconn_notify_listeners(obj->intern->conn);
                }
        }
  }
@@@ -515,29 -537,29 +515,29 @@@ static PHP_METHOD(pqtxn, exportSnapshot
        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_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 +              php_pqtxn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
  
                if (!obj->intern) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Transaction not initialized");
                } else {
                        PGresult *res = php_pq_exec(obj->intern->conn->intern->conn, "SELECT pg_export_snapshot()");
  
                        if (!res) {
 -                              throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to export transaction snapshot (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
 +                              throw_exce(EX_RUNTIME, "Failed to export transaction snapshot (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                        } else {
 -                              if (SUCCESS == php_pqres_success(res TSRMLS_CC)) {
 -                                      RETVAL_STRING(PQgetvalue(res, 0, 0), 1);
 +                              if (SUCCESS == php_pqres_success(res)) {
 +                                      RETVAL_STRING(PQgetvalue(res, 0, 0));
                                }
  
-                               php_pq_clear_res(res);
+                               php_pqres_clear(res);
                        }
  
 -                      php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
 +                      php_pqconn_notify_listeners(obj->intern->conn);
                }
        }
  }
@@@ -548,20 -570,20 +548,20 @@@ static PHP_METHOD(pqtxn, exportSnapshot
        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_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 +              php_pqtxn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
  
                if (!obj->intern) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Transaction not initialized");
                } else if (!PQsendQuery(obj->intern->conn->intern->conn, "SELECT pg_export_snapshot()")) {
 -                      throw_exce(EX_IO TSRMLS_CC, "Failed to export transaction snapshot (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
 +                      throw_exce(EX_IO, "Failed to export transaction snapshot (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                } else {
                        obj->intern->conn->intern->poller = PQconsumeInput;
 -                      php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
 +                      php_pqconn_notify_listeners(obj->intern->conn);
                }
        }
  }
@@@ -572,25 -594,25 +572,25 @@@ ZEND_END_ARG_INFO()
  static PHP_METHOD(pqtxn, importSnapshot) {
        zend_error_handling zeh;
        char *snapshot_str;
 -      int snapshot_len;
 +      size_t snapshot_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", &snapshot_str, &snapshot_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", &snapshot_str, &snapshot_len);
 +      zend_restore_error_handling(&zeh);
  
        if (SUCCESS == rv) {
 -              php_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 +              php_pqtxn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
  
                if (!obj->intern) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Transaction not initialized");
                } else if (obj->intern->isolation < PHP_PQTXN_REPEATABLE_READ) {
 -                      throw_exce(EX_RUNTIME TSRMLS_CC, "pq\\Transaction must have at least isolation level REPEATABLE READ to be able to import a snapshot");
 +                      throw_exce(EX_RUNTIME, "pq\\Transaction must have at least isolation level REPEATABLE READ to be able to import a snapshot");
                } else {
                        char *sid = PQescapeLiteral(obj->intern->conn->intern->conn, snapshot_str, snapshot_len);
  
                        if (!sid) {
 -                              throw_exce(EX_ESCAPE TSRMLS_CC, "Failed to quote snapshot identifier (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
 +                              throw_exce(EX_ESCAPE, "Failed to quote snapshot identifier (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                        } else {
                                PGresult *res;
                                smart_str cmd = {0};
                                smart_str_appends(&cmd, sid);
                                smart_str_0(&cmd);
  
 -                              res = php_pq_exec(obj->intern->conn->intern->conn, cmd.c);
 +                              res = php_pq_exec(obj->intern->conn->intern->conn, smart_str_v(&cmd));
  
                                if (!res) {
 -                                      throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to import transaction snapshot (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
 +                                      throw_exce(EX_RUNTIME, "Failed to import transaction snapshot (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                                } else {
 -                                      php_pqres_success(res TSRMLS_CC);
 +                                      php_pqres_success(res);
-                                       php_pq_clear_res(res);
+                                       php_pqres_clear(res);
                                }
  
                                smart_str_free(&cmd);
 -                              php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
 +                              php_pqconn_notify_listeners(obj->intern->conn);
                        }
                }
        }
@@@ -621,25 -643,25 +621,25 @@@ ZEND_END_ARG_INFO()
  static PHP_METHOD(pqtxn, importSnapshotAsync) {
        zend_error_handling zeh;
        char *snapshot_str;
 -      int snapshot_len;
 +      size_t snapshot_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", &snapshot_str, &snapshot_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", &snapshot_str, &snapshot_len);
 +      zend_restore_error_handling(&zeh);
  
        if (SUCCESS == rv) {
 -              php_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 +              php_pqtxn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
  
                if (!obj->intern) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Transaction not initialized");
                } else if (obj->intern->isolation < PHP_PQTXN_REPEATABLE_READ) {
 -                      throw_exce(EX_RUNTIME TSRMLS_CC, "pq\\Transaction must have at least isolation level REPEATABLE READ to be able to import a snapshot");
 +                      throw_exce(EX_RUNTIME, "pq\\Transaction must have at least isolation level REPEATABLE READ to be able to import a snapshot");
                } else {
                        char *sid = PQescapeLiteral(obj->intern->conn->intern->conn, snapshot_str, snapshot_len);
  
                        if (!sid) {
 -                              throw_exce(EX_ESCAPE TSRMLS_CC, "Failed to quote snapshot identifier (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
 +                              throw_exce(EX_ESCAPE, "Failed to quote snapshot identifier (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                        } else {
                                smart_str cmd = {0};
  
                                smart_str_appends(&cmd, sid);
                                smart_str_0(&cmd);
  
 -                              if (!PQsendQuery(obj->intern->conn->intern->conn, cmd.c)) {
 -                                      throw_exce(EX_IO TSRMLS_CC, "Failed to %s (%s)", cmd.c, PHP_PQerrorMessage(obj->intern->conn->intern->conn));
 +                              if (!PQsendQuery(obj->intern->conn->intern->conn, smart_str_v(&cmd))) {
 +                                      throw_exce(EX_IO, "Failed to %s (%s)", smart_str_v(&cmd), PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                                } else {
                                        obj->intern->conn->intern->poller = PQconsumeInput;
                                }
  
                                smart_str_free(&cmd);
 -                              php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
 +                              php_pqconn_notify_listeners(obj->intern->conn);
                        }
                }
        }
@@@ -666,35 -688,36 +666,35 @@@ ZEND_BEGIN_ARG_INFO_EX(ai_pqtxn_open_lo
  ZEND_END_ARG_INFO();
  static PHP_METHOD(pqtxn, openLOB) {
        zend_error_handling zeh;
 -      long mode = INV_WRITE|INV_READ, loid;
 +      zend_long mode = INV_WRITE|INV_READ, loid;
        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", &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(), "l|l", &loid, &mode);
 +      zend_restore_error_handling(&zeh);
  
        if (SUCCESS == rv) {
 -              php_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 +              php_pqtxn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
  
                if (!obj->intern) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Transaction not initialized");
                } else {
                        int lofd = lo_open(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(obj->intern->conn->intern->conn));
 +                              throw_exce(EX_RUNTIME, "Failed to open large object with oid=%lu with mode '%s' (%s)", loid, php_pq_strmode(mode), PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                        } else {
                                php_pqlob_t *lob = ecalloc(1, sizeof(*lob));
  
                                lob->lofd = lofd;
                                lob->loid = loid;
 -                              php_pq_object_addref(obj TSRMLS_CC);
 +                              php_pq_object_addref(obj);
                                lob->txn = obj;
  
 -                              return_value->type = IS_OBJECT;
 -                              return_value->value.obj = php_pqlob_create_object_ex(php_pqlob_class_entry, lob, NULL TSRMLS_CC);
 +                              RETVAL_OBJ(&php_pqlob_create_object_ex(php_pqlob_class_entry, lob)->zo);
                        }
  
 -                      php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
 +                      php_pqconn_notify_listeners(obj->intern->conn);
                }
        }
  }
@@@ -704,41 -727,42 +704,41 @@@ ZEND_BEGIN_ARG_INFO_EX(ai_pqtxn_create_
  ZEND_END_ARG_INFO();
  static PHP_METHOD(pqtxn, createLOB) {
        zend_error_handling zeh;
 -      long mode = INV_WRITE|INV_READ;
 +      zend_long mode = INV_WRITE|INV_READ;
        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", &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(), "|l", &mode);
 +      zend_restore_error_handling(&zeh);
  
        if (SUCCESS == rv) {
 -              php_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 +              php_pqtxn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
  
                if (!obj->intern) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Transaction not initialized");
                } else {
                        Oid loid = lo_creat(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(obj->intern->conn->intern->conn));
 +                              throw_exce(EX_RUNTIME, "Failed to create large object with mode '%s' (%s)", php_pq_strmode(mode), PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                        } else {
                                int lofd = lo_open(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(obj->intern->conn->intern->conn));
 +                                      throw_exce(EX_RUNTIME, "Failed to open large object with oid=%lu with mode '%s': %s", loid, php_pq_strmode(mode), PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                                } else {
                                        php_pqlob_t *lob = ecalloc(1, sizeof(*lob));
  
                                        lob->lofd = lofd;
                                        lob->loid = loid;
 -                                      php_pq_object_addref(obj TSRMLS_CC);
 +                                      php_pq_object_addref(obj);
                                        lob->txn = obj;
  
 -                                      return_value->type = IS_OBJECT;
 -                                      return_value->value.obj = php_pqlob_create_object_ex(php_pqlob_class_entry, lob, NULL TSRMLS_CC);
 +                                      RETVAL_OBJ(&php_pqlob_create_object_ex(php_pqlob_class_entry, lob)->zo);
                                }
                        }
  
 -                      php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
 +                      php_pqconn_notify_listeners(obj->intern->conn);
                }
        }
  }
@@@ -748,26 -772,26 +748,26 @@@ ZEND_BEGIN_ARG_INFO_EX(ai_pqtxn_unlink_
  ZEND_END_ARG_INFO();
  static PHP_METHOD(pqtxn, unlinkLOB) {
        zend_error_handling zeh;
 -      long loid;
 +      zend_long loid;
        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", &loid);
 -      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", &loid);
 +      zend_restore_error_handling(&zeh);
  
        if (SUCCESS == rv) {
 -              php_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 +              php_pqtxn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
  
                if (!obj->intern) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Transaction not initialized");
                } else {
                        int rc = lo_unlink(obj->intern->conn->intern->conn, loid);
  
                        if (rc != 1) {
 -                              throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to unlink LOB (oid=%u): %s", loid, PHP_PQerrorMessage(obj->intern->conn->intern->conn));
 +                              throw_exce(EX_RUNTIME, "Failed to unlink LOB (oid=%lu): %s", loid, PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                        }
  
 -                      php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
 +                      php_pqconn_notify_listeners(obj->intern->conn);
                }
        }
  }
@@@ -779,19 -803,19 +779,19 @@@ ZEND_END_ARG_INFO()
  static PHP_METHOD(pqtxn, importLOB) {
        zend_error_handling zeh;
        char *path_str;
 -      int path_len;
 -      long oid = InvalidOid;
 +      size_t path_len;
 +      zend_long oid = 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, "p|l", &path_str, &path_len, &oid);
 -      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(), "p|l", &path_str, &path_len, &oid);
 +      zend_restore_error_handling(&zeh);
  
        if (rv == SUCCESS) {
 -              php_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 +              php_pqtxn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
  
                if (!obj->intern) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Transaction not initialized");
                } else {
                        if (oid == InvalidOid) {
                                oid = lo_import(obj->intern->conn->intern->conn, path_str);
                        }
  
                        if (oid == InvalidOid) {
 -                              throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to import LOB from '%s' (%s)", path_str, PHP_PQerrorMessage(obj->intern->conn->intern->conn));
 +                              throw_exce(EX_RUNTIME, "Failed to import LOB from '%s' (%s)", path_str, PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                        } else {
                                RETVAL_LONG(oid);
                        }
  
 -                      php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
 +                      php_pqconn_notify_listeners(obj->intern->conn);
                }
        }
  }
@@@ -817,27 -841,27 +817,27 @@@ ZEND_END_ARG_INFO()
  static PHP_METHOD(pqtxn, exportLOB) {
        zend_error_handling zeh;
        char *path_str;
 -      int path_len;
 -      long oid;
 +      size_t path_len;
 +      zend_long oid;
        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, "lp", &oid, &path_str, &path_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(), "lp", &oid, &path_str, &path_len);
 +      zend_restore_error_handling(&zeh);
  
        if (rv == SUCCESS) {
 -              php_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 +              php_pqtxn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
  
                if (!obj->intern) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Transaction not initialized");
                } else {
                        int rc = lo_export(obj->intern->conn->intern->conn, oid, path_str);
  
                        if (rc == -1) {
 -                              throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to export LOB (oid=%u) to '%s' (%s)", oid, path_str, PHP_PQerrorMessage(obj->intern->conn->intern->conn));
 +                              throw_exce(EX_RUNTIME, "Failed to export LOB (oid=%lu) to '%s' (%s)", oid, path_str, PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                        }
  
 -                      php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
 +                      php_pqconn_notify_listeners(obj->intern->conn);
                }
        }
  }
@@@ -874,47 -898,43 +874,47 @@@ PHP_MINIT_FUNCTION(pqtxn
        php_pq_object_prophandler_t ph = {0};
  
        INIT_NS_CLASS_ENTRY(ce, "pq", "Transaction", php_pqtxn_methods);
 -      php_pqtxn_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
 +      php_pqtxn_class_entry = zend_register_internal_class_ex(&ce, NULL);
        php_pqtxn_class_entry->create_object = php_pqtxn_create_object;
  
        memcpy(&php_pqtxn_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
 +      php_pqtxn_object_handlers.offset = XtOffsetOf(php_pqtxn_object_t, zo);
 +      php_pqtxn_object_handlers.free_obj = php_pqtxn_object_free;
        php_pqtxn_object_handlers.read_property = php_pq_object_read_prop;
        php_pqtxn_object_handlers.write_property = php_pq_object_write_prop;
        php_pqtxn_object_handlers.clone_obj = NULL;
        php_pqtxn_object_handlers.get_property_ptr_ptr = NULL;
 -      php_pqtxn_object_handlers.get_gc = NULL;
 +      php_pqtxn_object_handlers.get_gc = php_pq_object_get_gc;
        php_pqtxn_object_handlers.get_properties = php_pq_object_properties;
        php_pqtxn_object_handlers.get_debug_info = php_pq_object_debug_info;
  
 -      zend_hash_init(&php_pqtxn_object_prophandlers, 4, NULL, NULL, 1);
 +      zend_hash_init(&php_pqtxn_object_prophandlers, 4, NULL, php_pq_object_prophandler_dtor, 1);
  
 -      zend_declare_property_null(php_pqtxn_class_entry, ZEND_STRL("connection"), ZEND_ACC_PUBLIC TSRMLS_CC);
 +      zend_declare_property_null(php_pqtxn_class_entry, ZEND_STRL("connection"), ZEND_ACC_PUBLIC);
        ph.read = php_pqtxn_object_read_connection;
 -      zend_hash_add(&php_pqtxn_object_prophandlers, "connection", sizeof("connection"), (void *) &ph, sizeof(ph), NULL);
 +      ph.gc = php_pqtxn_object_gc_connection;
 +      zend_hash_str_add_mem(&php_pqtxn_object_prophandlers, "connection", sizeof("connection")-1, (void *) &ph, sizeof(ph));
 +      ph.gc = NULL;
  
 -      zend_declare_property_null(php_pqtxn_class_entry, ZEND_STRL("isolation"), ZEND_ACC_PUBLIC TSRMLS_CC);
 +      zend_declare_property_null(php_pqtxn_class_entry, ZEND_STRL("isolation"), ZEND_ACC_PUBLIC);
        ph.read = php_pqtxn_object_read_isolation;
        ph.write = php_pqtxn_object_write_isolation;
 -      zend_hash_add(&php_pqtxn_object_prophandlers, "isolation", sizeof("isolation"), (void *) &ph, sizeof(ph), NULL);
 +      zend_hash_str_add_mem(&php_pqtxn_object_prophandlers, "isolation", sizeof("isolation")-1, (void *) &ph, sizeof(ph));
  
 -      zend_declare_property_bool(php_pqtxn_class_entry, ZEND_STRL("readonly"), 0, ZEND_ACC_PUBLIC TSRMLS_CC);
 +      zend_declare_property_bool(php_pqtxn_class_entry, ZEND_STRL("readonly"), 0, ZEND_ACC_PUBLIC);
        ph.read = php_pqtxn_object_read_readonly;
        ph.write = php_pqtxn_object_write_readonly;
 -      zend_hash_add(&php_pqtxn_object_prophandlers, "readonly", sizeof("readonly"), (void *) &ph, sizeof(ph), NULL);
 +      zend_hash_str_add_mem(&php_pqtxn_object_prophandlers, "readonly", sizeof("readonly")-1, (void *) &ph, sizeof(ph));
  
 -      zend_declare_property_bool(php_pqtxn_class_entry, ZEND_STRL("deferrable"), 0, ZEND_ACC_PUBLIC TSRMLS_CC);
 +      zend_declare_property_bool(php_pqtxn_class_entry, ZEND_STRL("deferrable"), 0, ZEND_ACC_PUBLIC);
        ph.read = php_pqtxn_object_read_deferrable;
        ph.write = php_pqtxn_object_write_deferrable;
 -      zend_hash_add(&php_pqtxn_object_prophandlers, "deferrable", sizeof("deferrable"), (void *) &ph, sizeof(ph), NULL);
 +      zend_hash_str_add_mem(&php_pqtxn_object_prophandlers, "deferrable", sizeof("deferrable")-1, (void *) &ph, sizeof(ph));
        ph.write = NULL;
  
 -      zend_declare_class_constant_long(php_pqtxn_class_entry, ZEND_STRL("READ_COMMITTED"), PHP_PQTXN_READ_COMMITTED TSRMLS_CC);
 -      zend_declare_class_constant_long(php_pqtxn_class_entry, ZEND_STRL("REPEATABLE_READ"), PHP_PQTXN_REPEATABLE_READ TSRMLS_CC);
 -      zend_declare_class_constant_long(php_pqtxn_class_entry, ZEND_STRL("SERIALIZABLE"), PHP_PQTXN_SERIALIZABLE TSRMLS_CC);
 +      zend_declare_class_constant_long(php_pqtxn_class_entry, ZEND_STRL("READ_COMMITTED"), PHP_PQTXN_READ_COMMITTED);
 +      zend_declare_class_constant_long(php_pqtxn_class_entry, ZEND_STRL("REPEATABLE_READ"), PHP_PQTXN_REPEATABLE_READ);
 +      zend_declare_class_constant_long(php_pqtxn_class_entry, ZEND_STRL("SERIALIZABLE"), PHP_PQTXN_SERIALIZABLE);
  
        return SUCCESS;
  }
diff --combined src/php_pqtypes.c
index 3f05248ece3b5529860babc4e3214b79245149e4,25cdc1e7a546fefe5c133e31a0831e85865700fb..8fd12e064e26e4ab92a0859e49a4af0c1f7a7116
@@@ -15,7 -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"
@@@ -28,119 -28,158 +28,119 @@@ zend_class_entry *php_pqtypes_class_ent
  static zend_object_handlers php_pqtypes_object_handlers;
  static HashTable php_pqtypes_object_prophandlers;
  
 -static void php_pqtypes_object_free(void *o TSRMLS_DC)
 +static void php_pqtypes_object_free(zend_object *o)
  {
 -      php_pqtypes_object_t *obj = o;
 +      php_pqtypes_object_t *obj = PHP_PQ_OBJ(NULL, o);
  #if DBG_GC
 -      fprintf(stderr, "FREE types(#%d) %p (conn(#%d): %p)\n", obj->zv.handle, obj, obj->intern->conn->zv.handle, obj->intern->conn);
 +      fprintf(stderr, "FREE types(#%d) %p (conn(#%d): %p)\n", obj->zo.handle, obj, obj->intern->conn->zo.handle, obj->intern->conn);
  #endif
        if (obj->intern) {
                zend_hash_destroy(&obj->intern->types);
 -              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);
 -      efree(obj);
 +      php_pq_object_dtor(o);
  }
  
 -zend_object_value php_pqtypes_create_object_ex(zend_class_entry *ce, php_pqtypes_t *intern, php_pqtypes_object_t **ptr TSRMLS_DC)
 +php_pqtypes_object_t *php_pqtypes_create_object_ex(zend_class_entry *ce, php_pqtypes_t *intern)
  {
 -      php_pqtypes_object_t *o;
 -
 -      o = ecalloc(1, sizeof(*o));
 -      zend_object_std_init((zend_object *) o, ce TSRMLS_CC);
 -      object_properties_init((zend_object *) o, ce);
 -      o->prophandler = &php_pqtypes_object_prophandlers;
 -
 -      if (ptr) {
 -              *ptr = o;
 -      }
 -
 -      if (intern) {
 -              o->intern = intern;
 -      }
 -
 -      o->zv.handle = zend_objects_store_put((zend_object *) o, NULL, php_pqtypes_object_free, NULL TSRMLS_CC);
 -      o->zv.handlers = &php_pqtypes_object_handlers;
 -
 -      return o->zv;
 +      return php_pq_object_create(ce, intern, sizeof(php_pqtypes_object_t),
 +                      &php_pqtypes_object_handlers, &php_pqtypes_object_prophandlers);
  }
  
 -static zend_object_value php_pqtypes_create_object(zend_class_entry *class_type TSRMLS_DC)
 +static zend_object *php_pqtypes_create_object(zend_class_entry *class_type)
  {
 -      return php_pqtypes_create_object_ex(class_type, NULL, NULL TSRMLS_CC);
 +      return &php_pqtypes_create_object_ex(class_type, NULL)->zo;
  }
  
 -static void php_pqtypes_object_read_connection(zval *object, void *o, zval *return_value TSRMLS_DC)
 +static void php_pqtypes_object_read_connection(zval *object, void *o, zval *return_value)
  {
        php_pqtypes_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_pqtypes_object_gc_connection(zval *object, void *o, zval *return_value)
 +{
 +      php_pqtypes_object_t *obj = o;
 +      zval zconn;
 +
 +      php_pq_object_to_zval_no_addref(obj->intern->conn, &zconn);
 +      add_next_index_zval(return_value, &zconn);
  }
  
 -static int has_dimension(HashTable *ht, zval *member, char **key_str, int *key_len, ulong *index TSRMLS_DC)
 +static int has_dimension(HashTable *ht, zval *member, zend_string **key, zend_long *index)
  {
 -      long lval = 0;
 -      zval *tmp = member;
 -
 -      switch (Z_TYPE_P(member)) {
 -      default:
 -              convert_to_string_ex(&tmp);
 -              /* no break */
 -      case IS_STRING:
 -              if (!is_numeric_string(Z_STRVAL_P(tmp), Z_STRLEN_P(tmp), &lval, NULL, 0)) {
 -                      int exists = zend_hash_exists(ht, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp) + 1);
 -
 -                      if (key_str) {
 -                              *key_str = estrndup(Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
 -                              if (key_len) {
 -                                      *key_len = Z_STRLEN_P(tmp) + 1;
 -                              }
 -                      }
 -                      if (member != tmp) {
 -                              zval_ptr_dtor(&tmp);
 -                      }
 +      if (Z_TYPE_P(member) == IS_LONG) {
 +              *index = Z_LVAL_P(member);
 +
 +              check_index:
 +              return zend_hash_index_exists(ht, *index);
 +      } else {
 +              zend_string *str = zval_get_string(member);
  
 -                      return exists;
 +              if (is_numeric_str_function(str, index, NULL)) {
 +                      zend_string_release(str);
 +                      goto check_index;
                }
 -              break;
 -      case IS_LONG:
 -              lval = Z_LVAL_P(member);
 -              break;
 -      }
  
 -      if (member != tmp) {
 -              zval_ptr_dtor(&tmp);
 -      }
 -      if (index) {
 -              *index = lval;
 +              if (zend_hash_exists(ht, str)) {
 +                      *key = str;
 +                      return 1;
 +              }
 +
 +              zend_string_release(str);
 +              return 0;
        }
 -      return zend_hash_index_exists(ht, lval);
  }
  
 -static int php_pqtypes_object_has_dimension(zval *object, zval *member, int check_empty TSRMLS_DC)
 +static int php_pqtypes_object_has_dimension(zval *object, zval *member, int check_empty)
  {
 -      php_pqtypes_object_t *obj = zend_object_store_get_object(object TSRMLS_CC);
 -      char *key_str = NULL;
 -      int key_len = 0;
 -      ulong index = 0;
 -
 -      if (check_empty) {
 -              if (has_dimension(&obj->intern->types, member, &key_str, &key_len, &index TSRMLS_CC)) {
 -                      zval **data;
 -
 -                      if (key_str && key_len) {
 -                              if (SUCCESS == zend_hash_find(&obj->intern->types, key_str, key_len, (void *) &data)) {
 -                                      efree(key_str);
 -                                      return Z_TYPE_PP(data) != IS_NULL;
 -                              }
 -                              efree(key_str);
 -                              key_str = NULL;
 -                      } else {
 -                              if (SUCCESS == zend_hash_index_find(&obj->intern->types, index, (void *) &data)) {
 -                                      return Z_TYPE_PP(data) != IS_NULL;
 +      php_pqtypes_object_t *obj = PHP_PQ_OBJ(object, NULL);
 +      zend_string *key = NULL;
 +      zend_long index = 0;
 +
 +      if (has_dimension(&obj->intern->types, member, &key, &index)) {
 +              if (check_empty) {
 +                      zval *data;
 +
 +                      if (key) {
 +                              if ((data = zend_hash_find(&obj->intern->types, key))) {
 +                                      zend_string_release(key);
 +                                      return Z_TYPE_P(data) != IS_NULL;
                                }
 +                              zend_string_release(key);
 +                      } else if ((data = zend_hash_index_find(&obj->intern->types, index))) {
 +                              return Z_TYPE_P(data) != IS_NULL;
                        }
 +              } else {
 +                      if (key) {
 +                              zend_string_release(key);
 +                      }
 +                      return 1;
                }
 -              if (key_str) {
 -                      efree(key_str);
 -              }
 -      } else {
 -              return has_dimension(&obj->intern->types, member, NULL, NULL, NULL TSRMLS_CC);
        }
  
        return 0;
  }
  
 -static zval *php_pqtypes_object_read_dimension(zval *object, zval *member, int type TSRMLS_DC)
 +static zval *php_pqtypes_object_read_dimension(zval *object, zval *member, int type, zval *rv)
  {
 -      ulong index = 0;
 -      char *key_str = NULL;
 -      int key_len = 0;
 -      php_pqtypes_object_t *obj = zend_object_store_get_object(object TSRMLS_CC);
 -
 -      if (has_dimension(&obj->intern->types, member, &key_str, &key_len, &index TSRMLS_CC)) {
 -              zval **data;
 -
 -              if (key_str && key_len) {
 -                      if (SUCCESS == zend_hash_find(&obj->intern->types, key_str, key_len, (void *) &data)) {
 -                              efree(key_str);
 -                              return *data;
 -                      }
 +      php_pqtypes_object_t *obj = PHP_PQ_OBJ(object, NULL);
 +      zend_string *key = NULL;
 +      zend_long index = 0;
 +      zval *data = NULL;
 +
 +      if (has_dimension(&obj->intern->types, member, &key, &index)) {
 +              if (key) {
 +                      data = zend_hash_find(&obj->intern->types, key);
 +                      zend_string_release(key);
                } else {
 -                      if (SUCCESS == zend_hash_index_find(&obj->intern->types, index, (void *) &data)) {
 -                              return *data;
 -                      }
 +                      data = zend_hash_index_find(&obj->intern->types, index);
                }
        }
  
 -      if (key_str) {
 -              efree(key_str);
 -      }
 -
 -      return NULL;
 +      return data;
  }
  
  ZEND_BEGIN_ARG_INFO_EX(ai_pqtypes_construct, 0, 0, 1)
@@@ -152,27 -191,32 +152,27 @@@ static PHP_METHOD(pqtypes, __construct
        zval *zconn, *znsp = 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, "O|a!", &zconn, php_pqconn_class_entry, &znsp);
 -      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|a!", &zconn, php_pqconn_class_entry, &znsp);
 +      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_pqtypes_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 -                      zval *retval = NULL;
 +                      php_pqtypes_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
  
                        obj->intern = ecalloc(1, sizeof(*obj->intern));
                        obj->intern->conn = conn_obj;
 -                      php_pq_object_addref(conn_obj TSRMLS_CC);
 +                      php_pq_object_addref(conn_obj);
                        zend_hash_init(&obj->intern->types, 512, NULL, ZVAL_PTR_DTOR, 0);
  
                        if (znsp) {
 -                              zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "refresh", &retval, znsp);
 +                              zend_call_method_with_1_params(getThis(), Z_OBJCE_P(getThis()), NULL, "refresh", NULL, znsp);
                        } else {
 -                              zend_call_method_with_0_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "refresh", &retval);
 -                      }
 -
 -                      if (retval) {
 -                              zval_ptr_dtor(&retval);
 +                              zend_call_method_with_0_params(getThis(), Z_OBJCE_P(getThis()), NULL, "refresh", NULL);
                        }
                }
        }
  # define PHP_PQ_OID_TEXT 25
  #endif
  
 -static int apply_nsp(void *p TSRMLS_DC, int argc, va_list argv, zend_hash_key *key)
 +static int apply_nsp(zval *zp, int argc, va_list argv, zend_hash_key *key)
  {
 -      zval **zp = p;
        unsigned pcount, tcount;
        php_pq_params_t *params = va_arg(argv, php_pq_params_t *);
        smart_str *str = va_arg(argv, smart_str *);
  
        tcount = php_pq_params_add_type_oid(params, PHP_PQ_OID_TEXT);
 -      pcount = php_pq_params_add_param(params, *zp);
 +      pcount = php_pq_params_add_param(params, zp);
  
        if (tcount != pcount) {
 -              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Param/Type count mismatch");
 +              php_error_docref(NULL, E_WARNING, "Param/Type count mismatch");
                return ZEND_HASH_APPLY_STOP;
        }
        if (pcount > 1) {
@@@ -217,15 -262,15 +217,15 @@@ static PHP_METHOD(pqtypes, refresh) 
        zend_error_handling zeh;
        ZEND_RESULT_CODE rv;
  
 -      zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
 -      rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|H/!", &nsp);
 -      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(), "|H/!", &nsp);
 +      zend_restore_error_handling(&zeh);
  
        if (SUCCESS == rv) {
 -              php_pqtypes_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 +              php_pqtypes_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
  
                if (!obj->intern) {
 -                      throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Types not initialized");
 +                      throw_exce(EX_UNINITIALIZED, "pq\\Types not initialized");
                } else {
                        PGresult *res;
  
                                res = php_pq_exec(obj->intern->conn->intern->conn, PHP_PQ_TYPES_QUERY " and nspname in ('public', 'pg_catalog')");
                        } else {
                                smart_str str = {0};
 -                              php_pq_params_t *params = php_pq_params_init(&obj->intern->conn->intern->converters, NULL, NULL TSRMLS_CC);
 +                              php_pq_params_t *params = php_pq_params_init(&obj->intern->conn->intern->converters, NULL, NULL);
  
                                smart_str_appends(&str, PHP_PQ_TYPES_QUERY " and nspname in(");
 -                              zend_hash_apply_with_arguments(nsp TSRMLS_CC, apply_nsp, 2, params, &str);
 +                              zend_hash_apply_with_arguments(nsp, apply_nsp, 2, params, &str);
                                smart_str_appendc(&str, ')');
                                smart_str_0(&str);
  
 -                              res = php_pq_exec_params(obj->intern->conn->intern->conn, str.c, params->param.count, params->type.oids, (const char *const*) params->param.strings, NULL, NULL, 0);
 +                              res = php_pq_exec_params(obj->intern->conn->intern->conn, smart_str_v(&str), params->param.count, params->type.oids, (const char *const*) params->param.strings, NULL, NULL, 0);
  
                                smart_str_free(&str);
                                php_pq_params_free(&params);
                        }
  
                        if (!res) {
 -                              throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to fetch types (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
 +                              throw_exce(EX_RUNTIME, "Failed to fetch types (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                        } else {
 -                              if (SUCCESS == php_pqres_success(res TSRMLS_CC)) {
 +                              if (SUCCESS == php_pqres_success(res)) {
                                        int r, rows;
  
                                        for (r = 0, rows = PQntuples(res); r < rows; ++r) {
 -                                              zval *row = php_pqres_row_to_zval(res, r, PHP_PQRES_FETCH_OBJECT, NULL TSRMLS_CC);
 -                                              long oid = atol(PQgetvalue(res, r, 0 ));
 -                                              char *name = PQgetvalue(res, r, 1);
 +                                              zval tmp, *row;
  
 +                                              ZVAL_NULL(&tmp);
 +                                              row = php_pqres_row_to_zval(res, r, PHP_PQRES_FETCH_OBJECT, &tmp);
                                                Z_ADDREF_P(row);
  
 -                                              zend_hash_index_update(&obj->intern->types, oid, (void *) &row, sizeof(zval *), NULL);
 -                                              zend_hash_update(&obj->intern->types, name, strlen(name) + 1, (void *) &row, sizeof(zval *), NULL);
 +                                              zend_hash_index_update(&obj->intern->types, atol(PQgetvalue(res, r, 0 )), row);
 +                                              zend_hash_str_update(&obj->intern->types, PQgetvalue(res, r, 1), PQgetlength(res, r, 1), row);
                                        }
                                }
  
-                               php_pq_clear_res(res);
+                               php_pqres_clear(res);
 -                              php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
 +                              php_pqconn_notify_listeners(obj->intern->conn);
                        }
                }
        }
@@@ -289,21 -334,19 +289,21 @@@ PHP_MINIT_FUNCTION(pqtypes
        php_pq_object_prophandler_t ph = {0};
  
        INIT_NS_CLASS_ENTRY(ce, "pq", "Types", php_pqtypes_methods);
 -      php_pqtypes_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
 +      php_pqtypes_class_entry = zend_register_internal_class_ex(&ce, NULL);
        php_pqtypes_class_entry->create_object = php_pqtypes_create_object;
  
        /*
 -      zend_class_implements(php_pqtypes_class_entry TSRMLS_CC, 1, zend_ce_arrayaccess);
 +      zend_class_implements(php_pqtypes_class_entry, 1, zend_ce_arrayaccess);
        */
  
        memcpy(&php_pqtypes_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
 +      php_pqtypes_object_handlers.offset = XtOffsetOf(php_pqtypes_object_t, zo);
 +      php_pqtypes_object_handlers.free_obj = php_pqtypes_object_free;
        php_pqtypes_object_handlers.read_property = php_pq_object_read_prop;
        php_pqtypes_object_handlers.write_property = php_pq_object_write_prop;
        php_pqtypes_object_handlers.clone_obj = NULL;
        php_pqtypes_object_handlers.get_property_ptr_ptr = NULL;
 -      php_pqtypes_object_handlers.get_gc = NULL;
 +      php_pqtypes_object_handlers.get_gc = php_pq_object_get_gc;
        php_pqtypes_object_handlers.get_properties = php_pq_object_properties;
        php_pqtypes_object_handlers.get_debug_info = php_pq_object_debug_info;
        php_pqtypes_object_handlers.has_dimension = php_pqtypes_object_has_dimension;
        php_pqtypes_object_handlers.unset_dimension = NULL;
        php_pqtypes_object_handlers.write_dimension = NULL;
  
 -      zend_hash_init(&php_pqtypes_object_prophandlers, 1, NULL, NULL, 1);
 +      zend_hash_init(&php_pqtypes_object_prophandlers, 1, NULL, php_pq_object_prophandler_dtor, 1);
  
 -      zend_declare_property_null(php_pqtypes_class_entry, ZEND_STRL("connection"), ZEND_ACC_PUBLIC TSRMLS_CC);
 +      zend_declare_property_null(php_pqtypes_class_entry, ZEND_STRL("connection"), ZEND_ACC_PUBLIC);
        ph.read = php_pqtypes_object_read_connection;
 -      zend_hash_add(&php_pqtypes_object_prophandlers, "connection", sizeof("connection"), (void *) &ph, sizeof(ph), NULL);
 +      ph.gc = php_pqtypes_object_gc_connection;
 +      zend_hash_str_add_mem(&php_pqtypes_object_prophandlers, "connection", sizeof("connection")-1, (void *) &ph, sizeof(ph));
 +      ph.gc = NULL;
  
  #     undef PHP_PQ_TYPE
 -#     define PHP_PQ_TYPE(name, oid) zend_declare_class_constant_long(php_pqtypes_class_entry, ZEND_STRL(name), oid TSRMLS_CC);
 +#     define PHP_PQ_TYPE(name, oid) zend_declare_class_constant_long(php_pqtypes_class_entry, ZEND_STRL(name), oid);
  #     include "php_pq_type.h"
  
        return SUCCESS;