Skip to content

Commit 98c2c0d

Browse files
committed
New test fixes
1 parent b1e9967 commit 98c2c0d

File tree

7 files changed

+56
-55
lines changed

7 files changed

+56
-55
lines changed

Zend/Optimizer/zend_func_info.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,7 @@ static const func_info_t func_infos[] = {
684684
F1("session_encode", MAY_BE_FALSE | MAY_BE_STRING),
685685

686686
/* ext/pgsql */
687-
F1("pg_connect", MAY_BE_FALSE | MAY_BE_RESOURCE),
688-
FN("pg_pconnect", MAY_BE_FALSE | MAY_BE_RESOURCE),
687+
F1("pg_connect", MAY_BE_FALSE | MAY_BE_OBJECT),
689688
F1("pg_dbname", MAY_BE_STRING),
690689
F1("pg_last_error", MAY_BE_STRING),
691690
F1("pg_options", MAY_BE_STRING),
@@ -694,10 +693,10 @@ static const func_info_t func_infos[] = {
694693
F1("pg_host", MAY_BE_STRING),
695694
F1("pg_version", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_STRING | MAY_BE_ARRAY_OF_LONG | MAY_BE_ARRAY_OF_NULL),
696695
F1("pg_parameter_status", MAY_BE_FALSE | MAY_BE_STRING),
697-
F1("pg_query", MAY_BE_FALSE | MAY_BE_RESOURCE),
698-
F1("pg_query_params", MAY_BE_FALSE | MAY_BE_RESOURCE),
699-
F1("pg_prepare", MAY_BE_FALSE | MAY_BE_RESOURCE),
700-
F1("pg_execute", MAY_BE_FALSE | MAY_BE_RESOURCE),
696+
F1("pg_query", MAY_BE_FALSE | MAY_BE_OBJECT),
697+
F1("pg_query_params", MAY_BE_FALSE | MAY_BE_OBJECT),
698+
F1("pg_prepare", MAY_BE_FALSE | MAY_BE_OBJECT),
699+
F1("pg_execute", MAY_BE_FALSE | MAY_BE_OBJECT),
701700
FN("pg_last_notice", MAY_BE_FALSE | MAY_BE_TRUE | MAY_BE_STRING | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY ),
702701
F1("pg_field_table", MAY_BE_FALSE | MAY_BE_LONG | MAY_BE_STRING),
703702
F1("pg_field_name", MAY_BE_STRING),
@@ -712,7 +711,7 @@ static const func_info_t func_infos[] = {
712711
F1("pg_fetch_all_columns", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_NULL | MAY_BE_ARRAY_OF_STRING),
713712
F1("pg_last_oid", MAY_BE_FALSE | MAY_BE_LONG | MAY_BE_STRING),
714713
F1("pg_lo_create", MAY_BE_FALSE | MAY_BE_LONG | MAY_BE_STRING),
715-
F1("pg_lo_open", MAY_BE_FALSE | MAY_BE_RESOURCE),
714+
F1("pg_lo_open", MAY_BE_FALSE | MAY_BE_OBJECT),
716715
F1("pg_lo_read", MAY_BE_FALSE | MAY_BE_STRING),
717716
F1("pg_lo_import", MAY_BE_FALSE | MAY_BE_LONG | MAY_BE_STRING),
718717
F1("pg_copy_to", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_STRING),
@@ -723,13 +722,13 @@ static const func_info_t func_infos[] = {
723722
F1("pg_escape_identifier", MAY_BE_FALSE | MAY_BE_STRING),
724723
F1("pg_result_error", MAY_BE_FALSE | MAY_BE_STRING),
725724
F1("pg_result_error_field", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_STRING),
726-
F1("pg_get_result", MAY_BE_FALSE | MAY_BE_RESOURCE),
725+
F1("pg_get_result", MAY_BE_FALSE | MAY_BE_OBJECT),
727726
F1("pg_result_status", MAY_BE_LONG | MAY_BE_STRING),
728727
F1("pg_get_notify", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY),
729-
F1("pg_socket", MAY_BE_FALSE | MAY_BE_RESOURCE),
728+
F1("pg_socket", MAY_BE_FALSE | MAY_BE_OBJECT),
730729
F1("pg_meta_data", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_ARRAY),
731730
F1("pg_convert", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_ANY),
732-
F1("pg_insert", MAY_BE_FALSE | MAY_BE_TRUE | MAY_BE_RESOURCE | MAY_BE_STRING),
731+
F1("pg_insert", MAY_BE_FALSE | MAY_BE_TRUE | MAY_BE_OBJECT | MAY_BE_STRING),
733732
F1("pg_update", MAY_BE_FALSE | MAY_BE_TRUE | MAY_BE_STRING),
734733
F1("pg_delete", MAY_BE_FALSE | MAY_BE_TRUE | MAY_BE_STRING),
735734
F1("pg_select", MAY_BE_FALSE | MAY_BE_STRING | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_ARRAY),

ext/pgsql/pgsql.c

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,20 @@ static void pgsql_link_free(pgsql_link_handle *link)
164164
while ((res = PQgetResult(link->conn))) {
165165
PQclear(res);
166166
}
167-
PQfinish(link->conn);
167+
if (!link->persistent) {
168+
PQfinish(link->conn);
169+
}
168170
PGG(num_links)--;
169171

170172
zend_hash_del(&PGG(regular_list), link->hash);
171173

172174
link->conn = NULL;
173175
zend_string_release(link->hash);
176+
174177
if (link->notices) {
175178
zend_hash_destroy(link->notices);
179+
FREE_HASHTABLE(link->notices);
180+
link->notices = NULL;
176181
}
177182
}
178183

@@ -290,48 +295,45 @@ static inline char * _php_pgsql_trim_result(PGconn * pgsql, char **buf)
290295

291296
static void php_pgsql_set_default_link(pgsql_link_handle *link)
292297
{
293-
if (PGG(default_link) != NULL) {
294-
pgsql_link_free(FETCH_DEFAULT_LINK());
295-
}
296-
297298
PGG(default_link) = link;
298299
}
299300

300301
static void _close_pgsql_plink(zend_resource *rsrc)
301302
{
302-
PGconn *link = (PGconn *)rsrc->ptr;
303-
PGresult *res;
303+
if (rsrc->ptr) {
304+
PGconn *link = (PGconn *)rsrc->ptr;
305+
PGresult *res;
304306

305-
while ((res = PQgetResult(link))) {
306-
PQclear(res);
307+
while ((res = PQgetResult(link))) {
308+
PQclear(res);
309+
}
310+
PQfinish(link);
311+
PGG(num_persistent)--;
312+
PGG(num_links)--;
313+
rsrc->ptr = NULL;
307314
}
308-
PQfinish(link);
309-
PGG(num_persistent)--;
310-
PGG(num_links)--;
311315
}
312316

313-
static void _php_pgsql_notice_handler(void *link, const char *message)
317+
static void _php_pgsql_notice_handler(void *l, const char *message)
314318
{
315-
HashTable *notices, tmp_notices;
319+
pgsql_link_handle *link;
316320
zval tmp;
317321
char *trimmed_message;
318322
size_t trimmed_message_len;
319323

320324
if (! PGG(ignore_notices)) {
321-
notices = ((pgsql_link_handle *) link)->notices;
322-
if (!notices) {
323-
zend_hash_init(&tmp_notices, 1, NULL, ZVAL_PTR_DTOR, 0);
324-
notices = &tmp_notices;
325+
link = ((pgsql_link_handle *) l);
326+
if (!link->notices) {
327+
link->notices = zend_new_array(1);
325328
}
326329
trimmed_message = _php_pgsql_trim_message(message, &trimmed_message_len);
327330
if (PGG(log_notices)) {
328331
php_error_docref(NULL, E_NOTICE, "%s", trimmed_message);
329332
}
330333

331334
ZVAL_STRINGL(&tmp, trimmed_message, trimmed_message_len);
332-
zend_hash_next_index_insert(notices, &tmp);
335+
zend_hash_next_index_insert(link->notices, &tmp);
333336
efree(trimmed_message);
334-
zval_ptr_dtor(&tmp);
335337
}
336338
}
337339

@@ -341,8 +343,9 @@ static int _rollback_transactions(zval *el)
341343
PGresult *res;
342344
zend_resource *rsrc = Z_RES_P(el);
343345

344-
if (rsrc->type != le_plink)
345-
return 0;
346+
if (rsrc->type != le_plink) {
347+
return ZEND_HASH_APPLY_KEEP;
348+
}
346349

347350
link = (PGconn *) rsrc->ptr;
348351

@@ -362,7 +365,7 @@ static int _rollback_transactions(zval *el)
362365
PGG(ignore_notices) = orig;
363366
}
364367

365-
return 0;
368+
return ZEND_HASH_APPLY_KEEP;
366369
}
367370

368371
static void _free_ptr(zend_resource *rsrc)
@@ -410,7 +413,6 @@ static PHP_GINIT_FUNCTION(pgsql)
410413
ZEND_TSRMLS_CACHE_UPDATE();
411414
#endif
412415
memset(pgsql_globals, 0, sizeof(zend_pgsql_globals));
413-
/* Initialize notice message hash at MINIT only */
414416
zend_hash_init(&pgsql_globals->regular_list, 0, NULL, ZVAL_PTR_DTOR, 1);
415417
}
416418

@@ -596,8 +598,6 @@ PHP_RINIT_FUNCTION(pgsql)
596598

597599
PHP_RSHUTDOWN_FUNCTION(pgsql)
598600
{
599-
/* clean up notice messages */
600-
zend_hash_clean(&PGG(regular_list));
601601
/* clean up persistent connection */
602602
zend_hash_apply(&EG(persistent_list), (apply_func_t) _rollback_transactions);
603603
return SUCCESS;
@@ -717,6 +717,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
717717
link->conn = pgsql;
718718
link->hash = zend_string_copy(str.s);
719719
link->notices = NULL;
720+
link->persistent = 1;
720721
} else { /* Non persistent connection */
721722
zval *index_ptr, new_index_ptr;
722723

@@ -764,6 +765,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
764765
link->conn = pgsql;
765766
link->hash = zend_string_copy(str.s);
766767
link->notices = NULL;
768+
link->persistent = 0;
767769

768770
/* add it to the hash */
769771
ZVAL_COPY(&new_index_ptr, return_value);
@@ -841,15 +843,16 @@ PHP_FUNCTION(pg_close)
841843
if (!pgsql_link) {
842844
link = FETCH_DEFAULT_LINK();
843845
CHECK_DEFAULT_LINK(link);
846+
zend_hash_del(&PGG(regular_list), link->hash);
844847
PGG(default_link) = NULL;
845-
pgsql_link_free(link);
846848
RETURN_TRUE;
847849
}
848850

849851
link = Z_PGSQL_LINK_P(pgsql_link);
850852
CHECK_PGSQL_LINK(link);
851853

852854
if (link == FETCH_DEFAULT_LINK()) {
855+
zend_hash_del(&PGG(regular_list), link->hash);
853856
PGG(default_link) = NULL;
854857
}
855858
pgsql_link_free(link);
@@ -3369,7 +3372,6 @@ PHP_FUNCTION(pg_escape_bytea)
33693372
RETURN_THROWS();
33703373
}
33713374
link = FETCH_DEFAULT_LINK();
3372-
CHECK_DEFAULT_LINK(link);
33733375
break;
33743376
default:
33753377
if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS", &pgsql_link, pgsql_link_ce, &from) == FAILURE) {
@@ -5683,7 +5685,6 @@ PHP_FUNCTION(pg_update)
56835685
zval *pgsql_link, *values, *ids;
56845686
pgsql_link_handle *link;
56855687
zend_string *table;
5686-
size_t table_len;
56875688
zend_ulong option = PGSQL_DML_EXEC;
56885689
PGconn *pg_link;
56895690
zend_string *sql = NULL;

ext/pgsql/php_pgsql.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ typedef struct pgsql_link_handle {
149149
zend_string *hash;
150150
HashTable *notices;
151151
zend_object std;
152+
bool persistent;
152153
} pgsql_link_handle;
153154

154155
typedef struct pgLofp {

ext/pgsql/tests/13pg_select_9.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ $fields = array('num'=>'1234', 'str'=>'ABC', 'bin'=>'XYZ');
1818
$ids = array('num'=>'1234');
1919

2020
$res = pg_select($db, $table_name, $ids) or print "Error\n";
21-
var_dump(pg_last_error($db));
2221
var_dump($res);
2322
echo pg_select($db, $table_name, $ids, PGSQL_DML_STRING)."\n";
2423
echo pg_select($db, $table_name, $ids, PGSQL_DML_STRING|PGSQL_DML_ESCAPE)."\n";

ext/pgsql/tests/80_bug32223b.phpt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,41 @@ pgsql.ignore_notice=0
2323
require_once('config.inc');
2424
require_once('lcmess.inc');
2525

26-
define('dbh', pg_connect($conn_str));
27-
if (!dbh) {
28-
die ("Could not connect to the server");
26+
$dbh = pg_connect($conn_str);
27+
if (!$dbh) {
28+
die ("Could not connect to the server");
2929
}
3030

3131
_set_lc_messages();
3232

33-
$res = pg_query(dbh, "CREATE OR REPLACE FUNCTION test_notice() RETURNS boolean AS '
33+
$res = pg_query($dbh, "CREATE OR REPLACE FUNCTION test_notice() RETURNS boolean AS '
3434
begin
3535
RAISE NOTICE ''11111'';
3636
return ''f'';
3737
end;
3838
' LANGUAGE plpgsql;");
3939

40-
$res = pg_query(dbh, 'SET client_min_messages TO NOTICE;');
40+
$res = pg_query($dbh, 'SET client_min_messages TO NOTICE;');
4141
var_dump($res);
4242

43-
function tester() {
44-
$res = pg_query(dbh, 'SELECT test_notice()');
43+
function tester($dbh) {
44+
$res = pg_query($dbh, 'SELECT test_notice()');
4545
$row = pg_fetch_row($res, 0);
4646
var_dump($row);
4747
pg_free_result($res);
4848
if ($row[0] == 'f')
4949
{
50-
var_dump(pg_last_notice(dbh));
50+
var_dump(pg_last_notice($dbh));
5151
}
5252
}
53-
tester();
53+
tester($dbh);
5454

55-
pg_close(dbh);
55+
pg_close($dbh);
5656

5757
?>
5858
--EXPECTF--
59-
resource(%d) of type (pgsql result)
59+
object(PgSqlResult)#%d (0) {
60+
}
6061
array(1) {
6162
[0]=>
6263
string(1) "f"

ext/pgsql/tests/bug46408.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Bug #46408 (Locale number format settings can cause pg_query_params to break wit
33
--SKIPIF--
44
<?php
55
require_once('skipif.inc');
6-
if (false === setlocale(LC_ALL, 'de_DE.utf-8', 'de_DE')) {
7-
echo "skip Locale de_DE.utf-8 not present";
6+
if (false === setlocale(LC_ALL, "de", "de_DE", "de_DE.ISO8859-1", "de_DE.ISO_8859-1", "de_DE.UTF-8")) {
7+
echo "skip Locale de-DE not present";
88
}
99
?>
1010
--FILE--
@@ -13,7 +13,7 @@ if (false === setlocale(LC_ALL, 'de_DE.utf-8', 'de_DE')) {
1313
require_once('config.inc');
1414

1515
$dbh = pg_connect($conn_str);
16-
setlocale(LC_ALL, 'de_DE.utf-8', 'de_DE');
16+
setlocale(LC_ALL, "de", "de_DE", "de_DE.ISO8859-1", "de_DE.ISO_8859-1", "de_DE.UTF-8");
1717
echo 3.5 , "\n";
1818
pg_query_params("SELECT $1::numeric", array(3.5));
1919
pg_close($dbh);

ext/pgsql/tests/connect_after_close.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ include('config.inc');
1010
$db1 = pg_connect($conn_str);
1111
unset($db1);
1212
var_dump(pg_close());
13-
exit;
13+
1414
$db2 = pg_connect($conn_str);
1515
unset($db2);
1616
var_dump(pg_close());

0 commit comments

Comments
 (0)