X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/a42893dda5f4dd2b89fbfe4e497da261159225ca..d5fdd49e70b734b791eb907706f92da5775e2a8b:/lib/sod-hosted.c diff --git a/lib/sod-hosted.c b/lib/sod-hosted.c index 961aa22..5b6e378 100644 --- a/lib/sod-hosted.c +++ b/lib/sod-hosted.c @@ -27,12 +27,43 @@ /*----- Header files ------------------------------------------------------*/ +#include #include #include "sod.h" +/*----- Preliminary macros ------------------------------------------------*/ + +#if __STDC_VERSION__ >= 199901 +# define PRIuSZ "zu" +# define PRINT_SZ(x) (x) +#else +# define PRIuSZ "lu" +# define PRINT_SZ(x) ((unsigned long)(x)) +#endif + /*----- Main code ---------------------------------------------------------*/ +/* --- @sod__chksz_fail@ --- * + * + * Arguments: @const SodClass *cls@ = class we were trying to instantiate + * @size_t sz@ = size allocated + * + * Returns: Doesn't. + * + * Use: Reports instantiation failure caused by a mismatch between + * the size allocated (@sz@) and the size required for an + * instance of class @cls@. + */ + +SOD__NORETURN void sod__chksz_fail(const SodClass *cls, size_t sz) +{ + fprintf(stderr, "INTERNAL ERROR: size mismatch for class `%s': " + "%"PRIuSZ" allocated but %"PRIuSZ" required", + cls->cls.name, PRINT_SZ(sz), PRINT_SZ(cls->cls.initsz)); + abort(); +} + /* --- @sod_make@, @sod_makev@ --- * * * Arguments: @const SodClass *cls@ = class object for new instance