From ffe43cb79923101b4cbd41cc1b2606090cfc887c Mon Sep 17 00:00:00 2001 From: Xuefer Date: Fri, 8 Nov 2013 09:30:06 +0000 Subject: [PATCH] relocate: update proto to like memcpy/store/restore, update test code git-svn-id: svn://svn.lighttpd.net/xcache/trunk@1455 c26eb9a1-5813-0410-bd6c-c2e55f420ca7 --- mod_cacher/xc_cacher.c | 22 +++++++++++++++++----- processor/foot.m4 | 20 ++++++++++---------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/mod_cacher/xc_cacher.c b/mod_cacher/xc_cacher.c index 2043250..8154c8e 100644 --- a/mod_cacher/xc_cacher.c +++ b/mod_cacher/xc_cacher.c @@ -181,13 +181,25 @@ static xc_entry_data_php_t *xc_php_store_unlocked(xc_cache_t *cache, xc_entry_da xc_entry_data_php_t *p = malloc(stored_php->size); xc_entry_data_php_t *backup = malloc(stored_php->size); fprintf(stderr, "%lu\n", stored_php->size); - memcpy(p, stored_php, stored_php->size); memcpy(backup, stored_php, stored_php->size); - xc_processor_relocate_xc_entry_data_php_t(stored_php, stored_php, p, 0 TSRMLS_CC); - assert(memcmp(stored_php, backup, stored_php->size) == 0); - memcpy(stored_php, p, p->size); - xc_processor_relocate_xc_entry_data_php_t(p, 0, stored_php, stored_php TSRMLS_CC); + { + memcpy(p, stored_php, stored_php->size); + xc_processor_relocate_xc_entry_data_php_t(p, p , stored_php, stored_php TSRMLS_CC); + assert(memcmp(stored_php, backup, stored_php->size) == 0); + + memcpy(stored_php, p, p->size); + xc_processor_relocate_xc_entry_data_php_t(stored_php, stored_php, p, p TSRMLS_CC); + } + + { + memcpy(p, stored_php, stored_php->size); + xc_processor_relocate_xc_entry_data_php_t(p, 0, stored_php, stored_php TSRMLS_CC); + assert(memcmp(stored_php, backup, stored_php->size) == 0); + + memcpy(stored_php, p, p->size); + xc_processor_relocate_xc_entry_data_php_t(stored_php, stored_php, p, 0 TSRMLS_CC); + } } #endif if (stored_php) { diff --git a/processor/foot.m4 b/processor/foot.m4 index 36e8fb4..778a3d4 100644 --- a/processor/foot.m4 +++ b/processor/foot.m4 @@ -136,22 +136,22 @@ EXPORTED_FUNCTION(`zval *xc_processor_restore_zval(zval *dst, const zval *src, z } dnl }}} define(`DEFINE_RELOCATE_API', ` -/* old_src = readable element, before memcpy if any - * new_src = writable element, after memcpy if any - * virtual_old_src = brother pointers relatived to this address, before relocation - * virtual_new_src = brother pointers relatived to this address, after relocation +/* src = readable element, before memcpy if any + * dst = writable element, after memcpy if any + * virtual_src = brother pointers relatived to this address, before relocation + * virtual_dst = brother pointers relatived to this address, after relocation */ -EXPORTED_FUNCTION(`void xc_processor_relocate_$1($1 *old_src, $1 *virtual_old_src, $1 *new_src, $1 *virtual_new_src TSRMLS_DC)') dnl {{{ +EXPORTED_FUNCTION(`void xc_processor_relocate_$1($1 *dst, $1 *virtual_dst, $1 *src, $1 *virtual_src TSRMLS_DC)') dnl {{{ { char *old_address = 0; /* unkown X used later */ - ptrdiff_t offset = ptrsub(old_address, (ptrdiff_t) virtual_old_src); + ptrdiff_t offset = ptrsub(old_address, (ptrdiff_t) virtual_src); /* diff to new_ptr */ - ptrdiff_t ptrdiff = ptrsub(new_src, old_src); - ptrdiff_t relocatediff = (ptrdiff_t) ptradd($1 *, virtual_new_src, offset); - assert(ptradd($1 *, old_src, ptrdiff) == new_src); + ptrdiff_t ptrdiff = ptrsub(dst, src); + ptrdiff_t relocatediff = (ptrdiff_t) ptradd($1 *, virtual_dst, offset); + assert(ptradd($1 *, src, ptrdiff) == dst); - xc_relocate_$1(new_src, ptrdiff, relocatediff TSRMLS_CC); + xc_relocate_$1(dst, ptrdiff, relocatediff TSRMLS_CC); } dnl }}} ')