source: trunk/processor/foot.m4 @ 1468

Last change on this file since 1468 was 1468, checked in by moo, 14 months ago

clean up shm handlers

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