Replacing dynamically sized on-stack arrays with heap allocated arrays defined through MEM_DEFINE_LOCAL_ARRAY.
This commit is contained in:
@@ -455,10 +455,10 @@ run_int_from_pos (opcode_counter_t start_pos,
|
|||||||
|
|
||||||
const uint32_t regs_num = (uint32_t) (max_reg_num - min_reg_num + 1);
|
const uint32_t regs_num = (uint32_t) (max_reg_num - min_reg_num + 1);
|
||||||
|
|
||||||
ecma_value_t regs[ regs_num ];
|
MEM_DEFINE_LOCAL_ARRAY (regs, regs_num, ecma_value_t);
|
||||||
|
|
||||||
/* memseting with zero initializes each 'register' to empty value */
|
/* memseting with zero initializes each 'register' to empty value */
|
||||||
__memset (regs, 0, sizeof (regs));
|
__memset (regs, 0, regs_num * sizeof (ecma_value_t));
|
||||||
JERRY_ASSERT (ecma_is_value_empty (regs[0]));
|
JERRY_ASSERT (ecma_is_value_empty (regs[0]));
|
||||||
|
|
||||||
int_data_t int_data;
|
int_data_t int_data;
|
||||||
@@ -496,6 +496,8 @@ run_int_from_pos (opcode_counter_t start_pos,
|
|||||||
interp_mem_stats_context_exit (&int_data, start_pos);
|
interp_mem_stats_context_exit (&int_data, start_pos);
|
||||||
#endif /* MEM_STATS */
|
#endif /* MEM_STATS */
|
||||||
|
|
||||||
|
MEM_FINALIZE_LOCAL_ARRAY (regs);
|
||||||
|
|
||||||
return completion;
|
return completion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,10 +43,10 @@ opfunc_native_call (opcode_t opdata, /**< operation data */
|
|||||||
|
|
||||||
JERRY_STATIC_ASSERT (OPCODE_NATIVE_CALL__COUNT < (1u << (sizeof (native_call_id_idx) * JERRY_BITSINBYTE)));
|
JERRY_STATIC_ASSERT (OPCODE_NATIVE_CALL__COUNT < (1u << (sizeof (native_call_id_idx) * JERRY_BITSINBYTE)));
|
||||||
|
|
||||||
ecma_value_t arg_values[args_number + 1 /* length of array should not be zero */];
|
|
||||||
|
|
||||||
ecma_completion_value_t ret_value = 0;
|
ecma_completion_value_t ret_value = 0;
|
||||||
|
|
||||||
|
MEM_DEFINE_LOCAL_ARRAY (arg_values, args_number, ecma_value_t);
|
||||||
|
|
||||||
ecma_length_t args_read;
|
ecma_length_t args_read;
|
||||||
ecma_completion_value_t get_arg_completion = fill_varg_list (int_data,
|
ecma_completion_value_t get_arg_completion = fill_varg_list (int_data,
|
||||||
args_number,
|
args_number,
|
||||||
@@ -168,5 +168,7 @@ opfunc_native_call (opcode_t opdata, /**< operation data */
|
|||||||
ecma_free_value (arg_values[arg_index], true);
|
ecma_free_value (arg_values[arg_index], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MEM_FINALIZE_LOCAL_ARRAY (arg_values);
|
||||||
|
|
||||||
return ret_value;
|
return ret_value;
|
||||||
} /* opfunc_native_call */
|
} /* opfunc_native_call */
|
||||||
|
|||||||
+32
-14
@@ -500,13 +500,16 @@ opfunc_func_decl_n (opcode_t opdata, /**< operation data */
|
|||||||
|
|
||||||
int_data->pos++;
|
int_data->pos++;
|
||||||
|
|
||||||
ecma_string_t *params_names[params_number + 1 /* length of array should not be zero */];
|
ecma_completion_value_t ret_value;
|
||||||
|
|
||||||
|
MEM_DEFINE_LOCAL_ARRAY (params_names, params_number, ecma_string_t*);
|
||||||
|
|
||||||
fill_params_list (int_data, params_number, params_names);
|
fill_params_list (int_data, params_number, params_names);
|
||||||
|
|
||||||
ecma_completion_value_t ret_value = function_declaration (int_data,
|
ret_value = function_declaration (int_data,
|
||||||
function_name_lit_id,
|
function_name_lit_id,
|
||||||
params_names,
|
params_names,
|
||||||
params_number);
|
params_number);
|
||||||
|
|
||||||
for (uint32_t param_index = 0;
|
for (uint32_t param_index = 0;
|
||||||
param_index < params_number;
|
param_index < params_number;
|
||||||
@@ -515,6 +518,8 @@ opfunc_func_decl_n (opcode_t opdata, /**< operation data */
|
|||||||
ecma_deref_ecma_string (params_names[param_index]);
|
ecma_deref_ecma_string (params_names[param_index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MEM_FINALIZE_LOCAL_ARRAY (params_names);
|
||||||
|
|
||||||
return ret_value;
|
return ret_value;
|
||||||
} /* opfunc_func_decl_n */
|
} /* opfunc_func_decl_n */
|
||||||
|
|
||||||
@@ -537,13 +542,18 @@ opfunc_func_expr_n (opcode_t opdata, /**< operation data */
|
|||||||
const ecma_length_t params_number = opdata.data.func_expr_n.arg_list;
|
const ecma_length_t params_number = opdata.data.func_expr_n.arg_list;
|
||||||
const bool is_named_func_expr = (function_name_lit_idx != INVALID_VALUE);
|
const bool is_named_func_expr = (function_name_lit_idx != INVALID_VALUE);
|
||||||
|
|
||||||
ecma_string_t *params_names[params_number + 1 /* length of array should not be zero */];
|
ecma_completion_value_t ret_value;
|
||||||
|
|
||||||
|
opcode_counter_t function_code_end_oc;
|
||||||
|
|
||||||
|
MEM_DEFINE_LOCAL_ARRAY (params_names, params_number, ecma_string_t*);
|
||||||
|
|
||||||
fill_params_list (int_data, params_number, params_names);
|
fill_params_list (int_data, params_number, params_names);
|
||||||
|
|
||||||
bool is_strict = int_data->is_strict;
|
bool is_strict = int_data->is_strict;
|
||||||
|
|
||||||
const opcode_counter_t function_code_end_oc = (opcode_counter_t) (
|
function_code_end_oc = (opcode_counter_t) (read_meta_opcode_counter (OPCODE_META_TYPE_FUNCTION_END,
|
||||||
read_meta_opcode_counter (OPCODE_META_TYPE_FUNCTION_END, int_data) + int_data->pos);
|
int_data) + int_data->pos);
|
||||||
int_data->pos++;
|
int_data->pos++;
|
||||||
|
|
||||||
opcode_t next_opcode = read_opcode (int_data->pos);
|
opcode_t next_opcode = read_opcode (int_data->pos);
|
||||||
@@ -580,9 +590,9 @@ opfunc_func_expr_n (opcode_t opdata, /**< operation data */
|
|||||||
is_strict,
|
is_strict,
|
||||||
int_data->pos);
|
int_data->pos);
|
||||||
|
|
||||||
ecma_completion_value_t ret_value = set_variable_value (int_data, lit_oc,
|
ret_value = set_variable_value (int_data, lit_oc,
|
||||||
dst_var_idx,
|
dst_var_idx,
|
||||||
ecma_make_object_value (func_obj_p));
|
ecma_make_object_value (func_obj_p));
|
||||||
|
|
||||||
if (is_named_func_expr)
|
if (is_named_func_expr)
|
||||||
{
|
{
|
||||||
@@ -602,6 +612,8 @@ opfunc_func_expr_n (opcode_t opdata, /**< operation data */
|
|||||||
ecma_deref_ecma_string (params_names[param_index]);
|
ecma_deref_ecma_string (params_names[param_index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MEM_FINALIZE_LOCAL_ARRAY (params_names);
|
||||||
|
|
||||||
int_data->pos = function_code_end_oc;
|
int_data->pos = function_code_end_oc;
|
||||||
|
|
||||||
return ret_value;
|
return ret_value;
|
||||||
@@ -653,7 +665,7 @@ opfunc_call_n (opcode_t opdata, /**< operation data */
|
|||||||
args_number = args_number_idx;
|
args_number = args_number_idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_value_t arg_values[args_number + 1 /* length of array should not be zero */];
|
MEM_DEFINE_LOCAL_ARRAY (arg_values, args_number, ecma_value_t);
|
||||||
|
|
||||||
ecma_length_t args_read;
|
ecma_length_t args_read;
|
||||||
ecma_completion_value_t get_arg_completion = fill_varg_list (int_data,
|
ecma_completion_value_t get_arg_completion = fill_varg_list (int_data,
|
||||||
@@ -716,6 +728,8 @@ opfunc_call_n (opcode_t opdata, /**< operation data */
|
|||||||
ecma_free_value (arg_values[arg_index], true);
|
ecma_free_value (arg_values[arg_index], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MEM_FINALIZE_LOCAL_ARRAY (arg_values);
|
||||||
|
|
||||||
ECMA_FINALIZE (func_value);
|
ECMA_FINALIZE (func_value);
|
||||||
|
|
||||||
return ret_value;
|
return ret_value;
|
||||||
@@ -743,7 +757,7 @@ opfunc_construct_n (opcode_t opdata, /**< operation data */
|
|||||||
get_variable_value (int_data, constructor_name_lit_idx, false),
|
get_variable_value (int_data, constructor_name_lit_idx, false),
|
||||||
ret_value);
|
ret_value);
|
||||||
|
|
||||||
ecma_value_t arg_values[args_number + 1 /* length of array should not be zero */];
|
MEM_DEFINE_LOCAL_ARRAY (arg_values, args_number, ecma_value_t);
|
||||||
|
|
||||||
int_data->pos++;
|
int_data->pos++;
|
||||||
|
|
||||||
@@ -791,6 +805,8 @@ opfunc_construct_n (opcode_t opdata, /**< operation data */
|
|||||||
ecma_free_value (arg_values[arg_index], true);
|
ecma_free_value (arg_values[arg_index], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MEM_FINALIZE_LOCAL_ARRAY (arg_values);
|
||||||
|
|
||||||
ECMA_FINALIZE (constructor_value);
|
ECMA_FINALIZE (constructor_value);
|
||||||
|
|
||||||
return ret_value;
|
return ret_value;
|
||||||
@@ -816,7 +832,7 @@ opfunc_array_decl (opcode_t opdata, /**< operation data */
|
|||||||
|
|
||||||
ecma_completion_value_t ret_value;
|
ecma_completion_value_t ret_value;
|
||||||
|
|
||||||
ecma_value_t arg_values[args_number + 1 /* length of array should not be zero */];
|
MEM_DEFINE_LOCAL_ARRAY (arg_values, args_number, ecma_value_t);
|
||||||
|
|
||||||
ecma_length_t args_read;
|
ecma_length_t args_read;
|
||||||
ecma_completion_value_t get_arg_completion = fill_varg_list (int_data,
|
ecma_completion_value_t get_arg_completion = fill_varg_list (int_data,
|
||||||
@@ -854,6 +870,8 @@ opfunc_array_decl (opcode_t opdata, /**< operation data */
|
|||||||
ecma_free_value (arg_values[arg_index], true);
|
ecma_free_value (arg_values[arg_index], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MEM_FINALIZE_LOCAL_ARRAY (arg_values);
|
||||||
|
|
||||||
return ret_value;
|
return ret_value;
|
||||||
} /* opfunc_array_decl */
|
} /* opfunc_array_decl */
|
||||||
|
|
||||||
|
|||||||
@@ -143,12 +143,12 @@ ecma_builtin_error_prototype_object_to_string (ecma_value_t this) /**< this argu
|
|||||||
ecma_zt_string_length (space_zt_magic_string_p));
|
ecma_zt_string_length (space_zt_magic_string_p));
|
||||||
|
|
||||||
const ssize_t buffer_size = (len + 1) * (ssize_t) sizeof (ecma_char_t);
|
const ssize_t buffer_size = (len + 1) * (ssize_t) sizeof (ecma_char_t);
|
||||||
ssize_t bytes, buffer_size_left = buffer_size;
|
ssize_t buffer_size_left = buffer_size;
|
||||||
|
|
||||||
ecma_char_t ret_str_buffer [buffer_size];
|
MEM_DEFINE_LOCAL_ARRAY (ret_str_buffer, buffer_size, ecma_char_t);
|
||||||
ecma_char_t *ret_str_buffer_p = ret_str_buffer;
|
ecma_char_t *ret_str_buffer_p = ret_str_buffer;
|
||||||
|
|
||||||
bytes = ecma_string_to_zt_string (name_string_p, ret_str_buffer_p, buffer_size_left);
|
ssize_t bytes = ecma_string_to_zt_string (name_string_p, ret_str_buffer_p, buffer_size_left);
|
||||||
JERRY_ASSERT (bytes >= 1 && buffer_size_left - bytes >= 0);
|
JERRY_ASSERT (bytes >= 1 && buffer_size_left - bytes >= 0);
|
||||||
|
|
||||||
buffer_size_left -= bytes - 1 /* null character */;
|
buffer_size_left -= bytes - 1 /* null character */;
|
||||||
@@ -176,6 +176,8 @@ ecma_builtin_error_prototype_object_to_string (ecma_value_t this) /**< this argu
|
|||||||
*ret_str_buffer_p = ECMA_CHAR_NULL;
|
*ret_str_buffer_p = ECMA_CHAR_NULL;
|
||||||
|
|
||||||
ret_str_p = ecma_new_ecma_string (ret_str_buffer);
|
ret_str_p = ecma_new_ecma_string (ret_str_buffer);
|
||||||
|
|
||||||
|
MEM_FINALIZE_LOCAL_ARRAY (ret_str_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret_value = ecma_make_normal_completion_value (ecma_make_string_value (ret_str_p));
|
ret_value = ecma_make_normal_completion_value (ecma_make_string_value (ret_str_p));
|
||||||
|
|||||||
@@ -84,11 +84,13 @@ ecma_builtin_object_prototype_object_to_string (ecma_value_t this) /**< this arg
|
|||||||
ecma_free_completion_value (obj_this);
|
ecma_free_completion_value (obj_this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ecma_string_t *ret_string_p;
|
||||||
|
|
||||||
/* Building string "[object #type#]" where type is 'Undefined',
|
/* Building string "[object #type#]" where type is 'Undefined',
|
||||||
'Null' or one of possible object's classes.
|
'Null' or one of possible object's classes.
|
||||||
The string with null character is maximum 19 characters long. */
|
The string with null character is maximum 19 characters long. */
|
||||||
const ssize_t buffer_size = 19;
|
const ssize_t buffer_size = 19;
|
||||||
ecma_char_t str_buffer[buffer_size];
|
MEM_DEFINE_LOCAL_ARRAY (str_buffer, buffer_size, ecma_char_t);
|
||||||
|
|
||||||
const ecma_char_t *left_square_zt_str_p = ecma_get_magic_string_zt (ECMA_MAGIC_STRING_LEFT_SQUARE_CHAR);
|
const ecma_char_t *left_square_zt_str_p = ecma_get_magic_string_zt (ECMA_MAGIC_STRING_LEFT_SQUARE_CHAR);
|
||||||
const ecma_char_t *object_zt_str_p = ecma_get_magic_string_zt (ECMA_MAGIC_STRING_OBJECT);
|
const ecma_char_t *object_zt_str_p = ecma_get_magic_string_zt (ECMA_MAGIC_STRING_OBJECT);
|
||||||
@@ -121,7 +123,9 @@ ecma_builtin_object_prototype_object_to_string (ecma_value_t this) /**< this arg
|
|||||||
|
|
||||||
JERRY_ASSERT (buffer_size_left >= 0);
|
JERRY_ASSERT (buffer_size_left >= 0);
|
||||||
|
|
||||||
ecma_string_t *ret_string_p = ecma_new_ecma_string (str_buffer);
|
ret_string_p = ecma_new_ecma_string (str_buffer);
|
||||||
|
|
||||||
|
MEM_FINALIZE_LOCAL_ARRAY (str_buffer);
|
||||||
|
|
||||||
return ecma_make_normal_completion_value (ecma_make_string_value (ret_string_p));
|
return ecma_make_normal_completion_value (ecma_make_string_value (ret_string_p));
|
||||||
} /* ecma_builtin_object_prototype_object_to_string */
|
} /* ecma_builtin_object_prototype_object_to_string */
|
||||||
|
|||||||
@@ -136,7 +136,9 @@ ecma_new_strings_collection (ecma_string_t* string_ptrs_buffer[], /**< pointers
|
|||||||
JERRY_ASSERT (string_ptrs_buffer != NULL);
|
JERRY_ASSERT (string_ptrs_buffer != NULL);
|
||||||
JERRY_ASSERT (strings_number > 0);
|
JERRY_ASSERT (strings_number > 0);
|
||||||
|
|
||||||
ecma_value_t values_buffer[strings_number];
|
ecma_collection_header_t *new_collection_p;
|
||||||
|
|
||||||
|
MEM_DEFINE_LOCAL_ARRAY (values_buffer, strings_number, ecma_value_t);
|
||||||
|
|
||||||
for (ecma_length_t string_index = 0;
|
for (ecma_length_t string_index = 0;
|
||||||
string_index < strings_number;
|
string_index < strings_number;
|
||||||
@@ -145,7 +147,13 @@ ecma_new_strings_collection (ecma_string_t* string_ptrs_buffer[], /**< pointers
|
|||||||
values_buffer[string_index] = ecma_make_string_value (string_ptrs_buffer[string_index]);
|
values_buffer[string_index] = ecma_make_string_value (string_ptrs_buffer[string_index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ecma_new_values_collection (values_buffer, strings_number, false);
|
new_collection_p = ecma_new_values_collection (values_buffer,
|
||||||
|
strings_number,
|
||||||
|
false);
|
||||||
|
|
||||||
|
MEM_FINALIZE_LOCAL_ARRAY (values_buffer);
|
||||||
|
|
||||||
|
return new_collection_p;
|
||||||
} /* ecma_new_strings_collection */
|
} /* ecma_new_strings_collection */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ ecma_create_arguments_object (ecma_object_t *func_obj_p, /**< callee function */
|
|||||||
ecma_object_t *map_p = ecma_op_create_object_object_noarg ();
|
ecma_object_t *map_p = ecma_op_create_object_object_noarg ();
|
||||||
|
|
||||||
// 11.c
|
// 11.c
|
||||||
ecma_string_t *formal_params[formal_params_number];
|
MEM_DEFINE_LOCAL_ARRAY (formal_params, formal_params_number, ecma_string_t *);
|
||||||
|
|
||||||
JERRY_ASSERT (formal_params_iter_p->current_value_p == NULL);
|
JERRY_ASSERT (formal_params_iter_p->current_value_p == NULL);
|
||||||
uint32_t param_index;
|
uint32_t param_index;
|
||||||
@@ -185,6 +185,8 @@ ecma_create_arguments_object (ecma_object_t *func_obj_p, /**< callee function */
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MEM_FINALIZE_LOCAL_ARRAY (formal_params);
|
||||||
|
|
||||||
// 12.
|
// 12.
|
||||||
ecma_set_object_type (obj_p, ECMA_OBJECT_TYPE_ARGUMENTS);
|
ecma_set_object_type (obj_p, ECMA_OBJECT_TYPE_ARGUMENTS);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user