src/method-{proto,impl}.lisp: Abstract out the receiver type.
[sod] / lib / sod-hosted.c
index 961aa22..5b6e378 100644 (file)
 
 /*----- Header files ------------------------------------------------------*/
 
+#include <stdio.h>
 #include <stdlib.h>
 
 #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