2006-05-09 10:58:38 +00:00
|
|
|
dnl {{{ === program start ========================================
|
|
|
|
divert(0)
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "php.h"
|
2006-09-20 00:24:42 +00:00
|
|
|
#include "zend_extensions.h"
|
2006-05-09 10:58:38 +00:00
|
|
|
#include "zend_compile.h"
|
|
|
|
#include "zend_API.h"
|
2006-05-13 01:54:55 +00:00
|
|
|
#include "zend_ini.h"
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
#include "xcache.h"
|
|
|
|
#include "align.h"
|
|
|
|
#include "const_string.h"
|
|
|
|
#include "processor.h"
|
|
|
|
#include "stack.h"
|
|
|
|
#include "xcache_globals.h"
|
|
|
|
|
2006-06-03 02:30:58 +00:00
|
|
|
#if defined(HARDENING_PATCH_HASH_PROTECT) && HARDENING_PATCH_HASH_PROTECT
|
|
|
|
extern unsigned int zend_hash_canary;
|
|
|
|
#endif
|
|
|
|
|
2006-05-09 10:58:38 +00:00
|
|
|
define(`SIZEOF_zend_uint', `sizeof(zend_uint)')
|
|
|
|
define(`COUNTOF_zend_uint', `1')
|
|
|
|
define(`SIZEOF_int', `sizeof(int)')
|
|
|
|
define(`COUNTOF_int', `1')
|
|
|
|
define(`SIZEOF_zend_function', `sizeof(zend_function)')
|
|
|
|
define(`COUNTOF_zend_function', `1')
|
|
|
|
define(`SIZEOF_zval_ptr', `sizeof(zval_ptr)')
|
|
|
|
define(`COUNTOF_zval_ptr', `1')
|
2012-03-22 18:18:05 +00:00
|
|
|
define(`SIZEOF_zval_ptr_nullable', `sizeof(zval_ptr_nullable)')
|
|
|
|
define(`COUNTOF_zval_ptr_nullable', `1')
|
2012-03-25 01:59:20 +00:00
|
|
|
define(`SIZEOF_zend_trait_alias_ptr', `sizeof(zend_trait_alias)')
|
|
|
|
define(`COUNTOF_zend_trait_alias_ptr', `1')
|
|
|
|
define(`SIZEOF_zend_trait_precedence_ptr', `sizeof(zend_trait_precedence)')
|
|
|
|
define(`COUNTOF_zend_trait_precedence_ptr', `1')
|
2006-05-09 10:58:38 +00:00
|
|
|
define(`SIZEOF_xc_entry_name_t', `sizeof(xc_entry_name_t)')
|
|
|
|
define(`COUNTOF_xc_entry_name_t', `1')
|
2012-03-25 07:01:16 +00:00
|
|
|
define(`SIZEOF_xc_ztstring', `sizeof(xc_ztstring)')
|
|
|
|
define(`COUNTOF_xc_ztstring', `1')
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
ifdef(`XCACHE_ENABLE_TEST', `
|
|
|
|
#undef NDEBUG
|
|
|
|
#include <assert.h>
|
2006-05-26 02:31:45 +00:00
|
|
|
m4_errprint(`AUTOCHECK INFO: runtime autocheck Enabled (debug build)')
|
|
|
|
', `
|
|
|
|
m4_errprint(`AUTOCHECK INFO: runtime autocheck Disabled (optimized build)')
|
2006-05-09 10:58:38 +00:00
|
|
|
')
|
2006-12-03 07:58:23 +00:00
|
|
|
ifdef(`DEBUG_SIZE', `static int xc_totalsize = 0;')
|
|
|
|
|
2006-05-26 02:31:45 +00:00
|
|
|
sinclude(builddir`/structinfo.m4')
|
|
|
|
|
2006-05-09 10:58:38 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
# undef inline
|
|
|
|
#define inline
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef zval *zval_ptr;
|
2012-03-22 18:18:05 +00:00
|
|
|
typedef zval *zval_ptr_nullable;
|
2012-03-25 07:01:16 +00:00
|
|
|
typedef char *xc_ztstring;
|
2012-03-25 01:59:20 +00:00
|
|
|
#ifdef ZEND_ENGINE_2_4
|
|
|
|
typedef zend_trait_alias *zend_trait_alias_ptr;
|
|
|
|
typedef zend_trait_precedence *zend_trait_precedence_ptr;
|
|
|
|
#endif
|
|
|
|
|
2012-03-25 07:01:16 +00:00
|
|
|
typedef zend_uchar xc_zval_data_type;
|
|
|
|
typedef int xc_op_type;
|
|
|
|
typedef zend_uchar xc_opcode;
|
2006-08-27 05:09:02 +00:00
|
|
|
#ifdef IS_UNICODE
|
|
|
|
typedef UChar zstr_uchar;
|
|
|
|
#endif
|
|
|
|
typedef char zstr_char;
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
#define MAX_DUP_STR_LEN 256
|
|
|
|
dnl }}}
|
2006-09-18 00:27:17 +00:00
|
|
|
/* export: typedef struct _xc_processor_t xc_processor_t; :export {{{ */
|
|
|
|
struct _xc_processor_t {
|
2006-05-09 10:58:38 +00:00
|
|
|
char *p;
|
|
|
|
zend_uint size;
|
|
|
|
HashTable strings;
|
|
|
|
HashTable zvalptrs;
|
|
|
|
zend_bool reference; /* enable if to deal with reference */
|
2006-10-10 00:46:00 +00:00
|
|
|
zend_bool have_references;
|
2009-09-29 11:25:01 +00:00
|
|
|
const xc_entry_t *entry_src;
|
|
|
|
const xc_entry_t *entry_dst;
|
2006-12-09 16:27:03 +00:00
|
|
|
const xc_entry_data_php_t *php_src;
|
|
|
|
const xc_entry_data_php_t *php_dst;
|
|
|
|
const xc_cache_t *cache;
|
2006-05-09 10:58:38 +00:00
|
|
|
const zend_class_entry *cache_ce;
|
2009-08-03 08:15:53 +00:00
|
|
|
zend_uint cache_class_index;
|
2006-05-09 10:58:38 +00:00
|
|
|
|
2011-04-22 07:51:38 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
const zend_op_array *active_op_array_src;
|
|
|
|
zend_op_array *active_op_array_dst;
|
|
|
|
#endif
|
2006-05-09 10:58:38 +00:00
|
|
|
const zend_op *active_opcodes_src;
|
|
|
|
zend_op *active_opcodes_dst;
|
|
|
|
const zend_class_entry *active_class_entry_src;
|
|
|
|
zend_class_entry *active_class_entry_dst;
|
2009-08-03 08:15:53 +00:00
|
|
|
zend_uint active_class_index;
|
|
|
|
zend_uint active_op_array_index;
|
|
|
|
const xc_op_array_info_t *active_op_array_infos_src;
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
zend_bool readonly_protection; /* wheather it's present */
|
|
|
|
IFASSERT(xc_stack_t allocsizes;)
|
|
|
|
};
|
|
|
|
/* }}} */
|
2012-03-25 01:59:20 +00:00
|
|
|
/* {{{ memsetptr */
|
|
|
|
IFASSERT(`dnl
|
|
|
|
static void *memsetptr(void *mem, void *content, size_t n)
|
|
|
|
{
|
|
|
|
void **p = (void **) mem;
|
2012-03-25 07:18:30 +00:00
|
|
|
void **end = (void **) ((char *) mem + n);
|
2012-03-25 02:24:14 +00:00
|
|
|
while (p < end - sizeof(content)) {
|
2012-03-25 01:59:20 +00:00
|
|
|
*p = content;
|
|
|
|
p += sizeof(content);
|
|
|
|
}
|
2012-03-25 02:24:14 +00:00
|
|
|
if (p < end) {
|
|
|
|
memset(p, -1, end - p);
|
|
|
|
}
|
2012-03-25 01:59:20 +00:00
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
')
|
|
|
|
/* }}} */
|
2006-10-10 00:31:50 +00:00
|
|
|
#ifdef HAVE_XCACHE_DPRINT
|
2006-05-09 10:58:38 +00:00
|
|
|
static void xc_dprint_indent(int indent) /* {{{ */
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < indent; i ++) {
|
|
|
|
fprintf(stderr, " ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
2006-10-10 00:31:50 +00:00
|
|
|
static void xc_dprint_str_len(const char *str, int len) /* {{{ */
|
|
|
|
{
|
2006-12-03 01:48:53 +00:00
|
|
|
const unsigned char *p = (const unsigned char *) str;
|
2006-10-10 00:31:50 +00:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < len; i ++) {
|
|
|
|
if (p[i] < 32 || p[i] == 127) {
|
|
|
|
fprintf(stderr, "\\%03o", (unsigned int) p[i]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fputc(p[i], stderr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
#endif
|
2006-08-27 05:09:02 +00:00
|
|
|
/* {{{ xc_zstrlen_char */
|
2012-03-25 07:18:30 +00:00
|
|
|
static inline int xc_zstrlen_char(const_zstr s)
|
2006-08-27 05:09:02 +00:00
|
|
|
{
|
|
|
|
return strlen(ZSTR_S(s));
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
#ifdef IS_UNICODE
|
|
|
|
/* {{{ xc_zstrlen_uchar */
|
|
|
|
static inline int xc_zstrlen_uchar(zstr s)
|
|
|
|
{
|
2008-01-05 10:44:30 +00:00
|
|
|
return u_strlen(ZSTR_U(s));
|
2006-08-27 05:09:02 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
/* {{{ xc_zstrlen */
|
2012-03-25 07:18:30 +00:00
|
|
|
static inline int xc_zstrlen(int type, const_zstr s)
|
2006-08-27 05:09:02 +00:00
|
|
|
{
|
|
|
|
return type == IS_UNICODE ? xc_zstrlen_uchar(s) : xc_zstrlen_char(s);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
#else
|
|
|
|
/* {{{ xc_zstrlen */
|
|
|
|
#define xc_zstrlen(dummy, s) xc_zstrlen_char(s)
|
|
|
|
/* }}} */
|
|
|
|
#endif
|
2006-05-09 10:58:38 +00:00
|
|
|
/* {{{ xc_calc_string_n */
|
|
|
|
REDEF(`KIND', `calc')
|
2010-05-29 15:39:00 +00:00
|
|
|
#undef C_RELAYLINE
|
|
|
|
#define C_RELAYLINE
|
|
|
|
IFASSERT(`
|
|
|
|
#undef C_RELAYLINE
|
|
|
|
#define C_RELAYLINE , __LINE__
|
|
|
|
')
|
2012-03-26 09:41:19 +00:00
|
|
|
static inline void xc_calc_string_n(xc_processor_t *processor, zend_uchar type, const_zstr str, long size IFASSERT(`, int relayline')) {
|
2006-05-09 10:58:38 +00:00
|
|
|
pushdef(`__LINE__', `relayline')
|
|
|
|
int realsize = UNISW(size, (type == IS_UNICODE) ? UBYTES(size) : size);
|
2006-08-27 05:09:02 +00:00
|
|
|
long dummy = 1;
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
if (realsize > MAX_DUP_STR_LEN) {
|
|
|
|
ALLOC(, char, realsize)
|
|
|
|
}
|
2006-08-27 05:09:02 +00:00
|
|
|
else if (zend_u_hash_add(&processor->strings, type, str, size, (void *) &dummy, sizeof(dummy), NULL) == SUCCESS) {
|
2006-05-09 10:58:38 +00:00
|
|
|
/* new string */
|
|
|
|
ALLOC(, char, realsize)
|
|
|
|
}
|
|
|
|
IFASSERT(`
|
|
|
|
else {
|
2006-08-27 05:09:02 +00:00
|
|
|
dnl fprintf(stderr, "dupstr %s\n", ZSTR_S(str));
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
')
|
|
|
|
popdef(`__LINE__')
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
/* {{{ xc_store_string_n */
|
|
|
|
REDEF(`KIND', `store')
|
2012-03-26 09:41:19 +00:00
|
|
|
static inline zstr xc_store_string_n(xc_processor_t *processor, zend_uchar type, const_zstr str, long size IFASSERT(`, int relayline')) {
|
2006-05-09 10:58:38 +00:00
|
|
|
pushdef(`__LINE__', `relayline')
|
|
|
|
int realsize = UNISW(size, (type == IS_UNICODE) ? UBYTES(size) : size);
|
2006-08-27 05:09:02 +00:00
|
|
|
zstr ret, *pret;
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
if (realsize > MAX_DUP_STR_LEN) {
|
2006-08-27 05:09:02 +00:00
|
|
|
ALLOC(ZSTR_V(ret), char, realsize)
|
|
|
|
memcpy(ZSTR_V(ret), ZSTR_V(str), realsize);
|
|
|
|
return ret;
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
2006-08-27 05:09:02 +00:00
|
|
|
|
|
|
|
if (zend_u_hash_find(&processor->strings, type, str, size, (void **) &pret) == SUCCESS) {
|
|
|
|
return *pret;
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
2006-08-27 05:09:02 +00:00
|
|
|
|
|
|
|
/* new string */
|
|
|
|
ALLOC(ZSTR_V(ret), char, realsize)
|
|
|
|
memcpy(ZSTR_V(ret), ZSTR_V(str), realsize);
|
|
|
|
zend_u_hash_add(&processor->strings, type, str, size, (void *) &ret, sizeof(zstr), NULL);
|
|
|
|
return ret;
|
|
|
|
|
2006-05-09 10:58:38 +00:00
|
|
|
popdef(`__LINE__')
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
/* {{{ xc_get_class_num
|
|
|
|
* return class_index + 1
|
|
|
|
*/
|
2006-09-18 00:27:17 +00:00
|
|
|
static zend_ulong xc_get_class_num(xc_processor_t *processor, zend_class_entry *ce) {
|
2006-07-16 06:06:46 +00:00
|
|
|
zend_ulong i;
|
2006-12-09 16:27:03 +00:00
|
|
|
const xc_entry_data_php_t *php = processor->php_src;
|
2006-05-09 10:58:38 +00:00
|
|
|
zend_class_entry *ceptr;
|
|
|
|
|
|
|
|
if (processor->cache_ce == ce) {
|
2009-08-03 08:15:53 +00:00
|
|
|
return processor->cache_class_index + 1;
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
2006-12-09 16:27:03 +00:00
|
|
|
for (i = 0; i < php->classinfo_cnt; i ++) {
|
|
|
|
ceptr = CestToCePtr(php->classinfos[i].cest);
|
2006-05-09 10:58:38 +00:00
|
|
|
if (ZCEP_REFCOUNT_PTR(ceptr) == ZCEP_REFCOUNT_PTR(ce)) {
|
|
|
|
processor->cache_ce = ceptr;
|
2009-08-04 11:14:00 +00:00
|
|
|
processor->cache_class_index = i;
|
2006-05-09 10:58:38 +00:00
|
|
|
return i + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(0);
|
2006-07-16 06:06:46 +00:00
|
|
|
return (zend_ulong) -1;
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
2009-08-03 08:15:53 +00:00
|
|
|
define(`xc_get_class_num', `xc_get_class_numNOTDEFINED')
|
2006-05-09 10:58:38 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ xc_get_class */
|
|
|
|
#ifdef ZEND_ENGINE_2
|
2006-09-18 00:27:17 +00:00
|
|
|
static zend_class_entry *xc_get_class(xc_processor_t *processor, zend_ulong class_num) {
|
2006-05-09 10:58:38 +00:00
|
|
|
/* must be parent or currrent class */
|
2009-08-03 08:15:53 +00:00
|
|
|
assert(class_num <= processor->active_class_index + 1);
|
2006-12-09 16:27:03 +00:00
|
|
|
return CestToCePtr(processor->php_dst->classinfos[class_num - 1].cest);
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
#endif
|
2009-08-03 08:15:53 +00:00
|
|
|
define(`xc_get_class', `xc_get_classNOTDEFINED')
|
2006-05-09 10:58:38 +00:00
|
|
|
/* }}} */
|
|
|
|
#ifdef ZEND_ENGINE_2
|
|
|
|
/* fix method on store */
|
2008-01-05 09:12:31 +00:00
|
|
|
static void xc_fix_method(xc_processor_t *processor, zend_op_array *dst TSRMLS_DC) /* {{{ */
|
2006-05-09 10:58:38 +00:00
|
|
|
{
|
|
|
|
zend_function *zf = (zend_function *) dst;
|
|
|
|
zend_class_entry *ce = processor->active_class_entry_dst;
|
2008-01-05 09:12:31 +00:00
|
|
|
const zend_class_entry *srcce = processor->active_class_entry_src;
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
/* Fixing up the default functions for objects here since
|
|
|
|
* we need to compare with the newly allocated functions
|
|
|
|
*
|
|
|
|
* caveat: a sub-class method can have the same name as the
|
|
|
|
* parent~s constructor and create problems.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (zf->common.fn_flags & ZEND_ACC_CTOR) {
|
|
|
|
if (!ce->constructor) {
|
|
|
|
ce->constructor = zf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (zf->common.fn_flags & ZEND_ACC_DTOR) {
|
|
|
|
ce->destructor = zf;
|
|
|
|
}
|
|
|
|
else if (zf->common.fn_flags & ZEND_ACC_CLONE) {
|
|
|
|
ce->clone = zf;
|
|
|
|
}
|
|
|
|
else {
|
2008-01-05 09:12:31 +00:00
|
|
|
pushdef(`SET_IF_SAME_NAMEs', `
|
2006-05-09 10:58:38 +00:00
|
|
|
SET_IF_SAME_NAME(__get);
|
|
|
|
SET_IF_SAME_NAME(__set);
|
2006-05-31 01:22:18 +00:00
|
|
|
#ifdef ZEND_ENGINE_2_1
|
2006-05-09 10:58:38 +00:00
|
|
|
SET_IF_SAME_NAME(__unset);
|
|
|
|
SET_IF_SAME_NAME(__isset);
|
2006-05-31 01:22:18 +00:00
|
|
|
#endif
|
2006-05-09 10:58:38 +00:00
|
|
|
SET_IF_SAME_NAME(__call);
|
2007-10-01 11:24:34 +00:00
|
|
|
#ifdef ZEND_CALLSTATIC_FUNC_NAME
|
|
|
|
SET_IF_SAME_NAME(__callstatic);
|
|
|
|
#endif
|
2006-07-16 09:19:40 +00:00
|
|
|
#if defined(ZEND_ENGINE_2_2) || PHP_MAJOR_VERSION >= 6
|
2006-05-09 10:58:38 +00:00
|
|
|
SET_IF_SAME_NAME(__tostring);
|
|
|
|
#endif
|
2008-01-05 09:12:31 +00:00
|
|
|
')
|
|
|
|
#ifdef IS_UNICODE
|
|
|
|
if (UG(unicode)) {
|
|
|
|
#define SET_IF_SAME_NAME(member) \
|
|
|
|
do { \
|
2008-01-05 09:42:09 +00:00
|
|
|
if (srcce->member && u_strcmp(ZSTR_U(zf->common.function_name), ZSTR_U(srcce->member->common.function_name)) == 0) { \
|
2008-01-05 09:12:31 +00:00
|
|
|
ce->member = zf; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
while(0)
|
2006-05-09 10:58:38 +00:00
|
|
|
|
2008-01-05 09:12:31 +00:00
|
|
|
SET_IF_SAME_NAMEs()
|
2006-05-09 10:58:38 +00:00
|
|
|
#undef SET_IF_SAME_NAME
|
2008-01-05 09:12:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
do {
|
|
|
|
#define SET_IF_SAME_NAME(member) \
|
|
|
|
do { \
|
|
|
|
if (srcce->member && strcmp(ZSTR_S(zf->common.function_name), ZSTR_S(srcce->member->common.function_name)) == 0) { \
|
|
|
|
ce->member = zf; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
while(0)
|
|
|
|
|
|
|
|
SET_IF_SAME_NAMEs()
|
|
|
|
#undef SET_IF_SAME_NAME
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
popdef(`SET_IF_SAME_NAMEs')
|
|
|
|
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
2006-09-24 08:33:31 +00:00
|
|
|
#endif
|
2006-09-24 05:14:13 +00:00
|
|
|
/* {{{ call op_array ctor handler */
|
|
|
|
extern zend_bool xc_have_op_array_ctor;
|
|
|
|
static void xc_zend_extension_op_array_ctor_handler(zend_extension *extension, zend_op_array *op_array TSRMLS_DC)
|
|
|
|
{
|
|
|
|
if (extension->op_array_ctor) {
|
|
|
|
extension->op_array_ctor(op_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
2011-04-09 10:22:14 +00:00
|
|
|
/* {{{ field name checker */
|
|
|
|
IFASSERT(`dnl
|
2012-03-25 01:59:20 +00:00
|
|
|
static int xc_check_names(const char *file, int line, const char *functionName, const char **assert_names, int assert_names_count, HashTable *done_names)
|
2011-04-09 10:22:14 +00:00
|
|
|
{
|
|
|
|
int errors = 0;
|
|
|
|
if (assert_names_count) {
|
|
|
|
int i;
|
|
|
|
Bucket *b;
|
|
|
|
|
|
|
|
for (i = 0; i < assert_names_count; ++i) {
|
|
|
|
if (!zend_hash_exists(done_names, assert_names[i], strlen(assert_names[i]) + 1)) {
|
|
|
|
fprintf(stderr
|
|
|
|
, "missing field at %s `#'%d %s`' : %s\n"
|
|
|
|
, file, line, functionName
|
|
|
|
, assert_names[i]
|
|
|
|
);
|
|
|
|
++errors;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (b = done_names->pListHead; b != NULL; b = b->pListNext) {
|
|
|
|
int known = 0;
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < assert_names_count; ++i) {
|
|
|
|
if (strcmp(assert_names[i], BUCKET_KEY_S(b)) == 0) {
|
|
|
|
known = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!known) {
|
|
|
|
fprintf(stderr
|
|
|
|
, "unknown field at %s `#'%d %s`' : %s\n"
|
|
|
|
, file, line, functionName
|
|
|
|
, BUCKET_KEY_S(b)
|
|
|
|
);
|
|
|
|
++errors;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
')
|
|
|
|
/* }}} */
|
2006-05-09 10:58:38 +00:00
|
|
|
dnl ================ export API
|
2006-12-09 16:27:03 +00:00
|
|
|
define(`DEFINE_STORE_API', `
|
|
|
|
/* export: $1 *xc_processor_store_$1($1 *src TSRMLS_DC); :export {{{ */
|
|
|
|
$1 *xc_processor_store_$1($1 *src TSRMLS_DC) {
|
|
|
|
$1 *dst;
|
2006-09-18 00:27:17 +00:00
|
|
|
xc_processor_t processor;
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
memset(&processor, 0, sizeof(processor));
|
2006-10-10 00:46:00 +00:00
|
|
|
processor.reference = 1;
|
2006-12-09 16:27:03 +00:00
|
|
|
processor.cache = src->cache;
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
IFASSERT(`xc_stack_init(&processor.allocsizes);')
|
|
|
|
|
|
|
|
/* calc size */ {
|
|
|
|
zend_hash_init(&processor.strings, 0, NULL, NULL, 0);
|
|
|
|
if (processor.reference) {
|
|
|
|
zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
processor.size = 0;
|
|
|
|
/* allocate */
|
|
|
|
processor.size = ALIGN(processor.size + sizeof(src[0]));
|
|
|
|
|
2006-12-09 16:27:03 +00:00
|
|
|
xc_calc_$1(&processor, src TSRMLS_CC);
|
2006-05-09 10:58:38 +00:00
|
|
|
if (processor.reference) {
|
|
|
|
zend_hash_destroy(&processor.zvalptrs);
|
|
|
|
}
|
|
|
|
zend_hash_destroy(&processor.strings);
|
|
|
|
}
|
|
|
|
src->size = processor.size;
|
2006-12-09 16:27:03 +00:00
|
|
|
ifelse(`$1', `xc_entry_t', `
|
|
|
|
src->data.var->have_references = processor.have_references;
|
|
|
|
', `
|
|
|
|
src->have_references = processor.have_references;
|
|
|
|
')
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
IFASSERT(`xc_stack_reverse(&processor.allocsizes);')
|
|
|
|
/* store {{{ */
|
|
|
|
{
|
|
|
|
IFASSERT(`char *oldp;')
|
|
|
|
zend_hash_init(&processor.strings, 0, NULL, NULL, 0);
|
|
|
|
if (processor.reference) {
|
|
|
|
zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* mem :) */
|
2006-12-09 16:27:03 +00:00
|
|
|
processor.p = (char *) processor.cache->mem->handlers->malloc(processor.cache->mem, processor.size);
|
2006-05-09 10:58:38 +00:00
|
|
|
if (processor.p == NULL) {
|
|
|
|
dst = NULL;
|
|
|
|
goto err_alloc;
|
|
|
|
}
|
|
|
|
IFASSERT(`oldp = processor.p;')
|
|
|
|
assert(processor.p == (char *) ALIGN(processor.p));
|
|
|
|
|
|
|
|
/* allocate */
|
2006-12-09 16:27:03 +00:00
|
|
|
dst = ($1 *) processor.p;
|
2006-05-09 10:58:38 +00:00
|
|
|
processor.p = (char *) ALIGN(processor.p + sizeof(dst[0]));
|
|
|
|
|
2006-12-09 16:27:03 +00:00
|
|
|
xc_store_$1(&processor, dst, src TSRMLS_CC);
|
2006-05-09 10:58:38 +00:00
|
|
|
IFASSERT(` {
|
|
|
|
int real = processor.p - oldp;
|
|
|
|
int should = processor.size;
|
|
|
|
if (real != processor.size) {
|
|
|
|
fprintf(stderr, "real %d - should %d = %d\n", real, should, real - should);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}')
|
|
|
|
err_alloc:
|
|
|
|
if (processor.reference) {
|
|
|
|
zend_hash_destroy(&processor.zvalptrs);
|
|
|
|
}
|
|
|
|
zend_hash_destroy(&processor.strings);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
IFASSERT(`xc_stack_destroy(&processor.allocsizes);')
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
/* }}} */
|
2006-12-09 16:27:03 +00:00
|
|
|
')
|
|
|
|
DEFINE_STORE_API(`xc_entry_t')
|
|
|
|
DEFINE_STORE_API(`xc_entry_data_php_t')
|
|
|
|
/* export: xc_entry_t *xc_processor_restore_xc_entry_t(xc_entry_t *dst, const xc_entry_t *src TSRMLS_DC); :export {{{ */
|
|
|
|
xc_entry_t *xc_processor_restore_xc_entry_t(xc_entry_t *dst, const xc_entry_t *src TSRMLS_DC) {
|
|
|
|
xc_processor_t processor;
|
|
|
|
|
|
|
|
memset(&processor, 0, sizeof(processor));
|
|
|
|
xc_restore_xc_entry_t(&processor, dst, src TSRMLS_CC);
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
/* }}} */
|
2009-09-29 11:25:01 +00:00
|
|
|
/* export: xc_entry_data_php_t *xc_processor_restore_xc_entry_data_php_t(const xc_entry_t *xce, xc_entry_data_php_t *dst, const xc_entry_data_php_t *src, zend_bool readonly_protection TSRMLS_DC); :export {{{ */
|
|
|
|
xc_entry_data_php_t *xc_processor_restore_xc_entry_data_php_t(const xc_entry_t *xce, xc_entry_data_php_t *dst, const xc_entry_data_php_t *src, zend_bool readonly_protection TSRMLS_DC) {
|
2006-09-18 00:27:17 +00:00
|
|
|
xc_processor_t processor;
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
memset(&processor, 0, sizeof(processor));
|
|
|
|
processor.readonly_protection = readonly_protection;
|
2006-12-09 16:27:03 +00:00
|
|
|
/* this function is used for php data only */
|
2006-10-10 00:46:00 +00:00
|
|
|
if (src->have_references) {
|
|
|
|
processor.reference = 1;
|
|
|
|
}
|
2009-09-29 11:25:01 +00:00
|
|
|
processor.entry_src = xce;
|
2006-05-09 10:58:38 +00:00
|
|
|
|
2006-10-10 00:46:00 +00:00
|
|
|
if (processor.reference) {
|
|
|
|
zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
|
|
|
|
}
|
2006-12-09 16:27:03 +00:00
|
|
|
xc_restore_xc_entry_data_php_t(&processor, dst, src TSRMLS_CC);
|
2006-10-10 00:46:00 +00:00
|
|
|
if (processor.reference) {
|
|
|
|
zend_hash_destroy(&processor.zvalptrs);
|
|
|
|
}
|
2006-05-09 10:58:38 +00:00
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
/* }}} */
|
2006-10-10 00:46:00 +00:00
|
|
|
/* export: zval *xc_processor_restore_zval(zval *dst, const zval *src, zend_bool have_references TSRMLS_DC); :export {{{ */
|
|
|
|
zval *xc_processor_restore_zval(zval *dst, const zval *src, zend_bool have_references TSRMLS_DC) {
|
2006-09-18 00:27:17 +00:00
|
|
|
xc_processor_t processor;
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
memset(&processor, 0, sizeof(processor));
|
2006-10-10 00:46:00 +00:00
|
|
|
processor.reference = have_references;
|
2006-05-09 10:58:38 +00:00
|
|
|
|
2006-10-10 00:46:00 +00:00
|
|
|
if (processor.reference) {
|
|
|
|
zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
|
|
|
|
dnl fprintf(stderr, "mark[%p] = %p\n", src, dst);
|
|
|
|
zend_hash_add(&processor.zvalptrs, (char *)src, sizeof(src), (void*)&dst, sizeof(dst), NULL);
|
|
|
|
}
|
2006-05-09 10:58:38 +00:00
|
|
|
xc_restore_zval(&processor, dst, src TSRMLS_CC);
|
2006-10-10 00:46:00 +00:00
|
|
|
if (processor.reference) {
|
|
|
|
zend_hash_destroy(&processor.zvalptrs);
|
|
|
|
}
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
/* export: void xc_dprint(xc_entry_t *src, int indent TSRMLS_DC); :export {{{ */
|
2006-10-10 00:31:50 +00:00
|
|
|
#ifdef HAVE_XCACHE_DPRINT
|
2006-05-09 10:58:38 +00:00
|
|
|
void xc_dprint(xc_entry_t *src, int indent TSRMLS_DC) {
|
|
|
|
IFDPRINT(`INDENT()`'fprintf(stderr, "xc_entry_t:src");')
|
|
|
|
xc_dprint_xc_entry_t(src, indent TSRMLS_CC);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* }}} */
|