@@ -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 )
@@ -307,26 +310,28 @@ static void _close_pgsql_plink(zend_resource *rsrc)
307
310
PGG (num_links )-- ;
308
311
}
309
312
310
- static void _php_pgsql_notice_handler (void * resource_id , const char * message )
313
+ static void _php_pgsql_notice_handler (void * link , const char * message )
311
314
{
312
- zval * notices ;
315
+ HashTable * notices , tmp_notices ;
313
316
zval tmp ;
314
- char * trimed_message ;
315
- size_t trimed_message_len ;
317
+ char * trimmed_message ;
318
+ size_t trimmed_message_len ;
316
319
317
320
if (! PGG (ignore_notices )) {
318
- notices = zend_hash_index_find ( & PGG ( notices ), ( zend_ulong ) resource_id ) ;
321
+ notices = (( pgsql_link_handle * ) link ) -> notices ;
319
322
if (!notices ) {
320
- array_init (& tmp );
321
- notices = & tmp ;
322
- zend_hash_index_update (& PGG (notices ), (zend_ulong )resource_id , notices );
323
+ zend_hash_init (& tmp_notices , 1 , NULL , ZVAL_PTR_DTOR , 0 );
324
+ notices = & tmp_notices ;
323
325
}
324
- trimed_message = _php_pgsql_trim_message (message , & trimed_message_len );
326
+ trimmed_message = _php_pgsql_trim_message (message , & trimmed_message_len );
325
327
if (PGG (log_notices )) {
326
- php_error_docref (NULL , E_NOTICE , "%s" , trimed_message );
328
+ php_error_docref (NULL , E_NOTICE , "%s" , trimmed_message );
327
329
}
328
- add_next_index_stringl (notices , trimed_message , trimed_message_len );
329
- efree (trimed_message );
330
+
331
+ ZVAL_STRINGL (& tmp , trimmed_message , trimmed_message_len );
332
+ zend_hash_next_index_insert (notices , & tmp );
333
+ efree (trimmed_message );
334
+ zval_ptr_dtor (& tmp );
330
335
}
331
336
}
332
337
@@ -406,7 +411,6 @@ static PHP_GINIT_FUNCTION(pgsql)
406
411
#endif
407
412
memset (pgsql_globals , 0 , sizeof (zend_pgsql_globals ));
408
413
/* Initialize notice message hash at MINIT only */
409
- zend_hash_init (& pgsql_globals -> notices , 0 , NULL , ZVAL_PTR_DTOR , 1 );
410
414
zend_hash_init (& pgsql_globals -> regular_list , 0 , NULL , ZVAL_PTR_DTOR , 1 );
411
415
}
412
416
@@ -578,7 +582,6 @@ PHP_MINIT_FUNCTION(pgsql)
578
582
PHP_MSHUTDOWN_FUNCTION (pgsql )
579
583
{
580
584
UNREGISTER_INI_ENTRIES ();
581
- zend_hash_destroy (& PGG (notices ));
582
585
zend_hash_destroy (& PGG (regular_list ));
583
586
584
587
return SUCCESS ;
@@ -594,7 +597,6 @@ PHP_RINIT_FUNCTION(pgsql)
594
597
PHP_RSHUTDOWN_FUNCTION (pgsql )
595
598
{
596
599
/* clean up notice messages */
597
- zend_hash_clean (& PGG (notices ));
598
600
zend_hash_clean (& PGG (regular_list ));
599
601
/* clean up persistent connection */
600
602
zend_hash_apply (& EG (persistent_list ), (apply_func_t ) _rollback_transactions );
@@ -713,6 +715,8 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
713
715
object_init_ex (return_value , pgsql_link_ce );
714
716
link = Z_PGSQL_LINK_P (return_value );
715
717
link -> conn = pgsql ;
718
+ link -> hash = zend_string_copy (str .s );
719
+ link -> notices = NULL ;
716
720
} else { /* Non persistent connection */
717
721
zval * index_ptr , new_index_ptr ;
718
722
@@ -759,6 +763,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
759
763
link = Z_PGSQL_LINK_P (return_value );
760
764
link -> conn = pgsql ;
761
765
link -> hash = zend_string_copy (str .s );
766
+ link -> notices = NULL ;
762
767
763
768
/* add it to the hash */
764
769
ZVAL_COPY (& new_index_ptr , return_value );
@@ -773,9 +778,9 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
773
778
}
774
779
/* set notice processor */
775
780
if (! PGG (ignore_notices ) && Z_TYPE_P (return_value ) == IS_OBJECT ) {
776
- PQsetNoticeProcessor (pgsql , _php_pgsql_notice_handler , ( void * )( zend_uintptr_t ) Z_OBJ_P ( return_value ) -> handle );
781
+ PQsetNoticeProcessor (pgsql , _php_pgsql_notice_handler , link );
777
782
}
778
- php_pgsql_set_default_link (pgsql_link_from_obj ( Z_OBJ_P ( return_value )) );
783
+ php_pgsql_set_default_link (link );
779
784
780
785
cleanup :
781
786
smart_str_free (& str );
@@ -1490,7 +1495,8 @@ PHP_FUNCTION(pg_affected_rows)
1490
1495
PHP_FUNCTION (pg_last_notice )
1491
1496
{
1492
1497
zval * pgsql_link = NULL ;
1493
- zval * notice , * notices ;
1498
+ zval * notice ;
1499
+ HashTable * notices ;
1494
1500
pgsql_link_handle * link ;
1495
1501
zend_long option = PGSQL_NOTICE_LAST ;
1496
1502
@@ -1501,12 +1507,12 @@ PHP_FUNCTION(pg_last_notice)
1501
1507
link = Z_PGSQL_LINK_P (pgsql_link );
1502
1508
CHECK_PGSQL_LINK (link );
1503
1509
1504
- notices = zend_hash_index_find ( & PGG ( notices ), ( zend_ulong ) Z_OBJ_P ( pgsql_link ) -> handle ) ;
1510
+ notices = link -> notices ;
1505
1511
switch (option ) {
1506
1512
case PGSQL_NOTICE_LAST :
1507
1513
if (notices ) {
1508
- zend_hash_internal_pointer_end (Z_ARRVAL_P ( notices ) );
1509
- if ((notice = zend_hash_get_current_data (Z_ARRVAL_P ( notices ) )) == NULL ) {
1514
+ zend_hash_internal_pointer_end (notices );
1515
+ if ((notice = zend_hash_get_current_data (notices )) == NULL ) {
1510
1516
RETURN_EMPTY_STRING ();
1511
1517
}
1512
1518
RETURN_COPY (notice );
@@ -1516,15 +1522,15 @@ PHP_FUNCTION(pg_last_notice)
1516
1522
break ;
1517
1523
case PGSQL_NOTICE_ALL :
1518
1524
if (notices ) {
1519
- RETURN_COPY ( notices );
1525
+ RETURN_ARR ( zend_array_dup ( notices ) );
1520
1526
} else {
1521
1527
array_init (return_value );
1522
1528
return ;
1523
1529
}
1524
1530
break ;
1525
1531
case PGSQL_NOTICE_CLEAR :
1526
1532
if (notices ) {
1527
- zend_hash_clean (& PGG ( notices ) );
1533
+ zend_hash_clean (link -> notices );
1528
1534
}
1529
1535
RETURN_TRUE ;
1530
1536
break ;
0 commit comments