summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeev Suraski <zeev@php.net>2000-03-29 22:28:04 +0000
committerZeev Suraski <zeev@php.net>2000-03-29 22:28:04 +0000
commitb7cd2bfa8e340f99f6f09215e310cc3b55d4b527 (patch)
treef4876ecdcaf4e0013efb9f9de0ce9096a57938ed
parentb543f9959c5672055f8ee87d6d9ab3ab45850b2e (diff)
downloadphp-git-b7cd2bfa8e340f99f6f09215e310cc3b55d4b527.tar.gz
- Make the argument order for the stack applies more consistent with other Zend
data structures - Fix a possible corruption problem due to switch() C-level optimization
-rw-r--r--Zend/zend_compile.c24
-rw-r--r--Zend/zend_stack.c4
-rw-r--r--Zend/zend_stack.h4
3 files changed, 17 insertions, 15 deletions
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 85c0a0bb65..f2831dfced 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -976,7 +976,7 @@ static int generate_free_switch_expr(zend_switch_entry *switch_entry CLS_DC)
{
zend_op *opline;
- if (switch_entry->cond.op_type == IS_UNUSED) {
+ if (switch_entry->cond.op_type!=IS_VAR && switch_entry->cond.op_type!=IS_TMP_VAR) {
return 1;
}
@@ -993,7 +993,7 @@ static int generate_free_foreach_copy(znode *foreach_copy CLS_DC)
{
zend_op *opline;
- if (foreach_copy->op_type == IS_UNUSED) {
+ if (foreach_copy->op_type!=IS_VAR && foreach_copy->op_type!=IS_TMP_VAR) {
return 1;
}
@@ -1018,11 +1018,11 @@ void do_return(znode *expr, int do_end_vparse CLS_DC)
}
}
#ifdef ZTS
- zend_stack_apply_with_argument(&CG(switch_cond_stack), (int (*)(void *element, void *)) generate_free_switch_expr, ZEND_STACK_APPLY_TOPDOWN CLS_CC);
- zend_stack_apply_with_argument(&CG(foreach_copy_stack), (int (*)(void *element, void *)) generate_free_foreach_copy, ZEND_STACK_APPLY_TOPDOWN CLS_CC);
+ zend_stack_apply_with_argument(&CG(switch_cond_stack), ZEND_STACK_APPLY_TOPDOWN, (int (*)(void *element, void *)) generate_free_switch_expr CLS_CC);
+ zend_stack_apply_with_argument(&CG(foreach_copy_stack), ZEND_STACK_APPLY_TOPDOWN, (int (*)(void *element, void *)) generate_free_foreach_copy CLS_CC);
#else
- zend_stack_apply(&CG(switch_cond_stack), (int (*)(void *element)) generate_free_switch_expr, ZEND_STACK_APPLY_TOPDOWN);
- zend_stack_apply(&CG(foreach_copy_stack), (int (*)(void *element)) generate_free_foreach_copy, ZEND_STACK_APPLY_TOPDOWN);
+ zend_stack_apply(&CG(switch_cond_stack), ZEND_STACK_APPLY_TOPDOWN, (int (*)(void *element)) generate_free_switch_expr);
+ zend_stack_apply(&CG(foreach_copy_stack), ZEND_STACK_APPLY_TOPDOWN, (int (*)(void *element)) generate_free_foreach_copy);
#endif
opline = get_next_op(CG(active_op_array) CLS_CC);
@@ -1340,11 +1340,13 @@ void do_switch_end(znode *case_list CLS_DC)
CG(active_op_array)->brk_cont_array[CG(active_op_array)->current_brk_cont].cont = CG(active_op_array)->brk_cont_array[CG(active_op_array)->current_brk_cont].brk = get_next_op_number(CG(active_op_array));
CG(active_op_array)->current_brk_cont = CG(active_op_array)->brk_cont_array[CG(active_op_array)->current_brk_cont].parent;
- /* emit free for the switch condition*/
- opline = get_next_op(CG(active_op_array) CLS_CC);
- opline->opcode = ZEND_SWITCH_FREE;
- opline->op1 = switch_entry_ptr->cond;
- SET_UNUSED(opline->op2);
+ if (switch_entry_ptr->cond.op_type==IS_VAR || switch_entry_ptr->cond.op_type==IS_TMP_VAR) {
+ /* emit free for the switch condition*/
+ opline = get_next_op(CG(active_op_array) CLS_CC);
+ opline->opcode = ZEND_SWITCH_FREE;
+ opline->op1 = switch_entry_ptr->cond;
+ SET_UNUSED(opline->op2);
+ }
if (switch_entry_ptr->cond.op_type == IS_CONST) {
zval_dtor(&switch_entry_ptr->cond.u.constant);
}
diff --git a/Zend/zend_stack.c b/Zend/zend_stack.c
index 231f6bc0c5..3618fb1bbd 100644
--- a/Zend/zend_stack.c
+++ b/Zend/zend_stack.c
@@ -118,7 +118,7 @@ ZEND_API int zend_stack_count(zend_stack *stack)
}
-ZEND_API void zend_stack_apply(zend_stack *stack, int (*apply_function)(void *element), int type)
+ZEND_API void zend_stack_apply(zend_stack *stack, int type, int (*apply_function)(void *element))
{
int i;
@@ -141,7 +141,7 @@ ZEND_API void zend_stack_apply(zend_stack *stack, int (*apply_function)(void *el
}
-ZEND_API void zend_stack_apply_with_argument(zend_stack *stack, int (*apply_function)(void *element, void *arg), int type, void *arg)
+ZEND_API void zend_stack_apply_with_argument(zend_stack *stack, int type, int (*apply_function)(void *element, void *arg), void *arg)
{
int i;
diff --git a/Zend/zend_stack.h b/Zend/zend_stack.h
index 09daeba615..9304f647d9 100644
--- a/Zend/zend_stack.h
+++ b/Zend/zend_stack.h
@@ -38,8 +38,8 @@ ZEND_API int zend_stack_is_empty(zend_stack *stack);
ZEND_API int zend_stack_destroy(zend_stack *stack);
ZEND_API void **zend_stack_base(zend_stack *stack);
ZEND_API int zend_stack_count(zend_stack *stack);
-ZEND_API void zend_stack_apply(zend_stack *stack, int (*apply_function)(void *element), int type);
-ZEND_API void zend_stack_apply_with_argument(zend_stack *stack, int (*apply_function)(void *element, void *arg), int type, void *arg);
+ZEND_API void zend_stack_apply(zend_stack *stack, int type, int (*apply_function)(void *element));
+ZEND_API void zend_stack_apply_with_argument(zend_stack *stack, int type, int (*apply_function)(void *element, void *arg), void *arg);
#define ZEND_STACK_APPLY_TOPDOWN 1
#define ZEND_STACK_APPLY_BOTTOMUP 2