summaryrefslogtreecommitdiff
path: root/mem.c
blob: d464f7d35cd431a1d33ae5818f2acda2d71d7fa0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "mem.h"

#include <stdio.h>
#include <stdlib.h>

void *M(void *p, size_t old, size_t new) {
	if (new == 0) {
		free(p);
		return NULL;
	} else {
		void *x = realloc(p, new);
		if (x == NULL) {
			printf("out of memory! aaaaaaa!!!!!\n");
			exit(42);
		}
		return x;
	}
}

Obj *alloc_obj(size_t sz, ObjTy oty) {
	Obj *o = M(NULL, 0, sz);
	o->oty = oty;
	return o;
}