#include "akerror.h" #include "err_capture.h" /* * AKERR_MAX_ERR_VALUE sizes the __AKERR_ERROR_NAMES table and is the upper bound * akerr_name_for_status() will accept. If it is smaller than the highest AKERR_* * code, those codes silently lose their names (this was a real bug: the max was * +15 while AKERR_BADEXC is +17). * * Guard the invariant: the AKERR_* range reserved above AKERR_LAST_ERRNO_VALUE * must be larger than the number of AKERR_* codes defined, and every code must * be individually indexable. */ /* Every AKERR_* library error code. Keep in sync with akerror.h. */ static const int akerr_codes[] = { AKERR_NULLPOINTER, AKERR_OUTOFBOUNDS, AKERR_API, AKERR_ATTRIBUTE, AKERR_TYPE, AKERR_KEY, AKERR_INDEX, AKERR_FORMAT, AKERR_IO, AKERR_VALUE, AKERR_RELATIONSHIP, AKERR_EOF, AKERR_CIRCULAR_REFERENCE, AKERR_ITERATOR_BREAK, AKERR_NOT_IMPLEMENTED, AKERR_BADEXC, }; int main(void) { int n = (int)(sizeof(akerr_codes) / sizeof(akerr_codes[0])); /* AKERR_MAX_ERR_VALUE must reserve more codes than are actually defined. */ AKERR_CHECK((AKERR_MAX_ERR_VALUE - AKERR_LAST_ERRNO_VALUE) > n); /* Stronger: every defined code must fall within the addressable range so * its name can be stored and retrieved. */ for ( int i = 0; i < n; i++ ) { AKERR_CHECK(akerr_codes[i] > AKERR_LAST_ERRNO_VALUE); AKERR_CHECK(akerr_codes[i] <= AKERR_MAX_ERR_VALUE); } fprintf(stderr, "err_maxval ok (%d codes, range %d)\n", n, AKERR_MAX_ERR_VALUE - AKERR_LAST_ERRNO_VALUE); return 0; }