Skip to content

Commit 09e1304

Browse files
committed
cleanup
1 parent 5949598 commit 09e1304

File tree

1 file changed

+47
-96
lines changed

1 file changed

+47
-96
lines changed

php_memcached.c

Lines changed: 47 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,9 @@
5858
#define MEMC_G(v) (php_memcached_globals.memc.v)
5959
#endif
6060

61-
static
62-
int le_memc;
61+
static int le_memc;
6362

64-
static
65-
int php_memc_list_entry(void)
66-
{
63+
static int php_memc_list_entry(void) {
6764
return le_memc;
6865
}
6966

@@ -379,8 +376,7 @@ static void php_memc_deleteMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by
379376
static void php_memc_getDelayed_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key);
380377

381378
/* 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);
384380

385381
/* Iterate result sets */
386382
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
655651
php_memc_result_apply_fn result_apply_fn, zend_bool with_cas, void *context)
656652
{
657653
memcached_return status;
658-
memcached_result_st result;
659654
int mget_status;
660655
uint64_t orig_cas_flag = 0;
661656

@@ -715,17 +710,19 @@ static
715710
zend_bool s_invoke_new_instance_cb(zval *object, zend_fcall_info *fci, zend_fcall_info_cache *fci_cache, zend_string *persistent_id)
716711
{
717712
zend_bool ret = 1;
718-
zval retval, id;
713+
zval retval;
714+
zval params[2];
719715

716+
ZVAL_COPY(&params[0], object);
720717
if (persistent_id) {
721-
ZVAL_STR(&id, persistent_id);
718+
ZVAL_STR(&params[1], zend_string_copy(persistent_id));
722719
} else {
723-
ZVAL_NULL(&id);
720+
ZVAL_NULL(&params[1]);
724721
}
725722

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;
729726

730727
if (zend_call_function(fci, fci_cache) == FAILURE) {
731728
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
734731
ret = 0;
735732
}
736733

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);
740737

741-
if (EG(exception)) {
742-
ret = 0;
743-
}
744-
745-
zend_fcall_info_args_clear(fci, 1);
746738
return ret;
747739
}
748740

749741
static
750742
zend_bool s_invoke_cache_callback(zval *zobject, zend_fcall_info *fci, zend_fcall_info_cache *fcc, zend_string *key, zval *value)
751743
{
752-
memcached_return rc;
753744
zend_bool status = 0;
754-
755745
zval params[4];
756746
zval retval;
757-
zval zv_key, ref_val;
758-
zval ref_expiration, zv_expiration;
759747
php_memc_object_t *intern = Z_MEMC_OBJ_P(zobject);
760748

761749
/* 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-
770750
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]));
774755

775756
fci->retval = &retval;
776757
fci->params = params;
777758
fci->param_count = 4;
778759

779760
if (zend_call_function(fci, fcc) == SUCCESS) {
780761
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]));
784766
}
785767
}
786768
else {
787769
s_memc_set_status(intern, MEMCACHED_NOTFOUND, 0);
788770
}
789771

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);
794777

795-
if (!Z_ISUNDEF(retval)) {
796-
zval_ptr_dtor(&retval);
797-
}
798778
return status;
799779
}
800780

@@ -1388,7 +1368,7 @@ void php_memc_get_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key)
13881368
zend_long get_flags = 0;
13891369
zend_string *key;
13901370
zend_string *server_key = NULL;
1391-
zend_bool extended, mget_status;
1371+
zend_bool mget_status;
13921372
memcached_return status = MEMCACHED_SUCCESS;
13931373
zend_fcall_info fci = empty_fcall_info;
13941374
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
14841464
zend_string *server_key = NULL;
14851465
zend_long flags = 0;
14861466
MEMC_METHOD_INIT_VARS;
1487-
1488-
zend_bool with_cas, retval, preserve_order, extended;
1467+
zend_bool retval, preserve_order;
14891468

14901469
if (by_key) {
14911470
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sa|l", &server_key,
@@ -1574,32 +1553,29 @@ static
15741553
zend_bool s_result_callback_apply(php_memc_object_t *intern, zend_string *key, zval *value, zval *cas, uint32_t flags, void *in_context)
15751554
{
15761555
zend_bool status = 1;
1577-
1578-
zval retval, zv_result;
1556+
zval params[2];
1557+
zval retval;
15791558
php_memc_result_callback_ctx_t *context = (php_memc_result_callback_ctx_t *) in_context;
15801559

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]);
15831562

1584-
zend_fcall_info_argn(&context->fci, 2, context->object, &zv_result);
1563+
s_create_result_array(key, value, cas, flags, &params[1]);
15851564

15861565
context->fci.retval = &retval;
1566+
context->fci.params = params;
15871567
context->fci.param_count = 2;
15881568

15891569
if (zend_call_function(&context->fci, &context->fcc) == FAILURE) {
1590-
if (Z_TYPE(retval) != IS_UNDEF) {
1591-
zval_ptr_dtor(&retval);
1592-
}
15931570
php_error_docref(NULL, E_WARNING, "could not invoke result callback");
15941571
status = 0;
15951572
}
15961573

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]);
16001578

1601-
zend_fcall_info_args_clear(&context->fci, 2);
1602-
zval_ptr_dtor(&zv_result);
16031579
return status;
16041580
}
16051581

@@ -1663,14 +1639,6 @@ zend_bool s_fetch_apply(php_memc_object_t *intern, zend_string *key, zval *value
16631639
Returns the next result from a previous delayed request */
16641640
PHP_METHOD(Memcached, fetch)
16651641
{
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;
16741642
memcached_return status = MEMCACHED_SUCCESS;
16751643
MEMC_METHOD_INIT_VARS;
16761644

@@ -1708,14 +1676,6 @@ zend_bool s_fetch_all_apply(php_memc_object_t *intern, zend_string *key, zval *v
17081676
Returns all the results from a previous delayed request */
17091677
PHP_METHOD(Memcached, fetchAll)
17101678
{
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;
17191679
memcached_return status = MEMCACHED_SUCCESS;
17201680
MEMC_METHOD_INIT_VARS;
17211681

@@ -1794,13 +1754,8 @@ static void php_memc_setMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke
17941754
zend_string *server_key = NULL;
17951755
time_t expiration = 0;
17961756
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;
18041759
int tmp_len = 0;
18051760
MEMC_METHOD_INIT_VARS;
18061761

@@ -1918,10 +1873,6 @@ static void php_memc_store_impl(INTERNAL_FUNCTION_PARAMETERS, int op, zend_bool
19181873
zval s_zvalue;
19191874
zval *value = NULL;
19201875
zend_long expiration = 0;
1921-
zend_string *payload = NULL;
1922-
uint32_t flags = 0;
1923-
uint32_t retry = 0;
1924-
memcached_return status;
19251876
MEMC_METHOD_INIT_VARS;
19261877

19271878
if (by_key) {
@@ -2314,15 +2265,15 @@ PHP_METHOD(Memcached, addServer)
23142265
s_memc_set_status(intern, MEMCACHED_SUCCESS, 0);
23152266

23162267
#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);
23192270
} 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);
23212272
} 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);
23232274
}
23242275
#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);
23262277
#endif
23272278

23282279
if (s_memc_status_handle_result_code(intern, status) == FAILURE) {
@@ -2409,7 +2360,7 @@ PHP_METHOD(Memcached, addServers)
24092360
}
24102361
i++;
24112362
/* 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);
24132364
} ZEND_HASH_FOREACH_END();
24142365

24152366
status = memcached_server_push(intern->memc, list);

0 commit comments

Comments
 (0)