From d76e748f8b1f468829ce6dc3fdc2a7516c619432 Mon Sep 17 00:00:00 2001 From: Johannes Barthelmes Date: Thu, 12 Oct 2023 13:46:39 +0200 Subject: [PATCH] Update amalgamated files --- flecs.c | 96 ++++++++++++++++++++------------------------------------- flecs.h | 10 +++--- 2 files changed, 38 insertions(+), 68 deletions(-) diff --git a/flecs.c b/flecs.c index 8a78c18177..0a8156cdbe 100644 --- a/flecs.c +++ b/flecs.c @@ -1792,19 +1792,16 @@ ecs_poly_t* ecs_poly_get_( /* Utilities for testing/asserting an object type */ #ifndef FLECS_NDEBUG -void* ecs_poly_assert_( - const ecs_poly_t *object, - int32_t type, - const char *file, - int32_t line); - -#define ecs_poly_assert(object, type)\ - ecs_poly_assert_(object, type##_magic, __FILE__, __LINE__) - -#define ecs_poly(object, T) ((T*)ecs_poly_assert(object, T)) +#define ecs_poly_assert(object, ty)\ + do {\ + ecs_assert(object != NULL, ECS_INVALID_PARAMETER, NULL);\ + const ecs_header_t *hdr = (ecs_header_t *)object;\ + const char *type_name = hdr->mixins->type_name;\ + ecs_assert(hdr->magic == ECS_OBJECT_MAGIC, ECS_INVALID_PARAMETER, type_name);\ + ecs_assert(hdr->type == ty##_magic, ECS_INVALID_PARAMETER, type_name);\ + } while (0) #else -#define ecs_poly_assert(object, type) -#define ecs_poly(object, T) ((T*)object) +#define ecs_poly_assert(object, ty) #endif /* Utility functions for getting a mixin from an object */ @@ -16273,7 +16270,8 @@ ecs_entity_t ecs_observer_init( ecs_get_name(world, entity)); } } else { - ecs_observer_t *observer = ecs_poly(poly->poly, ecs_observer_t); + ecs_poly_assert(poly->poly, ecs_observer_t); + ecs_observer_t *observer = (ecs_observer_t*)poly->poly; if (desc->run) { observer->run = desc->run; @@ -17098,27 +17096,6 @@ ecs_poly_t* ecs_poly_get_( return NULL; } -#ifndef FLECS_NDEBUG -#define assert_object(cond, file, line, type_name)\ - ecs_assert_((cond), ECS_INVALID_PARAMETER, #cond, file, line, type_name);\ - assert(cond) - -void* ecs_poly_assert_( - const ecs_poly_t *poly, - int32_t type, - const char *file, - int32_t line) -{ - assert_object(poly != NULL, file, line, 0); - - const ecs_header_t *hdr = poly; - const char *type_name = hdr->mixins->type_name; - assert_object(hdr->magic == ECS_OBJECT_MAGIC, file, line, type_name); - assert_object(hdr->type == type, file, line, type_name); - return ECS_CONST_CAST(ecs_poly_t*, poly); -} -#endif - bool ecs_poly_is_( const ecs_poly_t *poly, int32_t type) @@ -27513,8 +27490,7 @@ void ecs_abort_( ecs_os_api.log_last_error_ = err; } -bool ecs_assert_( - bool condition, +void ecs_assert_log_( int32_t err, const char *cond_str, const char *file, @@ -27522,23 +27498,19 @@ bool ecs_assert_( const char *fmt, ...) { - if (!condition) { - if (fmt) { - va_list args; - va_start(args, fmt); - char *msg = ecs_vasprintf(fmt, args); - va_end(args); - ecs_fatal_(file, line, "assert: %s %s (%s)", - cond_str, msg, ecs_strerror(err)); - ecs_os_free(msg); - } else { - ecs_fatal_(file, line, "assert: %s %s", - cond_str, ecs_strerror(err)); - } - ecs_os_api.log_last_error_ = err; + if (fmt) { + va_list args; + va_start(args, fmt); + char *msg = ecs_vasprintf(fmt, args); + va_end(args); + ecs_fatal_(file, line, "assert: %s %s (%s)", + cond_str, msg, ecs_strerror(err)); + ecs_os_free(msg); + } else { + ecs_fatal_(file, line, "assert: %s %s", + cond_str, ecs_strerror(err)); } - - return condition; + ecs_os_api.log_last_error_ = err; } void ecs_deprecated_( @@ -27671,8 +27643,7 @@ void ecs_abort_( (void)fmt; } -bool ecs_assert_( - bool condition, +void ecs_assert_log_( int32_t error_code, const char *condition_str, const char *file, @@ -27680,13 +27651,11 @@ bool ecs_assert_( const char *fmt, ...) { - (void)condition; (void)error_code; (void)condition_str; (void)file; (void)line; (void)fmt; - return true; } #endif @@ -58612,7 +58581,8 @@ bool flecs_pipeline_build( int32_t i; for (i = 0; i < it.count; i ++) { - ecs_system_t *sys = ecs_poly(poly[i].poly, ecs_system_t); + ecs_poly_assert(poly[i].poly, ecs_system_t); + ecs_system_t *sys = (ecs_system_t*)poly[i].poly; ecs_query_t *q = sys->query; bool needs_merge = false; @@ -58718,8 +58688,8 @@ bool flecs_pipeline_build( for (i = 0; i < count; i ++) { ecs_entity_t system = systems[i]; const EcsPoly *poly = ecs_get_pair(world, system, EcsPoly, EcsSystem); - ecs_assert(poly != NULL, ECS_INTERNAL_ERROR, NULL); - ecs_system_t *sys = ecs_poly(poly->poly, ecs_system_t); + ecs_poly_assert(poly->poly, ecs_system_t); + ecs_system_t *sys = (ecs_system_t*)poly->poly; #ifdef FLECS_LOG_1 char *path = ecs_get_fullpath(world, system); @@ -58877,8 +58847,8 @@ int32_t flecs_run_pipeline_ops( for (; i < count; i++) { ecs_entity_t system = systems[i]; const EcsPoly* poly = ecs_get_pair(world, system, EcsPoly, EcsSystem); - ecs_assert(poly != NULL, ECS_INTERNAL_ERROR, NULL); - ecs_system_t* sys = ecs_poly(poly->poly, ecs_system_t); + ecs_poly_assert(poly->poly, ecs_system_t); + ecs_system_t* sys = (ecs_system_t*)poly->poly; /* Keep track of the last frame for which the system has ran, so we * know from where to resume the schedule in case the schedule @@ -64362,7 +64332,8 @@ ecs_entity_t ecs_system_init( ecs_defer_end(world); } else { - ecs_system_t *system = ecs_poly(poly->poly, ecs_system_t); + ecs_poly_assert(poly->poly, ecs_system_t); + ecs_system_t *system = (ecs_system_t*)poly->poly; if (desc->run) { system->run = desc->run; @@ -64431,4 +64402,3 @@ void FlecsSystemImport( } #endif - diff --git a/flecs.h b/flecs.h index 4b03f41731..184ec6a77a 100644 --- a/flecs.h +++ b/flecs.h @@ -9619,8 +9619,7 @@ void ecs_abort_( ...); FLECS_API -bool ecs_assert_( - bool condition, +void ecs_assert_log_( int32_t error_code, const char *condition_str, const char *file, @@ -9814,7 +9813,8 @@ void ecs_parser_errorv_( #define ecs_assert(condition, error_code, ...) #else #define ecs_assert(condition, error_code, ...)\ - if (!ecs_assert_(condition, error_code, #condition, __FILE__, __LINE__, __VA_ARGS__)) {\ + if (!(condition)) {\ + ecs_assert_log_(error_code, #condition, __FILE__, __LINE__, __VA_ARGS__);\ ecs_os_abort();\ }\ assert(condition) /* satisfy compiler/static analyzers */ @@ -9854,7 +9854,8 @@ void ecs_parser_errorv_( #else #ifdef FLECS_SOFT_ASSERT #define ecs_check(condition, error_code, ...)\ - if (!ecs_assert_(condition, error_code, #condition, __FILE__, __LINE__, __VA_ARGS__)) {\ + if (!(condition)) {\ + ecs_assert_log_(error_code, #condition, __FILE__, __LINE__, __VA_ARGS__);\ goto error;\ } #else // FLECS_SOFT_ASSERT @@ -30929,4 +30930,3 @@ inline flecs::scoped_world world::scope(const char* name) const { #endif -