source: branches/1.3/xcache.h @ 622

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

merged r504:513 from trunk

  • Property svn:eol-style set to native
File size: 8.4 KB
RevLine 
[1]1#ifndef __XCACHE_H
2#define __XCACHE_H
3#define XCACHE_NAME       "XCache"
[494]4#define XCACHE_VERSION    "1.3.0-dev"
[1]5#define XCACHE_AUTHOR     "mOo"
[610]6#define XCACHE_COPYRIGHT  "Copyright (c) 2005-2009"
[1]7#define XCACHE_URL        "http://xcache.lighttpd.net"
8
9#include <php.h>
10#include <zend_compile.h>
11#include <zend_API.h>
[617]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
[481]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
[617]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
[618]58#ifndef IS_CONSTANT_TYPE_MASK
59#   define IS_CONSTANT_TYPE_MASK 0xf
60#endif
[617]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
[622]143#   define zend_u_hash_quick_add(ht, type, arKey, nKeyLength, h, pData, nDataSize, pDest) \
144       zend_hash_quick_add(ht, arKey, nKeyLength, h, pData, nDataSize, pDest)
145
[88]146#   define zend_u_hash_update(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
147       zend_hash_update(ht, arKey, nKeyLength, pData, nDataSize, pDest)
148
[622]149#   define zend_u_hash_quick_update(ht, type, arKey, nKeyLength, h, pData, nDataSize, pDest) \
150       zend_hash_quick_update(ht, arKey, nKeyLength, h, pData, nDataSize, pDest)
151
[1]152#   define zend_u_hash_find(ht, type, arKey, nKeyLength, pData) \
153       zend_hash_find(ht, arKey, nKeyLength, pData)
154
[200]155#   define zend_u_hash_quick_find(ht, type, arKey, nKeyLength, h, pData) \
156       zend_hash_quick_find(ht, arKey, nKeyLength, h, pData)
157
[1]158#   define add_u_assoc_zval_ex(arg, type, key, key_len, value) \
159        add_assoc_zval_ex(arg, key, key_len, value)
160
[268]161#   define zend_u_is_auto_global(type, name, name_len) \
162        zend_is_auto_global(name, name_len)
[1]163#endif
164/* }}} */
165
166
167#define ECALLOC_N(x, n) ((x) = ecalloc(n, sizeof((x)[0])))
168#define ECALLOC_ONE(x) ECALLOC_N(x, 1)
169
170
171
172typedef ulong xc_hash_value_t;
173typedef struct {
174    int bits;
175    int size;
176    int mask;
177} xc_hash_t;
178
179/* the class entry type to be stored in class_table */
180typedef ZESW(zend_class_entry, zend_class_entry*) xc_cest_t;
181
182/* xc_cest_t to (zend_class_entry*) */
183#define CestToCePtr(st) (ZESW(\
184            &(st), \
185            st \
186            ) )
187
188/* ZCEP=zend class entry ptr */
189#define ZCEP_REFCOUNT_PTR(pce) (ZESW( \
190            (pce)->refcount, \
191            &((pce)->refcount) \
192            ))
193
194#define ZCE_REFCOUNT_PTR(ce) ZCE_REFCOUNT_PTR(&ce)
195
196typedef zend_op_array *(zend_compile_file_t)(zend_file_handle *h, int type TSRMLS_DC);
197
198/* {{{ xc_cache_t */
199typedef struct _xc_entry_t xc_entry_t;
[11]200typedef struct {
[1]201    int cacheid;
202    xc_hash_t  *hcache; /* hash to cacheid */
203
[11]204    time_t     compiling;
[1]205    zend_ulong misses;
206    zend_ulong hits;
207    zend_ulong clogs;
208    zend_ulong ooms;
[457]209    zend_ulong errors;
[1]210    xc_lock_t  *lck;
211    xc_shm_t   *shm; /* to which shm contains us */
212    xc_mem_t   *mem; /* to which mem contains us */
213
214    xc_entry_t **entries;
[32]215    int entries_count;
[1]216    xc_entry_t *deletes;
[32]217    int deletes_count;
[1]218    xc_hash_t  *hentry; /* hash to entry */
[114]219
220    time_t     last_gc_deletes;
221    time_t     last_gc_expires;
[1]222} xc_cache_t;
223/* }}} */
224/* {{{ xc_classinfo_t */
225typedef struct {
[14]226#ifdef IS_UNICODE
227    zend_uchar type;
228#endif
[103]229    zstr      key;
[1]230    zend_uint key_size;
[622]231    ulong     h;
[1]232    xc_cest_t cest;
[212]233    int       oplineno;
[1]234} xc_classinfo_t;
235/* }}} */
[95]236#ifdef HAVE_XCACHE_CONSTANT
237/* {{{ xc_constinfo_t */
238typedef struct {
239#ifdef IS_UNICODE
240    zend_uchar type;
241#endif
[103]242    zstr      key;
[95]243    zend_uint key_size;
[622]244    ulong     h;
[95]245    zend_constant constant;
246} xc_constinfo_t;
247/* }}} */
248#endif
[1]249/* {{{ xc_funcinfo_t */
250typedef struct {
[14]251#ifdef IS_UNICODE
252    zend_uchar type;
253#endif
[103]254    zstr      key;
[1]255    zend_uint key_size;
[622]256    ulong     h;
[1]257    zend_function func;
258} xc_funcinfo_t;
259/* }}} */
[268]260#ifdef ZEND_ENGINE_2_1
261/* {{{ xc_autoglobal_t */
262typedef struct {
263#ifdef IS_UNICODE
264    zend_uchar type;
265#endif
266    zstr       key;
267    zend_uint  key_len;
[622]268    ulong      h;
[268]269} xc_autoglobal_t;
270/* }}} */
271#endif
[1]272typedef enum { XC_TYPE_PHP, XC_TYPE_VAR } xc_entry_type_t;
273/* {{{ xc_entry_data_php_t */
274typedef struct {
275    size_t sourcesize;
276#ifdef HAVE_INODE
277    int device;             /* the filesystem device */
278    int inode;              /* the filesystem inode */
279#endif
280    time_t mtime;           /* the mtime of origin source file */
281
282    zend_op_array *op_array;
283
[95]284#ifdef HAVE_XCACHE_CONSTANT
285    zend_uint constinfo_cnt;
286    xc_constinfo_t *constinfos;
287#endif
288
[1]289    zend_uint funcinfo_cnt;
290    xc_funcinfo_t *funcinfos;
291
292    zend_uint classinfo_cnt;
293    xc_classinfo_t *classinfos;
[212]294    zend_bool have_early_binding;
[268]295
296#ifdef ZEND_ENGINE_2_1
297    zend_uint autoglobal_cnt;
298    xc_autoglobal_t *autoglobals;
299#endif
[1]300} xc_entry_data_php_t;
301/* }}} */
302/* {{{ xc_entry_data_var_t */
303typedef struct {
304    zval   *value;
305} xc_entry_data_var_t;
306/* }}} */
307typedef zvalue_value xc_entry_name_t;
308/* {{{ xc_entry_t */
309struct _xc_entry_t {
310    xc_entry_type_t type;
311    xc_hash_value_t hvalue;
312    xc_entry_t *next;
313    xc_cache_t *cache;      /* which cache it's on */
314
315    size_t     size;
316    zend_ulong refcount;
317    zend_ulong hits;
318    time_t     ctime;           /* the ctime of this entry */
319    time_t     atime;           /* the atime of this entry */
320    time_t     dtime;           /* the deletion time of this entry */
[114]321    long       ttl;             /* ttl of time entry, var only */
[1]322
323#ifdef IS_UNICODE
324    zend_uchar name_type;
325#endif
326    xc_entry_name_t name;
327
328    union {
329        xc_entry_data_php_t *php;
330        xc_entry_data_var_t *var;
331    } data;
[233]332
333    zend_bool  have_references;
[1]334};
335/* }}} */
336
337extern zend_module_entry xcache_module_entry;
338#define phpext_xcache_ptr &xcache_module_entry
339
340int xc_is_rw(const void *p);
341int xc_is_ro(const void *p);
342int xc_is_shm(const void *p);
[619]343void xc_gc_add_op_array(zend_op_array *op_array TSRMLS_DC);
[1]344
345#endif /* __XCACHE_H */
Note: See TracBrowser for help on using the repository browser.