source: branches/1.3/xcache.h @ 617

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

PHP 5.3 support

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