summaryrefslogtreecommitdiff
path: root/mem.c
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-08-04 23:05:22 +0100
committerubq323 <ubq323@ubq323.website>2023-08-04 23:05:22 +0100
commit93fe66fb8ef5c731b46a30a804f74b4bf3b133d7 (patch)
treef3c1121f992ac6d651af22e03ad55a44a8c84e2c /mem.c
parentf67a3fd05c1b2fe8c749fc2f58287b1b14b011d8 (diff)
give M extra param for tracking alloc size; macros for allocation
Diffstat (limited to 'mem.c')
-rw-r--r--mem.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/mem.c b/mem.c
index 6e0bc1b..d464f7d 100644
--- a/mem.c
+++ b/mem.c
@@ -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;
+}