source: trunk/xcache.h @ 480

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

compile against PHP_5_3

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