Skip to content

Commit eb22b17

Browse files
committed
New test fixes
1 parent fae9bcf commit eb22b17

File tree

7 files changed

+57
-55
lines changed

7 files changed

+57
-55
lines changed

Zend/Optimizer/zend_func_info.c

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

687687
/* ext/pgsql */
688-
F1("pg_connect", MAY_BE_FALSE | MAY_BE_RESOURCE),
689-
FN("pg_pconnect", MAY_BE_FALSE | MAY_BE_RESOURCE),
688+
F1("pg_connect", MAY_BE_FALSE | MAY_BE_OBJECT),
690689
F1("pg_dbname", MAY_BE_STRING),
691690
F1("pg_last_error", MAY_BE_STRING),
692691
F1("pg_options", MAY_BE_STRING),
@@ -695,10 +694,10 @@ static const func_info_t func_infos[] = {
695694
F1("pg_host", MAY_BE_STRING),
696695
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),
697696
F1("pg_parameter_status", MAY_BE_FALSE | MAY_BE_STRING),
698-
F1("pg_query", MAY_BE_FALSE | MAY_BE_RESOURCE),
699-
F1("pg_query_params", MAY_BE_FALSE | MAY_BE_RESOURCE),
700-
F1("pg_prepare", MAY_BE_FALSE | MAY_BE_RESOURCE),
701-
F1("pg_execute", MAY_BE_FALSE | MAY_BE_RESOURCE),
697+
F1("pg_query", MAY_BE_FALSE | MAY_BE_OBJECT),
698+
F1("pg_query_params", MAY_BE_FALSE | MAY_BE_OBJECT),
699+
F1("pg_prepare", MAY_BE_FALSE | MAY_BE_OBJECT),
700+
F1("pg_execute", MAY_BE_FALSE | MAY_BE_OBJECT),
702701
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 ),
703702
F1("pg_field_table", MAY_BE_FALSE | MAY_BE_LONG | MAY_BE_STRING),
704703
F1("pg_field_name", MAY_BE_STRING),
@@ -713,7 +712,7 @@ static const func_info_t func_infos[] = {
713712
F1("pg_fetch_all_columns", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_NULL | MAY_BE_ARRAY_OF_STRING),
714713
F1("pg_last_oid", MAY_BE_FALSE | MAY_BE_LONG | MAY_BE_STRING),
715714
F1("pg_lo_create", MAY_BE_FALSE | MAY_BE_LONG | MAY_BE_STRING),
716-
F1("pg_lo_open", MAY_BE_FALSE | MAY_BE_RESOURCE),
715+
F1("pg_lo_open", MAY_BE_FALSE | MAY_BE_OBJECT),
717716
F1("pg_lo_read", MAY_BE_FALSE | MAY_BE_STRING),
718717
F1("pg_lo_import", MAY_BE_FALSE | MAY_BE_LONG | MAY_BE_STRING),
719718
F1("pg_copy_to", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_STRING),
@@ -724,13 +723,13 @@ static const func_info_t func_infos[] = {
724723
F1("pg_escape_identifier", MAY_BE_FALSE | MAY_BE_STRING),
725724
F1("pg_result_error", MAY_BE_FALSE | MAY_BE_STRING),
726725
F1("pg_result_error_field", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_STRING),
727-
F1("pg_get_result", MAY_BE_FALSE | MAY_BE_RESOURCE),
726+
F1("pg_get_result", MAY_BE_FALSE | MAY_BE_OBJECT),
728727
F1("pg_result_status", MAY_BE_LONG | MAY_BE_STRING),
729728
F1("pg_get_notify", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY),
730-
F1("pg_socket", MAY_BE_FALSE | MAY_BE_RESOURCE),
729+
F1("pg_socket", MAY_BE_FALSE | MAY_BE_OBJECT),
731730
F1("pg_meta_data", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_ARRAY),
732731
F1("pg_convert", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_ANY),
733-
F1("pg_insert", MAY_BE_FALSE | MAY_BE_TRUE | MAY_BE_RESOURCE | MAY_BE_STRING),
732+
F1("pg_insert", MAY_BE_FALSE | MAY_BE_TRUE | MAY_BE_OBJECT | MAY_BE_STRING),
734733
F1("pg_update", MAY_BE_FALSE | MAY_BE_TRUE | MAY_BE_STRING),
735734
F1("pg_delete", MAY_BE_FALSE | MAY_BE_TRUE | MAY_BE_STRING),
736735
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 & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,20 @@ static void pgsql_link_free(pgsql_link_handle *link)
167167
while ((res = PQgetResult(link->conn))) {
168168
PQclear(res);
169169
}
170-
PQfinish(link->conn);
170+
if (!link->persistent) {
171+
PQfinish(link->conn);
172+
}
171173
PGG(num_links)--;
172174

173175
zend_hash_del(&PGG(regular_list), link->hash);
174176

175177
link->conn = NULL;
176178
zend_string_release(link->hash);
179+
177180
if (link->notices) {
178181
zend_hash_destroy(link->notices);
182+
FREE_HASHTABLE(link->notices);
183+
link->notices = NULL;
179184
}
180185
}
181186

@@ -293,48 +298,45 @@ static inline char * _php_pgsql_trim_result(PGconn * pgsql, char **buf)
293298

294299
static void php_pgsql_set_default_link(pgsql_link_handle *link)
295300
{
296-
if (PGG(default_link) != NULL) {
297-
pgsql_link_free(FETCH_DEFAULT_LINK());
298-
}
299-
300301
PGG(default_link) = link;
301302
}
302303

303304
static void _close_pgsql_plink(zend_resource *rsrc)
304305
{
305-
PGconn *link = (PGconn *)rsrc->ptr;
306-
PGresult *res;
306+
if (rsrc->ptr) {
307+
PGconn *link = (PGconn *)rsrc->ptr;
308+
PGresult *res;
307309

308-
while ((res = PQgetResult(link))) {
309-
PQclear(res);
310+
while ((res = PQgetResult(link))) {
311+
PQclear(res);
312+
}
313+
PQfinish(link);
314+
PGG(num_persistent)--;
315+
PGG(num_links)--;
316+
rsrc->ptr = NULL;
310317
}
311-
PQfinish(link);
312-
PGG(num_persistent)--;
313-
PGG(num_links)--;
314318
}
315319

316-
static void _php_pgsql_notice_handler(void *link, const char *message)
320+
static void _php_pgsql_notice_handler(void *l, const char *message)
317321
{
318-
HashTable *notices, tmp_notices;
322+
pgsql_link_handle *link;
319323
zval tmp;
320324
char *trimmed_message;
321325
size_t trimmed_message_len;
322326

323327
if (! PGG(ignore_notices)) {
324-
notices = ((pgsql_link_handle *) link)->notices;
325-
if (!notices) {
326-
zend_hash_init(&tmp_notices, 1, NULL, ZVAL_PTR_DTOR, 0);
327-
notices = &tmp_notices;
328+
link = ((pgsql_link_handle *) l);
329+
if (!link->notices) {
330+
link->notices = zend_new_array(1);
328331
}
329332
trimmed_message = _php_pgsql_trim_message(message, &trimmed_message_len);
330333
if (PGG(log_notices)) {
331334
php_error_docref(NULL, E_NOTICE, "%s", trimmed_message);
332335
}
333336

334337
ZVAL_STRINGL(&tmp, trimmed_message, trimmed_message_len);
335-
zend_hash_next_index_insert(notices, &tmp);
338+
zend_hash_next_index_insert(link->notices, &tmp);
336339
efree(trimmed_message);
337-
zval_ptr_dtor(&tmp);
338340
}
339341
}
340342

@@ -344,8 +346,9 @@ static int _rollback_transactions(zval *el)
344346
PGresult *res;
345347
zend_resource *rsrc = Z_RES_P(el);
346348

347-
if (rsrc->type != le_plink)
348-
return 0;
349+
if (rsrc->type != le_plink) {
350+
return ZEND_HASH_APPLY_KEEP;
351+
}
349352

350353
link = (PGconn *) rsrc->ptr;
351354

@@ -365,7 +368,7 @@ static int _rollback_transactions(zval *el)
365368
PGG(ignore_notices) = orig;
366369
}
367370

368-
return 0;
371+
return ZEND_HASH_APPLY_KEEP;
369372
}
370373

371374
static void _free_ptr(zend_resource *rsrc)
@@ -413,7 +416,6 @@ static PHP_GINIT_FUNCTION(pgsql)
413416
ZEND_TSRMLS_CACHE_UPDATE();
414417
#endif
415418
memset(pgsql_globals, 0, sizeof(zend_pgsql_globals));
416-
/* Initialize notice message hash at MINIT only */
417419
zend_hash_init(&pgsql_globals->regular_list, 0, NULL, ZVAL_PTR_DTOR, 1);
418420
}
419421

