source: trunk/processor/foot.m4

Last change on this file was 1578, checked in by moo, 7 weeks ago

cacher: fix more var caching leaks

  • Property svn:eol-style set to native
File size: 6.4 KB
RevLine 
[1470]1dnl {{{ xc_store_target
2EXPORT(`typedef void *(*xc_processor_storage_allocator_t)(void *data, size_t size);')
3EXPORT(`typedef struct { xc_processor_storage_allocator_t allocator; void *allocator_data; ptrdiff_t relocatediff; } xc_processor_storage_t;')
4dnl }}}
[1444]5define(`DEFINE_STORE_API', `
[1470]6EXPORTED_FUNCTION(`$1 *xc_processor_store_$1(const xc_processor_storage_t *storage, $1 *src TSRMLS_DC)') dnl {{{
[1444]7{
8    $1 *dst;
9    xc_processor_t processor;
10
11    memset(&processor, 0, sizeof(processor));
[1468]12    processor.handle_reference = 1;
[1470]13    processor.relocatediff = storage->relocatediff;
[1444]14
[1566]15    IFAUTOCHECK(`xc_vector_init(unsigned long, &processor.allocsizes);')
[1444]16
17    /* calc size */ {
18        zend_hash_init(&processor.strings, 0, NULL, NULL, 0);
[1468]19        if (processor.handle_reference) {
[1444]20            zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
21        }
22
23        processor.size = 0;
24        /* allocate */
25        processor.size = ALIGN(processor.size + sizeof(src[0]));
26
27        xc_calc_$1(&processor, src TSRMLS_CC);
[1468]28        if (processor.handle_reference) {
[1444]29            zend_hash_destroy(&processor.zvalptrs);
30        }
31        zend_hash_destroy(&processor.strings);
32    }
33    ifelse(
34        `$1', `xc_entry_data_php_t', `SRC(`size')',
35        `', `', SRC(`entry.size')) = processor.size;
36    ifelse(
37        `$1', `xc_entry_var_t', `SRC(`have_references') = processor.have_references;',
38        `$1', `xc_entry_data_php_t', `SRC(`have_references') = processor.have_references;'
39    )
40
[1551]41    IFAUTOCHECK(`xc_vector_reverse(&processor.allocsizes);')
[1444]42    /* store {{{ */
43    {
44        IFAUTOCHECK(`char *oldp;')
45        zend_hash_init(&processor.strings, 0, NULL, NULL, 0);
[1468]46        if (processor.handle_reference) {
[1444]47            zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
48        }
49
50        /* allocator :) */
[1470]51        processor.p = (char *) storage->allocator(storage->allocator_data, processor.size);
[1444]52        if (processor.p == NULL) {
53            dst = NULL;
54            goto err_alloc;
55        }
56        IFAUTOCHECK(`oldp = processor.p;')
57        assert(processor.p == (char *) ALIGN(processor.p));
58
59        /* allocate */
60        dst = ($1 *) processor.p;
61        processor.p = (char *) ALIGN(processor.p + sizeof(dst[0]));
62
63        xc_store_$1(&processor, dst, src TSRMLS_CC);
64        IFAUTOCHECK(` {
65            size_t unexpected = processor.p - oldp;
66            size_t expected = processor.size;
67            if (unexpected != processor.size) {
68                fprintf(stderr, "unexpected:%lu - expected:%lu = %ld != 0\n", (unsigned long) unexpected, (unsigned long) expected, (long) unexpected - expected);
69                abort();
70            }
71        }')
72err_alloc:
[1468]73        if (processor.handle_reference) {
[1444]74            zend_hash_destroy(&processor.zvalptrs);
75        }
76        zend_hash_destroy(&processor.strings);
77    }
78    /* }}} */
79
[1551]80    IFAUTOCHECK(`xc_vector_destroy(&processor.allocsizes);')
[1444]81
82    return dst;
83}
84dnl }}}
85')
86DEFINE_STORE_API(`xc_entry_php_t')
87DEFINE_STORE_API(`xc_entry_data_php_t')
[1558]88DEFINE_STORE_API(`xc_entry_var_t')
[1572]89EXPORTED_FUNCTION(`void xc_processor_restore_xc_entry_php_t(xc_entry_php_t *dst, const xc_entry_php_t *src TSRMLS_DC)') dnl {{{
[1444]90{
91    xc_processor_t processor;
92
93    memset(&processor, 0, sizeof(processor));
94    xc_restore_xc_entry_php_t(&processor, dst, src TSRMLS_CC);
95}
96dnl }}}
[1572]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 {{{
[1444]98{
99    xc_processor_t processor;
100
101    memset(&processor, 0, sizeof(processor));
102    processor.readonly_protection = readonly_protection;
103    /* this function is used for php data only */
104    if (SRC(`have_references')) {
[1468]105        processor.handle_reference = 1;
[1444]106    }
107    processor.entry_php_src = entry_php;
108
[1468]109    if (processor.handle_reference) {
[1444]110        zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
111    }
112    xc_restore_xc_entry_data_php_t(&processor, dst, src TSRMLS_CC);
[1468]113    if (processor.handle_reference) {
[1444]114        zend_hash_destroy(&processor.zvalptrs);
115    }
116}
117dnl }}}
[1572]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 {{{
[1444]119{
120    xc_processor_t processor;
121
122    memset(&processor, 0, sizeof(processor));
[1558]123    processor.handle_reference = src->have_references;
[1444]124
[1468]125    if (processor.handle_reference) {
[1444]126        zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
127    }
[1560]128    processor.index_to_ce = index_to_ce;
[1558]129
130#ifdef ZEND_ENGINE_2
131    if (src->objects_count) {
[1568]132        int i;
133        size_t size = sizeof(processor.object_handles[0]) * src->objects_count;
134        processor.object_handles = emalloc(size);
[1570]135        IFAUTOCHECK(`xc_memsetptr(processor.object_handles, (void *) -1, size);')
[1568]136        /* other objects in $object->properties after $object, reverse order is necessary */
137        for (i = src->objects_count - 1; i >= 0; --i) {
[1558]138            zend_object *object = emalloc(sizeof(*object));
[1568]139            processor.object_handles[i] = zend_objects_store_put(object, (zend_objects_store_dtor_t) zend_objects_destroy_object, (zend_objects_free_object_storage_t) zend_objects_free_object_storage, NULL TSRMLS_CC);
[1564]140            xc_restore_zend_object(&processor, object, &src->objects[i] TSRMLS_CC);
[1558]141        }
142    }
143#endif
[1572]144    if (dst_ptr) {
[1578]145        zval_ptr_dtor(dst_ptr);
[1572]146        xc_restore_zval_ptr(&processor, dst_ptr, &src->value TSRMLS_CC);
147    }
148    else {
[1578]149        zval_dtor(dst);
[1572]150        xc_restore_zval(&processor, dst, src->value TSRMLS_CC);
151    }
[1468]152    if (processor.handle_reference) {
[1444]153        zend_hash_destroy(&processor.zvalptrs);
154    }
155
[1558]156#ifdef ZEND_ENGINE_2
157    if (src->objects_count) {
[1565]158        zend_uint i;
[1558]159        for (i = 0; i < src->objects_count; ++i) {
[1568]160            zend_objects_store_del_ref_by_handle(processor.object_handles[i] TSRMLS_CC);
[1558]161        }
[1568]162        efree(processor.object_handles);
[1558]163    }
164#endif
[1444]165}
166dnl }}}
167define(`DEFINE_RELOCATE_API', `
[1455]168/* src = readable element, before memcpy if any
169 * dst = writable element, after memcpy if any
170 * virtual_src = brother pointers relatived to this address, before relocation
171 * virtual_dst = brother pointers relatived to this address, after  relocation
[1453]172 */
[1455]173EXPORTED_FUNCTION(`void xc_processor_relocate_$1($1 *dst, $1 *virtual_dst, $1 *src, $1 *virtual_src TSRMLS_DC)') dnl {{{
[1444]174{
[1453]175    char *old_address = 0; /* unkown X used later */
[1455]176    ptrdiff_t offset = ptrsub(old_address, (ptrdiff_t) virtual_src);
[1446]177
[1448]178    /* diff to new_ptr */
[1456]179    ptrdiff_t ptrdiff = ptrsub(dst, virtual_src);
[1455]180    ptrdiff_t relocatediff = (ptrdiff_t) ptradd($1 *, virtual_dst, offset);
[1446]181
[1455]182    xc_relocate_$1(dst, ptrdiff, relocatediff TSRMLS_CC);
[1444]183}
184dnl }}}
185')
186DEFINE_RELOCATE_API(`xc_entry_var_t')
187DEFINE_RELOCATE_API(`xc_entry_php_t')
188DEFINE_RELOCATE_API(`xc_entry_data_php_t')
189EXPORTED(`#ifdef HAVE_XCACHE_DPRINT')
190EXPORTED_FUNCTION(`void xc_dprint(xc_entry_php_t *src, int indent TSRMLS_DC)') dnl {{{
191{
192    IFDPRINT(`INDENT()`'fprintf(stderr, "xc_entry_php_t:src");')
193    xc_dprint_xc_entry_php_t(src, indent TSRMLS_CC);
194}
195dnl }}}
196EXPORTED(`#endif')
Note: See TracBrowser for help on using the repository browser.