source: trunk/xcache.h @ 496

Last change on this file since 496 was 496, checked in by moo, 7 years ago

fixed #157: support user error handler for E_STRICT. E_STRICT is now cached

  • Property svn:eol-style set to native
File size: 8.8 KB
RevLine 
[1]1#ifndef __XCACHE_H
2#define __XCACHE_H
3#define XCACHE_NAME       "XCache"
[309]4#define XCACHE_VERSION    "2.0.0-dev"
[1]5#define XCACHE_AUTHOR     "mOo"
[442]6#define XCACHE_COPYRIGHT  "Copyright (c) 2005-2007"
[1]7#define XCACHE_URL        "http://xcache.lighttpd.net"
8
9#include <php.h>
10#include <zend_compile.h>
11#include <zend_API.h>
[485]12#include <zend.h>
[1]13#include "php_ini.h"
14#include "zend_hash.h"
15
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
[148]19#include "xc_shm.h"
[1]20#include "lock.h"
21
[165]22#define HAVE_INODE
[1]23#if !defined(ZEND_ENGINE_2_1) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1 || PHP_MAJOR_VERSION > 5)
24#   define ZEND_ENGINE_2_1
25#endif
[78]26#if !defined(ZEND_ENGINE_2_2) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 2 || PHP_MAJOR_VERSION > 5)
27#   define ZEND_ENGINE_2_2
28#endif
[480]29#if !defined(ZEND_ENGINE_2_3) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 3 || PHP_MAJOR_VERSION > 5)
30#   define ZEND_ENGINE_2_3
31#endif
[1]32
[19]33#define NOTHING
[1]34/* ZendEngine code Switcher */
35#ifndef ZEND_ENGINE_2
36#   define ZESW(v1, v2) v1
37#else
38#   define ZESW(v1, v2) v2
39#endif
40
[485]41#ifdef ALLOCA_FLAG
42#   define my_do_alloca(size, use_heap) do_alloca(size, use_heap)
43#   define my_free_alloca(size, use_heap) free_alloca(size, use_heap)
44#else
45#   define my_do_alloca(size, use_heap) do_alloca(size)
46#   define my_free_alloca(size, use_heap) free_alloca(size)
47#   define ALLOCA_FLAG(x)
48#endif
49#ifndef Z_SET_ISREF
50#   define Z_SET_ISREF(z) (z).is_ref = 1;
51#endif
52#ifndef Z_UNSET_ISREF
53#   define Z_UNSET_ISREF(z) (z).is_ref = 0;
54#endif
55#ifndef Z_SET_REFCOUNT
56#   define Z_SET_REFCOUNT(z, rc) (z).refcount = rc;
57#endif
[491]58#ifndef IS_CONSTANT_TYPE_MASK
59#   define IS_CONSTANT_TYPE_MASK 0xf
60#endif
[485]61
[263]62/* {{{ dirty fix for PHP 6 */
63#ifdef add_assoc_long_ex
64static inline void my_add_assoc_long_ex(zval *arg, char *key, uint key_len, long value)
65{
66    add_assoc_long_ex(arg, key, key_len, value);
67}
68#   undef add_assoc_long_ex
69#   define add_assoc_long_ex my_add_assoc_long_ex
70#endif
71#ifdef add_assoc_bool_ex
72static inline void my_add_assoc_bool_ex(zval *arg, char *key, uint key_len, zend_bool value)
73{
74    add_assoc_bool_ex(arg, key, key_len, value);
75}
76#   undef add_assoc_bool_ex
77#   define add_assoc_bool_ex my_add_assoc_bool_ex
78#endif
79#ifdef add_assoc_null_ex
80static inline void my_add_assoc_null_ex(zval *arg, char *key, uint key_len)
81{
82    add_assoc_null_ex(arg, key, key_len);
83}
84#   undef add_assoc_null_ex
85#   define add_assoc_null_ex my_add_assoc_null_ex
86#endif
87/* }}} */
88
[1]89/* unicode */
90#ifdef IS_UNICODE
91#   define UNISW(text, unicode) unicode
92#else
93#   define UNISW(text, unicode) text
94#endif
95#define BUCKET_KEY_SIZE(b) \
96        (UNISW( \
97            (b)->nKeyLength, \
98                ((b)->key.type == IS_UNICODE) \
99                ? UBYTES(b->nKeyLength) \
100                : b->nKeyLength \
101                ))
[200]102#define BUCKET_KEY_S(b)    (UNISW((b)->arKey, (b)->key.arKey.s))
103#define BUCKET_KEY_U(b)    (UNISW((b)->arKey, (b)->key.arKey.u))
104#define BUCKET_KEY_TYPE(b) (UNISW(IS_STRING,  (b)->key.type))
[2]105#ifdef IS_UNICODE
[104]106#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, key.arKey)
[2]107#else
[11]108#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, arKey)
[2]109#endif
[1]110#define BUCKET_SIZE(b) (BUCKET_HEAD_SIZE(b) + BUCKET_KEY_SIZE(b))
111
112#ifndef IS_UNICODE
113typedef char *zstr;
[103]114#   define ZSTR_S(s)     (s)
115#   define ZSTR_U(s)     (s)
116#   define ZSTR_V(s)     (s)
117#   define ZSTR_PS(s)    (s)
118#   define ZSTR_PU(s)    (s)
119#   define ZSTR_PV(s)    (s)
[1]120#else
[103]121#   define ZSTR_S(zs)    ((zs).s)
122#   define ZSTR_U(zs)    ((zs).u)
123#   define ZSTR_V(zs)    ((zs).v)
124#   define ZSTR_PS(pzs)  ((pzs)->s)
125#   define ZSTR_PU(pzs)  ((pzs)->u)
126#   define ZSTR_PV(pzs)  ((pzs)->v)
[1]127#endif
128
[103]129#ifndef ZSTR
130#   define ZSTR(s)      (s)
131#endif
132
133#ifndef Z_UNIVAL
134#   define Z_UNIVAL(zval) (zval).value.str.val
135#   define Z_UNILEN(zval) (zval).value.str.len
136#endif
137
[1]138/* {{{ u hash wrapper */
139#ifndef IS_UNICODE
140#   define zend_u_hash_add(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
141       zend_hash_add(ht, arKey, nKeyLength, pData, nDataSize, pDest)
142
[88]143#   define zend_u_hash_update(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
144       zend_hash_update(ht, arKey, nKeyLength, pData, nDataSize, pDest)
145
[1]146#   define zend_u_hash_find(ht, type, arKey, nKeyLength, pData) \
147       zend_hash_find(ht, arKey, nKeyLength, pData)
148
[200]149#   define zend_u_hash_quick_find(ht, type, arKey, nKeyLength, h, pData) \
150       zend_hash_quick_find(ht, arKey, nKeyLength, h, pData)
151
[1]152#   define add_u_assoc_zval_ex(arg, type, key, key_len, value) \
153        add_assoc_zval_ex(arg, key, key_len, value)
154
[268]155#   define zend_u_is_auto_global(type, name, name_len) \
156        zend_is_auto_global(name, name_len)
[1]157#endif
158/* }}} */
159
160
161#define ECALLOC_N(x, n) ((x) = ecalloc(n, sizeof((x)[0])))
162#define ECALLOC_ONE(x) ECALLOC_N(x, 1)
163
164
165
166typedef ulong xc_hash_value_t;
167typedef struct {
168    int bits;
169    int size;
170    int mask;
171} xc_hash_t;
172
173/* the class entry type to be stored in class_table */
174typedef ZESW(zend_class_entry, zend_class_entry*) xc_cest_t;
175
176/* xc_cest_t to (zend_class_entry*) */
177#define CestToCePtr(st) (ZESW(\
178            &(st), \
179            st \
180            ) )
181
182/* ZCEP=zend class entry ptr */
183#define ZCEP_REFCOUNT_PTR(pce) (ZESW( \
184            (pce)->refcount, \
185            &((pce)->refcount) \
186            ))
187
188#define ZCE_REFCOUNT_PTR(ce) ZCE_REFCOUNT_PTR(&ce)
189
190typedef zend_op_array *(zend_compile_file_t)(zend_file_handle *h, int type TSRMLS_DC);
191
[311]192typedef struct _xc_entry_t xc_entry_t;
193typedef struct _xc_entry_data_php_t xc_entry_data_php_t;
[1]194/* {{{ xc_cache_t */
[11]195typedef struct {
[1]196    int cacheid;
197    xc_hash_t  *hcache; /* hash to cacheid */
198
[11]199    time_t     compiling;
[1]200    zend_ulong misses;
201    zend_ulong hits;
202    zend_ulong clogs;
203    zend_ulong ooms;
[456]204    zend_ulong errors;
[1]205    xc_lock_t  *lck;
206    xc_shm_t   *shm; /* to which shm contains us */
207    xc_mem_t   *mem; /* to which mem contains us */
208
209    xc_entry_t **entries;
[32]210    int entries_count;
[311]211    xc_entry_data_php_t **phps;
212    int phps_count;
[1]213    xc_entry_t *deletes;
[32]214    int deletes_count;
[311]215    xc_hash_t  *hentry; /* hash settings to entry */
216    xc_hash_t  *hphp;   /* hash settings to php */
[114]217
218    time_t     last_gc_deletes;
219    time_t     last_gc_expires;
[1]220} xc_cache_t;
221/* }}} */
222/* {{{ xc_classinfo_t */
223typedef struct {
[14]224#ifdef IS_UNICODE
225    zend_uchar type;
226#endif
[103]227    zstr      key;
[1]228    zend_uint key_size;
229    xc_cest_t cest;
[212]230    int       oplineno;
[1]231} xc_classinfo_t;
232/* }}} */
[95]233#ifdef HAVE_XCACHE_CONSTANT
234/* {{{ xc_constinfo_t */
235typedef struct {
236#ifdef IS_UNICODE
237    zend_uchar type;
238#endif
[103]239    zstr      key;
[95]240    zend_uint key_size;
241    zend_constant constant;
242} xc_constinfo_t;
243/* }}} */
244#endif
[1]245/* {{{ xc_funcinfo_t */
246typedef struct {
[14]247#ifdef IS_UNICODE
248    zend_uchar type;
249#endif
[103]250    zstr      key;
[1]251    zend_uint key_size;
252    zend_function func;
253} xc_funcinfo_t;
254/* }}} */
[268]255#ifdef ZEND_ENGINE_2_1
256/* {{{ xc_autoglobal_t */
257typedef struct {
258#ifdef IS_UNICODE
259    zend_uchar type;
260#endif
261    zstr       key;
262    zend_uint  key_len;
263} xc_autoglobal_t;
264/* }}} */
265#endif
[1]266typedef enum { XC_TYPE_PHP, XC_TYPE_VAR } xc_entry_type_t;
[311]267typedef char xc_md5sum_t[16];
[496]268/* {{{ xc_compilererror_t */
269typedef struct {
270    int type;
271    uint lineno;
272    int error_len;
273    char *error;
274} xc_compilererror_t;
275/* }}} */
[1]276/* {{{ xc_entry_data_php_t */
[311]277struct _xc_entry_data_php_t {
278    xc_hash_value_t hvalue; /* hash of md5 */
279    xc_entry_data_php_t *next;
280    xc_cache_t *cache;      /* which cache it's on */
281
282    xc_md5sum_t md5;        /* md5sum of the source */
283    zend_ulong  refcount;   /* count of entries referencing to this data */
284
[1]285    size_t sourcesize;
[311]286    zend_ulong hits;        /* hits of this php */
287    size_t     size;
[1]288
289    zend_op_array *op_array;
290
[95]291#ifdef HAVE_XCACHE_CONSTANT
292    zend_uint constinfo_cnt;
293    xc_constinfo_t *constinfos;
294#endif
295
[1]296    zend_uint funcinfo_cnt;
297    xc_funcinfo_t *funcinfos;
298
299    zend_uint classinfo_cnt;
300    xc_classinfo_t *classinfos;
[212]301    zend_bool have_early_binding;
[268]302
303#ifdef ZEND_ENGINE_2_1
304    zend_uint autoglobal_cnt;
305    xc_autoglobal_t *autoglobals;
306#endif
[311]307
[496]308#ifdef E_STRICT
309    zend_uint compilererror_cnt;
310    xc_compilererror_t *compilererrors;
311#endif
312
[311]313    zend_bool  have_references;
314};
[1]315/* }}} */
316/* {{{ xc_entry_data_var_t */
317typedef struct {
318    zval   *value;
[311]319
320    zend_bool  have_references;
[1]321} xc_entry_data_var_t;
322/* }}} */
323typedef zvalue_value xc_entry_name_t;
324/* {{{ xc_entry_t */
325struct _xc_entry_t {
326    xc_entry_type_t type;
327    xc_hash_value_t hvalue;
328    xc_entry_t *next;
329    xc_cache_t *cache;      /* which cache it's on */
330
331    size_t     size;
[311]332    zend_ulong refcount;    /* count of instances holding this entry */
[1]333    zend_ulong hits;
334    time_t     ctime;           /* the ctime of this entry */
335    time_t     atime;           /* the atime of this entry */
336    time_t     dtime;           /* the deletion time of this entry */
[114]337    long       ttl;             /* ttl of time entry, var only */
[1]338
339#ifdef IS_UNICODE
340    zend_uchar name_type;
341#endif
342    xc_entry_name_t name;
343
344    union {
345        xc_entry_data_php_t *php;
346        xc_entry_data_var_t *var;
347    } data;
[233]348
[311]349    time_t mtime;           /* the mtime of origin source file */
350#ifdef HAVE_INODE
351    int device;             /* the filesystem device */
352    int inode;              /* the filesystem inode */
353#endif
[1]354};
355/* }}} */
356
357extern zend_module_entry xcache_module_entry;
358#define phpext_xcache_ptr &xcache_module_entry
359
360int xc_is_rw(const void *p);
361int xc_is_ro(const void *p);
362int xc_is_shm(const void *p);
363
364#endif /* __XCACHE_H */
Note: See TracBrowser for help on using the repository browser.