#include #include #include #include "util.h" void * must_malloc(size_t size) { void *ret = malloc(size); if (ret == NULL) { fprintf(stderr, "Out of memory\n"); exit(EXIT_ABNORMAL); } } void * must_calloc(size_t nmemb, size_t size) { void *ret = calloc(nmemb, size); if (ret == NULL) { fprintf(stderr, "Out of memory\n"); exit(EXIT_ABNORMAL); } return ret; } void * must_realloc(void *ptr, size_t size) { void *ret = realloc(ptr, size); if (ret == NULL) { fprintf(stderr, "Out of memory\n"); exit(EXIT_ABNORMAL); } return ret; } void error(struct location loc, const char *fmt, ...) { fprintf(stderr, "%s:%d:%d: ", loc.file, loc.line, loc.column); va_list ap; va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); fprintf(stderr, "\n"); exit(EXIT_PARSE); }