source: trunk/xcache.h @ 212

Last change on this file since 212 was 212, checked in by moo, 8 years ago

fixed #41, early class binding

File size: 6.1 KB
Line 
1#ifndef __XCACHE_H
2#define __XCACHE_H
3#define XCACHE_NAME       "XCache"
4#define XCACHE_VERSION    "1.2-dev"
5#define XCACHE_AUTHOR     "mOo"
6#define XCACHE_COPYRIGHT  "Copyright (c) 2005-2006"
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
18#include "xc_shm.h"
19#include "lock.h"
20
21#define HAVE_INODE
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
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
28
29#define NOTHING
30/* ZendEngine code Switcher */
31#ifndef ZEND_ENGINE_2
32#   define ZESW(v1, v2) v1
33#else
34#   define ZESW(v1, v2) v2
35#endif
36
37/* unicode */
38#ifdef IS_UNICODE
39#   define UNISW(text, unicode) unicode
40#else
41#   define UNISW(text, unicode) text
42#endif
43#define BUCKET_KEY_SIZE(b) \
44        (UNISW( \
45            (b)->nKeyLength, \
46                ((b)->key.type == IS_UNICODE) \
47                ? UBYTES(b->nKeyLength) \
48                : b->nKeyLength \
49                ))
50#define BUCKET_KEY_S(b)    (UNISW((b)->arKey, (b)->key.arKey.s))
51#define BUCKET_KEY_U(b)    (UNISW((b)->arKey, (b)->key.arKey.u))
52#define BUCKET_KEY_TYPE(b) (UNISW(IS_STRING,  (b)->key.type))
53#ifdef IS_UNICODE
54#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, key.arKey)
55#else
56#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, arKey)
57#endif
58#define BUCKET_SIZE(b) (BUCKET_HEAD_SIZE(b) + BUCKET_KEY_SIZE(b))
59
60#ifndef IS_UNICODE
61typedef char *zstr;
62#   define ZSTR_S(s)     (s)
63#   define ZSTR_U(s)     (s)
64#   define ZSTR_V(s)     (s)
65#   define ZSTR_PS(s)    (s)
66#   define ZSTR_PU(s)    (s)
67#   define ZSTR_PV(s)    (s)
68#else
69#   define ZSTR_S(zs)    ((zs).s)
70#   define ZSTR_U(zs)    ((zs).u)
71#   define ZSTR_V(zs)    ((zs).v)
72#   define ZSTR_PS(pzs)  ((pzs)->s)
73#   define ZSTR_PU(pzs)  ((pzs)->u)
74#   define ZSTR_PV(pzs)  ((pzs)->v)
75#endif
76
77#ifndef ZSTR
78#   define ZSTR(s)      (s)
79#endif
80
81#ifndef Z_UNIVAL
82#   define Z_UNIVAL(zval) (zval).value.str.val
83#   define Z_UNILEN(zval) (zval).value.str.len
84#endif
85
86/* {{{ u hash wrapper */
87#ifndef IS_UNICODE
88#   define zend_u_hash_add(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
89       zend_hash_add(ht, arKey, nKeyLength, pData, nDataSize, pDest)
90
91#   define zend_u_hash_update(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
92       zend_hash_update(ht, arKey, nKeyLength, pData, nDataSize, pDest)
93
94#   define zend_u_hash_find(ht, type, arKey, nKeyLength, pData) \
95       zend_hash_find(ht, arKey, nKeyLength, pData)
96
97#   define zend_u_hash_quick_find(ht, type, arKey, nKeyLength, h, pData) \
98       zend_hash_quick_find(ht, arKey, nKeyLength, h, pData)
99
100#   define add_u_assoc_zval_ex(arg, type, key, key_len, value) \
101        add_assoc_zval_ex(arg, key, key_len, value)
102
103#endif
104/* }}} */
105
106
107#define ECALLOC_N(x, n) ((x) = ecalloc(n, sizeof((x)[0])))
108#define ECALLOC_ONE(x) ECALLOC_N(x, 1)
109
110
111
112typedef ulong xc_hash_value_t;
113typedef struct {
114    int bits;
115    int size;
116    int mask;
117} xc_hash_t;
118
119/* the class entry type to be stored in class_table */
120typedef ZESW(zend_class_entry, zend_class_entry*) xc_cest_t;
121
122/* xc_cest_t to (zend_class_entry*) */
123#define CestToCePtr(st) (ZESW(\
124            &(st), \
125            st \
126            ) )
127
128/* ZCEP=zend class entry ptr */
129#define ZCEP_REFCOUNT_PTR(pce) (ZESW( \
130            (pce)->refcount, \
131            &((pce)->refcount) \
132            ))
133
134#define ZCE_REFCOUNT_PTR(ce) ZCE_REFCOUNT_PTR(&ce)
135
136typedef zend_op_array *(zend_compile_file_t)(zend_file_handle *h, int type TSRMLS_DC);
137
138/* {{{ xc_cache_t */
139typedef struct _xc_entry_t xc_entry_t;
140typedef struct {
141    int cacheid;
142    xc_hash_t  *hcache; /* hash to cacheid */
143
144    time_t     compiling;
145    zend_ulong misses;
146    zend_ulong hits;
147    zend_ulong clogs;
148    zend_ulong ooms;
149    xc_lock_t  *lck;
150    xc_shm_t   *shm; /* to which shm contains us */
151    xc_mem_t   *mem; /* to which mem contains us */
152
153    xc_entry_t **entries;
154    int entries_count;
155    xc_entry_t *deletes;
156    int deletes_count;
157    xc_hash_t  *hentry; /* hash to entry */
158
159    time_t     last_gc_deletes;
160    time_t     last_gc_expires;
161} xc_cache_t;
162/* }}} */
163/* {{{ xc_classinfo_t */
164typedef struct {
165#ifdef IS_UNICODE
166    zend_uchar type;
167#endif
168    zstr      key;
169    zend_uint key_size;
170    xc_cest_t cest;
171    int       oplineno;
172} xc_classinfo_t;
173/* }}} */
174#ifdef HAVE_XCACHE_CONSTANT
175/* {{{ xc_constinfo_t */
176typedef struct {
177#ifdef IS_UNICODE
178    zend_uchar type;
179#endif
180    zstr      key;
181    zend_uint key_size;
182    zend_constant constant;
183} xc_constinfo_t;
184/* }}} */
185#endif
186/* {{{ xc_funcinfo_t */
187typedef struct {
188#ifdef IS_UNICODE
189    zend_uchar type;
190#endif
191    zstr      key;
192    zend_uint key_size;
193    zend_function func;
194} xc_funcinfo_t;
195/* }}} */
196typedef enum { XC_TYPE_PHP, XC_TYPE_VAR } xc_entry_type_t;
197/* {{{ xc_entry_data_php_t */
198typedef struct {
199    size_t sourcesize;
200#ifdef HAVE_INODE
201    int device;             /* the filesystem device */
202    int inode;              /* the filesystem inode */
203#endif
204    time_t mtime;           /* the mtime of origin source file */
205
206    zend_op_array *op_array;
207
208#ifdef HAVE_XCACHE_CONSTANT
209    zend_uint constinfo_cnt;
210    xc_constinfo_t *constinfos;
211#endif
212
213    zend_uint funcinfo_cnt;
214    xc_funcinfo_t *funcinfos;
215
216    zend_uint classinfo_cnt;
217    xc_classinfo_t *classinfos;
218    zend_bool have_early_binding;
219} xc_entry_data_php_t;
220/* }}} */
221/* {{{ xc_entry_data_var_t */
222typedef struct {
223    zval   *value;
224} xc_entry_data_var_t;
225/* }}} */
226typedef zvalue_value xc_entry_name_t;
227/* {{{ xc_entry_t */
228struct _xc_entry_t {
229    xc_entry_type_t type;
230    xc_hash_value_t hvalue;
231    xc_entry_t *next;
232    xc_cache_t *cache;      /* which cache it's on */
233
234    size_t     size;
235    zend_ulong refcount;
236    zend_ulong hits;
237    time_t     ctime;           /* the ctime of this entry */
238    time_t     atime;           /* the atime of this entry */
239    time_t     dtime;           /* the deletion time of this entry */
240    long       ttl;             /* ttl of time entry, var only */
241
242#ifdef IS_UNICODE
243    zend_uchar name_type;
244#endif
245    xc_entry_name_t name;
246
247    union {
248        xc_entry_data_php_t *php;
249        xc_entry_data_var_t *var;
250    } data;
251};
252/* }}} */
253
254extern zend_module_entry xcache_module_entry;
255#define phpext_xcache_ptr &xcache_module_entry
256
257int xc_is_rw(const void *p);
258int xc_is_ro(const void *p);
259int xc_is_shm(const void *p);
260
261#endif /* __XCACHE_H */
Note: See TracBrowser for help on using the repository browser.