int retval = 1;
ALLOCA_FLAG(use_heap);
- if (zend_hash_find(EG(zend_constants), name, name_len+1, (void **) &c) == FAILURE) {
- lookup_name = DO_ALLOCA(name_len+1);
- memcpy(lookup_name, name, name_len+1);
+ if (zend_hash_find(EG(zend_constants), name, name_len + 1, (void **) &c) == FAILURE) {
+ lookup_name = DO_ALLOCA(name_len + 1);
+ memcpy(lookup_name, name, name_len + 1);
zend_str_tolower(lookup_name, name_len);
- if (zend_hash_find(EG(zend_constants), lookup_name, name_len+1, (void **) &c)==SUCCESS) {
+ if (zend_hash_find(EG(zend_constants), lookup_name, name_len + 1, (void **) &c) == SUCCESS) {
if (!(c->flags & CONST_CT_SUBST) || (c->flags & CONST_CS)) {
- retval=0;
+ retval = 0;
}
} else {
- retval=0;
+ retval = 0;
}
FREE_ALLOCA(lookup_name);
}
if (retval) {
- if(c->flags & CONST_PERSISTENT) {
+ if (c->flags & CONST_PERSISTENT) {
*result = c->value;
- if(copy) {
+ if (copy) {
zval_copy_ctor(result);
}
} else {
static inline void print_block(zend_code_block *block, zend_op *opcodes, char *txt)
{
fprintf(stderr, "%sBlock: %d-%d (%d)", txt, block->start_opline - opcodes, block->start_opline - opcodes+block->len-1, block->len);
- if(!block->access) {
+ if (!block->access) {
fprintf(stderr, " unused");
}
- if(block->op1_to) {
+ if (block->op1_to) {
fprintf(stderr, " 1: %d", block->op1_to->start_opline - opcodes);
}
- if(block->op2_to) {
+ if (block->op2_to) {
fprintf(stderr, " 2: %d", block->op2_to->start_opline - opcodes);
}
- if(block->ext_to) {
+ if (block->ext_to) {
fprintf(stderr, " e: %d", block->ext_to->start_opline - opcodes);
}
- if(block->follow_to) {
+ if (block->follow_to) {
fprintf(stderr, " f: %d", block->follow_to->start_opline - opcodes);
}
- if(block->sources) {
+ if (block->sources) {
zend_block_source *bs = block->sources;
fprintf(stderr, " s:");
- while(bs) {
+ while (bs) {
fprintf(stderr, " %d", bs->from->start_opline - opcodes);
bs = bs->next;
}
static zend_code_block *find_code_blocks(zend_op_array *op_array)
{
zend_op *opline;
- zend_op *end = op_array->opcodes+op_array->last;
- zend_code_block *blocks = ecalloc(op_array->last+2, sizeof(zend_code_block));
+ zend_op *end = op_array->opcodes + op_array->last;
+ zend_code_block *blocks = ecalloc(op_array->last + 2, sizeof(zend_code_block));
zend_code_block *cur_block;
zend_uint opno = 0;
blocks[0].start_opline = opline;
blocks[0].start_opline_no = 0;
/* first find block start points */
- if(op_array->last_try_catch) {
- int i;
+ if (op_array->last_try_catch) {
+ int i = 0;
blocks->try = ecalloc(op_array->last_try_catch, sizeof(zend_code_block *));
blocks->catch = ecalloc(op_array->last_try_catch, sizeof(zend_code_block *));
- for(i=0; i< op_array->last_try_catch; i++) {
+ for (; i< op_array->last_try_catch; i++) {
blocks->try[i] = &blocks[op_array->try_catch_array[i].try_op];
blocks->catch[i] = &blocks[op_array->try_catch_array[i].catch_op];
START_BLOCK_OP(op_array->try_catch_array[i].try_op);
blocks[op_array->try_catch_array[i].try_op].is_try = 1;
}
}
- while (opline<end) {
+ while (opline < end) {
switch((unsigned)opline->opcode) {
case ZEND_BRK:
case ZEND_CONT:
case ZEND_EXIT:
case ZEND_THROW:
/* start new block from this+1 */
- START_BLOCK_OP(opno+1);
+ START_BLOCK_OP(opno + 1);
break;
/* TODO: if conditional jmp depends on constant,
don't start block that won't be executed */
case ZEND_CATCH:
START_BLOCK_OP(opline->extended_value);
- START_BLOCK_OP(opno+1);
+ START_BLOCK_OP(opno + 1);
break;
case ZEND_JMPZNZ:
START_BLOCK_OP(opline->extended_value);
case ZEND_JMP_SET_VAR:
#endif
START_BLOCK_OP(ZEND_OP2(opline).opline_num);
- START_BLOCK_OP(opno+1);
+ START_BLOCK_OP(opno + 1);
break;
}
/* Build CFG (Control Flow Graph) */
cur_block = blocks;
- for(opno = 1; opno < op_array->last; opno++) {
- if(blocks[opno].start_opline) {
+ for (opno = 1; opno < op_array->last; opno++) {
+ if (blocks[opno].start_opline) {
/* found new block start */
cur_block->len = blocks[opno].start_opline - cur_block->start_opline;
cur_block->next = &blocks[opno];
/* what is the last OP of previous block? */
- opline = blocks[opno].start_opline-1;
+ opline = blocks[opno].start_opline - 1;
switch((unsigned)opline->opcode) {
case ZEND_RETURN:
#if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
print_block(cur_block, op_array->opcodes, "");
/* The op_array doesn't have BRK, CONT, GOTO opcodes anyway */
- if(op_array->brk_cont_array) {
+ if (op_array->brk_cont_array) {
efree(op_array->brk_cont_array);
}
op_array->brk_cont_array = NULL;
#define ADD_SOURCE(fromb, tob) { \
zend_block_source *__s = tob->sources; \
- while(__s && __s->from != fromb) __s = __s->next; \
- if(__s == NULL) { \
+ while (__s && __s->from != fromb) __s = __s->next; \
+ if (__s == NULL) { \
zend_block_source *__t = emalloc(sizeof(zend_block_source)); \
__t->next = tob->sources; \
tob->sources = __t; \
zend_block_source **cs;
int found = 0;
- for(cs = &list; *cs; cs = &((*cs)->next)) {
- if((*cs)->from == new) {
- if(found) {
+ for (cs = &list; *cs; cs = &((*cs)->next)) {
+ if ((*cs)->from == new) {
+ if (found) {
DEL_SOURCE(cs);
} else {
found = 1;
}
}
- if((*cs)->from == old) {
- if(found) {
+ if ((*cs)->from == old) {
+ if (found) {
DEL_SOURCE(cs);
} else {
(*cs)->from = new;
/* delete source 'from' from 'to'-s sources list */
zend_block_source **cs = &to->sources;
- if(to->sources == NULL) {
+ if (to->sources == NULL) {
to->access = 0;
return;
}
- while(*cs) {
- if((*cs)->from == from) {
- DEL_SOURCE(cs);
+ while (*cs) {
+ if ((*cs)->from == from) {
+ DEL_SOURCE(cs);
break;
}
cs = &((*cs)->next);
}
- if(to->sources == NULL) {
+ if (to->sources == NULL) {
/* 'to' has no more sources - it's unused, will be stripped */
to->access = 0;
return;
}
- if(to->sources->next == NULL) {
+ if (to->sources->next == NULL) {
/* source to only one block */
zend_code_block *from_block = to->sources->from;
-
- if(from_block->access && from_block->follow_to == to &&
- from_block->op1_to == NULL &&
- from_block->op2_to == NULL &&
- from_block->ext_to == NULL
- ) {
+
+ if (from_block->access && from_block->follow_to == to &&
+ from_block->op1_to == NULL &&
+ from_block->op2_to == NULL &&
+ from_block->ext_to == NULL) {
/* this block follows it's only predecessor - we can join them */
zend_op *new_to = from_block->start_opline + from_block->len;
- if(new_to != to->start_opline) {
+ if (new_to != to->start_opline) {
/* move block to new location */
memmove(new_to, to->start_opline, sizeof(zend_op)*to->len);
}
efree(to->sources);
to->sources = NULL;
from_block->follow_to = to->follow_to;
- if(to->op1_to) {
+ if (to->op1_to) {
from_block->op1_to = to->op1_to;
replace_source(to->op1_to->sources, to, from_block);
}
- if(to->op2_to) {
+ if (to->op2_to) {
from_block->op2_to = to->op2_to;
replace_source(to->op2_to->sources, to, from_block);
}
- if(to->ext_to) {
+ if (to->ext_to) {
from_block->ext_to = to->ext_to;
replace_source(to->ext_to->sources, to, from_block);
}
- if(to->follow_to) {
+ if (to->follow_to) {
replace_source(to->follow_to->sources, to, from_block);
}
/* remove "to" from list */
static void delete_code_block(zend_code_block *block)
{
- if(block->follow_to) {
+ if (block->follow_to) {
zend_block_source *bs = block->sources;
- while(bs) {
+ while (bs) {
zend_code_block *from_block = bs->from;
zend_code_block *to = block->follow_to;
- if(from_block->op1_to == block) {
+ if (from_block->op1_to == block) {
from_block->op1_to = to;
ADD_SOURCE(from_block, to);
}
- if(from_block->op2_to == block) {
+ if (from_block->op2_to == block) {
from_block->op2_to = to;
ADD_SOURCE(from_block, to);
}
- if(from_block->ext_to == block) {
+ if (from_block->ext_to == block) {
from_block->ext_to = to;
ADD_SOURCE(from_block, to);
}
- if(from_block->follow_to == block) {
+ if (from_block->follow_to == block) {
from_block->follow_to = to;
ADD_SOURCE(from_block, to);
}
static void zend_access_path(zend_code_block *block)
{
- if(block->access) {
+ if (block->access) {
return;
}
block->access = 1;
- if(block->op1_to) {
+ if (block->op1_to) {
zend_access_path(block->op1_to);
ADD_SOURCE(block, block->op1_to);
}
- if(block->op2_to) {
+ if (block->op2_to) {
zend_access_path(block->op2_to);
ADD_SOURCE(block, block->op2_to);
}
- if(block->ext_to) {
+ if (block->ext_to) {
zend_access_path(block->ext_to);
ADD_SOURCE(block, block->ext_to);
}
- if(block->follow_to) {
+ if (block->follow_to) {
zend_access_path(block->follow_to);
ADD_SOURCE(block, block->follow_to);
}
/* Traverse CFG, mark reachable basic blocks and build back references */
static void zend_rebuild_access_path(zend_code_block *blocks, zend_op_array *op_array, int find_start)
{
- zend_code_block *start = find_start?NULL:blocks;
+ zend_code_block *start = find_start? NULL : blocks;
zend_code_block *b;
/* Mark all blocks as unaccessable and destroy back references */
}
b->access = 0;
cs = b->sources;
- while(cs) {
+ while (cs) {
zend_block_source *n = cs->next;
efree(cs);
cs = n;
/* Add exception pathes */
if (op_array->last_try_catch) {
int i;
- for(i=0; i< op_array->last_try_catch; i++) {
- if(!blocks->catch[i]->access) {
+ for (i=0; i< op_array->last_try_catch; i++) {
+ if (!blocks->catch[i]->access) {
zend_access_path(blocks->catch[i]);
}
}
#else
-# define VAR_NUM_EX(op) ((op).op_type==IS_TMP_VAR||(op).op_type==IS_VAR?VAR_NUM((op).u.var):(op).u.var)
+# define VAR_NUM_EX(op) ((op).op_type == IS_TMP_VAR || (op).op_type == IS_VAR? VAR_NUM((op).u.var) : (op).u.var)
# define VAR_SOURCE(op) Tsource[VAR_NUM(op.u.var)]
# define SET_VAR_SOURCE(opline) Tsource[VAR_NUM(ZEND_RESULT(opline).var)] = opline
-# define VAR_UNSET(op) do { if ((op).op_type==IS_TMP_VAR||(op).op_type==IS_VAR) {VAR_SOURCE(op) = NULL;}} while (0)
+# define VAR_UNSET(op) do { if ((op).op_type == IS_TMP_VAR || (op).op_type == IS_VAR) {VAR_SOURCE(op) = NULL;}} while (0)
#endif
#define convert_to_string_safe(v) \
- if(Z_TYPE_P((v)) == IS_NULL) { \
+ if (Z_TYPE_P((v)) == IS_NULL) { \
ZVAL_STRINGL((v), "", 0, 1); \
} else { \
convert_to_string((v)); \
print_block(block, op_array->opcodes, "Opt ");
/* remove leading NOPs */
- while(block->start_opline->opcode == ZEND_NOP) {
- if(block->len == 1) {
+ while (block->start_opline->opcode == ZEND_NOP) {
+ if (block->len == 1) {
/* this block is all NOPs, join with following block */
- if(block->follow_to) {
+ if (block->follow_to) {
delete_code_block(block);
}
return;
}
/* we track data dependencies only insight a single basic block */
- if(op_array->T){
+ if (op_array->T) {
Tsource = ecalloc(op_array->T, sizeof(zend_op *));
}
opline = block->start_opline;
- end = opline+block->len;
- while((op_array->T)&&(opline<end)) {
+ end = opline + block->len;
+ while ((op_array->T) && (opline < end)) {
/* strip X = QM_ASSIGN(const) */
- if(ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
- VAR_SOURCE(opline->op1) &&
- VAR_SOURCE(opline->op1)->opcode == ZEND_QM_ASSIGN &&
- ZEND_OP1_TYPE(VAR_SOURCE(opline->op1)) == IS_CONST &&
- opline->opcode != ZEND_CASE && /* CASE _always_ expects variable */
- opline->opcode != ZEND_FETCH_DIM_TMP_VAR && /* in 5.1, FETCH_DIM_TMP_VAR expects T */
- opline->opcode != ZEND_FE_RESET &&
- opline->opcode != ZEND_FREE
- ) {
+ if (ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
+ VAR_SOURCE(opline->op1) &&
+ VAR_SOURCE(opline->op1)->opcode == ZEND_QM_ASSIGN &&
+ ZEND_OP1_TYPE(VAR_SOURCE(opline->op1)) == IS_CONST &&
+ opline->opcode != ZEND_CASE && /* CASE _always_ expects variable */
+ opline->opcode != ZEND_FETCH_DIM_TMP_VAR && /* in 5.1, FETCH_DIM_TMP_VAR expects T */
+ opline->opcode != ZEND_FE_RESET &&
+ opline->opcode != ZEND_FREE
+ ) {
zend_op *src = VAR_SOURCE(opline->op1);
VAR_UNSET(opline->op1);
COPY_NODE(opline->op1, src->op1);
}
/* T = QM_ASSIGN(C), F(T) => NOP, F(C) */
- if(ZEND_OP2_TYPE(opline) == IS_TMP_VAR &&
- VAR_SOURCE(opline->op2) &&
- VAR_SOURCE(opline->op2)->opcode == ZEND_QM_ASSIGN &&
- ZEND_OP1_TYPE(VAR_SOURCE(opline->op2)) == IS_CONST) {
+ if (ZEND_OP2_TYPE(opline) == IS_TMP_VAR &&
+ VAR_SOURCE(opline->op2) &&
+ VAR_SOURCE(opline->op2)->opcode == ZEND_QM_ASSIGN &&
+ ZEND_OP1_TYPE(VAR_SOURCE(opline->op2)) == IS_CONST) {
zend_op *src = VAR_SOURCE(opline->op2);
VAR_UNSET(opline->op2);
COPY_NODE(opline->op2, src->op1);
}
/* T = PRINT(X), F(T) => ECHO(X), F(1) */
- if(ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
- VAR_SOURCE(opline->op1) &&
- VAR_SOURCE(opline->op1)->opcode == ZEND_PRINT &&
- opline->opcode != ZEND_CASE && opline->opcode != ZEND_FREE) {
+ if (ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
+ VAR_SOURCE(opline->op1) &&
+ VAR_SOURCE(opline->op1)->opcode == ZEND_PRINT &&
+ opline->opcode != ZEND_CASE && opline->opcode != ZEND_FREE) {
ZEND_OP1_TYPE(opline) = IS_CONST;
LITERAL_LONG(opline->op1, 1);
}
- if(ZEND_OP2_TYPE(opline) == IS_TMP_VAR &&
- VAR_SOURCE(opline->op2) &&
- VAR_SOURCE(opline->op2)->opcode == ZEND_PRINT) {
+ if (ZEND_OP2_TYPE(opline) == IS_TMP_VAR &&
+ VAR_SOURCE(opline->op2) &&
+ VAR_SOURCE(opline->op2)->opcode == ZEND_PRINT) {
ZEND_OP2_TYPE(opline) = IS_CONST;
LITERAL_LONG(opline->op2, 1);
}
/* T = CAST(X, String), ECHO(T) => NOP, ECHO(X) */
- if((opline->opcode == ZEND_ECHO || opline->opcode == ZEND_PRINT) &&
- ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
- VAR_SOURCE(opline->op1) &&
- VAR_SOURCE(opline->op1)->opcode == ZEND_CAST &&
- VAR_SOURCE(opline->op1)->extended_value == IS_STRING) {
+ if ((opline->opcode == ZEND_ECHO || opline->opcode == ZEND_PRINT) &&
+ ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
+ VAR_SOURCE(opline->op1) &&
+ VAR_SOURCE(opline->op1)->opcode == ZEND_CAST &&
+ VAR_SOURCE(opline->op1)->extended_value == IS_STRING) {
zend_op *src = VAR_SOURCE(opline->op1);
COPY_NODE(opline->op1, src->op1);
MAKE_NOP(src);
}
/* T = PRINT(X), FREE(T) => ECHO(X) */
- if(opline->opcode == ZEND_FREE &&
+ if (opline->opcode == ZEND_FREE &&
ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
- VAR_SOURCE(opline->op1)) {
+ VAR_SOURCE(opline->op1)) {
zend_op *src = VAR_SOURCE(opline->op1);
- if(src->opcode == ZEND_PRINT) {
+ if (src->opcode == ZEND_PRINT) {
src->opcode = ZEND_ECHO;
ZEND_RESULT_TYPE(src) = IS_UNUSED;
MAKE_NOP(opline);
}
/* T = BOOL(X), FREE(T) => NOP */
- if(opline->opcode == ZEND_FREE &&
- ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
- VAR_SOURCE(opline->op1)) {
+ if (opline->opcode == ZEND_FREE &&
+ ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
+ VAR_SOURCE(opline->op1)) {
zend_op *src = VAR_SOURCE(opline->op1);
if (src->opcode == ZEND_BOOL) {
if (ZEND_OP1_TYPE(src) == IS_CONST) {
* IS_NOT_EQ(TRUE, X) => BOOL_NOT(X)
* IS_NOT_EQ(FALSE, X) => BOOL(X)
*/
- if(opline->opcode == ZEND_IS_EQUAL ||
- opline->opcode == ZEND_IS_NOT_EQUAL) {
+ if (opline->opcode == ZEND_IS_EQUAL ||
+ opline->opcode == ZEND_IS_NOT_EQUAL) {
if (ZEND_OP1_TYPE(opline) == IS_CONST &&
Z_TYPE(ZEND_OP1_LITERAL(opline)) == IS_BOOL) {
opline->opcode =
((opline->opcode == ZEND_IS_EQUAL) == Z_LVAL(ZEND_OP1_LITERAL(opline)))?
- ZEND_BOOL:ZEND_BOOL_NOT;
+ ZEND_BOOL : ZEND_BOOL_NOT;
COPY_NODE(opline->op1, opline->op2);
SET_UNUSED(opline->op2);
} else if (ZEND_OP2_TYPE(opline) == IS_CONST &&
Z_TYPE(ZEND_OP2_LITERAL(opline)) == IS_BOOL) {
opline->opcode =
((opline->opcode == ZEND_IS_EQUAL) == Z_LVAL(ZEND_OP2_LITERAL(opline)))?
- ZEND_BOOL:ZEND_BOOL_NOT;
+ ZEND_BOOL : ZEND_BOOL_NOT;
SET_UNUSED(opline->op2);
}
}
- if((opline->opcode == ZEND_BOOL ||
+ if ((opline->opcode == ZEND_BOOL ||
opline->opcode == ZEND_BOOL_NOT ||
opline->opcode == ZEND_JMPZ ||
opline->opcode == ZEND_JMPNZ ||
opline->opcode == ZEND_JMPZNZ) &&
- ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
- VAR_SOURCE(opline->op1) != NULL &&
- !used_ext[VAR_NUM(ZEND_OP1(opline).var)] &&
- VAR_SOURCE(opline->op1)->opcode == ZEND_BOOL_NOT
- ) {
+ ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
+ VAR_SOURCE(opline->op1) != NULL &&
+ !used_ext[VAR_NUM(ZEND_OP1(opline).var)] &&
+ VAR_SOURCE(opline->op1)->opcode == ZEND_BOOL_NOT) {
/* T = BOOL_NOT(X) + JMPZ(T) -> NOP, JMPNZ(X) */
zend_op *src = VAR_SOURCE(opline->op1);
COPY_NODE(opline->op1, src->op1);
- switch(opline->opcode) {
+ switch (opline->opcode) {
case ZEND_BOOL:
/* T = BOOL_NOT(X) + BOOL(T) -> NOP, BOOL_NOT(X) */
opline->opcode = ZEND_BOOL_NOT;
} else
#endif
/* T = BOOL(X) + JMPZ(T) -> NOP, JMPZ(X) */
- if((opline->opcode == ZEND_BOOL ||
+ if ((opline->opcode == ZEND_BOOL ||
opline->opcode == ZEND_BOOL_NOT ||
opline->opcode == ZEND_JMPZ ||
opline->opcode == ZEND_JMPZ_EX ||
opline->opcode == ZEND_JMPNZ_EX ||
opline->opcode == ZEND_JMPNZ ||
opline->opcode == ZEND_JMPZNZ) &&
- ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
- VAR_SOURCE(opline->op1) != NULL &&
- (!used_ext[VAR_NUM(ZEND_OP1(opline).var)] ||
+ ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
+ VAR_SOURCE(opline->op1) != NULL &&
+ (!used_ext[VAR_NUM(ZEND_OP1(opline).var)] ||
(ZEND_RESULT_TYPE(opline) == IS_TMP_VAR &&
ZEND_RESULT(opline).var == ZEND_OP1(opline).var)) &&
- (VAR_SOURCE(opline->op1)->opcode == ZEND_BOOL ||
- VAR_SOURCE(opline->op1)->opcode == ZEND_QM_ASSIGN)
- ) {
+ (VAR_SOURCE(opline->op1)->opcode == ZEND_BOOL ||
+ VAR_SOURCE(opline->op1)->opcode == ZEND_QM_ASSIGN)) {
zend_op *src = VAR_SOURCE(opline->op1);
COPY_NODE(opline->op1, src->op1);
VAR_UNSET(opline->op1);
MAKE_NOP(src);
continue;
- } else if(last_op && opline->opcode == ZEND_ECHO &&
+ } else if (last_op && opline->opcode == ZEND_ECHO &&
last_op->opcode == ZEND_ECHO &&
ZEND_OP1_TYPE(opline) == IS_CONST &&
Z_TYPE(ZEND_OP1_LITERAL(opline)) != IS_DOUBLE &&
*/
int l;
- if(Z_TYPE(ZEND_OP1_LITERAL(opline)) != IS_STRING) {
+ if (Z_TYPE(ZEND_OP1_LITERAL(opline)) != IS_STRING) {
convert_to_string_safe(&ZEND_OP1_LITERAL(opline));
}
- if(Z_TYPE(ZEND_OP1_LITERAL(last_op)) != IS_STRING) {
+ if (Z_TYPE(ZEND_OP1_LITERAL(last_op)) != IS_STRING) {
convert_to_string_safe(&ZEND_OP1_LITERAL(last_op));
}
l = Z_STRLEN(ZEND_OP1_LITERAL(opline)) + Z_STRLEN(ZEND_OP1_LITERAL(last_op));
#endif
Z_STRLEN(ZEND_OP1_LITERAL(opline)) = l;
MAKE_NOP(last_op);
- } else if(opline->opcode == ZEND_CONCAT &&
+ } else if (opline->opcode == ZEND_CONCAT &&
ZEND_OP2_TYPE(opline) == IS_CONST &&
ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
VAR_SOURCE(opline->op1) &&
(VAR_SOURCE(opline->op1)->opcode == ZEND_CONCAT ||
VAR_SOURCE(opline->op1)->opcode == ZEND_ADD_STRING) &&
ZEND_OP2_TYPE(VAR_SOURCE(opline->op1)) == IS_CONST &&
- ZEND_RESULT(VAR_SOURCE(opline->op1)).var == ZEND_OP1(opline).var
- ) {
+ ZEND_RESULT(VAR_SOURCE(opline->op1)).var == ZEND_OP1(opline).var) {
/* compress consecutive CONCATs */
zend_op *src = VAR_SOURCE(opline->op1);
int l;
- if(Z_TYPE(ZEND_OP2_LITERAL(opline)) != IS_STRING) {
+ if (Z_TYPE(ZEND_OP2_LITERAL(opline)) != IS_STRING) {
convert_to_string_safe(&ZEND_OP2_LITERAL(opline));
}
- if(Z_TYPE(ZEND_OP2_LITERAL(src)) != IS_STRING) {
+ if (Z_TYPE(ZEND_OP2_LITERAL(src)) != IS_STRING) {
convert_to_string_safe(&ZEND_OP2_LITERAL(src));
}
memcpy(tmp, Z_STRVAL(ZEND_OP2_LITERAL(src)), l + 1);
Z_STRVAL(ZEND_OP2_LITERAL(src)) = tmp;
} else {
- Z_STRVAL(ZEND_OP2_LITERAL(src)) = erealloc(Z_STRVAL(ZEND_OP2_LITERAL(src)), l+1);
+ Z_STRVAL(ZEND_OP2_LITERAL(src)) = erealloc(Z_STRVAL(ZEND_OP2_LITERAL(src)), l + 1);
}
memcpy(Z_STRVAL(ZEND_OP2_LITERAL(src))+Z_STRLEN(ZEND_OP2_LITERAL(src)), Z_STRVAL(ZEND_OP2_LITERAL(opline)), Z_STRLEN(ZEND_OP2_LITERAL(opline)));
Z_STRVAL(ZEND_OP2_LITERAL(src))[l] = '\0';
#endif
Z_STRLEN(ZEND_OP2_LITERAL(opline)) = l;
MAKE_NOP(src);
- } else if((opline->opcode == ZEND_ADD_STRING ||
- opline->opcode == ZEND_ADD_VAR) &&
- ZEND_OP1_TYPE(opline) == IS_CONST) {
+ } else if ((opline->opcode == ZEND_ADD_STRING || opline->opcode == ZEND_ADD_VAR) && ZEND_OP1_TYPE(opline) == IS_CONST) {
/* convert ADD_STRING(C1, C2) to CONCAT(C1, C2) */
opline->opcode = ZEND_CONCAT;
continue;
- } else if(opline->opcode == ZEND_ADD_CHAR && ZEND_OP1_TYPE(opline) == IS_CONST && ZEND_OP2_TYPE(opline) == IS_CONST) {
+ } else if (opline->opcode == ZEND_ADD_CHAR && ZEND_OP1_TYPE(opline) == IS_CONST && ZEND_OP2_TYPE(opline) == IS_CONST) {
/* convert ADD_CHAR(C1, C2) to CONCAT(C1, C2) */
char c = (char)Z_LVAL(ZEND_OP2_LITERAL(opline));
ZVAL_STRINGL(&ZEND_OP2_LITERAL(opline), &c, 1, 1);
opline->opcode = ZEND_CONCAT;
continue;
- } else if(
- (opline->opcode == ZEND_ADD ||
- opline->opcode == ZEND_SUB ||
- opline->opcode == ZEND_MUL ||
- opline->opcode == ZEND_DIV ||
- opline->opcode == ZEND_MOD ||
- opline->opcode == ZEND_SL ||
- opline->opcode == ZEND_SR ||
- opline->opcode == ZEND_CONCAT ||
- opline->opcode == ZEND_IS_EQUAL ||
- opline->opcode == ZEND_IS_NOT_EQUAL ||
- opline->opcode == ZEND_IS_SMALLER ||
- opline->opcode == ZEND_IS_SMALLER_OR_EQUAL ||
- opline->opcode == ZEND_IS_IDENTICAL ||
- opline->opcode == ZEND_IS_NOT_IDENTICAL ||
- opline->opcode == ZEND_BOOL_XOR ||
- opline->opcode == ZEND_BW_OR ||
- opline->opcode == ZEND_BW_AND ||
- opline->opcode == ZEND_BW_XOR) &&
- ZEND_OP1_TYPE(opline)==IS_CONST &&
- ZEND_OP2_TYPE(opline)==IS_CONST) {
+ } else if ((opline->opcode == ZEND_ADD ||
+ opline->opcode == ZEND_SUB ||
+ opline->opcode == ZEND_MUL ||
+ opline->opcode == ZEND_DIV ||
+ opline->opcode == ZEND_MOD ||
+ opline->opcode == ZEND_SL ||
+ opline->opcode == ZEND_SR ||
+ opline->opcode == ZEND_CONCAT ||
+ opline->opcode == ZEND_IS_EQUAL ||
+ opline->opcode == ZEND_IS_NOT_EQUAL ||
+ opline->opcode == ZEND_IS_SMALLER ||
+ opline->opcode == ZEND_IS_SMALLER_OR_EQUAL ||
+ opline->opcode == ZEND_IS_IDENTICAL ||
+ opline->opcode == ZEND_IS_NOT_IDENTICAL ||
+ opline->opcode == ZEND_BOOL_XOR ||
+ opline->opcode == ZEND_BW_OR ||
+ opline->opcode == ZEND_BW_AND ||
+ opline->opcode == ZEND_BW_XOR) &&
+ ZEND_OP1_TYPE(opline)==IS_CONST &&
+ ZEND_OP2_TYPE(opline)==IS_CONST) {
/* evaluate constant expressions */
int (*binary_op)(zval *result, zval *op1, zval *op2 TSRMLS_DC) = get_binary_op(opline->opcode);
zval result;
int er;
- if ((opline->opcode == ZEND_DIV ||
- opline->opcode == ZEND_MOD) &&
+ if ((opline->opcode == ZEND_DIV || opline->opcode == ZEND_MOD) &&
((Z_TYPE(ZEND_OP2_LITERAL(opline)) == IS_LONG &&
Z_LVAL(ZEND_OP2_LITERAL(opline)) == 0) ||
(Z_TYPE(ZEND_OP2_LITERAL(opline)) == IS_DOUBLE &&
Z_DVAL(ZEND_OP2_LITERAL(opline)) == 0.0))) {
- if(RESULT_USED(opline)) {
+ if (RESULT_USED(opline)) {
SET_VAR_SOURCE(opline);
}
opline++;
}
er = EG(error_reporting);
EG(error_reporting) = 0;
- if(binary_op(&result, &ZEND_OP1_LITERAL(opline), &ZEND_OP2_LITERAL(opline) TSRMLS_CC) == SUCCESS) {
+ if (binary_op(&result, &ZEND_OP1_LITERAL(opline), &ZEND_OP2_LITERAL(opline) TSRMLS_CC) == SUCCESS) {
PZ_SET_REFCOUNT_P(&result, 1);
PZ_UNSET_ISREF_P(&result);
opline->opcode = ZEND_QM_ASSIGN;
}
EG(error_reporting) = er;
- } else if((opline->opcode == ZEND_BOOL ||
- opline->opcode == ZEND_BOOL_NOT ||
- opline->opcode == ZEND_BW_NOT) && ZEND_OP1_TYPE(opline)==IS_CONST
- ) {
+ } else if ((opline->opcode == ZEND_BOOL ||
+ opline->opcode == ZEND_BOOL_NOT ||
+ opline->opcode == ZEND_BW_NOT) && ZEND_OP1_TYPE(opline) == IS_CONST) {
/* evaluate constant unary ops */
unary_op_type unary_op = get_unary_op(opline->opcode);
zval result;
- if(unary_op) {
+ if (unary_op) {
unary_op(&result, &ZEND_OP1_LITERAL(opline) TSRMLS_CC);
literal_dtor(&ZEND_OP1_LITERAL(opline));
} else {
PZ_UNSET_ISREF_P(&result);
ZEND_OP1_LITERAL(opline) = result;
opline->opcode = ZEND_QM_ASSIGN;
- } else if((opline->opcode == ZEND_RETURN || opline->opcode == ZEND_EXIT) &&
- ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
- VAR_SOURCE(opline->op1) &&
- VAR_SOURCE(opline->op1)->opcode == ZEND_QM_ASSIGN
- ) {
+ } else if ((opline->opcode == ZEND_RETURN || opline->opcode == ZEND_EXIT) &&
+ ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
+ VAR_SOURCE(opline->op1) &&
+ VAR_SOURCE(opline->op1)->opcode == ZEND_QM_ASSIGN) {
/* T = QM_ASSIGN(X), RETURN(T) to RETURN(X) */
zend_op *src = VAR_SOURCE(opline->op1);
VAR_UNSET(opline->op1);
COPY_NODE(opline->op1, src->op1);
MAKE_NOP(src);
- } else if((opline->opcode == ZEND_ADD_STRING ||
- opline->opcode == ZEND_ADD_CHAR) &&
- ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
- VAR_SOURCE(opline->op1) &&
- VAR_SOURCE(opline->op1)->opcode == ZEND_INIT_STRING) {
+ } else if ((opline->opcode == ZEND_ADD_STRING ||
+ opline->opcode == ZEND_ADD_CHAR) &&
+ ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
+ VAR_SOURCE(opline->op1) &&
+ VAR_SOURCE(opline->op1)->opcode == ZEND_INIT_STRING) {
/* convert T = INIT_STRING(), T = ADD_STRING(T, X) to T = QM_ASSIGN(X) */
/* CHECKME: Remove ZEND_ADD_VAR optimizsation, since some conversions -
namely, BOOL(false)->string - don't allocate memory but use empty_string
zend_op *src = VAR_SOURCE(opline->op1);
VAR_UNSET(opline->op1);
COPY_NODE(opline->op1, opline->op2);
- if(opline->opcode == ZEND_ADD_CHAR) {
+ if (opline->opcode == ZEND_ADD_CHAR) {
char c = (char)Z_LVAL(ZEND_OP2_LITERAL(opline));
ZVAL_STRINGL(&ZEND_OP1_LITERAL(opline), &c, 1, 1);
}
SET_UNUSED(opline->op2);
MAKE_NOP(src);
opline->opcode = ZEND_QM_ASSIGN;
- } else if((opline->opcode == ZEND_ADD_STRING ||
- opline->opcode == ZEND_ADD_CHAR ||
- opline->opcode == ZEND_ADD_VAR ||
- opline->opcode == ZEND_CONCAT) &&
- ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
- VAR_SOURCE(opline->op1) &&
- VAR_SOURCE(opline->op1)->opcode == ZEND_CONCAT &&
- ZEND_OP2_TYPE(VAR_SOURCE(opline->op1)) == IS_CONST &&
- Z_TYPE(ZEND_OP2_LITERAL(VAR_SOURCE(opline->op1))) == IS_STRING &&
- Z_STRLEN(ZEND_OP2_LITERAL(VAR_SOURCE(opline->op1))) == 0) {
+ } else if ((opline->opcode == ZEND_ADD_STRING ||
+ opline->opcode == ZEND_ADD_CHAR ||
+ opline->opcode == ZEND_ADD_VAR ||
+ opline->opcode == ZEND_CONCAT) &&
+ ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
+ VAR_SOURCE(opline->op1) &&
+ VAR_SOURCE(opline->op1)->opcode == ZEND_CONCAT &&
+ ZEND_OP2_TYPE(VAR_SOURCE(opline->op1)) == IS_CONST &&
+ Z_TYPE(ZEND_OP2_LITERAL(VAR_SOURCE(opline->op1))) == IS_STRING &&
+ Z_STRLEN(ZEND_OP2_LITERAL(VAR_SOURCE(opline->op1))) == 0) {
/* convert T = CONCAT(X,''), T = ADD_STRING(T, Y) to T = CONCAT(X,Y) */
zend_op *src = VAR_SOURCE(opline->op1);
VAR_UNSET(opline->op1);
COPY_NODE(opline->op1, src->op1);
- if(opline->opcode == ZEND_ADD_CHAR) {
+ if (opline->opcode == ZEND_ADD_CHAR) {
char c = (char)Z_LVAL(ZEND_OP2_LITERAL(opline));
ZVAL_STRINGL(&ZEND_OP2_LITERAL(opline), &c, 1, 1);
}
opline->opcode = ZEND_CONCAT;
literal_dtor(&ZEND_OP2_LITERAL(src)); /* will take care of empty_string too */
MAKE_NOP(src);
- } else if(opline->opcode == ZEND_ADD_VAR &&
- ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
- VAR_SOURCE(opline->op1) &&
- VAR_SOURCE(opline->op1)->opcode == ZEND_INIT_STRING) {
+ } else if (opline->opcode == ZEND_ADD_VAR &&
+ ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
+ VAR_SOURCE(opline->op1) &&
+ VAR_SOURCE(opline->op1)->opcode == ZEND_INIT_STRING) {
/* convert T = INIT_STRING(), T = ADD_VAR(T, X) to T = CAST(STRING, X) */
zend_op *src = VAR_SOURCE(opline->op1);
VAR_UNSET(opline->op1);
MAKE_NOP(src);
opline->opcode = ZEND_CAST;
opline->extended_value = IS_STRING;
- } else if((opline->opcode == ZEND_ADD_STRING ||
- opline->opcode == ZEND_ADD_CHAR ||
- opline->opcode == ZEND_ADD_VAR ||
- opline->opcode == ZEND_CONCAT) &&
- ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
- VAR_SOURCE(opline->op1) &&
- VAR_SOURCE(opline->op1)->opcode == ZEND_CAST &&
- VAR_SOURCE(opline->op1)->extended_value == IS_STRING) {
+ } else if ((opline->opcode == ZEND_ADD_STRING ||
+ opline->opcode == ZEND_ADD_CHAR ||
+ opline->opcode == ZEND_ADD_VAR ||
+ opline->opcode == ZEND_CONCAT) &&
+ ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
+ VAR_SOURCE(opline->op1) &&
+ VAR_SOURCE(opline->op1)->opcode == ZEND_CAST &&
+ VAR_SOURCE(opline->op1)->extended_value == IS_STRING) {
/* convert T1 = CAST(STRING, X), T2 = CONCAT(T1, Y) to T2 = CONCAT(X,Y) */
zend_op *src = VAR_SOURCE(opline->op1);
VAR_UNSET(opline->op1);
COPY_NODE(opline->op1, src->op1);
- if(opline->opcode == ZEND_ADD_CHAR) {
+ if (opline->opcode == ZEND_ADD_CHAR) {
char c = (char)Z_LVAL(ZEND_OP2_LITERAL(opline));
ZVAL_STRINGL(&ZEND_OP2_LITERAL(opline), &c, 1, 1);
}
opline->opcode = ZEND_CONCAT;
MAKE_NOP(src);
- } else if(opline->opcode == ZEND_QM_ASSIGN &&
- ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
- ZEND_RESULT_TYPE(opline) == IS_TMP_VAR &&
- ZEND_OP1(opline).var == ZEND_RESULT(opline).var) {
+ } else if (opline->opcode == ZEND_QM_ASSIGN &&
+ ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
+ ZEND_RESULT_TYPE(opline) == IS_TMP_VAR &&
+ ZEND_OP1(opline).var == ZEND_RESULT(opline).var) {
/* strip T = QM_ASSIGN(T) */
MAKE_NOP(opline);
- } else if(opline->opcode == ZEND_BOOL &&
- ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
- VAR_SOURCE(opline->op1) &&
- (VAR_SOURCE(opline->op1)->opcode == ZEND_IS_EQUAL ||
- VAR_SOURCE(opline->op1)->opcode == ZEND_IS_NOT_EQUAL ||
- VAR_SOURCE(opline->op1)->opcode == ZEND_IS_SMALLER ||
- VAR_SOURCE(opline->op1)->opcode == ZEND_IS_SMALLER_OR_EQUAL ||
- VAR_SOURCE(opline->op1)->opcode == ZEND_BOOL ||
- VAR_SOURCE(opline->op1)->opcode == ZEND_IS_IDENTICAL ||
- VAR_SOURCE(opline->op1)->opcode == ZEND_IS_NOT_IDENTICAL ||
- VAR_SOURCE(opline->op1)->opcode == ZEND_ISSET_ISEMPTY_VAR ||
- VAR_SOURCE(opline->op1)->opcode == ZEND_ISSET_ISEMPTY_DIM_OBJ
- ) && !used_ext[VAR_NUM(ZEND_OP1(opline).var)]
- ) {
+ } else if (opline->opcode == ZEND_BOOL &&
+ ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
+ VAR_SOURCE(opline->op1) &&
+ (VAR_SOURCE(opline->op1)->opcode == ZEND_IS_EQUAL ||
+ VAR_SOURCE(opline->op1)->opcode == ZEND_IS_NOT_EQUAL ||
+ VAR_SOURCE(opline->op1)->opcode == ZEND_IS_SMALLER ||
+ VAR_SOURCE(opline->op1)->opcode == ZEND_IS_SMALLER_OR_EQUAL ||
+ VAR_SOURCE(opline->op1)->opcode == ZEND_BOOL ||
+ VAR_SOURCE(opline->op1)->opcode == ZEND_IS_IDENTICAL ||
+ VAR_SOURCE(opline->op1)->opcode == ZEND_IS_NOT_IDENTICAL ||
+ VAR_SOURCE(opline->op1)->opcode == ZEND_ISSET_ISEMPTY_VAR ||
+ VAR_SOURCE(opline->op1)->opcode == ZEND_ISSET_ISEMPTY_DIM_OBJ) &&
+ !used_ext[VAR_NUM(ZEND_OP1(opline).var)]) {
/* T = IS_SMALLER(X, Y), T1 = BOOL(T) => T = IS_SMALLER(X, Y), T1 = QM_ASSIGN(T) */
zend_op *src = VAR_SOURCE(opline->op1);
COPY_NODE(src->result, opline->result);
MAKE_NOP(opline);
}
/* get variable source */
- if(RESULT_USED(opline)) {
+ if (RESULT_USED(opline)) {
SET_VAR_SOURCE(opline);
}
- if(opline->opcode != ZEND_NOP) {
+ if (opline->opcode != ZEND_NOP) {
last_op = opline;
}
opline++;
}
/* remove leading NOPs */
- while(block->start_opline->opcode == ZEND_NOP) {
- if(block->len == 1) {
+ while (block->start_opline->opcode == ZEND_NOP) {
+ if (block->len == 1) {
/* this block is all NOPs, join with following block */
- if(block->follow_to) {
+ if (block->follow_to) {
delete_code_block(block);
}
- if(op_array->T){
+ if (op_array->T) {
efree(Tsource);
}
return;
/* strip the inside NOPs */
opline = block->start_opline;
end = opline+block->len;
- while(opline<end) {
- if(opline->opcode == ZEND_NOP) {
- zend_op *nop = opline+1;
+ while (opline < end) {
+ if (opline->opcode == ZEND_NOP) {
+ zend_op *nop = opline + 1;
int noplen;
- while(nop<end && nop->opcode == ZEND_NOP) {
+ while (nop < end && nop->opcode == ZEND_NOP) {
nop++;
}
noplen = nop-opline;
- if(nop<end) {
+ if (nop < end) {
/* move up non-NOP opcodes */
memmove(opline, nop, (end-nop)*sizeof(zend_op));
} else {
opline++;
}
- if(op_array->T){
+ if (op_array->T) {
efree(Tsource);
}
}
zend_code_block *cur_block = blocks;
/* Copy code of reachable blocks into a single buffer */
- while(cur_block) {
- if(cur_block->access) {
+ while (cur_block) {
+ if (cur_block->access) {
memcpy(opline, cur_block->start_opline, cur_block->len*sizeof(zend_op));
cur_block->start_opline = opline;
opline += cur_block->len;
- if((opline-1)->opcode == ZEND_JMP) {
+ if ((opline-1)->opcode == ZEND_JMP) {
zend_code_block *next;
next = cur_block->next;
- while(next && !next->access) {
+ while (next && !next->access) {
next = next->next;
}
- if(next && next == cur_block->op1_to) {
+ if (next && next == cur_block->op1_to) {
/* JMP to the next block - strip it */
cur_block->follow_to = cur_block->op1_to;
cur_block->op1_to = NULL;
/* this block will not be used, delete all constants there */
zend_op *_opl;
zend_op *end = cur_block->start_opline+cur_block->len;
- for(_opl = cur_block->start_opline; _opl && _opl < end; _opl++) {
- if(ZEND_OP1_TYPE(_opl) == IS_CONST) {
+ for (_opl = cur_block->start_opline; _opl && _opl < end; _opl++) {
+ if (ZEND_OP1_TYPE(_opl) == IS_CONST) {
literal_dtor(&ZEND_OP1_LITERAL(_opl));
}
- if(ZEND_OP2_TYPE(_opl) == IS_CONST) {
+ if (ZEND_OP2_TYPE(_opl) == IS_CONST) {
literal_dtor(&ZEND_OP2_LITERAL(_opl));
}
}
cur_block = cur_block->next;
}
#if ZEND_EXTENSION_API_NO < PHP_5_3_X_API_NO
- if(opline[-1].opcode == ZEND_THROW) {
+ if (opline[-1].opcode == ZEND_THROW) {
/* if we finished with THROW, we need to add space between THROW and HANDLE to not confuse
zend_throw_internal */
MAKE_NOP(opline);
op_array->last = opline-new_opcodes;
/* adjust exception jump targets */
- if(op_array->last_try_catch) {
+ if (op_array->last_try_catch) {
int i;
- for(i=0; i< op_array->last_try_catch; i++) {
+ for (i=0; i< op_array->last_try_catch; i++) {
op_array->try_catch_array[i].try_op = blocks->try[i]->start_opline - new_opcodes;
op_array->try_catch_array[i].catch_op = blocks->catch[i]->start_opline - new_opcodes;
}
}
/* adjust jump targets */
- for(cur_block = blocks; cur_block; cur_block = cur_block->next) {
- if(!cur_block->access) {
+ for (cur_block = blocks; cur_block; cur_block = cur_block->next) {
+ if (!cur_block->access) {
continue;
}
- if(cur_block->op1_to) {
+ if (cur_block->op1_to) {
ZEND_OP1(&cur_block->start_opline[cur_block->len-1]).opline_num = cur_block->op1_to->start_opline - new_opcodes;
}
- if(cur_block->op2_to) {
+ if (cur_block->op2_to) {
ZEND_OP2(&cur_block->start_opline[cur_block->len-1]).opline_num = cur_block->op2_to->start_opline - new_opcodes;
}
- if(cur_block->ext_to) {
+ if (cur_block->ext_to) {
cur_block->start_opline[cur_block->len-1].extended_value = cur_block->ext_to->start_opline - new_opcodes;
}
print_block(cur_block, new_opcodes, "Out ");
static void zend_jmp_optimization(zend_code_block *block, zend_op_array *op_array, zend_code_block *blocks)
{
/* last_op is the last opcode of the current block */
- zend_op *last_op = (block->start_opline+block->len-1);
+ zend_op *last_op = (block->start_opline + block->len - 1);
- switch(last_op->opcode) {
+ switch (last_op->opcode) {
case ZEND_JMP:
{
zend_op *target = block->op1_to->start_opline;
}
/* JMP(next) -> NOP */
- if(block->op1_to == next) {
+ if (block->op1_to == next) {
block->follow_to = block->op1_to;
block->op1_to = NULL;
MAKE_NOP(last_op);
block->len--;
- if(block->len == 0) {
+ if (block->len == 0) {
/* this block is nothing but NOP now */
delete_code_block(block);
}
break;
}
- if(((target->opcode == ZEND_JMP &&
- block->op1_to != block->op1_to->op1_to) ||
- target->opcode == ZEND_JMPZNZ) &&
- !block->op1_to->is_try) {
+ if (((target->opcode == ZEND_JMP &&
+ block->op1_to != block->op1_to->op1_to) ||
+ target->opcode == ZEND_JMPZNZ) &&
+ !block->op1_to->is_try) {
/* JMP L, L: JMP L1 -> JMP L1 */
/* JMP L, L: JMPZNZ L1,L2 -> JMPZNZ L1,L2 */
*last_op = *target;
- if(ZEND_OP1_TYPE(last_op) == IS_CONST) {
+ if (ZEND_OP1_TYPE(last_op) == IS_CONST) {
zval_copy_ctor(&ZEND_OP1_LITERAL(last_op));
}
del_source(block, block->op1_to);
} else {
block->op1_to = NULL;
}
- } else if(target->opcode == ZEND_RETURN ||
+ } else if (target->opcode == ZEND_RETURN ||
#if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
target->opcode == ZEND_RETURN_BY_REF ||
#endif
target->opcode == ZEND_EXIT) {
/* JMP L, L: RETURN to immediate RETURN */
*last_op = *target;
- if(ZEND_OP1_TYPE(last_op) == IS_CONST) {
+ if (ZEND_OP1_TYPE(last_op) == IS_CONST) {
zval_copy_ctor(&ZEND_OP1_LITERAL(last_op));
}
del_source(block, block->op1_to);
case ZEND_JMPZ:
case ZEND_JMPNZ:
/* constant conditional JMPs */
- if(ZEND_OP1_TYPE(last_op) == IS_CONST) {
+ if (ZEND_OP1_TYPE(last_op) == IS_CONST) {
int should_jmp = zend_is_true(&ZEND_OP1_LITERAL(last_op));
if (last_op->opcode == ZEND_JMPZ) {
should_jmp = !should_jmp;
break;
}
- if(block->op2_to) {
+ if (block->op2_to) {
zend_uchar same_type = ZEND_OP1_TYPE(last_op);
zend_uint same_var = VAR_NUM_EX(last_op->op1);
zend_op *target;
next_target:
target = target_block->start_opline;
target_end = target_block->start_opline + target_block->len;
- while(target < target_end && target->opcode == ZEND_NOP) {
+ while (target < target_end && target->opcode == ZEND_NOP) {
target++;
}
/* next block is only NOP's */
- if(target == target_end) {
+ if (target == target_end) {
target_block = target_block->follow_to;
goto next_target;
- } else
- /* JMPZ(X, L), L: JMPNZ(X, L2) -> JMPZ(X, L+1) */
- if(target->opcode == INV_COND(last_op->opcode) &&
+ } else if (target->opcode == INV_COND(last_op->opcode) &&
+ /* JMPZ(X, L), L: JMPNZ(X, L2) -> JMPZ(X, L+1) */
(ZEND_OP1_TYPE(target) & (IS_TMP_VAR|IS_CV)) &&
same_type == ZEND_OP1_TYPE(target) &&
same_var == VAR_NUM_EX(target->op1) &&
del_source(block, block->op2_to);
block->op2_to = target_block->follow_to;
ADD_SOURCE(block, block->op2_to);
- }
- /* JMPZ(X, L), L: X = JMPNZ_EX(X, L2) -> JMPZ(X, L+1) */
- else if(target->opcode == INV_COND_EX(last_op->opcode) &&
- (ZEND_OP1_TYPE(target) & (IS_TMP_VAR|IS_CV)) &&
- same_type == ZEND_OP1_TYPE(target) &&
- same_var == VAR_NUM_EX(target->op1) &&
- target_block->follow_to &&
- !target_block->is_try
- ) {
+ } else if (target->opcode == INV_COND_EX(last_op->opcode) &&
+ (ZEND_OP1_TYPE(target) & (IS_TMP_VAR|IS_CV)) &&
+ same_type == ZEND_OP1_TYPE(target) &&
+ same_var == VAR_NUM_EX(target->op1) &&
+ target_block->follow_to &&
+ !target_block->is_try) {
+ /* JMPZ(X, L), L: X = JMPNZ_EX(X, L2) -> JMPZ(X, L+1) */
last_op->opcode += 3;
last_op->result = target->result;
del_source(block, block->op2_to);
block->op2_to = target_block->follow_to;
ADD_SOURCE(block, block->op2_to);
- }
- /* JMPZ(X, L), L: JMPZ(X, L2) -> JMPZ(X, L2) */
- else if(target_block->op2_to &&
- target->opcode == last_op->opcode &&
- (ZEND_OP1_TYPE(target) & (IS_TMP_VAR|IS_CV)) &&
- same_type == ZEND_OP1_TYPE(target) &&
- same_var == VAR_NUM_EX(target->op1) &&
- !target_block->is_try
- ) {
+ } else if (target_block->op2_to &&
+ target->opcode == last_op->opcode &&
+ (ZEND_OP1_TYPE(target) & (IS_TMP_VAR|IS_CV)) &&
+ same_type == ZEND_OP1_TYPE(target) &&
+ same_var == VAR_NUM_EX(target->op1) &&
+ !target_block->is_try) {
+ /* JMPZ(X, L), L: JMPZ(X, L2) -> JMPZ(X, L2) */
del_source(block, block->op2_to);
block->op2_to = target_block->op2_to;
ADD_SOURCE(block, block->op2_to);
- }
- /* JMPZ(X, L), L: JMP(L2) -> JMPZ(X, L2) */
- else if(target_block->op1_to &&
- target->opcode == ZEND_JMP &&
- !target_block->is_try
- ) {
+ } else if (target_block->op1_to &&
+ target->opcode == ZEND_JMP &&
+ !target_block->is_try) {
+ /* JMPZ(X, L), L: JMP(L2) -> JMPZ(X, L2) */
del_source(block, block->op2_to);
block->op2_to = target_block->op1_to;
ADD_SOURCE(block, block->op2_to);
- }
- /* JMPZ(X, L), L: JMPZNZ(X, L2, L3) -> JMPZ(X, L2) */
- else if(target_block->op2_to &&
- target_block->ext_to &&
- target->opcode == ZEND_JMPZNZ &&
- (ZEND_OP1_TYPE(target) & (IS_TMP_VAR|IS_CV)) &&
- same_type == ZEND_OP1_TYPE(target) &&
- same_var == VAR_NUM_EX(target->op1) &&
- ! target_block->is_try
- ) {
+ } else if (target_block->op2_to &&
+ target_block->ext_to &&
+ target->opcode == ZEND_JMPZNZ &&
+ (ZEND_OP1_TYPE(target) & (IS_TMP_VAR|IS_CV)) &&
+ same_type == ZEND_OP1_TYPE(target) &&
+ same_var == VAR_NUM_EX(target->op1) &&
+ !target_block->is_try) {
+ /* JMPZ(X, L), L: JMPZNZ(X, L2, L3) -> JMPZ(X, L2) */
del_source(block, block->op2_to);
if (last_op->opcode == ZEND_JMPZ) {
block->op2_to = target_block->op2_to;
}
/* next block is only NOP's */
- if(target == target_end) {
+ if (target == target_end) {
del_source(block, block->follow_to);
block->follow_to = block->follow_to->follow_to;
ADD_SOURCE(block, block->follow_to);
case ZEND_JMPNZ_EX:
case ZEND_JMPZ_EX:
/* constant conditional JMPs */
- if(ZEND_OP1_TYPE(last_op) == IS_CONST) {
+ if (ZEND_OP1_TYPE(last_op) == IS_CONST) {
int should_jmp = zend_is_true(&ZEND_OP1_LITERAL(last_op));
if (last_op->opcode == ZEND_JMPZ_EX) {
should_jmp = !should_jmp;
break;
}
- if(block->op2_to) {
+ if (block->op2_to) {
zend_op *target, *target_end;
char *same_t=NULL;
zend_code_block *target_block;
int var_num = 0;
- if(op_array->T >= (zend_uint)op_array->last_var){
+ if (op_array->T >= (zend_uint)op_array->last_var) {
var_num = op_array->T;
} else {
var_num = op_array->last_var;
}
- if( var_num <= 0 ) {
+ if (var_num <= 0) {
return;
}
same_t = ecalloc(var_num, sizeof(char));
- if(same_t == NULL){
+ if (same_t == NULL) {
return;
}
same_t[VAR_NUM_EX(last_op->op1)] |= ZEND_OP1_TYPE(last_op);
next_target_ex:
target = target_block->start_opline;
target_end = target_block->start_opline + target_block->len;
- while(target < target_end && target->opcode == ZEND_NOP) {
+ while (target < target_end && target->opcode == ZEND_NOP) {
target++;
}
/* next block is only NOP's */
- if(target == target_end) {
+ if (target == target_end) {
target_block = target_block->follow_to;
goto next_target_ex;
- } else
- /* T = JMPZ_EX(X, L1), L1: JMPZ({X|T}, L2) -> T = JMPZ_EX(X, L2) */
- if(target_block->op2_to &&
- target->opcode == last_op->opcode-3 &&
- (ZEND_OP1_TYPE(target) & (IS_TMP_VAR|IS_CV)) &&
- (same_t[VAR_NUM_EX(target->op1)] & ZEND_OP1_TYPE(target)) != 0 &&
- !target_block->is_try
- ) {
+ } else if (target_block->op2_to &&
+ target->opcode == last_op->opcode-3 &&
+ (ZEND_OP1_TYPE(target) & (IS_TMP_VAR|IS_CV)) &&
+ (same_t[VAR_NUM_EX(target->op1)] & ZEND_OP1_TYPE(target)) != 0 &&
+ !target_block->is_try) {
+ /* T = JMPZ_EX(X, L1), L1: JMPZ({X|T}, L2) -> T = JMPZ_EX(X, L2) */
del_source(block, block->op2_to);
block->op2_to = target_block->op2_to;
ADD_SOURCE(block, block->op2_to);
+ } else if (target_block->op2_to &&
+ target->opcode == INV_EX_COND(last_op->opcode) &&
+ (ZEND_OP1_TYPE(target) & (IS_TMP_VAR|IS_CV)) &&
+ (same_t[VAR_NUM_EX(target->op1)] & ZEND_OP1_TYPE(target)) != 0 &&
+ !target_block->is_try) {
/* T = JMPZ_EX(X, L1), L1: JMPNZ({X|T1}, L2) -> T = JMPZ_EX(X, L1+1) */
- } else if(target_block->op2_to &&
- target->opcode == INV_EX_COND(last_op->opcode) &&
- (ZEND_OP1_TYPE(target) & (IS_TMP_VAR|IS_CV)) &&
- (same_t[VAR_NUM_EX(target->op1)] & ZEND_OP1_TYPE(target)) != 0 &&
- !target_block->is_try
- ) {
del_source(block, block->op2_to);
block->op2_to = target_block->follow_to;
ADD_SOURCE(block, block->op2_to);
+ } else if (target_block->op2_to &&
+ target->opcode == INV_EX_COND_EX(last_op->opcode) &&
+ (ZEND_OP1_TYPE(target) & (IS_TMP_VAR|IS_CV)) &&
+ (same_t[VAR_NUM_EX(target->op1)] & ZEND_OP1_TYPE(target)) != 0 &&
+ (same_t[VAR_NUM_EX(target->result)] & ZEND_RESULT_TYPE(target)) != 0 &&
+ !target_block->is_try) {
/* T = JMPZ_EX(X, L1), L1: T = JMPNZ_EX(T, L2) -> T = JMPZ_EX(X, L1+1) */
- } else if(target_block->op2_to &&
- target->opcode == INV_EX_COND_EX(last_op->opcode) &&
- (ZEND_OP1_TYPE(target) & (IS_TMP_VAR|IS_CV)) &&
- (same_t[VAR_NUM_EX(target->op1)] & ZEND_OP1_TYPE(target)) != 0 &&
- (same_t[VAR_NUM_EX(target->result)] & ZEND_RESULT_TYPE(target)) != 0 &&
- !target_block->is_try) {
del_source(block, block->op2_to);
block->op2_to = target_block->follow_to;
ADD_SOURCE(block, block->op2_to);
- /* T = JMPZ_EX(X, L1), L1: T = JMPZ({X|T}, L2) -> T = JMPZ_EX(X, L2) */
- } else if(target_block->op2_to &&
- target->opcode == last_op->opcode &&
- (ZEND_OP1_TYPE(target) & (IS_TMP_VAR|IS_CV)) &&
- (same_t[VAR_NUM_EX(target->op1)] & ZEND_OP1_TYPE(target)) != 0 &&
- (same_t[VAR_NUM_EX(target->result)] & ZEND_RESULT_TYPE(target)) != 0 &&
- !target_block->is_try) {
+ } else if (target_block->op2_to &&
+ target->opcode == last_op->opcode &&
+ (ZEND_OP1_TYPE(target) & (IS_TMP_VAR|IS_CV)) &&
+ (same_t[VAR_NUM_EX(target->op1)] & ZEND_OP1_TYPE(target)) != 0 &&
+ (same_t[VAR_NUM_EX(target->result)] & ZEND_RESULT_TYPE(target)) != 0 &&
+ !target_block->is_try) {
+ /* T = JMPZ_EX(X, L1), L1: T = JMPZ({X|T}, L2) -> T = JMPZ_EX(X, L2) */
del_source(block, block->op2_to);
block->op2_to = target_block->op2_to;
ADD_SOURCE(block, block->op2_to);
- /* T = JMPZ_EX(X, L), L: JMP(L2) -> T = JMPZ(X, L2) */
- } else if(target_block->op1_to &&
- target->opcode == ZEND_JMP &&
- !target_block->is_try) {
+ } else if (target_block->op1_to &&
+ target->opcode == ZEND_JMP &&
+ !target_block->is_try) {
+ /* T = JMPZ_EX(X, L), L: JMP(L2) -> T = JMPZ(X, L2) */
del_source(block, block->op2_to);
block->op2_to = target_block->op1_to;
ADD_SOURCE(block, block->op2_to);
- /* T = JMPZ_EX(X, L), L: JMPZNZ({X|T}, L2, L3) -> T = JMPZ_EX(X, L2) */
- } else if(target_block->op2_to &&
- target_block->ext_to &&
- target->opcode == ZEND_JMPZNZ &&
- (ZEND_OP1_TYPE(target) & (IS_TMP_VAR|IS_CV)) &&
- (same_t[VAR_NUM_EX(target->op1)] & ZEND_OP1_TYPE(target)) != 0 &&
- !target_block->is_try
- ) {
+ } else if (target_block->op2_to &&
+ target_block->ext_to &&
+ target->opcode == ZEND_JMPZNZ &&
+ (ZEND_OP1_TYPE(target) & (IS_TMP_VAR|IS_CV)) &&
+ (same_t[VAR_NUM_EX(target->op1)] & ZEND_OP1_TYPE(target)) != 0 &&
+ !target_block->is_try) {
+ /* T = JMPZ_EX(X, L), L: JMPZNZ({X|T}, L2, L3) -> T = JMPZ_EX(X, L2) */
del_source(block, block->op2_to);
if (last_op->opcode == ZEND_JMPZ_EX) {
block->op2_to = target_block->op2_to;
}
ADD_SOURCE(block, block->op2_to);
}
- if(same_t != NULL){
+ if (same_t != NULL) {
efree(same_t);
}
}
next = next->next;
}
- if(ZEND_OP1_TYPE(last_op) == IS_CONST) {
+ if (ZEND_OP1_TYPE(last_op) == IS_CONST) {
if (!zend_is_true(&ZEND_OP1_LITERAL(last_op))) {
/* JMPZNZ(false,L1,L2) -> JMP(L1) */
zend_code_block *todel;
-
+
literal_dtor(&ZEND_OP1_LITERAL(last_op));
last_op->opcode = ZEND_JMP;
SET_UNUSED(last_op->op1);
} else {
/* JMPZNZ(true,L1,L2) -> JMP(L2) */
zend_code_block *todel;
-
+
literal_dtor(&ZEND_OP1_LITERAL(last_op));
last_op->opcode = ZEND_JMP;
SET_UNUSED(last_op->op1);
/* no need to add source - it's block->ext_to */
}
- if(last_op->opcode == ZEND_JMPZNZ && block->op2_to) {
+ if (last_op->opcode == ZEND_JMPZNZ && block->op2_to) {
zend_uchar same_type = ZEND_OP1_TYPE(last_op);
zend_uchar same_var = VAR_NUM_EX(last_op->op1);
zend_op *target;
next_target_znz:
target = target_block->start_opline;
target_end = target_block->start_opline + target_block->len;
- while(target < target_end && target->opcode == ZEND_NOP) {
+ while (target < target_end && target->opcode == ZEND_NOP) {
target++;
}
/* next block is only NOP's */
- if(target == target_end) {
+ if (target == target_end) {
target_block = target_block->follow_to;
goto next_target_znz;
- /* JMPZNZ(X, L1, L2), L1: JMPZ(X, L3) -> JMPZNZ(X, L3, L2) */
- } else if(target_block->op2_to &&
- (target->opcode == ZEND_JMPZ || target->opcode == ZEND_JMPZNZ) &&
- (ZEND_OP1_TYPE(target) & (IS_TMP_VAR|IS_CV)) &&
- same_type == ZEND_OP1_TYPE(target) &&
- same_var == VAR_NUM_EX(target->op1) &&
- !target_block->is_try) {
+ } else if (target_block->op2_to &&
+ (target->opcode == ZEND_JMPZ || target->opcode == ZEND_JMPZNZ) &&
+ (ZEND_OP1_TYPE(target) & (IS_TMP_VAR|IS_CV)) &&
+ same_type == ZEND_OP1_TYPE(target) &&
+ same_var == VAR_NUM_EX(target->op1) &&
+ !target_block->is_try) {
+ /* JMPZNZ(X, L1, L2), L1: JMPZ(X, L3) -> JMPZNZ(X, L3, L2) */
del_source(block, block->op2_to);
block->op2_to = target_block->op2_to;
ADD_SOURCE(block, block->op2_to);
- }
- /* JMPZNZ(X, L1, L2), L1: X = JMPNZ(X, L3) -> JMPZNZ(X, L1+1, L2) */
- else if(target->opcode == ZEND_JMPNZ &&
- (ZEND_OP1_TYPE(target) & (IS_TMP_VAR|IS_CV)) &&
- same_type == ZEND_OP1_TYPE(target) &&
- same_var == VAR_NUM_EX(target->op1) &&
- target_block->follow_to &&
- !target_block->is_try) {
+ } else if (target->opcode == ZEND_JMPNZ &&
+ (ZEND_OP1_TYPE(target) & (IS_TMP_VAR|IS_CV)) &&
+ same_type == ZEND_OP1_TYPE(target) &&
+ same_var == VAR_NUM_EX(target->op1) &&
+ target_block->follow_to &&
+ !target_block->is_try) {
+ /* JMPZNZ(X, L1, L2), L1: X = JMPNZ(X, L3) -> JMPZNZ(X, L1+1, L2) */
del_source(block, block->op2_to);
block->op2_to = target_block->follow_to;
ADD_SOURCE(block, block->op2_to);
- }
- /* JMPZNZ(X, L1, L2), L1: JMP(L3) -> JMPZNZ(X, L3, L2) */
- else if(target_block->op1_to &&
- target->opcode == ZEND_JMP &&
- !target_block->is_try) {
+ } else if (target_block->op1_to &&
+ target->opcode == ZEND_JMP &&
+ !target_block->is_try) {
+ /* JMPZNZ(X, L1, L2), L1: JMP(L3) -> JMPZNZ(X, L3, L2) */
del_source(block, block->op2_to);
block->op2_to = target_block->op1_to;
ADD_SOURCE(block, block->op2_to);
#if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
# define T_USAGE(op) do { \
- if((op ## _type & (IS_VAR | IS_TMP_VAR)) && \
+ if ((op ## _type & (IS_VAR | IS_TMP_VAR)) && \
!defined_here[VAR_NUM(op.var)] && !used_ext[VAR_NUM(op.var)]) { \
used_ext[VAR_NUM(op.var)] = 1; \
} \
#else
# define T_USAGE(op) do { \
- if((op.op_type == IS_VAR || op.op_type == IS_TMP_VAR) && \
+ if ((op.op_type == IS_VAR || op.op_type == IS_TMP_VAR) && \
!defined_here[VAR_NUM(op.u.var)] && !used_ext[VAR_NUM(op.u.var)]) { \
used_ext[VAR_NUM(op.u.var)] = 1; \
} \
char *usage;
char *defined_here;
- if(op_array->T == 0) {
+ if (op_array->T == 0) {
/* shortcut - if no Ts, nothing to do */
return;
}
usage = ecalloc(op_array->T, 1);
defined_here = emalloc(op_array->T);
- while(next_block) {
+ while (next_block) {
zend_op *opline = next_block->start_opline;
zend_op *end = opline+next_block->len;
- if(!next_block->access) {
+ if (!next_block->access) {
next_block = next_block->next;
continue;
}
memset(defined_here, 0, op_array->T);
- while(opline<end) {
+ while (opline<end) {
T_USAGE(opline->op1);
T_USAGE(opline->op2);
- if(RESULT_USED(opline)) {
- if(!defined_here[VAR_NUM(ZEND_RESULT(opline).var)] && !used_ext[VAR_NUM(ZEND_RESULT(opline).var)] &&
- (opline->opcode == ZEND_RECV || opline->opcode == ZEND_RECV_INIT ||
+ if (RESULT_USED(opline)) {
+ if (!defined_here[VAR_NUM(ZEND_RESULT(opline).var)] && !used_ext[VAR_NUM(ZEND_RESULT(opline).var)] &&
+ (opline->opcode == ZEND_RECV || opline->opcode == ZEND_RECV_INIT ||
(opline->opcode == ZEND_OP_DATA && ZEND_RESULT_TYPE(opline) == IS_TMP_VAR) ||
opline->opcode == ZEND_ADD_ARRAY_ELEMENT)) {
/* these opcodes use the result as argument */
#if DEBUG_BLOCKPASS
{
int i;
- for(i=0; i< op_array->T; i++) {
- fprintf(stderr, "T%d: %c\n", i, used_ext[i]+'0');
+ for (i=0; i< op_array->T; i++) {
+ fprintf(stderr, "T%d: %c\n", i, used_ext[i] + '0');
}
}
#endif
- while(block) {
- zend_op *opline = block->start_opline+block->len-1;
+ while (block) {
+ zend_op *opline = block->start_opline+block->len - 1;
- if(!block->access) {
+ if (!block->access) {
block = block->next;
continue;
}
memcpy(usage, used_ext, op_array->T);
- while(opline>=block->start_opline) {
+ while (opline >= block->start_opline) {
/* usage checks */
- if(RES_NEVER_USED(opline)) {
- switch(opline->opcode) {
+ if (RES_NEVER_USED(opline)) {
+ switch (opline->opcode) {
case ZEND_ASSIGN_ADD:
case ZEND_ASSIGN_SUB:
case ZEND_ASSIGN_MUL:
case ZEND_ASSIGN_REF:
case ZEND_DO_FCALL:
case ZEND_DO_FCALL_BY_NAME:
- if(ZEND_RESULT_TYPE(opline) == IS_VAR) {
+ if (ZEND_RESULT_TYPE(opline) == IS_VAR) {
#if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
ZEND_RESULT_TYPE(opline) |= EXT_TYPE_UNUSED;
#else
case ZEND_QM_ASSIGN:
case ZEND_BOOL:
case ZEND_BOOL_NOT:
- if(ZEND_OP1_TYPE(opline) == IS_CONST) {
+ if (ZEND_OP1_TYPE(opline) == IS_CONST) {
literal_dtor(&ZEND_OP1_LITERAL(opline));
}
MAKE_NOP(opline);
}
}
- if(opline->opcode == ZEND_RECV || opline->opcode == ZEND_RECV_INIT ||
- opline->opcode == ZEND_ADD_ARRAY_ELEMENT) {
- if(ZEND_OP1_TYPE(opline) == IS_VAR || ZEND_OP1_TYPE(opline) == IS_TMP_VAR) {
+ if (opline->opcode == ZEND_RECV ||
+ opline->opcode == ZEND_RECV_INIT ||
+ opline->opcode == ZEND_ADD_ARRAY_ELEMENT) {
+ if (ZEND_OP1_TYPE(opline) == IS_VAR || ZEND_OP1_TYPE(opline) == IS_TMP_VAR) {
usage[VAR_NUM(ZEND_RESULT(opline).var)] = 1;
}
} else {
- if(RESULT_USED(opline)) {
+ if (RESULT_USED(opline)) {
usage[VAR_NUM(ZEND_RESULT(opline).var)] = 0;
}
}
- if(ZEND_OP1_TYPE(opline) == IS_VAR || ZEND_OP1_TYPE(opline) == IS_TMP_VAR) {
+ if (ZEND_OP1_TYPE(opline) == IS_VAR || ZEND_OP1_TYPE(opline) == IS_TMP_VAR) {
usage[VAR_NUM(ZEND_OP1(opline).var)] = 1;
}
- if(ZEND_OP2_TYPE(opline) == IS_VAR || ZEND_OP2_TYPE(opline) == IS_TMP_VAR) {
+ if (ZEND_OP2_TYPE(opline) == IS_VAR || ZEND_OP2_TYPE(opline) == IS_TMP_VAR) {
usage[VAR_NUM(ZEND_OP2(opline).var)] = 1;
}
#if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
- if((ZEND_RESULT_TYPE(opline) & IS_VAR) &&
- (ZEND_RESULT_TYPE(opline) & EXT_TYPE_UNUSED) &&
- usage[VAR_NUM(ZEND_RESULT(opline).var)]) {
+ if ((ZEND_RESULT_TYPE(opline) & IS_VAR) &&
+ (ZEND_RESULT_TYPE(opline) & EXT_TYPE_UNUSED) &&
+ usage[VAR_NUM(ZEND_RESULT(opline).var)]) {
ZEND_RESULT_TYPE(opline) &= ~EXT_TYPE_UNUSED;
}
#else
- if(ZEND_RESULT_TYPE(opline) == IS_VAR &&
- usage[VAR_NUM(ZEND_RESULT(opline).var)] &&
- (ZEND_RESULT(opline).EA.type & EXT_TYPE_UNUSED) != 0) {
+ if (ZEND_RESULT_TYPE(opline) == IS_VAR &&
+ usage[VAR_NUM(ZEND_RESULT(opline).var)] &&
+ (ZEND_RESULT(opline).EA.type & EXT_TYPE_UNUSED) != 0) {
ZEND_RESULT(opline).EA.type &= ~EXT_TYPE_UNUSED;
}
#endif
}
block = block->next;
} /* end blocks */
+
efree(defined_here);
efree(usage);
}
char *usage;
#if DEBUG_BLOCKPASS
- fprintf(stderr, "File %s func %s\n", op_array->filename, op_array->function_name?op_array->function_name:"main");
+ fprintf(stderr, "File %s func %s\n", op_array->filename, op_array->function_name? op_array->function_name : "main");
fflush(stderr);
#endif
/* Build CFG */
blocks = find_code_blocks(op_array);
- if(!blocks) {
+ if (!blocks) {
return;
}
zend_rebuild_access_path(blocks, op_array, 0);
/* full rebuild here to produce correct sources! */
usage = emalloc(op_array->T);
- for(pass=0; pass< PASSES; pass++) {
+ for (pass = 0; pass < PASSES; pass++) {
/* Compute data dependencies */
memset(usage, 0, op_array->T);
zend_t_usage(blocks, op_array, usage);
/* optimize each basic block separately */
- for(cur_block = blocks; cur_block; cur_block = cur_block->next) {
- if(!cur_block->access) {
+ for (cur_block = blocks; cur_block; cur_block = cur_block->next) {
+ if (!cur_block->access) {
continue;
}
zend_optimize_block(cur_block, op_array, usage TSRMLS_CC);
}
/* Jump optimization for each block */
- for(cur_block = blocks; cur_block; cur_block = cur_block->next) {
- if(!cur_block->access) {
+ for (cur_block = blocks; cur_block; cur_block = cur_block->next) {
+ if (!cur_block->access) {
continue;
}
zend_jmp_optimization(cur_block, op_array, blocks);
efree(usage);
/* Destroy CFG */
- for(cur_block = blocks; cur_block; cur_block = cur_block->next) {
+ for (cur_block = blocks; cur_block; cur_block = cur_block->next) {
zend_block_source *cs = cur_block->sources;
- while(cs) {
+ while (cs) {
zend_block_source *n = cs->next;
efree(cs);
cs = n;
}
/* update brk/cont array */
- for (j=0; j<op_array->last_brk_cont; j++) {
+ for (j = 0; j < op_array->last_brk_cont; j++) {
op_array->brk_cont_array[j].brk -= shiftlist[op_array->brk_cont_array[j].brk];
op_array->brk_cont_array[j].cont -= shiftlist[op_array->brk_cont_array[j].cont];
op_array->brk_cont_array[j].start -= shiftlist[op_array->brk_cont_array[j].start];
}
/* update try/catch array */
- for (j=0; j<op_array->last_try_catch; j++) {
+ for (j = 0; j < op_array->last_try_catch; j++) {
op_array->try_catch_array[j].try_op -= shiftlist[op_array->try_catch_array[j].try_op];
op_array->try_catch_array[j].catch_op -= shiftlist[op_array->try_catch_array[j].catch_op];
#if ZEND_EXTENSION_API_NO > PHP_5_4_X_API_NO
#endif
#define GET_AVAILABLE_T() \
- for (i=0; i<T; i++) { \
+ for (i = 0; i < T; i++) { \
if (!taken_T[i]) { \
break; \
} \
}
/* Skip OP_DATA */
- if (opline->opcode == ZEND_OP_DATA &&
+ if (opline->opcode == ZEND_OP_DATA &&
(opline-1)->opcode == ZEND_ASSIGN_DIM) {
opline--;
continue;
efree(start_of_T);
efree(valid_T);
efree(map_T);
- op_array->T = max+1;
+ op_array->T = max + 1;
}
*/
if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
- int i=0;
+ int i = 0;
zend_op *opline = op_array->opcodes;
zend_op *end = opline + op_array->last;
- while (opline<end) {
+ while (opline < end) {
switch (opline->opcode) {
case ZEND_ADD:
case ZEND_SUB:
case ZEND_BW_AND:
case ZEND_BW_XOR:
case ZEND_BOOL_XOR:
- if (ZEND_OP1_TYPE(opline)==IS_CONST
- && ZEND_OP2_TYPE(opline)==IS_CONST) {
- /* binary operation wheit constant operands */
+ if (ZEND_OP1_TYPE(opline) == IS_CONST &&
+ ZEND_OP2_TYPE(opline) == IS_CONST) {
+ /* binary operation with constant operands */
int (*binary_op)(zval *result, zval *op1, zval *op2 TSRMLS_DC) = get_binary_op(opline->opcode);
zend_uint tv = ZEND_RESULT(opline).var; /* temporary variable */
zval result;
zend_op *tmp_opline;
int er;
- if (opline->opcode == ZEND_DIV &&
- Z_TYPE(ZEND_OP2_LITERAL(opline)) == IS_LONG &&
- Z_LVAL(ZEND_OP2_LITERAL(opline)) == 0) {
+ if (opline->opcode == ZEND_DIV &&
+ Z_TYPE(ZEND_OP2_LITERAL(opline)) == IS_LONG &&
+ Z_LVAL(ZEND_OP2_LITERAL(opline)) == 0) {
/* div by 0 */
break;
}
MAKE_NOP(opline);
/* substitute the following TMP_VAR usage with constant */
- for (tmp_opline=opline+1; tmp_opline<end; tmp_opline++) {
- if (ZEND_OP1_TYPE(tmp_opline)== IS_TMP_VAR
- && ZEND_OP1(tmp_opline).var == tv) {
- if (tmp_opline->opcode==ZEND_FREE) {
+ for (tmp_opline = opline + 1; tmp_opline < end; tmp_opline++) {
+ if (ZEND_OP1_TYPE(tmp_opline) == IS_TMP_VAR &&
+ ZEND_OP1(tmp_opline).var == tv) {
+ if (tmp_opline->opcode == ZEND_FREE) {
MAKE_NOP(tmp_opline);
zval_dtor(&result);
} else {
#if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
tmp_opline->op1.constant = zend_add_literal(op_array, &result TSRMLS_CC);
if (Z_TYPE(result) == IS_STRING) {
- Z_HASH_P(&ZEND_OP1_LITERAL(tmp_opline)) = zend_hash_func(Z_STRVAL(ZEND_OP1_LITERAL(tmp_opline)), Z_STRLEN(ZEND_OP1_LITERAL(tmp_opline))+1);
+ Z_HASH_P(&ZEND_OP1_LITERAL(tmp_opline)) = zend_hash_func(Z_STRVAL(ZEND_OP1_LITERAL(tmp_opline)), Z_STRLEN(ZEND_OP1_LITERAL(tmp_opline)) + 1);
if (tmp_opline->opcode == ZEND_INIT_STATIC_METHOD_CALL ||
- tmp_opline->opcode == ZEND_DO_FCALL ||
- tmp_opline->opcode == ZEND_CATCH ||
- tmp_opline->opcode == ZEND_FETCH_CONSTANT) {
+ tmp_opline->opcode == ZEND_DO_FCALL ||
+ tmp_opline->opcode == ZEND_CATCH ||
+ tmp_opline->opcode == ZEND_FETCH_CONSTANT) {
op_array->literals[tmp_opline->op1.constant].cache_slot = op_array->last_cache_slot++;
}
}
/* TMP_VAR my be used only once */
break;
}
- if (ZEND_OP2_TYPE(tmp_opline)== IS_TMP_VAR
- && ZEND_OP2(tmp_opline).var == tv) {
+ if (ZEND_OP2_TYPE(tmp_opline) == IS_TMP_VAR &&
+ ZEND_OP2(tmp_opline).var == tv) {
ZEND_OP2_TYPE(tmp_opline) = IS_CONST;
#if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
tmp_opline->op2.constant = zend_add_literal(op_array, &result TSRMLS_CC);
if (Z_TYPE(result) == IS_STRING) {
- Z_HASH_P(&ZEND_OP2_LITERAL(tmp_opline)) = zend_hash_func(Z_STRVAL(ZEND_OP2_LITERAL(tmp_opline)), Z_STRLEN(ZEND_OP2_LITERAL(tmp_opline))+1);
+ Z_HASH_P(&ZEND_OP2_LITERAL(tmp_opline)) = zend_hash_func(Z_STRVAL(ZEND_OP2_LITERAL(tmp_opline)), Z_STRLEN(ZEND_OP2_LITERAL(tmp_opline)) + 1);
if (tmp_opline->opcode == ZEND_FETCH_R ||
- tmp_opline->opcode == ZEND_FETCH_W ||
- tmp_opline->opcode == ZEND_FETCH_RW ||
- tmp_opline->opcode == ZEND_FETCH_IS ||
- tmp_opline->opcode == ZEND_FETCH_UNSET ||
- tmp_opline->opcode == ZEND_FETCH_FUNC_ARG ||
- tmp_opline->opcode == ZEND_FETCH_CLASS ||
- tmp_opline->opcode == ZEND_INIT_FCALL_BY_NAME ||
- tmp_opline->opcode == ZEND_INIT_NS_FCALL_BY_NAME ||
- tmp_opline->opcode == ZEND_UNSET_VAR ||
- tmp_opline->opcode == ZEND_ISSET_ISEMPTY_VAR ||
- tmp_opline->opcode == ZEND_ADD_INTERFACE ||
- tmp_opline->opcode == ZEND_ADD_TRAIT) {
+ tmp_opline->opcode == ZEND_FETCH_W ||
+ tmp_opline->opcode == ZEND_FETCH_RW ||
+ tmp_opline->opcode == ZEND_FETCH_IS ||
+ tmp_opline->opcode == ZEND_FETCH_UNSET ||
+ tmp_opline->opcode == ZEND_FETCH_FUNC_ARG ||
+ tmp_opline->opcode == ZEND_FETCH_CLASS ||
+ tmp_opline->opcode == ZEND_INIT_FCALL_BY_NAME ||
+ tmp_opline->opcode == ZEND_INIT_NS_FCALL_BY_NAME ||
+ tmp_opline->opcode == ZEND_UNSET_VAR ||
+ tmp_opline->opcode == ZEND_ISSET_ISEMPTY_VAR ||
+ tmp_opline->opcode == ZEND_ADD_INTERFACE ||
+ tmp_opline->opcode == ZEND_ADD_TRAIT) {
op_array->literals[tmp_opline->op2.constant].cache_slot = op_array->last_cache_slot++;
} else if (tmp_opline->opcode == ZEND_INIT_METHOD_CALL ||
- tmp_opline->opcode == ZEND_INIT_STATIC_METHOD_CALL ||
- tmp_opline->opcode == ZEND_FETCH_CONSTANT ||
- tmp_opline->opcode == ZEND_ASSIGN_OBJ ||
- tmp_opline->opcode == ZEND_FETCH_OBJ_R ||
- tmp_opline->opcode == ZEND_FETCH_OBJ_W ||
- tmp_opline->opcode == ZEND_FETCH_OBJ_RW ||
- tmp_opline->opcode == ZEND_FETCH_OBJ_IS ||
- tmp_opline->opcode == ZEND_FETCH_OBJ_UNSET ||
- tmp_opline->opcode == ZEND_FETCH_OBJ_FUNC_ARG ||
- tmp_opline->opcode == ZEND_UNSET_OBJ ||
- tmp_opline->opcode == ZEND_PRE_INC_OBJ ||
- tmp_opline->opcode == ZEND_PRE_DEC_OBJ ||
- tmp_opline->opcode == ZEND_POST_INC_OBJ ||
- tmp_opline->opcode == ZEND_POST_DEC_OBJ ||
- tmp_opline->opcode == ZEND_ISSET_ISEMPTY_PROP_OBJ) {
+ tmp_opline->opcode == ZEND_INIT_STATIC_METHOD_CALL ||
+ tmp_opline->opcode == ZEND_FETCH_CONSTANT ||
+ tmp_opline->opcode == ZEND_ASSIGN_OBJ ||
+ tmp_opline->opcode == ZEND_FETCH_OBJ_R ||
+ tmp_opline->opcode == ZEND_FETCH_OBJ_W ||
+ tmp_opline->opcode == ZEND_FETCH_OBJ_RW ||
+ tmp_opline->opcode == ZEND_FETCH_OBJ_IS ||
+ tmp_opline->opcode == ZEND_FETCH_OBJ_UNSET ||
+ tmp_opline->opcode == ZEND_FETCH_OBJ_FUNC_ARG ||
+ tmp_opline->opcode == ZEND_UNSET_OBJ ||
+ tmp_opline->opcode == ZEND_PRE_INC_OBJ ||
+ tmp_opline->opcode == ZEND_PRE_DEC_OBJ ||
+ tmp_opline->opcode == ZEND_POST_INC_OBJ ||
+ tmp_opline->opcode == ZEND_POST_DEC_OBJ ||
+ tmp_opline->opcode == ZEND_ISSET_ISEMPTY_PROP_OBJ) {
op_array->literals[tmp_opline->op2.constant].cache_slot = op_array->last_cache_slot;
op_array->last_cache_slot += 2;
} else if (tmp_opline->opcode == ZEND_ASSIGN_ADD ||
- tmp_opline->opcode == ZEND_ASSIGN_SUB ||
- tmp_opline->opcode == ZEND_ASSIGN_MUL ||
- tmp_opline->opcode == ZEND_ASSIGN_DIV ||
- tmp_opline->opcode == ZEND_ASSIGN_MOD ||
- tmp_opline->opcode == ZEND_ASSIGN_SL ||
- tmp_opline->opcode == ZEND_ASSIGN_SR ||
- tmp_opline->opcode == ZEND_ASSIGN_CONCAT ||
- tmp_opline->opcode == ZEND_ASSIGN_BW_OR ||
- tmp_opline->opcode == ZEND_ASSIGN_BW_AND ||
- tmp_opline->opcode == ZEND_ASSIGN_BW_XOR) {
+ tmp_opline->opcode == ZEND_ASSIGN_SUB ||
+ tmp_opline->opcode == ZEND_ASSIGN_MUL ||
+ tmp_opline->opcode == ZEND_ASSIGN_DIV ||
+ tmp_opline->opcode == ZEND_ASSIGN_MOD ||
+ tmp_opline->opcode == ZEND_ASSIGN_SL ||
+ tmp_opline->opcode == ZEND_ASSIGN_SR ||
+ tmp_opline->opcode == ZEND_ASSIGN_CONCAT ||
+ tmp_opline->opcode == ZEND_ASSIGN_BW_OR ||
+ tmp_opline->opcode == ZEND_ASSIGN_BW_AND ||
+ tmp_opline->opcode == ZEND_ASSIGN_BW_XOR) {
if (tmp_opline->extended_value == ZEND_ASSIGN_OBJ) {
op_array->literals[tmp_opline->op2.constant].cache_slot = op_array->last_cache_slot;
op_array->last_cache_slot += 2;
break;
case ZEND_CAST:
- if (ZEND_OP1_TYPE(opline)==IS_CONST &&
+ if (ZEND_OP1_TYPE(opline) == IS_CONST &&
opline->extended_value != IS_ARRAY &&
opline->extended_value != IS_OBJECT &&
opline->extended_value != IS_RESOURCE) {
case ZEND_BW_NOT:
case ZEND_BOOL_NOT:
- if (ZEND_OP1_TYPE(opline)==IS_CONST) {
+ if (ZEND_OP1_TYPE(opline) == IS_CONST) {
/* unary operation on constant operand */
unary_op_type unary_op = get_unary_op(opline->opcode);
zval result;
MAKE_NOP(opline);
/* substitute the following TMP_VAR usage with constant */
- for (tmp_opline=opline+1; tmp_opline<end; tmp_opline++) {
- if (ZEND_OP1_TYPE(tmp_opline)== IS_TMP_VAR
- && ZEND_OP1(tmp_opline).var == tv) {
- if (tmp_opline->opcode==ZEND_FREE) {
+ for (tmp_opline = opline + 1; tmp_opline < end; tmp_opline++) {
+ if (ZEND_OP1_TYPE(tmp_opline) == IS_TMP_VAR &&
+ ZEND_OP1(tmp_opline).var == tv) {
+ if (tmp_opline->opcode == ZEND_FREE) {
MAKE_NOP(tmp_opline);
zval_dtor(&result);
} else {
}
break;
}
- if (ZEND_OP2_TYPE(tmp_opline)== IS_TMP_VAR
- && ZEND_OP2(tmp_opline).var == tv) {
+ if (ZEND_OP2_TYPE(tmp_opline) == IS_TMP_VAR &&
+ ZEND_OP2(tmp_opline).var == tv) {
ZEND_OP2_TYPE(tmp_opline) = IS_CONST;
#if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
tmp_opline->op2.constant = zend_add_literal(op_array, &result TSRMLS_CC);
case ZEND_ADD_STRING:
case ZEND_ADD_CHAR:
{
- zend_op *next_op = opline+1;
- int requires_conversion = (opline->opcode==ZEND_ADD_CHAR?1:0);
+ zend_op *next_op = opline + 1;
+ int requires_conversion = (opline->opcode == ZEND_ADD_CHAR? 1 : 0);
size_t final_length = 0;
char *ptr;
zend_op *last_op;
/* There is always a ZEND_RETURN at the end
if (next_op>=end) {
- break;
+ break;
}
*/
while (next_op->opcode == ZEND_ADD_STRING || next_op->opcode == ZEND_ADD_CHAR) {
}
last_op = next_op;
final_length += (requires_conversion ? 1 : ZEND_OP2_LITERAL(opline).value.str.len);
- ptr = (char *) emalloc(final_length+1);
+ ptr = (char *)emalloc(final_length+1);
ptr[final_length] = '\0';
if (requires_conversion) { /* ZEND_ADD_CHAR */
char chval = (char)ZEND_OP2_LITERAL(opline).value.lval;
ptr += Z_STRLEN(ZEND_OP2_LITERAL(opline));
}
ZEND_OP2_LITERAL(opline).value.str.len = final_length;
- next_op = opline+1;
+ next_op = opline + 1;
while (next_op < last_op) {
if (next_op->opcode == ZEND_ADD_STRING) {
memcpy(ptr, ZEND_OP2_LITERAL(next_op).value.str.val, ZEND_OP2_LITERAL(next_op).value.str.len);
if (!((ZEND_OPTIMIZER_PASS_5|ZEND_OPTIMIZER_PASS_10) & OPTIMIZATION_LEVEL)) {
/* NOP removel is disabled => insert JMP over NOPs */
if (last_op-opline >= 3) { /* If we have more than 2 NOPS then JMP over them */
- (opline+1)->opcode = ZEND_JMP;
- ZEND_OP1(opline+1).opline_num = last_op - op_array->opcodes; /* that's OK even for ZE2, since opline_num's are resolved in pass 2 later */
+ (opline + 1)->opcode = ZEND_JMP;
+ ZEND_OP1(opline + 1).opline_num = last_op - op_array->opcodes; /* that's OK even for ZE2, since opline_num's are resolved in pass 2 later */
}
}
}
case ZEND_FETCH_CONSTANT:
if (ZEND_OP1_TYPE(opline) == IS_UNUSED &&
- ZEND_OP2_TYPE(opline) == IS_CONST &&
- Z_TYPE(ZEND_OP2_LITERAL(opline)) == IS_STRING &&
- Z_STRLEN(ZEND_OP2_LITERAL(opline)) == sizeof("__COMPILER_HALT_OFFSET__")-1 &&
- memcmp(Z_STRVAL(ZEND_OP2_LITERAL(opline)), "__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__")-1) == 0) {
- /* substitute __COMPILER_HALT_OFFSET__ constant */
+ ZEND_OP2_TYPE(opline) == IS_CONST &&
+ Z_TYPE(ZEND_OP2_LITERAL(opline)) == IS_STRING &&
+ Z_STRLEN(ZEND_OP2_LITERAL(opline)) == sizeof("__COMPILER_HALT_OFFSET__")-1 &&
+ memcmp(Z_STRVAL(ZEND_OP2_LITERAL(opline)), "__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__")-1) == 0) {
+ /* substitute __COMPILER_HALT_OFFSET__ constant */
zend_bool orig_in_execution = EG(in_execution);
zend_op_array *orig_op_array = EG(active_op_array);
zval offset;
}
if (ZEND_OP1_TYPE(opline) == IS_UNUSED &&
- ZEND_OP2_TYPE(opline) == IS_CONST &&
- ZEND_OP2_LITERAL(opline).type == IS_STRING) {
- /* substitute persistent constants */
+ ZEND_OP2_TYPE(opline) == IS_CONST &&
+ ZEND_OP2_LITERAL(opline).type == IS_STRING) {
+ /* substitute persistent constants */
zval c;
- if(zend_get_persistent_constant(Z_STRVAL(ZEND_OP2_LITERAL(opline)), Z_STRLEN(ZEND_OP2_LITERAL(opline)), &c, 1 TSRMLS_CC) == 0) {
+ if (!zend_get_persistent_constant(Z_STRVAL(ZEND_OP2_LITERAL(opline)), Z_STRLEN(ZEND_OP2_LITERAL(opline)), &c, 1 TSRMLS_CC)) {
break;
}
literal_dtor(&ZEND_OP2_LITERAL(opline));
break;
case ZEND_INIT_FCALL_BY_NAME:
- if(opline->extended_value == 0 /* not method */ &&
- ZEND_OP1_TYPE(opline) == IS_UNUSED &&
- ZEND_OP2_TYPE(opline) == IS_CONST) {
- if((opline+1)->opcode == ZEND_DO_FCALL_BY_NAME &&
- (opline+1)->extended_value == 0) {
- (opline+1)->opcode = ZEND_DO_FCALL;
- COPY_NODE((opline+1)->op1, opline->op2);
- zend_str_tolower(Z_STRVAL(ZEND_OP1_LITERAL(opline+1)), Z_STRLEN(ZEND_OP1_LITERAL(opline+1)));
+ if (opline->extended_value == 0 /* not method */ &&
+ ZEND_OP1_TYPE(opline) == IS_UNUSED &&
+ ZEND_OP2_TYPE(opline) == IS_CONST) {
+ if ((opline + 1)->opcode == ZEND_DO_FCALL_BY_NAME &&
+ (opline + 1)->extended_value == 0) {
+ (opline + 1)->opcode = ZEND_DO_FCALL;
+ COPY_NODE((opline + 1)->op1, opline->op2);
+ zend_str_tolower(Z_STRVAL(ZEND_OP1_LITERAL(opline + 1)), Z_STRLEN(ZEND_OP1_LITERAL(opline + 1)));
#if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
- Z_HASH_P(&ZEND_OP1_LITERAL(opline+1)) = zend_hash_func(Z_STRVAL(ZEND_OP1_LITERAL(opline+1)), Z_STRLEN(ZEND_OP1_LITERAL(opline+1))+1);
- op_array->literals[(opline+1)->op1.constant].cache_slot = op_array->last_cache_slot++;
+ Z_HASH_P(&ZEND_OP1_LITERAL(opline + 1)) = zend_hash_func(Z_STRVAL(ZEND_OP1_LITERAL(opline + 1)), Z_STRLEN(ZEND_OP1_LITERAL(opline + 1)) + 1);
+ op_array->literals[(opline + 1)->op1.constant].cache_slot = op_array->last_cache_slot++;
#endif
MAKE_NOP(opline);
}
if (ZEND_OPTIMIZER_PASS_2 & OPTIMIZATION_LEVEL) {
zend_op *opline;
- zend_op *end = op_array->opcodes+op_array->last;
+ zend_op *end = op_array->opcodes + op_array->last;
opline = op_array->opcodes;
- while (opline<end) {
+ while (opline < end) {
switch (opline->opcode) {
case ZEND_ADD:
case ZEND_SUB:
case ZEND_ASSIGN_SUB:
case ZEND_ASSIGN_MUL:
case ZEND_ASSIGN_DIV:
- if(opline->extended_value != 0) {
+ if (opline->extended_value != 0) {
/* object tristate op - don't attempt to optimize it! */
break;
}
case ZEND_ASSIGN_MOD:
case ZEND_ASSIGN_SL:
case ZEND_ASSIGN_SR:
- if(opline->extended_value != 0) {
+ if (opline->extended_value != 0) {
/* object tristate op - don't attempt to optimize it! */
break;
}
}
}
break;
-
+
case ZEND_CONCAT:
if (ZEND_OP1_TYPE(opline) == IS_CONST) {
if (ZEND_OP1_LITERAL(opline).type != IS_STRING) {
}
/* break missing *intentionally - the assign_op's may only optimize op2 */
case ZEND_ASSIGN_CONCAT:
- if(opline->extended_value != 0) {
+ if (opline->extended_value != 0) {
/* object tristate op - don't attempt to optimize it! */
break;
}
}
}
break;
-
+
case ZEND_JMPZ_EX:
case ZEND_JMPNZ_EX:
/* convert Ti = JMPZ_EX(Ti, L) to JMPZ(Ti, L) */
}
break;
}
- if ((opline+1)->opcode == ZEND_JMP) {
+ if ((opline + 1)->opcode == ZEND_JMP) {
/* JMPZ(X, L1), JMP(L2) => JMPZNZ(X, L1, L2) */
/* JMPNZ(X, L1), JMP(L2) => JMPZNZ(X, L2, L1) */
- if (ZEND_OP2(opline).opline_num == ZEND_OP1(opline+1).opline_num) {
+ if (ZEND_OP2(opline).opline_num == ZEND_OP1(opline + 1).opline_num) {
/* JMPZ(X, L1), JMP(L1) => NOP, JMP(L1) */
MAKE_NOP(opline);
} else {
if (opline->opcode == ZEND_JMPZ) {
- opline->extended_value = ZEND_OP1(opline+1).opline_num;
+ opline->extended_value = ZEND_OP1(opline + 1).opline_num;
} else {
opline->extended_value = ZEND_OP2(opline).opline_num;
- COPY_NODE(opline->op2, (opline+1)->op1);
+ COPY_NODE(opline->op2, (opline + 1)->op1);
}
opline->opcode = ZEND_JMPZNZ;
}
opline->opcode = ZEND_JMP;
}
break;
-
+
case ZEND_BRK:
case ZEND_CONT:
{
zend_brk_cont_element *jmp_to;
int array_offset;
int nest_levels;
- int dont_optimize=0;
+ int dont_optimize = 0;
if (ZEND_OP2_TYPE(opline) != IS_CONST) {
break;
array_offset = ZEND_OP1(opline).opline_num;
while (1) {
- if (array_offset==-1) {
- dont_optimize=1; /* don't optimize this bogus break/continue, let the executor shout */
+ if (array_offset == -1) {
+ dont_optimize = 1; /* don't optimize this bogus break/continue, let the executor shout */
break;
}
jmp_to = &op_array->brk_cont_array[array_offset];
if (opline->opcode == ZEND_BRK &&
(op_array->opcodes[jmp_to->brk].opcode == ZEND_FREE ||
op_array->opcodes[jmp_to->brk].opcode == ZEND_SWITCH_FREE)) {
- dont_optimize=1;
+ dont_optimize = 1;
break;
}
} else {
if (dont_optimize) {
break;
}
-
+
/* optimize - convert to a JMP */
switch (opline->opcode) {
case ZEND_BRK:
} \
jmp_hitlist[jmp_hitlist_count++] = ZEND_OP2(&op_array->opcodes[target]).opline_num;
-if(ZEND_OPTIMIZER_PASS_3 & OPTIMIZATION_LEVEL) {
+if (ZEND_OPTIMIZER_PASS_3 & OPTIMIZATION_LEVEL) {
zend_op *opline;
zend_op *end = op_array->opcodes+op_array->last;
zend_uint *jmp_hitlist;
zend_uint opline_num = 0;
ALLOCA_FLAG(use_heap);
- jmp_hitlist = (zend_uint *) DO_ALLOCA(sizeof(zend_uint)*op_array->last);
+ jmp_hitlist = (zend_uint *)DO_ALLOCA(sizeof(zend_uint)*op_array->last);
opline = op_array->opcodes;
- while (opline<end) {
+ while (opline < end) {
jmp_hitlist_count = 0;
switch (opline->opcode) {
case ZEND_BW_AND:
case ZEND_BW_XOR:
{
- zend_op *next_opline = opline+1;
+ zend_op *next_opline = opline + 1;
while (next_opline < end && next_opline->opcode == ZEND_NOP) {
++next_opline;
break;
}
- if ((ZEND_OP2_TYPE(opline)==IS_VAR || ZEND_OP2_TYPE(opline)==IS_CV)
+ if ((ZEND_OP2_TYPE(opline) == IS_VAR || ZEND_OP2_TYPE(opline) == IS_CV)
&& ZEND_OP2(opline).var == ZEND_OP1(next_opline).var &&
(opline->opcode == ZEND_ADD ||
opline->opcode == ZEND_MUL ||
* optimization works on it
*/
#if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
- zend_uchar tmp_type=opline->op1_type;
- znode_op tmp=opline->op1;
+ zend_uchar tmp_type = opline->op1_type;
+ znode_op tmp = opline->op1;
#else
- znode tmp=opline->op1;
+ znode tmp = opline->op1;
#endif
- if(opline->opcode != ZEND_ADD || ZEND_OP1_TYPE(opline) == IS_CONST) {
+ if (opline->opcode != ZEND_ADD || ZEND_OP1_TYPE(opline) == IS_CONST) {
/* protection from array add: $a = array + $a is not commutative! */
COPY_NODE(opline->op1, opline->op2);
COPY_NODE(opline->op2, tmp);
}
}
- if ((ZEND_OP1_TYPE(opline)==IS_VAR || ZEND_OP1_TYPE(opline)==IS_CV)
+ if ((ZEND_OP1_TYPE(opline) == IS_VAR || ZEND_OP1_TYPE(opline) == IS_CV)
&& ZEND_OP1(opline).var == ZEND_OP1(next_opline).var
&& ZEND_OP1_TYPE(opline) == ZEND_OP1_TYPE(next_opline)) {
switch (opline->opcode) {
#endif
/* convert L: JMP L+1 to NOP */
- if(ZEND_OP1(opline).opline_num == opline_num + 1) {
+ if (ZEND_OP1(opline).opline_num == opline_num + 1) {
MAKE_NOP(opline);
goto done_jmp_optimization;
}
/* convert JMP L1 ... L1: JMP L2 to JMP L2 .. L1: JMP L2 */
- while (ZEND_OP1(opline).opline_num<op_array->last
+ while (ZEND_OP1(opline).opline_num < op_array->last
&& op_array->opcodes[ZEND_OP1(opline).opline_num].opcode == ZEND_JMP) {
int target = ZEND_OP1(opline).opline_num;
CHECK_JMP(target, done_jmp_optimization);
}
#endif
- while (ZEND_OP2(opline).opline_num<op_array->last) {
+ while (ZEND_OP2(opline).opline_num < op_array->last) {
int target = ZEND_OP2(opline).opline_num;
if (op_array->opcodes[target].opcode == ZEND_JMP) {
ZEND_OP2(opline).opline_num = ZEND_OP1(&op_array->opcodes[target]).opline_num;
#endif
/* convert L: JMPZ L+1 to NOP */
- if(ZEND_OP2(opline).opline_num == opline_num + 1) {
+ if (ZEND_OP2(opline).opline_num == opline_num + 1) {
MAKE_NOP(opline);
goto done_jmp_optimization;
}
- while (ZEND_OP2(opline).opline_num<op_array->last) {
+ while (ZEND_OP2(opline).opline_num < op_array->last) {
int target = ZEND_OP2(opline).opline_num;
if (op_array->opcodes[target].opcode == ZEND_JMP) {
/* plain JMP */
/* JMPZ(X,L1), L1: JMP(L2) => JMPZ(X,L2), L1: JMP(L2) */
- CHECK_JMP(target, done_jmp_optimization);
+ CHECK_JMP(target, done_jmp_optimization);
ZEND_OP2(opline).opline_num = ZEND_OP1(&op_array->opcodes[target]).opline_num;
} else if (op_array->opcodes[target].opcode == opline->opcode &&
SAME_VAR(opline->op1, op_array->opcodes[target].op1)) {
/* same opcode and same var as this opcode */
/* JMPZ(X,L1), L1: JMPZ(X,L2) => JMPZ(X,L2), L1: JMPZ(X,L2) */
- CHECK_JMP2(target, done_jmp_optimization);
+ CHECK_JMP2(target, done_jmp_optimization);
ZEND_OP2(opline).opline_num = ZEND_OP2(&op_array->opcodes[target]).opline_num;
} else if (op_array->opcodes[target].opcode == opline->opcode+3 &&
SAME_VAR(opline->op1, op_array->opcodes[target].op1)) {
#endif
/* convert L: T = JMPZ_EX X,L+1 to T = BOOL(X) */
/* convert L: T = JMPZ_EX T,L+1 to NOP */
- if(ZEND_OP2(opline).opline_num == opline_num + 1) {
- if(ZEND_OP1(opline).var == ZEND_RESULT(opline).var) {
+ if (ZEND_OP2(opline).opline_num == opline_num + 1) {
+ if (ZEND_OP1(opline).var == ZEND_RESULT(opline).var) {
MAKE_NOP(opline);
} else {
opline->opcode = ZEND_BOOL;
goto done_jmp_optimization;
}
- while (ZEND_OP2(opline).opline_num<op_array->last) {
+ while (ZEND_OP2(opline).opline_num < op_array->last) {
int target = ZEND_OP2(opline).opline_num;
- if(SAME_OPCODE_EX(opline->opcode, op_array->opcodes[target].opcode) &&
- SAME_VAR(op_array->opcodes[target].op1, T)) {
+ if (SAME_OPCODE_EX(opline->opcode, op_array->opcodes[target].opcode) &&
+ SAME_VAR(op_array->opcodes[target].op1, T)) {
/* Check for JMPZ_EX to JMPZ[_EX] with the same condition, either with _EX or not */
- if(op_array->opcodes[target].opcode == opline->opcode) {
+ if (op_array->opcodes[target].opcode == opline->opcode) {
/* change T only if we have _EX opcode there */
COPY_NODE(T, op_array->opcodes[target].result);
}
CHECK_JMP2(target, continue_jmp_ex_optimization);
ZEND_OP2(opline).opline_num = ZEND_OP2(&op_array->opcodes[target]).opline_num;
- } else if(op_array->opcodes[target].opcode == ZEND_JMPZNZ &&
+ } else if (op_array->opcodes[target].opcode == ZEND_JMPZNZ &&
SAME_VAR(op_array->opcodes[target].op1, T)) {
/* Check for JMPZNZ with same cond variable */
int new_target;
CHECK_JMP2(target, continue_jmp_ex_optimization);
- if(opline->opcode == ZEND_JMPZ_EX) {
+ if (opline->opcode == ZEND_JMPZ_EX) {
new_target = ZEND_OP2(&op_array->opcodes[target]).opline_num;
} else {
/* JMPNZ_EX */
new_target = op_array->opcodes[target].extended_value;
}
ZEND_OP2(opline).opline_num = new_target;
- } else if((op_array->opcodes[target].opcode == INV_EX_COND_EX(opline->opcode) ||
- op_array->opcodes[target].opcode == INV_EX_COND(opline->opcode)
- ) &&
- SAME_VAR(opline->op1, op_array->opcodes[target].op1)) {
+ } else if ((op_array->opcodes[target].opcode == INV_EX_COND_EX(opline->opcode) ||
+ op_array->opcodes[target].opcode == INV_EX_COND(opline->opcode)) &&
+ SAME_VAR(opline->op1, op_array->opcodes[target].op1)) {
/* convert JMPZ_EX(X,L1), L1: JMPNZ_EX(X,L2) to
JMPZ_EX(X,L1+1) */
ZEND_OP2(opline).opline_num = target+1;
case ZEND_POST_INC:
case ZEND_POST_DEC: {
/* POST_INC, FREE => PRE_INC */
- zend_op *next_op = opline+1;
+ zend_op *next_op = opline + 1;
- if (next_op>=end) {
+ if (next_op >= end) {
break;
}
- if (next_op->opcode == ZEND_FREE
- && ZEND_OP1(next_op).var == ZEND_RESULT(opline).var) {
+ if (next_op->opcode == ZEND_FREE &&
+ ZEND_OP1(next_op).var == ZEND_RESULT(opline).var) {
MAKE_NOP(next_op);
switch (opline->opcode) {
case ZEND_POST_INC:
p = (Bucket *) ZCSG(interned_strings_top);
ZCSG(interned_strings_top) += ZEND_MM_ALIGNED_SIZE(sizeof(Bucket) + nKeyLength);
- p->arKey = (char*)(p+1);
+ p->arKey = (char*)(p + 1);
memcpy((char*)p->arKey, arKey, nKeyLength);
p->nKeyLength = nKeyLength;
p->h = h;
}
if (ce->name) {
- ce->name = accel_new_interned_string(ce->name, ce->name_length+1, 0 TSRMLS_CC);
+ ce->name = accel_new_interned_string(ce->name, ce->name_length + 1, 0 TSRMLS_CC);
}
q = ce->properties_info.pListHead;
}
if (info->name) {
- info->name = accel_new_interned_string(info->name, info->name_length+1, 0 TSRMLS_CC);
+ info->name = accel_new_interned_string(info->name, info->name_length + 1, 0 TSRMLS_CC);
}
q = q->pListNext;
#else
static const FLOCK_STRUCTURE(restart_in_progress, F_WRLCK, SEEK_SET, 2, 1);
- if (fcntl(lock_file, F_SETLK, &restart_in_progress)==-1) {
+ if (fcntl(lock_file, F_SETLK, &restart_in_progress) == -1) {
zend_accel_error(ACCEL_LOG_DEBUG, "RestartC(+1): %s (%d)", strerror(errno), errno);
}
#endif
static const FLOCK_STRUCTURE(restart_finished, F_UNLCK, SEEK_SET, 2, 1);
ZCSG(restart_in_progress) = 0;
- if (fcntl(lock_file, F_SETLK, &restart_finished)==-1) {
+ if (fcntl(lock_file, F_SETLK, &restart_finished) == -1) {
zend_accel_error(ACCEL_LOG_DEBUG, "RestartC(-1): %s (%d)", strerror(errno), errno);
}
#endif
static inline int accel_restart_is_active(TSRMLS_D)
{
- if(ZCSG(restart_in_progress)) {
+ if (ZCSG(restart_in_progress)) {
#ifndef ZEND_WIN32
FLOCK_STRUCTURE(restart_check, F_WRLCK, SEEK_SET, 2, 1);
#else
static const FLOCK_STRUCTURE(mem_usage_lock, F_RDLCK, SEEK_SET, 1, 1);
- if (fcntl(lock_file, F_SETLK, &mem_usage_lock)==-1) {
+ if (fcntl(lock_file, F_SETLK, &mem_usage_lock) == -1) {
zend_accel_error(ACCEL_LOG_DEBUG, "UpdateC(+1): %s (%d)", strerror(errno), errno);
}
#endif
#else
static const FLOCK_STRUCTURE(mem_usage_unlock, F_UNLCK, SEEK_SET, 1, 1);
- if (fcntl(lock_file, F_SETLK, &mem_usage_unlock)==-1) {
+ if (fcntl(lock_file, F_SETLK, &mem_usage_unlock) == -1) {
zend_accel_error(ACCEL_LOG_DEBUG, "UpdateC(-1): %s (%d)", strerror(errno), errno);
}
#endif
#else
static const FLOCK_STRUCTURE(mem_usage_unlock_all, F_UNLCK, SEEK_SET, 0, 0);
- if (fcntl(lock_file, F_SETLK, &mem_usage_unlock_all)==-1) {
+ if (fcntl(lock_file, F_SETLK, &mem_usage_unlock_all) == -1) {
zend_accel_error(ACCEL_LOG_DEBUG, "UnlockAll: %s (%d)", strerror(errno), errno);
}
#endif
if (ZCG(accel_directives).force_restart_timeout
&& ZCSG(force_restart_time)
- && time(NULL)>=ZCSG(force_restart_time)) {
+ && time(NULL) >= ZCSG(force_restart_time)) {
zend_accel_error(ACCEL_LOG_WARNING, "Forced restart at %d (after %d seconds), locked by %d", time(NULL), ZCG(accel_directives).force_restart_timeout, mem_usage_check.l_pid);
kill_all_lockers(&mem_usage_check);
php_stream_statbuf stream_statbuf;
int ret, er;
- if(!filename) {
+ if (!filename) {
return FAILURE;
}
wrapper = php_stream_locate_url_wrapper(filename, NULL, STREAM_LOCATE_WRAPPERS_ONLY TSRMLS_CC);
- if(!wrapper) {
-
+ if (!wrapper) {
return FAILURE;
}
- if(!wrapper->wops || !wrapper->wops->url_stat) {
-
+ if (!wrapper->wops || !wrapper->wops->url_stat) {
statbuf->st_mtime = 1;
return SUCCESS; /* anything other than 0 is considered to be a valid timestamp */
}
-
er = EG(error_reporting);
EG(error_reporting) = 0;
zend_try {
static FILETIME utc_base_ft;
WIN32_FILE_ATTRIBUTE_DATA fdata;
- if(!file_handle->opened_path) {
+ if (!file_handle->opened_path) {
return 0;
}
utc_base = (((unsigned __int64)utc_base_ft.dwHighDateTime) << 32) + utc_base_ft.dwLowDateTime;
}
- if(GetFileAttributesEx(file_handle->opened_path, GetFileExInfoStandard, &fdata) != 0) {
+ if (GetFileAttributesEx(file_handle->opened_path, GetFileExInfoStandard, &fdata) != 0) {
unsigned __int64 ftime;
if (CompareFileTime (&fdata.ftLastWriteTime, &utc_base_ft) < 0)
accel_time_t res;
res = zend_get_file_handle_timestamp_win(file_handle);
- if(res) {
+ if (res) {
return res;
}
#endif
switch (file_handle->type) {
case ZEND_HANDLE_FD:
- if (fstat(file_handle->handle.fd, &statbuf)==-1) {
+ if (fstat(file_handle->handle.fd, &statbuf) == -1) {
return 0;
}
break;
{
char *file_path = file_handle->opened_path;
- if(file_path) {
+ if (file_path) {
if (is_stream_path(file_path)) {
if (zend_get_stream_timestamp(file_path, &statbuf TSRMLS_CC) == SUCCESS) {
break;
}
}
- if (VCWD_STAT(file_path, &statbuf) !=-1) {
+ if (VCWD_STAT(file_path, &statbuf) != -1) {
break;
}
}
* See bug #15140
*/
if (file_handle->opened_path) {
- if (strcmp(persistent_script->full_path,file_handle->opened_path)!=0) {
+ if (strcmp(persistent_script->full_path, file_handle->opened_path) != 0) {
return FAILURE;
}
} else {
- char actualpath [MAXPATHLEN+1];
+ char actualpath [MAXPATHLEN + 1];
char *full_path_ptr;
full_path_ptr = VCWD_REALPATH(file_handle->filename, actualpath);
- if (full_path_ptr && strcmp(persistent_script->full_path,full_path_ptr)!=0) {
+ if (full_path_ptr && strcmp(persistent_script->full_path, full_path_ptr) != 0) {
return FAILURE;
}
}
if (ZCG(accel_directives).revalidate_freq &&
(persistent_script->dynamic_members.revalidate >= ZCSG(revalidate_at))) {
return SUCCESS;
- } else if (do_validate_timestamps(persistent_script, file_handle TSRMLS_CC)==FAILURE) {
+ } else if (do_validate_timestamps(persistent_script, file_handle TSRMLS_CC) == FAILURE) {
return FAILURE;
} else {
persistent_script->dynamic_members.revalidate = ZCSG(revalidate_at);
if (ZCG(accel_directives).use_cwd &&
!IS_ABSOLUTE_PATH(file_handle->filename, path_length) &&
!is_stream_path(file_handle->filename)) {
- char *include_path=NULL;
- int include_path_len=0;
+ char *include_path = NULL;
+ int include_path_len = 0;
const char *parent_script = NULL;
- int parent_script_len=0;
- int cur_len=0;
+ int parent_script_len = 0;
+ int cur_len = 0;
int cwd_len;
char *cwd;
if ((cwd = accel_getcwd(&cwd_len TSRMLS_CC)) == NULL) {
/* we don't handle this well for now. */
zend_accel_error(ACCEL_LOG_INFO, "getcwd() failed for '%s' (%d), please try to set zend_optimizerplus.use_cwd to 0 in ini file", file_handle->filename, errno);
- if(file_handle->opened_path) {
+ if (file_handle->opened_path) {
cwd = file_handle->opened_path;
cwd_len = strlen(cwd);
} else {
}
/* Calculate key length */
- key_length = cwd_len+path_length+include_path_len+2;
+ key_length = cwd_len + path_length+include_path_len + 2;
if (parent_script_len) {
- key_length += parent_script_len+1;
+ key_length += parent_script_len + 1;
}
/* Generate key
memcpy(ZCG(key), cwd, cwd_len);
ZCG(key)[cwd_len] = ':';
- memcpy(ZCG(key)+cwd_len+1, file_handle->filename, path_length);
+ memcpy(ZCG(key) + cwd_len + 1, file_handle->filename, path_length);
- ZCG(key)[cwd_len+1+path_length] = ':';
+ ZCG(key)[cwd_len + 1 + path_length] = ':';
- cur_len = cwd_len+1+path_length+1;
+ cur_len = cwd_len + 1 + path_length + 1;
if (parent_script_len) {
- memcpy(ZCG(key)+cur_len, parent_script, parent_script_len);
+ memcpy(ZCG(key) + cur_len, parent_script, parent_script_len);
cur_len += parent_script_len;
ZCG(key)[cur_len] = ':';
cur_len++;
}
- memcpy(ZCG(key)+cur_len, include_path, include_path_len);
+ memcpy(ZCG(key) + cur_len, include_path, include_path_len);
ZCG(key)[key_length] = '\0';
} else {
/* not use_cwd */
ZCG(key_len) = 0;
return NULL;
}
- memcpy(ZCG(key), file_handle->filename, key_length+1);
+ memcpy(ZCG(key), file_handle->filename, key_length + 1);
}
*key_len = ZCG(key_len) = key_length;
/* Adds another key for existing cached script */
static void zend_accel_add_key(char *key, unsigned int key_length, zend_accel_hash_entry *bucket TSRMLS_DC)
{
- if (!zend_accel_hash_find(&ZCSG(hash), key, key_length+1)) {
+ if (!zend_accel_hash_find(&ZCSG(hash), key, key_length + 1)) {
if (zend_accel_hash_is_full(&ZCSG(hash))) {
- zend_accel_error(ACCEL_LOG_DEBUG,"No more entries in hash table!");
+ zend_accel_error(ACCEL_LOG_DEBUG, "No more entries in hash table!");
ZSMMG(memory_exhausted) = 1;
} else {
- char *new_key = zend_shared_alloc(key_length+1);
+ char *new_key = zend_shared_alloc(key_length + 1);
if (new_key) {
- memcpy(new_key, key, key_length+1);
- zend_accel_hash_update(&ZCSG(hash), new_key, key_length+1, 1, bucket);
+ memcpy(new_key, key, key_length + 1);
+ zend_accel_hash_update(&ZCSG(hash), new_key, key_length + 1, 1, bucket);
} else {
- zend_accel_error(ACCEL_LOG_DEBUG,"No more memory!");
+ zend_accel_error(ACCEL_LOG_DEBUG, "No more memory!");
ZSMMG(memory_exhausted) = 1;
}
}
uint memory_used;
/* Check if script may be stored in shared memory */
- if(!zend_accel_script_persistable(new_persistent_script)) {
+ if (!zend_accel_script_persistable(new_persistent_script)) {
return new_persistent_script;
}
zend_shared_alloc_lock(TSRMLS_C);
if (zend_accel_hash_is_full(&ZCSG(hash))) {
- zend_accel_error(ACCEL_LOG_DEBUG,"No more entries in hash table!");
+ zend_accel_error(ACCEL_LOG_DEBUG, "No more entries in hash table!");
ZSMMG(memory_exhausted) = 1;
zend_accel_schedule_restart_if_necessary(TSRMLS_C);
zend_shared_alloc_unlock(TSRMLS_C);
/* Check if we still need to put the file into the cache (may be it was
* already stored by another process. This final check is done under
* exclusive lock) */
- bucket = zend_accel_hash_find_entry(&ZCSG(hash), new_persistent_script->full_path, new_persistent_script->full_path_len+1);
+ bucket = zend_accel_hash_find_entry(&ZCSG(hash), new_persistent_script->full_path, new_persistent_script->full_path_len + 1);
if (bucket) {
zend_persistent_script *existing_persistent_script = (zend_persistent_script *)bucket->data;
new_persistent_script->dynamic_members.checksum = zend_accel_script_checksum(new_persistent_script);
/* store script structure in the hash table */
- bucket = zend_accel_hash_update(&ZCSG(hash), new_persistent_script->full_path, new_persistent_script->full_path_len+1, 0, new_persistent_script);
+ bucket = zend_accel_hash_update(&ZCSG(hash), new_persistent_script->full_path, new_persistent_script->full_path_len + 1, 0, new_persistent_script);
if (bucket &&
(new_persistent_script->full_path_len != key_length ||
memcmp(new_persistent_script->full_path, key, key_length) != 0)) {
/* link key to the same persistent script in hash table */
- if (!zend_accel_hash_update(&ZCSG(hash), key, key_length+1, 1, bucket)) {
- zend_accel_error(ACCEL_LOG_DEBUG,"No more entries in hash table!");
+ if (!zend_accel_hash_update(&ZCSG(hash), key, key_length + 1, 1, bucket)) {
+ zend_accel_error(ACCEL_LOG_DEBUG, "No more entries in hash table!");
ZSMMG(memory_exhausted) = 1;
}
}
}
} else {
*op_array_p = NULL;
- if (type==ZEND_REQUIRE) {
+ if (type == ZEND_REQUIRE) {
zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename TSRMLS_CC);
zend_bailout();
} else {
/* compilation failed */
free_persistent_script(new_persistent_script, 1);
zend_accel_free_user_functions(&ZCG(function_table) TSRMLS_CC);
- if(do_bailout) {
+ if (do_bailout) {
zend_bailout();
}
return NULL;
if ((key = accel_make_persistent_key(file_handle, &key_length TSRMLS_CC)) == NULL) {
return accelerator_orig_compile_file(file_handle, type TSRMLS_CC);
}
- persistent_script = zend_accel_hash_find(&ZCSG(hash), key, key_length+1);
+ persistent_script = zend_accel_hash_find(&ZCSG(hash), key, key_length + 1);
if (!persistent_script) {
/* try to find cached script by full real path */
zend_accel_hash_entry *bucket;
#else
zend_stream_open(file_handle->filename, file_handle TSRMLS_CC) == FAILURE) {
#endif
- if (type==ZEND_REQUIRE) {
+ if (type == ZEND_REQUIRE) {
zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename TSRMLS_CC);
zend_bailout();
} else {
}
if (file_handle->opened_path &&
- (bucket = zend_accel_hash_find_entry(&ZCSG(hash), file_handle->opened_path, strlen(file_handle->opened_path)+1)) != NULL) {
+ (bucket = zend_accel_hash_find_entry(&ZCSG(hash), file_handle->opened_path, strlen(file_handle->opened_path) + 1)) != NULL) {
persistent_script = (zend_persistent_script *)bucket->data;
if (!ZCG(accel_directives).revalidate_path &&
/* If script is found then validate_timestamps if option is enabled */
if (persistent_script && ZCG(accel_directives).validate_timestamps) {
- if (validate_timestamp_and_record(persistent_script, file_handle TSRMLS_CC)==FAILURE) {
+ if (validate_timestamp_and_record(persistent_script, file_handle TSRMLS_CC) == FAILURE) {
zend_shared_alloc_lock(TSRMLS_C);
if (!persistent_script->corrupted) {
persistent_script->corrupted = 1;
#endif
void *dummy = (void *) 1;
- zend_hash_quick_add(&EG(included_files), persistent_script->full_path, persistent_script->full_path_len+1, persistent_script->hash_value, &dummy, sizeof(void *), NULL);
+ zend_hash_quick_add(&EG(included_files), persistent_script->full_path, persistent_script->full_path_len + 1, persistent_script->hash_value, &dummy, sizeof(void *), NULL);
}
}
zend_file_handle_dtor(file_handle TSRMLS_CC);
return NULL;
}
- real_path = emalloc(new_state.cwd_length+1);
- memcpy(real_path, new_state.cwd, new_state.cwd_length+1);
+ real_path = emalloc(new_state.cwd_length + 1);
+ memcpy(real_path, new_state.cwd, new_state.cwd_length + 1);
free(new_state.cwd);
return real_path;
}
ptr = path;
while (*ptr) {
for (end = ptr; *end && *end != DEFAULT_DIR_SEPARATOR; end++);
- len = end-ptr;
+ len = end - ptr;
if (*end) end++;
if (len + 1 + filename_length + 1 >= MAXPATHLEN) {
ptr = end;
}
memcpy(trypath, ptr, len);
trypath[len] = '/';
- memcpy(trypath+len+1, filename, filename_length+1);
+ memcpy(trypath + len + 1, filename, filename_length + 1);
ptr = end;
- if ((resolved_path = accel_tsrm_realpath(trypath, len+1+filename_length TSRMLS_CC)) != NULL) {
+ if ((resolved_path = accel_tsrm_realpath(trypath, len + 1 + filename_length TSRMLS_CC)) != NULL) {
return resolved_path;
}
} /* end provided path */
exec_fname_length > 0 &&
exec_fname_length + 1 + filename_length + 1 < MAXPATHLEN) {
memcpy(trypath, exec_fname, exec_fname_length + 1);
- memcpy(trypath+exec_fname_length + 1, filename, filename_length+1);
- return accel_tsrm_realpath(trypath, exec_fname_length+1+filename_length TSRMLS_CC);
+ memcpy(trypath + exec_fname_length + 1, filename, filename_length + 1);
+ return accel_tsrm_realpath(trypath, exec_fname_length + 1 + filename_length TSRMLS_CC);
}
}
/* Check if requestd file already cached (by full name) */
if (IS_ABSOLUTE_PATH(filename, filename_len) &&
- (persistent_script = zend_accel_hash_find(&ZCSG(hash), (char*)filename, filename_len+1)) != NULL &&
+ (persistent_script = zend_accel_hash_find(&ZCSG(hash), (char*)filename, filename_len + 1)) != NULL &&
!persistent_script->corrupted) {
handle->opened_path = estrndup(persistent_script->full_path, persistent_script->full_path_len);
handle->type = ZEND_HANDLE_FILENAME;
- memcpy(ZCG(key), persistent_script->full_path, persistent_script->full_path_len+1);
+ memcpy(ZCG(key), persistent_script->full_path, persistent_script->full_path_len + 1);
ZCG(key_len) = persistent_script->full_path_len;
ZCG(cache_opline) = opline;
ZCG(cache_persistent_script) = persistent_script;
key = accel_make_persistent_key_ex(handle, filename_len, &key_length TSRMLS_CC);
if (!ZCG(accel_directives).revalidate_path &&
key &&
- (persistent_script = zend_accel_hash_find(&ZCSG(hash), key, key_length+1)) != NULL &&
+ (persistent_script = zend_accel_hash_find(&ZCSG(hash), key, key_length + 1)) != NULL &&
!persistent_script->corrupted) {
handle->opened_path = estrndup(persistent_script->full_path, persistent_script->full_path_len);
/* Check if requestd file already cached (by real name) */
if (resolved_path &&
- (bucket = zend_accel_hash_find_entry(&ZCSG(hash), resolved_path, strlen(resolved_path)+1)) != NULL) {
+ (bucket = zend_accel_hash_find_entry(&ZCSG(hash), resolved_path, strlen(resolved_path) + 1)) != NULL) {
persistent_script = (zend_persistent_script *)bucket->data;
if (persistent_script && !persistent_script->corrupted) {
if ((IS_ABSOLUTE_PATH(filename, filename_len) ||
is_stream_path(filename)) &&
- (persistent_script = zend_accel_hash_find(&ZCSG(hash), (char*)filename, filename_len+1)) != NULL &&
+ (persistent_script = zend_accel_hash_find(&ZCSG(hash), (char*)filename, filename_len + 1)) != NULL &&
!persistent_script->corrupted) {
handle->opened_path = estrndup(persistent_script->full_path, persistent_script->full_path_len);
handle->type = ZEND_HANDLE_FILENAME;
- memcpy(ZCG(key), persistent_script->full_path, persistent_script->full_path_len+1);
+ memcpy(ZCG(key), persistent_script->full_path, persistent_script->full_path_len + 1);
ZCG(key_len) = persistent_script->full_path_len;
ZCG(cache_opline) = EG(opline_ptr) ? *EG(opline_ptr) : NULL;
ZCG(cache_persistent_script) = EG(opline_ptr) ? persistent_script : NULL;
char *resolved_path;
zend_accel_hash_entry *bucket;
zend_persistent_script *persistent_script;
-
+
/* Check if requestd file already cached (by full name) */
if ((IS_ABSOLUTE_PATH(filename, filename_len) ||
is_stream_path(filename)) &&
- (bucket = zend_accel_hash_find_entry(&ZCSG(hash), (char*)filename, filename_len+1)) != NULL) {
+ (bucket = zend_accel_hash_find_entry(&ZCSG(hash), (char*)filename, filename_len + 1)) != NULL) {
persistent_script = (zend_persistent_script *)bucket->data;
if (persistent_script && !persistent_script->corrupted) {
- memcpy(ZCG(key), persistent_script->full_path, persistent_script->full_path_len+1);
+ memcpy(ZCG(key), persistent_script->full_path, persistent_script->full_path_len + 1);
ZCG(key_len) = persistent_script->full_path_len;
ZCG(cache_opline) = EG(opline_ptr) ? *EG(opline_ptr) : NULL;
ZCG(cache_persistent_script) = persistent_script;
key = accel_make_persistent_key_ex(&handle, filename_len, &key_length TSRMLS_CC);
if (!ZCG(accel_directives).revalidate_path &&
key &&
- (persistent_script = zend_accel_hash_find(&ZCSG(hash), key, key_length+1)) != NULL &&
+ (persistent_script = zend_accel_hash_find(&ZCSG(hash), key, key_length + 1)) != NULL &&
!persistent_script->corrupted) {
/* we have persistent script */
/* Check if requestd file already cached (by real path) */
if (resolved_path &&
- (bucket = zend_accel_hash_find_entry(&ZCSG(hash), resolved_path, strlen(resolved_path)+1)) != NULL) {
+ (bucket = zend_accel_hash_find_entry(&ZCSG(hash), resolved_path, strlen(resolved_path) + 1)) != NULL) {
persistent_script = (zend_persistent_script *)bucket->data;
if (persistent_script && !persistent_script->corrupted) {
}
/* check if ZCG(function_table) wasn't somehow polluted on the way */
- if(ZCG(internal_functions_count) != zend_hash_num_elements(&ZCG(function_table))) {
+ if (ZCG(internal_functions_count) != zend_hash_num_elements(&ZCG(function_table))) {
zend_accel_error(ACCEL_LOG_WARNING, "Internal functions count changed - was %d, now %d", ZCG(internal_functions_count), zend_hash_num_elements(&ZCG(function_table)));
}
{
zval *zvalue = *zval_ptr;
- if (Z_DELREF_P(zvalue)==0) {
+ if (Z_DELREF_P(zvalue) == 0) {
#if ZEND_EXTENSION_API_NO >= PHP_5_3_X_API_NO
switch (Z_TYPE_P(zvalue) & IS_CONSTANT_TYPE_MASK) {
#else
const char **sapi_name;
if (sapi_module.name) {
- for (sapi_name=supported_sapis; *sapi_name; sapi_name++) {
- if (strcmp(sapi_module.name, *sapi_name)==0) {
+ for (sapi_name = supported_sapis; *sapi_name; sapi_name++) {
+ if (strcmp(sapi_module.name, *sapi_name) == 0) {
return SUCCESS;
}
}
if (ZCG(accel_directives).enable_cli &&
- strcmp(sapi_module.name, "cli")==0) {
+ strcmp(sapi_module.name, "cli") == 0) {
return SUCCESS;
}
}
}
/* no supported SAPI found - disable acceleration and stop initalization */
- if( accel_find_sapi(TSRMLS_C) == FAILURE ){
+ if (accel_find_sapi(TSRMLS_C) == FAILURE) {
accel_startup_ok = 0;
if (!ZCG(accel_directives).enable_cli &&
- strcmp(sapi_module.name, "cli")==0) {
+ strcmp(sapi_module.name, "cli") == 0) {
zps_startup_failure("Opcode Caching is disabled for CLI", NULL, accelerator_remove_cb TSRMLS_CC);
} else {
zps_startup_failure("Opcode Caching is only supported in Apache, ISAPI, FPM and FastCGI SAPIs", NULL, accelerator_remove_cb TSRMLS_CC);
break;
case ALLOC_FAILURE:
accel_startup_ok = 0;
- zend_accel_error(ACCEL_LOG_FATAL,"Failure to initialize shared memory structures - probably not enough shared memory.");
+ zend_accel_error(ACCEL_LOG_FATAL, "Failure to initialize shared memory structures - probably not enough shared memory.");
return SUCCESS;
case SUCCESSFULLY_REATTACHED:
accel_shared_globals = (zend_accel_shared_globals *) ZSMMG(app_shared_globals);
break;
case FAILED_REATTACHED:
accel_startup_ok = 0;
- zend_accel_error(ACCEL_LOG_FATAL,"Failure to initialize shared memory structures - can not reattach to exiting shared memory.");
+ zend_accel_error(ACCEL_LOG_FATAL, "Failure to initialize shared memory structures - can not reattach to exiting shared memory.");
return SUCCESS;
break;
}
zend_resolve_path = persistent_zend_resolve_path;
#endif
- if(ZCG(accel_directives).validate_timestamps) {
+ if (ZCG(accel_directives).validate_timestamps) {
ZCSG(revalidate_at) = zend_accel_get_time() + ZCG(accel_directives).revalidate_freq;
}
ZCG(cwd) = NULL;
/* Override "include_path" modifier callback */
- if (zend_hash_find(EG(ini_directives), "include_path", sizeof("include_path"), (void **) &ini_entry)==SUCCESS) {
+ if (zend_hash_find(EG(ini_directives), "include_path", sizeof("include_path"), (void **) &ini_entry) == SUCCESS) {
ZCG(include_path) = INI_STR("include_path");
ZCG(include_path_key) = NULL;
if (ZCG(include_path) && *ZCG(include_path)) {
zend_shared_alloc_shutdown();
zend_compile_file = accelerator_orig_compile_file;
- if (zend_hash_find(EG(ini_directives), "include_path", sizeof("include_path"), (void **) &ini_entry)==SUCCESS) {
+ if (zend_hash_find(EG(ini_directives), "include_path", sizeof("include_path"), (void **) &ini_entry) == SUCCESS) {
ini_entry->on_modify = orig_include_path_on_modify;
}
*/
int accelerator_shm_read_lock(TSRMLS_D)
{
- if(ZCG(counted)) {
+ if (ZCG(counted)) {
/* counted means we are holding read lock for SHM, so that nothing bad can happen */
return SUCCESS;
} else {
or is in progress now */
accel_activate_add(TSRMLS_C); /* acquire usage lock */
/* Now if we weren't inside restart, restart would not begin until we remove usage lock */
- if(ZCSG(restart_in_progress)) {
+ if (ZCSG(restart_in_progress)) {
/* we already were inside restart this means it's not safe to touch shm */
accel_deactivate_now(); /* drop usage lock */
return FAILURE;
/* must be called ONLY after SUCCESSFUL accelerator_shm_read_lock */
void accelerator_shm_read_unlock(TSRMLS_D)
{
- if(!ZCG(counted)) {
+ if (!ZCG(counted)) {
/* counted is 0 - meaning we had to readlock manually, release readlock now */
accel_deactivate_now();
}
zend_shared_segment *shared_segment;
*shared_segments_count = 1;
- *shared_segments_p = (zend_shared_segment **) calloc(1, sizeof(zend_shared_segment)+sizeof(void *));
+ *shared_segments_p = (zend_shared_segment **) calloc(1, sizeof(zend_shared_segment) + sizeof(void *));
shared_segment = (zend_shared_segment *)((char *)(*shared_segments_p) + sizeof(void *));
(*shared_segments_p)[0] = shared_segment;
shared_segment->p = mmap(0, requested_size, PROT_READ | PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
- if(shared_segment->p == MAP_FAILED) {
+ if (shared_segment->p == MAP_FAILED) {
*error_in = "mmap";
return ALLOC_FAILURE;
}
static int create_segments(size_t requested_size, zend_shared_segment_posix ***shared_segments_p, int *shared_segments_count, char **error_in)
{
zend_shared_segment_posix *shared_segment;
- char shared_segment_name[sizeof("/ZendAccelerator.")+20];
+ char shared_segment_name[sizeof("/ZendAccelerator.") + 20];
*shared_segments_count = 1;
- *shared_segments_p = (zend_shared_segment_posix **) calloc(1, sizeof(zend_shared_segment_posix)+sizeof(void *));
+ *shared_segments_p = (zend_shared_segment_posix **) calloc(1, sizeof(zend_shared_segment_posix) + sizeof(void *));
shared_segment = (zend_shared_segment_posix *)((char *)(*shared_segments_p) + sizeof(void *));
(*shared_segments_p)[0] = shared_segment;
sprintf(shared_segment_name, "/ZendAccelerator.%d", getpid());
shared_segment->shm_fd = shm_open(shared_segment_name, O_RDWR|O_CREAT|O_TRUNC, 0600);
- if(shared_segment->shm_fd == -1) {
+ if (shared_segment->shm_fd == -1) {
*error_in = "shm_open";
return ALLOC_FAILURE;
}
- if(ftruncate(shared_segment->shm_fd, requested_size) != 0) {
+ if (ftruncate(shared_segment->shm_fd, requested_size) != 0) {
*error_in = "ftruncate";
shm_unlink(shared_segment_name);
return ALLOC_FAILURE;
}
shared_segment->common.p = mmap(0, requested_size, PROT_READ | PROT_WRITE, MAP_SHARED, shared_segment->shm_fd, 0);
- if(shared_segment->common.p == MAP_FAILED) {
+ if (shared_segment->common.p == MAP_FAILED) {
*error_in = "mmap";
shm_unlink(shared_segment_name);
return ALLOC_FAILURE;
static int create_segments(size_t requested_size, zend_shared_segment_shm ***shared_segments_p, int *shared_segments_count, char **error_in)
{
int i;
- unsigned int allocate_size=0, remaining_bytes=requested_size, seg_allocate_size;
- int first_segment_id=-1;
+ unsigned int allocate_size = 0, remaining_bytes = requested_size, seg_allocate_size;
+ int first_segment_id = -1;
key_t first_segment_key = -1;
struct shmid_ds sds;
int shmget_flags;
/* determine segment size we _really_ need:
* no more than to include requested_size
*/
- while (requested_size*2 <= seg_allocate_size && seg_allocate_size > SEG_ALLOC_SIZE_MIN) {
+ while (requested_size * 2 <= seg_allocate_size && seg_allocate_size > SEG_ALLOC_SIZE_MIN) {
seg_allocate_size >>= 1;
}
return ALLOC_FAILURE;
}
- *shared_segments_count = ((requested_size-1)/seg_allocate_size) + 1;
- *shared_segments_p = (zend_shared_segment_shm **) calloc(1, (*shared_segments_count)*sizeof(zend_shared_segment_shm)+sizeof(void *)*(*shared_segments_count));
- shared_segments = (zend_shared_segment_shm *)((char *)(*shared_segments_p) + sizeof(void *)*(*shared_segments_count));
- for(i=0; i<*shared_segments_count; i++) {
- (*shared_segments_p)[i] = shared_segments+i;
+ *shared_segments_count = ((requested_size - 1) / seg_allocate_size) + 1;
+ *shared_segments_p = (zend_shared_segment_shm **) calloc(1, (*shared_segments_count) * sizeof(zend_shared_segment_shm) + sizeof(void *) * (*shared_segments_count));
+ shared_segments = (zend_shared_segment_shm *)((char *)(*shared_segments_p) + sizeof(void *) * (*shared_segments_count));
+ for (i = 0; i < *shared_segments_count; i++) {
+ (*shared_segments_p)[i] = shared_segments + i;
}
remaining_bytes = requested_size;
- for (i=0; i<*shared_segments_count; i++) {
+ for (i = 0; i < *shared_segments_count; i++) {
allocate_size = MIN(remaining_bytes, seg_allocate_size);
if (i != 0) {
shared_segments[i].shm_id = shmget(IPC_PRIVATE, allocate_size, shmget_flags);
shared_segments[i].shm_id = first_segment_id;
}
- if (shared_segments[i].shm_id==-1) {
+ if (shared_segments[i].shm_id == -1) {
return ALLOC_FAILURE;
}
{
DWORD waitRes = WaitForSingleObject(memory_mutex, INFINITE);
- if(waitRes == WAIT_FAILED) {
+ if (waitRes == WAIT_FAILED) {
zend_accel_error(ACCEL_LOG_ERROR, "Cannot lock mutex");
}
}
MEMORY_BASIC_INFORMATION info;
err = GetLastError();
- if(!fp) {
+ if (!fp) {
zend_win_error_message(ACCEL_LOG_WARNING, mmap_base_file, err);
zend_win_error_message(ACCEL_LOG_FATAL, "Unable to open base address file", err);
*error_in="fopen";
return ALLOC_FAILURE;
}
- if(!fscanf(fp, "%p", &wanted_mapping_base)) {
+ if (!fscanf(fp, "%p", &wanted_mapping_base)) {
err = GetLastError();
zend_win_error_message(ACCEL_LOG_FATAL, "Unable to read base address", err);
*error_in="read mapping base";
mapping_base = MapViewOfFileEx(memfile, FILE_MAP_ALL_ACCESS, 0, 0, 0, wanted_mapping_base);
err = GetLastError();
- if(mapping_base == NULL) {
+ if (mapping_base == NULL) {
if (err == ERROR_INVALID_ADDRESS) {
zend_win_error_message(ACCEL_LOG_FATAL, "Unable to reattach to base address", err);
return ALLOC_FAILURE;
} else {
return ret;
}
- } while(++map_retries < MAX_MAP_RETRIES);
+ } while (++map_retries < MAX_MAP_RETRIES);
- if(map_retries == MAX_MAP_RETRIES) {
+ if (map_retries == MAX_MAP_RETRIES) {
zend_win_error_message(ACCEL_LOG_FATAL, "Unable to open file mapping", err);
*error_in = "OpenFileMapping";
return ALLOC_FAILURE;
memfile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, requested_size,
create_name_with_username(ACCEL_FILEMAP_NAME));
err = GetLastError();
- if(memfile == NULL) {
+ if (memfile == NULL) {
zend_win_error_message(ACCEL_LOG_FATAL, "Unable to create file mapping", err);
*error_in = "CreateFileMapping";
return ALLOC_FAILURE;
GetSystemInfo(&si);
/* Are we running Vista ? */
- if(osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && osvi.dwMajorVersion == 6 ) {
+ if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && osvi.dwMajorVersion == 6) {
/* Assert that platform is 32 bit (for 64 bit we need to test a different set */
- if(si.wProcessorArchitecture != PROCESSOR_ARCHITECTURE_INTEL)
+ if (si.wProcessorArchitecture != PROCESSOR_ARCHITECTURE_INTEL)
DebugBreak();
wanted_mapping_base = vista_mapping_base_set;
do {
shared_segment->p = mapping_base = MapViewOfFileEx(memfile, FILE_MAP_ALL_ACCESS, 0, 0, 0, *wanted_mapping_base);
- if(*wanted_mapping_base == NULL) /* Auto address (NULL) is the last option on the array */
+ if (*wanted_mapping_base == NULL) /* Auto address (NULL) is the last option on the array */
break;
wanted_mapping_base++;
} while (!mapping_base);
err = GetLastError();
- if(mapping_base == NULL) {
+ if (mapping_base == NULL) {
zend_win_error_message(ACCEL_LOG_FATAL, "Unable to create view for file mapping", err);
*error_in = "MapViewOfFile";
return ALLOC_FAILURE;
char *mmap_base_file = get_mmap_base_file();
FILE *fp = fopen(mmap_base_file, "w");
err = GetLastError();
- if(!fp) {
+ if (!fp) {
zend_win_error_message(ACCEL_LOG_WARNING, mmap_base_file, err);
zend_win_error_message(ACCEL_LOG_FATAL, "Unable to write base address", err);
return ALLOC_FAILURE;
static int detach_segment(zend_shared_segment *shared_segment)
{
- if(mapping_base) {
+ if (mapping_base) {
UnmapViewOfFile(mapping_base);
}
CloseHandle(memfile);
blacklist->pos = 0;
blacklist->size = ZEND_BLACKLIST_BLOCK_SIZE;
- if( blacklist->entries != NULL ){
+ if (blacklist->entries != NULL) {
zend_accel_blacklist_shutdown(blacklist);
}
static void zend_accel_blacklist_update_regexp(zend_blacklist *blacklist)
{
- int i, end=0, j, rlen=6, clen, reg_err;
char *regexp;
+ int i, j, clen, reg_err, end = 0, rlen = 6;
zend_regexp_list **regexp_list_it, *it;
if (blacklist->pos == 0) {
}
regexp_list_it = &(blacklist->regexp_list);
- for (i=0; i<blacklist->pos; i++) {
- rlen += blacklist->entries[i].path_length*2+2;
+ for (i = 0; i < blacklist->pos; i++) {
+ rlen += blacklist->entries[i].path_length * 2 + 2;
/* don't create a regexp buffer bigger than 12K)*/
- if((i+1 == blacklist->pos) || ((rlen+blacklist->entries[i+1].path_length*2+2)>(12*1024) ) ) {
+ if ((i + 1 == blacklist->pos) || ((rlen + blacklist->entries[i + 1].path_length * 2 + 2) > (12 * 1024))) {
regexp = (char *)malloc(rlen);
if (!regexp) {
zend_accel_error(ACCEL_LOG_ERROR, "malloc() failed\n");
regexp[0] = '^';
regexp[1] = '(';
- clen=2;
- for (j=end; j<=i ;j++) {
+ clen = 2;
+ for (j = end; j <= i ;j++) {
int c;
- if (j!=end) {
+ if (j != end) {
regexp[clen++] = '|';
}
/* copy mangled filename */
- for(c=0; c<blacklist->entries[j].path_length; c++) {
- if(strchr("^.[]$()|*+?{}\\", blacklist->entries[j].path[c])) {
+ for (c = 0; c < blacklist->entries[j].path_length; c++) {
+ if (strchr("^.[]$()|*+?{}\\", blacklist->entries[j].path[c])) {
regexp[clen++] = '\\';
}
regexp[clen++] = blacklist->entries[j].path[c];
}
/* prepare for the next iteration */
free(regexp);
- end = i+1;
+ end = i + 1;
rlen = 6;
*regexp_list_it = it;
regexp_list_it = &it->next;
blacklist->entries = NULL;
if (blacklist->regexp_list) {
zend_regexp_list *temp, *it = blacklist->regexp_list;
- while( it ){
+ while (it) {
regfree(&it->comp_regex);
temp = it;
it = it->next;
static inline void zend_accel_blacklist_allocate(zend_blacklist *blacklist)
{
- if (blacklist->pos==blacklist->size) {
+ if (blacklist->pos == blacklist->size) {
blacklist->size += ZEND_BLACKLIST_BLOCK_SIZE;
blacklist->entries = (zend_blacklist_entry *) realloc(blacklist->entries, sizeof(zend_blacklist_entry)*blacklist->size);
}
void zend_accel_blacklist_load(zend_blacklist *blacklist, char *filename)
{
- char buf[MAXPATHLEN+1], real_path[MAXPATHLEN+1];
+ char buf[MAXPATHLEN + 1], real_path[MAXPATHLEN + 1];
FILE *fp;
int path_length;
TSRMLS_FETCH();
- if ((fp=fopen(filename, "r"))==NULL) {
+ if ((fp = fopen(filename, "r")) == NULL) {
zend_accel_error(ACCEL_LOG_WARNING, "Cannot load blacklist file: %s\n", filename);
return;
}
memset(buf, 0, sizeof(buf));
memset(real_path, 0, sizeof(real_path));
- while (fgets(buf, MAXPATHLEN, fp)!=NULL) {
+ while (fgets(buf, MAXPATHLEN, fp) != NULL) {
char *path_dup, *pbuf;
path_length = strlen(buf);
- if (path_length > 0 && buf[path_length-1]=='\n') {
+ if (path_length > 0 && buf[path_length - 1] == '\n') {
buf[--path_length] = 0;
- if (path_length > 0 && buf[path_length-1]=='\r') {
+ if (path_length > 0 && buf[path_length - 1] == '\r') {
buf[--path_length] = 0;
}
}
/* Strip ctrl-m prefix */
pbuf = &buf[0];
- while(*pbuf == '\r') {
+ while (*pbuf == '\r') {
*pbuf++ = 0;
path_length--;
}
/* strip \" */
- if( pbuf[0] == '\"' && pbuf[path_length-1]== '\"' ){
+ if (pbuf[0] == '\"' && pbuf[path_length - 1]== '\"') {
*pbuf++ = 0;
- path_length-=2;
+ path_length -= 2;
}
- if (path_length==0) {
+ if (path_length == 0) {
continue;
}
zend_accel_blacklist_allocate(blacklist);
blacklist->entries[blacklist->pos].path_length = path_length;
- blacklist->entries[blacklist->pos].path = (char *) malloc(path_length+1);
+ blacklist->entries[blacklist->pos].path = (char *)malloc(path_length + 1);
if (!blacklist->entries[blacklist->pos].path) {
zend_accel_error(ACCEL_LOG_ERROR, "malloc() failed\n");
return;
}
blacklist->entries[blacklist->pos].id = blacklist->pos;
- memcpy(blacklist->entries[blacklist->pos].path, real_path, path_length+1);
+ memcpy(blacklist->entries[blacklist->pos].path, real_path, path_length + 1);
blacklist->pos++;
}
fclose(fp);
{
int i;
- for(i=0; i<blacklist->pos; i++) {
+ for (i = 0; i < blacklist->pos; i++) {
func(&blacklist->entries[i], argument TSRMLS_CC);
}
}
zend_ini_entry *ini_entry;
memsize = 8;
- zend_accel_error(ACCEL_LOG_WARNING,"zend_optimizerplus.memory_consumption is set below the required 8MB.\n" );
+ zend_accel_error(ACCEL_LOG_WARNING, "zend_optimizerplus.memory_consumption is set below the required 8MB.\n" );
zend_accel_error(ACCEL_LOG_WARNING, ACCELERATOR_PRODUCT_NAME " will use the minimal 8MB cofiguration.\n" );
if (zend_hash_find(EG(ini_directives),
"zend_optimizerplus.memory_consumption",
sizeof("zend_optimizerplus.memory_consumption"),
- (void *) &ini_entry)==FAILURE) {
+ (void *) &ini_entry) == FAILURE) {
return FAILURE;
}
const char *new_new_value;
zend_ini_entry *ini_entry;
- if(size < MIN_ACCEL_FILES){
+ if (size < MIN_ACCEL_FILES) {
size = MIN_ACCEL_FILES;
new_new_value = TOKENTOSTR(MIN_ACCEL_FILES);
- zend_accel_error(ACCEL_LOG_WARNING,"zend_optimizerplus.max_accelerated_files is set below the required minimum (%d).\n", MIN_ACCEL_FILES );
+ zend_accel_error(ACCEL_LOG_WARNING, "zend_optimizerplus.max_accelerated_files is set below the required minimum (%d).\n", MIN_ACCEL_FILES );
zend_accel_error(ACCEL_LOG_WARNING,ACCELERATOR_PRODUCT_NAME " will use the minimal cofiguration.\n" );
}
- if(size > MAX_ACCEL_FILES){
+ if (size > MAX_ACCEL_FILES) {
size = MAX_ACCEL_FILES;
new_new_value = TOKENTOSTR(MAX_ACCEL_FILES);
- zend_accel_error(ACCEL_LOG_WARNING,"zend_optimizerplus.max_accelerated_files is set above the limit (%d).\n", MAX_ACCEL_FILES );
+ zend_accel_error(ACCEL_LOG_WARNING, "zend_optimizerplus.max_accelerated_files is set above the limit (%d).\n", MAX_ACCEL_FILES );
zend_accel_error(ACCEL_LOG_WARNING, ACCELERATOR_PRODUCT_NAME " will use the maximal cofiguration.\n" );
}
if (zend_hash_find(EG(ini_directives),
"zend_optimizerplus.max_accelerated_files",
sizeof("zend_optimizerplus.max_accelerated_files"),
- (void *) &ini_entry)==FAILURE) {
+ (void *) &ini_entry) == FAILURE) {
return FAILURE;
}
ini_entry->value = strdup(new_new_value);
zend_ini_entry *ini_entry;
percentage = 5;
- zend_accel_error(ACCEL_LOG_WARNING,"zend_optimizerplus.max_wasted_percentage must be ser netweeb 1 and 50.\n");
+ zend_accel_error(ACCEL_LOG_WARNING, "zend_optimizerplus.max_wasted_percentage must be ser netweeb 1 and 50.\n");
zend_accel_error(ACCEL_LOG_WARNING,ACCELERATOR_PRODUCT_NAME " will use 5%.\n" );
if (zend_hash_find(EG(ini_directives),
"zend_optimizerplus.max_wasted_percentage",
sizeof("zend_optimizerplus.max_wasted_percentage"),
- (void *) &ini_entry)==FAILURE) {
+ (void *) &ini_entry) == FAILURE) {
return FAILURE;
}
ini_entry->value = strdup(new_new_value);
}
ZEND_INI_BEGIN()
- STD_PHP_INI_BOOLEAN("zend_optimizerplus.enable" ,"1", PHP_INI_SYSTEM, OnUpdateBool, enabled , zend_accel_globals, accel_globals)
- STD_PHP_INI_BOOLEAN("zend_optimizerplus.use_cwd" ,"1", PHP_INI_SYSTEM, OnUpdateBool, accel_directives.use_cwd , zend_accel_globals, accel_globals)
- STD_PHP_INI_BOOLEAN("zend_optimizerplus.validate_timestamps","1", PHP_INI_ALL , OnUpdateBool, accel_directives.validate_timestamps, zend_accel_globals, accel_globals)
- STD_PHP_INI_BOOLEAN("zend_optimizerplus.inherited_hack" ,"1", PHP_INI_SYSTEM, OnUpdateBool, accel_directives.inherited_hack , zend_accel_globals, accel_globals)
- STD_PHP_INI_BOOLEAN("zend_optimizerplus.dups_fix" ,"0", PHP_INI_ALL , OnUpdateBool, accel_directives.ignore_dups , zend_accel_globals, accel_globals)
- STD_PHP_INI_BOOLEAN("zend_optimizerplus.revalidate_path" ,"0", PHP_INI_ALL , OnUpdateBool, accel_directives.revalidate_path , zend_accel_globals, accel_globals)
+ STD_PHP_INI_BOOLEAN("zend_optimizerplus.enable" , "1", PHP_INI_SYSTEM, OnUpdateBool, enabled , zend_accel_globals, accel_globals)
+ STD_PHP_INI_BOOLEAN("zend_optimizerplus.use_cwd" , "1", PHP_INI_SYSTEM, OnUpdateBool, accel_directives.use_cwd , zend_accel_globals, accel_globals)
+ STD_PHP_INI_BOOLEAN("zend_optimizerplus.validate_timestamps", "1", PHP_INI_ALL , OnUpdateBool, accel_directives.validate_timestamps, zend_accel_globals, accel_globals)
+ STD_PHP_INI_BOOLEAN("zend_optimizerplus.inherited_hack" , "1", PHP_INI_SYSTEM, OnUpdateBool, accel_directives.inherited_hack , zend_accel_globals, accel_globals)
+ STD_PHP_INI_BOOLEAN("zend_optimizerplus.dups_fix" , "0", PHP_INI_ALL , OnUpdateBool, accel_directives.ignore_dups , zend_accel_globals, accel_globals)
+ STD_PHP_INI_BOOLEAN("zend_optimizerplus.revalidate_path" , "0", PHP_INI_ALL , OnUpdateBool, accel_directives.revalidate_path , zend_accel_globals, accel_globals)
STD_PHP_INI_ENTRY("zend_optimizerplus.log_verbosity_level" , "1" , PHP_INI_SYSTEM, OnUpdateLong, accel_directives.log_verbosity_level, zend_accel_globals, accel_globals)
STD_PHP_INI_ENTRY("zend_optimizerplus.memory_consumption" , "64" , PHP_INI_SYSTEM, OnUpdateMemoryConsumption, accel_directives.memory_consumption, zend_accel_globals, accel_globals)
}
}
- if((key = accel_make_persistent_key_ex(&handle, filename_len, &key_length TSRMLS_CC)) != NULL) {
+ if ((key = accel_make_persistent_key_ex(&handle, filename_len, &key_length TSRMLS_CC)) != NULL) {
persistent_script = zend_accel_hash_find(&ZCSG(hash), key, key_length+1);
return persistent_script && !persistent_script->corrupted;
}
return;
}
#endif
- if(filename_len > 0) {
- if(filename_is_in_cache(filename, filename_len TSRMLS_CC)) {
+ if (filename_len > 0) {
+ if (filename_is_in_cache(filename, filename_len TSRMLS_CC)) {
RETURN_TRUE;
}
}
void zend_accel_override_file_functions(TSRMLS_D)
{
zend_function *old_function;
- if(accel_startup_ok && ZCG(accel_directives).file_override_enabled) {
+ if (accel_startup_ok && ZCG(accel_directives).file_override_enabled) {
/* override file_exists */
- if(zend_hash_find(CG(function_table), "file_exists", sizeof("file_exists"), (void **)&old_function) == SUCCESS) {
+ if (zend_hash_find(CG(function_table), "file_exists", sizeof("file_exists"), (void **)&old_function) == SUCCESS) {
old_function->internal_function.handler = accel_file_exists;
}
- if(zend_hash_find(CG(function_table), "is_file", sizeof("is_file"), (void **)&old_function) == SUCCESS) {
+ if (zend_hash_find(CG(function_table), "is_file", sizeof("is_file"), (void **)&old_function) == SUCCESS) {
old_function->internal_function.handler = accel_is_file;
}
- if(zend_hash_find(CG(function_table), "is_readable", sizeof("is_readable"), (void **)&old_function) == SUCCESS) {
+ if (zend_hash_find(CG(function_table), "is_readable", sizeof("is_readable"), (void **)&old_function) == SUCCESS) {
old_function->internal_function.handler = accel_is_readable;
}
}
MAKE_STD_ZVAL(return_value);
array_init(return_value);
- for (i=0; i<ZCSG(hash).max_num_entries; i++) {
- for (cache_entry=ZCSG(hash).hash_table[i]; cache_entry; cache_entry = cache_entry->next) {
+ for (i = 0; i<ZCSG(hash).max_num_entries; i++) {
+ for (cache_entry = ZCSG(hash).hash_table[i]; cache_entry; cache_entry = cache_entry->next) {
zend_persistent_script *script;
if (cache_entry->indirect) continue;
add_assoc_zval(return_value, "accelerator_statistics",statistics);
/* acceleratred scripts */
- scripts=accelerator_get_scripts(TSRMLS_C);
- if( scripts ){
+ scripts = accelerator_get_scripts(TSRMLS_C);
+ if (scripts) {
add_assoc_zval(return_value, "scripts",scripts);
}
}
add_assoc_bool(directives, "zend_optimizerplus.enable_file_override", ZCG(accel_directives).file_override_enabled);
add_assoc_long(directives, "zend_optimizerplus.optimization_level", ZCG(accel_directives).optimization_level);
- add_assoc_zval(return_value,"directives",directives);
+ add_assoc_zval(return_value, "directives",directives);
/*version */
MAKE_STD_ZVAL(version);
array_init(version);
add_assoc_string(version, "version", ACCELERATOR_VERSION, 1);
add_assoc_string(version, "accelerator_product_name", ACCELERATOR_PRODUCT_NAME, 1);
- add_assoc_zval(return_value,"version",version);
+ add_assoc_zval(return_value, "version",version);
/* blacklist */
MAKE_STD_ZVAL(blacklist);
array_init(blacklist);
zend_accel_blacklist_apply(&accel_blacklist, (apply_func_arg_t) add_blacklist_path, blacklist TSRMLS_CC);
- add_assoc_zval(return_value,"blacklist",blacklist);
+ add_assoc_zval(return_value, "blacklist",blacklist);
}
/* {{{ proto void accelerator_reset()
HashTable *function_table = va_arg(args, HashTable *);
(void)num_args; /* keep the compiler happy */
- if (function->type==ZEND_USER_FUNCTION) {
+ if (function->type == ZEND_USER_FUNCTION) {
zend_hash_quick_update(function_table, hash_key->arKey, hash_key->nKeyLength, hash_key->h, function, sizeof(zend_function), NULL);
return 1;
} else {
static int copy_internal_function(zend_function *function, HashTable *function_table TSRMLS_DC)
{
- if (function->type==ZEND_INTERNAL_FUNCTION) {
- zend_hash_update(function_table, function->common.function_name, strlen(function->common.function_name)+1, function, sizeof(zend_function), NULL);
+ if (function->type == ZEND_INTERNAL_FUNCTION) {
+ zend_hash_update(function_table, function->common.function_name, strlen(function->common.function_name) + 1, function, sizeof(zend_function), NULL);
}
return 0;
}
static void zend_destroy_property_info(zend_property_info *property_info)
{
interned_efree((char*)property_info->name);
- if(property_info->doc_comment){
+ if (property_info->doc_comment) {
efree((char*)property_info->doc_comment);
}
}
q->pData = (void *) emalloc(sizeof(zend_function));
new_entry = (zend_op_array*)q->pData;
*new_entry = *(zend_op_array*)p->pData;
- q->pDataPtr=NULL;
+ q->pDataPtr = NULL;
/* Copy constructor */
/* we use refcount to show that op_array is referenced from several places */
zend_prepare_function_for_execution(new_entry);
- if(old_ce == new_entry->scope) {
+ if (old_ce == new_entry->scope) {
new_entry->scope = ce;
} else {
- if(accel_xlat_get(new_entry->scope, new_ce) == SUCCESS) {
+ if (accel_xlat_get(new_entry->scope, new_ce) == SUCCESS) {
new_entry->scope = *new_ce;
} else {
zend_error(E_ERROR, ACCELERATOR_PRODUCT_NAME " class loading error, class %s, function %s. Please call Zend Support", ce->name, new_entry->function_name);
}
/* update prototype */
- if (new_entry->prototype ){
- if(accel_xlat_get(new_entry->prototype, new_prototype)==SUCCESS) {
+ if (new_entry->prototype) {
+ if (accel_xlat_get(new_entry->prototype, new_prototype) == SUCCESS) {
new_entry->prototype = *new_prototype;
} else {
zend_error(E_ERROR, ACCELERATOR_PRODUCT_NAME " class loading error, class %s, function %s. Please call Zend Support", ce->name, new_entry->function_name);
q->pData = (void *) emalloc(sizeof(zend_property_info));
prop_info = q->pData;
*prop_info = *(zend_property_info*)p->pData;
- q->pDataPtr=NULL;
+ q->pDataPtr = NULL;
/* Copy constructor */
prop_info->name = interned_estrndup(prop_info->name, prop_info->name_length);
- if(prop_info->doc_comment) {
+ if (prop_info->doc_comment) {
if (ZCG(accel_directives).load_comments) {
prop_info->doc_comment = estrndup(prop_info->doc_comment, prop_info->doc_comment_len);
} else {
prop_info->doc_comment = NULL;
}
}
- if(prop_info->ce == old_ce) {
+ if (prop_info->ce == old_ce) {
prop_info->ce = ce;
- } else if(accel_xlat_get(prop_info->ce, new_ce) == SUCCESS) {
+ } else if (accel_xlat_get(prop_info->ce, new_ce) == SUCCESS) {
prop_info->ce = *new_ce;
} else {
zend_error(E_ERROR, ACCELERATOR_PRODUCT_NAME" class loading error, class %s, property %s. Please call Zend Support", ce->name, prop_info->name);
#define zend_update_inherited_handler(handler) \
{ \
- if(ce->handler != NULL) { \
- if(accel_xlat_get(ce->handler, new_func)==SUCCESS) { \
+ if (ce->handler != NULL) { \
+ if (accel_xlat_get(ce->handler, new_func) == SUCCESS) { \
ce->handler = *new_func; \
} else { \
zend_error(E_ERROR, ACCELERATOR_PRODUCT_NAME " class loading error, class %s. Please call Zend Support", ce->name); \
ce->name = interned_estrndup(ce->name, ce->name_length);
/* interfaces aren't really implemented, so we create a new table */
- if(ce->num_interfaces) {
+ if (ce->num_interfaces) {
ce->interfaces = emalloc(sizeof(zend_class_entry *) * ce->num_interfaces);
memset(ce->interfaces, 0, sizeof(zend_class_entry *) * ce->num_interfaces);
} else {
}
}
- if(ce->parent) {
- if(accel_xlat_get(ce->parent, new_ce)==SUCCESS) {
+ if (ce->parent) {
+ if (accel_xlat_get(ce->parent, new_ce) == SUCCESS) {
ce->parent = *new_ce;
} else {
zend_error(E_ERROR, ACCELERATOR_PRODUCT_NAME" class loading error, class %s. Please call Zend Support", ce->name);
while (ce->trait_aliases[i]) {
i++;
}
- trait_aliases = emalloc(sizeof(zend_trait_alias*) * (i+1));
+ trait_aliases = emalloc(sizeof(zend_trait_alias*) * (i + 1));
i = 0;
while (ce->trait_aliases[i]) {
trait_aliases[i] = emalloc(sizeof(zend_trait_alias));
while (ce->trait_precedences[i]) {
i++;
}
- trait_precedences = emalloc(sizeof(zend_trait_precedence*) * (i+1));
+ trait_precedences = emalloc(sizeof(zend_trait_precedence*) * (i + 1));
i = 0;
while (ce->trait_precedences[i]) {
trait_precedences[i] = emalloc(sizeof(zend_trait_precedence));
while (trait_precedences[i]->exclude_from_classes[j]) {
j++;
}
- exclude_from_classes = emalloc(sizeof(zend_class_entry*) * (j+1));
+ exclude_from_classes = emalloc(sizeof(zend_class_entry*) * (j + 1));
j = 0;
while (trait_precedences[i]->exclude_from_classes[j]) {
exclude_from_classes[j] = (zend_class_entry*)estrndup(
zend_op_array *op1 = (zend_op_array *)func1;
zend_op_array *op2 = (zend_op_array *)func2;
- if(func1->type != ZEND_USER_FUNCTION || func2->type != ZEND_USER_FUNCTION) {
+ if (func1->type != ZEND_USER_FUNCTION || func2->type != ZEND_USER_FUNCTION) {
return 0;
}
- if(func1 == func2) {
+ if (func1 == func2) {
return 1;
}
- if(op1->function_name != op2->function_name && (!op1->function_name || !op2->function_name || strcmp(op1->function_name, op2->function_name))) {
+ if (op1->function_name != op2->function_name && (!op1->function_name || !op2->function_name || strcmp(op1->function_name, op2->function_name))) {
/* compare filenames */
return 0;
}
- if(op1->filename != op2->filename && (!op1->filename || !op2->filename || strcmp(op1->filename, op2->filename))) {
+ if (op1->filename != op2->filename && (!op1->filename || !op2->filename || strcmp(op1->filename, op2->filename))) {
/* compare filenames */
return 0;
}
- if(!op1->opcodes || !op2->opcodes || op1->opcodes[0].lineno != op2->opcodes[0].lineno) {
+ if (!op1->opcodes || !op2->opcodes || op1->opcodes[0].lineno != op2->opcodes[0].lineno) {
/* compare first lines */
return 0;
}
zend_class_entry *ce1 = *(zend_class_entry **)f1;
zend_class_entry *ce2 = *(zend_class_entry **)f2;
- if(ce1->type != ZEND_USER_CLASS || ce2->type != ZEND_USER_CLASS) {
+ if (ce1->type != ZEND_USER_CLASS || ce2->type != ZEND_USER_CLASS) {
return 0;
}
- if(ce1 == ce2) {
+ if (ce1 == ce2) {
return 1;
}
- if(!ce1->name || !ce2->name || zend_binary_strcmp(ce1->name, ce1->name_length, ce2->name, ce2->name_length)) {
+ if (!ce1->name || !ce2->name || zend_binary_strcmp(ce1->name, ce1->name_length, ce2->name, ce2->name_length)) {
return 0;
}
return 0;
}
- if(zend_hash_num_elements(&ce1->function_table)) {
+ if (zend_hash_num_elements(&ce1->function_table)) {
HashPosition pos;
zend_function *func1, *func2;
zend_hash_get_current_data_ex(&ce1->function_table, (void **)&func1, &pos);
zend_hash_internal_pointer_reset_ex(&ce2->function_table, &pos);
zend_hash_get_current_data_ex(&ce2->function_table, (void **)&func2, &pos);
- if(!zend_accel_same_function(func1, func2)) {
+ if (!zend_accel_same_function(func1, func2)) {
return 0;
}
}
Bucket *p;
void *t;
- p = source->pListHead;
+ p = source->pListHead;
while (p) {
- if (p->nKeyLength>0) {
- if (zend_hash_quick_add(target, p->arKey, p->nKeyLength, p->h, p->pData, size, &t) ==SUCCESS) {
- if(pCopyConstructor) {
+ if (p->nKeyLength > 0) {
+ if (zend_hash_quick_add(target, p->arKey, p->nKeyLength, p->h, p->pData, size, &t) == SUCCESS) {
+ if (pCopyConstructor) {
pCopyConstructor(t);
}
} else {
- if(p->nKeyLength>0 && p->arKey[0]==0) {
+ if (p->nKeyLength > 0 && p->arKey[0] == 0) {
/* Mangled key, ignore and wait for runtime */
- } else if(zend_hash_quick_find(target, p->arKey, p->nKeyLength, p->h, &t) == SUCCESS &&
+ } else if (zend_hash_quick_find(target, p->arKey, p->nKeyLength, p->h, &t) == SUCCESS &&
(!pIdFunc || pIdFunc(p->pData, t))) {
/* same one, ignore it */
} else {
- if(key_fail) {
+ if (key_fail) {
*key_fail = p->arKey;
}
- if(key_fail_l) {
+ if (key_fail_l) {
*key_fail_l = p->nKeyLength;
}
return FAILURE;
}
} else {
if (!zend_hash_index_exists(target, p->h) && zend_hash_index_update(target, p->h, p->pData, size, &t) == SUCCESS) {
- if(pCopyConstructor) {
+ if (pCopyConstructor) {
pCopyConstructor(t);
}
} else {
- if(key_fail) {
+ if (key_fail) {
*key_fail = NULL;
}
- if(key_fail_l) {
+ if (key_fail_l) {
*key_fail_l = p->h;
}
return FAILURE;
zend_function *function;
TSRMLS_FETCH();
- if(zend_hash_unique_copy(target, source, pCopyConstructor, sizeof(zend_function), &name, &name_len, ZCG(accel_directives).ignore_dups?NULL:zend_accel_same_function) != SUCCESS) {
- if (zend_hash_find(target, name, name_len, (void *) &function)==SUCCESS
- && function->type==ZEND_USER_FUNCTION
- && ((zend_op_array *) function)->last>0) {
+ if (zend_hash_unique_copy(target, source, pCopyConstructor, sizeof(zend_function), &name, &name_len, ZCG(accel_directives).ignore_dups?NULL:zend_accel_same_function) != SUCCESS) {
+ if (zend_hash_find(target, name, name_len, (void *) &function) == SUCCESS
+ && function->type == ZEND_USER_FUNCTION
+ && ((zend_op_array *) function)->last > 0) {
zend_error(E_ERROR, "Cannot redeclare function %.*s() (previously declared in %s:%d). If this code worked without the " ACCELERATOR_PRODUCT_NAME ", please set zend_optimizerplus.dups_fix=1 in your ini file",
(int)name_len, name,
((zend_op_array *) function)->filename,
uint size;
size = sizeof(zend_class_entry*);
- if(zend_hash_unique_copy(target, source, pCopyConstructor, size, &name, &name_len, ZCG(accel_directives).ignore_dups?NULL:zend_accel_same_class) != SUCCESS) {
+ if (zend_hash_unique_copy(target, source, pCopyConstructor, size, &name, &name_len, ZCG(accel_directives).ignore_dups? NULL : zend_accel_same_class) != SUCCESS) {
zend_error(E_ERROR, "Cannot redeclare class %.*s. If this code worked without the " ACCELERATOR_PRODUCT_NAME ", please set zend_optimizerplus.dups_fix=1 in your php.ini", (int)name_len, name);
}
}
CG(in_compilation) = 1;
while ((int)opline_num != -1) {
- if (zend_lookup_class(Z_STRVAL(op_array->opcodes[opline_num-1].op2.u.constant), Z_STRLEN(op_array->opcodes[opline_num-1].op2.u.constant), &pce TSRMLS_CC) == SUCCESS) {
+ if (zend_lookup_class(Z_STRVAL(op_array->opcodes[opline_num - 1].op2.u.constant), Z_STRLEN(op_array->opcodes[opline_num - 1].op2.u.constant), &pce TSRMLS_CC) == SUCCESS) {
do_bind_inherited_class(&op_array->opcodes[opline_num], EG(class_table), *pce, 1 TSRMLS_CC);
}
opline_num = op_array->opcodes[opline_num].result.u.opline_num;
cfilename = persistent_script->full_path;
clen = strlen(cfilename);
zend_mangle_property_name(&name, &len, haltoff, sizeof(haltoff) - 1, cfilename, clen, 0);
- if (!zend_hash_exists(EG(zend_constants), name, len+1)) {
- zend_register_long_constant(name, len+1, persistent_script->compiler_halt_offset, CONST_CS, 0 TSRMLS_CC);
+ if (!zend_hash_exists(EG(zend_constants), name, len + 1)) {
+ zend_register_long_constant(name, len + 1, persistent_script->compiler_halt_offset, CONST_CS, 0 TSRMLS_CC);
}
efree(name);
}
#define ADLER32_NMAX 5552
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
-#define ADLER32_DO1(buf) {s1 += *(buf); s2 += s1;}
-#define ADLER32_DO2(buf,i) ADLER32_DO1(buf+i); ADLER32_DO1(buf+i+1);
-#define ADLER32_DO4(buf,i) ADLER32_DO2(buf,i); ADLER32_DO2(buf,i+2);
-#define ADLER32_DO8(buf,i) ADLER32_DO4(buf,i); ADLER32_DO4(buf,i+4);
-#define ADLER32_DO16(buf) ADLER32_DO8(buf,0); ADLER32_DO8(buf,8);
+#define ADLER32_DO1(buf) {s1 += *(buf); s2 += s1;}
+#define ADLER32_DO2(buf, i) ADLER32_DO1(buf + i); ADLER32_DO1(buf + i + 1);
+#define ADLER32_DO4(buf, i) ADLER32_DO2(buf, i); ADLER32_DO2(buf, i + 2);
+#define ADLER32_DO8(buf, i) ADLER32_DO4(buf, i); ADLER32_DO4(buf, i + 4);
+#define ADLER32_DO16(buf) ADLER32_DO8(buf, 0); ADLER32_DO8(buf, 8);
unsigned int zend_adler32(unsigned int checksum, signed char *buf, uint len)
{
}
s1 %= ADLER32_BASE;
s2 %= ADLER32_BASE;
- }
+ }
return (s2 << 16) | s1;
}
#endif
EG(in_execution) = 1;
EG(active_op_array) = op_array;
- if (zend_get_constant("__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__")-1, &offset TSRMLS_CC)) {
+ if (zend_get_constant("__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__") - 1, &offset TSRMLS_CC)) {
main_persistent_script->compiler_halt_offset = Z_LVAL(offset);
}
EG(active_op_array) = orig_op_array;
int offset = 0;
for (;opline<end;opline++, offset++) {
- if (ZEND_OP1_TYPE(opline)==IS_CONST) {
+ if (ZEND_OP1_TYPE(opline) == IS_CONST) {
#if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
opline->op1.zv = (zval*)((char*)opline->op1.zv + ((char*)op_array->literals - (char*)orig_literals));
#else
zend_protect_zval(&opline->op1.u.constant TSRMLS_CC);
#endif
}
- if (ZEND_OP2_TYPE(opline)==IS_CONST) {
+ if (ZEND_OP2_TYPE(opline) == IS_CONST) {
#if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
opline->op2.zv = (zval*)((char*)opline->op2.zv + ((char*)op_array->literals - (char*)orig_literals));
#else
case ZEND_DECLARE_INHERITED_CLASS:
if (main_persistent_script && ZCG(accel_directives).inherited_hack) {
if (!has_jmp &&
- ((opline+2) >= end ||
- (opline+1)->opcode != ZEND_FETCH_CLASS ||
- (opline+2)->opcode != ZEND_ADD_INTERFACE)) {
+ ((opline + 2) >= end ||
+ (opline + 1)->opcode != ZEND_FETCH_CLASS ||
+ (opline + 2)->opcode != ZEND_ADD_INTERFACE)) {
zend_uint *opline_num = &main_persistent_script->early_binding;
break;
}
}
-#endif /* if ZEND_EXTENSION_API_NO >= PHP_5_3_X_API_NO */
+#endif /* if ZEND_EXTENSION_API_NO >= PHP_5_3_X_API_NO */
}
efree(op_array->opcodes);
if ((new_name = zend_shared_alloc_get_xlat_entry(op_array->function_name))) {
op_array->function_name = new_name;
} else {
- zend_accel_store(op_array->function_name, strlen(op_array->function_name)+1);
+ zend_accel_store(op_array->function_name, strlen(op_array->function_name) + 1);
}
}
if (op_array->arg_info) {
zend_arg_info *new_ptr;
- if((new_ptr = zend_shared_alloc_get_xlat_entry(op_array->arg_info))) {
+ if ((new_ptr = zend_shared_alloc_get_xlat_entry(op_array->arg_info))) {
op_array->arg_info = new_ptr;
} else {
zend_uint i;
zend_accel_store(op_array->arg_info, sizeof(zend_arg_info) * op_array->num_args);
- for(i=0;i<op_array->num_args;i++) {
- if(op_array->arg_info[i].name) {
+ for (i = 0; i < op_array->num_args; i++) {
+ if (op_array->arg_info[i].name) {
zend_accel_store_interned_string(op_array->arg_info[i].name, op_array->arg_info[i].name_len + 1);
}
- if(op_array->arg_info[i].class_name) {
+ if (op_array->arg_info[i].class_name) {
zend_accel_store_interned_string(op_array->arg_info[i].class_name, op_array->arg_info[i].class_name_len + 1);
}
}
zend_accel_store(op_array->static_variables, sizeof(HashTable));
}
- if(op_array->scope) {
+ if (op_array->scope) {
op_array->scope = zend_shared_alloc_get_xlat_entry(op_array->scope);
}
- if(op_array->doc_comment) {
+ if (op_array->doc_comment) {
if (ZCG(accel_directives).save_comments) {
zend_accel_store(op_array->doc_comment, op_array->doc_comment_len + 1);
} else {
- if(!zend_shared_alloc_get_xlat_entry(op_array->doc_comment)) {
+ if (!zend_shared_alloc_get_xlat_entry(op_array->doc_comment)) {
zend_shared_alloc_register_xlat_entry(op_array->doc_comment, op_array->doc_comment);
efree((char*)op_array->doc_comment);
}
}
}
- if(op_array->try_catch_array) {
+ if (op_array->try_catch_array) {
zend_accel_store(op_array->try_catch_array, sizeof(zend_try_catch_element) * op_array->last_try_catch);
}
- if(op_array->vars) {
+ if (op_array->vars) {
if ((persist_ptr = zend_shared_alloc_get_xlat_entry(op_array->vars))) {
op_array->vars = (zend_compiled_variable*)persist_ptr;
} else {
int i;
zend_accel_store(op_array->vars, sizeof(zend_compiled_variable) * op_array->last_var);
- for(i=0; i<op_array->last_var; i++) {
+ for (i = 0; i < op_array->last_var; i++) {
zend_accel_store_interned_string(op_array->vars[i].name, op_array->vars[i].name_len + 1);
}
}
}
/* "prototype" may be undefined if "scope" isn't set */
- if(op_array->scope && op_array->prototype) {
+ if (op_array->scope && op_array->prototype) {
if ((persist_ptr = zend_shared_alloc_get_xlat_entry(op_array->prototype))) {
op_array->prototype = (union _zend_function*)persist_ptr;
/* we use refcount to show that op_array is referenced from several places */
static void zend_persist_property_info(zend_property_info *prop TSRMLS_DC)
{
zend_accel_store_interned_string(prop->name, prop->name_length + 1);
- if(prop->doc_comment) {
+ if (prop->doc_comment) {
if (ZCG(accel_directives).save_comments) {
zend_accel_store(prop->doc_comment, prop->doc_comment_len + 1);
} else {
- if(!zend_shared_alloc_get_xlat_entry(prop->doc_comment)) {
+ if (!zend_shared_alloc_get_xlat_entry(prop->doc_comment)) {
zend_shared_alloc_register_xlat_entry(prop->doc_comment, prop->doc_comment);
efree((char*)prop->doc_comment);
}
#endif
zend_hash_persist(&ce->constants_table, (zend_persist_func_t) zend_persist_zval_ptr, sizeof(zval**) TSRMLS_CC);
- if(ZEND_CE_FILENAME(ce)) {
+ if (ZEND_CE_FILENAME(ce)) {
/* do not free! PHP has centralized filename storage, compiler will free it */
ZEND_CE_FILENAME(ce) = zend_accel_memdup(ZEND_CE_FILENAME(ce), strlen(ZEND_CE_FILENAME(ce)) + 1);
}
- if(ZEND_CE_DOC_COMMENT(ce)) {
+ if (ZEND_CE_DOC_COMMENT(ce)) {
if (ZCG(accel_directives).save_comments) {
zend_accel_store(ZEND_CE_DOC_COMMENT(ce), ZEND_CE_DOC_COMMENT_LEN(ce) + 1);
} else {
- if(!zend_shared_alloc_get_xlat_entry(ZEND_CE_DOC_COMMENT(ce))) {
+ if (!zend_shared_alloc_get_xlat_entry(ZEND_CE_DOC_COMMENT(ce))) {
zend_shared_alloc_register_xlat_entry(ZEND_CE_DOC_COMMENT(ce), ZEND_CE_DOC_COMMENT(ce));
efree((char*)ZEND_CE_DOC_COMMENT(ce));
}
}
}
zend_hash_persist(&ce->properties_info, (zend_persist_func_t) zend_persist_property_info, sizeof(zend_property_info) TSRMLS_CC);
- if(ce->num_interfaces && ce->interfaces) {
+ if (ce->num_interfaces && ce->interfaces) {
efree(ce->interfaces);
}
ce->interfaces = NULL; /* will be filled in on fetch */
if (ce->trait_aliases[i]->trait_method) {
if (ce->trait_aliases[i]->trait_method->method_name) {
zend_accel_store(ce->trait_aliases[i]->trait_method->method_name,
- ce->trait_aliases[i]->trait_method->mname_len+1);
+ ce->trait_aliases[i]->trait_method->mname_len + 1);
}
if (ce->trait_aliases[i]->trait_method->class_name) {
zend_accel_store(ce->trait_aliases[i]->trait_method->class_name,
- ce->trait_aliases[i]->trait_method->cname_len+1);
+ ce->trait_aliases[i]->trait_method->cname_len + 1);
}
ce->trait_aliases[i]->trait_method->ce = NULL;
zend_accel_store(ce->trait_aliases[i]->trait_method,
if (ce->trait_aliases[i]->alias) {
zend_accel_store(ce->trait_aliases[i]->alias,
- ce->trait_aliases[i]->alias_len+1);
+ ce->trait_aliases[i]->alias_len + 1);
}
#if ZEND_EXTENSION_API_NO <= PHP_5_4_X_API_NO
while (ce->trait_precedences[i]) {
zend_accel_store(ce->trait_precedences[i]->trait_method->method_name,
- ce->trait_precedences[i]->trait_method->mname_len+1);
+ ce->trait_precedences[i]->trait_method->mname_len + 1);
zend_accel_store(ce->trait_precedences[i]->trait_method->class_name,
- ce->trait_precedences[i]->trait_method->cname_len+1);
+ ce->trait_precedences[i]->trait_method->cname_len + 1);
ce->trait_precedences[i]->trait_method->ce = NULL;
zend_accel_store(ce->trait_precedences[i]->trait_method,
sizeof(zend_trait_method_reference));
j++;
}
zend_accel_store(ce->trait_precedences[i]->exclude_from_classes,
- sizeof(zend_class_entry*) * (j+1));
+ sizeof(zend_class_entry*) * (j + 1));
}
#if ZEND_EXTENSION_API_NO <= PHP_5_4_X_API_NO
i++;
}
zend_accel_store(
- ce->trait_precedences, sizeof(zend_trait_precedence*) * (i+1));
+ ce->trait_precedences, sizeof(zend_trait_precedence*) * (i + 1));
}
#endif
}
}
/* update methods */
- if(ce->constructor) {
+ if (ce->constructor) {
ce->constructor = zend_shared_alloc_get_xlat_entry(ce->constructor);
/* we use refcount to show that op_array is referenced from several places */
ce->constructor->op_array.refcount++;
}
- if(ce->destructor) {
+ if (ce->destructor) {
ce->destructor = zend_shared_alloc_get_xlat_entry(ce->destructor);
ce->destructor->op_array.refcount++;
}
- if(ce->clone) {
+ if (ce->clone) {
ce->clone = zend_shared_alloc_get_xlat_entry(ce->clone);
ce->clone->op_array.refcount++;
}
- if(ce->__get) {
+ if (ce->__get) {
ce->__get = zend_shared_alloc_get_xlat_entry(ce->__get);
ce->__get->op_array.refcount++;
}
- if(ce->__set) {
+ if (ce->__set) {
ce->__set = zend_shared_alloc_get_xlat_entry(ce->__set);
ce->__set->op_array.refcount++;
}
- if(ce->__call) {
+ if (ce->__call) {
ce->__call = zend_shared_alloc_get_xlat_entry(ce->__call);
ce->__call->op_array.refcount++;
}
- if(ce->serialize_func) {
+ if (ce->serialize_func) {
ce->serialize_func = zend_shared_alloc_get_xlat_entry(ce->serialize_func);
ce->serialize_func->op_array.refcount++;
}
- if(ce->unserialize_func) {
+ if (ce->unserialize_func) {
ce->unserialize_func = zend_shared_alloc_get_xlat_entry(ce->unserialize_func);
ce->unserialize_func->op_array.refcount++;
}
- if(ce->__isset) {
+ if (ce->__isset) {
ce->__isset = zend_shared_alloc_get_xlat_entry(ce->__isset);
ce->__isset->op_array.refcount++;
}
- if(ce->__unset) {
+ if (ce->__unset) {
ce->__unset = zend_shared_alloc_get_xlat_entry(ce->__unset);
ce->__unset->op_array.refcount++;
}
- if(ce->__tostring) {
+ if (ce->__tostring) {
ce->__tostring = zend_shared_alloc_get_xlat_entry(ce->__tostring);
ce->__tostring->op_array.refcount++;
}
#if ZEND_EXTENSION_API_NO >= PHP_5_3_X_API_NO
- if(ce->__callstatic) {
+ if (ce->__callstatic) {
ce->__callstatic = zend_shared_alloc_get_xlat_entry(ce->__callstatic);
ce->__callstatic->op_array.refcount++;
}
if (!zend_shared_alloc_get_xlat_entry(op_array->opcodes)) {
#if ZEND_EXTENSION_API_NO <= PHP_5_3_X_API_NO
zend_op *opline = op_array->opcodes;
- zend_op *end = op_array->opcodes+op_array->last;
+ zend_op *end = op_array->opcodes + op_array->last;
ADD_DUP_SIZE(op_array->opcodes, sizeof(zend_op) * op_array->last);
while (opline<end) {
- if (opline->op1.op_type==IS_CONST) {
+ if (opline->op1.op_type == IS_CONST) {
ADD_SIZE(zend_persist_zval_calc(&opline->op1.u.constant TSRMLS_CC));
}
- if (opline->op2.op_type==IS_CONST) {
+ if (opline->op2.op_type == IS_CONST) {
ADD_SIZE(zend_persist_zval_calc(&opline->op2.u.constant TSRMLS_CC));
}
opline++;
zend_uint i;
ADD_DUP_SIZE(op_array->arg_info, sizeof(zend_arg_info) * op_array->num_args);
- for(i=0;i<op_array->num_args;i++) {
- if(op_array->arg_info[i].name) {
+ for (i = 0;i < op_array->num_args; i++) {
+ if (op_array->arg_info[i].name) {
ADD_INTERNED_STRING(op_array->arg_info[i].name, op_array->arg_info[i].name_len + 1);
}
- if(op_array->arg_info[i].class_name) {
+ if (op_array->arg_info[i].class_name) {
ADD_INTERNED_STRING(op_array->arg_info[i].class_name, op_array->arg_info[i].class_name_len + 1);
}
ADD_SIZE(zend_hash_persist_calc(op_array->static_variables, (int (*)(void* TSRMLS_DC)) zend_persist_zval_ptr_calc, sizeof(zval**) TSRMLS_CC));
}
- if(ZCG(accel_directives).save_comments && op_array->doc_comment) {
+ if (ZCG(accel_directives).save_comments && op_array->doc_comment) {
ADD_DUP_SIZE(op_array->doc_comment, op_array->doc_comment_len + 1);
}
- if(op_array->try_catch_array) {
+ if (op_array->try_catch_array) {
ADD_DUP_SIZE(op_array->try_catch_array, sizeof(zend_try_catch_element) * op_array->last_try_catch);
}
- if(op_array->vars && !zend_shared_alloc_get_xlat_entry(op_array->vars)) {
+ if (op_array->vars && !zend_shared_alloc_get_xlat_entry(op_array->vars)) {
int i;
ADD_DUP_SIZE(op_array->vars, sizeof(zend_compiled_variable) * op_array->last_var);
- for(i=0; i<op_array->last_var; i++) {
+ for (i = 0; i < op_array->last_var; i++) {
ADD_INTERNED_STRING(op_array->vars[i].name, op_array->vars[i].name_len + 1);
}
}
{
START_SIZE();
ADD_INTERNED_STRING(prop->name, prop->name_length + 1);
- if(ZCG(accel_directives).save_comments && prop->doc_comment) {
+ if (ZCG(accel_directives).save_comments && prop->doc_comment) {
ADD_DUP_SIZE(prop->doc_comment, prop->doc_comment_len + 1);
}
RETURN_SIZE();
if (ZEND_CE_FILENAME(ce)) {
ADD_DUP_SIZE(ZEND_CE_FILENAME(ce), strlen(ZEND_CE_FILENAME(ce)) + 1);
}
- if(ZCG(accel_directives).save_comments && ZEND_CE_DOC_COMMENT(ce)) {
+ if (ZCG(accel_directives).save_comments && ZEND_CE_DOC_COMMENT(ce)) {
ADD_DUP_SIZE(ZEND_CE_DOC_COMMENT(ce), ZEND_CE_DOC_COMMENT_LEN(ce) + 1);
}
while (ce->trait_aliases[i]) {
if (ce->trait_aliases[i]->trait_method) {
if (ce->trait_aliases[i]->trait_method->method_name) {
- ADD_SIZE(ce->trait_aliases[i]->trait_method->mname_len+1);
+ ADD_SIZE(ce->trait_aliases[i]->trait_method->mname_len + 1);
}
if (ce->trait_aliases[i]->trait_method->class_name) {
- ADD_SIZE(ce->trait_aliases[i]->trait_method->cname_len+1);
+ ADD_SIZE(ce->trait_aliases[i]->trait_method->cname_len + 1);
}
ADD_SIZE(sizeof(zend_trait_method_reference));
}
if (ce->trait_aliases[i]->alias) {
- ADD_SIZE(ce->trait_aliases[i]->alias_len+1);
+ ADD_SIZE(ce->trait_aliases[i]->alias_len + 1);
}
ADD_SIZE(sizeof(zend_trait_alias));
i++;
int i = 0;
while (ce->trait_precedences[i]) {
- ADD_SIZE(ce->trait_precedences[i]->trait_method->mname_len+1);
- ADD_SIZE(ce->trait_precedences[i]->trait_method->cname_len+1);
+ ADD_SIZE(ce->trait_precedences[i]->trait_method->mname_len + 1);
+ ADD_SIZE(ce->trait_precedences[i]->trait_method->cname_len + 1);
ADD_SIZE(sizeof(zend_trait_method_reference));
if (ce->trait_precedences[i]->exclude_from_classes) {
ADD_SIZE(strlen((char*)ce->trait_precedences[i]->exclude_from_classes[j]) + 1);
j++;
}
- ADD_SIZE(sizeof(zend_class_entry*) * (j+1));
+ ADD_SIZE(sizeof(zend_class_entry*) * (j + 1));
}
ADD_SIZE(sizeof(zend_trait_precedence));
i++;
}
- ADD_SIZE(sizeof(zend_trait_precedence*) * (i+1));
+ ADD_SIZE(sizeof(zend_trait_precedence*) * (i + 1));
}
#endif
}
static MUTEX_T zts_lock;
#endif
int lock_file;
-static char lockfile_name[sizeof(TMP_DIR)+sizeof(SEM_FILENAME_PREFIX)+8];
+static char lockfile_name[sizeof(TMP_DIR) + sizeof(SEM_FILENAME_PREFIX) + 8];
#endif
static const zend_shared_memory_handler_entry handler_table[] = {
void *shared_segments_from_p = from;
int i;
- for(i=0;i<count;i++) {
+ for (i = 0; i < count; i++) {
shared_segments_v[i] = shared_segments_to_p;
memcpy(shared_segments_to_p, shared_segments_from_p, size);
shared_segments_to_p = ((char *)shared_segments_to_p + size);
res = S_H(create_segments)(requested_size, shared_segments_p, shared_segments_count, error_in);
- if( res ) {
+ if (res) {
/* this model works! */
return res;
}
- if(*shared_segments_p) {
+ if (*shared_segments_p) {
int i;
/* cleanup */
- for(i=0;i<*shared_segments_count;i++) {
- if((*shared_segments_p)[i]->p && (int)(*shared_segments_p)[i]->p != -1) {
+ for (i = 0; i < *shared_segments_count; i++) {
+ if ((*shared_segments_p)[i]->p && (int)(*shared_segments_p)[i]->p != -1) {
S_H(detach_segment)((*shared_segments_p)[i]);
}
}
zend_shared_alloc_create_lock();
- if(ZCG(accel_directives).memory_model && ZCG(accel_directives).memory_model[0]) {
- char* model = ZCG(accel_directives).memory_model;
+ if (ZCG(accel_directives).memory_model && ZCG(accel_directives).memory_model[0]) {
+ char *model = ZCG(accel_directives).memory_model;
/* "cgi" is really "shm"... */
- if( strncmp(ZCG(accel_directives).memory_model,"cgi",4) == 0 ){
+ if (strncmp(ZCG(accel_directives).memory_model, "cgi", sizeof("cgi")) == 0) {
model = "shm";
}
- for(he = handler_table; he->name; he++) {
- if(strcmp(model, he->name) == 0) {
- res=zend_shared_alloc_try(he, requested_size, &ZSMMG(shared_segments), &ZSMMG(shared_segments_count), &error_in);
- if( res ) {
+ for (he = handler_table; he->name; he++) {
+ if (strcmp(model, he->name) == 0) {
+ res = zend_shared_alloc_try(he, requested_size, &ZSMMG(shared_segments), &ZSMMG(shared_segments_count), &error_in);
+ if (res) {
/* this model works! */
}
break;
}
}
- if( res == FAILED_REATTACHED ){
+ if (res == FAILED_REATTACHED) {
smm_shared_globals = NULL;
return res;
}
- if(!g_shared_alloc_handler) {
+ if (!g_shared_alloc_handler) {
/* try memory handlers in order */
- for(he = handler_table; he->name; he++) {
- res=zend_shared_alloc_try(he, requested_size, &ZSMMG(shared_segments), &ZSMMG(shared_segments_count), &error_in);
- if( res ) {
+ for (he = handler_table; he->name; he++) {
+ res = zend_shared_alloc_try(he, requested_size, &ZSMMG(shared_segments), &ZSMMG(shared_segments_count), &error_in);
+ if (res) {
/* this model works! */
break;
}
}
}
- if(!g_shared_alloc_handler) {
+ if (!g_shared_alloc_handler) {
no_memory_bailout(requested_size, error_in);
return ALLOC_FAILURE;
}
- if( res == SUCCESSFULLY_REATTACHED ){
+ if (res == SUCCESSFULLY_REATTACHED) {
return res;
}
- shared_segments_array_size = ZSMMG(shared_segments_count)*S_H(segment_type_size)();
+ shared_segments_array_size = ZSMMG(shared_segments_count) * S_H(segment_type_size)();
/* move shared_segments and shared_free to shared memory */
ZCG(locked) = 1; /* no need to perform a real lock at this point */
p_tmp_shared_globals = (zend_smm_shared_globals *) zend_shared_alloc(sizeof(zend_smm_shared_globals));
- tmp_shared_segments = zend_shared_alloc(shared_segments_array_size+ZSMMG(shared_segments_count)*sizeof(void *));
+ tmp_shared_segments = zend_shared_alloc(shared_segments_array_size + ZSMMG(shared_segments_count) * sizeof(void *));
copy_shared_segments(tmp_shared_segments, ZSMMG(shared_segments)[0], ZSMMG(shared_segments_count), S_H(segment_type_size)());
*p_tmp_shared_globals = tmp_shared_globals;
free(ZSMMG(shared_segments));
ZSMMG(shared_segments) = tmp_shared_segments;
- ZSMMG(shared_memory_state).positions = (int *) zend_shared_alloc(sizeof(int)*ZSMMG(shared_segments_count));
+ ZSMMG(shared_memory_state).positions = (int *)zend_shared_alloc(sizeof(int) * ZSMMG(shared_segments_count));
ZCG(locked) = 0;
return res;
tmp_shared_globals = *smm_shared_globals;
smm_shared_globals = &tmp_shared_globals;
- shared_segments_array_size = ZSMMG(shared_segments_count)*(S_H(segment_type_size)()+sizeof(void *));
+ shared_segments_array_size = ZSMMG(shared_segments_count) * (S_H(segment_type_size)() + sizeof(void *));
tmp_shared_segments = emalloc(shared_segments_array_size);
copy_shared_segments(tmp_shared_segments, ZSMMG(shared_segments)[0], ZSMMG(shared_segments_count), S_H(segment_type_size)());
ZSMMG(shared_segments) = tmp_shared_segments;
- for(i=0; i<ZSMMG(shared_segments_count); i++) {
+ for (i = 0; i < ZSMMG(shared_segments_count); i++) {
S_H(detach_segment)(ZSMMG(shared_segments)[i]);
}
efree(ZSMMG(shared_segments));
void *zend_shared_alloc(size_t size)
{
int i;
- unsigned int block_size = size+sizeof(zend_shared_memory_block_header);
+ unsigned int block_size = size + sizeof(zend_shared_memory_block_header);
TSRMLS_FETCH();
#if 1
SHARED_ALLOC_FAILED();
return NULL;
}
- for (i=0; i<ZSMMG(shared_segments_count); i++) {
- if (ZSMMG(shared_segments)[i]->size-ZSMMG(shared_segments)[i]->pos >= block_size) { /* found a valid block */
- zend_shared_memory_block_header *p = (zend_shared_memory_block_header *) (((char *) ZSMMG(shared_segments)[i]->p)+ZSMMG(shared_segments)[i]->pos);
+ for (i = 0; i < ZSMMG(shared_segments_count); i++) {
+ if (ZSMMG(shared_segments)[i]->size - ZSMMG(shared_segments)[i]->pos >= block_size) { /* found a valid block */
+ zend_shared_memory_block_header *p = (zend_shared_memory_block_header *) (((char *) ZSMMG(shared_segments)[i]->p) + ZSMMG(shared_segments)[i]->pos);
int remainder = block_size % PLATFORM_ALIGNMENT;
void *retval;
- if (remainder!=0) {
- size += PLATFORM_ALIGNMENT-remainder;
- block_size += PLATFORM_ALIGNMENT-remainder;
+ if (remainder != 0) {
+ size += PLATFORM_ALIGNMENT - remainder;
+ block_size += PLATFORM_ALIGNMENT - remainder;
}
ZSMMG(shared_segments)[i]->pos += block_size;
ZSMMG(shared_free) -= block_size;
p->size = size;
- retval = ((char *) p)+sizeof(zend_shared_memory_block_header);
+ retval = ((char *) p) + sizeof(zend_shared_memory_block_header);
memset(retval, 0, size);
return retval;
}
{
void **old_p;
- if (zend_hash_index_find(&xlat_table, (ulong) source, (void **) &old_p)==SUCCESS) {
+ if (zend_hash_index_find(&xlat_table, (ulong)source, (void **)&old_p) == SUCCESS) {
/* we already duplicated this pointer */
return 0;
}
{
void **old_p, *retval;
- if (zend_hash_index_find(&xlat_table, (ulong) source, (void **) &old_p)==SUCCESS) {
+ if (zend_hash_index_find(&xlat_table, (ulong)source, (void **)&old_p) == SUCCESS) {
/* we already duplicated this pointer */
return *old_p;
}
void zend_shared_alloc_register_xlat_entry(const void *old, const void *new)
{
- zend_hash_index_update(&xlat_table, (ulong) old, (void*)&new, sizeof(void *), NULL);
+ zend_hash_index_update(&xlat_table, (ulong)old, (void*)&new, sizeof(void *), NULL);
}
void *zend_shared_alloc_get_xlat_entry(const void *old)
{
void **retval;
- if (zend_hash_index_find(&xlat_table, (ulong) old, (void **) &retval)==FAILURE) {
+ if (zend_hash_index_find(&xlat_table, (ulong)old, (void **)&retval) == FAILURE) {
return NULL;
}
return *retval;
size_t zend_shared_alloc_get_largest_free_block(void)
{
int i;
- size_t largest_block_size=0;
+ size_t largest_block_size = 0;
- for (i=0; i<ZSMMG(shared_segments_count); i++) {
+ for (i = 0; i < ZSMMG(shared_segments_count); i++) {
size_t block_size = ZSMMG(shared_segments)[i]->size - ZSMMG(shared_segments)[i]->pos;
if (block_size>largest_block_size) {
{
int i;
- for (i=0; i<ZSMMG(shared_segments_count); i++) {
+ for (i = 0; i < ZSMMG(shared_segments_count); i++) {
ZSMMG(shared_memory_state).positions[i] = ZSMMG(shared_segments)[i]->pos;
}
ZSMMG(shared_memory_state).shared_free = ZSMMG(shared_free);
{
int i;
- for (i=0; i<ZSMMG(shared_segments_count); i++) {
+ for (i = 0; i < ZSMMG(shared_segments_count); i++) {
ZSMMG(shared_segments)[i]->pos = ZSMMG(shared_memory_state).positions[i];
}
ZSMMG(shared_free) = ZSMMG(shared_memory_state).shared_free;
mode = PROT_READ|PROT_WRITE;
}
- for(i=0; i < ZSMMG(shared_segments_count); i++) {
+ for (i = 0; i < ZSMMG(shared_segments_count); i++) {
mprotect(ZSMMG(shared_segments)[i]->p, ZSMMG(shared_segments)[i]->size, mode);
}
#endif