source: branches/1.3/utils.h @ 677

Last change on this file since 677 was 677, checked in by moo, 5 years ago

merged r671 from trunk

  • Property svn:eol-style set to native
File size: 5.1 KB
Line 
1#include "php.h"
2#include "xcache.h"
3
4#ifdef XCACHE_DEBUG
5#   define IFDEBUG(x) (x)
6int xc_vtrace(const char *fmt, va_list args);
7int xc_trace(const char *fmt, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 1, 2);
8
9#   ifdef ZEND_WIN32
10static inline int TRACE(const char *fmt, ...) 
11{
12    va_list args;
13    int ret;
14
15    va_start(args, fmt);
16    ret = xc_vtrace(fmt, args);
17    va_end(args);
18    return ret;
19}
20#   else
21#       define TRACE(fmt, ...) \
22        xc_trace("%s:%d: " fmt "\r\n", __FILE__, __LINE__, __VA_ARGS__)
23#   endif /* ZEND_WIN32 */
24#   undef NDEBUG
25#   undef inline
26#   define inline
27#else /* XCACHE_DEBUG */
28
29#   ifdef ZEND_WIN32
30static inline int TRACE_DUMMY(const char *fmt, ...)
31{
32    return 0;
33}
34#       define TRACE 1 ? 0 : TRACE_DUMMY
35#   else
36#       define TRACE(fmt, ...) do { } while (0)
37#   endif /* ZEND_WIN32 */
38
39#   define IFDEBUG(x) do { } while (0)
40#   ifndef NDEBUG
41#       define NDEBUG
42#   endif
43#endif /* XCACHE_DEBUG */
44#include <assert.h>
45
46typedef struct {
47    int alloc;
48    zend_op_array *op_array;
49    HashTable *function_table;
50    HashTable *class_table;
51} xc_compile_result_t;
52
53xc_compile_result_t *xc_compile_result_init(xc_compile_result_t *cr,
54        zend_op_array *op_array,
55        HashTable *function_table,
56        HashTable *class_table);
57void xc_compile_result_free(xc_compile_result_t *cr);
58xc_compile_result_t *xc_compile_result_init_cur(xc_compile_result_t *cr, zend_op_array *op_array TSRMLS_DC);
59/* apply func */
60int xc_apply_function(zend_function *zf, apply_func_t applyer TSRMLS_DC);
61int xc_apply_class(zend_class_entry *ce, apply_func_t applyer TSRMLS_DC);
62int xc_apply_op_array(xc_compile_result_t *cr, apply_func_t applyer TSRMLS_DC);
63
64int xc_undo_pass_two(zend_op_array *op_array TSRMLS_DC);
65int xc_redo_pass_two(zend_op_array *op_array TSRMLS_DC);
66int xc_fix_opcode(zend_op_array *op_array TSRMLS_DC);
67int xc_undo_fix_opcode(zend_op_array *op_array TSRMLS_DC);
68zend_uchar xc_get_fixed_opcode(zend_uchar opcode, int line);
69
70int xc_foreach_early_binding_class(zend_op_array *op_array, void (*callback)(zend_op *opline, int oplineno, void *data TSRMLS_DC), void *data TSRMLS_DC);
71
72/* installer */
73#ifdef HAVE_XCACHE_CONSTANT
74void xc_install_constant(char *filename, zend_constant *constant, zend_uchar type, zstr key, uint len, ulong h TSRMLS_DC);
75#endif
76void xc_install_function(char *filename, zend_function *func, zend_uchar type, zstr key, uint len, ulong h TSRMLS_DC);
77ZESW(xc_cest_t *, void) xc_install_class(char *filename, xc_cest_t *cest, int oplineno, zend_uchar type, zstr key, uint len, ulong h TSRMLS_DC);
78
79/* sandbox */
80typedef struct {
81    int alloc;
82    char *filename;
83
84    HashTable orig_included_files;
85    HashTable *tmp_included_files;
86
87#ifdef HAVE_XCACHE_CONSTANT
88    HashTable *orig_zend_constants;
89    HashTable tmp_zend_constants;
90#endif
91    HashTable *orig_function_table;
92    HashTable *orig_class_table;
93    HashTable *orig_auto_globals;
94    HashTable tmp_function_table;
95    HashTable tmp_class_table;
96    HashTable tmp_auto_globals;
97#ifdef HAVE_XCACHE_CONSTANT
98    Bucket    *tmp_internal_constant_tail;
99#endif
100    Bucket    *tmp_internal_function_tail;
101    Bucket    *tmp_internal_class_tail;
102
103#ifdef E_STRICT
104    int orig_user_error_handler_error_reporting;
105#endif
106
107#ifdef ZEND_COMPILE_IGNORE_INTERNAL_CLASSES
108    zend_uint orig_compiler_options;
109#endif
110} xc_sandbox_t;
111
112typedef enum _xc_install_action_t {
113    XC_NoInstall,
114    XC_Install,
115    XC_InstallNoBinding
116} xc_install_action_t;
117
118void xc_zend_class_add_ref(zend_class_entry ZESW(*ce, **ce));
119xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, char *filename TSRMLS_DC);
120void xc_sandbox_free(xc_sandbox_t *sandbox, xc_install_action_t install TSRMLS_DC);
121
122typedef zend_bool (*xc_if_func_t)(void *data);
123
124void xc_hash_copy_if(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size, xc_if_func_t checker);
125#ifdef HAVE_XCACHE_CONSTANT
126void xc_zend_constant_ctor(zend_constant *c);
127void xc_zend_constant_dtor(zend_constant *c);
128void xc_copy_internal_zend_constants(HashTable *target, HashTable *source);
129#endif
130
131#ifndef ZEND_ENGINE_2_3
132size_t zend_dirname(char *path, size_t len);
133long zend_atol(const char *str, int len);
134#endif
135
136typedef struct {
137    zend_uint size;
138    zend_uint cnt;
139    void *data;
140} xc_vector_t;
141
142#define xc_vector_init(type, vector) do { \
143    (vector)->cnt = 0;     \
144    (vector)->size = 0;    \
145    (vector)->data = NULL; \
146} while (0)
147
148#define xc_vector_add(type, vector, value) do { \
149    if ((vector)->cnt == (vector)->size) { \
150        if ((vector)->size) { \
151            (vector)->size <<= 1; \
152            (vector)->data = erealloc((vector)->data, sizeof(type) * (vector)->size); \
153        } \
154        else { \
155            (vector)->size = 8; \
156            (vector)->data = emalloc(sizeof(type) * (vector)->size); \
157        } \
158    } \
159    ((type *) (vector)->data)[(vector)->cnt++] = value; \
160} while (0)
161
162static inline void *xc_vector_detach_impl(xc_vector_t *vector)
163{
164    void *data = vector->data;
165    vector->data = NULL;
166    vector->size = 0;
167    vector->cnt = 0;
168    return data;
169}
170
171#define xc_vector_detach(type, vector) ((type *) xc_vector_detach_impl(vector))
172
173static inline void xc_vector_free_impl(xc_vector_t *vector TSRMLS_DC)
174{
175    if (vector->data) {
176        efree(vector->data);
177    }
178    vector->size = 0;
179    vector->cnt = 0;
180}
181
182#define xc_vector_free(type, vector) xc_vector_free_impl(vector TSRMLS_CC)
183
184>>>>>>> .merge-right.r671
Note: See TracBrowser for help on using the repository browser.