summaryrefslogtreecommitdiff
path: root/alloc.c
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2023-12-23 00:12:34 +0000
committerrodri <rgl@antares-labs.eu>2023-12-23 00:12:34 +0000
commitb34446e7025a15bd5b74fd5f88bb952028cc8a4a (patch)
treebb6e51e0c63bcf4f167936fd8e7991da2bbb1ac1 /alloc.c
parentf69cd8f04bbe059ce21f0c7be93fd081495c6371 (diff)
downloadtinyrend-b34446e7025a15bd5b74fd5f88bb952028cc8a4a.tar.gz
tinyrend-b34446e7025a15bd5b74fd5f88bb952028cc8a4a.tar.bz2
tinyrend-b34446e7025a15bd5b74fd5f88bb952028cc8a4a.zip
organize the code better.
Diffstat (limited to 'alloc.c')
-rw-r--r--alloc.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/alloc.c b/alloc.c
new file mode 100644
index 0000000..7042bd5
--- /dev/null
+++ b/alloc.c
@@ -0,0 +1,64 @@
+#include <u.h>
+#include <libc.h>
+#include <thread.h>
+#include <draw.h>
+#include <memdraw.h>
+#include <mouse.h>
+#include <keyboard.h>
+#include <geometry.h>
+#include "libobj/obj.h"
+#include "dat.h"
+#include "fns.h"
+
+void *
+emalloc(ulong n)
+{
+ void *p;
+
+ p = malloc(n);
+ if(p == nil)
+ sysfatal("malloc: %r");
+ setmalloctag(p, getcallerpc(&n));
+ return p;
+}
+
+void *
+erealloc(void *p, ulong n)
+{
+ void *np;
+
+ np = realloc(p, n);
+ if(np == nil){
+ if(n == 0)
+ return nil;
+ sysfatal("realloc: %r");
+ }
+ if(p == nil)
+ setmalloctag(np, getcallerpc(&p));
+ else
+ setrealloctag(np, getcallerpc(&p));
+ return np;
+}
+
+Image *
+eallocimage(Display *d, Rectangle r, ulong chan, int repl, ulong col)
+{
+ Image *i;
+
+ i = allocimage(d, r, chan, repl, col);
+ if(i == nil)
+ sysfatal("allocimage: %r");
+ return i;
+}
+
+Memimage *
+eallocmemimage(Rectangle r, ulong chan)
+{
+ Memimage *i;
+
+ i = allocmemimage(r, chan);
+ if(i == nil)
+ sysfatal("allocmemimage: %r");
+ memfillcolor(i, DTransparent);
+ return i;
+}