From: Michael Wallner Date: Tue, 3 May 2016 13:02:54 +0000 (+0200) Subject: Merge branch 'v1.0.x' X-Git-Tag: v2.0.1~4 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=c753ebfed3a4b21409cfa46212fd2c55227c809f;p=m6w6%2Fext-pq Merge branch 'v1.0.x' --- c753ebfed3a4b21409cfa46212fd2c55227c809f diff --cc src/php_pq_misc.h index 26ac0e1,eee535b..2fdb7e1 --- a/src/php_pq_misc.h +++ b/src/php_pq_misc.h @@@ -16,17 -16,21 +16,17 @@@ #include -#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); diff --cc src/php_pqconn.c index 07c907f,1caf4d8..976e336 --- a/src/php_pqconn.c +++ b/src/php_pqconn.c @@@ -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(¶ms); 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); diff --cc src/php_pqcopy.c index 1a6d37e,c073798..1b3a3aa --- a/src/php_pqcopy.c +++ b/src/php_pqcopy.c @@@ -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 4197cdf,e24c042..682b78a --- a/src/php_pqcur.c +++ b/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 index fbab27e,b82adcf..4eec3b8 --- a/src/php_pqstm.c +++ b/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 index 7b57ebf,e90a2d8..9a97a8f --- a/src/php_pqtxn.c +++ b/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); diff --cc src/php_pqtypes.c index 3f05248,25cdc1e..8fd12e0 --- a/src/php_pqtypes.c +++ b/src/php_pqtypes.c @@@ -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); } } }