diff options
| author | Louis Burda <quent.burda@gmail.com> | 2023-05-13 16:16:45 +0200 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2023-05-13 16:16:45 +0200 |
| commit | 110b99563e127abe1439fffb0084400b47eea5b3 (patch) | |
| tree | ded22ce24e5d0545b287817661267de34e9810fd | |
| download | libstrvec-c-110b99563e127abe1439fffb0084400b47eea5b3.tar.gz libstrvec-c-110b99563e127abe1439fffb0084400b47eea5b3.zip | |
Prelim push
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | .gitmodules | 3 | ||||
| -rw-r--r-- | Makefile | 59 | ||||
| -rw-r--r-- | build.jst | 36 | ||||
| -rw-r--r-- | include/strvec.h | 15 | ||||
| m--------- | lib/liballoc | 0 | ||||
| -rw-r--r-- | libstrvec.api | 22 | ||||
| -rw-r--r-- | libstrvec.lds | 23 | ||||
| -rw-r--r-- | src/strvec.c | 36 |
9 files changed, 197 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c4b7ce0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build +.cache +compile_commands.json diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b2dc357 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib/liballoc"] + path = lib/liballoc + url = git@sinitax.com:sinitax/liballoc diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0c32d75 --- /dev/null +++ b/Makefile @@ -0,0 +1,59 @@ +PREFIX ?= /usr/local +LIBDIR ?= /lib +INCLDIR ?= /include + +CFLAGS = -I include -I lib/liballoc/include -I lib/libdvec/include +CFLAGS += -Wunused-function -Wunused-variable -Wno-prototype +CFLAGS += -Wconversion -Wsign-compare -Werror + +ifeq "$(DEBUG)" "1" +CFLAGS += -Og -g +else +CFLAGS += -O2 +endif + +ifeq "$(ASSERT_ARGS)" "1" +CFLAGS += -Dlibstrvec_ASSERT_ARGS=1 +endif + +ifeq "$(ASSERT_ALLOC)" "1" +CFLAGS += -Dlibstrvec_ASSERT_ALLOC=1 +endif + +all: build/libstrvec.so build/libstrvec.a build/test + +clean: + rm -rf build + +build: + mkdir build + +lib/liballoc/build/liballoc.a: + make -C lib/liballoc build/liballoc.a + +lib/libdvec/build/libdvec.a: + make -C lib/libdvec build/libdvec.a + +build/libstrvec.a: src/strvec.c include/strvec.h libstrvec.api | build + $(CC) -o build/tmp.o src/strvec.c $(CFLAGS) -r + objcopy --keep-global-symbols=libstrvec.api build/tmp.o build/fixed.o + ar rcs $@ build/fixed.o + +build/libstrvec.so: src/strvec.c include/strvec.h libstrvec.lds | build + $(CC) -o $@ src/strvec.c -fPIC $(CFLAGS) \ + -shared -Wl,-version-script libstrvec.lds + +build/test: src/test.c build/libstrvec.a lib/liballoc/build/liballoc.a + $(CC) -o $@ $^ $(CFLAGS) + +install: + install -m644 include/strvec.h -t "$(DESTDIR)$(PREFIX)$(INCLDIR)" + install -m755 build/libstrvec.so -t "$(DESTDIR)$(PREFIX)$(LIBDIR)" + install -m755 build/libstrvec.a -t "$(DESTDIR)$(PREFIX)$(LIBDIR)" + +uninstall: + rm -f "$(DESTDIR)$(PREFIX)$(INCLDIR)/strvec.h" + rm -f "$(DESTDIR)$(PREFIX)$(LIBDIR)/libstrvec.so" + rm -f "$(DESTDIR)$(PREFIX)$(LIBDIR)/libstrvec.a" + +.PHONY: all clean install uninstall diff --git a/build.jst b/build.jst new file mode 100644 index 0000000..d7ab92c --- /dev/null +++ b/build.jst @@ -0,0 +1,36 @@ +liballoc = lib/liballoc//build/liballoc.a + +cflags = -Wunused-function -Wunused-variable -Wconversion -Wformat + -I include -I lib/liballoc/include + +rule liba + gcc -o $out.tmp.o $in $cflags -r + objcopy --keep-global-symbols=libdvec.api $out.tmp.o $out.fixed.o + ar rcs $out $out.fixed.o + rm $out.tmp.o $out.fixed.o + +rule libso + gcc -o $out $in $cflags -shared -Wl,-version-script libdvec.lds + +rule cc + gcc -o $out $in $cflags + +rule mkdir + mkdir $out + +target build + mkdir + +target build/libdvec.a + # TODO add include dep + liba src/dvec.c $liballoc + +target build/libdvec.so + # TODO add include dep + libso src/dvec.c + +target build/test + cc src/test.c build/libdvec.a $liballoc + +target all + file build build/libdvec.a build/libdvec.so build/test diff --git a/include/strvec.h b/include/strvec.h new file mode 100644 index 0000000..21624e9 --- /dev/null +++ b/include/strvec.h @@ -0,0 +1,15 @@ +#pragma once + +#include "allocator.h" + +#include <stdlib.h> + +struct strvec; + +void strvec_init(struct strvec *strvec, size_t cap, struct allocator *allocator); +void strvec_deinit(struct strvec *strvec); + +struct strvec *strvec_alloc(size_t reserved, struct allocator *allocator); +void strvec_free(struct strvec *strvec); + + diff --git a/lib/liballoc b/lib/liballoc new file mode 160000 +Subproject 7bb4bd65d7a11bbf4ad4e085aa2a32d5028585d diff --git a/libstrvec.api b/libstrvec.api new file mode 100644 index 0000000..803fd35 --- /dev/null +++ b/libstrvec.api @@ -0,0 +1,22 @@ +strvec_init +strvec_deinit + +strvec_alloc +strvec_free + +strvec_copy +strvec_swap + +strvec_clear +strvec_reserve +strvec_shrink + +strvec_push +strvec_pop +strvec_replace + +strvec_append +strvec_delete + +strvec_iter_fwd +strvec_iter_bwd diff --git a/libstrvec.lds b/libstrvec.lds new file mode 100644 index 0000000..bcc3132 --- /dev/null +++ b/libstrvec.lds @@ -0,0 +1,23 @@ +LIBDVEC_1.1.2 { + global: + dvec_init; + dvec_deinit; + + dvec_alloc; + dvec_free; + + dvec_copy; + dvec_swap; + + dvec_clear; + dvec_reserve; + dvec_shrink; + + dvec_add; + dvec_rm; + dvec_replace; + + dvec_iter_fwd; + dvec_iter_bwd; + local: *; +}; diff --git a/src/strvec.c b/src/strvec.c new file mode 100644 index 0000000..343d8ba --- /dev/null +++ b/src/strvec.c @@ -0,0 +1,36 @@ +#include "strvec.h" +#include "dvec.h" +#include "allocator.h" + +struct strvec { + struct dvec vec; + const struct allocator *alloc; +}; + +void +strvec_init(struct strvec *strvec, size_t cap, struct allocator *allocator) +{ + strvec->alloc = allocator; + dvec_init(&strvec->vec, sizeof(char *), cap, allocator); +} + +void +strvec_deinit(struct strvec *strvec) +{ + dvec_deinit(&strvec->vec); +} + +struct strvec * +strvec_alloc(size_t reserved, struct allocator *allocator) +{ + +} + +int +strvec_free(struct strvec *strvec) +{ + dvec_deinit(&strvec->vec); + strvec->alloc->free(strvec); +} + + |
