From a60220d39ba6a6c4af7bcada931aef0d8f3611d6 Mon Sep 17 00:00:00 2001 From: Andrew Kesterson Date: Fri, 31 Jul 2026 23:58:28 -0400 Subject: [PATCH] Name every local error context errctx Closes internal-consistency item 18. The convention was settled -- AGENTS.md records errctx winning 92 sites to 45 -- but the other 45 were still there, and four files favoured `e` throughout while six favoured errctx, sometimes within one file. Its own commit because it is a rename and nothing else. All 333 changed lines are a single identifier substitution: applying \be\b -> errctx to each removed line reproduces the added line exactly, and the counts match at 333 either way. `e` keeps its meaning where the convention actually wants it -- an incoming error context being inspected, as in akgl_get_json_with_default(e, ...) -- which is why that function was left alone. 25/25 pass, reindent --check clean. Co-Authored-By: Claude Opus 5 (1M context) --- src/controller.c | 18 ++-- src/game.c | 242 ++++++++++++++++++++++----------------------- src/heap.c | 4 +- src/physics.c | 128 ++++++++++++------------ src/registry.c | 28 +++--- src/renderer.c | 84 ++++++++-------- src/sprite.c | 10 +- src/staticstring.c | 10 +- src/tilemap.c | 90 ++++++++--------- src/util.c | 50 +++++----- 10 files changed, 332 insertions(+), 332 deletions(-) diff --git a/src/controller.c b/src/controller.c index ddd4434..7d34a89 100644 --- a/src/controller.c +++ b/src/controller.c @@ -186,9 +186,9 @@ akerr_ErrorContext *akgl_controller_list_keyboards(void) { int count; SDL_KeyboardID *keyboards = SDL_GetKeyboards(&count); - PREPARE_ERROR(e); + PREPARE_ERROR(errctx); - FAIL_ZERO_RETURN(e, keyboards, AKERR_NULLPOINTER, "%s", SDL_GetError()); + FAIL_ZERO_RETURN(errctx, keyboards, AKERR_NULLPOINTER, "%s", SDL_GetError()); // The array is SDL's to allocate and ours to free -- that is the contract on // every SDL_Get*s() enumeration. Released in CLEANUP so the loop can fail @@ -201,9 +201,9 @@ akerr_ErrorContext *akgl_controller_list_keyboards(void) } CLEANUP { SDL_free(keyboards); keyboards = NULL; - } PROCESS(e) { - } FINISH(e, true); - SUCCEED_RETURN(e); + } PROCESS(errctx) { + } FINISH(errctx, true); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_controller_open_gamepads(void) @@ -213,14 +213,14 @@ akerr_ErrorContext *akgl_controller_open_gamepads(void) SDL_JoystickID *gamepads = NULL; SDL_Gamepad *gamepad = NULL; - PREPARE_ERROR(e); + PREPARE_ERROR(errctx); if ( SDL_HasGamepad() ) { gamepads = SDL_GetGamepads(&count); if ( count > 0 ) { - FAIL_ZERO_RETURN(e, gamepads, AKERR_NULLPOINTER, "%s", SDL_GetError()); + FAIL_ZERO_RETURN(errctx, gamepads, AKERR_NULLPOINTER, "%s", SDL_GetError()); for ( i = 0; i < count ; i++ ) { gamepad = SDL_OpenGamepad(gamepads[i]); - FAIL_ZERO_RETURN(e, gamepad, AKERR_NULLPOINTER, "%s", SDL_GetError()); + FAIL_ZERO_RETURN(errctx, gamepad, AKERR_NULLPOINTER, "%s", SDL_GetError()); SDL_Log("Gamepad %d is %s", i, SDL_GetGamepadNameForID(gamepads[i])); } SDL_free(gamepads); @@ -230,7 +230,7 @@ akerr_ErrorContext *akgl_controller_open_gamepads(void) } else { SDL_Log("No gamepads connected"); } - SUCCEED_RETURN(e); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_controller_handle_event(void *appstate, SDL_Event *event) diff --git a/src/game.c b/src/game.c index c7684ff..94d47f4 100644 --- a/src/game.c +++ b/src/game.c @@ -99,11 +99,11 @@ static akerr_ErrorContext *write_name_field(const char *name, size_t width, FILE { char field[AKGL_GAME_SAVE_MAX_NAME_FIELD]; - PREPARE_ERROR(e); - FAIL_ZERO_RETURN(e, name, AKERR_NULLPOINTER, "NULL name"); - FAIL_ZERO_RETURN(e, fp, AKERR_NULLPOINTER, "NULL file pointer"); + PREPARE_ERROR(errctx); + FAIL_ZERO_RETURN(errctx, name, AKERR_NULLPOINTER, "NULL name"); + FAIL_ZERO_RETURN(errctx, fp, AKERR_NULLPOINTER, "NULL file pointer"); FAIL_NONZERO_RETURN( - e, + errctx, (width > sizeof(field)), AKERR_OUTOFBOUNDS, "Name field width %zu exceeds the staging buffer (%zu)", @@ -112,8 +112,8 @@ static akerr_ErrorContext *write_name_field(const char *name, size_t width, FILE memset(&field, 0x00, sizeof(field)); strncpy((char *)&field, name, (width - 1)); - PASS(e, write_exact((char *)&field, 1, width, fp)); - SUCCEED_RETURN(e); + PASS(errctx, write_exact((char *)&field, 1, width, fp)); + SUCCEED_RETURN(errctx); } static akerr_ErrorContext *read_exact(void *ptr, size_t size, size_t nmemb, FILE *fp) @@ -135,31 +135,31 @@ akerr_ErrorContext *akgl_game_init(void) int screenheight = 0; int i = 0; - PREPARE_ERROR(e); + PREPARE_ERROR(errctx); // First, before anything that can raise: everything below reports through // AKGL_ERR_* codes, and a code raised before its name is registered prints // as "Unknown Error" in the stack trace the caller is left holding. - PASS(e, akgl_error_init()); + PASS(errctx, akgl_error_init()); strncpy((char *)&akgl_game.libversion, AKGL_VERSION, 32); akgl_game.gameStartTime = SDL_GetTicksNS(); akgl_game.lastIterTime = akgl_game.gameStartTime; akgl_game.lastFPSTime = akgl_game.gameStartTime; akgl_game.lowfpsfunc = &akgl_game_lowfps; akgl_game.statelock = SDL_CreateMutex(); - FAIL_ZERO_RETURN(e, akgl_game.statelock, AKGL_ERR_SDL, "%s", SDL_GetError()); - PASS(e, akgl_game_state_lock()); - FAIL_ZERO_RETURN(e, strlen((char *)&akgl_game.name), AKERR_NULLPOINTER, "Must provide game name"); - FAIL_ZERO_RETURN(e, strlen((char *)&akgl_game.version), AKERR_NULLPOINTER, "Must provide game version"); - FAIL_ZERO_RETURN(e, strlen((char *)&akgl_game.uri), AKERR_NULLPOINTER, "Must provide game uri"); - PASS(e, akgl_heap_init()); - PASS(e, akgl_registry_init_actor()); - PASS(e, akgl_registry_init_sprite()); - PASS(e, akgl_registry_init_spritesheet()); - PASS(e, akgl_registry_init_character()); - PASS(e, akgl_registry_init_font()); - PASS(e, akgl_registry_init_music()); - PASS(e, akgl_registry_init_properties()); - PASS(e, akgl_registry_init_actor_state_strings()); + FAIL_ZERO_RETURN(errctx, akgl_game.statelock, AKGL_ERR_SDL, "%s", SDL_GetError()); + PASS(errctx, akgl_game_state_lock()); + FAIL_ZERO_RETURN(errctx, strlen((char *)&akgl_game.name), AKERR_NULLPOINTER, "Must provide game name"); + FAIL_ZERO_RETURN(errctx, strlen((char *)&akgl_game.version), AKERR_NULLPOINTER, "Must provide game version"); + FAIL_ZERO_RETURN(errctx, strlen((char *)&akgl_game.uri), AKERR_NULLPOINTER, "Must provide game uri"); + PASS(errctx, akgl_heap_init()); + PASS(errctx, akgl_registry_init_actor()); + PASS(errctx, akgl_registry_init_sprite()); + PASS(errctx, akgl_registry_init_spritesheet()); + PASS(errctx, akgl_registry_init_character()); + PASS(errctx, akgl_registry_init_font()); + PASS(errctx, akgl_registry_init_music()); + PASS(errctx, akgl_registry_init_properties()); + PASS(errctx, akgl_registry_init_actor_state_strings()); SDL_SetAppMetadata(akgl_game.name, akgl_game.version, akgl_game.uri); @@ -168,7 +168,7 @@ akerr_ErrorContext *akgl_game_init(void) } FAIL_ZERO_RETURN( - e, + errctx, SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD | SDL_INIT_AUDIO), AKGL_ERR_SDL, "Couldn't initialize SDL: %s", @@ -178,27 +178,27 @@ akerr_ErrorContext *akgl_game_init(void) for ( i = 0; i < AKGL_SDL_GAMECONTROLLER_DB_LEN ; i++ ) { if ( SDL_AddGamepadMapping(SDL_GAMECONTROLLER_DB[i]) == -1 ) { - FAIL_ZERO_RETURN(e, 0, AKGL_ERR_SDL, "%s", SDL_GetError()); + FAIL_ZERO_RETURN(errctx, 0, AKGL_ERR_SDL, "%s", SDL_GetError()); } } - PASS(e, akgl_controller_open_gamepads()); + PASS(errctx, akgl_controller_open_gamepads()); FAIL_ZERO_RETURN( - e, + errctx, MIX_Init(), AKGL_ERR_SDL, "Couldn't initialize audio: %s", SDL_GetError()); akgl_mixer = MIX_CreateMixerDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, 0); FAIL_ZERO_RETURN( - e, + errctx, akgl_mixer, AKGL_ERR_SDL, "Unable to create mixer device: %s", SDL_GetError()); FAIL_ZERO_RETURN( - e, + errctx, TTF_Init(), AKGL_ERR_SDL, "Couldn't initialize front engine: %s", @@ -209,13 +209,13 @@ akerr_ErrorContext *akgl_game_init(void) akgl_physics = &akgl_default_physics; akgl_gamemap = &akgl_default_gamemap; - PASS(e, akgl_game_state_unlock()); - SUCCEED_RETURN(e); + PASS(errctx, akgl_game_state_unlock()); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_game_state_lock(void) { - PREPARE_ERROR(e); + PREPARE_ERROR(errctx); // Milliseconds, which is what SDL_Delay takes. This used to count against // AKGL_TIME_ONESEC_MS, a constant whose name said "one second in // milliseconds" and whose value was a thousand times that, so the budget @@ -224,7 +224,7 @@ akerr_ErrorContext *akgl_game_state_lock(void) while ( waitedms < AKGL_GAME_STATE_LOCK_BUDGET_MS ) { if ( SDL_TryLockMutex(akgl_game.statelock) == true ) { - SUCCEED_RETURN(e); + SUCCEED_RETURN(errctx); } waitedms += AKGL_GAME_STATE_LOCK_RETRY_MS; SDL_Delay(AKGL_GAME_STATE_LOCK_RETRY_MS); @@ -233,7 +233,7 @@ akerr_ErrorContext *akgl_game_state_lock(void) // call reports contention by returning false, not by setting an error -- so // say what actually happened and keep SDL's text as trailing context. FAIL_RETURN( - e, + errctx, AKGL_ERR_SDL, "Gave up waiting %d ms for the game state lock: %s", AKGL_GAME_STATE_LOCK_BUDGET_MS, @@ -242,9 +242,9 @@ akerr_ErrorContext *akgl_game_state_lock(void) akerr_ErrorContext *akgl_game_state_unlock(void) { - PREPARE_ERROR(e); + PREPARE_ERROR(errctx); SDL_UnlockMutex(akgl_game.statelock); - SUCCEED_RETURN(e); + SUCCEED_RETURN(errctx); } void akgl_game_update_fps(void) @@ -291,15 +291,15 @@ static void save_actorname_iterator(void *userdata, SDL_PropertiesID props, cons { FILE *fp = (FILE *)userdata; akgl_Actor *actor = NULL; - PREPARE_ERROR(e); + PREPARE_ERROR(errctx); ATTEMPT { - FAIL_ZERO_BREAK(e, fp, AKERR_NULLPOINTER, "NULL file pointer"); - CATCH(e, write_name_field(name, AKGL_ACTOR_MAX_NAME_LENGTH, fp)); + FAIL_ZERO_BREAK(errctx, fp, AKERR_NULLPOINTER, "NULL file pointer"); + CATCH(errctx, write_name_field(name, AKGL_ACTOR_MAX_NAME_LENGTH, fp)); actor = SDL_GetPointerProperty(props, name, NULL); - CATCH(e, write_exact(&actor, 1, sizeof(akgl_Actor *), fp)); + CATCH(errctx, write_exact(&actor, 1, sizeof(akgl_Actor *), fp)); } CLEANUP { - } PROCESS(e) { - } FINISH_NORETURN(e); + } PROCESS(errctx) { + } FINISH_NORETURN(errctx); } /** @@ -319,15 +319,15 @@ static void save_spritename_iterator(void *userdata, SDL_PropertiesID props, con { FILE *fp = (FILE *)userdata; akgl_Sprite *sprite = NULL; - PREPARE_ERROR(e); + PREPARE_ERROR(errctx); ATTEMPT { - FAIL_ZERO_BREAK(e, fp, AKERR_NULLPOINTER, "NULL file pointer"); + FAIL_ZERO_BREAK(errctx, fp, AKERR_NULLPOINTER, "NULL file pointer"); sprite = SDL_GetPointerProperty(props, name, NULL); - CATCH(e, write_name_field(name, AKGL_SPRITE_MAX_NAME_LENGTH, fp)); - CATCH(e, write_exact(&sprite, 1, sizeof(akgl_Sprite *), fp)); + CATCH(errctx, write_name_field(name, AKGL_SPRITE_MAX_NAME_LENGTH, fp)); + CATCH(errctx, write_exact(&sprite, 1, sizeof(akgl_Sprite *), fp)); } CLEANUP { - } PROCESS(e) { - } FINISH_NORETURN(e); + } PROCESS(errctx) { + } FINISH_NORETURN(errctx); } /** @@ -351,15 +351,15 @@ static void save_spritesheetname_iterator(void *userdata, SDL_PropertiesID props { FILE *fp = (FILE *)userdata; akgl_SpriteSheet *spritesheet = NULL; - PREPARE_ERROR(e); + PREPARE_ERROR(errctx); ATTEMPT { - FAIL_ZERO_BREAK(e, fp, AKERR_NULLPOINTER, "NULL file pointer"); + FAIL_ZERO_BREAK(errctx, fp, AKERR_NULLPOINTER, "NULL file pointer"); spritesheet = SDL_GetPointerProperty(props, name, NULL); - CATCH(e, write_name_field(name, AKGL_SPRITE_SHEET_MAX_FILENAME_LENGTH, fp)); - CATCH(e, write_exact(&spritesheet, 1, sizeof(akgl_SpriteSheet *), fp)); + CATCH(errctx, write_name_field(name, AKGL_SPRITE_SHEET_MAX_FILENAME_LENGTH, fp)); + CATCH(errctx, write_exact(&spritesheet, 1, sizeof(akgl_SpriteSheet *), fp)); } CLEANUP { - } PROCESS(e) { - } FINISH_NORETURN(e); + } PROCESS(errctx) { + } FINISH_NORETURN(errctx); } /** @@ -378,21 +378,21 @@ static void save_spritesheetname_iterator(void *userdata, SDL_PropertiesID props static void save_charactername_iterator(void *userdata, SDL_PropertiesID props, const char *name) { FILE *fp = (FILE *)userdata; - PREPARE_ERROR(e); + PREPARE_ERROR(errctx); akgl_Character *character = NULL; ATTEMPT { - FAIL_ZERO_BREAK(e, fp, AKERR_NULLPOINTER, "NULL file pointer"); + FAIL_ZERO_BREAK(errctx, fp, AKERR_NULLPOINTER, "NULL file pointer"); character = SDL_GetPointerProperty(props, name, NULL); - CATCH(e, write_name_field(name, AKGL_CHARACTER_MAX_NAME_LENGTH, fp)); - CATCH(e, write_exact(&character, 1, sizeof(akgl_Character *), fp)); + CATCH(errctx, write_name_field(name, AKGL_CHARACTER_MAX_NAME_LENGTH, fp)); + CATCH(errctx, write_exact(&character, 1, sizeof(akgl_Character *), fp)); } CLEANUP { - } PROCESS(e) { - } FINISH_NORETURN(e); + } PROCESS(errctx) { + } FINISH_NORETURN(errctx); } akerr_ErrorContext *akgl_game_save_actors(FILE *fp) { - PREPARE_ERROR(e); + PREPARE_ERROR(errctx); // Each name table ends with a zeroed name field and a zeroed pointer, which // is what load_objectnamemap() looks for to stop reading. The // terminator has to come from a buffer at least as long as the longest name @@ -405,51 +405,51 @@ akerr_ErrorContext *akgl_game_save_actors(FILE *fp) memset((void *)&nullbuf, 0x00, sizeof(nullbuf)); ATTEMPT { - FAIL_ZERO_BREAK(e, fp, AKERR_NULLPOINTER, "NULL file pointer"); + FAIL_ZERO_BREAK(errctx, fp, AKERR_NULLPOINTER, "NULL file pointer"); // write the actor name pointer table SDL_EnumerateProperties( AKGL_REGISTRY_ACTOR, &save_actorname_iterator, (void *)fp); - CATCH(e, write_exact((void *)&nullbuf, 1, AKGL_ACTOR_MAX_NAME_LENGTH, fp)); - CATCH(e, write_exact((void *)&nullbuf, 1, sizeof(akgl_Actor *), fp)); + CATCH(errctx, write_exact((void *)&nullbuf, 1, AKGL_ACTOR_MAX_NAME_LENGTH, fp)); + CATCH(errctx, write_exact((void *)&nullbuf, 1, sizeof(akgl_Actor *), fp)); // write the sprite name pointer table SDL_EnumerateProperties( AKGL_REGISTRY_SPRITE, &save_spritename_iterator, (void *)fp); - CATCH(e, write_exact((void *)&nullbuf, 1, AKGL_SPRITE_MAX_NAME_LENGTH, fp)); - CATCH(e, write_exact((void *)&nullbuf, 1, sizeof(akgl_Sprite *), fp)); + CATCH(errctx, write_exact((void *)&nullbuf, 1, AKGL_SPRITE_MAX_NAME_LENGTH, fp)); + CATCH(errctx, write_exact((void *)&nullbuf, 1, sizeof(akgl_Sprite *), fp)); // write the spritesheet name pointer table SDL_EnumerateProperties( AKGL_REGISTRY_SPRITESHEET, &save_spritesheetname_iterator, (void *)fp); - CATCH(e, write_exact((void *)&nullbuf, 1, AKGL_SPRITE_SHEET_MAX_FILENAME_LENGTH, fp)); - CATCH(e, write_exact((void *)&nullbuf, 1, sizeof(akgl_SpriteSheet *), fp)); + CATCH(errctx, write_exact((void *)&nullbuf, 1, AKGL_SPRITE_SHEET_MAX_FILENAME_LENGTH, fp)); + CATCH(errctx, write_exact((void *)&nullbuf, 1, sizeof(akgl_SpriteSheet *), fp)); // write the character name pointer table SDL_EnumerateProperties( AKGL_REGISTRY_CHARACTER, &save_charactername_iterator, (void *)fp); - CATCH(e, write_exact((void *)&nullbuf, 1, AKGL_CHARACTER_MAX_NAME_LENGTH, fp)); - CATCH(e, write_exact((void *)&nullbuf, 1, sizeof(akgl_Character *), fp)); + CATCH(errctx, write_exact((void *)&nullbuf, 1, AKGL_CHARACTER_MAX_NAME_LENGTH, fp)); + CATCH(errctx, write_exact((void *)&nullbuf, 1, sizeof(akgl_Character *), fp)); } CLEANUP { - } PROCESS(e) { - } FINISH(e, true); - SUCCEED_RETURN(e); + } PROCESS(errctx) { + } FINISH(errctx, true); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_game_save(char *fpath) { FILE *fp = NULL; - PREPARE_ERROR(e); + PREPARE_ERROR(errctx); ATTEMPT { - FAIL_ZERO_BREAK(e, fpath, AKERR_NULLPOINTER, "NULL file path"); - CATCH(e, aksl_fopen(fpath, "wb", &fp)); - CATCH(e, write_exact(&akgl_game, 1, sizeof(akgl_Game), fp)); - CATCH(e, akgl_game_save_actors(fp)); + FAIL_ZERO_BREAK(errctx, fpath, AKERR_NULLPOINTER, "NULL file path"); + CATCH(errctx, aksl_fopen(fpath, "wb", &fp)); + CATCH(errctx, write_exact(&akgl_game, 1, sizeof(akgl_Game), fp)); + CATCH(errctx, akgl_game_save_actors(fp)); } CLEANUP { // CLEANUP must precede PROCESS: with the two transposed, the fclose // lands inside the PROCESS switch and only runs when an error context @@ -457,9 +457,9 @@ akerr_ErrorContext *akgl_game_save(char *fpath) // closed its stream. if ( fp != NULL ) fclose(fp); - } PROCESS(e) { - } FINISH(e, true); - SUCCEED_RETURN(e); // SUCCEED_NORETURN if in main(). + } PROCESS(errctx) { + } FINISH(errctx, true); + SUCCEED_RETURN(errctx); // SUCCEED_NORETURN if in main(). } /** @@ -484,7 +484,7 @@ akerr_ErrorContext *akgl_game_save(char *fpath) * @param namelength Width of the table's name field, which must match what the * corresponding save iterator wrote. It also sizes a * variable-length array on the stack. - * @param ptrlength Width of the table's pointer field, i.e. `sizeof` the + * @param ptrlength Width of the table's pointer field, i.errctx. `sizeof` the * pointer type that table holds. * @param registry The registry to resolve names against -- #AKGL_REGISTRY_ACTOR * for the actor table, and so on. @@ -506,7 +506,7 @@ static akerr_ErrorContext *load_objectnamemap(FILE *fp, SDL_PropertiesID map, in int retval = 0; bool done = false; - PREPARE_ERROR(e); + PREPARE_ERROR(errctx); // The ATTEMPT block sits inside the loop on purpose. CATCH reports a // failure by breaking, and a break binds to the innermost enclosing switch // or loop, so a CATCH written directly inside `while` would leave the loop @@ -514,8 +514,8 @@ static akerr_ErrorContext *load_objectnamemap(FILE *fp, SDL_PropertiesID map, in // corrupt name table as a successful load. while ( done == false ) { ATTEMPT { - CATCH(e, read_exact((void *)&objname, 1, namelength, fp)); - CATCH(e, read_exact((void *)&ptr, 1, ptrlength, fp)); + CATCH(errctx, read_exact((void *)&objname, 1, namelength, fp)); + CATCH(errctx, read_exact((void *)&ptr, 1, ptrlength, fp)); // End of the map if ( ptr == 0x00 && objname[0] == 0x00 ) { done = true; @@ -529,46 +529,46 @@ static akerr_ErrorContext *load_objectnamemap(FILE *fp, SDL_PropertiesID map, in // SDL_Properties objects can only use string keys, so we can't use the // old pointer as a key without first converting it to a string. - CATCH(e, aksl_memset((void *)&ptrstring, 0x00, 32)); + CATCH(errctx, aksl_memset((void *)&ptrstring, 0x00, 32)); snprintf((char *)&ptrstring, 32, "%p", ptr); SDL_SetPointerProperty( map, ptrstring, SDL_GetPointerProperty(registry, objname, NULL)); } CLEANUP { - } PROCESS(e) { - } FINISH(e, true); + } PROCESS(errctx) { + } FINISH(errctx, true); }; - SUCCEED_RETURN(e); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_game_load_versioncmp(char *versiontype, char *newversion, char *curversion) { semver_t current_version = {}; semver_t compare_version = {}; - PREPARE_ERROR(e); - FAIL_ZERO_RETURN(e, versiontype, AKERR_NULLPOINTER, "NULL argument"); - FAIL_ZERO_RETURN(e, curversion, AKERR_NULLPOINTER, "NULL argument"); - FAIL_ZERO_RETURN(e, newversion, AKERR_NULLPOINTER, "NULL argument"); + PREPARE_ERROR(errctx); + FAIL_ZERO_RETURN(errctx, versiontype, AKERR_NULLPOINTER, "NULL argument"); + FAIL_ZERO_RETURN(errctx, curversion, AKERR_NULLPOINTER, "NULL argument"); + FAIL_ZERO_RETURN(errctx, newversion, AKERR_NULLPOINTER, "NULL argument"); ATTEMPT { // Check save game library version FAIL_NONZERO_BREAK( - e, + errctx, semver_parse((const char *)curversion, ¤t_version), AKERR_VALUE, "Invalid semantic %s version in current game: %s", versiontype, (char *)curversion); FAIL_NONZERO_BREAK( - e, + errctx, semver_parse((const char *)newversion, &compare_version), AKERR_VALUE, "Invalid semantic %s version in save game: %s", versiontype, (char *)&newversion); FAIL_ZERO_BREAK( - e, + errctx, semver_satisfies(compare_version, current_version, "="), AKERR_API, "Incompatible save game %s version (%s != %s)", @@ -578,9 +578,9 @@ akerr_ErrorContext *akgl_game_load_versioncmp(char *versiontype, char *newversio } CLEANUP { semver_free(¤t_version); semver_free(&compare_version); - } PROCESS(e) { - } FINISH(e, true); - SUCCEED_RETURN(e); + } PROCESS(errctx) { + } FINISH(errctx, true); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_game_load(char *fpath) @@ -592,21 +592,21 @@ akerr_ErrorContext *akgl_game_load(char *fpath) SDL_PropertiesID charactermap; FILE *fp = NULL; - PREPARE_ERROR(e); - FAIL_ZERO_RETURN(e, fpath, AKERR_NULLPOINTER, "NULL file path"); + PREPARE_ERROR(errctx); + FAIL_ZERO_RETURN(errctx, fpath, AKERR_NULLPOINTER, "NULL file path"); ATTEMPT { - CATCH(e, aksl_fopen(fpath, "rb", &fp)); - CATCH(e, read_exact((void *)&savegame, 1, sizeof(akgl_Game), fp)); - CATCH(e, akgl_game_load_versioncmp("library", (char *)&savegame.libversion, (char *)AKGL_VERSION)); - CATCH(e, akgl_game_load_versioncmp("game", (char *)&savegame.version, (char *)&akgl_game.version)); + CATCH(errctx, aksl_fopen(fpath, "rb", &fp)); + CATCH(errctx, read_exact((void *)&savegame, 1, sizeof(akgl_Game), fp)); + CATCH(errctx, akgl_game_load_versioncmp("library", (char *)&savegame.libversion, (char *)AKGL_VERSION)); + CATCH(errctx, akgl_game_load_versioncmp("game", (char *)&savegame.version, (char *)&akgl_game.version)); FAIL_NONZERO_BREAK( - e, + errctx, strncmp((char *)&savegame.name, (char *)&akgl_game.name, 256), AKERR_API, "Savegame is not compatible with this game"); FAIL_NONZERO_BREAK( - e, + errctx, strncmp((char *)&savegame.uri, (char *)&akgl_game.uri, 256), AKERR_API, "Savegame is not compatible with this game"); @@ -614,30 +614,30 @@ akerr_ErrorContext *akgl_game_load(char *fpath) memcpy((void *)&akgl_game, (void *)&savegame, sizeof(akgl_Game)); // Load actor name map actormap = SDL_CreateProperties(); - CATCH(e, load_objectnamemap(fp, actormap, AKGL_ACTOR_MAX_NAME_LENGTH, sizeof(akgl_Actor *), AKGL_REGISTRY_ACTOR)); + CATCH(errctx, load_objectnamemap(fp, actormap, AKGL_ACTOR_MAX_NAME_LENGTH, sizeof(akgl_Actor *), AKGL_REGISTRY_ACTOR)); // Load sprite name map spritemap = SDL_CreateProperties(); - CATCH(e, load_objectnamemap(fp, spritemap, AKGL_ACTOR_MAX_NAME_LENGTH, sizeof(akgl_Sprite *), AKGL_REGISTRY_SPRITE)); + CATCH(errctx, load_objectnamemap(fp, spritemap, AKGL_ACTOR_MAX_NAME_LENGTH, sizeof(akgl_Sprite *), AKGL_REGISTRY_SPRITE)); // Load spritesheet name map spritesheetmap = SDL_CreateProperties(); - CATCH(e, load_objectnamemap(fp, spritesheetmap, AKGL_ACTOR_MAX_NAME_LENGTH, sizeof(akgl_SpriteSheet *), AKGL_REGISTRY_SPRITESHEET)); + CATCH(errctx, load_objectnamemap(fp, spritesheetmap, AKGL_ACTOR_MAX_NAME_LENGTH, sizeof(akgl_SpriteSheet *), AKGL_REGISTRY_SPRITESHEET)); // Load character name map charactermap = SDL_CreateProperties(); - CATCH(e, load_objectnamemap(fp, charactermap, AKGL_ACTOR_MAX_NAME_LENGTH, sizeof(akgl_Character *), AKGL_REGISTRY_CHARACTER)); + CATCH(errctx, load_objectnamemap(fp, charactermap, AKGL_ACTOR_MAX_NAME_LENGTH, sizeof(akgl_Character *), AKGL_REGISTRY_CHARACTER)); // Now that we have all of our pointer maps built, we can load the actual binary objects and reset their pointers } CLEANUP { if ( fp != NULL ) { fclose(fp); } - } PROCESS(e) { - } FINISH(e, true); + } PROCESS(errctx) { + } FINISH(errctx, true); - SUCCEED_RETURN(e); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_game_update(akgl_Iterator *opflags) { - PREPARE_ERROR(e); + PREPARE_ERROR(errctx); akgl_Iterator defflags = { .flags = (AKGL_ITERATOR_OP_LAYERMASK | AKGL_ITERATOR_OP_LAYERMASK), .layerid = 0 @@ -649,7 +649,7 @@ akerr_ErrorContext *akgl_game_update(akgl_Iterator *opflags) opflags = &defflags; } - PASS(e, akgl_game_state_lock()); + PASS(errctx, akgl_game_state_lock()); akgl_game_update_fps(); @@ -663,15 +663,15 @@ akerr_ErrorContext *akgl_game_update(akgl_Iterator *opflags) continue; } if ( AKGL_BITMASK_HAS(opflags->flags, AKGL_ITERATOR_OP_TILEMAPSCALE) ) { - PASS(e, akgl_tilemap_scale_actor(akgl_gamemap, actor)); + PASS(errctx, akgl_tilemap_scale_actor(akgl_gamemap, actor)); } else { actor->scale = 1.0; } - PASS(e, actor->updatefunc(actor)); + PASS(errctx, actor->updatefunc(actor)); } } - PASS(e, akgl_physics->simulate(akgl_physics, NULL)); - PASS(e, akgl_renderer->draw_world(akgl_renderer, NULL)); - PASS(e, akgl_game_state_unlock()); - SUCCEED_RETURN(e); + PASS(errctx, akgl_physics->simulate(akgl_physics, NULL)); + PASS(errctx, akgl_renderer->draw_world(akgl_renderer, NULL)); + PASS(errctx, akgl_game_state_unlock()); + SUCCEED_RETURN(errctx); } diff --git a/src/heap.c b/src/heap.c index 7b6a8b5..758d7bb 100644 --- a/src/heap.c +++ b/src/heap.c @@ -42,11 +42,11 @@ akerr_ErrorContext *akgl_heap_init(void) akerr_ErrorContext *akgl_heap_init_actor(void) { - PREPARE_ERROR(e); + PREPARE_ERROR(errctx); for ( int i = 0; i < AKGL_MAX_HEAP_ACTOR; i++) { memset(&akgl_heap_actors[i], 0x00, sizeof(akgl_Actor)); } - SUCCEED_RETURN(e); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_heap_next_actor(akgl_Actor **dest) diff --git a/src/physics.c b/src/physics.c index fa5abd1..834945f 100644 --- a/src/physics.c +++ b/src/physics.c @@ -14,48 +14,48 @@ akerr_ErrorContext *akgl_physics_null_gravity(akgl_PhysicsBackend *self, akgl_Actor *actor, float32_t dt) { - PREPARE_ERROR(e); - FAIL_ZERO_RETURN(e, self, AKERR_NULLPOINTER, "self"); - FAIL_ZERO_RETURN(e, actor, AKERR_NULLPOINTER, "actor"); - SUCCEED_RETURN(e); + PREPARE_ERROR(errctx); + FAIL_ZERO_RETURN(errctx, self, AKERR_NULLPOINTER, "self"); + FAIL_ZERO_RETURN(errctx, actor, AKERR_NULLPOINTER, "actor"); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_physics_null_collide(akgl_PhysicsBackend *self, akgl_Actor *a1, akgl_Actor *a2) { - PREPARE_ERROR(e); - FAIL_ZERO_RETURN(e, self, AKERR_NULLPOINTER, "self"); - FAIL_ZERO_RETURN(e, a1, AKERR_NULLPOINTER, "a1"); - FAIL_ZERO_RETURN(e, a2, AKERR_NULLPOINTER, "a2"); - SUCCEED_RETURN(e); + PREPARE_ERROR(errctx); + FAIL_ZERO_RETURN(errctx, self, AKERR_NULLPOINTER, "self"); + FAIL_ZERO_RETURN(errctx, a1, AKERR_NULLPOINTER, "a1"); + FAIL_ZERO_RETURN(errctx, a2, AKERR_NULLPOINTER, "a2"); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_physics_null_move(akgl_PhysicsBackend *self, akgl_Actor *actor, float32_t dt) { - PREPARE_ERROR(e); - FAIL_ZERO_RETURN(e, self, AKERR_NULLPOINTER, "self"); - FAIL_ZERO_RETURN(e, actor, AKERR_NULLPOINTER, "actor"); - SUCCEED_RETURN(e); + PREPARE_ERROR(errctx); + FAIL_ZERO_RETURN(errctx, self, AKERR_NULLPOINTER, "self"); + FAIL_ZERO_RETURN(errctx, actor, AKERR_NULLPOINTER, "actor"); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_physics_init_null(akgl_PhysicsBackend *self) { - PREPARE_ERROR(e); - FAIL_ZERO_RETURN(e, self, AKERR_NULLPOINTER, "self"); + PREPARE_ERROR(errctx); + FAIL_ZERO_RETURN(errctx, self, AKERR_NULLPOINTER, "self"); self->gravity = akgl_physics_null_gravity; self->collide = akgl_physics_null_collide; self->move = akgl_physics_null_move; self->simulate = akgl_physics_simulate; - SUCCEED_RETURN(e); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_physics_arcade_gravity(akgl_PhysicsBackend *self, akgl_Actor *actor, float32_t dt) { - PREPARE_ERROR(e); - FAIL_ZERO_RETURN(e, self, AKERR_NULLPOINTER, "self"); - FAIL_ZERO_RETURN(e, actor, AKERR_NULLPOINTER, "actor"); + PREPARE_ERROR(errctx); + FAIL_ZERO_RETURN(errctx, self, AKERR_NULLPOINTER, "self"); + FAIL_ZERO_RETURN(errctx, actor, AKERR_NULLPOINTER, "actor"); if ( self->gravity_x != 0 ) { // Assume the X origin is - (screen left) @@ -70,34 +70,34 @@ akerr_ErrorContext *akgl_physics_arcade_gravity(akgl_PhysicsBackend *self, akgl_ actor->ez -= (self->gravity_z * dt); } - SUCCEED_RETURN(e); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_physics_arcade_collide(akgl_PhysicsBackend *self, akgl_Actor *a1, akgl_Actor *a2) { - PREPARE_ERROR(e); - FAIL_ZERO_RETURN(e, self, AKERR_NULLPOINTER, "self"); - FAIL_RETURN(e, AKERR_API, "Not implemented"); - SUCCEED_RETURN(e); + PREPARE_ERROR(errctx); + FAIL_ZERO_RETURN(errctx, self, AKERR_NULLPOINTER, "self"); + FAIL_RETURN(errctx, AKERR_API, "Not implemented"); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_physics_arcade_move(akgl_PhysicsBackend *self, akgl_Actor *actor, float32_t dt) { - PREPARE_ERROR(e); - FAIL_ZERO_RETURN(e, self, AKERR_NULLPOINTER, "self"); - FAIL_ZERO_RETURN(e, actor, AKERR_NULLPOINTER, "actor"); + PREPARE_ERROR(errctx); + FAIL_ZERO_RETURN(errctx, self, AKERR_NULLPOINTER, "self"); + FAIL_ZERO_RETURN(errctx, actor, AKERR_NULLPOINTER, "actor"); actor->x += actor->vx * dt; actor->y += actor->vy * dt; actor->z += actor->vz * dt; - SUCCEED_RETURN(e); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_physics_init_arcade(akgl_PhysicsBackend *self) { akgl_String *tmp; - PREPARE_ERROR(e); - FAIL_ZERO_RETURN(e, self, AKERR_NULLPOINTER, "self"); - PASS(e, akgl_heap_next_string(&tmp)); + PREPARE_ERROR(errctx); + FAIL_ZERO_RETURN(errctx, self, AKERR_NULLPOINTER, "self"); + PASS(errctx, akgl_heap_next_string(&tmp)); self->gravity = akgl_physics_arcade_gravity; self->collide = akgl_physics_arcade_collide; @@ -105,29 +105,29 @@ akerr_ErrorContext *akgl_physics_init_arcade(akgl_PhysicsBackend *self) self->simulate = akgl_physics_simulate; ATTEMPT { - CATCH(e, akgl_get_property("physics.gravity.x", &tmp, "0.0")); - CATCH(e, aksl_atof(tmp->data, &self->gravity_x)); - CATCH(e, akgl_get_property("physics.gravity.y", &tmp, "0.0")); - CATCH(e, aksl_atof(tmp->data, &self->gravity_y)); - CATCH(e, akgl_get_property("physics.gravity.z", &tmp, "0.0")); - CATCH(e, aksl_atof(tmp->data, &self->gravity_z)); - CATCH(e, akgl_get_property("physics.drag.x", &tmp, "0.0")); - CATCH(e, aksl_atof(tmp->data, &self->drag_x)); - CATCH(e, akgl_get_property("physics.drag.y", &tmp, "0.0")); - CATCH(e, aksl_atof(tmp->data, &self->drag_y)); - CATCH(e, akgl_get_property("physics.drag.z", &tmp, "0.0")); - CATCH(e, aksl_atof(tmp->data, &self->drag_z)); + CATCH(errctx, akgl_get_property("physics.gravity.x", &tmp, "0.0")); + CATCH(errctx, aksl_atof(tmp->data, &self->gravity_x)); + CATCH(errctx, akgl_get_property("physics.gravity.y", &tmp, "0.0")); + CATCH(errctx, aksl_atof(tmp->data, &self->gravity_y)); + CATCH(errctx, akgl_get_property("physics.gravity.z", &tmp, "0.0")); + CATCH(errctx, aksl_atof(tmp->data, &self->gravity_z)); + CATCH(errctx, akgl_get_property("physics.drag.x", &tmp, "0.0")); + CATCH(errctx, aksl_atof(tmp->data, &self->drag_x)); + CATCH(errctx, akgl_get_property("physics.drag.y", &tmp, "0.0")); + CATCH(errctx, aksl_atof(tmp->data, &self->drag_y)); + CATCH(errctx, akgl_get_property("physics.drag.z", &tmp, "0.0")); + CATCH(errctx, aksl_atof(tmp->data, &self->drag_z)); } CLEANUP { IGNORE(akgl_heap_release_string(tmp)); - } PROCESS(e) { - } FINISH(e, true); + } PROCESS(errctx) { + } FINISH(errctx, true); - SUCCEED_RETURN(e); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_physics_simulate(akgl_PhysicsBackend *self, akgl_Iterator *opflags) { - PREPARE_ERROR(e); + PREPARE_ERROR(errctx); akgl_Iterator defflags = { .flags = 0, .layerid = 0 @@ -136,8 +136,8 @@ akerr_ErrorContext *akgl_physics_simulate(akgl_PhysicsBackend *self, akgl_Iterat float32_t dt = 0; akgl_Actor *actor = NULL; - FAIL_ZERO_RETURN(e, self, AKERR_NULLPOINTER, "self"); - FAIL_ZERO_RETURN(e, self->move, AKERR_NULLPOINTER, "self->move"); + FAIL_ZERO_RETURN(errctx, self, AKERR_NULLPOINTER, "self"); + FAIL_ZERO_RETURN(errctx, self->move, AKERR_NULLPOINTER, "self->move"); // Reading the elapsed time requires self, so it cannot be hoisted above // the null check. @@ -202,8 +202,8 @@ akerr_ErrorContext *akgl_physics_simulate(akgl_PhysicsBackend *self, akgl_Iterat } } ATTEMPT { - CATCH(e, actor->movementlogicfunc(actor, dt)); - PASS(e, self->gravity(self, actor, dt)); + CATCH(errctx, actor->movementlogicfunc(actor, dt)); + PASS(errctx, self->gravity(self, actor, dt)); // Counteract velocity with atmospheric drag if ( self->drag_x != 0 ) { @@ -220,31 +220,31 @@ akerr_ErrorContext *akgl_physics_simulate(akgl_PhysicsBackend *self, akgl_Iterat actor->vy = actor->ey + actor->ty; actor->vz = actor->ez + actor->tz; - PASS(e, self->move(self, actor, dt)); + PASS(errctx, self->move(self, actor, dt)); } CLEANUP { - } PROCESS(e) { - } HANDLE(e, AKGL_ERR_LOGICINTERRUPT) { + } PROCESS(errctx) { + } HANDLE(errctx, AKGL_ERR_LOGICINTERRUPT) { // noop - } FINISH(e, true); + } FINISH(errctx, true); } self->gravity_time = curtime; - SUCCEED_RETURN(e); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_physics_factory(akgl_PhysicsBackend *self, akgl_String *type) { uint32_t hashval; - PREPARE_ERROR(e); - FAIL_ZERO_RETURN(e, self, AKERR_NULLPOINTER, "self"); - FAIL_ZERO_RETURN(e, type, AKERR_NULLPOINTER, "type"); + PREPARE_ERROR(errctx); + FAIL_ZERO_RETURN(errctx, self, AKERR_NULLPOINTER, "self"); + FAIL_ZERO_RETURN(errctx, type, AKERR_NULLPOINTER, "type"); if ( strncmp(type->data, "null", 4) == 0) { - PASS(e, akgl_physics_init_null(self)); - SUCCEED_RETURN(e); + PASS(errctx, akgl_physics_init_null(self)); + SUCCEED_RETURN(errctx); } if ( strncmp(type->data, "arcade", 6) == 0) { - PASS(e, akgl_physics_init_arcade(self)); - SUCCEED_RETURN(e); + PASS(errctx, akgl_physics_init_arcade(self)); + SUCCEED_RETURN(errctx); } - FAIL_RETURN(e, AKERR_KEY, "Invalid physics engine %s", type->data); + FAIL_RETURN(errctx, AKERR_KEY, "Invalid physics engine %s", type->data); } diff --git a/src/registry.c b/src/registry.c index 77c0e52..f8da9e7 100644 --- a/src/registry.c +++ b/src/registry.c @@ -177,11 +177,11 @@ akerr_ErrorContext *akgl_registry_load_properties(char *fname) akerr_ErrorContext *akgl_set_property(char *name, char *value) { - PREPARE_ERROR(e); - FAIL_ZERO_RETURN(e, name, AKERR_NULLPOINTER, "NULL char *"); - FAIL_ZERO_RETURN(e, value, AKERR_NULLPOINTER, "NULL char *"); + PREPARE_ERROR(errctx); + FAIL_ZERO_RETURN(errctx, name, AKERR_NULLPOINTER, "NULL char *"); + FAIL_ZERO_RETURN(errctx, value, AKERR_NULLPOINTER, "NULL char *"); SDL_SetStringProperty(AKGL_REGISTRY_PROPERTIES, name, value); - SUCCEED_RETURN(e); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_get_property(char *name, akgl_String **dest, char *def) @@ -189,12 +189,12 @@ akerr_ErrorContext *akgl_get_property(char *name, akgl_String **dest, char *def) const char *value = NULL; size_t valuelen = 0; - PREPARE_ERROR(e); - FAIL_ZERO_RETURN(e, name, AKERR_NULLPOINTER, "NULL char *"); - FAIL_ZERO_RETURN(e, dest, AKERR_NULLPOINTER, "NULL akgl_String *"); + PREPARE_ERROR(errctx); + FAIL_ZERO_RETURN(errctx, name, AKERR_NULLPOINTER, "NULL char *"); + FAIL_ZERO_RETURN(errctx, dest, AKERR_NULLPOINTER, "NULL akgl_String *"); ATTEMPT { if ( *dest == NULL ) { - CATCH(e, akgl_heap_next_string(dest)); + CATCH(errctx, akgl_heap_next_string(dest)); } // Copy the value's own length, not the destination's capacity. What // SDL hands back is its strdup of the value -- four bytes for "0.0" -- @@ -207,23 +207,23 @@ akerr_ErrorContext *akgl_get_property(char *name, akgl_String **dest, char *def) // which is what the header has always promised. It used to arrive from // inside aksl_memcpy; now it is raised here, before anything is measured. FAIL_ZERO_BREAK( - e, + errctx, value, AKERR_NULLPOINTER, "Property %s is not set and no default was given", name); valuelen = strlen(value); FAIL_NONZERO_BREAK( - e, + errctx, (valuelen >= AKGL_MAX_STRING_LENGTH), AKERR_OUTOFBOUNDS, "Property %s is %zu bytes, which does not fit an akgl_String (%d)", name, valuelen, AKGL_MAX_STRING_LENGTH); - CATCH(e, aksl_memcpy((*dest)->data, (void *)value, (valuelen + 1))); + CATCH(errctx, aksl_memcpy((*dest)->data, (void *)value, (valuelen + 1))); } CLEANUP { - } PROCESS(e) { - } FINISH(e, true); - SUCCEED_RETURN(e); + } PROCESS(errctx) { + } FINISH(errctx, true); + SUCCEED_RETURN(errctx); } diff --git a/src/renderer.c b/src/renderer.c index a65878c..79b282e 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -20,19 +20,19 @@ akerr_ErrorContext *akgl_render_2d_init(akgl_RenderBackend *self) akgl_String *height = NULL; int screenwidth; int screenheight; - PREPARE_ERROR(e); - FAIL_ZERO_RETURN(e, self, AKERR_NULLPOINTER, "self"); + PREPARE_ERROR(errctx); + FAIL_ZERO_RETURN(errctx, self, AKERR_NULLPOINTER, "self"); - PASS(e, akgl_get_property("game.screenwidth", &width, "0")); - PASS(e, akgl_get_property("game.screenheight", &height, "0")); - PASS(e, aksl_atoi(width->data, &screenwidth)); - PASS(e, aksl_atoi(height->data, &screenheight)); + PASS(errctx, akgl_get_property("game.screenwidth", &width, "0")); + PASS(errctx, akgl_get_property("game.screenheight", &height, "0")); + PASS(errctx, aksl_atoi(width->data, &screenwidth)); + PASS(errctx, aksl_atoi(height->data, &screenheight)); SDL_Log("Initializing screen (%sx%s = %dx%d)", width->data, height->data, screenwidth, screenheight); - PASS(e, akgl_heap_release_string(width)); - PASS(e, akgl_heap_release_string(height)); + PASS(errctx, akgl_heap_release_string(width)); + PASS(errctx, akgl_heap_release_string(height)); FAIL_ZERO_RETURN( - e, + errctx, SDL_CreateWindowAndRenderer(akgl_game.uri, screenwidth, screenheight, 0, &akgl_window, &self->sdl_renderer), AKGL_ERR_SDL, "Couldn't create window/renderer: %s", @@ -43,14 +43,14 @@ akerr_ErrorContext *akgl_render_2d_init(akgl_RenderBackend *self) akgl_camera->w = screenwidth; akgl_camera->h = screenheight; - PASS(e, akgl_render_2d_bind(self)); - SUCCEED_RETURN(e); + PASS(errctx, akgl_render_2d_bind(self)); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_render_2d_bind(akgl_RenderBackend *self) { - PREPARE_ERROR(e); - FAIL_ZERO_RETURN(e, self, AKERR_NULLPOINTER, "self"); + PREPARE_ERROR(errctx); + FAIL_ZERO_RETURN(errctx, self, AKERR_NULLPOINTER, "self"); // Deliberately does not touch self->sdl_renderer: a host that owns its own // window has already put one there, and this is the only way it gets a @@ -61,84 +61,84 @@ akerr_ErrorContext *akgl_render_2d_bind(akgl_RenderBackend *self) self->draw_texture = &akgl_render_2d_draw_texture; self->draw_mesh = &akgl_render_2d_draw_mesh; self->draw_world = &akgl_render_2d_draw_world; - SUCCEED_RETURN(e); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_render_2d_shutdown(akgl_RenderBackend *self) { - PREPARE_ERROR(e); - FAIL_ZERO_RETURN(e, self, AKERR_NULLPOINTER, "self"); - SUCCEED_RETURN(e); + PREPARE_ERROR(errctx); + FAIL_ZERO_RETURN(errctx, self, AKERR_NULLPOINTER, "self"); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_render_2d_frame_start(akgl_RenderBackend *self) { - PREPARE_ERROR(e); - FAIL_ZERO_RETURN(e, self, AKERR_NULLPOINTER, "self"); - FAIL_ZERO_RETURN(e, self->sdl_renderer, AKERR_NULLPOINTER, "No valid SDL rendering backend"); + PREPARE_ERROR(errctx); + FAIL_ZERO_RETURN(errctx, self, AKERR_NULLPOINTER, "self"); + FAIL_ZERO_RETURN(errctx, self->sdl_renderer, AKERR_NULLPOINTER, "No valid SDL rendering backend"); SDL_SetRenderDrawColor(self->sdl_renderer, 0, 0, 0, 255); SDL_RenderClear(self->sdl_renderer); - SUCCEED_RETURN(e); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_render_2d_frame_end(akgl_RenderBackend *self) { - PREPARE_ERROR(e); - FAIL_ZERO_RETURN(e, self, AKERR_NULLPOINTER, "self"); - FAIL_ZERO_RETURN(e, self->sdl_renderer, AKERR_NULLPOINTER, "No valid SDL rendering backend"); + PREPARE_ERROR(errctx); + FAIL_ZERO_RETURN(errctx, self, AKERR_NULLPOINTER, "self"); + FAIL_ZERO_RETURN(errctx, self->sdl_renderer, AKERR_NULLPOINTER, "No valid SDL rendering backend"); SDL_RenderPresent(self->sdl_renderer); - SUCCEED_RETURN(e); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_render_2d_draw_texture(akgl_RenderBackend *self, SDL_Texture *texture, SDL_FRect *src, SDL_FRect *dest, double angle, SDL_FPoint *center, SDL_FlipMode flip) { - PREPARE_ERROR(e); - FAIL_ZERO_RETURN(e, self, AKERR_NULLPOINTER, "self"); - FAIL_ZERO_RETURN(e, texture, AKERR_NULLPOINTER, "texture"); - //FAIL_ZERO_RETURN(e, src, AKERR_NULLPOINTER, "src"); - //FAIL_ZERO_RETURN(e, dest, AKERR_NULLPOINTER, "dest"); + PREPARE_ERROR(errctx); + FAIL_ZERO_RETURN(errctx, self, AKERR_NULLPOINTER, "self"); + FAIL_ZERO_RETURN(errctx, texture, AKERR_NULLPOINTER, "texture"); + //FAIL_ZERO_RETURN(errctx, src, AKERR_NULLPOINTER, "src"); + //FAIL_ZERO_RETURN(errctx, dest, AKERR_NULLPOINTER, "dest"); if ( angle != 0 ) { - FAIL_ZERO_RETURN(e, center, AKERR_NULLPOINTER, "center"); + FAIL_ZERO_RETURN(errctx, center, AKERR_NULLPOINTER, "center"); FAIL_ZERO_RETURN( - e, + errctx, SDL_RenderTextureRotated(self->sdl_renderer, texture, src, dest, angle, center, flip), AKERR_NULLPOINTER, "%s", SDL_GetError() ); } else { FAIL_ZERO_RETURN( - e, + errctx, SDL_RenderTexture(self->sdl_renderer, texture, src, dest), AKERR_NULLPOINTER, "%s", SDL_GetError() ); } - SUCCEED_RETURN(e); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_render_2d_draw_mesh(akgl_RenderBackend *self) { - PREPARE_ERROR(e); - FAIL_RETURN(e, AKERR_API, "Not implemented"); + PREPARE_ERROR(errctx); + FAIL_RETURN(errctx, AKERR_API, "Not implemented"); } akerr_ErrorContext *akgl_render_2d_draw_world(akgl_RenderBackend *self, akgl_Iterator *opflags) { - PREPARE_ERROR(e); + PREPARE_ERROR(errctx); akgl_Iterator defflags; SDL_Time curTime = SDL_GetTicksNS(); akgl_Actor *actor = NULL; int j = 0; - FAIL_ZERO_RETURN(e, self, AKERR_NULLPOINTER, "self"); + FAIL_ZERO_RETURN(errctx, self, AKERR_NULLPOINTER, "self"); if ( opflags == NULL ) { opflags = &defflags; - PASS(e, aksl_memset((void *)opflags, 0x00, sizeof(akgl_Iterator))); + PASS(errctx, aksl_memset((void *)opflags, 0x00, sizeof(akgl_Iterator))); } for ( int i = 0; i < AKGL_TILEMAP_MAX_LAYERS ; i++ ) { if ( i < akgl_gamemap->numlayers ) { - PASS(e, akgl_tilemap_draw(akgl_gamemap, akgl_camera, i)); + PASS(errctx, akgl_tilemap_draw(akgl_gamemap, akgl_camera, i)); } for ( int j = 0; j < AKGL_MAX_HEAP_ACTOR ; j++ ) { actor = &akgl_heap_actors[j]; @@ -148,9 +148,9 @@ akerr_ErrorContext *akgl_render_2d_draw_world(akgl_RenderBackend *self, akgl_Ite if ( actor->layer != i ) { continue; } - PASS(e, actor->renderfunc(actor)); + PASS(errctx, actor->renderfunc(actor)); } } - SUCCEED_RETURN(e); + SUCCEED_RETURN(errctx); } diff --git a/src/sprite.c b/src/sprite.c index 4d540a7..820c46d 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -21,11 +21,11 @@ akerr_ErrorContext *akgl_spritesheet_coords_for_frame(akgl_Sprite *self, SDL_FRect *srccoords, uint8_t frameid) { - PREPARE_ERROR(e); + PREPARE_ERROR(errctx); - FAIL_ZERO_RETURN(e, self, AKERR_NULLPOINTER, "NULL sprite"); - FAIL_ZERO_RETURN(e, srccoords, AKERR_NULLPOINTER, "NULL SDL_Rect"); - FAIL_ZERO_RETURN(e, self->sheet, AKERR_NULLPOINTER, "NULL spritesheet"); + FAIL_ZERO_RETURN(errctx, self, AKERR_NULLPOINTER, "NULL sprite"); + FAIL_ZERO_RETURN(errctx, srccoords, AKERR_NULLPOINTER, "NULL SDL_Rect"); + FAIL_ZERO_RETURN(errctx, self->sheet, AKERR_NULLPOINTER, "NULL spritesheet"); srccoords->x = self->width * self->frameids[frameid]; if ( srccoords->x >= self->sheet->texture->w ) { @@ -37,7 +37,7 @@ akerr_ErrorContext *akgl_spritesheet_coords_for_frame(akgl_Sprite *self, SDL_FRe srccoords->w = self->width; srccoords->h = self->height; - SUCCEED_RETURN(e); + SUCCEED_RETURN(errctx); } /** diff --git a/src/staticstring.c b/src/staticstring.c index 8dd51cf..8026fa9 100644 --- a/src/staticstring.c +++ b/src/staticstring.c @@ -22,14 +22,14 @@ akerr_ErrorContext *akgl_string_initialize(akgl_String *obj, char *init) akerr_ErrorContext *akgl_string_copy(akgl_String *src, akgl_String *dst, int count) { - PREPARE_ERROR(e); - FAIL_ZERO_RETURN(e, src, AKERR_NULLPOINTER, "NULL argument"); - FAIL_ZERO_RETURN(e, dst, AKERR_NULLPOINTER, "NULL argument"); + PREPARE_ERROR(errctx); + FAIL_ZERO_RETURN(errctx, src, AKERR_NULLPOINTER, "NULL argument"); + FAIL_ZERO_RETURN(errctx, dst, AKERR_NULLPOINTER, "NULL argument"); if ( count == 0 ) { count = AKGL_MAX_STRING_LENGTH; } if ( (char *)dst->data != strncpy((char *)&dst->data, (char *)&src->data, count) ) { - FAIL_RETURN(e, errno, "strncpy"); + FAIL_RETURN(errctx, errno, "strncpy"); } - SUCCEED_RETURN(e); + SUCCEED_RETURN(errctx); } diff --git a/src/tilemap.c b/src/tilemap.c index 24fd886..2280f1d 100644 --- a/src/tilemap.c +++ b/src/tilemap.c @@ -132,41 +132,41 @@ akerr_ErrorContext *akgl_get_json_properties_double(json_t *obj, char *key, doub akerr_ErrorContext *akgl_tilemap_load_tilesets_each(json_t *tileset, akgl_Tilemap *dest, int tsidx, akgl_String *dirname) { - PREPARE_ERROR(e); + PREPARE_ERROR(errctx); akgl_String *tmpstr = NULL; akgl_String *tmppath = NULL; - PASS(e, akgl_get_json_integer_value((json_t *)tileset, "columns", &dest->tilesets[tsidx].columns)); - PASS(e, akgl_get_json_integer_value((json_t *)tileset, "firstgid", &dest->tilesets[tsidx].firstgid)); - PASS(e, akgl_get_json_integer_value((json_t *)tileset, "imageheight", &dest->tilesets[tsidx].imageheight)); - PASS(e, akgl_get_json_integer_value((json_t *)tileset, "imagewidth", &dest->tilesets[tsidx].imagewidth)); - PASS(e, akgl_get_json_integer_value((json_t *)tileset, "margin", &dest->tilesets[tsidx].margin)); - PASS(e, akgl_get_json_integer_value((json_t *)tileset, "spacing", &dest->tilesets[tsidx].spacing)); - PASS(e, akgl_get_json_integer_value((json_t *)tileset, "tilecount", &dest->tilesets[tsidx].tilecount)); - PASS(e, akgl_get_json_integer_value((json_t *)tileset, "tileheight", &dest->tilesets[tsidx].tileheight)); - PASS(e, akgl_get_json_integer_value((json_t *)tileset, "tilewidth", &dest->tilesets[tsidx].tilewidth)); + PASS(errctx, akgl_get_json_integer_value((json_t *)tileset, "columns", &dest->tilesets[tsidx].columns)); + PASS(errctx, akgl_get_json_integer_value((json_t *)tileset, "firstgid", &dest->tilesets[tsidx].firstgid)); + PASS(errctx, akgl_get_json_integer_value((json_t *)tileset, "imageheight", &dest->tilesets[tsidx].imageheight)); + PASS(errctx, akgl_get_json_integer_value((json_t *)tileset, "imagewidth", &dest->tilesets[tsidx].imagewidth)); + PASS(errctx, akgl_get_json_integer_value((json_t *)tileset, "margin", &dest->tilesets[tsidx].margin)); + PASS(errctx, akgl_get_json_integer_value((json_t *)tileset, "spacing", &dest->tilesets[tsidx].spacing)); + PASS(errctx, akgl_get_json_integer_value((json_t *)tileset, "tilecount", &dest->tilesets[tsidx].tilecount)); + PASS(errctx, akgl_get_json_integer_value((json_t *)tileset, "tileheight", &dest->tilesets[tsidx].tileheight)); + PASS(errctx, akgl_get_json_integer_value((json_t *)tileset, "tilewidth", &dest->tilesets[tsidx].tilewidth)); - PASS(e, akgl_get_json_string_value((json_t *)tileset, "name", &tmpstr)); - PASS(e, akgl_heap_next_string(&tmppath)); + PASS(errctx, akgl_get_json_string_value((json_t *)tileset, "name", &tmpstr)); + PASS(errctx, akgl_heap_next_string(&tmppath)); ATTEMPT { strncpy((char *)&dest->tilesets[tsidx].name, (char *)&tmpstr->data, AKGL_TILEMAP_MAX_TILESET_NAME_SIZE ); - CATCH(e, akgl_get_json_string_value((json_t *)tileset, "image", &tmpstr)); - CATCH(e, akgl_path_relative((char *)&dirname->data, (char *)&tmpstr->data, tmppath)); + CATCH(errctx, akgl_get_json_string_value((json_t *)tileset, "image", &tmpstr)); + CATCH(errctx, akgl_path_relative((char *)&dirname->data, (char *)&tmpstr->data, tmppath)); strncpy((char *)&dest->tilesets[tsidx].imagefilename, tmppath->data, AKGL_MAX_STRING_LENGTH); } CLEANUP { IGNORE(akgl_heap_release_string(tmpstr)); IGNORE(akgl_heap_release_string(tmppath)); - } PROCESS(e) { - } FINISH(e, true); + } PROCESS(errctx) { + } FINISH(errctx, true); dest->tilesets[tsidx].texture = IMG_LoadTexture(akgl_renderer->sdl_renderer, (char *)&dest->tilesets[tsidx].imagefilename); - FAIL_ZERO_RETURN(e, dest->tilesets[tsidx].texture, AKERR_NULLPOINTER, "Failed loading tileset image : %s", SDL_GetError()); + FAIL_ZERO_RETURN(errctx, dest->tilesets[tsidx].texture, AKERR_NULLPOINTER, "Failed loading tileset image : %s", SDL_GetError()); - SUCCEED_RETURN(e); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_tilemap_compute_tileset_offsets(akgl_Tilemap *dest, int tilesetidx) @@ -459,70 +459,70 @@ akerr_ErrorContext *akgl_tilemap_load_layers(akgl_Tilemap *dest, json_t *root, a akerr_ErrorContext *akgl_tilemap_load_physics(akgl_Tilemap *dest, json_t *root) { - PREPARE_ERROR(e); + PREPARE_ERROR(errctx); json_t *props = NULL; akgl_String *tmpval = NULL; double defzero = 0.0; ATTEMPT { - CATCH(e, akgl_heap_next_string(&tmpval)); - CATCH(e, akgl_get_json_array_value((json_t *)root, "properties", &props)); + CATCH(errctx, akgl_heap_next_string(&tmpval)); + CATCH(errctx, akgl_get_json_array_value((json_t *)root, "properties", &props)); } CLEANUP { IGNORE(akgl_heap_release_string(tmpval)); - } PROCESS(e) { - } HANDLE(e, AKERR_KEY) { + } PROCESS(errctx) { + } HANDLE(errctx, AKERR_KEY) { // Map has no properties, do nothing SDL_Log("Map has no properties"); - SUCCEED_RETURN(e); - } FINISH(e, true); + SUCCEED_RETURN(errctx); + } FINISH(errctx, true); ATTEMPT { - CATCH(e, akgl_heap_next_string(&tmpval)); - CATCH(e, akgl_get_json_properties_string( + CATCH(errctx, akgl_heap_next_string(&tmpval)); + CATCH(errctx, akgl_get_json_properties_string( root, "physics.model", &tmpval ) ); - PASS(e, akgl_physics_factory(&dest->physics, tmpval)); + PASS(errctx, akgl_physics_factory(&dest->physics, tmpval)); dest->use_own_physics = true; - CATCH(e, akgl_get_json_with_default( + CATCH(errctx, akgl_get_json_with_default( akgl_get_json_properties_double( root, "physics.gravity.x", &dest->physics.gravity_x ), (void *)&defzero, (void *)&dest->physics.gravity_x, sizeof(double))); - CATCH(e, akgl_get_json_with_default( + CATCH(errctx, akgl_get_json_with_default( akgl_get_json_properties_double( root, "physics.gravity.y", &dest->physics.gravity_y ), (void *)&defzero, (void *)&dest->physics.gravity_y, sizeof(double))); - CATCH(e, akgl_get_json_with_default( + CATCH(errctx, akgl_get_json_with_default( akgl_get_json_properties_double( root, "physics.gravity.z", &dest->physics.gravity_z ), (void *)&defzero, (void *)&dest->physics.gravity_z, sizeof(double))); - CATCH(e, akgl_get_json_with_default( + CATCH(errctx, akgl_get_json_with_default( akgl_get_json_properties_double( root, "physics.drag.x", &dest->physics.drag_x ), (void *)&defzero, (void *)&dest->physics.drag_x, sizeof(double))); - CATCH(e, akgl_get_json_with_default( + CATCH(errctx, akgl_get_json_with_default( akgl_get_json_properties_double( root, "physics.drag.y", &dest->physics.drag_y ), (void *)&defzero, (void *)&dest->physics.drag_y, sizeof(double))); - CATCH(e, akgl_get_json_with_default( + CATCH(errctx, akgl_get_json_with_default( akgl_get_json_properties_double( root, "physics.drag.z", &dest->physics.drag_z ), @@ -531,12 +531,12 @@ akerr_ErrorContext *akgl_tilemap_load_physics(akgl_Tilemap *dest, json_t *root) sizeof(double))); } CLEANUP { IGNORE(akgl_heap_release_string(tmpval)); - } PROCESS(e) { - } HANDLE(e, AKERR_KEY) { + } PROCESS(errctx) { + } HANDLE(errctx, AKERR_KEY) { SDL_Log("Map uses game physics"); - } FINISH(e, true); + } FINISH(errctx, true); - SUCCEED_RETURN(e); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_tilemap_load(char *fname, akgl_Tilemap *dest) @@ -787,10 +787,10 @@ akerr_ErrorContext *akgl_tilemap_draw_tileset(akgl_Tilemap *map, int tilesetidx) akerr_ErrorContext *akgl_tilemap_scale_actor(akgl_Tilemap *map, akgl_Actor *actor) { - PREPARE_ERROR(e); + PREPARE_ERROR(errctx); - FAIL_ZERO_RETURN(e, map, AKERR_NULLPOINTER, "NULL map"); - FAIL_ZERO_RETURN(e, actor, AKERR_NULLPOINTER, "NULL actor"); + FAIL_ZERO_RETURN(errctx, map, AKERR_NULLPOINTER, "NULL map"); + FAIL_ZERO_RETURN(errctx, actor, AKERR_NULLPOINTER, "NULL actor"); if ( actor->y <= map->p_vanishing_y ) { actor->scale = map->p_vanishing_scale; @@ -799,7 +799,7 @@ akerr_ErrorContext *akgl_tilemap_scale_actor(akgl_Tilemap *map, akgl_Actor *acto } else { actor->scale = map->p_foreground_scale - (map->p_rate * (map->p_foreground_y - actor->y)); } - SUCCEED_RETURN(e); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_tilemap_release(akgl_Tilemap *dest) @@ -807,8 +807,8 @@ akerr_ErrorContext *akgl_tilemap_release(akgl_Tilemap *dest) // Release all tileset textures // Release all image layer textures // Memset to zero - PREPARE_ERROR(e); - FAIL_ZERO_RETURN(e, dest, AKERR_NULLPOINTER, "NULL map"); + PREPARE_ERROR(errctx); + FAIL_ZERO_RETURN(errctx, dest, AKERR_NULLPOINTER, "NULL map"); int i = 0; for ( i = 0; i < AKGL_TILEMAP_MAX_TILESETS; i++ ) { if ( dest->tilesets[i].texture != NULL ) { @@ -820,5 +820,5 @@ akerr_ErrorContext *akgl_tilemap_release(akgl_Tilemap *dest) SDL_DestroyTexture(dest->tilesets[i].texture); } } - SUCCEED_RETURN(e); + SUCCEED_RETURN(errctx); } diff --git a/src/util.c b/src/util.c index b882236..e80219e 100644 --- a/src/util.c +++ b/src/util.c @@ -53,7 +53,7 @@ */ static akerr_ErrorContext *path_relative_root(char *root, char *path, akgl_String *dst) { - PREPARE_ERROR(e); + PREPARE_ERROR(errctx); akgl_String *pathbuf; akgl_String *strbuf; char *result; @@ -61,22 +61,22 @@ static akerr_ErrorContext *path_relative_root(char *root, char *path, akgl_Strin int pathlen; int count; - FAIL_ZERO_RETURN(e, root, AKERR_NULLPOINTER, "NULL argument"); - FAIL_ZERO_RETURN(e, path, AKERR_NULLPOINTER, "NULL argument"); - FAIL_ZERO_RETURN(e, dst, AKERR_NULLPOINTER, "NULL argument"); + 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"); - PASS(e, akgl_heap_next_string(&strbuf)); - PASS(e, akgl_heap_next_string(&pathbuf)); + PASS(errctx, akgl_heap_next_string(&strbuf)); + PASS(errctx, akgl_heap_next_string(&pathbuf)); ATTEMPT { // Is it relative to the root? rootlen = strlen(root); pathlen = strlen(path); if ( (rootlen + pathlen) >= AKGL_MAX_STRING_LENGTH ) { - FAIL_BREAK(e, AKERR_OUTOFBOUNDS, "Total path length (%d) is greater than maximum akgl_String length (%d)", (rootlen + pathlen), AKGL_MAX_STRING_LENGTH); + FAIL_BREAK(errctx, AKERR_OUTOFBOUNDS, "Total path length (%d) is greater than maximum akgl_String length (%d)", (rootlen + pathlen), AKGL_MAX_STRING_LENGTH); } DISABLE_GCC_WARNING_FORMAT_TRUNCATION - CATCH(e, aksl_snprintf( + CATCH(errctx, aksl_snprintf( &count, (char *)&pathbuf->data, sizeof(pathbuf->data), @@ -85,38 +85,38 @@ static akerr_ErrorContext *path_relative_root(char *root, char *path, akgl_Strin path )); RESTORE_GCC_WARNINGS - CATCH(e, aksl_realpath((char *)&pathbuf->data, (char *)&strbuf->data, sizeof(strbuf->data))); - CATCH(e, akgl_string_copy(strbuf, dst, 0)); + CATCH(errctx, aksl_realpath((char *)&pathbuf->data, (char *)&strbuf->data, sizeof(strbuf->data))); + CATCH(errctx, akgl_string_copy(strbuf, dst, 0)); } CLEANUP { IGNORE(akgl_heap_release_string(strbuf)); IGNORE(akgl_heap_release_string(pathbuf)); - } PROCESS(e) { - } FINISH(e, true); - SUCCEED_RETURN(e); + } PROCESS(errctx) { + } FINISH(errctx, true); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_path_relative(char *root, char *path, akgl_String *dst) { - PREPARE_ERROR(e); + PREPARE_ERROR(errctx); akgl_String *strbuf; char *result; bool relative_to_root = false; - FAIL_ZERO_RETURN(e, root, AKERR_NULLPOINTER, "NULL argument"); - FAIL_ZERO_RETURN(e, path, AKERR_NULLPOINTER, "NULL argument"); - FAIL_ZERO_RETURN(e, dst, AKERR_NULLPOINTER, "NULL argument"); + 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"); - PASS(e, akgl_heap_next_string(&strbuf)); + PASS(errctx, akgl_heap_next_string(&strbuf)); ATTEMPT { // Is path relative to our current working directory? - CATCH(e, aksl_realpath(path, (char *)&strbuf->data, sizeof(strbuf->data))); + CATCH(errctx, aksl_realpath(path, (char *)&strbuf->data, sizeof(strbuf->data))); // Yes it is. strbuf->data contains the absolute path. - CATCH(e, akgl_string_copy(strbuf, dst, 0)); + CATCH(errctx, akgl_string_copy(strbuf, dst, 0)); } CLEANUP { IGNORE(akgl_heap_release_string(strbuf)); - } PROCESS(e) { - } HANDLE(e, ENOENT) { + } PROCESS(errctx) { + } HANDLE(errctx, ENOENT) { // Path is not relative to our current working directory. Resolve it // against root instead -- but after FINISH, not from in here. Returning // from inside a HANDLE block skips the RELEASE_ERROR that FINISH ends @@ -126,12 +126,12 @@ akerr_ErrorContext *akgl_path_relative(char *root, char *path, akgl_String *dst) // context from the array!". Every map load resolves several paths this // way. relative_to_root = true; - } FINISH(e, true); + } FINISH(errctx, true); if ( relative_to_root == true ) { - PASS(e, path_relative_root(root, path, dst)); + PASS(errctx, path_relative_root(root, path, dst)); } - SUCCEED_RETURN(e); + SUCCEED_RETURN(errctx); } akerr_ErrorContext *akgl_rectangle_points(akgl_RectanglePoints *dest, SDL_FRect *rect)