Skip to content

Commit

Permalink
Update amalgamated files
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarthelmes committed Oct 12, 2023
1 parent bb20076 commit d76e748
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 68 deletions.
96 changes: 33 additions & 63 deletions flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -27513,32 +27490,27 @@ 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,
int32_t line,
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_(
Expand Down Expand Up @@ -27671,22 +27643,19 @@ 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,
int32_t line,
const char *fmt,
...)
{
(void)condition;
(void)error_code;
(void)condition_str;
(void)file;
(void)line;
(void)fmt;
return true;
}

#endif
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -64431,4 +64402,3 @@ void FlecsSystemImport(
}

#endif

10 changes: 5 additions & 5 deletions flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -30929,4 +30930,3 @@ inline flecs::scoped_world world::scope(const char* name) const {


#endif

0 comments on commit d76e748

Please sign in to comment.