Merge branch 'v1.1.x'
authorMichael Wallner <mike@php.net>
Tue, 17 May 2016 14:33:37 +0000 (16:33 +0200)
committerMichael Wallner <mike@php.net>
Tue, 17 May 2016 14:33:37 +0000 (16:33 +0200)
1  2 
src/php_pqconn.c
src/php_pqconn.h
src/php_pqconn_event.c
src/php_pqstm.c

@@@ -83,9 -75,10 +83,10 @@@ static void php_pqconn_object_free(zend
  #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->statements);
                zend_hash_destroy(&obj->intern->converters);
                zend_hash_destroy(&obj->intern->eventhandlers);
                efree(obj->intern);
@@@ -667,15 -679,14 +668,16 @@@ static PHP_METHOD(pqconn, __construct) 
  
                        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->statements, 0, NULL, NULL, 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);
                        }
Simple merge
  
  #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 "php_pq.h"
  #include "php_pq_misc.h"
  #include "php_pq_object.h"
  #include "php_pqconn_event.h"
+ #include "php_pqstm.h"
  #include "php_pqres.h"
  
 -static int apply_event(void *p, void *a TSRMLS_DC)
 +static int apply_event(zval *p, void *a)
  {
 -      php_pq_callback_t *cb = p;
 +      php_pq_callback_t *cb = Z_PTR_P(p);
        zval *args = a;
 -      zval *retval = NULL;
 +      zval rv;
  
 -      zend_fcall_info_args(&cb->fci, args TSRMLS_CC);
 -      zend_fcall_info_call(&cb->fci, &cb->fcc, &retval, NULL TSRMLS_CC);
 -      if (retval) {
 -              zval_ptr_dtor(&retval);
 -      }
 +      ZVAL_NULL(&rv);
 +      zend_fcall_info_args(&cb->fci, args);
 +      zend_fcall_info_call(&cb->fci, &cb->fcc, &rv, NULL);
 +      zend_fcall_info_args_clear(&cb->fci, 0);
 +      zval_ptr_dtor(&rv);
  
        return ZEND_HASH_APPLY_KEEP;
  }
  
 -static inline PGresult *relisten(PGconn *conn, const char *channel_str, size_t channel_len TSRMLS_DC)
 -              res = PQexec(conn, cmd.c);
++static inline PGresult *relisten(PGconn *conn, const char *channel_str, size_t channel_len)
+ {
+       char *quoted_channel = PQescapeIdentifier(conn, channel_str, channel_len);
+       PGresult *res = NULL;
+       if (quoted_channel) {
+               smart_str cmd = {0};
+               smart_str_appends(&cmd, "LISTEN ");
+               smart_str_appends(&cmd, quoted_channel);
+               smart_str_0(&cmd);
 -static int apply_relisten(void *p TSRMLS_DC, int argc, va_list argv, zend_hash_key *key)
++              res = PQexec(conn, smart_str_v(&cmd));
+               smart_str_free(&cmd);
+               PQfreemem(quoted_channel);
+       }
+       return res;
+ }
 -      PGresult *res = relisten(obj->intern->conn, key->arKey, key->nKeyLength - 1 TSRMLS_CC);
++static int apply_relisten(zval *p, int argc, va_list argv, zend_hash_key *key)
+ {
+       php_pqconn_object_t *obj = va_arg(argv, php_pqconn_object_t *);
 -static int apply_reprepare(void *p TSRMLS_DC, int argc, va_list argv, zend_hash_key *key)
++      PGresult *res = relisten(obj->intern->conn, key->key->val, key->key->len);
+       if (res) {
+               php_pqres_clear(res);
+       }
+       return ZEND_HASH_APPLY_KEEP;
+ }
 -      php_pqstm_t *stm = *(php_pqstm_object_t **) p;
++static int apply_reprepare(zval *p, int argc, va_list argv, zend_hash_key *key)
+ {
+       php_pqconn_object_t *obj = va_arg(argv, php_pqconn_object_t *);
 -      php_pqconn_prepare(NULL, obj, stm->name, stm->query, stm->params TSRMLS_CC);
++      php_pqstm_t *stm = Z_PTR_P(p);
++      php_pqconn_prepare(NULL, obj, stm->name, stm->query, stm->params);
+       return ZEND_HASH_APPLY_KEEP;
+ }
  static void php_pqconn_event_connreset(PGEventConnReset *event)
  {
        php_pqconn_event_data_t *data = PQinstanceData(event->conn, php_pqconn_event);
  
        if (data) {
 -              HashTable *evhs;
 -              TSRMLS_DF(data);
 +              zval *zevhs;
  
 -              zend_hash_apply_with_arguments(&data->obj->intern->listeners TSRMLS_CC, apply_relisten, 1, data->obj);
+               /* restore listeners */
 -              zend_hash_apply_with_arguments(&data->obj->intern->statements TSRMLS_CC, apply_reprepare, 1, data->obj);
++              zend_hash_apply_with_arguments(&data->obj->intern->listeners, apply_relisten, 1, data->obj);
+               /* restore statements */
 -              if (SUCCESS == zend_hash_find(&data->obj->intern->eventhandlers, ZEND_STRS("reset"), (void *) &evhs)) {
 -                      zval *args, *connection = NULL;
 -
 -                      MAKE_STD_ZVAL(args);
 -                      array_init(args);
 -                      php_pq_object_to_zval(data->obj, &connection TSRMLS_CC);
 -                      add_next_index_zval(args, connection);
 -                      zend_hash_apply_with_argument(evhs, apply_event, args TSRMLS_CC);
++              zend_hash_apply_with_arguments(&data->obj->intern->statements, apply_reprepare, 1, data->obj);
+               /* eventhandler */
 +              if ((zevhs = zend_hash_str_find(&data->obj->intern->eventhandlers, ZEND_STRL("reset")))) {
 +                      zval args, connection;
 +
 +                      array_init(&args);
 +                      php_pq_object_to_zval(data->obj, &connection);
 +                      add_next_index_zval(&args, &connection);
 +                      zend_hash_apply_with_argument(Z_ARRVAL_P(zevhs), apply_event, &args);
                        zval_ptr_dtor(&args);
                }
        }
diff --cc src/php_pqstm.c
@@@ -63,6 -63,7 +63,7 @@@ static void php_pqstm_deallocate(php_pq
                }
  
                obj->intern->allocated = 0;
 -              zend_hash_del(&obj->intern->conn->intern->statements, obj->intern->name, strlen(obj->intern->name)+1);
++              zend_hash_str_del(&obj->intern->conn->intern->statements, obj->intern->name, strlen(obj->intern->name));
        }
  }
  
@@@ -155,6 -165,8 +156,8 @@@ php_pqstm_t *php_pqstm_init(php_pqconn_
  
        ZEND_INIT_SYMTABLE(&stm->bound);
  
 -      zend_hash_add(&conn->intern->statements, name, strlen(name)+1, &stm, sizeof(stm), NULL);
++      zend_hash_str_add_ptr(&conn->intern->statements, name, strlen(name), stm);
        return stm;
  }
  
@@@ -433,6 -446,9 +436,9 @@@ static inline void php_pqstm_prepare_ha
  
                        if (SUCCESS == rv) {
                                obj->intern->allocated = 1;
 -                              zend_hash_add(&obj->intern->conn->intern->statements,
 -                                              obj->intern->name, strlen(obj->intern->name)+1, &obj, sizeof(obj), NULL);
++                              zend_hash_str_add_ptr(&obj->intern->conn->intern->statements,
++                                              obj->intern->name, strlen(obj->intern->name), obj->intern);
                        }
                }
        }