commit 6cd25d711739ea44de770962fab99576d0eb69a0
parent f1318007de1b919bf8e76c254e1d489b6b84eedf
Author: Robert Russell <robertrussell.72001@gmail.com>
Date: Tue, 26 Sep 2023 10:51:36 -0700
Update list
Set previous commits.
Diffstat:
15 files changed, 150 insertions(+), 141 deletions(-)
diff --git a/inc/list/declare.h b/inc/list/declare.h
@@ -1,9 +0,0 @@
-#include <errno.h>
-
-#include "../alloc.h"
-#include "../def.h"
-
-#include "impl/macro.h"
-#include "impl/common.h"
-#include "impl/declare.h"
-#include "impl/unmacro.h"
diff --git a/inc/list/define.h b/inc/list/define.h
@@ -1,10 +0,0 @@
-#include <errno.h>
-#include <string.h>
-
-#include "../alloc.h"
-#include "../def.h"
-#include "../internal/util.h"
-
-#include "impl/macro.h"
-#include "impl/define.h"
-#include "impl/unmacro.h"
diff --git a/inc/list/impl/clean.h b/inc/list/impl/clean.h
@@ -0,0 +1,11 @@
+#undef LIST_HDR
+#undef LIST_ASSERT
+#undef LIST_FREE
+#undef LIST_REALLOC
+#undef LIST_MIN_CAP
+#undef LIST_METHOD
+#undef LIST_T
+#undef LIST_STATIC
+#undef LIST_DEFS
+#undef LIST_DECLS
+#undef LIST_TYPES
diff --git a/inc/list/impl/declare.h b/inc/list/impl/declare.h
@@ -1,76 +0,0 @@
-#ifndef LIST_STATIC
-#define LIST_STATIC
-#endif
-
-LIST_STATIC UNUSED int LIST_METHOD(resize)(LIST_T **l, usize cap);
-LIST_STATIC UNUSED int LIST_METHOD(reserve)(LIST_T **l, usize n);
-LIST_STATIC UNUSED int LIST_METHOD(insarr)(LIST_T **dst, usize i, LIST_T *src, usize n);
-LIST_STATIC UNUSED LIST_T LIST_METHOD(del)(LIST_T **l, usize i);
-
-#undef LIST_STATIC
-
-static inline UNUSED void
-LIST_METHOD(free)(LIST_T **l) {
- if (*l) {
- int e = errno;
- LIST_FREE(LIST_HDR(*l));
- errno = e;
- }
- *l = 0;
-}
-
-static inline UNUSED usize
-LIST_METHOD(len)(LIST_T **l) {
- return *l ? LIST_HDR(*l)->len : 0;
-}
-
-static inline UNUSED usize
-LIST_METHOD(cap)(LIST_T **l) {
- return *l ? LIST_HDR(*l)->cap : 0;
-}
-
-static inline UNUSED int
-LIST_METHOD(ins)(LIST_T **l, usize i, LIST_T e) {
- return LIST_METHOD(insarr)(l, i, &e, 1);
-}
-
-static inline UNUSED int
-LIST_METHOD(inslst)(LIST_T **dst, usize i, LIST_T *src) {
- return LIST_METHOD(insarr)(dst, i, src, LIST_METHOD(len)(&src));
-}
-
-static inline UNUSED int
-LIST_METHOD(catarr)(LIST_T **dst, LIST_T *src, usize n) {
- return LIST_METHOD(insarr)(dst, LIST_METHOD(len)(dst), src, n);
-}
-
-static inline UNUSED int
-LIST_METHOD(catlst)(LIST_T **dst, LIST_T *src) {
- return LIST_METHOD(catarr)(dst, src, LIST_METHOD(len)(&src));
-}
-
-static inline UNUSED int
-LIST_METHOD(push)(LIST_T **l, LIST_T e) {
- return LIST_METHOD(catarr)(l, &e, 1);
-}
-
-static inline UNUSED LIST_T
-LIST_METHOD(pop)(LIST_T **l) {
- LIST_ASSERT(LIST_METHOD(len)(l) > 0,
- STRINGIFY(LIST_METHOD(pop))" called on empty list");
- return LIST_METHOD(del)(l, LIST_HDR(*l)->len - 1);
-}
-
-static inline UNUSED LIST_T
-LIST_METHOD(peek)(LIST_T **l) {
- LIST_ASSERT(LIST_METHOD(len)(l) > 0,
- STRINGIFY(LIST_METHOD(peek))" called on empty list");
- return (*l)[LIST_HDR(*l)->len - 1];
-}
-
-static inline UNUSED void
-LIST_METHOD(trunc)(LIST_T **l, usize n) {
- LIST_ASSERT(n <= LIST_METHOD(len)(l),
- STRINGIFY(LIST_METHOD(trunc))" called with n > len");
- if (*l) LIST_HDR(*l)->len = n;
-}
diff --git a/inc/list/impl/decls.h b/inc/list/impl/decls.h
@@ -0,0 +1,70 @@
+LIST_STATIC UNUSED int LIST_METHOD(resize)(LIST_T **l, usize cap);
+LIST_STATIC UNUSED int LIST_METHOD(reserve)(LIST_T **l, usize n);
+LIST_STATIC UNUSED int LIST_METHOD(insarr)(LIST_T **dst, usize i, LIST_T *src, usize n);
+LIST_STATIC UNUSED LIST_T LIST_METHOD(del)(LIST_T **l, usize i);
+
+static inline UNUSED void
+LIST_METHOD(free)(LIST_T **l) {
+ if (*l) {
+ int e = errno;
+ LIST_FREE(LIST_HDR(*l));
+ errno = e;
+ }
+ *l = 0;
+}
+
+static inline UNUSED usize
+LIST_METHOD(len)(LIST_T **l) {
+ return *l ? LIST_HDR(*l)->len : 0;
+}
+
+static inline UNUSED usize
+LIST_METHOD(cap)(LIST_T **l) {
+ return *l ? LIST_HDR(*l)->cap : 0;
+}
+
+static inline UNUSED int
+LIST_METHOD(ins)(LIST_T **l, usize i, LIST_T e) {
+ return LIST_METHOD(insarr)(l, i, &e, 1);
+}
+
+static inline UNUSED int
+LIST_METHOD(inslst)(LIST_T **dst, usize i, LIST_T *src) {
+ return LIST_METHOD(insarr)(dst, i, src, LIST_METHOD(len)(&src));
+}
+
+static inline UNUSED int
+LIST_METHOD(catarr)(LIST_T **dst, LIST_T *src, usize n) {
+ return LIST_METHOD(insarr)(dst, LIST_METHOD(len)(dst), src, n);
+}
+
+static inline UNUSED int
+LIST_METHOD(catlst)(LIST_T **dst, LIST_T *src) {
+ return LIST_METHOD(catarr)(dst, src, LIST_METHOD(len)(&src));
+}
+
+static inline UNUSED int
+LIST_METHOD(push)(LIST_T **l, LIST_T e) {
+ return LIST_METHOD(catarr)(l, &e, 1);
+}
+
+static inline UNUSED LIST_T
+LIST_METHOD(pop)(LIST_T **l) {
+ LIST_ASSERT(LIST_METHOD(len)(l) > 0,
+ STRINGIFY(LIST_METHOD(pop))" called on empty list");
+ return LIST_METHOD(del)(l, LIST_HDR(*l)->len - 1);
+}
+
+static inline UNUSED LIST_T
+LIST_METHOD(peek)(LIST_T **l) {
+ LIST_ASSERT(LIST_METHOD(len)(l) > 0,
+ STRINGIFY(LIST_METHOD(peek))" called on empty list");
+ return (*l)[LIST_HDR(*l)->len - 1];
+}
+
+static inline UNUSED void
+LIST_METHOD(trunc)(LIST_T **l, usize n) {
+ LIST_ASSERT(n <= LIST_METHOD(len)(l),
+ STRINGIFY(LIST_METHOD(trunc))" called with n > len");
+ if (*l) LIST_HDR(*l)->len = n;
+}
diff --git a/inc/list/impl/define.h b/inc/list/impl/defs.h
diff --git a/inc/list/impl/macro.h b/inc/list/impl/macro.h
@@ -1,26 +0,0 @@
-#ifndef LIST_T
-#error "rcx/list: LIST_T must be defined"
-#endif
-
-#ifndef LIST_METHOD
-#define LIST_METHOD(name) name
-#endif
-
-#ifndef LIST_MIN_CAP
-#define LIST_MIN_CAP 8
-#endif
-
-#ifndef LIST_REALLOC
-#define LIST_REALLOC r_erealloc
-#endif
-
-#ifndef LIST_FREE
-#define LIST_FREE free
-#endif
-
-#ifndef LIST_ASSERT
-#include "../../debug.h"
-#define LIST_ASSERT ASSERT
-#endif
-
-#define LIST_HDR(l) ((RListHdr_ *)(l) - 1)
diff --git a/inc/list/impl/macros.h b/inc/list/impl/macros.h
@@ -0,0 +1,33 @@
+#ifdef LIST_STATIC
+#undef LIST_STATIC
+#define LIST_STATIC static
+#else
+#define LIST_STATIC
+#endif
+
+#ifndef LIST_T
+#error "rcx/list: LIST_T must be defined"
+#endif
+
+#ifndef LIST_METHOD
+#define LIST_METHOD(name) name
+#endif
+
+#ifndef LIST_MIN_CAP
+#define LIST_MIN_CAP 8
+#endif
+
+#ifndef LIST_REALLOC
+#define LIST_REALLOC r_erealloc
+#endif
+
+#ifndef LIST_FREE
+#define LIST_FREE free
+#endif
+
+#ifndef LIST_ASSERT
+#include "../../debug.h"
+#define LIST_ASSERT ASSERT
+#endif
+
+#define LIST_HDR(l) ((RListHdr_ *)(l) - 1)
diff --git a/inc/list/impl/unmacro.h b/inc/list/impl/unmacro.h
@@ -1,7 +0,0 @@
-#undef LIST_HDR
-#undef LIST_ASSERT
-#undef LIST_FREE
-#undef LIST_REALLOC
-#undef LIST_MIN_CAP
-#undef LIST_METHOD
-#undef LIST_T
diff --git a/inc/list/main.h b/inc/list/main.h
@@ -0,0 +1,19 @@
+#include "../def.h"
+#if defined(LIST_DECLS) || defined(LIST_DEFS)
+#include <errno.h>
+#include "../alloc.h"
+#endif
+#ifdef LIST_DEFS
+#include <string.h>
+#include "../internal/util.h"
+#endif
+
+#include "impl/macros.h"
+#include "impl/common.h"
+#ifdef LIST_DECLS
+#include "impl/decls.h"
+#endif
+#ifdef LIST_DEFS
+#include "impl/defs.h"
+#endif
+#include "impl/clean.h"
diff --git a/inc/list/priv-hdr.h b/inc/list/priv-hdr.h
@@ -0,0 +1,3 @@
+#define LIST_TYPES
+#define LIST_STATIC
+#include "main.h"
diff --git a/inc/list/priv-src.h b/inc/list/priv-src.h
@@ -0,0 +1,4 @@
+#define LIST_DECLS
+#define LIST_DEFS
+#define LIST_STATIC
+#include "main.h"
diff --git a/inc/list/pub-hdr.h b/inc/list/pub-hdr.h
@@ -0,0 +1,3 @@
+#define LIST_TYPES
+#define LIST_DECLS
+#include "main.h"
diff --git a/inc/list/pub-src.h b/inc/list/pub-src.h
@@ -0,0 +1,2 @@
+#define LIST_DEFS
+#include "main.h"
diff --git a/inc/list/static.h b/inc/list/static.h
@@ -1,13 +1,5 @@
-#include <errno.h>
-#include <string.h>
-
-#include "../alloc.h"
-#include "../def.h"
-#include "../internal/util.h"
-
-#include "impl/macro.h"
-#include "impl/common.h"
-#define LIST_STATIC static
-#include "impl/declare.h"
-#include "impl/define.h"
-#include "impl/unmacro.h"
+#define LIST_TYPES
+#define LIST_DECLS
+#define LIST_DEFS
+#define LIST_STATIC
+#include "main.h"