Fix the type, macro and state-table defects, and the leftover debris
Closes internal-consistency items 19 through 36, 38 and 41. Item 37, the ~180 redundant casts, is deliberately left open with its reasoning in TODO.md: the benefit only arrives once the build turns on the warnings those casts suppress, and doing it before that is churn across the two files with the most outstanding functional defects. The two that were real bugs are in the actor state table. AKGL_ACTOR_STATE_STRING_NAMES was declared [AKGL_ACTOR_MAX_STATES+1] and defined [32], so a consumer trusting the declared bound read past the object; and indices 11 and 12 were named UNDEFINED_11 and UNDEFINED_12 where actor.h has MOVING_IN and MOVING_OUT, so no character JSON could bind a sprite to either state. tests/registry.c now walks the whole table -- every entry non-NULL, every entry resolving to its own bit, no two entries sharing a name. The bitmask macros are parenthesized and AKGL_BITMASK_CLEAR has lost the semicolon inside its body. Writing tests/bitmasks.c for that turned up something worth knowing: the obvious test does not catch it. For a bit that is set, the misparse `!(mask & bit) == bit` gives the same answer as the correct one. It only diverges for an unset bit whose value is not 1, and that is the shape the suite uses now. akgl_draw_background was the last public function outside the error protocol. It takes a backend like everything else in draw.h, restores the draw colour it found, and is tested -- TODO.md had it filed under "needs the offscreen renderer harness", which was never true; what it needed was to stop reading the global. All eight registry initializers go through one helper, so the seven that leaked an SDL_PropertiesID on every call after the first no longer do. Fixed in the same place because it is the same function: akgl_registry_init never called akgl_registry_init_properties, which made akgl_set_property a silent no-op for anyone not going through akgl_game_init -- Defects, Known and still open item 3. Also: AKGL_COLLIDE_RECTANGLES (three open parens, two closes) and akgl_Frame deleted, float32_t/float64_t used consistently, the developer-specific debug logging removed from the controller inner loop, the abandoned SDL_GetBasePath comments removed, nine unused locals removed, and dst renamed to dest. akgl_game_update's default flags no longer OR the same bit twice. That changes nothing today, and the reason is Performance item 32: the loop never reads either bit, which is why every actor is updated sixteen times a frame. Still open. 25/25 pass, memcheck clean, reindent --check clean. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
22
src/util.c
22
src/util.c
@@ -21,7 +21,7 @@
|
||||
#include <akstdlib.h>
|
||||
|
||||
/**
|
||||
* @brief Resolve @p path against @p root and write the absolute result to @p dst.
|
||||
* @brief Resolve @p path against @p root and write the absolute result to @p dest.
|
||||
*
|
||||
* The second half of akgl_path_relative: joins the two with a `/` and resolves
|
||||
* the join, so symlinks and `..` are folded out and the result is absolute. It
|
||||
@@ -36,10 +36,10 @@
|
||||
* @param path Relative path to resolve. Required. An absolute @p path still gets
|
||||
* @p root pasted in front of it, which will not exist -- so callers
|
||||
* must not send absolute paths down this branch.
|
||||
* @param dst Receives the resolved absolute path. Required, and must already be
|
||||
* @param dest Receives the resolved absolute path. Required, and must already be
|
||||
* a claimed pool string.
|
||||
* @return `NULL` on success, otherwise an error context owned by the caller.
|
||||
* @throws AKERR_NULLPOINTER If @p root, @p path, or @p dst is `NULL`.
|
||||
* @throws AKERR_NULLPOINTER If @p root, @p path, or @p dest is `NULL`.
|
||||
* @throws AKERR_OUTOFBOUNDS If `root + path` is at least #AKGL_MAX_STRING_LENGTH
|
||||
* bytes. The message reports both the combined length and the limit.
|
||||
* @throws ENOENT If the joined path does not exist. Any other `errno`
|
||||
@@ -51,19 +51,18 @@
|
||||
* scratch strings are never released. This is exactly the hazard AGENTS.md
|
||||
* warns about; it wants a `FAIL_BREAK`.
|
||||
*/
|
||||
static akerr_ErrorContext *path_relative_root(char *root, char *path, akgl_String *dst)
|
||||
static akerr_ErrorContext *path_relative_root(char *root, char *path, akgl_String *dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
akgl_String *pathbuf;
|
||||
akgl_String *strbuf;
|
||||
char *result;
|
||||
int rootlen;
|
||||
int pathlen;
|
||||
int count;
|
||||
|
||||
FAIL_ZERO_RETURN(errctx, root, AKERR_NULLPOINTER, "NULL argument");
|
||||
FAIL_ZERO_RETURN(errctx, path, AKERR_NULLPOINTER, "NULL argument");
|
||||
FAIL_ZERO_RETURN(errctx, dst, AKERR_NULLPOINTER, "NULL argument");
|
||||
FAIL_ZERO_RETURN(errctx, dest, AKERR_NULLPOINTER, "NULL argument");
|
||||
|
||||
PASS(errctx, akgl_heap_next_string(&strbuf));
|
||||
PASS(errctx, akgl_heap_next_string(&pathbuf));
|
||||
@@ -86,7 +85,7 @@ static akerr_ErrorContext *path_relative_root(char *root, char *path, akgl_Strin
|
||||
));
|
||||
RESTORE_GCC_WARNINGS
|
||||
CATCH(errctx, aksl_realpath((char *)&pathbuf->data, (char *)&strbuf->data, sizeof(strbuf->data)));
|
||||
CATCH(errctx, akgl_string_copy(strbuf, dst, 0));
|
||||
CATCH(errctx, akgl_string_copy(strbuf, dest, 0));
|
||||
} CLEANUP {
|
||||
IGNORE(akgl_heap_release_string(strbuf));
|
||||
IGNORE(akgl_heap_release_string(pathbuf));
|
||||
@@ -95,16 +94,15 @@ static akerr_ErrorContext *path_relative_root(char *root, char *path, akgl_Strin
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
akerr_ErrorContext *akgl_path_relative(char *root, char *path, akgl_String *dst)
|
||||
akerr_ErrorContext *akgl_path_relative(char *root, char *path, akgl_String *dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
akgl_String *strbuf;
|
||||
char *result;
|
||||
bool relative_to_root = false;
|
||||
|
||||
FAIL_ZERO_RETURN(errctx, root, AKERR_NULLPOINTER, "NULL argument");
|
||||
FAIL_ZERO_RETURN(errctx, path, AKERR_NULLPOINTER, "NULL argument");
|
||||
FAIL_ZERO_RETURN(errctx, dst, AKERR_NULLPOINTER, "NULL argument");
|
||||
FAIL_ZERO_RETURN(errctx, dest, AKERR_NULLPOINTER, "NULL argument");
|
||||
|
||||
PASS(errctx, akgl_heap_next_string(&strbuf));
|
||||
|
||||
@@ -112,7 +110,7 @@ akerr_ErrorContext *akgl_path_relative(char *root, char *path, akgl_String *dst)
|
||||
// Is path relative to our current working directory?
|
||||
CATCH(errctx, aksl_realpath(path, (char *)&strbuf->data, sizeof(strbuf->data)));
|
||||
// Yes it is. strbuf->data contains the absolute path.
|
||||
CATCH(errctx, akgl_string_copy(strbuf, dst, 0));
|
||||
CATCH(errctx, akgl_string_copy(strbuf, dest, 0));
|
||||
} CLEANUP {
|
||||
IGNORE(akgl_heap_release_string(strbuf));
|
||||
} PROCESS(errctx) {
|
||||
@@ -129,7 +127,7 @@ akerr_ErrorContext *akgl_path_relative(char *root, char *path, akgl_String *dst)
|
||||
} FINISH(errctx, true);
|
||||
|
||||
if ( relative_to_root == true ) {
|
||||
PASS(errctx, path_relative_root(root, path, dst));
|
||||
PASS(errctx, path_relative_root(root, path, dest));
|
||||
}
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user