summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile21
-rw-r--r--config.mk7
-rw-r--r--pk.h.in35
-rw-r--r--pkmem-types.h33
-rw-r--r--pkmem.h8
-rw-r--r--pkstr.h4
7 files changed, 84 insertions, 25 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3eb7760
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+pk.h
diff --git a/Makefile b/Makefile
index 4891508..553c6bc 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,9 @@
-# pkh - header-only library
+# pk.h
# See LICENSE file for copyright and license details.
include config.mk
-.PHONY: pkmem-types pkmem
+.PHONY: pkmacros pkmem-types pkmem pkstr
SRC = \
pkmacros.h \
@@ -29,8 +29,8 @@ all: options .WAIT clean .WAIT \
pkmem-types \
pkmem \
pkstr \
+ test-pkmem-types test-pkmem-types-cpp \
test-pkmem test-pkmem-cpp \
- test-types-pkmem test-types-pkmem-cpp \
test-pkmacros test-pkmacros-cpp \
test-pkstr test-pkstr-cpp \
@@ -64,6 +64,19 @@ pkmem: pkmem-types pkmem.gch pkmem.gchpp
pkstr: pkmacros pkstr.gch pkstr.gchpp
+build: pkmacros
+build: pkmem-types
+build: pkmem
+build: pkstr
+ @sed "1d; s/@@PK_VERSION@@/$(VERSION)/g; s/@@YEAR@@/`date -u +%%Y`/g;" pk.h.in > tmp
+ cat tmp \
+ pkmacros.h \
+ pkmem-types.h \
+ pkmem.h \
+ pkstr.h \
+ > pk.h
+ rm tmp
+
test-pkmacros: test/pkmacros.o
$(CC) -g -O0 -std=c2x $(CFLAGS) -o test/$@ $^ $(LDFLAGS)
@@ -88,7 +101,7 @@ test-pkstr: test/pkstr.o
test-pkstr-cpp: test/pkstr.so
$(CXX) -g -O0 -std=c++23 $(CPPFLAGS) -o test/$@ $^ $(LDFLAGS)
-test: pkmacros pkmem-types pkmem
+test: pkmacros pkmem-types pkmem pkstr
test: test-pkmacros test-pkmacros-cpp
test: test-pkmem-types test-pkmem-types-cpp
test: test-pkmem test-pkmem-cpp
diff --git a/config.mk b/config.mk
index cf3ab50..5cc5bb7 100644
--- a/config.mk
+++ b/config.mk
@@ -1,4 +1,4 @@
-# pkh version
+# pk.h version
VERSION = 0.0.1
# paths
@@ -15,7 +15,10 @@ LIBS = -lm \
# flags
# -pedantic
SHARED_FLAGS = -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L \
- -DVERSION=\"$(VERSION)\" -DPK_MEMORY_DEBUGGER -DPK_IMPLEMENTATION \
+ -DVERSION=\"$(VERSION)\" -DPK_MEMORY_DEBUGGER -DPK_IMPL_ALL \
+ -DPK_IMPL_MEM_TYPES \
+ -DPK_IMPL_MEM \
+ -DPK_IMPL_STR \
CPPFLAGS += -Wall $(INCS) $(SHARED_FLAGS)
CFLAGS += -Wall $(INCS) $(SHARED_FLAGS)
diff --git a/pk.h.in b/pk.h.in
new file mode 100644
index 0000000..eb33eee
--- /dev/null
+++ b/pk.h.in
@@ -0,0 +1,35 @@
+// vim: tw=80
+/******************************************************************************
+* PK Single-Header-Library V@@PK_VERSION@@
+*
+* Author: Jonathan Bradley
+* Copyright: © 2024-@@YEAR@@ Jonathan Bradley
+* Description:
+*
+*******************************************************************************
+* pkmacros.h:
+*
+*******************************************************************************
+* pkmem-types.h:
+*
+*******************************************************************************
+* pkmem.h:
+*
+*******************************************************************************
+* pkstr.h:
+*
+******************************************************************************/
+
+#define PK_VERSION "@@PK_VERSION@@"
+
+#ifdef PK_IMPL_ALL
+# ifndef PK_IMPL_MEM_TYPES
+# define PK_IMPL_MEM_TYPES
+# endif
+# ifndef PK_IMPL_MEM
+# define PK_IMPL_MEM
+# endif
+# ifndef PK_IMPL_STR
+# define PK_IMPL_STR
+# endif
+#endif
diff --git a/pkmem-types.h b/pkmem-types.h
index 27f6f50..8be66f1 100644
--- a/pkmem-types.h
+++ b/pkmem-types.h
@@ -20,19 +20,8 @@ struct pk_handle {
const struct pk_handle pk_handle_MAX = (struct pk_handle){ .bucketIndex = 0xFFFFFFFF, .itemIndex = 0xFFFFFFFF };
-static inline enum PK_HANDLE_VALIDATION
-pk_handle_validate(const struct pk_handle handle, const struct pk_handle bucketHandle, const uint64_t maxItems)
-{
- if (handle.bucketIndex == pk_handle_MAX.bucketIndex && handle.itemIndex == pk_handle_MAX.itemIndex)
- return PK_HANDLE_VALIDATION_VALUE_MAX;
- if (handle.bucketIndex > bucketHandle.bucketIndex)
- return PK_HANDLE_VALIDATION_BUCKET_INDEX_TOO_HIGH;
- if (handle.itemIndex > maxItems)
- return PK_HANDLE_VALIDATION_ITEM_INDEX_TOO_HIGH;
- if (handle.bucketIndex == bucketHandle.bucketIndex && handle.itemIndex > bucketHandle.itemIndex)
- return PK_HANDLE_VALIDATION_ITEM_INDEX_TOO_HIGH;
- return PK_HANDLE_VALIDATION_VALID;
-}
+static inline enum PK_HANDLE_VALIDATION pk_handle_validate(const struct pk_handle handle, const struct pk_handle bucketHandle, const uint64_t maxItems);
+
#if defined(__cplusplus)
@@ -63,3 +52,21 @@ pk_handle_validate_constexpr()
struct pk_membucket;
#endif /* PK_MEM_TYPES_H */
+
+#ifdef PK_IMPL_MEM_TYPES
+
+enum PK_HANDLE_VALIDATION
+pk_handle_validate(const struct pk_handle handle, const struct pk_handle bucketHandle, const uint64_t maxItems)
+{
+ if (handle.bucketIndex == pk_handle_MAX.bucketIndex && handle.itemIndex == pk_handle_MAX.itemIndex)
+ return PK_HANDLE_VALIDATION_VALUE_MAX;
+ if (handle.bucketIndex > bucketHandle.bucketIndex)
+ return PK_HANDLE_VALIDATION_BUCKET_INDEX_TOO_HIGH;
+ if (handle.itemIndex > maxItems)
+ return PK_HANDLE_VALIDATION_ITEM_INDEX_TOO_HIGH;
+ if (handle.bucketIndex == bucketHandle.bucketIndex && handle.itemIndex > bucketHandle.itemIndex)
+ return PK_HANDLE_VALIDATION_ITEM_INDEX_TOO_HIGH;
+ return PK_HANDLE_VALIDATION_VALID;
+}
+
+#endif /* PK_IMPL_MEM_TYPES */
diff --git a/pkmem.h b/pkmem.h
index e0267c4..6a2b93a 100644
--- a/pkmem.h
+++ b/pkmem.h
@@ -1,8 +1,8 @@
#ifndef PK_MEM_H
#define PK_MEM_H
-#include "pkmem-types.h"
-#include "pkmacros.h"
+#include "./pkmem-types.h"
+#include "./pkmacros.h"
#include <string.h>
#include <stdint.h>
@@ -109,7 +109,7 @@ pk_delete(const T* ptr, long count, pk_membucket* bucket = nullptr)
#endif /* PK_MEM */
-#ifdef PK_IMPLEMENTATION
+#ifdef PK_IMPL_MEM
#include <threads.h>
#include <assert.h>
@@ -553,4 +553,4 @@ pk_delete_base(const void* ptr, size_t sz)
pk_delete_bkt(ptr, sz, bkt);
}
-#endif /* PK_IMPLEMENTATION */
+#endif /* PK_IMPL_MEM */
diff --git a/pkstr.h b/pkstr.h
index fc53c49..75d6801 100644
--- a/pkstr.h
+++ b/pkstr.h
@@ -23,7 +23,7 @@ int pk_compare_cstr(const struct pk_cstr *lhs, const struct pk_cstr *rhs);
#endif /* PK_STR_H */
-#ifdef PK_IMPLEMENTATION
+#ifdef PK_IMPL_STR
#include "./pkmacros.h"
@@ -81,4 +81,4 @@ pk_compare_cstr(const struct pk_cstr *lhs, const struct pk_cstr *rhs)
return strncmp(lhs->val, rhs->val, PK_MIN(lhs->length, rhs->length));
}
-#endif /* PK_IMPLEMENTATION */
+#endif /* PK_IMPL_STR */