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
  
  #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);
@@@ -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);
@@@ -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
@@@ -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
@@@ -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
@@@ -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);
@@@ -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);
                        }
                }
        }