From 93fe66fb8ef5c731b46a30a804f74b4bf3b133d7 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 4 Aug 2023 23:05:22 +0100 Subject: give M extra param for tracking alloc size; macros for allocation --- mem.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'mem.c') diff --git a/mem.c b/mem.c index 6e0bc1b..d464f7d 100644 --- a/mem.c +++ b/mem.c @@ -3,12 +3,12 @@ #include #include -void *M(void *p, size_t sz) { - if (sz == 0) { +void *M(void *p, size_t old, size_t new) { + if (new == 0) { free(p); return NULL; } else { - void *x = realloc(p, sz); + void *x = realloc(p, new); if (x == NULL) { printf("out of memory! aaaaaaa!!!!!\n"); exit(42); @@ -16,3 +16,9 @@ void *M(void *p, size_t sz) { return x; } } + +Obj *alloc_obj(size_t sz, ObjTy oty) { + Obj *o = M(NULL, 0, sz); + o->oty = oty; + return o; +} -- cgit v1.2.3