-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Restructure argument passing onto stack #1679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
89c2585
35d5225
2a230dc
82d44e6
98d9614
21e996f
6d46c57
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,7 @@ ZEND_API int zend_get_parameters(int ht, int param_count, ...) /* {{{ */ | |
ZVAL_COPY_VALUE(param_ptr, &new_tmp); | ||
} | ||
*param = param_ptr; | ||
param_ptr++; | ||
param_ptr--; | ||
} | ||
va_end(ptr); | ||
|
||
|
@@ -97,7 +97,7 @@ ZEND_API int zend_get_parameters_ex(int param_count, ...) /* {{{ */ | |
while (param_count-->0) { | ||
param = va_arg(ptr, zval **); | ||
*param = param_ptr; | ||
param_ptr++; | ||
param_ptr--; | ||
} | ||
va_end(ptr); | ||
|
||
|
@@ -120,7 +120,7 @@ ZEND_API int _zend_get_parameters_array_ex(int param_count, zval *argument_array | |
while (param_count-->0) { | ||
ZVAL_COPY_VALUE(argument_array, param_ptr); | ||
argument_array++; | ||
param_ptr++; | ||
param_ptr--; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. zend_get_parameters_array() is going to be logical inconsistent with the rest or parameter parsing API. |
||
} | ||
|
||
return SUCCESS; | ||
|
@@ -144,7 +144,7 @@ ZEND_API int zend_copy_parameters_array(int param_count, zval *argument_array) / | |
Z_ADDREF_P(param_ptr); | ||
} | ||
zend_hash_next_index_insert_new(Z_ARRVAL_P(argument_array), param_ptr); | ||
param_ptr++; | ||
param_ptr--; | ||
} | ||
|
||
return SUCCESS; | ||
|
@@ -2158,6 +2158,7 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio | |
internal_function->function_name = zend_new_interned_string(zend_string_init(ptr->fname, fname_len, 1)); | ||
internal_function->scope = scope; | ||
internal_function->prototype = NULL; | ||
internal_function->stack_size = ZEND_CALL_FRAME_SLOT * ZEND_MM_ALIGNED_SIZE(sizeof(zval)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do all internal functions use the same stack size? |
||
if (ptr->flags) { | ||
if (!(ptr->flags & ZEND_ACC_PPP_MASK)) { | ||
if (ptr->flags != ZEND_ACC_DEPRECATED || scope) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -438,10 +438,9 @@ ZEND_FUNCTION(func_num_args) | |
Get the $arg_num'th argument that was passed to the function */ | ||
ZEND_FUNCTION(func_get_arg) | ||
{ | ||
uint32_t arg_count, first_extra_arg; | ||
zval *arg; | ||
zend_long requested_offset; | ||
zend_execute_data *ex; | ||
zend_execute_data *ex = EX(prev_execute_data); | ||
|
||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &requested_offset) == FAILURE) { | ||
return; | ||
|
@@ -458,19 +457,12 @@ ZEND_FUNCTION(func_get_arg) | |
RETURN_FALSE; | ||
} | ||
|
||
arg_count = ZEND_CALL_NUM_ARGS(ex); | ||
|
||
if (requested_offset >= arg_count) { | ||
if (requested_offset >= ZEND_CALL_NUM_ARGS(ex)) { | ||
zend_error(E_WARNING, "func_get_arg(): Argument " ZEND_LONG_FMT " not passed to function", requested_offset); | ||
RETURN_FALSE; | ||
} | ||
|
||
first_extra_arg = ex->func->op_array.num_args; | ||
if (requested_offset >= first_extra_arg && (ZEND_CALL_NUM_ARGS(ex) > first_extra_arg)) { | ||
arg = ZEND_CALL_VAR_NUM(ex, ex->func->op_array.last_var + ex->func->op_array.T) + (requested_offset - first_extra_arg); | ||
} else { | ||
arg = ZEND_CALL_ARG(ex, requested_offset + 1); | ||
} | ||
arg = ZEND_CALL_ARG(ex, requested_offset + 1); | ||
if (EXPECTED(!Z_ISUNDEF_P(arg))) { | ||
ZVAL_DEREF(arg); | ||
ZVAL_COPY(return_value, arg); | ||
|
@@ -483,8 +475,7 @@ ZEND_FUNCTION(func_get_arg) | |
ZEND_FUNCTION(func_get_args) | ||
{ | ||
zval *p, *q; | ||
uint32_t arg_count, first_extra_arg; | ||
uint32_t i, n; | ||
uint32_t arg_count, i, n; | ||
zend_execute_data *ex = EX(prev_execute_data); | ||
|
||
if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) { | ||
|
@@ -496,29 +487,12 @@ ZEND_FUNCTION(func_get_args) | |
|
||
array_init_size(return_value, arg_count); | ||
if (arg_count) { | ||
first_extra_arg = ex->func->op_array.num_args; | ||
zend_hash_real_init(Z_ARRVAL_P(return_value), 1); | ||
ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { | ||
i = 0; | ||
n = 0; | ||
p = ZEND_CALL_ARG(ex, 1); | ||
if (arg_count > first_extra_arg) { | ||
while (i < first_extra_arg) { | ||
q = p; | ||
if (EXPECTED(Z_TYPE_INFO_P(q) != IS_UNDEF)) { | ||
ZVAL_DEREF(q); | ||
if (Z_OPT_REFCOUNTED_P(q)) { | ||
Z_ADDREF_P(q); | ||
} | ||
n++; | ||
} | ||
ZEND_HASH_FILL_ADD(q); | ||
p++; | ||
i++; | ||
} | ||
p = ZEND_CALL_VAR_NUM(ex, ex->func->op_array.last_var + ex->func->op_array.T); | ||
} | ||
while (i < arg_count) { | ||
do { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need special cases for "extra" arguments handling. This is good! |
||
q = p; | ||
if (EXPECTED(Z_TYPE_INFO_P(q) != IS_UNDEF)) { | ||
ZVAL_DEREF(q); | ||
|
@@ -528,9 +502,9 @@ ZEND_FUNCTION(func_get_args) | |
n++; | ||
} | ||
ZEND_HASH_FILL_ADD(q); | ||
p++; | ||
p--; | ||
i++; | ||
} | ||
} while (i < arg_count); | ||
} ZEND_HASH_FILL_END(); | ||
Z_ARRVAL_P(return_value)->nNumOfElements = n; | ||
} | ||
|
@@ -2243,25 +2217,6 @@ static void debug_backtrace_get_args(zend_execute_data *call, zval *arg_array) / | |
|
||
zend_hash_real_init(Z_ARRVAL_P(arg_array), 1); | ||
ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(arg_array)) { | ||
if (call->func->type == ZEND_USER_FUNCTION) { | ||
uint32_t first_extra_arg = call->func->op_array.num_args; | ||
|
||
if (ZEND_CALL_NUM_ARGS(call) > first_extra_arg) { | ||
while (i < first_extra_arg) { | ||
if (EXPECTED(Z_TYPE_INFO_P(p) != IS_UNDEF)) { | ||
if (Z_OPT_REFCOUNTED_P(p)) { | ||
Z_ADDREF_P(p); | ||
} | ||
n++; | ||
} | ||
ZEND_HASH_FILL_ADD(p); | ||
p++; | ||
i++; | ||
} | ||
p = ZEND_CALL_VAR_NUM(call, call->func->op_array.last_var + call->func->op_array.T); | ||
} | ||
} | ||
|
||
while (i < num_args) { | ||
if (EXPECTED(Z_TYPE_INFO_P(p) != IS_UNDEF)) { | ||
if (Z_OPT_REFCOUNTED_P(p)) { | ||
|
@@ -2270,7 +2225,7 @@ static void debug_backtrace_get_args(zend_execute_data *call, zval *arg_array) / | |
n++; | ||
} | ||
ZEND_HASH_FILL_ADD(p); | ||
p++; | ||
p--; | ||
i++; | ||
} | ||
} ZEND_HASH_FILL_END(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,7 +147,7 @@ ZEND_METHOD(Closure, call) | |
|
||
fci.retval = &closure_result; | ||
fci.params = my_params; | ||
fci.param_count = my_param_count; | ||
fci.param_count = -my_param_count; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. negative param_count looks terrible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small note: negative param count is a hack to avoid copying around. I'm open for other suggestions. (let's discuss that later.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you eliminate copy in comparison to php-7? (I didn't understand this) On Wed, Dec 16, 2015 at 5:38 PM, Bob Weinand [email protected]
|
||
fci.object = fci_cache.object = newobj; | ||
fci_cache.initialized = 1; | ||
fci_cache.called_scope = Z_OBJCE_P(newthis); | ||
|
@@ -277,6 +277,7 @@ ZEND_API zend_function *zend_get_closure_invoke_method(zend_object *object) /* { | |
invoke->internal_function.module = 0; | ||
invoke->internal_function.scope = zend_ce_closure; | ||
invoke->internal_function.function_name = zend_string_init(ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1, 0); | ||
invoke->internal_function.stack_size = ZEND_CALL_FRAME_SLOT * sizeof(zval); | ||
return invoke; | ||
} | ||
/* }}} */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should remove deprecated API by separate commit: zend_get_parameters(), zend_get_parameters_ex(), zend_copy_parameters_array().