diff options
| author | Tyge Løvset <[email protected]> | 2023-05-18 23:00:42 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-05-18 23:00:42 +0200 |
| commit | c94e7b91d552a05d49e1cc3859f80e9f20406b48 (patch) | |
| tree | 8b95af9c4537031ab8435e7be43473c50eaa72dc | |
| parent | c54da07eb171455ad182d61a1fb5c4e4520aebbb (diff) | |
| download | STC-modified-c94e7b91d552a05d49e1cc3859f80e9f20406b48.tar.gz STC-modified-c94e7b91d552a05d49e1cc3859f80e9f20406b48.zip | |
Renamed template param i_con => i_base in stc/extend.h. Also the macro c_getcon(self) => c_extend(self).
| -rw-r--r-- | README.md | 8 | ||||
| -rw-r--r-- | include/stc/extend.h | 10 | ||||
| -rw-r--r-- | misc/examples/functor.c | 4 |
3 files changed, 11 insertions, 11 deletions
@@ -564,8 +564,8 @@ It adds a MemoryContext to each container by defining the `i_extend` template pa the by inclusion of `<stc/extend.h>`. ```c // stcpgs.h -#define pgs_malloc(sz) MemoryContextAlloc(c_getcon(self)->memctx, sz) -#define pgs_calloc(n, sz) MemoryContextAllocZero(c_getcon(self)->memctx, (n)*(sz)) +#define pgs_malloc(sz) MemoryContextAlloc(c_extend(self)->memctx, sz) +#define pgs_calloc(n, sz) MemoryContextAllocZero(c_extend(self)->memctx, (n)*(sz)) #define pgs_realloc(p, sz) (p ? repalloc(p, sz) : pgs_malloc(sz)) #define pgs_free(p) (p ? pfree(p) : (void)0) // pfree/repalloc does not accept NULL. @@ -574,12 +574,12 @@ the by inclusion of `<stc/extend.h>`. #define i_extend MemoryContext memctx; #include <stc/extend.h> ``` -To use it, define both `i_type` and `i_con` (the container type) before including the custom header: +To use it, define both `i_type` and `i_base` (the container type) before including the custom header: ```c #define i_type IMap +#define i_base csmap #define i_key int #define i_val int -#define i_con csmap #include "stcpgs.h" // Note the wrapper struct type is IMap_ext. IMap is accessed by .get diff --git a/include/stc/extend.h b/include/stc/extend.h index 66b3ebd1..f697d2b3 100644 --- a/include/stc/extend.h +++ b/include/stc/extend.h @@ -44,9 +44,9 @@ #endif #ifdef _i_key - c_PASTE(forward_, i_con)(i_type, _i_key, _i_val); + c_PASTE(forward_, i_base)(i_type, _i_key, _i_val); #else - c_PASTE(forward_, i_con)(i_type, _i_val); + c_PASTE(forward_, i_base)(i_type, _i_val); #endif typedef struct { @@ -54,13 +54,13 @@ typedef struct { i_type get; } c_PASTE(i_type, _ext); -#define c_getcon(cptr) c_container_of(cptr, _cx_memb(_ext), get) +#define c_extend(self) c_container_of(self, _cx_memb(_ext), get) #define i_is_forward -#define _i_inc <stc/i_con.h> +#define _i_inc <stc/i_base.h> #include _i_inc #undef _i_inc #undef _i_key #undef _i_val -#undef i_con +#undef i_base #undef i_extend diff --git a/misc/examples/functor.c b/misc/examples/functor.c index c0a4f8e8..d6adfcb1 100644 --- a/misc/examples/functor.c +++ b/misc/examples/functor.c @@ -8,10 +8,10 @@ #include <stdio.h> #define i_type IPQue +#define i_base cpque #define i_val int #define i_extend bool (*less)(const int*, const int*); -#define i_less(x, y) c_getcon(self)->less(x, y) -#define i_con cpque +#define i_less(x, y) c_extend(self)->less(x, y) #include <stc/extend.h> void print_queue(const char* name, IPQue_ext q) { |
