diff options
| author | Tyge Lovset <[email protected]> | 2023-05-21 23:30:25 +0200 |
|---|---|---|
| committer | Tyge Lovset <[email protected]> | 2023-05-21 23:30:25 +0200 |
| commit | 0b34cadda2bc4da1cb0904989c8a5f2fe0236358 (patch) | |
| tree | 038335539ecd9363fbfc70a850a340b291a10888 | |
| parent | 56b0884044610861866a1a27fb64276411604986 (diff) | |
| download | STC-modified-0b34cadda2bc4da1cb0904989c8a5f2fe0236358.tar.gz STC-modified-0b34cadda2bc4da1cb0904989c8a5f2fe0236358.zip | |
NB! Made cstr.h header-only by default. Now requires #define i_static, i_implement or i_extern (includes utf8code.c) to implement non-inline functions (or link with libstc).
| -rw-r--r-- | .github/workflows/workflow.yml | 4 | ||||
| -rw-r--r-- | CMakeLists.txt | 1 | ||||
| -rw-r--r-- | include/stc/ccommon.h | 2 | ||||
| -rw-r--r-- | include/stc/cregex.h | 6 | ||||
| -rw-r--r-- | include/stc/cstack.h | 6 | ||||
| -rw-r--r-- | include/stc/cstr.h | 1 | ||||
| -rw-r--r-- | include/stc/csview.h | 1 | ||||
| -rwxr-xr-x | misc/examples/make.sh | 2 | ||||
| -rw-r--r-- | misc/tests/cregex_test.c | 6 | ||||
| -rw-r--r-- | src/libstc.c | 4 |
10 files changed, 20 insertions, 13 deletions
diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 5ceacd43..b1443a0d 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -7,8 +7,8 @@ jobs: build_and_test: runs-on: ubuntu-latest env: - CFLAGS: -Wall -Wno-unused-function -ggdb3 -fsanitize=address -fsanitize=undefined -fsanitize=pointer-compare -fsanitize=pointer-subtract - CXXFLAGS: -Wall -Wno-unused-function -ggdb3 -fsanitize=address -fsanitize=undefined -fsanitize=pointer-compare -fsanitize=pointer-subtract + CFLAGS: -DSTC_STATIC -Wall -Wno-unused-function -ggdb3 -fsanitize=address -fsanitize=undefined -fsanitize=pointer-compare -fsanitize=pointer-subtract + CXXFLAGS: -DSTC_STATIC -Wall -Wno-unused-function -ggdb3 -fsanitize=address -fsanitize=undefined -fsanitize=pointer-compare -fsanitize=pointer-subtract steps: - name: 'Checkout' uses: actions/checkout@v2 diff --git a/CMakeLists.txt b/CMakeLists.txt index 87662318..3edd39cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ if(BUILD_TESTING) get_filename_component(name "${file}" NAME_WE) add_executable(${name} ${file}) #target_compile_options(${name} PRIVATE "-pthread") + target_compile_options(${name} PRIVATE "-DSTC_STATIC") if(CMAKE_THREAD_LIBS_INIT) target_link_libraries(${name} PRIVATE "${CMAKE_THREAD_LIBS_INIT}") endif() diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index e9d97d4b..eb3a6601 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -253,6 +253,6 @@ STC_INLINE intptr_t cnextpow2(intptr_t n) { #if defined(STC_EXTERN) #define i_extern #endif -#if defined(i_static) || defined(STC_IMPLEMENT) +#if defined(i_static) || defined(STC_IMPLEMENT) || defined(i_extern) #define i_implement #endif diff --git a/include/stc/cregex.h b/include/stc/cregex.h index f90acbf4..bf239ff6 100644 --- a/include/stc/cregex.h +++ b/include/stc/cregex.h @@ -160,12 +160,14 @@ cstr cregex_replace_pattern_6(const char* pattern, const char* input, const char void cregex_drop(cregex* re); #endif // CREGEX_H_INCLUDED -#if defined(i_extern) +#if defined i_extern || defined i_implement # include "../../src/cregex.c" +#endif +#if defined i_extern # include "../../src/utf8code.c" -# undef i_extern #endif #undef i_opt #undef i_header #undef i_static #undef i_implement +#undef i_extern diff --git a/include/stc/cstack.h b/include/stc/cstack.h index eb6ccb58..ae8b3c40 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -175,12 +175,12 @@ STC_INLINE i_keyraw _cx_memb(_value_toraw)(const _cx_value* val) #endif // !i_no_clone STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { - return c_LITERAL(_cx_iter){self->_len ? self->data : NULL, - self->data + self->_len}; + return c_LITERAL(_cx_iter){self->_len ? (_cx_value*)self->data : NULL, + (_cx_value*)self->data + self->_len}; } STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) - { return c_LITERAL(_cx_iter){NULL, self->data + self->_len}; } + { return c_LITERAL(_cx_iter){NULL, (_cx_value*)self->data + self->_len}; } STC_INLINE void _cx_memb(_next)(_cx_iter* it) { if (++it->ref == it->end) it->ref = NULL; } diff --git a/include/stc/cstr.h b/include/stc/cstr.h index 244b0a91..d496b85e 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -27,6 +27,7 @@ #ifndef CSTR_H_INCLUDED #define CSTR_H_INCLUDED +#define i_header #if defined i_extern || defined STC_EXTERN # define _i_extern #endif diff --git a/include/stc/csview.h b/include/stc/csview.h index bba3aea3..571bb278 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -24,7 +24,6 @@ #define CSVIEW_H_INCLUDED #include "ccommon.h" -#include "forward.h" #include "utf8.h" #define csview_NULL c_sv_1("") diff --git a/misc/examples/make.sh b/misc/examples/make.sh index ee8d2267..25b720b8 100755 --- a/misc/examples/make.sh +++ b/misc/examples/make.sh @@ -6,7 +6,7 @@ if [ "$(uname)" = 'Linux' ]; then oflag='-o ' fi -cc=gcc; cflags="-s -O3 -std=c99 -Wall -Wextra -Wpedantic -Wconversion -Wwrite-strings -Wdouble-promotion -Wno-unused-parameter -Wno-implicit-fallthrough -Wno-maybe-uninitialized -Wno-missing-field-initializers" +cc=gcc; cflags="-DSTC_STATIC -s -O3 -std=c99 -Wall -Wextra -Wpedantic -Wconversion -Wwrite-strings -Wdouble-promotion -Wno-unused-parameter -Wno-implicit-fallthrough -Wno-maybe-uninitialized -Wno-missing-field-initializers" #cc=gcc; cflags="-g -std=c99 -Werror -Wfatal-errors -Wpedantic -Wall $sanitize" #cc=tcc; cflags="-Wall -std=c99" #cc=clang; cflags="-s -O2 -std=c99 -Werror -Wfatal-errors -Wpedantic -Wall -Wno-unused-function -Wsign-compare -Wwrite-strings" diff --git a/misc/tests/cregex_test.c b/misc/tests/cregex_test.c index 07e5c3cb..301ecf4f 100644 --- a/misc/tests/cregex_test.c +++ b/misc/tests/cregex_test.c @@ -209,7 +209,7 @@ CTEST(cregex, captures_len) { c_auto (cregex, re) { re = cregex_from("(ab(cd))(ef)"); - ASSERT_EQ(cregex_captures(&re), 4); + ASSERT_EQ(cregex_captures(&re), 3); } } @@ -218,7 +218,7 @@ CTEST(cregex, captures_cap) const char* inp; c_auto (cregex, re) { re = cregex_from("(ab)((cd)+)"); - ASSERT_EQ(cregex_captures(&re), 4); + ASSERT_EQ(cregex_captures(&re), 3); csview cap[5]; ASSERT_EQ(cregex_find(&re, inp="xxabcdcde", cap), CREG_OK); @@ -273,7 +273,7 @@ CTEST(cregex, replace) // Compile RE separately re = cregex_from(pattern); - ASSERT_EQ(cregex_captures(&re), 4); + ASSERT_EQ(cregex_captures(&re), 3); // European date format. cstr_take(&str, cregex_replace(&re, input, "$3.$2.$1")); diff --git a/src/libstc.c b/src/libstc.c new file mode 100644 index 00000000..bc61e37c --- /dev/null +++ b/src/libstc.c @@ -0,0 +1,4 @@ +#define i_extern
+#include "../include/stc/cregex.h"
+#define i_implement
+#include "../include/stc/csview.h"
|
