Skip to content

Commit

Permalink
Replaced EG(This) and EX(object) with EX(This).
Browse files Browse the repository at this point in the history
Internal functions now recieves zend_execute_data as the first argument.
  • Loading branch information
dstogov committed Oct 3, 2014
1 parent 5e39d0c commit bd9a234
Show file tree
Hide file tree
Showing 26 changed files with 325 additions and 333 deletions.
11 changes: 5 additions & 6 deletions Zend/zend.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@
# define HANDLE_UNBLOCK_INTERRUPTIONS() ZEND_SIGNAL_UNBLOCK_INTERRUPTIONS()
#endif

#define INTERNAL_FUNCTION_PARAMETERS uint32_t param_count, zval *return_value TSRMLS_DC
#define INTERNAL_FUNCTION_PARAM_PASSTHRU param_count, return_value TSRMLS_CC
#define INTERNAL_FUNCTION_PARAMETERS zend_execute_data *execute_data, zval *return_value TSRMLS_DC
#define INTERNAL_FUNCTION_PARAM_PASSTHRU execute_data, return_value TSRMLS_CC

#define USED_RET() \
(!EG(current_execute_data) || \
!EG(current_execute_data)->prev_execute_data || \
!ZEND_USER_CODE(EG(current_execute_data)->prev_execute_data->func->common.type) || \
!(EG(current_execute_data)->prev_execute_data->opline->result_type & EXT_TYPE_UNUSED))
(!EX(prev_execute_data) || \
!ZEND_USER_CODE(EX(prev_execute_data)->func->common.type) || \
!(EX(prev_execute_data)->opline->result_type & EXT_TYPE_UNUSED))

