@@ -171,6 +171,9 @@ static void pgsql_link_free(pgsql_link_handle *link)
171
171
172
172
link -> conn = NULL ;
173
173
zend_string_release (link -> hash );
174
+ if (link -> notices ) {
175
+ zend_hash_destroy (link -> notices );
176
+ }
174
177
}
175
178
176
179
static void pgsql_link_free_obj (zend_object * obj )
@@ -298,14 +301,15 @@ static void _close_pgsql_plink(zend_resource *rsrc)
298
301
PGG (num_links )-- ;
299
302
}
300
303
301
- static void _php_pgsql_notice_handler (void * resource_id , const char * message )
304
+ static void _php_pgsql_notice_handler (void * link , const char * message )
302
305
{
303
306
if (PGG (ignore_notices )) {
304
307
return ;
305
308
}
306
309
310
+ HashTable * notices , tmp_notices ;
307
311
zval tmp ;
308
- zval * notices = zend_hash_index_find ( & PGG ( notices ), ( zend_ulong ) resource_id ) ;
312
+ zval * notices = notices = (( pgsql_link_handle * ) link ) -> notices ;
309
313
if (!notices ) {
310
314
array_init (& tmp );
311
315
notices = & tmp ;
@@ -400,7 +404,6 @@ static PHP_GINIT_FUNCTION(pgsql)
400
404
#endif
401
405
memset (pgsql_globals , 0 , sizeof (zend_pgsql_globals ));
402
406
/* Initialize notice message hash at MINIT only */
403
- zend_hash_init (& pgsql_globals -> notices , 0 , NULL , ZVAL_PTR_DTOR , 1 );
404
407
zend_hash_init (& pgsql_globals -> regular_list , 0 , NULL , ZVAL_PTR_DTOR , 1 );
405
408
}
406
409
@@ -571,7 +574,6 @@ PHP_MINIT_FUNCTION(pgsql)
571
574
PHP_MSHUTDOWN_FUNCTION (pgsql )
572
575
{
573
576
UNREGISTER_INI_ENTRIES ();
574
- zend_hash_destroy (& PGG (notices ));
575
577
zend_hash_destroy (& PGG (regular_list ));
576
578
577
579
return SUCCESS ;
@@ -589,7 +591,6 @@ PHP_RINIT_FUNCTION(pgsql)
589
591
PHP_RSHUTDOWN_FUNCTION (pgsql )
590
592
{
591
593
/* clean up notice messages */
592
- zend_hash_clean (& PGG (notices ));
593
594
zend_hash_clean (& PGG (hashes ));
594
595
zend_hash_destroy (& PGG (field_oids ));
595
596
zend_hash_destroy (& PGG (table_oids ));
@@ -711,6 +712,8 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
711
712
object_init_ex (return_value , pgsql_link_ce );
712
713
link = Z_PGSQL_LINK_P (return_value );
713
714
link -> conn = pgsql ;
715
+ link -> hash = zend_string_copy (str .s );
716
+ link -> notices = NULL ;
714
717
} else { /* Non persistent connection */
715
718
zval * index_ptr , new_index_ptr ;
716
719
@@ -757,6 +760,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
757
760
link = Z_PGSQL_LINK_P (return_value );
758
761
link -> conn = pgsql ;
759
762
link -> hash = zend_string_copy (str .s );
763
+ link -> notices = NULL ;
760
764
761
765
/* add it to the hash */
762
766
ZVAL_COPY (& new_index_ptr , return_value );
@@ -771,9 +775,9 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
771
775
}
772
776
/* set notice processor */
773
777
if (! PGG (ignore_notices ) && Z_TYPE_P (return_value ) == IS_OBJECT ) {
774
- PQsetNoticeProcessor (pgsql , _php_pgsql_notice_handler , ( void * )( zend_uintptr_t ) Z_OBJ_P ( return_value ) -> handle );
778
+ PQsetNoticeProcessor (pgsql , _php_pgsql_notice_handler , link );
775
779
}
776
- php_pgsql_set_default_link (pgsql_link_from_obj ( Z_OBJ_P ( return_value )) );
780
+ php_pgsql_set_default_link (link );
777
781
778
782
cleanup :
779
783
smart_str_free (& str );
@@ -1484,7 +1488,8 @@ PHP_FUNCTION(pg_affected_rows)
1484
1488
PHP_FUNCTION (pg_last_notice )
1485
1489
{
1486
1490
zval * pgsql_link = NULL ;
1487
- zval * notice , * notices ;
1491
+ zval * notice ;
1492
+ HashTable * notices ;
1488
1493
pgsql_link_handle * link ;
1489
1494
zend_long option = PGSQL_NOTICE_LAST ;
1490
1495
@@ -1495,12 +1500,12 @@ PHP_FUNCTION(pg_last_notice)
1495
1500
link = Z_PGSQL_LINK_P (pgsql_link );
1496
1501
CHECK_PGSQL_LINK (link );
1497
1502
1498
- notices = zend_hash_index_find ( & PGG ( notices ), ( zend_ulong ) Z_OBJ_P ( pgsql_link ) -> handle ) ;
1503
+ notices = link -> notices ;
1499
1504
switch (option ) {
1500
1505
case PGSQL_NOTICE_LAST :
1501
1506
if (notices ) {
1502
- zend_hash_internal_pointer_end (Z_ARRVAL_P ( notices ) );
1503
- if ((notice = zend_hash_get_current_data (Z_ARRVAL_P ( notices ) )) == NULL ) {
1507
+ zend_hash_internal_pointer_end (notices );
1508
+ if ((notice = zend_hash_get_current_data (notices )) == NULL ) {
1504
1509
RETURN_EMPTY_STRING ();
1505
1510
}
1506
1511
RETURN_COPY (notice );
@@ -1510,15 +1515,15 @@ PHP_FUNCTION(pg_last_notice)
1510
1515
break ;
1511
1516
case PGSQL_NOTICE_ALL :
1512
1517
if (notices ) {
1513
- RETURN_COPY ( notices );
1518
+ RETURN_ARR ( zend_array_dup ( notices ) );
1514
1519
} else {
1515
1520
array_init (return_value );
1516
1521
return ;
1517
1522
}
1518
1523
break ;
1519
1524
case PGSQL_NOTICE_CLEAR :
1520
1525
if (notices ) {
1521
- zend_hash_clean (& PGG ( notices ) );
1526
+ zend_hash_clean (link -> notices );
1522
1527
}
1523
1528
RETURN_TRUE ;
1524
1529
break ;
0 commit comments