Skip to content

Commit 7a2c758

Browse files
committed
Address review comments
1 parent c7b13af commit 7a2c758

15 files changed

+422
-427
lines changed

NEWS

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,9 @@ PHP NEWS
9999
. Fixed bug #38334 (Proper data-type support for PDO_SQLITE). (Nikita)
100100

101101
- PgSQL:
102-
. Convert resource<pgsql link> to object \PgSql. (Máté)
103-
. Convert resource<pgsql result> to object \PgSqlResult. (Máté)
104-
. Convert resource<pgsql large object> to object \PgSqlLob. (Máté)
105-
. Convert resource<pgsql string> to object \PgsqlString. (Máté)
102+
. Convert resource<pgsql link> to object \PgSql\Connection. (Máté)
103+
. Convert resource<pgsql result> to object \PgSql\Result. (Máté)
104+
. Convert resource<pgsql large object> to object \PgSql\Lob. (Máté)
106105

107106
- PSpell:
108107
. Convert resource<pspell> to object \PSpell. (Sara)

UPGRADING

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,15 @@ PHP 8.1 UPGRADE NOTES
121121
PDO::ATTR_STRINGIFY_FETCHES option.
122122

123123
- PgSQL:
124-
. The PgSQL functions now accept and return, respectively, PgSql objects
125-
instead of "pgsql link" resources. Return value checks using is_resource()
126-
should be replaced with checks for `false`.
127-
. The PgSQL functions now accept and return, respectively, PgSqlResult
124+
. The PgSQL functions now accept and return, respectively, \PgSql\Connection
125+
objects instead of "pgsql link" resources. Return value checks using
126+
is_resource() should be replaced with checks for `false`.
127+
. The PgSQL functions now accept and return, respectively, \PgSql\Result
128128
objects instead of "pgsql result" resources. Return value checks using
129129
is_resource() should be replaced with checks for `false`.
130-
. The PgSQL functions now accept and return, respectively, PgSqlLob
130+
. The PgSQL functions now accept and return, respectively, \PgSql\Lob
131131
objects instead of "pgsql large object" resources. Return value checks
132132
using is_resource() should be replaced with checks for `false`.
133-
. The PgSQL functions now accept and return, respectively, PgSqlString
134-
objects instead of "pgsql string" resources. Return value checks
135-
using is_resource() should be replaced with checks for `false`.
136133

137134
- Standard:
138135
. version_compare() no longer accepts undocumented operator abbreviations.

ext/pgsql/pgsql.c

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ static void pgsql_link_free(pgsql_link_handle *link)
169169
}
170170
PGG(num_links)--;
171171

172-
zend_hash_del(&PGG(regular_list), link->hash);
172+
zend_hash_del(&PGG(connections), link->hash);
173173

174174
link->conn = NULL;
175175
zend_string_release(link->hash);
@@ -257,7 +257,6 @@ static void pgsql_lob_free_obj(zend_object *obj)
257257

258258
zend_object_std_dtor(&lofp->std);
259259
}
260-
static int le_link, le_plink, le_result, le_lofp;
261260

262261
/* Compatibility definitions */
263262

@@ -286,6 +285,8 @@ static zend_string *_php_pgsql_trim_message(const char *message)
286285

287286
static void php_pgsql_set_default_link(pgsql_link_handle *link)
288287
{
288+
GC_ADDREF(res);
289+
289290
PGG(default_link) = link;
290291
}
291292

@@ -312,10 +313,9 @@ static void _php_pgsql_notice_handler(void *l, const char *message)
312313
}
313314

314315
pgsql_link_handle *link;
315-
HashTable *notices, tmp_notices;
316316
zval tmp;
317317

318-
link = ((pgsql_link_handle *) l);
318+
link = (pgsql_link_handle *) l;
319319
if (!link->notices) {
320320
link->notices = zend_new_array(1);
321321
}
@@ -325,7 +325,8 @@ static void _php_pgsql_notice_handler(void *l, const char *message)
325325
php_error_docref(NULL, E_NOTICE, "%s", ZSTR_VAL(trimmed_message));
326326
}
327327

328-
add_next_index_str(link->notices, trimmed_message);
328+
ZVAL_STR(&tmp, trimmed_message);
329+
zend_hash_next_index_insert(link->notices, &tmp);
329330
}
330331

331332
static int _rollback_transactions(zval *el)
@@ -359,12 +360,6 @@ static int _rollback_transactions(zval *el)
359360
return ZEND_HASH_APPLY_KEEP;
360361
}
361362

362-
static void _free_ptr(zend_resource *rsrc)
363-
{
364-
pgLofp *lofp = (pgLofp *)rsrc->ptr;
365-
efree(lofp);
366-
}
367-
368363
static void release_string(zval *zv)
369364
{
370365
zend_string_release((zend_string *) Z_PTR_P(zv));
@@ -409,7 +404,7 @@ static PHP_GINIT_FUNCTION(pgsql)
409404
ZEND_TSRMLS_CACHE_UPDATE();
410405
#endif
411406
memset(pgsql_globals, 0, sizeof(zend_pgsql_globals));
412-
zend_hash_init(&pgsql_globals->regular_list, 0, NULL, ZVAL_PTR_DTOR, 1);
407+
zend_hash_init(&pgsql_globals->connections, 0, NULL, ZVAL_PTR_DTOR, 1);
413408
}
414409

