commit b0d838aeffa170ffb9e037f6208ad036aa14e383
parent 19ad7d952629c5ecc1e713c897825a1eaf581dbf
Author: Louis Burda <quent.burda@gmail.com>
Date: Sun, 21 May 2023 21:14:41 +0200
Update liballoc
Diffstat:
3 files changed, 49 insertions(+), 4 deletions(-)
diff --git a/build.jst b/build.jst
@@ -0,0 +1,45 @@
+cc = clang
+
+cflags = -Wunused-function -Wunused-variable -Wconversion -Wformat
+ -I include -I lib/liballoc/include
+
+rule liba
+ $cc -o $out.tmp.o $in $cflags -r
+ objcopy --keep-global-symbols=libstr.api $out.tmp.o $out.fixed.o
+ ar rcs $out $out.fixed.o
+ rm $out.tmp.o $out.fixed.o
+
+rule libso
+ $cc -o $out $in $cflags -shared -Wl,-version-script libstr.lds
+
+rule cc
+ $cc -o $out $in $cflags
+
+rule mkdir
+ mkdir $out
+
+target build
+ mkdir
+
+target lib/liballoc/build/liballoc.a
+ just lib/liballoc
+
+target build/libstr.a
+ liba src/str.c | include/str.h build
+
+target build/libstr.so
+ libso src/str.c | include/str.h build
+
+target build/test
+ cc src/test.c build/libstr.a lib/liballoc/build/liballoc.a | build
+
+command clean
+ rm -rf build
+
+command cleanall
+ just clean
+ just -C lib/liballoc cleanall
+
+command all
+ just build/libstr.a build/libstr.so build/test
+
diff --git a/src/str.c b/src/str.c
@@ -26,7 +26,7 @@ str_fmt(const struct allocator *allocator, int *rc, const char *fmtstr, ...)
return NULL;
}
- str = allocator->alloc((size_t) (n + 1), rc);
+ str = allocator->alloc(allocator, (size_t) (n + 1), rc);
LIBSTR_ABORT_ON_ALLOC(!str);
if (!str && rc) *rc = -*rc;
if (!str) return NULL;
@@ -47,7 +47,7 @@ str_dup(const struct allocator *allocator, int *rc, const char *str)
LIBSTR_ABORT_ON_ARGS(!allocator || !str);
len = strlen(str);
- nstr = allocator->alloc(len + 1, rc);
+ nstr = allocator->alloc(allocator, len + 1, rc);
LIBSTR_ABORT_ON_ALLOC(!nstr);
if (!nstr && rc) *rc = -*rc;
if (!nstr) return NULL;
@@ -67,7 +67,7 @@ str_app(const struct allocator *allocator, int *rc, char *str, const char *app)
alen = strlen(app);
slen = str ? strlen(str) : 0;
- str = allocator->realloc(str, slen + alen + 1, rc);
+ str = allocator->realloc(allocator, str, slen + alen + 1, rc);
LIBSTR_ABORT_ON_ALLOC(!str);
if (!str && rc) *rc = -*rc;
if (!str) return NULL;
diff --git a/src/test.c b/src/test.c
@@ -16,5 +16,5 @@ main(int argc, const char **argv)
printf("%s\n", str);
- ga->free(str);
+ ga->free(ga, str);
}