Merge pull request 'Release ignored error contexts' (#21) from 14 into main
Some checks failed
libakerror CI Build / cmake_build (push) Has been cancelled
libakerror CI Build / coverage (push) Has been cancelled
libakerror CI Build / mutation_test (push) Has been cancelled

Reviewed-on: #21
This commit was merged in pull request #21.
This commit is contained in:
2026-08-04 11:28:29 -04:00
committed by Starfort Source Vault
9 changed files with 58 additions and 36 deletions

View File

@@ -107,7 +107,7 @@ The remaining survivors are dominated by:
* **Equivalent mutants** in `akerr_init`: deleting the `memset`/`NULL` setup of
file-scope statics (`AKERR_ARRAY_ERROR`, `__akerr_last_ditch`,
`__akerr_last_ignored`) changes nothing, because C already zero-initializes
`akerr_last_ignored`) changes nothing, because C already zero-initializes
objects with static storage duration. `int oldid = 0;``1` is likewise
dead: it is overwritten before use, and so is clearing `akerr_initializing`
at the end of initialization — nothing reads that flag once the once-routine

View File

@@ -1,11 +1,8 @@
#include "akerror.h"
#include "err_capture.h"
#include <string.h>
/*
* IGNORE deliberately swallows an error: it records the context in
* __akerr_last_ignored, logs it with an "IGNORED ERROR" marker, and lets
* execution continue.
*/
/* IGNORE snapshots and logs an error, releases its pool slot, then continues. */
akerr_ErrorContext *boom(void)
{
@@ -21,11 +18,19 @@ int main(void)
PREPARE_ERROR(e);
(void)e;
IGNORE(boom());
/* More failures than the pool has slots must remain safe: a leaking
* IGNORE used to exhaust the pool and terminate the process here. The
* copied snapshot must also survive the slot being reused on the next
* iteration. */
for ( int i = 0; i < AKERR_MAX_ARRAY_ERROR + 1; i++ ) {
IGNORE(boom());
AKERR_CHECK(akerr_last_ignored.status == AKERR_VALUE);
AKERR_CHECK(strcmp(akerr_last_ignored.message,
"this error is ignored on purpose") == 0);
AKERR_CHECK(akerr_slots_in_use() == 0);
}
reached_after_ignore = 1;
AKERR_CHECK(__akerr_last_ignored != NULL);
AKERR_CHECK(__akerr_last_ignored->status == AKERR_VALUE);
AKERR_CHECK(reached_after_ignore == 1);
AKERR_CHECK_CONTAINS("IGNORED ERROR");
AKERR_CHECK_CONTAINS("this error is ignored on purpose");

View File

@@ -100,17 +100,21 @@ static void *pool_body(void *raw)
one_checkout(arg);
}
/* An ignored error is a fact about the thread that ignored it: each thread
* must see its own, not the last one any thread swallowed. */
/* IGNORE's snapshot is thread-local while logging and remains valid after
* release. Concurrent ignored errors must all return their pool slots. */
IGNORE(ignorable(arg));
AKERR_TCHECK(arg, __akerr_last_ignored != NULL);
if ( __akerr_last_ignored != NULL ) {
AKERR_TCHECK(arg, __akerr_last_ignored->status == AKERR_IO);
AKERR_TCHECK(arg, strcmp(__akerr_last_ignored->message, expected) == 0);
AKERR_TCHECK(arg, akerr_last_ignored.status == AKERR_IO);
AKERR_TCHECK(arg, strcmp(akerr_last_ignored.message, expected) == 0);
/* Reuse a slot after IGNORE and prove that the copied snapshot did not
* become an alias for the newly acquired context. */
akerr_ErrorContext *reused = akerr_next_error();
AKERR_TCHECK(arg, reused != NULL);
if ( reused != NULL ) {
RELEASE_ERROR(reused);
}
/* IGNORE keeps the reference by design; hand it back so the pool is empty
* at the end of the test. */
RELEASE_ERROR(__akerr_last_ignored);
AKERR_TCHECK(arg, akerr_last_ignored.status == AKERR_IO);
AKERR_TCHECK(arg, strcmp(akerr_last_ignored.message, expected) == 0);
return NULL;
}