415410
static void php_libpq_version(char *buf, size_t len)
@@ -434,7 +429,7 @@ PHP_MINIT_FUNCTION(pgsql)
434429

435430
le_plink = zend_register_list_destructors_ex(NULL, _close_pgsql_plink, "pgsql link persistent", module_number);
436431

437-
pgsql_link_ce = register_class_PgSql();
432+
pgsql_link_ce = register_class_PgSql_Connection();
438433
pgsql_link_ce->create_object = pgsql_link_create_object;
439434
pgsql_link_ce->serialize = zend_class_serialize_deny;
440435
pgsql_link_ce->unserialize = zend_class_unserialize_deny;
@@ -446,7 +441,7 @@ PHP_MINIT_FUNCTION(pgsql)
446441
pgsql_link_object_handlers.clone_obj = NULL;
447442
pgsql_link_object_handlers.compare = zend_objects_not_comparable;
448443

449-
pgsql_result_ce = register_class_PgSqlResult();
444+
pgsql_result_ce = register_class_PgSql_Result();
450445
pgsql_result_ce->create_object = pgsql_result_create_object;
451446
pgsql_result_ce->serialize = zend_class_serialize_deny;
452447
pgsql_result_ce->unserialize = zend_class_unserialize_deny;
@@ -458,7 +453,7 @@ PHP_MINIT_FUNCTION(pgsql)
458453
pgsql_result_object_handlers.clone_obj = NULL;
459454
pgsql_result_object_handlers.compare = zend_objects_not_comparable;
460455

461-
pgsql_lob_ce = register_class_PgSqlLob();
456+
pgsql_lob_ce = register_class_PgSql_Lob();
462457
pgsql_lob_ce->create_object = pgsql_lob_create_object;
463458
pgsql_lob_ce->serialize = zend_class_serialize_deny;
464459
pgsql_lob_ce->unserialize = zend_class_unserialize_deny;
@@ -579,7 +574,7 @@ PHP_MINIT_FUNCTION(pgsql)
579574
PHP_MSHUTDOWN_FUNCTION(pgsql)
580575
{
581576
UNREGISTER_INI_ENTRIES();
582-
zend_hash_destroy(&PGG(regular_list));
577+
zend_hash_destroy(&PGG(connections));
583578

584579
return SUCCESS;
585580
}
@@ -726,7 +721,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
726721
* and add a pointer to it with hashed_details as the key.
727722
*/
728723
if (!(connect_type & PGSQL_CONNECT_FORCE_NEW)
729-
&& (index_ptr = zend_hash_find_ptr(&PGG(regular_list), str.s)) != NULL) {
724+
&& (index_ptr = zend_hash_find_ptr(&PGG(connections), str.s)) != NULL) {
730725
php_pgsql_set_default_link(pgsql_link_from_obj(Z_OBJ_P(index_ptr)));
731726
GC_ADDREF(Z_OBJ_P(index_ptr));
732727
ZVAL_COPY(return_value, index_ptr);
@@ -768,9 +763,9 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
768763

769764
/* add it to the hash */
770765
ZVAL_COPY(&new_index_ptr, return_value);
771-
zend_hash_update(&PGG(regular_list), str.s, &new_index_ptr);
766+
zend_hash_update(&PGG(connections), str.s, &new_index_ptr);
772767

773-
/* Keep track of link => hash mapping, so we can remove the hash entry from regular_list
768+
/* Keep track of link => hash mapping, so we can remove the hash entry from connections
774769
* when the connection is closed. This uses the address of the connection rather than the
775770
* zend_resource, because the resource destructor is passed a stack copy of the resource
776771
* structure. */
@@ -842,7 +837,7 @@ PHP_FUNCTION(pg_close)
842837
if (!pgsql_link) {
843838
link = FETCH_DEFAULT_LINK();
844839
CHECK_DEFAULT_LINK(link);
845-
zend_hash_del(&PGG(regular_list), link->hash);
840+
zend_hash_del(&PGG(connections), link->hash);
846841
PGG(default_link) = NULL;
847842
RETURN_TRUE;
848843
}
@@ -851,7 +846,7 @@ PHP_FUNCTION(pg_close)
851846
CHECK_PGSQL_LINK(link);
852847

853848
if (link == FETCH_DEFAULT_LINK()) {
854-
zend_hash_del(&PGG(regular_list), link->hash);
849+
zend_hash_del(&PGG(connections), link->hash);
855850
PGG(default_link) = NULL;
856851
}
857852
pgsql_link_free(link);

0 commit comments

Comments
 (0)