aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-06-06 12:30:48 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-06-06 12:30:48 -0700
commite02e1403b432f8cd6d07ebbdd235627f20f01cfb (patch)
treee479b02d2ede4d34270889a8c2d1f627f3701e1e
parenteeb5831bb4d62c35eca6db333137a9b8bf682e6e (diff)
small changes to exposure of allocation functions
-rw-r--r--Makefile7
-rw-r--r--include/libn.h14
-rw-r--r--sys/cmd/cc/cc.c18
-rw-r--r--sys/cmd/cc/lex.c18
-rw-r--r--sys/cmd/rules.mk4
-rw-r--r--sys/libn/memory.c10
6 files changed, 55 insertions, 16 deletions
diff --git a/Makefile b/Makefile
index dd18cc6..c518063 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,8 @@
# Compiler, Linker, and Assembler
-CC := gcc
-AR := ar
-AS := nasm
+CC := gcc
+AR := ar
+AS := nasm
+PKG := pkg-config
# All needed build directories
INC_DIR := include
diff --git a/include/libn.h b/include/libn.h
index 38f0a3a..d47e7c5 100644
--- a/include/libn.h
+++ b/include/libn.h
@@ -59,6 +59,7 @@ typedef struct Iface {
// -----------------------------------------------------------------------------
// memory allocation
+// TODO(nnoll): Allow for nil iterfaces?
/* allocator interface */
typedef struct mem·Allocator {
void *(*alloc)(void *iface, uint n, ulong size);
@@ -72,17 +73,8 @@ typedef struct mem·Reallocator {
} mem·Reallocator;
/* system implementation */
-extern void ·free(void* _, void *ptr);
-extern void *·alloc(void* _, uint n, ulong size);
-extern void *·calloc(void* _, uint n, ulong size);
-extern void *·realloc(void* _, void *ptr, uint n, ulong size);
-
-// TODO(nnoll): Allow for nil iterfaces?
-static
-mem·Allocator mem·sys = {
- .alloc = ·alloc,
- .free = ·free
-};
+extern mem·Allocator mem·sys;
+extern mem·Reallocator mem·rsys;
/* simple memory arena */
typedef struct mem·Arena mem·Arena;
diff --git a/sys/cmd/cc/cc.c b/sys/cmd/cc/cc.c
index 3246292..3602643 100644
--- a/sys/cmd/cc/cc.c
+++ b/sys/cmd/cc/cc.c
@@ -54,6 +54,24 @@ getstr(string key, int *ok)
return idx;
}
+static
+void
+·free(void* _, void* ptr) {
+ return free(ptr);
+}
+
+static
+void *
+·alloc(void* _, uint n, ulong size) {
+ return malloc(n*size);
+}
+
+static
+void *
+·calloc(void* _, uint n, ulong size) {
+ return calloc(n, size);
+}
+
static
int
morestrtab(StrTab *tab, int n)
diff --git a/sys/cmd/cc/lex.c b/sys/cmd/cc/lex.c
index 1396358..0963fb9 100644
--- a/sys/cmd/cc/lex.c
+++ b/sys/cmd/cc/lex.c
@@ -791,6 +791,24 @@ Nospace:
#define PTR_HASH(p) (uintptr)(p)
#define PTR_EQUAL(p1, p2) ((uintptr)(p1) == (uintptr)(p2))
+static
+void
+·free(void* _, void* ptr) {
+ return free(ptr);
+}
+
+static
+void *
+·alloc(void* _, uint n, ulong size) {
+ return malloc(n*size);
+}
+
+static
+void *
+·calloc(void* _, uint n, ulong size) {
+ return calloc(n, size);
+}
+
static
int
moresymtab(SymTab *tab, int n)
diff --git a/sys/cmd/rules.mk b/sys/cmd/rules.mk
index 1a6bd88..d23396c 100644
--- a/sys/cmd/rules.mk
+++ b/sys/cmd/rules.mk
@@ -14,8 +14,8 @@ include $(DIR)/rules.mk
# DIR := $(d)/rc
# include $(DIR)/rules.mk
-DIR := $(d)/dwm
-include $(DIR)/rules.mk
+# DIR := $(d)/dwm
+# include $(DIR)/rules.mk
DIR := $(d)/term
include $(DIR)/rules.mk
diff --git a/sys/libn/memory.c b/sys/libn/memory.c
index 46f2478..31f910e 100644
--- a/sys/libn/memory.c
+++ b/sys/libn/memory.c
@@ -1,26 +1,36 @@
#include <u.h>
#include <libn.h>
+static
void
·free(void* _, void* ptr) {
return free(ptr);
}
+static
void *
·alloc(void* _, uint n, ulong size) {
return malloc(n*size);
}
+static
void *
·calloc(void* _, uint n, ulong size) {
return calloc(n, size);
}
+static
void *
·realloc(void* _, void *ptr, uint n, ulong size) {
return realloc(ptr, n*size);
}
+mem·Allocator mem·sys = {
+ .alloc = ·alloc,
+ .free = ·free
+};
+
+
// -------------------------------------------------------------------------
// Dynamic buffer.