diff options
| author | Tyge Løvset <[email protected]> | 2020-09-08 18:24:35 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2020-09-08 18:24:35 +0200 |
| commit | 98d80fcef94ccd738173196dc3de0c889d847f28 (patch) | |
| tree | a312bbf5be60cb2a2073b07251c6cf83ef56e2d4 | |
| parent | c3a2ed06079718176a0f763c1700e182875486c0 (diff) | |
| download | STC-modified-98d80fcef94ccd738173196dc3de0c889d847f28.tar.gz STC-modified-98d80fcef94ccd738173196dc3de0c889d847f28.zip | |
Fixed clist iterators again. Removed zero args support for overloadable macros - had issues.
| -rw-r--r-- | stc/cdefs.h | 16 | ||||
| -rw-r--r-- | stc/clist.h | 20 |
2 files changed, 17 insertions, 19 deletions
diff --git a/stc/cdefs.h b/stc/cdefs.h index c3e24c64..0c8b5672 100644 --- a/stc/cdefs.h +++ b/stc/cdefs.h @@ -44,15 +44,13 @@ #endif
/* Macro overloading feature support: https://rextester.com/ONP80107 */
-#define c_CAT(A, B) A ## B
-#define c_EXPAND(...) __VA_ARGS__
-#define _c_RSEQ_N 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
-#define _c_ARG_N(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, N,...) N
-#define _c_ZERO_ARGS_PREFIX__ZERO_ARGS_SUFFIX ,,,,,,,,,,,,,0 /* 13 commas */
-#define _c_ZERO_ARGS(...) c_EXPAND(_c_ZERO_ARGS_PREFIX_ ## __VA_ARGS__ ## _ZERO_ARGS_SUFFIX)
-#define _c_VA_ARG_SIZE(...) c_EXPAND(_c_APPLY_ARG_N((_c_ZERO_ARGS(__VA_ARGS__), _c_RSEQ_N)))
-#define _c_APPLY_ARG_N(ARGS) c_EXPAND(_c_ARG_N ARGS)
-#define _c_OVERLOAD_SELECT(NAME, NUM) c_CAT(NAME ## _, NUM)
+#define _c_CAT( A, B ) A ## B
+#define _c_EXPAND(...) __VA_ARGS__
+#define _c_ARG_N(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, N,...) N
+#define _c_RSEQ_N 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
+#define _c_APPLY_ARG_N(ARGS) _c_EXPAND(_c_ARG_N ARGS)
+#define _c_VA_ARG_SIZE(...) _c_EXPAND(_c_APPLY_ARG_N((__VA_ARGS__, _c_RSEQ_N)))
+#define _c_OVERLOAD_SELECT(NAME, NUM) _c_CAT( NAME ## _, NUM)
#define c_MACRO_OVERLOAD(NAME, ...) _c_OVERLOAD_SELECT(NAME, _c_VA_ARG_SIZE(__VA_ARGS__))(__VA_ARGS__)
/*#define FOO(...) c_MACRO_OVERLOAD(FOO, __VA_ARGS__) #define FOO_0() "0" #define FOO_1(x) "1" #define FOO_2(x,y) "2"*/
diff --git a/stc/clist.h b/stc/clist.h index e8a0dca0..9c5777f5 100644 --- a/stc/clist.h +++ b/stc/clist.h @@ -80,7 +80,7 @@ \
typedef struct { \
clist_##X##_node_t **_last, *item; \
- int prefirst; \
+ int state; \
} clist_##X##_iter_t
#define clist_ini {NULL}
@@ -130,7 +130,7 @@ STC_API size_t _clist_size(const clist_void* self); \
STC_INLINE clist_##X##_iter_t \
clist_##X##_before_begin(clist_##X* self) { \
- clist_##X##_iter_t it = {&self->last, self->last, 1}; return it; \
+ clist_##X##_iter_t it = {&self->last, self->last, -1}; return it; \
} \
STC_INLINE clist_##X##_iter_t \
clist_##X##_begin(clist_##X* self) { \
@@ -143,8 +143,7 @@ STC_API size_t _clist_size(const clist_void* self); } \
STC_INLINE void \
clist_##X##_next(clist_##X##_iter_t* it) { \
- it->prefirst = 0; \
- it->item = (it->item == *it->_last) ? NULL : it->item->next; \
+ it->item = ((it->state += it->item == *it->_last) == 1) ? NULL : it->item->next; \
} \
STC_INLINE clist_##X##_value_t* \
clist_##X##_itval(clist_##X##_iter_t it) {return &it.item->value;} \
@@ -168,13 +167,13 @@ STC_API size_t _clist_size(const clist_void* self); } \
STC_INLINE void \
clist_##X##_splice_back(clist_##X* self, clist_##X* other) { \
- clist_##X##_iter_t last = {&self->last, self->last}; \
+ clist_##X##_iter_t last = {&self->last, self->last, 0}; \
clist_##X##_splice_after(self, last, other); \
} \
\
STC_API clist_##X##_iter_t \
clist_##X##_find_before(clist_##X* self, clist_##X##_iter_t prev, RawValue val); \
- STC_API Value* \
+ STC_API clist_##X##_iter_t \
clist_##X##_find(clist_##X* self, RawValue val); \
STC_API size_t \
clist_##X##_remove(clist_##X* self, RawValue val); \
@@ -222,7 +221,7 @@ STC_API size_t _clist_size(const clist_void* self); STC_API clist_##X##_iter_t \
clist_##X##_insert_after(clist_##X* self, clist_##X##_iter_t it, Value value) { \
_clist_insert_after(self, X, it.item, value); \
- if (it.item == self->last && !it.prefirst) self->last = entry; \
+ if (it.item == self->last && it.state == 0) self->last = entry; \
it.item = entry; return it; \
} \
STC_API clist_##X##_iter_t \
@@ -244,10 +243,11 @@ STC_API size_t _clist_size(const clist_void* self); return prev; \
} \
\
- STC_API Value* \
+ STC_API clist_##X##_iter_t \
clist_##X##_find(clist_##X* self, RawValue val) { \
clist_##X##_iter_t it = clist_##X##_find_before(self, clist_##X##_before_begin(self), val); \
- return it.item ? &it.item->next->value : NULL; \
+ if (it.item) it.item = it.item->next; \
+ return it; \
} \
\
STC_API size_t \
@@ -297,7 +297,7 @@ _clist_splice_after(clist_void* self, clist_void_iter_t it, clist_void* other) { clist_void_node_t *next = it.item->next;
it.item->next = other->last->next;
other->last->next = next;
- if (it.item == self->last && !it.prefirst) self->last = other->last;
+ if (it.item == self->last && it.state == 0) self->last = other->last;
}
other->last = NULL;
}
|
