source: trunk/xcache.h @ 485

Last change on this file since 485 was 485, checked in by moo, 6 years ago

5.3 support

  • Property svn:eol-style set to native
File size: 8.5 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
58
[263]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
[1]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                ))
[200]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))
[2]102#ifdef IS_UNICODE
[104]103#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, key.arKey)
[2]104#else
[11]105#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, arKey)
[2]106#endif
[1]107#define BUCKET_SIZE(b) (BUCKET_HEAD_SIZE(b) + BUCKET_KEY_SIZE(b))
108
109#ifndef IS_UNICODE
110typedef char *zstr;
[103]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)
[1]117#else
[103]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)
[1]124#endif
125
[103]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
[1]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
[88]140#   define zend_u_hash_update(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
141       zend_hash_update(ht, arKey, nKeyLength, pData, nDataSize, pDest)
142
[1]143#   define zend_u_hash_find(ht, type, arKey, nKeyLength, pData) \
144       zend_hash_find(ht, arKey, nKeyLength, pData)
145
[200]146#   define zend_u_hash_quick_find(ht, type, arKey, nKeyLength, h, pData) \
147       zend_hash_quick_find(ht, arKey, nKeyLength, h, pData)
148
[1]149#   define add_u_assoc_zval_ex(arg, type, key, key_len, value) \
150        add_assoc_zval_ex(arg, key, key_len, value)
151
[268]152#   define zend_u_is_auto_global(type, name, name_len) \
153        zend_is_auto_global(name, name_len)
[1]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
[311]189typedef struct _xc_entry_t xc_entry_t;
190typedef struct _xc_entry_data_php_t xc_entry_data_php_t;
[1]191/* {{{ xc_cache_t */
[11]192typedef struct {
[1]193    int cacheid;
194    xc_hash_t  *hcache; /* hash to cacheid */
195
[11]196    time_t     compiling;
[1]197    zend_ulong misses;
198    zend_ulong hits;
199    zend_ulong clogs;
200    zend_ulong ooms;
[456]201    zend_ulong errors;
[1]202    xc_lock_t  *lck;
203    xc_shm_t   *shm; /* to which shm contains us */
204    xc_mem_t   *mem; /* to which mem contains us */
205
206    xc_entry_t **entries;
[32]207    int entries_count;
[311]208    xc_entry_data_php_t **phps;
209    int phps_count;
[1]210    xc_entry_t *deletes;
[32]211    int deletes_count;
[311]212    xc_hash_t  *hentry; /* hash settings to entry */
213    xc_hash_t  *hphp;   /* hash settings to php */
[114]214
215    time_t     last_gc_deletes;
216    time_t     last_gc_expires;
[1]217} xc_cache_t;
218/* }}} */
219/* {{{ xc_classinfo_t */
220typedef struct {
[14]221#ifdef IS_UNICODE
222    zend_uchar type;
223#endif
[103]224    zstr      key;
[1]225    zend_uint key_size;
226    xc_cest_t cest;
[212]227    int       oplineno;
[1]228} xc_classinfo_t;
229/* }}} */
[95]230#ifdef HAVE_XCACHE_CONSTANT
231/* {{{ xc_constinfo_t */
232typedef struct {
233#ifdef IS_UNICODE
234    zend_uchar type;
235#endif
[103]236    zstr      key;
[95]237    zend_uint key_size;
238    zend_constant constant;
239} xc_constinfo_t;
240/* }}} */
241#endif
[1]242/* {{{ xc_funcinfo_t */
243typedef struct {
[14]244#ifdef IS_UNICODE
245    zend_uchar type;
246#endif
[103]247    zstr      key;
[1]248    zend_uint key_size;
249    zend_function func;
250} xc_funcinfo_t;
251/* }}} */
[268]252#ifdef ZEND_ENGINE_2_1
253/* {{{ xc_autoglobal_t */
254typedef struct {
255#ifdef IS_UNICODE
256    zend_uchar type;
257#endif
258    zstr       key;
259    zend_uint  key_len;
260} xc_autoglobal_t;
261/* }}} */
262#endif
[1]263typedef enum { XC_TYPE_PHP, XC_TYPE_VAR } xc_entry_type_t;
[311]264typedef char xc_md5sum_t[16];
[1]265/* {{{ xc_entry_data_php_t */
[311]266struct _xc_entry_data_php_t {
267    xc_hash_value_t hvalue; /* hash of md5 */
268    xc_entry_data_php_t *next;
269    xc_cache_t *cache;      /* which cache it's on */
270
271    xc_md5sum_t md5;        /* md5sum of the source */
272    zend_ulong  refcount;   /* count of entries referencing to this data */
273
[1]274    size_t sourcesize;
[311]275    zend_ulong hits;        /* hits of this php */
276    size_t     size;
[1]277
278    zend_op_array *op_array;
279
[95]280#ifdef HAVE_XCACHE_CONSTANT
281    zend_uint constinfo_cnt;
282    xc_constinfo_t *constinfos;
283#endif
284
[1]285    zend_uint funcinfo_cnt;
286    xc_funcinfo_t *funcinfos;
287
288    zend_uint classinfo_cnt;
289    xc_classinfo_t *classinfos;
[212]290    zend_bool have_early_binding;
[268]291
292#ifdef ZEND_ENGINE_2_1
293    zend_uint autoglobal_cnt;
294    xc_autoglobal_t *autoglobals;
295#endif
[311]296
297    zend_bool  have_references;
298};
[1]299/* }}} */
300/* {{{ xc_entry_data_var_t */
301typedef struct {
302    zval   *value;
[311]303
304    zend_bool  have_references;
[1]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;
[311]316    zend_ulong refcount;    /* count of instances holding this entry */
[1]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
[311]333    time_t mtime;           /* the mtime of origin source file */
334#ifdef HAVE_INODE
335    int device;             /* the filesystem device */
336    int inode;              /* the filesystem inode */
337#endif
[1]338};
339/* }}} */
340
341extern zend_module_entry xcache_module_entry;
342#define phpext_xcache_ptr &xcache_module_entry
343
344int xc_is_rw(const void *p);
345int xc_is_ro(const void *p);
346int xc_is_shm(const void *p);
347
348#endif /* __XCACHE_H */
Note: See TracBrowser for help on using the repository browser.