1
0
mirror of https://github.com/php/php-src.git synced 2026-04-11 01:53:36 +02:00

Merge branch 'refactoring2' of github.com:zend-dev/php into refactoring2

This commit is contained in:
Dmitry Stogov
2014-02-21 18:55:26 +04:00
12 changed files with 476 additions and 383 deletions

View File

@@ -733,11 +733,11 @@ END_EXTERN_C()
Z_SET_REFCOUNT_PP(ppzv_dest, refcount); \
}
#define SEPARATE_ARG_IF_REF(varptr) \
if (Z_ISREF_P(varptr)) { \
ZVAL_DUP(varptr, Z_REFVAL_P(varptr)); \
} else { \
Z_ADDREF_P(varptr); \
#define SEPARATE_ARG_IF_REF(varptr) \
if (Z_ISREF_P(varptr)) { \
ZVAL_DUP(varptr, Z_REFVAL_P(varptr)); \
} else if (IS_REFCOUNTED(Z_TYPE_P(varptr))) { \
Z_ADDREF_P(varptr); \
}
#define READY_TO_DESTROY(zv) \

View File

@@ -176,7 +176,9 @@ ZEND_API int zend_copy_parameters_array(int param_count, zval *argument_array TS
while (param_count-->0) {
zval *param = p-(arg_count--);
Z_ADDREF_P(param);
if (Z_REFCOUNTED_P(param)) {
Z_ADDREF_P(param);
}
add_next_index_zval(argument_array, param);
}
@@ -3151,7 +3153,7 @@ ZEND_API zend_bool zend_is_callable_ex(zval *callable, zval *object_ptr, uint ch
}
} else {
if (!!EG(objects_store).object_buckets ||
if (!EG(objects_store).object_buckets ||
!IS_VALID(EG(objects_store).object_buckets[Z_OBJ_HANDLE_P(obj)])) {
return 0;
}

View File

@@ -1906,7 +1906,6 @@ void zend_do_receive_param(zend_uchar op, znode *varname, const znode *initializ
cur_arg_info->allow_null = 1;
cur_arg_info->is_variadic = is_variadic;
cur_arg_info->class_name = NULL;
cur_arg_info->class_name_len = 0;
if (class_type->op_type != IS_UNUSED) {
cur_arg_info->allow_null = 0;
@@ -1936,8 +1935,7 @@ void zend_do_receive_param(zend_uchar op, znode *varname, const znode *initializ
zend_resolve_class_name(class_type TSRMLS_CC);
}
Z_STR(class_type->u.constant) = zend_new_interned_string(Z_STR(class_type->u.constant) TSRMLS_CC);
cur_arg_info->class_name = Z_STRVAL(class_type->u.constant);
cur_arg_info->class_name_len = Z_STRLEN(class_type->u.constant);
cur_arg_info->class_name = STR_COPY(Z_STR(class_type->u.constant));
if (op == ZEND_RECV_INIT) {
if (Z_TYPE(initialization->u.constant) == IS_NULL || (Z_TYPE(initialization->u.constant) == IS_CONSTANT && !strcasecmp(Z_STRVAL(initialization->u.constant), "NULL")) || Z_TYPE(initialization->u.constant) == IS_CONSTANT_AST) {
cur_arg_info->allow_null = 1;
@@ -3283,32 +3281,20 @@ static zend_bool zend_do_perform_implementation_check(const zend_function *fe, c
if (fe_arg_info->class_name) {
zend_string *fe_class_name, *proto_class_name;
if (!strcasecmp(fe_arg_info->class_name, "parent") && proto->common.scope) {
fe_class_name = STR_INIT(
proto->common.scope->name->val,
proto->common.scope->name->len, 0);
} else if (!strcasecmp(fe_arg_info->class_name, "self") && fe->common.scope) {
fe_class_name = STR_INIT(
fe->common.scope->name->val,
fe->common.scope->name->len, 0);
if (!strcasecmp(fe_arg_info->class_name->val, "parent") && proto->common.scope) {
fe_class_name = proto->common.scope->name;
} else if (!strcasecmp(fe_arg_info->class_name->val, "self") && fe->common.scope) {
fe_class_name = fe->common.scope->name;
} else {
fe_class_name = STR_INIT(
fe_arg_info->class_name,
fe_arg_info->class_name_len, 0);
fe_class_name = fe_arg_info->class_name;
}
if (!strcasecmp(proto_arg_info->class_name, "parent") && proto->common.scope && proto->common.scope->parent) {
proto_class_name = STR_INIT(
proto->common.scope->parent->name->val,
proto->common.scope->parent->name->len, 0);
} else if (!strcasecmp(proto_arg_info->class_name, "self") && proto->common.scope) {
proto_class_name = STR_INIT(
proto->common.scope->name->val,
proto->common.scope->name->len, 0);
if (!strcasecmp(proto_arg_info->class_name->val, "parent") && proto->common.scope && proto->common.scope->parent) {
proto_class_name = proto->common.scope->parent->name;
} else if (!strcasecmp(proto_arg_info->class_name->val, "self") && proto->common.scope) {
proto_class_name = proto->common.scope->name;
} else {
proto_class_name = STR_INIT(
proto_arg_info->class_name,
proto_arg_info->class_name_len, 0);
proto_class_name = proto_arg_info->class_name;
}
if (strcasecmp(fe_class_name->val, proto_class_name->val)!=0) {
@@ -3388,21 +3374,17 @@ static char * zend_get_function_declaration(zend_function *fptr TSRMLS_DC) /* {{
required = fptr->common.required_num_args;
for (i = 0; i < fptr->common.num_args;) {
if (arg_info->class_name) {
const char *class_name;
zend_uint class_name_len;
if (!strcasecmp(arg_info->class_name, "self") && fptr->common.scope ) {
class_name = fptr->common.scope->name->val;
class_name_len = fptr->common.scope->name->len;
} else if (!strcasecmp(arg_info->class_name, "parent") && fptr->common.scope->parent) {
class_name = fptr->common.scope->parent->name->val;
class_name_len = fptr->common.scope->parent->name->len;
zend_string *class_name;
if (!strcasecmp(arg_info->class_name->val, "self") && fptr->common.scope ) {
class_name = fptr->common.scope->name;
} else if (!strcasecmp(arg_info->class_name->val, "parent") && fptr->common.scope->parent) {
class_name = fptr->common.scope->parent->name;
} else {
class_name = arg_info->class_name;
class_name_len = arg_info->class_name_len;
}
REALLOC_BUF_IF_EXCEED(buf, offset, length, class_name_len);
memcpy(offset, class_name, class_name_len);
offset += class_name_len;
REALLOC_BUF_IF_EXCEED(buf, offset, length, class_name->len);
memcpy(offset, class_name->val, class_name->len);
offset += class_name->len;
*(offset++) = ' ';
} else if (arg_info->type_hint) {
zend_uint type_name_len;

View File

@@ -228,10 +228,10 @@ typedef struct _zend_property_info {
typedef struct _zend_arg_info {
const char *name;
zend_uint name_len;
const char *class_name;
zend_uint class_name_len;
//??? zend_string *name;
//??? zend_string *class_name;
//??? const char *class_name;
// zend_uint class_name_len;
// zend_string *name;
zend_string *class_name;
zend_uchar type_hint;
zend_uchar pass_by_reference;
zend_bool allow_null;

View File

@@ -642,9 +642,8 @@ static inline void make_real_object(zval *object_ptr TSRMLS_DC)
ZEND_API char * zend_verify_arg_class_kind(const zend_arg_info *cur_arg_info, ulong fetch_type, char **class_name, zend_class_entry **pce TSRMLS_DC)
{
zend_string *key = STR_INIT(cur_arg_info->class_name, cur_arg_info->class_name_len, 0);
zend_string *key = cur_arg_info->class_name;
*pce = zend_fetch_class(key, (fetch_type | ZEND_FETCH_CLASS_AUTO | ZEND_FETCH_CLASS_NO_AUTOLOAD) TSRMLS_CC);
STR_FREE(key);
*class_name = (*pce) ? (*pce)->name->val : (char*)cur_arg_info->class_name;
if (*pce && (*pce)->ce_flags & ZEND_ACC_INTERFACE) {
return "implement interface ";

View File

@@ -831,31 +831,33 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TS
zval *param;
if (ARG_SHOULD_BE_SENT_BY_REF(EX(function_state).function, i + 1)) {
if (!Z_ISREF(fci->params[i]) && Z_REFCOUNT(fci->params[i]) > 1) {
zval new_zval;
if (Z_REFCOUNTED(fci->params[i])) {
if (!Z_ISREF(fci->params[i]) && Z_REFCOUNT(fci->params[i]) > 1) {
zval new_zval;
if (fci->no_separation &&
!ARG_MAY_BE_SENT_BY_REF(EX(function_state).function, i + 1)) {
if (i || UNEXPECTED(ZEND_VM_STACK_ELEMETS(EG(argument_stack)) == (EG(argument_stack)->top))) {
/* hack to clean up the stack */
ZVAL_LONG(&tmp, i);
zend_vm_stack_push(&tmp TSRMLS_CC);
zend_vm_stack_clear_multiple(0 TSRMLS_CC);
if (fci->no_separation &&
!ARG_MAY_BE_SENT_BY_REF(EX(function_state).function, i + 1)) {
if (i || UNEXPECTED(ZEND_VM_STACK_ELEMETS(EG(argument_stack)) == (EG(argument_stack)->top))) {
/* hack to clean up the stack */
ZVAL_LONG(&tmp, i);
zend_vm_stack_push(&tmp TSRMLS_CC);
zend_vm_stack_clear_multiple(0 TSRMLS_CC);
}
zend_error(E_WARNING, "Parameter %d to %s%s%s() expected to be a reference, value given",
i+1,
EX(function_state).function->common.scope ? EX(function_state).function->common.scope->name->val : "",
EX(function_state).function->common.scope ? "::" : "",
EX(function_state).function->common.function_name->val);
return FAILURE;
}
zend_error(E_WARNING, "Parameter %d to %s%s%s() expected to be a reference, value given",
i+1,
EX(function_state).function->common.scope ? EX(function_state).function->common.scope->name->val : "",
EX(function_state).function->common.scope ? "::" : "",
EX(function_state).function->common.function_name->val);
return FAILURE;
ZVAL_DUP(&new_zval, &fci->params[i]);
Z_DELREF(fci->params[i]);
ZVAL_COPY_VALUE(&fci->params[i], &new_zval);
}
ZVAL_DUP(&new_zval, &fci->params[i]);
Z_DELREF(fci->params[i]);
ZVAL_COPY_VALUE(&fci->params[i], &new_zval);
Z_ADDREF(fci->params[i]);
}
Z_ADDREF(fci->params[i]);
//??? Z_SET_ISREF_PP(fci->params[i]);
param = &fci->params[i];
} else if (Z_ISREF(fci->params[i]) &&

View File

@@ -62,6 +62,7 @@ ZEND_API zval* zend_call_method(zval *object, zend_class_entry *obj_ce, zend_fun
* needed later inside zend_call_function. */
fci.function_table = !object ? EG(function_table) : NULL;
result = zend_call_function(&fci, NULL TSRMLS_CC);
zval_ptr_dtor(&fci.function_name);
} else {
zend_fcall_info_cache fcic;
@@ -97,6 +98,7 @@ ZEND_API zval* zend_call_method(zval *object, zend_class_entry *obj_ce, zend_fun
}
fcic.object_ptr = object;
result = zend_call_function(&fci, &fcic TSRMLS_CC);
zval_ptr_dtor(&fci.function_name);
}
if (result == FAILURE) {
/* error at c-level */

View File

@@ -1527,9 +1527,9 @@ ZEND_API int zend_std_cast_object_tostring(zval *readobj, zval *writeobj, int ty
if (EXPECTED(Z_TYPE(retval) == IS_STRING)) {
//??? INIT_PZVAL(writeobj);
if (readobj == writeobj) {
zval_dtor(readobj);
zval_ptr_dtor(readobj);
}
ZVAL_ZVAL(writeobj, &retval, 1, 1);
ZVAL_COPY_VALUE(writeobj, &retval);
if (Z_TYPE_P(writeobj) != type) {
convert_to_explicit_type(writeobj, type);
}
@@ -1538,7 +1538,7 @@ ZEND_API int zend_std_cast_object_tostring(zval *readobj, zval *writeobj, int ty
zval_ptr_dtor(&retval);
//??? INIT_PZVAL(writeobj);
if (readobj == writeobj) {
zval_dtor(readobj);
zval_ptr_dtor(readobj);
}
ZVAL_EMPTY_STRING(writeobj);
zend_error(E_RECOVERABLE_ERROR, "Method %s::__toString() must return a string value", ce->name->val);

View File

@@ -412,7 +412,7 @@ ZEND_API void destroy_op_array(zend_op_array *op_array TSRMLS_DC)
efree((char*)op_array->arg_info[i].name);
if (op_array->arg_info[i].class_name) {
//??? str_efree(op_array->arg_info[i].class_name);
efree((char*)op_array->arg_info[i].class_name);
STR_RELEASE(op_array->arg_info[i].class_name);
}
}
efree(op_array->arg_info);

View File

@@ -1025,7 +1025,9 @@ ZEND_VM_HELPER_EX(zend_fetch_var_address_helper, CONST|TMP|VAR|CV, UNUSED|CONST|
zend_error(E_NOTICE,"Undefined variable: %s", Z_STRVAL_P(varname));
/* break missing intentionally */
case BP_VAR_IS:
ZVAL_NULL(retval);
//???
//ZVAL_NULL(retval);
ZVAL_NULL(EX_VAR(opline->result.var));
break;
case BP_VAR_RW:
zend_error(E_NOTICE,"Undefined variable: %s", Z_STRVAL_P(varname));
@@ -1060,30 +1062,33 @@ ZEND_VM_HELPER_EX(zend_fetch_var_address_helper, CONST|TMP|VAR|CV, UNUSED|CONST|
if (OP1_TYPE != IS_CONST && varname == &tmp_varname) {
zval_dtor(&tmp_varname);
}
if (opline->extended_value & ZEND_FETCH_MAKE_REF) {
SEPARATE_ZVAL_TO_MAKE_IS_REF(retval);
}
if (IS_REFCOUNTED(Z_TYPE_P(retval))) Z_ADDREF_P(retval);
switch (type) {
case BP_VAR_R:
case BP_VAR_IS:
ZVAL_COPY_VALUE(EX_VAR(opline->result.var), retval);
break;
case BP_VAR_UNSET: {
//??? zend_free_op free_res;
//???
//??? PZVAL_UNLOCK(*retval, &free_res);
//??? if (retval != &EG(uninitialized_zval_ptr)) {
//??? SEPARATE_ZVAL_IF_NOT_REF(retval);
//??? }
//??? PZVAL_LOCK(*retval);
//??? FREE_OP_VAR_PTR(free_res);
}
/* break missing intentionally */
default:
ZVAL_INDIRECT(EX_VAR(opline->result.var), retval);
break;
if (EXPECTED(retval)) {
if (IS_REFCOUNTED(Z_TYPE_P(retval))) Z_ADDREF_P(retval);
switch (type) {
case BP_VAR_R:
case BP_VAR_IS:
ZVAL_COPY_VALUE(EX_VAR(opline->result.var), retval);
break;
case BP_VAR_UNSET: {
//??? zend_free_op free_res;
//???
//??? PZVAL_UNLOCK(*retval, &free_res);
//??? if (retval != &EG(uninitialized_zval_ptr)) {
//??? SEPARATE_ZVAL_IF_NOT_REF(retval);
//??? }
//??? PZVAL_LOCK(*retval);
//??? FREE_OP_VAR_PTR(free_res);
}
/* break missing intentionally */
default:
ZVAL_INDIRECT(EX_VAR(opline->result.var), retval);
break;
}
}
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
@@ -3620,7 +3625,9 @@ ZEND_VM_HANDLER(72, ZEND_ADD_ARRAY_ELEMENT, CONST|TMP|VAR|CV, CONST|TMP|VAR|UNUS
zend_error_noreturn(E_ERROR, "Cannot create references to/from string offsets");
}
SEPARATE_ZVAL_TO_MAKE_IS_REF(expr_ptr);
Z_ADDREF_P(expr_ptr);
if (Z_COUNTED_P(expr_ptr)) {
Z_ADDREF_P(expr_ptr);
}
} else {
expr_ptr=GET_OP1_ZVAL_PTR(BP_VAR_R);
if (IS_OP1_TMP_FREE()) { /* temporary variable */
@@ -3634,7 +3641,7 @@ ZEND_VM_HANDLER(72, ZEND_ADD_ARRAY_ELEMENT, CONST|TMP|VAR|CV, CONST|TMP|VAR|UNUS
ZVAL_DUP(&new_expr, expr_ptr);
expr_ptr = &new_expr;
FREE_OP1_IF_VAR();
} else if (OP1_TYPE == IS_CV) {
} else if (OP1_TYPE == IS_CV && Z_COUNTED_P(expr_ptr)) {
Z_ADDREF_P(expr_ptr);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -3318,8 +3318,8 @@ PHP_FUNCTION(addcslashes)
Escapes single quote, double quotes and backslash characters in a string with backslashes */
PHP_FUNCTION(addslashes)
{
char *str;
int str_len;
char *str, *new_str;
int str_len, new_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) {
return;
@@ -3333,10 +3333,9 @@ PHP_FUNCTION(addslashes)
//??? str_len,
//??? &Z_STRLEN_P(return_value), 0
//??? TSRMLS_CC), 0);
RETURN_STRING(php_addslashes(str,
str_len,
&Z_STRLEN_P(return_value), 0
TSRMLS_CC));
new_str = php_addslashes(str, str_len, &new_len, 0 TSRMLS_CC);
RETVAL_STRINGL(new_str, new_len);
efree(new_str);
}
/* }}} */