Skip to content

Commit 51df8f3

Browse files
committed
Better implementation
1 parent a642447 commit 51df8f3

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

php_memcached.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3517,7 +3517,7 @@ static memcached_return php_memc_do_cache_callback(zval *zmemc_obj, zend_fcall_i
35173517
zval retval;
35183518
zval z_key;
35193519
zval z_val;
3520-
zval z_expiration;
3520+
zval *expiration, z_expiration;
35213521

35223522
uint32_t flags = 0;
35233523
memcached_return rc;
@@ -3527,41 +3527,37 @@ static memcached_return php_memc_do_cache_callback(zval *zmemc_obj, zend_fcall_i
35273527

35283528
ZVAL_STR(&z_key, key);
35293529
ZVAL_NULL(&z_val);
3530-
ZVAL_NEW_REF(value, &z_val);
3531-
ZVAL_NEW_REF(&z_expiration, &z_val);
3530+
ZVAL_NEW_REF(&z_val, value);
3531+
ZVAL_NEW_REF(&z_expiration, value);
35323532
ZVAL_LONG(Z_REFVAL(z_expiration), 0);
35333533

35343534
ZVAL_COPY(&params[0], zmemc_obj);
35353535
ZVAL_COPY(&params[1], &z_key);
3536-
ZVAL_COPY(&params[2], value);
3537-
ZVAL_COPY(&params[3], &z_expiration);
3536+
ZVAL_COPY_VALUE(&params[2], &z_val);
3537+
ZVAL_COPY_VALUE(&params[3], &z_expiration);
35383538

35393539
fci->retval = &retval;
35403540
fci->params = params;
35413541
fci->param_count = 4;
35423542

35433543
result = zend_call_function(fci, fcc);
3544-
ZVAL_UNREF(value);
3545-
ZVAL_UNREF(&z_expiration);
3544+
ZVAL_DUP(value, Z_REFVAL(z_val));
3545+
expiration = Z_REFVAL(z_expiration);
35463546
if (result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
35473547
struct memc_obj *m_obj;
35483548
i_obj = Z_MEMC_OBJ_P(zmemc_obj)
35493549
m_obj = i_obj->obj;
35503550

35513551
if (zend_is_true(&retval)) {
3552-
time_t expiration;
3552+
time_t expir;
35533553

3554-
if (Z_TYPE(z_expiration) != IS_LONG) {
3555-
convert_to_long(&z_expiration);
3556-
}
3557-
3558-
expiration = Z_LVAL(z_expiration);
3554+
expir = zval_get_long(expiration);
35593555

35603556
payload = php_memc_zval_to_payload(value, &payload_len, &flags, m_obj->serializer, m_obj->compression_type);
35613557
if (payload == NULL) {
35623558
status = (memcached_return)MEMC_RES_PAYLOAD_FAILURE;
35633559
} else {
3564-
rc = memcached_set(m_obj->memc, key->val, key->len, payload, payload_len, expiration, flags);
3560+
rc = memcached_set(m_obj->memc, key->val, key->len, payload, payload_len, expir, flags);
35653561
if (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED) {
35663562
status = rc;
35673563
}
@@ -3575,8 +3571,6 @@ static memcached_return php_memc_do_cache_callback(zval *zmemc_obj, zend_fcall_i
35753571

35763572
} else {
35773573
if (result == FAILURE) {
3578-
zval_ptr_dtor(&z_key);
3579-
zval_ptr_dtor(&z_expiration);
35803574
php_error_docref(NULL, E_WARNING, "could not invoke cache callback");
35813575
}
35823576
status = MEMCACHED_FAILURE;
@@ -3589,6 +3583,7 @@ static memcached_return php_memc_do_cache_callback(zval *zmemc_obj, zend_fcall_i
35893583
}
35903584

35913585
zval_ptr_dtor(&z_key);
3586+
zval_ptr_dtor(&z_val);
35923587
zval_ptr_dtor(&z_expiration);
35933588

35943589
return status;

0 commit comments

Comments
 (0)