diff options
| author | Louis Burda <quent.burda@gmail.com> | 2023-05-20 12:45:23 +0200 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2023-05-20 12:45:23 +0200 |
| commit | 8240eff87bb928e12a093cc37aae78576cdf4f6c (patch) | |
| tree | fada3c8d25be0923327697d9480adcdeda3d53ce | |
| parent | 44b67786e23d4254b918f4ebaae5459f463979e6 (diff) | |
| download | libstrvec-c-8240eff87bb928e12a093cc37aae78576cdf4f6c.tar.gz libstrvec-c-8240eff87bb928e12a093cc37aae78576cdf4f6c.zip | |
Make struct non-opaque and fix build.jst
| -rw-r--r-- | build.jst | 10 | ||||
| -rw-r--r-- | include/strvec.h | 38 | ||||
| -rw-r--r-- | src/strvec.c | 30 |
3 files changed, 39 insertions, 39 deletions
@@ -24,14 +24,20 @@ target build target lib/liballoc/build/liballoc.a just lib/liballoc +target lib/libdvec/build/libdvec.a + just lib/libdvec + target build/libstrvec.a - liba src/strvec.c lib/liballoc/build/liballoc.a | build + liba src/strvec.c + lib/liballoc/build/liballoc.a | build target build/libstrvec.so libso src/strvec.c | build target build/test - cc src/test.c build/libstrvec.a $liballoc | build + cc src/test.c build/libstrvec.a + lib/liballoc/build/liballoc.a + lib/libdvec/build/libdvec.a | build command clean rm -rf build diff --git a/include/strvec.h b/include/strvec.h index 648487c..a7f622c 100644 --- a/include/strvec.h +++ b/include/strvec.h @@ -1,5 +1,6 @@ #pragma once +#include "dvec.h" #include "allocator.h" #include <stdbool.h> @@ -21,7 +22,9 @@ #define LIBSTRVEC_ABORT_ON_ALLOC(cond) #endif -struct strvec; +struct strvec { + struct dvec vec; +}; int strvec_init(struct strvec *strvec, size_t cap, struct allocator *allocator); int strvec_deinit(struct strvec *strvec); @@ -38,16 +41,15 @@ void strvec_clear(struct strvec *strvec); int strvec_reserve(struct strvec *strvec, size_t cap); int strvec_shrink(struct strvec *strvec); -const char **strvec_stra(struct strvec *strvec); +static inline const char **strvec_stra(struct strvec *strvec); -const char **strvec_at(struct strvec *strvec, size_t index); +static inline const char **strvec_at(struct strvec *strvec, size_t index); static inline const char *strvec_get(struct strvec *strvec, size_t index); static inline const char *strvec_front(struct strvec *strvec); static inline const char *strvec_back(struct strvec *strvec); -size_t strvec_len(struct strvec *strvec); +static inline size_t strvec_len(struct strvec *strvec); static inline bool strvec_empty(struct strvec *strvec); - int strvec_pushn(struct strvec *strvec, const char **str, size_t n); static inline int strvec_push(struct strvec *strvec, const char *str); const char **strvec_popn(struct strvec *strvec, size_t n); @@ -58,6 +60,30 @@ void strvec_remove(struct strvec *strvec, size_t index, size_t n); const char **strvec_iter_fwd(const struct strvec *strvec, const char **p); const char **strvec_iter_bwd(const struct strvec *strvec, const char **p); +static inline const char ** +strvec_stra(struct strvec *strvec) +{ + LIBSTRVEC_ABORT_ON_ARGS(!strvec && !strvec->vec.data); + + return strvec->vec.data; +} + +static inline const char ** +strvec_at(struct strvec *strvec, size_t index) +{ + LIBSTRVEC_ABORT_ON_ARGS(!strvec); + + return dvec_at(&strvec->vec, index); +} + +static inline size_t +strvec_len(struct strvec *strvec) +{ + LIBSTRVEC_ABORT_ON_ARGS(!strvec); + + return strvec->vec.len; +} + static inline bool strvec_empty(struct strvec *strvec) { @@ -95,5 +121,3 @@ strvec_pop(struct strvec *strvec) { return *strvec_popn(strvec, 1); } - -extern const size_t strvec_dsize; diff --git a/src/strvec.c b/src/strvec.c index f6432b9..bf8b95c 100644 --- a/src/strvec.c +++ b/src/strvec.c @@ -4,12 +4,6 @@ #include <string.h> -struct strvec { - struct dvec vec; -}; - -const size_t strvec_dsize = sizeof(struct strvec); - int strvec_init(struct strvec *strvec, size_t cap, struct allocator *allocator) { @@ -158,30 +152,6 @@ strvec_shrink(struct strvec *strvec) return rc; } -const char ** -strvec_stra(struct strvec *strvec) -{ - LIBSTRVEC_ABORT_ON_ARGS(!strvec && !strvec->vec.data); - - return strvec->vec.data; -} - -const char ** -strvec_at(struct strvec *strvec, size_t index) -{ - LIBSTRVEC_ABORT_ON_ARGS(!strvec); - - return dvec_at(&strvec->vec, index); -} - -size_t -strvec_len(struct strvec *strvec) -{ - LIBSTRVEC_ABORT_ON_ARGS(!strvec); - - return strvec->vec.len; -} - int strvec_pushn(struct strvec *strvec, const char **str, size_t count) { |