#ifdef HAVE_NORETURN
# if defined(ZEND_WIN32)
Expand Down
69 changes: 51 additions & 18 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -2854,8 +2854,8 @@ static int zend_is_callable_check_class(zend_string *name, zend_fcall_info_cache
} else {
fcc->called_scope = EG(current_execute_data) ? EG(current_execute_data)->called_scope : NULL;
fcc->calling_scope = EG(scope);
if (!fcc->object && Z_OBJ(EG(This))) {
fcc->object = Z_OBJ(EG(This));
if (!fcc->object && EG(current_execute_data) && Z_OBJ(EG(current_execute_data)->This)) {
fcc->object = Z_OBJ(EG(current_execute_data)->This);
}
ret = 1;
}
Expand All @@ -2867,8 +2867,8 @@ static int zend_is_callable_check_class(zend_string *name, zend_fcall_info_cache
} else {
fcc->called_scope = EG(current_execute_data) ? EG(current_execute_data)->called_scope : NULL;
fcc->calling_scope = EG(scope)->parent;
if (!fcc->object && Z_OBJ(EG(This))) {
fcc->object = Z_OBJ(EG(This));
if (!fcc->object && EG(current_execute_data) && Z_OBJ(EG(current_execute_data)->This)) {
fcc->object = Z_OBJ(EG(current_execute_data)->This);
}
*strict_class = 1;
ret = 1;
Expand All @@ -2879,8 +2879,8 @@ static int zend_is_callable_check_class(zend_string *name, zend_fcall_info_cache
} else {
fcc->called_scope = EG(current_execute_data)->called_scope;
fcc->calling_scope = EG(current_execute_data)->called_scope;
if (!fcc->object && Z_OBJ(EG(This))) {
fcc->object = Z_OBJ(EG(This));
if (!fcc->object && Z_OBJ(EG(current_execute_data)->This)) {
fcc->object = Z_OBJ(EG(current_execute_data)->This);
}
*strict_class = 1;
ret = 1;
Expand All @@ -2894,11 +2894,11 @@ static int zend_is_callable_check_class(zend_string *name, zend_fcall_info_cache
}
scope = ex ? ex->func->common.scope : NULL;
fcc->calling_scope = ce;
if (scope && !fcc->object && Z_OBJ(EG(This)) &&
instanceof_function(Z_OBJCE(EG(This)), scope TSRMLS_CC) &&
if (scope && !fcc->object && EG(current_execute_data) && Z_OBJ(EG(current_execute_data)->This) &&
instanceof_function(Z_OBJCE(EG(current_execute_data)->This), scope TSRMLS_CC) &&
instanceof_function(scope, fcc->calling_scope TSRMLS_CC)) {
fcc->object = Z_OBJ(EG(This));
fcc->called_scope = Z_OBJCE(EG(This));
fcc->object = Z_OBJ(EG(current_execute_data)->This);
fcc->called_scope = Z_OBJCE(EG(current_execute_data)->This);
} else {
fcc->called_scope = fcc->object ? zend_get_class_entry(fcc->object TSRMLS_CC) : fcc->calling_scope;
}
Expand Down Expand Up @@ -3099,10 +3099,10 @@ static int zend_is_callable_check_func(int check_flags, zval *callable, zend_fca
if (fcc->function_handler) {
retval = 1;
call_via_handler = (fcc->function_handler->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0;
if (call_via_handler && !fcc->object && Z_OBJ(EG(This)) &&
Z_OBJ_HT(EG(This))->get_class_entry &&
instanceof_function(Z_OBJCE(EG(This)), fcc->calling_scope TSRMLS_CC)) {
fcc->object = Z_OBJ(EG(This));
if (call_via_handler && !fcc->object && EG(current_execute_data) && Z_OBJ(EG(current_execute_data)->This) &&
Z_OBJ_HT(EG(current_execute_data)->This)->get_class_entry &&
instanceof_function(Z_OBJCE(EG(current_execute_data)->This), fcc->calling_scope TSRMLS_CC)) {
fcc->object = Z_OBJ(EG(current_execute_data)->This);
}
}
}
Expand Down Expand Up @@ -3131,15 +3131,15 @@ static int zend_is_callable_check_func(int check_flags, zval *callable, zend_fca
if ((check_flags & IS_CALLABLE_CHECK_IS_STATIC) != 0) {
retval = 0;
}
if (Z_OBJ(EG(This)) && instanceof_function(Z_OBJCE(EG(This)), fcc->calling_scope TSRMLS_CC)) {
fcc->object = Z_OBJ(EG(This));
if (EG(current_execute_data) && Z_OBJ(EG(current_execute_data)->This) && instanceof_function(Z_OBJCE(EG(current_execute_data)->This), fcc->calling_scope TSRMLS_CC)) {
fcc->object = Z_OBJ(EG(current_execute_data)->This);
if (error) {
zend_spprintf(error, 0, "non-static method %s::%s() %s be called statically, assuming $this from compatible context %s", fcc->calling_scope->name->val, fcc->function_handler->common.function_name->val, verb, Z_OBJCE(EG(This))->name->val);
zend_spprintf(error, 0, "non-static method %s::%s() %s be called statically, assuming $this from compatible context %s", fcc->calling_scope->name->val, fcc->function_handler->common.function_name->val, verb, Z_OBJCE(EG(current_execute_data)->This)->name->val);
if (severity == E_ERROR) {
retval = 0;
}
} else if (retval) {
zend_error(severity, "Non-static method %s::%s() %s be called statically, assuming $this from compatible context %s", fcc->calling_scope->name->val, fcc->function_handler->common.function_name->val, verb, Z_OBJCE(EG(This))->name->val);
zend_error(severity, "Non-static method %s::%s() %s be called statically, assuming $this from compatible context %s", fcc->calling_scope->name->val, fcc->function_handler->common.function_name->val, verb, Z_OBJCE(EG(current_execute_data)->This)->name->val);
}
} else {
if (error) {
Expand Down Expand Up @@ -4147,6 +4147,39 @@ ZEND_API zend_string *zend_resolve_method_name(zend_class_entry *ce, zend_functi
}
/* }}} */

ZEND_API void zend_ctor_make_null(zend_execute_data *execute_data) /* {{{ */
{
if (EX(return_value)) {
/*
if (Z_TYPE_P(EX(return_value)) == IS_OBJECT) {
zend_object *object = Z_OBJ_P(EX(return_value));
zend_execute_data *ex = EX(prev_execute_data);
while (ex && Z_OBJ(ex->This) == object) {
if (ex->func) {
if (ZEND_USER_CODE(ex->func->type)) {
if (ex->func->op_array.this_var != -1) {
zval *this_var = EX_VAR_2(ex, ex->func->op_array.this_var);
if (this_var != EX(return_value)) {
zval_ptr_dtor(this_var);
ZVAL_NULL(this_var);
}
}
}
}
Z_OBJ(ex->This) = NULL;
ZVAL_NULL(&ex->This);
ex = ex->prev_execute_data;
}
}
*/
zval_ptr_dtor(EX(return_value));
Z_OBJ_P(EX(return_value)) = NULL;
ZVAL_NULL(EX(return_value));
}
}
/* }}} */

/*
* Local variables:
* tab-width: 4
Expand Down
34 changes: 9 additions & 25 deletions Zend/zend_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,12 @@ ZEND_API zend_class_entry *zend_get_class_entry(const zend_object *object TSRMLS
ZEND_API zend_string *zend_get_object_classname(const zend_object *object TSRMLS_DC);
ZEND_API char *zend_get_type_by_const(int type);

#define getThis() (Z_OBJ(EG(This)) ? &EG(This) : NULL)
#define getThis() (Z_OBJ(EX(This)) ? &EX(This) : NULL)

#define WRONG_PARAM_COUNT ZEND_WRONG_PARAM_COUNT()
#define WRONG_PARAM_COUNT_WITH_RETVAL(ret) ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)
#define ARG_COUNT(dummy) (param_count)
#define ZEND_NUM_ARGS() (param_count)
#define ARG_COUNT(dummy) EX(num_args)
#define ZEND_NUM_ARGS() EX(num_args)
#define ZEND_WRONG_PARAM_COUNT() { zend_wrong_param_count(TSRMLS_C); return; }
#define ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret) { zend_wrong_param_count(TSRMLS_C); return ret; }

Expand Down Expand Up @@ -531,6 +531,8 @@ ZEND_API int zend_set_local_var_str(const char *name, int len, zval *value, int
ZEND_API zend_string *zend_find_alias_name(zend_class_entry *ce, zend_string *name);
ZEND_API zend_string *zend_resolve_method_name(zend_class_entry *ce, zend_function *f);

ZEND_API void zend_ctor_make_null(zend_execute_data *execute_data);

#define add_method(arg, key, method) add_assoc_function((arg), (key), (method))

ZEND_API ZEND_FUNCTION(display_disabled_function);
Expand Down Expand Up @@ -639,26 +641,8 @@ END_EXTERN_C()
} while (0)

/* May be used in internal constructors to make them return NULL */
#if 1 // support for directly called constructors only ???
#define ZEND_CTOR_MAKE_NULL() do { \
if (EG(current_execute_data)->return_value) { \
zval_ptr_dtor(EG(current_execute_data)->return_value); \
ZVAL_NULL(EG(current_execute_data)->return_value); \
} \
} while (0)
#else // attempt to support calls to parent::__construct() ???
// see: ext/date/tests/bug67118.phpt
#define ZEND_CTOR_MAKE_NULL() do { \
if (EG(current_execute_data)->return_value) { \
zval_ptr_dtor(EG(current_execute_data)->return_value); \
ZVAL_NULL(EG(current_execute_data)->return_value); \
} else if (EG(current_execute_data)->prev_execute_data && \
EG(current_execute_data)->prev_execute_data->object == \
EG(current_execute_data)->object) { \
EG(current_execute_data)->prev_execute_data->object = NULL; \
} \
} while (0)
#endif
#define ZEND_CTOR_MAKE_NULL() \
zend_ctor_make_null(execute_data)

#define RETURN_ZVAL_FAST(z) { RETVAL_ZVAL_FAST(z); return; }

Expand Down Expand Up @@ -729,7 +713,7 @@ ZEND_API int _z_param_class(zval *arg, zend_class_entry **pce, int num, int chec
const int _flags = (flags); \
int _min_num_args = (min_num_args); \
int _max_num_args = (max_num_args); \
int _num_args = EG(current_execute_data)->num_args; \
int _num_args = EX(num_args); \
int _i; \
zval *_real_arg, *_arg = NULL; \
zend_expected_type _expected_type = IS_UNDEF; \
Expand All @@ -756,7 +740,7 @@ ZEND_API int _z_param_class(zval *arg, zend_class_entry **pce, int num, int chec
break; \
} \
_i = 0; \
_real_arg = ZEND_CALL_ARG(EG(current_execute_data), 0);
_real_arg = ZEND_CALL_ARG(execute_data, 0);

#define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args) \
ZEND_PARSE_PARAMETERS_START_EX(0, min_num_args, max_num_args)
Expand Down
16 changes: 8 additions & 8 deletions Zend/zend_builtin_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ ZEND_FUNCTION(gc_disable)
Get the number of arguments that were passed to the function */
ZEND_FUNCTION(func_num_args)
{
zend_execute_data *ex = EG(current_execute_data)->prev_execute_data;
zend_execute_data *ex = EX(prev_execute_data);

if (ex->frame_kind == VM_FRAME_NESTED_FUNCTION || ex->frame_kind == VM_FRAME_TOP_FUNCTION) {
RETURN_LONG(ex->num_args);
Expand Down Expand Up @@ -429,7 +429,7 @@ ZEND_FUNCTION(func_get_arg)
RETURN_FALSE;
}

ex = EG(current_execute_data)->prev_execute_data;
ex = EX(prev_execute_data);
if (ex->frame_kind != VM_FRAME_NESTED_FUNCTION && ex->frame_kind != VM_FRAME_TOP_FUNCTION) {
zend_error(E_WARNING, "func_get_arg(): Called from the global scope - no function context");
RETURN_FALSE;
Expand Down Expand Up @@ -462,7 +462,7 @@ ZEND_FUNCTION(func_get_args)
zval *p;
uint32_t arg_count, first_extra_arg;
uint32_t i;
zend_execute_data *ex = EG(current_execute_data)->prev_execute_data;
zend_execute_data *ex = EX(prev_execute_data);

if (ex->frame_kind != VM_FRAME_NESTED_FUNCTION && ex->frame_kind != VM_FRAME_TOP_FUNCTION) {
zend_error(E_WARNING, "func_get_args(): Called from the global scope - no function context");
Expand Down Expand Up @@ -823,8 +823,8 @@ ZEND_FUNCTION(get_called_class)
return;
}

if (EG(current_execute_data)->called_scope) {
RETURN_STR(zend_string_copy(EG(current_execute_data)->called_scope->name));
if (EX(called_scope)) {
RETURN_STR(zend_string_copy(EX(called_scope)->name));
} else if (!EG(scope)) {
zend_error(E_WARNING, "get_called_class() called from outside a class");
}
Expand Down Expand Up @@ -2132,7 +2132,7 @@ ZEND_FUNCTION(debug_print_backtrace)
}

ZVAL_UNDEF(&arg_array);
ptr = EG(current_execute_data)->prev_execute_data;
ptr = EX(prev_execute_data);

/* skip debug_backtrace() */
call = ptr;
Expand Down Expand Up @@ -2172,7 +2172,7 @@ ZEND_FUNCTION(debug_print_backtrace)
}

/* $this may be passed into regular internal functions */
object = call->object;
object = Z_OBJ(call->This);
if (object &&
call &&
call->func->type == ZEND_INTERNAL_FUNCTION &&
Expand Down Expand Up @@ -2394,7 +2394,7 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int
}

/* $this may be passed into regular internal functions */
object = call ? call->object : NULL;
object = call ? Z_OBJ(call->This) : NULL;
if (object &&
call->func &&
call->func->type == ZEND_INTERNAL_FUNCTION &&
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_closures.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static zend_object_handlers closure_handlers;

ZEND_METHOD(Closure, __invoke) /* {{{ */
{
zend_function *func = EG(current_execute_data)->func;
zend_function *func = EX(func);
zval *arguments;

arguments = emalloc(sizeof(zval) * ZEND_NUM_ARGS());
Expand Down
6 changes: 2 additions & 4 deletions Zend/zend_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ void zend_compile_var(znode *node, zend_ast *ast, uint32_t type TSRMLS_DC);
void zend_eval_const_expr(zend_ast **ast_ptr TSRMLS_DC);
void zend_const_expr_to_zval(zval *result, zend_ast *ast TSRMLS_DC);

typedef struct _zend_execute_data zend_execute_data;

#define ZEND_OPCODE_HANDLER_ARGS zend_execute_data *execute_data TSRMLS_DC
#define ZEND_OPCODE_HANDLER_ARGS_PASSTHRU execute_data TSRMLS_CC

Expand Down Expand Up @@ -366,7 +364,7 @@ struct _zend_execute_data {
zend_uchar flags;
zend_uchar frame_kind;
zend_class_entry *called_scope;
zend_object *object;
zval This;
zend_execute_data *prev_execute_data;
zval *return_value;
zend_class_entry *scope; /* function scope (self) */
Expand All @@ -385,7 +383,7 @@ struct _zend_execute_data {
#define ZEND_CALL_ARG(call, n) \
(((zval*)(call)) + ((n) + (ZEND_CALL_FRAME_SLOT - 1)))

#define EX(element) execute_data.element
#define EX(element) ((execute_data)->element)

#define EX_VAR_2(ex, n) ((zval*)(((char*)(ex)) + ((int)(n))))
#define EX_VAR_NUM_2(ex, n) (((zval*)(ex)) + (ZEND_CALL_FRAME_SLOT + ((int)(n))))
Expand Down
Loading

1 comment on commit bd9a234

@laruence
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

Please sign in to comment.