Changeset 1572 in svn


Ignore:
Timestamp:
2014-11-12T07:03:46Z (5 years ago)
Author:
Xuefer
Message:

support for reference value

Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r1558 r1572  
    22API Changes
    33========
    4  * new: proto array xcache_get_refcount(mixed &$variable), with +1 side effect removed
    5  * chg: proto array xcache_get_cowcount(mixed $value)
     4 * new: proto int xcache_get_refcount(mixed &$variable), with +1 side effect removed
     5 * chg: proto int xcache_get_cowcount(mixed $value)
     6 * new: proto mixed &xcache_get_ref(string name): Get cached data by specified name return referenced value. Not supported in PHP_4
     7 * new: proto mixed &xcache_get_ref(string name): Get cached data by specified name return referenced value. Not supported in PHP_4
     8 * new: proto bool  xcache_set(string name, mixed &value [, int ttl]): Store data to cache by specified name maintaining value referenced
    69
    710ChangeLog
     
    1215   * fixed #348: added class const support for __FILE__ __DIR__
    1316   * closes #342: added support for object caching. handle IS_RESTORCE as interger
     17   * able to return reference value by xcache_set_ref/xcache_get_ref
    1418 * disassembler, decompiler:
    1519   * PHP_5_6 support
  • trunk/mod_cacher/xc_cacher.c

    r1567 r1572  
    34013401            }
    34023402
    3403             xc_processor_restore_var(return_value, stored_entry_var, xc_vector_data(zend_class_entry *, &index_to_ce) TSRMLS_CC);
     3403            xc_processor_restore_var(return_value, ZESW(NULL, return_value_ptr), stored_entry_var, xc_vector_data(zend_class_entry *, &index_to_ce) TSRMLS_CC);
    34043404            xc_cached_hit_unlocked(cache->cached TSRMLS_CC);
    34053405        } LEAVE_LOCK(cache);
     
    34743474}
    34753475/* }}} */
     3476/* {{{ proto mixed &xcache_get_ref(string name)
     3477   Get cached data by specified name return referenced value. Not supported in PHP_4 */
     3478#ifdef ZEND_BEGIN_ARG_INFO_EX
     3479ZEND_BEGIN_ARG_INFO_EX(arginfo_xcache_get_ref, 0, 1, 1)
     3480    ZEND_ARG_INFO(0, name)
     3481ZEND_END_ARG_INFO()
     3482#else
     3483static unsigned char arginfo_xcache_get_ref[] = { 1, BYREF_NONE };
     3484#endif
     3485
     3486PHP_FUNCTION(xcache_get_ref)
     3487{
     3488    zif_xcache_get(INTERNAL_FUNCTION_PARAM_PASSTHRU);
     3489}
     3490/* }}} */
     3491/* {{{ proto bool  xcache_set(string name, mixed &value [, int ttl])
     3492   Store data to cache by specified name maintaining value referenced */
     3493#ifdef ZEND_BEGIN_ARG_INFO_EX
     3494ZEND_BEGIN_ARG_INFO_EX(arginfo_xcache_set_ref, 0, 0, 2)
     3495    ZEND_ARG_INFO(0, name)
     3496    ZEND_ARG_INFO(1, value)
     3497    ZEND_ARG_INFO(0, ttl)
     3498ZEND_END_ARG_INFO()
     3499#else
     3500static unsigned char arginfo_xcache_set_ref[] = { 3, BYREF_NONE, BYREF_FORCE, BYREF_NONE };
     3501#endif
     3502
     3503PHP_FUNCTION(xcache_set_ref)
     3504{
     3505    zif_xcache_set(INTERNAL_FUNCTION_PARAM_PASSTHRU);
     3506}
     3507/* }}} */
    34763508/* {{{ proto bool  xcache_isset(string name)
    34773509   Check if an entry exists in cache by specified name */
     
    36283660    long count = 1;
    36293661    long value = 0;
    3630     zval oldzval;
    36313662    VAR_BUFFER_FLAGS(name);
    36323663
     
    36813712            }
    36823713            else {
    3683                 xc_processor_restore_var(&oldzval, stored_entry_var, NULL TSRMLS_CC);
    3684                 convert_to_long(&oldzval);
    3685                 value = Z_LVAL(oldzval);
    3686                 zval_dtor(&oldzval);
     3714                zval zv;
     3715                xc_processor_restore_var(&zv, NULL, stored_entry_var, NULL TSRMLS_CC);
     3716                convert_to_long(&zv);
     3717                value = Z_LVAL(zv);
     3718                zval_dtor(&zv);
    36873719            }
    36883720        }
     
    37513783    PHP_FE(xcache_get,               arginfo_xcache_get)
    37523784    PHP_FE(xcache_set,               arginfo_xcache_set)
     3785    PHP_FE(xcache_get_ref,           arginfo_xcache_get_ref)
     3786    PHP_FE(xcache_set_ref,           arginfo_xcache_set_ref)
     3787#ifdef ZEND_BEGIN_ARG_INFO_EX
     3788#endif
    37533789    PHP_FE(xcache_isset,             arginfo_xcache_isset)
    37543790    PHP_FE(xcache_unset,             arginfo_xcache_unset)
  • trunk/processor/foot.m4

    r1570 r1572  
    8787DEFINE_STORE_API(`xc_entry_data_php_t')
    8888DEFINE_STORE_API(`xc_entry_var_t')
    89 EXPORTED_FUNCTION(`xc_entry_php_t *xc_processor_restore_xc_entry_php_t(xc_entry_php_t *dst, const xc_entry_php_t *src TSRMLS_DC)') dnl {{{
     89EXPORTED_FUNCTION(`void xc_processor_restore_xc_entry_php_t(xc_entry_php_t *dst, const xc_entry_php_t *src TSRMLS_DC)') dnl {{{
    9090{
    9191    xc_processor_t processor;
     
    9393    memset(&processor, 0, sizeof(processor));
    9494    xc_restore_xc_entry_php_t(&processor, dst, src TSRMLS_CC);
    95 
    96     return dst;
    9795}
    9896dnl }}}
    99 EXPORTED_FUNCTION(`xc_entry_data_php_t *xc_processor_restore_xc_entry_data_php_t(const xc_entry_php_t *entry_php, xc_entry_data_php_t *dst, const xc_entry_data_php_t *src, zend_bool readonly_protection TSRMLS_DC)') dnl {{{
     97EXPORTED_FUNCTION(`void xc_processor_restore_xc_entry_data_php_t(const xc_entry_php_t *entry_php, xc_entry_data_php_t *dst, const xc_entry_data_php_t *src, zend_bool readonly_protection TSRMLS_DC)') dnl {{{
    10098{
    10199    xc_processor_t processor;
     
    116114        zend_hash_destroy(&processor.zvalptrs);
    117115    }
    118     return dst;
    119116}
    120117dnl }}}
    121 EXPORTED_FUNCTION(`zval *xc_processor_restore_var(zval *dst, const xc_entry_var_t *src, zend_class_entry **index_to_ce TSRMLS_DC)') dnl {{{
     118EXPORTED_FUNCTION(`void xc_processor_restore_var(zval *dst, zval **dst_ptr, const xc_entry_var_t *src, zend_class_entry **index_to_ce TSRMLS_DC)') dnl {{{
    122119{
    123120    xc_processor_t processor;
     
    128125    if (processor.handle_reference) {
    129126        zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
    130         dnl fprintf(stderr, "mark[%p] = %p\n", src, dst);
    131         zend_hash_add(&processor.zvalptrs, (char *)src->value, sizeof(src->value), (void *) &dst, sizeof(dst), NULL);
     127        if (dst_ptr) {
     128            zval_ptr_dtor(dst_ptr);
     129        }
    132130    }
    133131    processor.index_to_ce = index_to_ce;
     
    147145    }
    148146#endif
    149     xc_restore_zval(&processor, dst, src->value TSRMLS_CC);
     147    if (dst_ptr) {
     148        xc_restore_zval_ptr(&processor, dst_ptr, &src->value TSRMLS_CC);
     149    }
     150    else {
     151        xc_restore_zval(&processor, dst, src->value TSRMLS_CC);
     152    }
    150153    if (processor.handle_reference) {
    151154        zend_hash_destroy(&processor.zvalptrs);
     
    161164    }
    162165#endif
    163 
    164     return dst;
    165166}
    166167dnl }}}
  • trunk/processor/processor.m4

    r1568 r1572  
    284284                        IFCOPY(`
    285285                            DST()[0] = *ppzv;
     286                            IFSTORE(`Z_ADDREF(**DST());')
    286287                            /* *DST() is updated */
    287                             dnl fprintf(stderr, "*DST() is set to %p, PROCESSOR_TYPE is_shm %d\n", DST()[0], xc_is_shm(DST()[0]));
     288                            dnl fprintf(stderr, "*DST() is set to %p, PROCESSOR_TYPE is_shm %d\n", (void *) DST()[0], xc_is_shm(DST()[0]));
    288289                        ')
    289290                        IFCALCSTORE(`processor->have_references = 1;')
     
    306307                    ')
    307308                    if (zend_hash_add(&processor->zvalptrs, (char *) &SRC()[0], sizeof(SRC()[0]), (void *) &pzv, sizeof(pzv), NULL) == SUCCESS) { /* first add, go on */
    308                         dnl fprintf(stderr, "mark[%p] = %p\n", SRC()[0], pzv);
     309                        IFSTORE(`Z_SET_REFCOUNT(**DST(), 1);')
     310                        dnl IFSTORE(`fprintf(stderr, "mark[%p] = %p\n", (void *) SRC()[0], (void *) pzv);')
    309311                    }
    310312                    else {
     
    14171419    IFDPRINT(`INDENT()`'fprintf(stderr, "zval:value");')
    14181420    STRUCT_P_EX(zval_ptr, DST(`value'), SRC(`value'), `value', `', `&')
     1421#if 0
     1422    IFSTORE(`
     1423    {
     1424        HashTable *ht;
     1425        zval **zv;
     1426
     1427        assert(Z_TYPE_P(SRC(`value')) == IS_ARRAY);
     1428        ht = Z_ARRVAL_P(SRC(`value'));
     1429        assert(ht->nNumOfElements == 1);
     1430        fprintf(stderr, "key %s\n", ht->pListHead->arKey);
     1431
     1432        zv = (zval **) ht->pListHead->pData;
     1433        fprintf(stderr, "%d\n", Z_TYPE_PP(zv));
     1434        assert(Z_TYPE_PP(zv) == IS_ARRAY);
     1435        assert(Z_ARRVAL_PP(zv) == ht);
     1436    }
     1437    ')
     1438#endif
    14191439
    14201440#ifdef ZEND_ENGINE_2
  • trunk/xcache/xc_compatibility.h

    r1561 r1572  
    6868#ifndef Z_SET_REFCOUNT
    6969#   define Z_SET_REFCOUNT(z, rc) (z).refcount = rc
     70#endif
     71#ifndef Z_ADDREF
     72#   define Z_ADDREF(z) (z).refcount++
    7073#endif
    7174#ifndef IS_CONSTANT_TYPE_MASK
Note: See TracChangeset for help on using the changeset viewer.