source: trunk/xcache.h @ 103

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

PHP_6: builds again with php6. update UChar/void ptr to zstr.

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