58
58
#define MEMC_G (v ) (php_memcached_globals.memc.v)
59
59
#endif
60
60
61
- static
62
- int le_memc ;
61
+ static int le_memc ;
63
62
64
- static
65
- int php_memc_list_entry (void )
66
- {
63
+ static int php_memc_list_entry (void ) {
67
64
return le_memc ;
68
65
}
69
66
@@ -379,8 +376,7 @@ static void php_memc_deleteMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by
379
376
static void php_memc_getDelayed_impl (INTERNAL_FUNCTION_PARAMETERS , zend_bool by_key );
380
377
381
378
/* Invoke PHP functions */
382
- static
383
- zend_bool s_invoke_cache_callback (zval * zobject , zend_fcall_info * fci , zend_fcall_info_cache * fcc , zend_string * key , zval * value );
379
+ static zend_bool s_invoke_cache_callback (zval * zobject , zend_fcall_info * fci , zend_fcall_info_cache * fcc , zend_string * key , zval * value );
384
380
385
381
/* Iterate result sets */
386
382
typedef zend_bool (* php_memc_result_apply_fn )(php_memc_object_t * intern , zend_string * key , zval * value , zval * cas , uint32_t flags , void * context );
@@ -655,7 +651,6 @@ zend_bool php_memc_mget_apply(php_memc_object_t *intern, zend_string *server_key
655
651
php_memc_result_apply_fn result_apply_fn , zend_bool with_cas , void * context )
656
652
{
657
653
memcached_return status ;
658
- memcached_result_st result ;
659
654
int mget_status ;
660
655
uint64_t orig_cas_flag = 0 ;
661
656
@@ -715,17 +710,19 @@ static
715
710
zend_bool s_invoke_new_instance_cb (zval * object , zend_fcall_info * fci , zend_fcall_info_cache * fci_cache , zend_string * persistent_id )
716
711
{
717
712
zend_bool ret = 1 ;
718
- zval retval , id ;
713
+ zval retval ;
714
+ zval params [2 ];
719
715
716
+ ZVAL_COPY (& params [0 ], object );
720
717
if (persistent_id ) {
721
- ZVAL_STR (& id , persistent_id );
718
+ ZVAL_STR (& params [ 1 ], zend_string_copy ( persistent_id ) );
722
719
} else {
723
- ZVAL_NULL (& id );
720
+ ZVAL_NULL (& params [ 1 ] );
724
721
}
725
722
726
- zend_fcall_info_argn ( fci , 2 , object , & id ) ;
727
- fci -> retval = & retval ;
728
- fci -> no_separation = 1 ;
723
+ fci -> retval = & retval ;
724
+ fci -> params = params ;
725
+ fci -> param_count = 2 ;
729
726
730
727
if (zend_call_function (fci , fci_cache ) == FAILURE ) {
731
728
char * buf = php_memc_printable_func (fci , fci_cache );
@@ -734,67 +731,50 @@ zend_bool s_invoke_new_instance_cb(zval *object, zend_fcall_info *fci, zend_fcal
734
731
ret = 0 ;
735
732
}
736
733
737
- if ( Z_TYPE ( retval ) != IS_UNDEF ) {
738
- zval_ptr_dtor (& retval );
739
- }
734
+ zval_ptr_dtor ( & params [ 0 ]);
735
+ zval_ptr_dtor (& params [ 1 ] );
736
+ zval_ptr_dtor ( & retval );
740
737
741
- if (EG (exception )) {
742
- ret = 0 ;
743
- }
744
-
745
- zend_fcall_info_args_clear (fci , 1 );
746
738
return ret ;
747
739
}
748
740
749
741
static
750
742
zend_bool s_invoke_cache_callback (zval * zobject , zend_fcall_info * fci , zend_fcall_info_cache * fcc , zend_string * key , zval * value )
751
743
{
752
- memcached_return rc ;
753
744
zend_bool status = 0 ;
754
-
755
745
zval params [4 ];
756
746
zval retval ;
757
- zval zv_key , ref_val ;
758
- zval ref_expiration , zv_expiration ;
759
747
php_memc_object_t * intern = Z_MEMC_OBJ_P (zobject );
760
748
761
749
/* Prepare params */
762
- ZVAL_STR (& zv_key , key );
763
-
764
- ZVAL_NULL (& ref_val );
765
- ZVAL_NULL (& zv_expiration );
766
-
767
- ZVAL_NEW_REF (& ref_val , value );
768
- ZVAL_NEW_REF (& ref_expiration , & zv_expiration );
769
-
770
750
ZVAL_COPY (& params [0 ], zobject );
771
- ZVAL_COPY (& params [1 ], & zv_key );
772
- ZVAL_COPY_VALUE (& params [2 ], & ref_val );
773
- ZVAL_COPY_VALUE (& params [3 ], & ref_expiration );
751
+ ZVAL_STR (& params [1 ], zend_string_copy (key )); /* key */
752
+ ZVAL_NEW_REF (& params [2 ], value ); /* value */
753
+ ZVAL_NEW_EMPTY_REF (& params [3 ]); /* expiration */
754
+ ZVAL_NULL (Z_REFVAL (params [3 ]));
774
755
775
756
fci -> retval = & retval ;
776
757
fci -> params = params ;
777
758
fci -> param_count = 4 ;
778
759
779
760
if (zend_call_function (fci , fcc ) == SUCCESS ) {
780
761
if (zend_is_true (& retval )) {
781
- time_t expiration = zval_get_long (Z_REFVAL (ref_expiration ));
782
- status = s_memc_write_zval (intern , MEMC_OP_SET , NULL , key , Z_REFVAL (ref_val ), expiration );
783
- ZVAL_DUP (value , Z_REFVAL (ref_val ));
762
+ time_t expiration = zval_get_long (Z_REFVAL (params [3 ]));
763
+ status = s_memc_write_zval (intern , MEMC_OP_SET , NULL , key , Z_REFVAL (params [2 ]), expiration );
764
+ /* memleak? zval_ptr_dtor(value); */
765
+ ZVAL_COPY (value , Z_REFVAL (params [2 ]));
784
766
}
785
767
}
786
768
else {
787
769
s_memc_set_status (intern , MEMCACHED_NOTFOUND , 0 );
788
770
}
789
771
790
- zval_ptr_dtor (zobject );
791
- zval_ptr_dtor (& zv_key );
792
- zval_ptr_dtor (& ref_val );
793
- zval_ptr_dtor (& ref_expiration );
772
+ zval_ptr_dtor (& params [0 ]);
773
+ zval_ptr_dtor (& params [1 ]);
774
+ zval_ptr_dtor (& params [2 ]);
775
+ zval_ptr_dtor (& params [3 ]);
776
+ zval_ptr_dtor (& retval );
794
777
795
- if (!Z_ISUNDEF (retval )) {
796
- zval_ptr_dtor (& retval );
797
- }
798
778
return status ;
799
779
}
800
780
@@ -1388,7 +1368,7 @@ void php_memc_get_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key)
1388
1368
zend_long get_flags = 0 ;
1389
1369
zend_string * key ;
1390
1370
zend_string * server_key = NULL ;
1391
- zend_bool extended , mget_status ;
1371
+ zend_bool mget_status ;
1392
1372
memcached_return status = MEMCACHED_SUCCESS ;
1393
1373
zend_fcall_info fci = empty_fcall_info ;
1394
1374
zend_fcall_info_cache fcc = empty_fcall_info_cache ;
@@ -1484,8 +1464,7 @@ static void php_memc_getMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke
1484
1464
zend_string * server_key = NULL ;
1485
1465
zend_long flags = 0 ;
1486
1466
MEMC_METHOD_INIT_VARS ;
1487
-
1488
- zend_bool with_cas , retval , preserve_order , extended ;
1467
+ zend_bool retval , preserve_order ;
1489
1468
1490
1469
if (by_key ) {
1491
1470
if (zend_parse_parameters (ZEND_NUM_ARGS (), "Sa|l" , & server_key ,
@@ -1574,32 +1553,29 @@ static
1574
1553
zend_bool s_result_callback_apply (php_memc_object_t * intern , zend_string * key , zval * value , zval * cas , uint32_t flags , void * in_context )
1575
1554
{
1576
1555
zend_bool status = 1 ;
1577
-
1578
- zval retval , zv_result ;
1556
+ zval params [ 2 ];
1557
+ zval retval ;
1579
1558
php_memc_result_callback_ctx_t * context = (php_memc_result_callback_ctx_t * ) in_context ;
1580
1559
1581
- array_init ( & zv_result );
1582
- s_create_result_array ( key , value , cas , flags , & zv_result );
1560
+ ZVAL_COPY ( & params [ 0 ], context -> object );
1561
+ array_init ( & params [ 1 ] );
1583
1562
1584
- zend_fcall_info_argn ( & context -> fci , 2 , context -> object , & zv_result );
1563
+ s_create_result_array ( key , value , cas , flags , & params [ 1 ] );
1585
1564
1586
1565
context -> fci .retval = & retval ;
1566
+ context -> fci .params = params ;
1587
1567
context -> fci .param_count = 2 ;
1588
1568
1589
1569
if (zend_call_function (& context -> fci , & context -> fcc ) == FAILURE ) {
1590
- if (Z_TYPE (retval ) != IS_UNDEF ) {
1591
- zval_ptr_dtor (& retval );
1592
- }
1593
1570
php_error_docref (NULL , E_WARNING , "could not invoke result callback" );
1594
1571
status = 0 ;
1595
1572
}
1596
1573
1597
- if (Z_TYPE (retval ) != IS_UNDEF ) {
1598
- zval_ptr_dtor (& retval );
1599
- }
1574
+ zval_ptr_dtor (& retval );
1575
+
1576
+ zval_ptr_dtor (& params [0 ]);
1577
+ zval_ptr_dtor (& params [1 ]);
1600
1578
1601
- zend_fcall_info_args_clear (& context -> fci , 2 );
1602
- zval_ptr_dtor (& zv_result );
1603
1579
return status ;
1604
1580
}
1605
1581
@@ -1663,14 +1639,6 @@ zend_bool s_fetch_apply(php_memc_object_t *intern, zend_string *key, zval *value
1663
1639
Returns the next result from a previous delayed request */
1664
1640
PHP_METHOD (Memcached , fetch )
1665
1641
{
1666
- const char * res_key = NULL ;
1667
- size_t res_key_len = 0 ;
1668
- const char * payload = NULL ;
1669
- size_t payload_len = 0 ;
1670
- uint32_t flags = 0 ;
1671
- uint64_t cas = 0 ;
1672
- zval value , zv_cas ;
1673
- memcached_result_st result ;
1674
1642
memcached_return status = MEMCACHED_SUCCESS ;
1675
1643
MEMC_METHOD_INIT_VARS ;
1676
1644
@@ -1708,14 +1676,6 @@ zend_bool s_fetch_all_apply(php_memc_object_t *intern, zend_string *key, zval *v
1708
1676
Returns all the results from a previous delayed request */
1709
1677
PHP_METHOD (Memcached , fetchAll )
1710
1678
{
1711
- const char * res_key = NULL ;
1712
- size_t res_key_len = 0 ;
1713
- const char * payload = NULL ;
1714
- size_t payload_len = 0 ;
1715
- uint32_t flags ;
1716
- uint64_t cas = 0 ;
1717
- zval value , entry , zv_cas ;
1718
- memcached_result_st result ;
1719
1679
memcached_return status = MEMCACHED_SUCCESS ;
1720
1680
MEMC_METHOD_INIT_VARS ;
1721
1681
@@ -1794,13 +1754,8 @@ static void php_memc_setMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke
1794
1754
zend_string * server_key = NULL ;
1795
1755
time_t expiration = 0 ;
1796
1756
zval * value ;
1797
- zend_string * skey , * str_key = NULL ;
1798
- ulong num_key ;
1799
- zend_string * payload ;
1800
- uint32_t flags = 0 ;
1801
- uint32_t retry = 0 ;
1802
- memcached_return status ;
1803
- char tmp_key [MEMCACHED_MAX_KEY ];
1757
+ zend_string * skey ;
1758
+ zend_ulong num_key ;
1804
1759
int tmp_len = 0 ;
1805
1760
MEMC_METHOD_INIT_VARS ;
1806
1761
@@ -1918,10 +1873,6 @@ static void php_memc_store_impl(INTERNAL_FUNCTION_PARAMETERS, int op, zend_bool
1918
1873
zval s_zvalue ;
1919
1874
zval * value = NULL ;
1920
1875
zend_long expiration = 0 ;
1921
- zend_string * payload = NULL ;
1922
- uint32_t flags = 0 ;
1923
- uint32_t retry = 0 ;
1924
- memcached_return status ;
1925
1876
MEMC_METHOD_INIT_VARS ;
1926
1877
1927
1878
if (by_key ) {
@@ -2314,15 +2265,15 @@ PHP_METHOD(Memcached, addServer)
2314
2265
s_memc_set_status (intern , MEMCACHED_SUCCESS , 0 );
2315
2266
2316
2267
#if defined(LIBMEMCACHED_VERSION_HEX ) && LIBMEMCACHED_VERSION_HEX < 0x01000002
2317
- if (host -> val [0 ] == '/' ) { /* unix domain socket */
2318
- status = memcached_server_add_unix_socket_with_weight (intern -> memc , host -> val , weight );
2268
+ if (ZSTR_VAL ( host ) [0 ] == '/' ) { /* unix domain socket */
2269
+ status = memcached_server_add_unix_socket_with_weight (intern -> memc , ZSTR_VAL ( host ) , weight );
2319
2270
} else if (memcached_behavior_get (intern -> memc , MEMCACHED_BEHAVIOR_USE_UDP )) {
2320
- status = memcached_server_add_udp_with_weight (intern -> memc , host -> val , port , weight );
2271
+ status = memcached_server_add_udp_with_weight (intern -> memc , ZSTR_VAL ( host ) , port , weight );
2321
2272
} else {
2322
- status = memcached_server_add_with_weight (intern -> memc , host -> val , port , weight );
2273
+ status = memcached_server_add_with_weight (intern -> memc , ZSTR_VAL ( host ) , port , weight );
2323
2274
}
2324
2275
#else
2325
- status = memcached_server_add_with_weight (intern -> memc , host -> val , port , weight );
2276
+ status = memcached_server_add_with_weight (intern -> memc , ZSTR_VAL ( host ) , port , weight );
2326
2277
#endif
2327
2278
2328
2279
if (s_memc_status_handle_result_code (intern , status ) == FAILURE ) {
@@ -2409,7 +2360,7 @@ PHP_METHOD(Memcached, addServers)
2409
2360
}
2410
2361
i ++ ;
2411
2362
/* catch-all for all errors */
2412
- php_error_docref (NULL , E_WARNING , "could not add entry #%d to the server list" , i + 1 );
2363
+ php_error_docref (NULL , E_WARNING , "could not add entry #%d to the server list" , i + 1 );
2413
2364
} ZEND_HASH_FOREACH_END ();
2414
2365
2415
2366
status = memcached_server_push (intern -> memc , list );
0 commit comments