source: trunk/xcache.h @ 78

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

catch up with PHP_5_2, zend_property_info.ce

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