Skip to content

Commit

Permalink
同步 php-8.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Apr 16, 2022
1 parent 7bc64ee commit 26a3605
Show file tree
Hide file tree
Showing 64 changed files with 668 additions and 331 deletions.
8 changes: 7 additions & 1 deletion Zend/Optimizer/block_pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,13 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
} else {
zval c;
ZVAL_COPY(&c, &ZEND_OP1_LITERAL(src));
if (zend_optimizer_update_op1_const(op_array, opline, &c)) {
if (opline->opcode != ZEND_CASE
&& opline->opcode != ZEND_CASE_STRICT
&& opline->opcode != ZEND_FETCH_LIST_R
&& opline->opcode != ZEND_SWITCH_LONG
&& opline->opcode != ZEND_SWITCH_STRING
&& opline->opcode != ZEND_MATCH
&& zend_optimizer_update_op1_const(op_array, opline, &c)) {
VAR_SOURCE(op1) = NULL;
literal_dtor(&ZEND_OP1_LITERAL(src));
MAKE_NOP(src);
Expand Down
3 changes: 2 additions & 1 deletion Zend/Optimizer/dce.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,8 @@ static inline bool is_free_of_live_var(context *ctx, zend_op *opline, zend_ssa_o
switch (opline->opcode) {
case ZEND_FREE:
/* It is always safe to remove FREEs of non-refcounted values, even if they are live. */
if (!may_be_refcounted(ctx->ssa->var_info[ssa_op->op1_use].type)) {
if ((ctx->ssa->var_info[ssa_op->op1_use].type & (MAY_BE_REF|MAY_BE_ANY|MAY_BE_UNDEF)) != 0
&& !may_be_refcounted(ctx->ssa->var_info[ssa_op->op1_use].type)) {
return 0;
}
ZEND_FALLTHROUGH;
Expand Down
2 changes: 2 additions & 0 deletions Zend/Optimizer/dfa_pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,7 @@ void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx

if (src_var >= 0
&& !(ssa->var_info[src_var].type & MAY_BE_REF)
&& (ssa->var_info[src_var].type & (MAY_BE_UNDEF|MAY_BE_ANY))
&& ssa->vars[src_var].definition >= 0
&& ssa->ops[ssa->vars[src_var].definition].result_def == src_var
&& ssa->ops[ssa->vars[src_var].definition].result_use < 0
Expand Down Expand Up @@ -1513,6 +1514,7 @@ void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx
if ((opline->op2_type & (IS_TMP_VAR|IS_VAR))
&& src_var >= 0
&& !(ssa->var_info[src_var].type & MAY_BE_REF)
&& (ssa->var_info[src_var].type & (MAY_BE_UNDEF|MAY_BE_ANY))
&& ssa->vars[src_var].definition >= 0
&& ssa->ops[ssa->vars[src_var].definition].result_def == src_var
&& ssa->ops[ssa->vars[src_var].definition].result_use < 0
Expand Down
8 changes: 6 additions & 2 deletions Zend/Optimizer/optimize_func_calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,18 @@ void zend_optimize_func_calls(zend_op_array *op_array, zend_optimizer_ctx *ctx)
fcall->op1.num = zend_vm_calc_used_stack(fcall->extended_value, call_stack[call].func);
literal_dtor(&ZEND_OP2_LITERAL(fcall));
fcall->op2.constant = fcall->op2.constant + 1;
opline->opcode = zend_get_call_op(fcall, call_stack[call].func);
if (opline->opcode != ZEND_CALLABLE_CONVERT) {
opline->opcode = zend_get_call_op(fcall, call_stack[call].func);
}
} else if (fcall->opcode == ZEND_INIT_NS_FCALL_BY_NAME) {
fcall->opcode = ZEND_INIT_FCALL;
fcall->op1.num = zend_vm_calc_used_stack(fcall->extended_value, call_stack[call].func);
literal_dtor(&op_array->literals[fcall->op2.constant]);
literal_dtor(&op_array->literals[fcall->op2.constant + 2]);
fcall->op2.constant = fcall->op2.constant + 1;
opline->opcode = zend_get_call_op(fcall, call_stack[call].func);
if (opline->opcode != ZEND_CALLABLE_CONVERT) {
opline->opcode = zend_get_call_op(fcall, call_stack[call].func);
}
} else if (fcall->opcode == ZEND_INIT_STATIC_METHOD_CALL
|| fcall->opcode == ZEND_INIT_METHOD_CALL
|| fcall->opcode == ZEND_NEW) {
Expand Down
6 changes: 3 additions & 3 deletions Zend/Optimizer/sccp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1524,13 +1524,13 @@ static void sccp_visit_instr(scdf_ctx *scdf, zend_op *opline, zend_ssa_op *ssa_o

dup_partial_object(&zv, op1);
ct_eval_assign_obj(&zv, &tmp2, op2);
if (opline->opcode == ZEND_PRE_INC_OBJ
|| opline->opcode == ZEND_PRE_DEC_OBJ) {
if (opline->opcode == ZEND_PRE_INC_OBJ || opline->opcode == ZEND_PRE_DEC_OBJ) {
SET_RESULT(result, &tmp2);
zval_ptr_dtor_nogc(&tmp1);
} else {
SET_RESULT(result, &tmp1);
}
zval_ptr_dtor_nogc(&tmp1);
zval_ptr_dtor_nogc(&tmp2);
SET_RESULT(op1, &zv);
zval_ptr_dtor_nogc(&zv);
break;
Expand Down
4 changes: 2 additions & 2 deletions Zend/Optimizer/zend_func_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ static uint32_t zend_range_info(const zend_call_info *call_info, const zend_ssa
|| (t3 & (MAY_BE_DOUBLE|MAY_BE_STRING))) {
tmp |= MAY_BE_ARRAY_OF_DOUBLE;
}
if ((t1 & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_STRING|MAY_BE_DOUBLE)))
&& (t2 & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_STRING|MAY_BE_DOUBLE)))) {
if ((t1 & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE))
&& (t2 & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE))) {
if ((t3 & MAY_BE_ANY) != MAY_BE_DOUBLE) {
tmp |= MAY_BE_ARRAY_OF_LONG;
}
Expand Down
18 changes: 18 additions & 0 deletions Zend/Optimizer/zend_inference.c
Original file line number Diff line number Diff line change
Expand Up @@ -2661,6 +2661,7 @@ static zend_always_inline int _zend_update_type_info(
case ZEND_ASSIGN_DIM:
if (opline->op1_type == IS_CV) {
tmp = assign_dim_result_type(t1, t2, OP1_DATA_INFO(), opline->op2_type);
tmp |= ssa->var_info[ssa_op->op1_def].type & (MAY_BE_ARRAY_PACKED|MAY_BE_ARRAY_NUMERIC_HASH|MAY_BE_ARRAY_STRING_HASH);
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
COPY_SSA_OBJ_TYPE(ssa_op->op1_use, ssa_op->op1_def);
}
Expand All @@ -2669,6 +2670,9 @@ static zend_always_inline int _zend_update_type_info(
if (t1 & MAY_BE_STRING) {
tmp |= MAY_BE_STRING | MAY_BE_NULL;
}
if (t1 & MAY_BE_OBJECT) {
tmp |= (MAY_BE_ANY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF);
}
if (t1 & (MAY_BE_ARRAY|MAY_BE_FALSE|MAY_BE_NULL|MAY_BE_UNDEF)) {
tmp |= (OP1_DATA_INFO() & (MAY_BE_ANY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF));

Expand Down Expand Up @@ -2789,6 +2793,20 @@ static zend_always_inline int _zend_update_type_info(
tmp &= ~MAY_BE_REF;
tmp |= MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_STRING|MAY_BE_RC1|MAY_BE_RCN;
}
if ((tmp & (MAY_BE_RC1|MAY_BE_RCN)) == MAY_BE_RCN) {
/* refcount may be indirectly decremented. Make an exception if the result is used in the next instruction */
if (!ssa_opcodes) {
if (ssa->vars[ssa_op->result_def].use_chain < 0
|| opline + 1 != op_array->opcodes + ssa->vars[ssa_op->result_def].use_chain) {
tmp |= MAY_BE_RC1;
}
} else {
if (ssa->vars[ssa_op->result_def].use_chain < 0
|| opline + 1 != ssa_opcodes[ssa->vars[ssa_op->result_def].use_chain]) {
tmp |= MAY_BE_RC1;
}
}
}
UPDATE_SSA_TYPE(tmp, ssa_op->result_def);
COPY_SSA_OBJ_TYPE(ssa_op->op2_use, ssa_op->result_def);
}
Expand Down
37 changes: 34 additions & 3 deletions Zend/zend.c
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,22 @@ static void function_copy_ctor(zval *zv) /* {{{ */
}
func->common.arg_info = new_arg_info + 1;
}
if (old_func->common.attributes) {
zend_attribute *old_attr;

func->common.attributes = NULL;

ZEND_HASH_FOREACH_PTR(old_func->common.attributes, old_attr) {
uint32_t i;
zend_attribute *attr;

attr = zend_add_attribute(&func->common.attributes, old_attr->name, old_attr->argc, old_attr->flags, old_attr->offset, old_attr->lineno);

for (i = 0 ; i < old_attr->argc; i++) {
ZVAL_DUP(&attr->args[i].value, &old_attr->args[i].value);
}
} ZEND_HASH_FOREACH_END();
}
}
/* }}} */

Expand Down Expand Up @@ -1249,8 +1265,6 @@ ZEND_API void zend_deactivate(void) /* {{{ */
/* we're no longer executing anything */
EG(current_execute_data) = NULL;

zend_observer_deactivate();

zend_try {
shutdown_scanner();
} zend_end_try();
Expand Down Expand Up @@ -1329,6 +1343,10 @@ ZEND_API ZEND_COLD void zend_error_zstr_at(
zend_stack loop_var_stack;
zend_stack delayed_oplines_stack;
int type = orig_type & E_ALL;
bool orig_record_errors;
uint32_t orig_num_errors;
zend_error_info **orig_errors;
zend_result res;

/* If we're executing a function during SCCP, count any warnings that may be emitted,
* but don't perform any other error handling. */
Expand Down Expand Up @@ -1422,7 +1440,20 @@ ZEND_API ZEND_COLD void zend_error_zstr_at(
CG(in_compilation) = 0;
}

if (call_user_function(CG(function_table), NULL, &orig_user_error_handler, &retval, 4, params) == SUCCESS) {
orig_record_errors = EG(record_errors);
orig_num_errors = EG(num_errors);
orig_errors = EG(errors);
EG(record_errors) = false;
EG(num_errors) = 0;
EG(errors) = NULL;

res = call_user_function(CG(function_table), NULL, &orig_user_error_handler, &retval, 4, params);

EG(record_errors) = orig_record_errors;
EG(num_errors) = orig_num_errors;
EG(errors) = orig_errors;

if (res == SUCCESS) {
if (Z_TYPE(retval) != IS_UNDEF) {
if (Z_TYPE(retval) == IS_FALSE) {
zend_error_cb(orig_type, error_filename, error_lineno, message);
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef ZEND_H
#define ZEND_H

#define ZEND_VERSION "4.1.3"
#define ZEND_VERSION "4.1.5"

#define ZEND_ENGINE_3

Expand Down
15 changes: 14 additions & 1 deletion Zend/zend_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2661,7 +2661,20 @@ ZEND_API char* ZEND_FASTCALL zend_strndup(const char *s, size_t length)
ZEND_API zend_result zend_set_memory_limit(size_t memory_limit)
{
#if ZEND_MM_LIMIT
if (UNEXPECTED(memory_limit < AG(mm_heap)->real_size)) {
zend_mm_heap *heap = AG(mm_heap);

if (UNEXPECTED(memory_limit < heap->real_size)) {
if (memory_limit >= heap->real_size - heap->cached_chunks_count * ZEND_MM_CHUNK_SIZE) {
/* free some cached chunks to fit into new memory limit */
do {
zend_mm_chunk *p = heap->cached_chunks;
heap->cached_chunks = p->next;
zend_mm_chunk_free(heap, p, ZEND_MM_CHUNK_SIZE);
heap->cached_chunks_count--;
heap->real_size -= ZEND_MM_CHUNK_SIZE;
} while (memory_limit < heap->real_size);
return SUCCESS;
}
return FAILURE;
}
AG(mm_heap)->limit = memory_limit;
Expand Down
9 changes: 7 additions & 2 deletions Zend/zend_attributes.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ ZEND_API bool zend_is_attribute_repeated(HashTable *attributes, zend_attribute *
static void attr_free(zval *v)
{
zend_attribute *attr = Z_PTR_P(v);
bool persistent = attr->flags & ZEND_ATTRIBUTE_PERSISTENT;

zend_string_release(attr->name);
zend_string_release(attr->lcname);
Expand All @@ -195,10 +196,14 @@ static void attr_free(zval *v)
if (attr->args[i].name) {
zend_string_release(attr->args[i].name);
}
zval_ptr_dtor(&attr->args[i].value);
if (persistent) {
zval_internal_ptr_dtor(&attr->args[i].value);
} else {
zval_ptr_dtor(&attr->args[i].value);
}
}

pefree(attr, attr->flags & ZEND_ATTRIBUTE_PERSISTENT);
pefree(attr, persistent);
}

ZEND_API zend_attribute *zend_add_attribute(HashTable **attributes, zend_string *name, uint32_t argc, uint32_t flags, uint32_t offset, uint32_t lineno)
Expand Down
10 changes: 9 additions & 1 deletion Zend/zend_closures.c
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,13 @@ static void zend_create_closure_ex(zval *res, zend_function *func, zend_class_en
}
ZEND_MAP_PTR_INIT(closure->func.op_array.static_variables_ptr,
&closure->func.op_array.static_variables);
} else if (func->op_array.static_variables) {
HashTable *ht = ZEND_MAP_PTR_GET(func->op_array.static_variables_ptr);

if (!ht) {
ht = zend_array_dup(func->op_array.static_variables);
ZEND_MAP_PTR_SET(closure->func.op_array.static_variables_ptr, ht);
}
}

/* Runtime cache is scope-dependent, so we cannot reuse it if the scope changed */
Expand Down Expand Up @@ -770,7 +777,8 @@ static void zend_create_closure_ex(zval *res, zend_function *func, zend_class_en

ZEND_API void zend_create_closure(zval *res, zend_function *func, zend_class_entry *scope, zend_class_entry *called_scope, zval *this_ptr)
{
zend_create_closure_ex(res, func, scope, called_scope, this_ptr, /* is_fake */ false);
zend_create_closure_ex(res, func, scope, called_scope, this_ptr,
/* is_fake */ (func->common.fn_flags & ZEND_ACC_FAKE_CLOSURE) != 0);
}

ZEND_API void zend_create_fake_closure(zval *res, zend_function *func, zend_class_entry *scope, zend_class_entry *called_scope, zval *this_ptr) /* {{{ */
Expand Down
12 changes: 12 additions & 0 deletions Zend/zend_execute_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,18 @@ ZEND_API void zend_shutdown_executor_values(bool fast_shutdown)
ZVAL_UNDEF(&c->value);
}
} ZEND_HASH_FOREACH_END();

/* properties may contain objects as well */
if (ce->default_properties_table) {
zval *p = ce->default_properties_table;
zval *end = p + ce->default_properties_count;

while (p != end) {
i_zval_ptr_dtor(p);
ZVAL_UNDEF(p);
p++;
}
}
}

if (ce->ce_flags & ZEND_HAS_STATIC_IN_METHODS) {
Expand Down
11 changes: 10 additions & 1 deletion Zend/zend_extensions.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,17 @@ ZEND_API int zend_get_resource_handle(const char *module_name)

ZEND_API int zend_get_op_array_extension_handle(const char *module_name)
{
int handle = zend_op_array_extension_handles++;
zend_add_system_entropy(module_name, "zend_get_op_array_extension_handle", &zend_op_array_extension_handles, sizeof(int));
return zend_op_array_extension_handles++;
return handle;
}

ZEND_API int zend_get_op_array_extension_handles(const char *module_name, int handles)
{
int handle = zend_op_array_extension_handles;
zend_op_array_extension_handles += handles;
zend_add_system_entropy(module_name, "zend_get_op_array_extension_handle", &zend_op_array_extension_handles, sizeof(int));
return handle;
}

ZEND_API zend_extension *zend_get_extension(const char *extension_name)
Expand Down
1 change: 1 addition & 0 deletions Zend/zend_extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ extern ZEND_API int zend_op_array_extension_handles;

ZEND_API int zend_get_resource_handle(const char *module_name);
ZEND_API int zend_get_op_array_extension_handle(const char *module_name);
ZEND_API int zend_get_op_array_extension_handles(const char *module_name, int handles);
ZEND_API void zend_extension_dispatch_message(int message, void *arg);
END_EXTERN_C()

Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_generators.c
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ ZEND_METHOD(Generator, send)

root = zend_generator_get_current(generator);
/* Put sent value in the target VAR slot, if it is used */
if (root->send_target) {
if (root->send_target && !(root->flags & ZEND_GENERATOR_CURRENTLY_RUNNING)) {
ZVAL_COPY(root->send_target, value);
}

Expand Down
10 changes: 9 additions & 1 deletion Zend/zend_interfaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ ZEND_API void zend_user_it_rewind(zend_object_iterator *_iter)
}
/* }}} */

ZEND_API HashTable *zend_user_it_get_gc(zend_object_iterator *_iter, zval **table, int *n)
{
zend_user_iterator *iter = (zend_user_iterator*)_iter;
*table = &iter->it.data;
*n = 1;
return NULL;
}

static const zend_object_iterator_funcs zend_interface_iterator_funcs_iterator = {
zend_user_it_dtor,
zend_user_it_valid,
Expand All @@ -190,7 +198,7 @@ static const zend_object_iterator_funcs zend_interface_iterator_funcs_iterator =
zend_user_it_move_forward,
zend_user_it_rewind,
zend_user_it_invalidate_current,
NULL, /* get_gc */
zend_user_it_get_gc,
};

/* {{{ zend_user_it_get_iterator */
Expand Down
1 change: 1 addition & 0 deletions Zend/zend_interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ ZEND_API void zend_user_it_get_current_key(zend_object_iterator *_iter, zval *ke
ZEND_API zval *zend_user_it_get_current_data(zend_object_iterator *_iter);
ZEND_API void zend_user_it_move_forward(zend_object_iterator *_iter);
ZEND_API void zend_user_it_invalidate_current(zend_object_iterator *_iter);
ZEND_API HashTable *zend_user_it_get_gc(zend_object_iterator *_iter, zval **table, int *n);

ZEND_API void zend_user_it_new_iterator(zend_class_entry *ce, zval *object, zval *iterator);
ZEND_API zend_object_iterator *zend_user_it_get_new_iterator(zend_class_entry *ce, zval *object, int by_ref);
Expand Down
Loading

0 comments on commit 26a3605

Please sign in to comment.