@@ -599,8 +601,6 @@ PHP_RINIT_FUNCTION(pgsql)
599601

600602
PHP_RSHUTDOWN_FUNCTION(pgsql)
601603
{
602-
/* clean up notice messages */
603-
zend_hash_clean(&PGG(regular_list));
604604
/* clean up persistent connection */
605605
zend_hash_apply(&EG(persistent_list), (apply_func_t) _rollback_transactions);
606606
return SUCCESS;
@@ -720,6 +720,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
720720
link->conn = pgsql;
721721
link->hash = zend_string_copy(str.s);
722722
link->notices = NULL;
723+
link->persistent = 1;
723724
} else { /* Non persistent connection */
724725
zval *index_ptr, new_index_ptr;
725726

@@ -767,6 +768,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
767768
link->conn = pgsql;
768769
link->hash = zend_string_copy(str.s);
769770
link->notices = NULL;
771+
link->persistent = 0;
770772

771773
/* add it to the hash */
772774
ZVAL_COPY(&new_index_ptr, return_value);
@@ -844,15 +846,16 @@ PHP_FUNCTION(pg_close)
844846
if (!pgsql_link) {
845847
link = FETCH_DEFAULT_LINK();
846848
CHECK_DEFAULT_LINK(link);
849+
zend_hash_del(&PGG(regular_list), link->hash);
847850
PGG(default_link) = NULL;
848-
pgsql_link_free(link);
849851
RETURN_TRUE;
850852
}
851853

852854
link = Z_PGSQL_LINK_P(pgsql_link);
853855
CHECK_PGSQL_LINK(link);
854856

855857
if (link == FETCH_DEFAULT_LINK()) {
858+
zend_hash_del(&PGG(regular_list), link->hash);
856859
PGG(default_link) = NULL;
857860
}
858861
pgsql_link_free(link);
@@ -3372,7 +3375,6 @@ PHP_FUNCTION(pg_escape_bytea)
33723375
RETURN_THROWS();
33733376
}
33743377
link = FETCH_DEFAULT_LINK();
3375-
CHECK_DEFAULT_LINK(link);
33763378
break;
33773379
default:
33783380
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &pgsql_link, pgsql_link_ce, &from, &from_len) == FAILURE) {

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: 4 additions & 4 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);
@@ -22,5 +22,5 @@ echo "Done".PHP_EOL;
2222

2323
?>
2424
--EXPECT--
25-
3,5
25+
3.5
2626
Done

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)