Skip to content

Commit 229c684

Browse files
laruencerlerdorf
authored andcommitted
Better implementation
1 parent 6851bdd commit 229c684

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
@@ -3513,7 +3513,7 @@ static memcached_return php_memc_do_cache_callback(zval *zmemc_obj, zend_fcall_i
35133513
zval retval;
35143514
zval z_key;
35153515
zval z_val;
3516-
zval z_expiration;
3516+
zval *expiration, z_expiration;
35173517

35183518
uint32_t flags = 0;
35193519
memcached_return rc;
@@ -3523,41 +3523,37 @@ static memcached_return php_memc_do_cache_callback(zval *zmemc_obj, zend_fcall_i
35233523

35243524
ZVAL_STR(&z_key, key);
35253525
ZVAL_NULL(&z_val);
3526-
ZVAL_NEW_REF(value, &z_val);
3527-
ZVAL_NEW_REF(&z_expiration, &z_val);
3526+
ZVAL_NEW_REF(&z_val, value);
3527+
ZVAL_NEW_REF(&z_expiration, value);
35283528
ZVAL_LONG(Z_REFVAL(z_expiration), 0);
35293529

35303530
ZVAL_COPY(&params[0], zmemc_obj);
35313531
ZVAL_COPY(&params[1], &z_key);
3532-
ZVAL_COPY(&params[2], value);
3533-
ZVAL_COPY(&params[3], &z_expiration);
3532+
ZVAL_COPY_VALUE(&params[2], &z_val);
3533+
ZVAL_COPY_VALUE(&params[3], &z_expiration);
35343534

35353535
fci->retval = &retval;
35363536
fci->params = params;
35373537
fci->param_count = 4;
35383538

35393539
result = zend_call_function(fci, fcc);
3540-
ZVAL_UNREF(value);
3541-
ZVAL_UNREF(&z_expiration);
3540+
ZVAL_DUP(value, Z_REFVAL(z_val));
3541+
expiration = Z_REFVAL(z_expiration);
35423542
if (result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
35433543
struct memc_obj *m_obj;
35443544
i_obj = Z_MEMC_OBJ_P(zmemc_obj)
35453545
m_obj = i_obj->obj;
35463546

35473547
if (zend_is_true(&retval)) {
3548-
time_t expiration;
3548+
time_t expir;
35493549

3550-
if (Z_TYPE(z_expiration) != IS_LONG) {
3551-
convert_to_long(&z_expiration);
3552-
}
3553-
3554-
expiration = Z_LVAL(z_expiration);
3550+
expir = zval_get_long(expiration);
35553551

35563552
payload = php_memc_zval_to_payload(value, &payload_len, &flags, m_obj->serializer, m_obj->compression_type);
35573553
if (payload == NULL) {
35583554
status = (memcached_return)MEMC_RES_PAYLOAD_FAILURE;
35593555
} else {
3560-
rc = memcached_set(m_obj->memc, key->val, key->len, payload, payload_len, expiration, flags);
3556+
rc = memcached_set(m_obj->memc, key->val, key->len, payload, payload_len, expir, flags);
35613557
if (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED) {
35623558
status = rc;
35633559
}
@@ -3571,8 +3567,6 @@ static memcached_return php_memc_do_cache_callback(zval *zmemc_obj, zend_fcall_i
35713567

35723568
} else {
35733569
if (result == FAILURE) {
3574-
zval_ptr_dtor(&z_key);
3575-
zval_ptr_dtor(&z_expiration);
35763570
php_error_docref(NULL, E_WARNING, "could not invoke cache callback");
35773571
}
35783572
status = MEMCACHED_FAILURE;
@@ -3585,6 +3579,7 @@ static memcached_return php_memc_do_cache_callback(zval *zmemc_obj, zend_fcall_i
35853579
}
35863580

35873581
zval_ptr_dtor(&z_key);
3582+
zval_ptr_dtor(&z_val);
35883583
zval_ptr_dtor(&z_expiration);
35893584

35903585
return status;

0 commit comments

Comments
 (0)