Browse Source

initial PHP_5_4 support

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@822 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
3.0
Xuefer 9 years ago
parent
commit
5daf260872
  1. 6
      optimizer.c
  2. 7
      processor/hashtable.m4
  3. 82
      processor/processor.m4
  4. 58
      utils.c
  5. 3
      xcache.h

6
optimizer.c

@ -20,6 +20,12 @@
# define XCACHE_IS_CV 16
#endif
#ifdef ZEND_ENGINE_2_4
# undef Z_OP_CONSTANT
/* Z_OP_CONSTANT is used before pass_two is applied */
# define Z_OP_CONSTANT(op) op_array->literals[op.constant].constant
#endif
typedef int bbid_t;
enum {
BBID_INVALID = -1,

7
processor/hashtable.m4

@ -108,13 +108,10 @@ define(`DEF_HASH_TABLE_FUNC', `
n = b->h & src->nTableMask;
/* pnew into hash node chain */
pnew->pLast = NULL;
if (dst->arBuckets[n]) {
pnew->pNext = dst->arBuckets[n];
pnew->pNext = dst->arBuckets[n];
if (pnew->pNext) {
pnew->pNext->pLast = pnew;
}
else {
pnew->pNext = NULL;
}
dst->arBuckets[n] = pnew;
')
IFDPRINT(`

82
processor/processor.m4

@ -485,7 +485,8 @@ dnl }}}
#ifdef ZEND_ENGINE_2_4
undefine(`UNION_znode_op')
define(`UNION_znode_op', `dnl {{{
switch ((src->$1_type & ~EXT_TYPE_UNUSED)) {
#ifndef NDEBUG
switch ((src->$1_type ifelse($1, `result', & ~EXT_TYPE_UNUSED))) {
case IS_CONST:
case IS_VAR:
case IS_CV:
@ -496,27 +497,35 @@ define(`UNION_znode_op', `dnl {{{
default:
assert(0);
}
#endif
dnl dirty dispatch
DISABLECHECK(`
switch ((src->$1_type & ~EXT_TYPE_UNUSED)) {
switch ((src->$1_type ifelse($1, `result', & ~EXT_TYPE_UNUSED))) {
case IS_CONST:
dnl TODO: fix me, use literals
IFDASM(`{
zval *zv;
ALLOC_INIT_ZVAL(zv);
*zv = ((zend_literal *) src->$1.ptr)->constant;
zval_copy_ctor(zv);
add_assoc_zval_ex(dst, ZEND_STRS("$1.constant"), zv);
}
', `
ifelse($1, `result', `
DISPATCH(zend_uint, $1.constant)
', `
IFDASM(`{
zval *zv;
ALLOC_INIT_ZVAL(zv);
*zv = src->$1.literal->constant;
zval_copy_ctor(zv);
add_assoc_zval_ex(dst, ZEND_STRS("$1.constant"), zv);
}
', `
IFCOPY(`
dst->$1 = src->$1;
', `
DISPATCH(zend_uint, $1.constant)
')
')
')
break;
IFCOPY(`
IFNOTMEMCPY(`
default:
*dst = *src;
$1 = $2;
')
', `
case IS_VAR:
@ -606,6 +615,17 @@ DEF_STRUCT_P_FUNC(`zend_op', , `dnl {{{
DISPATCH(zend_uchar, result_type)
#endif
IFCOPY(`
pushdef(`UNION_znode_op_literal', `
if (dst->$1_type == IS_CONST) {
IFSTORE(`
dst->$1.constant = src->$1.literal - processor->active_op_array_src->literals;
dst->$1.literal = &processor->active_op_array_dst->literals[dst->$1.constant];
')
}
')
UNION_znode_op_literal(op1)
UNION_znode_op_literal(op2)
popdef(`UNION_znode_op_literal')
switch (src->opcode) {
#ifdef ZEND_GOTO
case ZEND_GOTO:
@ -658,7 +678,7 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{
zend_bool shallow_copy = !processor->readonly_protection && !(src == processor->php_src->op_array && need_early_binding);
if (shallow_copy) {
zend_bool gc_arg_info = 0;
int gc_opcodes = 0;
zend_bool gc_opcodes = 0;
/* really fast shallow copy */
memcpy(dst, src, sizeof(src[0]));
dst->refcount[0] = 1000;
@ -668,14 +688,33 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{
STRUCT_ARRAY(num_args, zend_arg_info, arg_info)
gc_arg_info = 1;
#endif
IFRESTORE(`dst->filename = processor->entry_src->filepath;')
#ifndef ZEND_ENGINE_2_4
dst->filename = processor->entry_src->filepath;
#ifdef ZEND_ENGINE_2_4
if (src->literals /* || op_array_info->literalsinfo_cnt */) {
gc_opcodes = 1;
}
#else
if (op_array_info->oplineinfo_cnt) {
zend_op *opline, *end;
gc_opcodes = 1;
}
#endif
if (gc_opcodes) {
zend_op *opline, *end;
COPY_N_EX(last, zend_op, opcodes)
for (opline = dst->opcodes, end = opline + src->last; opline < end; ++opline) {
#ifdef ZEND_ENGINE_2_4
pushdef(`UNION_znode_op_literal', `
if (opline->$1_type == IS_CONST) {
opline->$1.constant = opline->$1.literal - src->literals;
opline->$1.literal = &dst->literals[opline->$1.constant];
}
')
UNION_znode_op_literal(op1)
UNION_znode_op_literal(op2)
popdef(`UNION_znode_op_literal')
#endif
switch (opline->opcode) {
#ifdef ZEND_GOTO
case ZEND_GOTO:
@ -699,14 +738,12 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{
}
}
}
#endif
if (gc_arg_info || gc_opcodes) {
xc_gc_op_array_t gc_op_array;
#ifdef ZEND_ENGINE_2
gc_op_array.num_args = gc_arg_info ? dst->num_args : 0;
gc_op_array.arg_info = gc_arg_info ? dst->arg_info : NULL;
#endif
gc_op_array.last = gc_opcodes > 1 ? dst->last : 0;
gc_op_array.opcodes = gc_opcodes ? dst->opcodes : NULL;
xc_gc_add_op_array(&gc_op_array TSRMLS_CC);
}
@ -770,6 +807,12 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{
UNFIXPOINTER(zend_uint, refcount)
IFSTORE(`dst->refcount[0] = 1;')
#ifdef ZEND_ENGINE_2_4
dnl before copying opcodes
DISPATCH(int, last_literal)
STRUCT_ARRAY(last_literal, zend_literal, literals)
#endif
pushdef(`AFTER_ALLOC', `IFCOPY(`
#ifndef NDEBUG
processor->active_op_array_dst = dst;
@ -856,9 +899,6 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{
DISPATCH(zend_bool, created_by_eval)
#endif
#ifdef ZEND_ENGINE_2_4
DISPATCH(int, last_literal)
IFRESTORE(`COPY(literals)', `STRUCT_ARRAY(last_literal, zend_literal, literals)')
COPYNULL(run_time_cache)
COPYNULL(last_cache_slot)
#endif

58
utils.c

@ -18,10 +18,14 @@
# define ZEND_VM_SET_OPCODE_HANDLER(opline) do { } while (0)
#endif
#define OP_ZVAL_DTOR(op) do { \
Z_UNSET_ISREF(Z_OP_CONSTANT(op)); \
zval_dtor(&Z_OP_CONSTANT(op)); \
} while(0)
#ifdef ZEND_ENGINE_2_4
# define OP_ZVAL_DTOR(op) do { } while(0)
#else
# define OP_ZVAL_DTOR(op) do { \
Z_UNSET_ISREF(Z_OP_CONSTANT(op)); \
zval_dtor(&Z_OP_CONSTANT(op)); \
} while(0)
#endif
xc_compile_result_t *xc_compile_result_init(xc_compile_result_t *cr, /* {{{ */
zend_op_array *op_array,
HashTable *function_table,
@ -129,12 +133,15 @@ int xc_apply_op_array(xc_compile_result_t *cr, apply_func_t applyer TSRMLS_DC) /
return applyer(cr->op_array TSRMLS_CC);
}
/* }}} */
int xc_undo_pass_two(zend_op_array *op_array TSRMLS_DC) /* {{{ */
{
zend_op *opline, *end;
#ifndef ZEND_ENGINE_2_4
#ifdef ZEND_ENGINE_2_4
if (!(op_array->fn_flags & ZEND_ACC_DONE_PASS_TWO)) {
return 0;
}
#else
if (!op_array->done_pass_two) {
return 0;
}
@ -143,6 +150,15 @@ int xc_undo_pass_two(zend_op_array *op_array TSRMLS_DC) /* {{{ */
opline = op_array->opcodes;
end = opline + op_array->last;
while (opline < end) {
#ifdef ZEND_ENGINE_2_4
if (opline->op1_type == IS_CONST) {
opline->op1.constant = opline->op1.literal - op_array->literals;
}
if (opline->op2_type == IS_CONST) {
opline->op2.constant = opline->op2.literal - op_array->literals;
}
#endif
#ifdef ZEND_ENGINE_2_1
switch (opline->opcode) {
#ifdef ZEND_GOTO
@ -166,7 +182,9 @@ int xc_undo_pass_two(zend_op_array *op_array TSRMLS_DC) /* {{{ */
#endif
opline++;
}
#ifndef ZEND_ENGINE_2_4
#ifdef ZEND_ENGINE_2_4
op_array->fn_flags &= ~ZEND_ACC_DONE_PASS_TWO;
#else
op_array->done_pass_two = 0;
#endif
@ -176,8 +194,15 @@ int xc_undo_pass_two(zend_op_array *op_array TSRMLS_DC) /* {{{ */
int xc_redo_pass_two(zend_op_array *op_array TSRMLS_DC) /* {{{ */
{
zend_op *opline, *end;
#ifdef ZEND_ENGINE_2_4
zend_literal *literal = op_array->literals;
#endif
#ifndef ZEND_ENGINE_2_4
#ifdef ZEND_ENGINE_2_4
if ((op_array->fn_flags & ZEND_ACC_DONE_PASS_TWO)) {
return 0;
}
#else
if (op_array->done_pass_two) {
return 0;
}
@ -187,19 +212,30 @@ int xc_redo_pass_two(zend_op_array *op_array TSRMLS_DC) /* {{{ */
op_array->opcodes = (zend_op *) erealloc(op_array->opcodes, sizeof(zend_op)*op_array->last);
op_array->size = op_array->last;
*/
#ifdef ZEND_ENGINE_2_4
if (literal) {
zend_literal *end = literal + op_array->last_literal;
while (literal < end) {
Z_SET_ISREF(literal->constant);
Z_SET_REFCOUNT(literal->constant, 2); /* Make sure is_ref won't be reset */
literal++;
}
}
#endif
opline = op_array->opcodes;
end = opline + op_array->last;
while (opline < end) {
#ifndef ZEND_ENGINE_2_4
if (Z_OP_TYPE(opline->op1) == IS_CONST) {
Z_SET_ISREF(Z_OP_CONSTANT(opline->op1));
Z_SET_REFCOUNT(Z_OP_CONSTANT(opline->op1), 2); /* Make sure is_ref won't be reset */
}
if (Z_OP_TYPE(opline->op2) == IS_CONST) {
Z_SET_ISREF(Z_OP_CONSTANT(opline->op2));
Z_SET_REFCOUNT(Z_OP_CONSTANT(opline->op2), 2);
}
#endif
#ifdef ZEND_ENGINE_2_1
switch (opline->opcode) {
#ifdef ZEND_GOTO
@ -225,7 +261,9 @@ int xc_redo_pass_two(zend_op_array *op_array TSRMLS_DC) /* {{{ */
opline++;
}
#ifndef ZEND_ENGINE_2_4
#ifdef ZEND_ENGINE_2_4
op_array->fn_flags |= ZEND_ACC_DONE_PASS_TWO;
#else
op_array->done_pass_two = 1;
#endif
return 0;

3
xcache.h

@ -21,7 +21,7 @@
#include "lock.h"
#define HAVE_INODE
#if !defined(ZEND_ENGINE_2_4) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 3 && PHP_RELEASE_VERSION >= 99 || PHP_MAJOR_VERSION > 5)
#if !defined(ZEND_ENGINE_2_4) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4 || PHP_MAJOR_VERSION > 5)
# define ZEND_ENGINE_2_4
#endif
#if !defined(ZEND_ENGINE_2_3) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 3 || defined(ZEND_ENGINE_2_4))
@ -449,7 +449,6 @@ typedef struct {
zend_uint num_args;
zend_arg_info *arg_info;
#endif
zend_uint last;
zend_op *opcodes;
} xc_gc_op_array_t;
/* }}} */

Loading…
Cancel
Save