diff --git a/distr/flecs.c b/distr/flecs.c index 50151b08a..58b20b1ef 100644 --- a/distr/flecs.c +++ b/distr/flecs.c @@ -60274,6 +60274,7 @@ int ecs_script_visit_( #ifdef FLECS_SCRIPT +static int flecs_script_check_expr( ecs_script_eval_visitor_t *v, ecs_expr_node_t **expr_ptr, @@ -61930,8 +61931,10 @@ int flecs_script_eval_for_range( ecs_script_eval_visitor_t *v, ecs_script_for_range_t *node) { - ecs_value_t from_val = { .type = ecs_id(ecs_i32_t) }; - ecs_value_t to_val = { .type = ecs_id(ecs_i32_t) }; + int32_t from; + int32_t to; + ecs_value_t from_val = { .type = ecs_id(ecs_i32_t), .ptr = &from }; + ecs_value_t to_val = { .type = ecs_id(ecs_i32_t), .ptr = &to }; if (flecs_script_eval_expr(v, &node->from, &from_val)) { return -1; @@ -61941,9 +61944,6 @@ int flecs_script_eval_for_range( return -1; } - int32_t from = *(int32_t*)from_val.ptr; - int32_t to = *(int32_t*)to_val.ptr; - v->vars = flecs_script_vars_push(v->vars, &v->r->stack, &v->r->allocator); ecs_script_var_t *var = ecs_script_vars_declare(v->vars, node->loop_var); @@ -78847,10 +78847,10 @@ int flecs_expr_interpolated_string_visit_type( } /* Fiddly, but reduces need for allocations */ - ecs_size_t offset = flecs_ito( - int32_t, node->buffer - node->value); - var_name = ECS_OFFSET(var_name, offset); - (*(char*)ECS_OFFSET(ptr, offset)) = '\0'; + ecs_size_t var_name_pos = flecs_ito(int32_t, var_name - node->value); + var_name = &node->buffer[var_name_pos]; + ecs_size_t var_name_end = flecs_ito(int32_t, ptr - node->value); + node->buffer[var_name_end] = '\0'; ecs_expr_variable_t *var = flecs_expr_variable_from( script, (ecs_expr_node_t*)node, var_name); @@ -78898,6 +78898,7 @@ int flecs_expr_interpolated_string_visit_type( result = (ecs_expr_node_t*)flecs_expr_cast(script, (ecs_expr_node_t*)result, ecs_id(ecs_string_t)); if (!result) { + /* Cast failed */ goto error; } } @@ -79015,11 +79016,12 @@ int flecs_expr_initializer_visit_type( } if (elem->value->type != elem_type) { - elem->value = (ecs_expr_node_t*)flecs_expr_cast( + ecs_expr_node_t *cast = (ecs_expr_node_t*)flecs_expr_cast( script, elem->value, elem_type); - if (!elem->value) { + if (!cast) { goto error; } + elem->value = cast; } if (!is_opaque) { diff --git a/distr/flecs.h b/distr/flecs.h index c90dd41b1..e9d1f9f68 100644 --- a/distr/flecs.h +++ b/distr/flecs.h @@ -265,7 +265,7 @@ * When enabled, Flecs will use the OS allocator provided in the OS API directly * instead of the builtin block allocator. This can decrease memory utilization * as memory will be freed more often, at the cost of decreased performance. */ -// #define FLECS_USE_OS_ALLOC +#define FLECS_USE_OS_ALLOC /** @def FLECS_ID_DESC_MAX * Maximum number of ids to add ecs_entity_desc_t / ecs_bulk_desc_t */ diff --git a/include/flecs.h b/include/flecs.h index 027abc239..ec96077c2 100644 --- a/include/flecs.h +++ b/include/flecs.h @@ -263,7 +263,7 @@ * When enabled, Flecs will use the OS allocator provided in the OS API directly * instead of the builtin block allocator. This can decrease memory utilization * as memory will be freed more often, at the cost of decreased performance. */ -// #define FLECS_USE_OS_ALLOC +#define FLECS_USE_OS_ALLOC /** @def FLECS_ID_DESC_MAX * Maximum number of ids to add ecs_entity_desc_t / ecs_bulk_desc_t */ diff --git a/src/addons/script/expr/visit_type.c b/src/addons/script/expr/visit_type.c index 53eb73176..dfed36307 100644 --- a/src/addons/script/expr/visit_type.c +++ b/src/addons/script/expr/visit_type.c @@ -566,10 +566,10 @@ int flecs_expr_interpolated_string_visit_type( } /* Fiddly, but reduces need for allocations */ - ecs_size_t offset = flecs_ito( - int32_t, node->buffer - node->value); - var_name = ECS_OFFSET(var_name, offset); - (*(char*)ECS_OFFSET(ptr, offset)) = '\0'; + ecs_size_t var_name_pos = flecs_ito(int32_t, var_name - node->value); + var_name = &node->buffer[var_name_pos]; + ecs_size_t var_name_end = flecs_ito(int32_t, ptr - node->value); + node->buffer[var_name_end] = '\0'; ecs_expr_variable_t *var = flecs_expr_variable_from( script, (ecs_expr_node_t*)node, var_name); @@ -617,6 +617,7 @@ int flecs_expr_interpolated_string_visit_type( result = (ecs_expr_node_t*)flecs_expr_cast(script, (ecs_expr_node_t*)result, ecs_id(ecs_string_t)); if (!result) { + /* Cast failed */ goto error; } } @@ -734,11 +735,12 @@ int flecs_expr_initializer_visit_type( } if (elem->value->type != elem_type) { - elem->value = (ecs_expr_node_t*)flecs_expr_cast( + ecs_expr_node_t *cast = (ecs_expr_node_t*)flecs_expr_cast( script, elem->value, elem_type); - if (!elem->value) { + if (!cast) { goto error; } + elem->value = cast; } if (!is_opaque) { diff --git a/src/addons/script/visit_check.c b/src/addons/script/visit_check.c index 519ae43eb..b7ec8bc6b 100644 --- a/src/addons/script/visit_check.c +++ b/src/addons/script/visit_check.c @@ -8,6 +8,7 @@ #ifdef FLECS_SCRIPT #include "script.h" +static int flecs_script_check_expr( ecs_script_eval_visitor_t *v, ecs_expr_node_t **expr_ptr, diff --git a/src/addons/script/visit_eval.c b/src/addons/script/visit_eval.c index 8d688029b..249ae1590 100644 --- a/src/addons/script/visit_eval.c +++ b/src/addons/script/visit_eval.c @@ -1166,8 +1166,10 @@ int flecs_script_eval_for_range( ecs_script_eval_visitor_t *v, ecs_script_for_range_t *node) { - ecs_value_t from_val = { .type = ecs_id(ecs_i32_t) }; - ecs_value_t to_val = { .type = ecs_id(ecs_i32_t) }; + int32_t from; + int32_t to; + ecs_value_t from_val = { .type = ecs_id(ecs_i32_t), .ptr = &from }; + ecs_value_t to_val = { .type = ecs_id(ecs_i32_t), .ptr = &to }; if (flecs_script_eval_expr(v, &node->from, &from_val)) { return -1; @@ -1177,9 +1179,6 @@ int flecs_script_eval_for_range( return -1; } - int32_t from = *(int32_t*)from_val.ptr; - int32_t to = *(int32_t*)to_val.ptr; - v->vars = flecs_script_vars_push(v->vars, &v->r->stack, &v->r->allocator); ecs_script_var_t *var = ecs_script_vars_declare(v->vars, node->loop_var); diff --git a/test/script/src/ExprAst.c b/test/script/src/ExprAst.c index 93703ac9e..59646973e 100644 --- a/test/script/src/ExprAst.c +++ b/test/script/src/ExprAst.c @@ -250,7 +250,7 @@ void ExprAst_interpolated_string_curly_brackets_w_var(void) { void ExprAst_template_w_foldable_const(void) { ecs_world_t *world = ecs_init(); - ecs_entity_t ecs_id(Position) = ecs_struct(world, { + ecs_struct(world, { .entity = ecs_entity(world, {.name = "Position"}), .members = { {"x", ecs_id(ecs_f32_t)},