source: trunk/processor/foot.m4 @ 1446

Last change on this file since 1446 was 1446, checked in by moo, 11 months ago

update relocate

  • Property svn:eol-style set to native
File size: 5.0 KB
RevLine 
[1444]1define(`DEFINE_STORE_API', `
2EXPORTED_FUNCTION(`$1 *xc_processor_store_$1(xc_shm_t *shm, xc_allocator_t *allocator, $1 *src TSRMLS_DC)') dnl {{{
3{
4    $1 *dst;
5    xc_processor_t processor;
6
7    memset(&processor, 0, sizeof(processor));
8    processor.reference = 1;
9    processor.shm = shm;
10    processor.allocator = allocator;
11
12    IFAUTOCHECK(`xc_stack_init(&processor.allocsizes);')
13
14    /* calc size */ {
15        zend_hash_init(&processor.strings, 0, NULL, NULL, 0);
16        if (processor.reference) {
17            zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
18        }
19
20        processor.size = 0;
21        /* allocate */
22        processor.size = ALIGN(processor.size + sizeof(src[0]));
23
24        xc_calc_$1(&processor, src TSRMLS_CC);
25        if (processor.reference) {
26            zend_hash_destroy(&processor.zvalptrs);
27        }
28        zend_hash_destroy(&processor.strings);
29    }
30    ifelse(
31        `$1', `xc_entry_data_php_t', `SRC(`size')',
32        `', `', SRC(`entry.size')) = processor.size;
33    ifelse(
34        `$1', `xc_entry_var_t', `SRC(`have_references') = processor.have_references;',
35        `$1', `xc_entry_data_php_t', `SRC(`have_references') = processor.have_references;'
36    )
37
38    IFAUTOCHECK(`xc_stack_reverse(&processor.allocsizes);')
39    /* store {{{ */
40    {
41        IFAUTOCHECK(`char *oldp;')
42        zend_hash_init(&processor.strings, 0, NULL, NULL, 0);
43        if (processor.reference) {
44            zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
45        }
46
47        /* allocator :) */
48        processor.p = (char *) processor.allocator->vtable->malloc(processor.allocator, processor.size);
49        if (processor.p == NULL) {
50            dst = NULL;
51            goto err_alloc;
52        }
53        IFAUTOCHECK(`oldp = processor.p;')
54        assert(processor.p == (char *) ALIGN(processor.p));
55
56        /* allocate */
57        dst = ($1 *) processor.p;
58        processor.p = (char *) ALIGN(processor.p + sizeof(dst[0]));
59
60        xc_store_$1(&processor, dst, src TSRMLS_CC);
61        IFAUTOCHECK(` {
62            size_t unexpected = processor.p - oldp;
63            size_t expected = processor.size;
64            if (unexpected != processor.size) {
65                fprintf(stderr, "unexpected:%lu - expected:%lu = %ld != 0\n", (unsigned long) unexpected, (unsigned long) expected, (long) unexpected - expected);
66                abort();
67            }
68        }')
69err_alloc:
70        if (processor.reference) {
71            zend_hash_destroy(&processor.zvalptrs);
72        }
73        zend_hash_destroy(&processor.strings);
74    }
75    /* }}} */
76
77    IFAUTOCHECK(`xc_stack_destroy(&processor.allocsizes);')
78
79    return dst;
80}
81dnl }}}
82')
83DEFINE_STORE_API(`xc_entry_var_t')
84DEFINE_STORE_API(`xc_entry_php_t')
85DEFINE_STORE_API(`xc_entry_data_php_t')
86EXPORTED_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 {{{
87{
88    xc_processor_t processor;
89
90    memset(&processor, 0, sizeof(processor));
91    xc_restore_xc_entry_php_t(&processor, dst, src TSRMLS_CC);
92
93    return dst;
94}
95dnl }}}
96EXPORTED_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 {{{
97{
98    xc_processor_t processor;
99
100    memset(&processor, 0, sizeof(processor));
101    processor.readonly_protection = readonly_protection;
102    /* this function is used for php data only */
103    if (SRC(`have_references')) {
104        processor.reference = 1;
105    }
106    processor.entry_php_src = entry_php;
107
108    if (processor.reference) {
109        zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
110    }
111    xc_restore_xc_entry_data_php_t(&processor, dst, src TSRMLS_CC);
112    if (processor.reference) {
113        zend_hash_destroy(&processor.zvalptrs);
114    }
115    return dst;
116}
117dnl }}}
118EXPORTED_FUNCTION(`zval *xc_processor_restore_zval(zval *dst, const zval *src, zend_bool have_references TSRMLS_DC)') dnl {{{
119{
120    xc_processor_t processor;
121
122    memset(&processor, 0, sizeof(processor));
123    processor.reference = have_references;
124
125    if (processor.reference) {
126        zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
127        dnl fprintf(stderr, "mark[%p] = %p\n", src, dst);
128        zend_hash_add(&processor.zvalptrs, (char *)src, sizeof(src), (void*)&dst, sizeof(dst), NULL);
129    }
130    xc_restore_zval(&processor, dst, src TSRMLS_CC);
131    if (processor.reference) {
132        zend_hash_destroy(&processor.zvalptrs);
133    }
134
135    return dst;
136}
137dnl }}}
138define(`DEFINE_RELOCATE_API', `
[1446]139EXPORTED_FUNCTION(`void xc_processor_relocate_$1($1 *src, $1 *old_start, $1 *new_start TSRMLS_DC)') dnl {{{
[1444]140{
[1446]141    /*
142    $1 *xc_addressof(offset) {
143        return (char *) offset + (ptrdiff_t) old_start;
144    }
145    */
146    ptrdiff_t ptrdiff = /* offset + */ (ptrdiff_t) old_start;
147
148    /*
149    ptrdiff_t *xc_offsetof(offset) {
150        return (char *) xc_addressof(offset) - src;
151    }
152
153    $1 *xc_newoffset(offset) {
154        return new_start + xc_offsetof(offset);
155    }
156    */
157    ptrdiff_t relocatediff = new_start + (/* offset + */ ptrdiff - (ptrdiff_t) src);
158
159    xc_relocate_$1(src, ptrdiff, relocatediff TSRMLS_CC);
[1444]160}
161dnl }}}
162')
163DEFINE_RELOCATE_API(`xc_entry_var_t')
164DEFINE_RELOCATE_API(`xc_entry_php_t')
165DEFINE_RELOCATE_API(`xc_entry_data_php_t')
166EXPORTED(`#ifdef HAVE_XCACHE_DPRINT')
167EXPORTED_FUNCTION(`void xc_dprint(xc_entry_php_t *src, int indent TSRMLS_DC)') dnl {{{
168{
169    IFDPRINT(`INDENT()`'fprintf(stderr, "xc_entry_php_t:src");')
170    xc_dprint_xc_entry_php_t(src, indent TSRMLS_CC);
171}
172dnl }}}
173EXPORTED(`#endif')
Note: See TracBrowser for help on using the repository browser.