@@ -174,6 +174,9 @@ static void pgsql_link_free(pgsql_link_handle *link)
174
174
175
175
link -> conn = NULL ;
176
176
zend_string_release (link -> hash );
177
+ if (link -> notices ) {
178
+ zend_hash_destroy (link -> notices );
179
+ }
177
180
}
178
181
179
182
static void pgsql_link_free_obj (zend_object * obj )
@@ -310,26 +313,28 @@ static void _close_pgsql_plink(zend_resource *rsrc)
310
313
PGG (num_links )-- ;
311
314
}
312
315
313
- static void _php_pgsql_notice_handler (void * resource_id , const char * message )
316
+ static void _php_pgsql_notice_handler (void * link , const char * message )
314
317
{
315
- zval * notices ;
318
+ HashTable * notices , tmp_notices ;
316
319
zval tmp ;
317
- char * trimed_message ;
318
- size_t trimed_message_len ;
320
+ char * trimmed_message ;
321
+ size_t trimmed_message_len ;
319
322
320
323
if (! PGG (ignore_notices )) {
321
- notices = zend_hash_index_find ( & PGG ( notices ), ( zend_ulong ) resource_id ) ;
324
+ notices = (( pgsql_link_handle * ) link ) -> notices ;
322
325
if (!notices ) {
323
- array_init (& tmp );
324
- notices = & tmp ;
325
- zend_hash_index_update (& PGG (notices ), (zend_ulong )resource_id , notices );
326
+ zend_hash_init (& tmp_notices , 1 , NULL , ZVAL_PTR_DTOR , 0 );
327
+ notices = & tmp_notices ;
326
328
}
327
- trimed_message = _php_pgsql_trim_message (message , & trimed_message_len );
329
+ trimmed_message = _php_pgsql_trim_message (message , & trimmed_message_len );
328
330
if (PGG (log_notices )) {
329
- php_error_docref (NULL , E_NOTICE , "%s" , trimed_message );
331
+ php_error_docref (NULL , E_NOTICE , "%s" , trimmed_message );
330
332
}
331
- add_next_index_stringl (notices , trimed_message , trimed_message_len );
332
- efree (trimed_message );
333
+
334
+ ZVAL_STRINGL (& tmp , trimmed_message , trimmed_message_len );
335
+ zend_hash_next_index_insert (notices , & tmp );
336
+ efree (trimmed_message );
337
+ zval_ptr_dtor (& tmp );
333
338
}
334
339
}
335
340
@@ -409,7 +414,6 @@ static PHP_GINIT_FUNCTION(pgsql)
409
414
#endif
410
415
memset (pgsql_globals , 0 , sizeof (zend_pgsql_globals ));
411
416
/* Initialize notice message hash at MINIT only */
412
- zend_hash_init (& pgsql_globals -> notices , 0 , NULL , ZVAL_PTR_DTOR , 1 );
413
417
zend_hash_init (& pgsql_globals -> regular_list , 0 , NULL , ZVAL_PTR_DTOR , 1 );
414
418
}
415
419
@@ -581,7 +585,6 @@ PHP_MINIT_FUNCTION(pgsql)
581
585
PHP_MSHUTDOWN_FUNCTION (pgsql )
582
586
{
583
587
UNREGISTER_INI_ENTRIES ();
584
- zend_hash_destroy (& PGG (notices ));
585
588
zend_hash_destroy (& PGG (regular_list ));
586
589
587
590
return SUCCESS ;
@@ -597,7 +600,6 @@ PHP_RINIT_FUNCTION(pgsql)
597
600
PHP_RSHUTDOWN_FUNCTION (pgsql )
598
601
{
599
602
/* clean up notice messages */
600
- zend_hash_clean (& PGG (notices ));
601
603
zend_hash_clean (& PGG (regular_list ));
602
604
/* clean up persistent connection */
603
605
zend_hash_apply (& EG (persistent_list ), (apply_func_t ) _rollback_transactions );
@@ -716,6 +718,8 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
716
718
object_init_ex (return_value , pgsql_link_ce );
717
719
link = Z_PGSQL_LINK_P (return_value );
718
720
link -> conn = pgsql ;
721
+ link -> hash = zend_string_copy (str .s );
722
+ link -> notices = NULL ;
719
723
} else { /* Non persistent connection */
720
724
zval * index_ptr , new_index_ptr ;
721
725
@@ -762,6 +766,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
762
766
link = Z_PGSQL_LINK_P (return_value );
763
767
link -> conn = pgsql ;
764
768
link -> hash = zend_string_copy (str .s );
769
+ link -> notices = NULL ;
765
770
766
771
/* add it to the hash */
767
772
ZVAL_COPY (& new_index_ptr , return_value );
@@ -776,9 +781,9 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
776
781
}
777
782
/* set notice processor */
778
783
if (! PGG (ignore_notices ) && Z_TYPE_P (return_value ) == IS_OBJECT ) {
779
- PQsetNoticeProcessor (pgsql , _php_pgsql_notice_handler , ( void * )( zend_uintptr_t ) Z_OBJ_P ( return_value ) -> handle );
784
+ PQsetNoticeProcessor (pgsql , _php_pgsql_notice_handler , link );
780
785
}
781
- php_pgsql_set_default_link (pgsql_link_from_obj ( Z_OBJ_P ( return_value )) );
786
+ php_pgsql_set_default_link (link );
782
787
783
788
cleanup :
784
789
smart_str_free (& str );
@@ -1497,7 +1502,8 @@ PHP_FUNCTION(pg_affected_rows)
1497
1502
PHP_FUNCTION (pg_last_notice )
1498
1503
{
1499
1504
zval * pgsql_link = NULL ;
1500
- zval * notice , * notices ;
1505
+ zval * notice ;
1506
+ HashTable * notices ;
1501
1507
pgsql_link_handle * link ;
1502
1508
zend_long option = PGSQL_NOTICE_LAST ;
1503
1509
@@ -1508,12 +1514,12 @@ PHP_FUNCTION(pg_last_notice)
1508
1514
link = Z_PGSQL_LINK_P (pgsql_link );
1509
1515
CHECK_PGSQL_LINK (link );
1510
1516
1511
- notices = zend_hash_index_find ( & PGG ( notices ), ( zend_ulong ) Z_OBJ_P ( pgsql_link ) -> handle ) ;
1517
+ notices = link -> notices ;
1512
1518
switch (option ) {
1513
1519
case PGSQL_NOTICE_LAST :
1514
1520
if (notices ) {
1515
- zend_hash_internal_pointer_end (Z_ARRVAL_P ( notices ) );
1516
- if ((notice = zend_hash_get_current_data (Z_ARRVAL_P ( notices ) )) == NULL ) {
1521
+ zend_hash_internal_pointer_end (notices );
1522
+ if ((notice = zend_hash_get_current_data (notices )) == NULL ) {
1517
1523
RETURN_EMPTY_STRING ();
1518
1524
}
1519
1525
RETURN_COPY (notice );
@@ -1523,15 +1529,15 @@ PHP_FUNCTION(pg_last_notice)
1523
1529
break ;
1524
1530
case PGSQL_NOTICE_ALL :
1525
1531
if (notices ) {
1526
- RETURN_COPY ( notices );
1532
+ RETURN_ARR ( zend_array_dup ( notices ) );
1527
1533
} else {
1528
1534
array_init (return_value );
1529
1535
return ;
1530
1536
}
1531
1537
break ;
1532
1538
case PGSQL_NOTICE_CLEAR :
1533
1539
if (notices ) {
1534
- zend_hash_clean (& PGG ( notices ) );
1540
+ zend_hash_clean (link -> notices );
1535
1541
}
1536
1542
RETURN_TRUE ;
1537
1543
break ;
0 commit comments