source: trunk/xcache.h @ 88

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

possible fix for #14 "Cannot redeclare ()"

File size: 5.2 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.u.string))
55#define BUCKET_UKEY(b) (UNISW((b)->arKey, (b)->key.u.unicode))
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#else
70#   define ZSTR_S(s) ((s)->s)
71#   define ZSTR_U(s) ((s)->u)
72#   define ZSTR_V(s) ((s)->v)
73#endif
74
75/* {{{ u hash wrapper */
76#ifndef IS_UNICODE
77#   define zend_u_hash_add(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
78       zend_hash_add(ht, arKey, nKeyLength, pData, nDataSize, pDest)
79
80#   define zend_u_hash_update(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
81       zend_hash_update(ht, arKey, nKeyLength, pData, nDataSize, pDest)
82
83#   define zend_u_hash_find(ht, type, arKey, nKeyLength, pData) \
84       zend_hash_find(ht, arKey, nKeyLength, pData)
85
86#   define add_u_assoc_zval_ex(arg, type, key, key_len, value) \
87        add_assoc_zval_ex(arg, key, key_len, value)
88
89#endif
90/* }}} */
91
92
93#define ECALLOC_N(x, n) ((x) = ecalloc(n, sizeof((x)[0])))
94#define ECALLOC_ONE(x) ECALLOC_N(x, 1)
95
96
97
98typedef ulong xc_hash_value_t;
99typedef struct {
100    int bits;
101    int size;
102    int mask;
103} xc_hash_t;
104
105/* the class entry type to be stored in class_table */
106typedef ZESW(zend_class_entry, zend_class_entry*) xc_cest_t;
107
108/* xc_cest_t to (zend_class_entry*) */
109#define CestToCePtr(st) (ZESW(\
110            &(st), \
111            st \
112            ) )
113
114/* ZCEP=zend class entry ptr */
115#define ZCEP_REFCOUNT_PTR(pce) (ZESW( \
116            (pce)->refcount, \
117            &((pce)->refcount) \
118            ))
119
120#define ZCE_REFCOUNT_PTR(ce) ZCE_REFCOUNT_PTR(&ce)
121
122typedef zend_op_array *(zend_compile_file_t)(zend_file_handle *h, int type TSRMLS_DC);
123
124/* {{{ xc_cache_t */
125typedef struct _xc_entry_t xc_entry_t;
126typedef struct {
127    int cacheid;
128    xc_hash_t  *hcache; /* hash to cacheid */
129
130    time_t     compiling;
131    zend_ulong misses;
132    zend_ulong hits;
133    zend_ulong clogs;
134    zend_ulong ooms;
135    xc_lock_t  *lck;
136    xc_shm_t   *shm; /* to which shm contains us */
137    xc_mem_t   *mem; /* to which mem contains us */
138
139    xc_entry_t **entries;
140    int entries_count;
141    xc_entry_t *deletes;
142    int deletes_count;
143    xc_hash_t  *hentry; /* hash to entry */
144} xc_cache_t;
145/* }}} */
146/* {{{ xc_classinfo_t */
147typedef struct {
148#ifdef IS_UNICODE
149    zend_uchar type;
150#endif
151    char *key;
152    zend_uint key_size;
153    xc_cest_t cest;
154} xc_classinfo_t;
155/* }}} */
156/* {{{ xc_funcinfo_t */
157typedef struct {
158#ifdef IS_UNICODE
159    zend_uchar type;
160#endif
161    char *key;
162    zend_uint key_size;
163    zend_function func;
164} xc_funcinfo_t;
165/* }}} */
166typedef enum { XC_TYPE_PHP, XC_TYPE_VAR } xc_entry_type_t;
167/* {{{ xc_entry_data_php_t */
168typedef struct {
169    size_t sourcesize;
170#ifdef HAVE_INODE
171    int device;             /* the filesystem device */
172    int inode;              /* the filesystem inode */
173#endif
174    time_t mtime;           /* the mtime of origin source file */
175
176    zend_op_array *op_array;
177
178    zend_uint funcinfo_cnt;
179    xc_funcinfo_t *funcinfos;
180
181    zend_uint classinfo_cnt;
182    xc_classinfo_t *classinfos;
183} xc_entry_data_php_t;
184/* }}} */
185/* {{{ xc_entry_data_var_t */
186typedef struct {
187    zval   *value;
188    time_t etime;
189} xc_entry_data_var_t;
190/* }}} */
191typedef zvalue_value xc_entry_name_t;
192/* {{{ xc_entry_t */
193struct _xc_entry_t {
194    xc_entry_type_t type;
195    xc_hash_value_t hvalue;
196    xc_entry_t *next;
197    xc_cache_t *cache;      /* which cache it's on */
198
199    size_t     size;
200    zend_ulong refcount;
201    zend_ulong hits;
202    time_t     ctime;           /* the ctime of this entry */
203    time_t     atime;           /* the atime of this entry */
204    time_t     dtime;           /* the deletion time of this entry */
205
206#ifdef IS_UNICODE
207    zend_uchar name_type;
208#endif
209    xc_entry_name_t name;
210
211    union {
212        xc_entry_data_php_t *php;
213        xc_entry_data_var_t *var;
214    } data;
215};
216/* }}} */
217
218extern zend_module_entry xcache_module_entry;
219#define phpext_xcache_ptr &xcache_module_entry
220
221int xc_is_rw(const void *p);
222int xc_is_ro(const void *p);
223int xc_is_shm(const void *p);
224
225#endif /* __XCACHE_H */
Note: See TracBrowser for help on using the repository browser.