Skip to content
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

Fix issue where the use of a function pointer cast can trip -fsanitize=undefined on recent versions of clang #1211

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/addons/rules/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ void flecs_rule_fini(
ecs_poly_free(rule, ecs_rule_t);
}

/* ecs_poly_dtor_t-compatible wrapper */
static
void flecs_rule_fini_poly(void *rule)
{
flecs_rule_fini(rule);
}

void ecs_rule_fini(
ecs_rule_t *rule)
{
Expand Down Expand Up @@ -137,7 +144,7 @@ ecs_rule_t* ecs_rule_init(
}

ecs_entity_t entity = const_desc->entity;
result->dtor = (ecs_poly_dtor_t)flecs_rule_fini;
result->dtor = flecs_rule_fini_poly;

if (entity) {
EcsPoly *poly = ecs_poly_bind(world, entity, ecs_rule_t);
Expand Down
9 changes: 8 additions & 1 deletion src/addons/system/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@ void flecs_system_fini(ecs_system_t *sys) {
ecs_poly_free(sys, ecs_system_t);
}

/* ecs_poly_dtor_t-compatible wrapper */
static
void flecs_system_fini_poly(void *sys)
{
flecs_system_fini(sys);
}

static
void flecs_system_init_timer(
ecs_world_t *world,
Expand Down Expand Up @@ -281,7 +288,7 @@ ecs_entity_t ecs_system_init(

poly->poly = system;
system->world = world;
system->dtor = (ecs_poly_dtor_t)flecs_system_fini;
system->dtor = flecs_system_fini_poly;
system->entity = entity;

ecs_query_desc_t query_desc = desc->query;
Expand Down
9 changes: 8 additions & 1 deletion src/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,13 @@ void flecs_filter_fini(
}
}

/* ecs_poly_dtor_t-compatible wrapper */
static
void flecs_filter_fini_poly(void *filter)
{
flecs_filter_fini(filter);
}

void ecs_filter_fini(
ecs_filter_t *filter)
{
Expand Down Expand Up @@ -1672,7 +1679,7 @@ ecs_filter_t* ecs_filter_init(

f->variable_names[0] = NULL;
f->iterable.init = flecs_filter_iter_init;
f->dtor = (ecs_poly_dtor_t)flecs_filter_fini;
f->dtor = flecs_filter_fini_poly;
f->entity = entity;

if (entity && (f->flags & EcsFilterOwnsStorage)) {
Expand Down
9 changes: 8 additions & 1 deletion src/observer.c
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,13 @@ int flecs_multi_observer_init(
return -1;
}

/* ecs_poly_dtor_t-compatible wrapper */
static
void flecs_observer_fini_poly(void *observer)
{
flecs_observer_fini(observer);
}

ecs_entity_t ecs_observer_init(
ecs_world_t *world,
const ecs_observer_desc_t *desc)
Expand All @@ -846,7 +853,7 @@ ecs_entity_t ecs_observer_init(

ecs_observer_t *observer = ecs_poly_new(ecs_observer_t);
ecs_assert(observer != NULL, ECS_INTERNAL_ERROR, NULL);
observer->dtor = (ecs_poly_dtor_t)flecs_observer_fini;
observer->dtor = flecs_observer_fini_poly;

/* Make writeable copy of filter desc so that we can set name. This will
* make debugging easier, as any error messages related to creating the
Expand Down
9 changes: 8 additions & 1 deletion src/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -2027,6 +2027,13 @@ void flecs_query_fini(
ecs_poly_free(query, ecs_query_t);
}

/* ecs_poly_dtor_t-compatible wrapper */
static
void flecs_query_fini_poly(void *query)
{
flecs_query_fini(query);
}

/* -- Public API -- */

ecs_query_t* ecs_query_init(
Expand Down Expand Up @@ -2081,7 +2088,7 @@ ecs_query_t* ecs_query_init(
}

result->iterable.init = flecs_query_iter_init;
result->dtor = (ecs_poly_dtor_t)flecs_query_fini;
result->dtor = flecs_query_fini_poly;
result->prev_match_count = -1;

result->ctx = desc->ctx;
Expand Down
Loading