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

Simple merge
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);
index 07c907f59e117f5d80d81fff5c7b1045adbf93f5,1caf4d831d19cde25a0b193193c1f0c133f614f5..976e336a4bd9cf233ade70c77705fc51bf64e055
@@@ -549,10 -560,10 +549,10 @@@ 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);
@@@ -580,13 -591,13 +580,13 @@@ static inline PGresult *unlisten(PGcon
        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;
@@@ -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);
                        }
                }
        }
@@@ -885,16 -888,16 +885,16 @@@ static PHP_METHOD(pqconn, listen) 
                                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);
                        }
                }
        }
@@@ -973,13 -976,13 +973,13 @@@ static PHP_METHOD(pqconn, notify) 
                        res = PQexecParams(obj->intern->conn, "select pg_notify($1, $2)", 2, NULL, (const char *const*) params, NULL, NULL, 0);
  
                        if (!res) {
 -                              throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to notify listeners (%s)", PHP_PQerrorMessage(obj->intern->conn));
 +                              throw_exce(EX_RUNTIME, "Failed to notify listeners (%s)", PHP_PQerrorMessage(obj->intern->conn));
                        } else {
 -                              php_pqres_success(res TSRMLS_CC);
 +                              php_pqres_success(res);
-                               php_pq_clear_res(res);
+                               php_pqres_clear(res);
                        }
  
 -                      php_pqconn_notify_listeners(obj TSRMLS_CC);
 +                      php_pqconn_notify_listeners(obj);
                }
        }
  }
@@@ -1067,14 -1070,14 +1067,14 @@@ static PHP_METHOD(pqconn, exec) 
                        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);
                }
        }
  }
@@@ -1173,15 -1176,15 +1173,15 @@@ static PHP_METHOD(pqconn, execParams) 
                        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);
                        }
                }
        }
@@@ -1248,11 -1251,11 +1248,11 @@@ ZEND_RESULT_CODE php_pqconn_prepare(zva
  
        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;
@@@ -1361,11 -1366,11 +1361,11 @@@ ZEND_RESULT_CODE php_pqconn_declare(zva
  
        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;
@@@ -1593,14 -1600,14 +1593,14 @@@ ZEND_RESULT_CODE php_pqconn_start_trans
                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);
index 1a6d37e1d42379463dd59962accfbb1b662d57af,c073798efde10630bdc7b6606a3457d15e02b413..1b3a3aa9212e6daca9eea49faaa8cc578f40ff5f
@@@ -152,10 -161,10 +152,10 @@@ static PHP_METHOD(pqcopy, __construct) 
                                        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);
@@@ -220,10 -229,10 +220,10 @@@ static PHP_METHOD(pqcopy, end) 
                                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);
                                }
                        }
  
@@@ -265,10 -274,10 +265,10 @@@ static PHP_METHOD(pqcopy, get) 
                                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;
diff --cc src/php_pqcur.c
index 4197cdf4109492774dffafadf2c7ed2fa1423a9c,e24c042915c695ea7626f6510761f45d791dd9eb..682b78aa01d8828bfd8a7823e46692cddc455907
@@@ -40,17 -40,17 +40,17 @@@ static void cur_close(php_pqcur_object_
                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));
                        }
                }
  
diff --cc src/php_pqstm.c
index fbab27e81037f9fe4d0f344b1669493da6086fb3,b82adcfbe96e4f17f144d8a76597f8d6364bb1a2..4eec3b8795fb965f69fe3de915c6c5503f4a2fca
@@@ -51,10 -51,10 +51,10 @@@ static void php_pqstm_deallocate(php_pq
                        } 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));
                                }
                        }
  
@@@ -340,8 -350,8 +340,8 @@@ static PHP_METHOD(pqstm, desc) 
                                                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);
                        }
                }
        }
diff --cc src/php_pqtxn.c
index 7b57ebf1e843c44e3312abbf4243f642f5f73bd7,e90a2d8738313c6e4214eb808ab5c948c7d36d1b..9a97a8f9567a8ca390359c901e5f142cda145f80
@@@ -58,10 -58,10 +58,10 @@@ static void php_pqtxn_object_free(zend_
                        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;
        }
@@@ -138,9 -160,13 +138,9 @@@ static void php_pqtxn_object_write_isol
                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);
        }
  }
  
@@@ -156,8 -182,8 +156,8 @@@ static void php_pqtxn_object_write_read
        }
  
        if (res) {
 -              php_pqres_success(res TSRMLS_CC);
 +              php_pqres_success(res);
-               php_pq_clear_res(res);
+               php_pqres_clear(res);
        }
  }
  
@@@ -173,8 -199,8 +173,8 @@@ static void php_pqtxn_object_write_defe
        }
  
        if (res) {
 -              php_pqres_success(res TSRMLS_CC);
 +              php_pqres_success(res);
-               php_pq_clear_res(res);
+               php_pqres_clear(res);
        }
  }
  
@@@ -265,13 -291,13 +265,13 @@@ static PHP_METHOD(pqtxn, 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 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);
@@@ -528,16 -550,16 +528,16 @@@ static PHP_METHOD(pqtxn, exportSnapshot
                        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);
                }
        }
  }
@@@ -599,13 -621,13 +599,13 @@@ static PHP_METHOD(pqtxn, importSnapshot
                                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);
index 3f05248ece3b5529860babc4e3214b79245149e4,25cdc1e7a546fefe5c133e31a0831e85865700fb..8fd12e064e26e4ab92a0859e49a4af0c1f7a7116
@@@ -264,8 -309,8 +264,8 @@@ static PHP_METHOD(pqtypes, refresh) 
                                        }
                                }
  
-                               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);
                        }
                }
        }