diff options
author | ubq323 <ubq323@ubq323.website> | 2023-08-04 23:05:22 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2023-08-04 23:05:22 +0100 |
commit | 93fe66fb8ef5c731b46a30a804f74b4bf3b133d7 (patch) | |
tree | f3c1121f992ac6d651af22e03ad55a44a8c84e2c /mem.c | |
parent | f67a3fd05c1b2fe8c749fc2f58287b1b14b011d8 (diff) |
give M extra param for tracking alloc size; macros for allocation
Diffstat (limited to 'mem.c')
-rw-r--r-- | mem.c | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -3,12 +3,12 @@ #include <stdio.h> #include <stdlib.h> -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; +} |