Skip to content

Commit c7b13af

Browse files
committed
New test fixes
1 parent 47ea219 commit c7b13af

File tree

7 files changed

+59
-55
lines changed

7 files changed

+59
-55
lines changed

Zend/Optimizer/zend_func_info.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -658,19 +658,19 @@ static const func_info_t func_infos[] = {
658658
F1("session_encode", MAY_BE_FALSE | MAY_BE_STRING),
659659

660660
/* ext/pgsql */
661-
FN("pg_connect", MAY_BE_FALSE | MAY_BE_RESOURCE),
662-
FN("pg_pconnect", MAY_BE_FALSE | MAY_BE_RESOURCE),
661+
FN("pg_connect", MAY_BE_FALSE | MAY_BE_OBJECT),
662+
FN("pg_pconnect", MAY_BE_FALSE | MAY_BE_OBJECT),
663663
F1("pg_dbname", MAY_BE_STRING),
664664
F1("pg_options", MAY_BE_STRING),
665665
F1("pg_port", MAY_BE_STRING),
666666
F1("pg_tty", MAY_BE_STRING),
667667
F1("pg_host", MAY_BE_STRING),
668668
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),
669669
F1("pg_parameter_status", MAY_BE_FALSE | MAY_BE_STRING),
670-
F1("pg_query", MAY_BE_FALSE | MAY_BE_RESOURCE),
671-
F1("pg_query_params", MAY_BE_FALSE | MAY_BE_RESOURCE),
672-
F1("pg_prepare", MAY_BE_FALSE | MAY_BE_RESOURCE),
673-
F1("pg_execute", MAY_BE_FALSE | MAY_BE_RESOURCE),
670+
F1("pg_query", MAY_BE_FALSE | MAY_BE_OBJECT),
671+
F1("pg_query_params", MAY_BE_FALSE | MAY_BE_OBJECT),
672+
F1("pg_prepare", MAY_BE_FALSE | MAY_BE_OBJECT),
673+
F1("pg_execute", MAY_BE_FALSE | MAY_BE_OBJECT),
674674
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 ),
675675
F1("pg_field_name", MAY_BE_STRING),
676676
F1("pg_field_type_oid", MAY_BE_LONG | MAY_BE_STRING),
@@ -683,7 +683,7 @@ static const func_info_t func_infos[] = {
683683
F1("pg_fetch_all_columns", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_NULL | MAY_BE_ARRAY_OF_STRING),
684684
F1("pg_last_oid", MAY_BE_FALSE | MAY_BE_LONG | MAY_BE_STRING),
685685
F1("pg_lo_create", MAY_BE_FALSE | MAY_BE_LONG | MAY_BE_STRING),
686-
F1("pg_lo_open", MAY_BE_FALSE | MAY_BE_RESOURCE),
686+
F1("pg_lo_open", MAY_BE_FALSE | MAY_BE_OBJECT),
687687
F1("pg_lo_read", MAY_BE_FALSE | MAY_BE_STRING),
688688
F1("pg_lo_import", MAY_BE_FALSE | MAY_BE_LONG | MAY_BE_STRING),
689689
F1("pg_copy_to", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_STRING),
@@ -694,13 +694,13 @@ static const func_info_t func_infos[] = {
694694
F1("pg_escape_identifier", MAY_BE_FALSE | MAY_BE_STRING),
695695
F1("pg_result_error", MAY_BE_FALSE | MAY_BE_STRING),
696696
F1("pg_result_error_field", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_STRING),
697-
F1("pg_get_result", MAY_BE_FALSE | MAY_BE_RESOURCE),
697+
F1("pg_get_result", MAY_BE_FALSE | MAY_BE_OBJECT),
698698
F1("pg_result_status", MAY_BE_LONG | MAY_BE_STRING),
699699
F1("pg_get_notify", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY),
700-
F1("pg_socket", MAY_BE_FALSE | MAY_BE_RESOURCE),
700+
F1("pg_socket", MAY_BE_FALSE | MAY_BE_OBJECT),
701701
F1("pg_meta_data", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_ARRAY),
702702
F1("pg_convert", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_ANY),
703-
F1("pg_insert", MAY_BE_FALSE | MAY_BE_TRUE | MAY_BE_RESOURCE | MAY_BE_STRING),
703+
F1("pg_insert", MAY_BE_FALSE | MAY_BE_TRUE | MAY_BE_OBJECT | MAY_BE_STRING),
704704
F1("pg_update", MAY_BE_FALSE | MAY_BE_TRUE | MAY_BE_STRING),
705705
F1("pg_delete", MAY_BE_FALSE | MAY_BE_TRUE | MAY_BE_STRING),
706706
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: 32 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

@@ -281,46 +286,46 @@ static zend_string *_php_pgsql_trim_message(const char *message)
281286

282287
static void php_pgsql_set_default_link(pgsql_link_handle *link)
283288
{
284-
if (PGG(default_link) != NULL) {
285-
pgsql_link_free(FETCH_DEFAULT_LINK());
286-
}
287-
288289
PGG(default_link) = link;
289290
}
290291

291292
static void _close_pgsql_plink(zend_resource *rsrc)
292293
{
293-
PGconn *link = (PGconn *)rsrc->ptr;
294-
PGresult *res;
294+
if (rsrc->ptr) {
295+
PGconn *link = (PGconn *)rsrc->ptr;
296+
PGresult *res;
295297

296-
while ((res = PQgetResult(link))) {
297-
PQclear(res);
298+
while ((res = PQgetResult(link))) {
299+
PQclear(res);
300+
}
301+
PQfinish(link);
302+
PGG(num_persistent)--;
303+
PGG(num_links)--;
304+
rsrc->ptr = NULL;
298305
}
299-
PQfinish(link);
300-
PGG(num_persistent)--;
301-
PGG(num_links)--;
302306
}
303307

304-
static void _php_pgsql_notice_handler(void *link, const char *message)
308+
static void _php_pgsql_notice_handler(void *l, const char *message)
305309
{
306310
if (PGG(ignore_notices)) {
307311
return;
308312
}
309313

314+
pgsql_link_handle *link;
310315
HashTable *notices, tmp_notices;
311316
zval tmp;
312-
zval *notices = notices = ((pgsql_link_handle *) link)->notices;
313-
if (!notices) {
314-
array_init(&tmp);
315-
notices = &tmp;
316-
zend_hash_index_update(&PGG(notices), (zend_ulong)resource_id, notices);
317+
318+
link = ((pgsql_link_handle *) l);
319+
if (!link->notices) {
320+
link->notices = zend_new_array(1);
317321
}
318322

319323
zend_string *trimmed_message = _php_pgsql_trim_message(message);
320324
if (PGG(log_notices)) {
321325
php_error_docref(NULL, E_NOTICE, "%s", ZSTR_VAL(trimmed_message));
322326
}
323-
add_next_index_str(notices, trimmed_message);
327+
328+
add_next_index_str(link->notices, trimmed_message);
324329
}
325330

326331
static int _rollback_transactions(zval *el)
@@ -329,8 +334,9 @@ static int _rollback_transactions(zval *el)
329334
PGresult *res;
330335
zend_resource *rsrc = Z_RES_P(el);
331336

332-
if (rsrc->type != le_plink)
333-
return 0;
337+
if (rsrc->type != le_plink) {
338+
return ZEND_HASH_APPLY_KEEP;
339+
}
334340

335341
link = (PGconn *) rsrc->ptr;
336342

@@ -350,7 +356,7 @@ static int _rollback_transactions(zval *el)
350356
PGG(ignore_notices) = orig;
351357
}
352358

353-
return 0;
359+
return ZEND_HASH_APPLY_KEEP;
354360
}
355361

356362
static void _free_ptr(zend_resource *rsrc)
@@ -403,7 +409,6 @@ static PHP_GINIT_FUNCTION(pgsql)
403409
ZEND_TSRMLS_CACHE_UPDATE();
404410
#endif
405411
memset(pgsql_globals, 0, sizeof(zend_pgsql_globals));
406-
/* Initialize notice message hash at MINIT only */
407412
zend_hash_init(&pgsql_globals->regular_list, 0, NULL, ZVAL_PTR_DTOR, 1);
408413
}
409414

@@ -590,11 +595,8 @@ PHP_RINIT_FUNCTION(pgsql)
590595

591596
PHP_RSHUTDOWN_FUNCTION(pgsql)
592597
{
593-
/* clean up notice messages */
594-
zend_hash_clean(&PGG(hashes));
595598
zend_hash_destroy(&PGG(field_oids));
596599
zend_hash_destroy(&PGG(table_oids));
597-
zend_hash_clean(&PGG(regular_list));
598600
/* clean up persistent connection */
599601
zend_hash_apply(&EG(persistent_list), (apply_func_t) _rollback_transactions);
600602
return SUCCESS;
@@ -714,6 +716,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
714716
link->conn = pgsql;
715717
link->hash = zend_string_copy(str.s);
716718
link->notices = NULL;
719+
link->persistent = 1;
717720
} else { /* Non persistent connection */
718721
zval *index_ptr, new_index_ptr;
719722

@@ -761,6 +764,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
761764
link->conn = pgsql;
762765
link->hash = zend_string_copy(str.s);
763766
link->notices = NULL;
767+
link->persistent = 0;
764768

765769
/* add it to the hash */
766770
ZVAL_COPY(&new_index_ptr, return_value);
@@ -838,15 +842,16 @@ PHP_FUNCTION(pg_close)
838842
if (!pgsql_link) {
839843
link = FETCH_DEFAULT_LINK();
840844
CHECK_DEFAULT_LINK(link);
845+
zend_hash_del(&PGG(regular_list), link->hash);
841846
PGG(default_link) = NULL;
842-
pgsql_link_free(link);
843847
RETURN_TRUE;
844848
}
845849

846850
link = Z_PGSQL_LINK_P(pgsql_link);
847851
CHECK_PGSQL_LINK(link);
848852

849853
if (link == FETCH_DEFAULT_LINK()) {
854+
zend_hash_del(&PGG(regular_list), link->hash);
850855
PGG(default_link) = NULL;
851856
}
852857
pgsql_link_free(link);
@@ -3328,7 +3333,6 @@ PHP_FUNCTION(pg_escape_bytea)
33283333
RETURN_THROWS();
33293334
}
33303335
link = FETCH_DEFAULT_LINK();
3331-
CHECK_DEFAULT_LINK(link);
33323336
break;
33333337
default:
33343338
if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS", &pgsql_link, pgsql_link_ce, &from) == FAILURE) {
@@ -5643,7 +5647,6 @@ PHP_FUNCTION(pg_update)
56435647
zval *pgsql_link, *values, *ids;
56445648
pgsql_link_handle *link;
56455649
zend_string *table;
5646-
size_t table_len;
56475650
zend_ulong option = PGSQL_DML_EXEC;
56485651
PGconn *pg_link;
56495652
zend_string *sql = NULL;

ext/pgsql/php_pgsql.h

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

153154
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)