summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-02-05 11:20:08 +0100
committerTyge Løvset <[email protected]>2023-02-05 11:20:08 +0100
commitff5a1bf4a623cf528e8b601959da993917e79c04 (patch)
tree9b071b64d0abe7f0c752c14f6582f6584c62a3a0
parentadc47cefc2976768c3f0b773bd26bfd1062e8a53 (diff)
downloadSTC-modified-ff5a1bf4a623cf528e8b601959da993917e79c04.tar.gz
STC-modified-ff5a1bf4a623cf528e8b601959da993917e79c04.zip
- Updated cspan.h to allow for compiling some functions as shared symbols.
- Fixed issue #45 warning -Wunused-parameter in clist.h - Fixed some issues with the singleheader.py generator.
-rw-r--r--include/stc/clist.h2
-rw-r--r--include/stc/cspan.h54
-rw-r--r--include/stc/cstr.h1
-rw-r--r--src/cregex.c1
-rw-r--r--src/singleheader.py6
-rw-r--r--src/utf8code.c1
6 files changed, 39 insertions, 26 deletions
diff --git a/include/stc/clist.h b/include/stc/clist.h
index 283c8774..cd6ec61e 100644
--- a/include/stc/clist.h
+++ b/include/stc/clist.h
@@ -138,7 +138,7 @@ STC_INLINE void _cx_memb(_put_n)(_cx_self* self, const _cx_raw* raw, int
{ while (n--) _cx_memb(_push_back)(self, i_keyfrom(*raw++)); }
STC_INLINE _cx_self _cx_memb(_from_n)(const _cx_raw* raw, intptr_t n)
{ _cx_self cx = {0}; _cx_memb(_put_n)(&cx, raw, n); return cx; }
-STC_INLINE bool _cx_memb(_reserve)(_cx_self* self, intptr_t n) { return true; }
+STC_INLINE bool _cx_memb(_reserve)(_cx_self* self, intptr_t n) { (void)(self + n); return true; }
STC_INLINE bool _cx_memb(_empty)(const _cx_self* self) { return self->last == NULL; }
STC_INLINE void _cx_memb(_clear)(_cx_self* self) { _cx_memb(_drop)(self); }
STC_INLINE _cx_value* _cx_memb(_push)(_cx_self* self, i_key value)
diff --git a/include/stc/cspan.h b/include/stc/cspan.h
index 68a13522..cc3d03b3 100644
--- a/include/stc/cspan.h
+++ b/include/stc/cspan.h
@@ -170,7 +170,13 @@ typedef struct { int32_t d[6]; } cspan_idx6;
#define cspan_submd4_4(self, x, y, z) \
{.data=cspan_at(self, x, y, z, 0), .shape={(self)->shape[3]}}
-// FUNCTIONS
+// private definitions:
+
+STC_INLINE intptr_t _cspan_size(const int32_t shape[], int rank) {
+ intptr_t sz = shape[0];
+ while (rank-- > 1) sz *= shape[rank];
+ return sz;
+}
STC_INLINE intptr_t _cspan_idx1(const int32_t shape[1], const cspan_idx1 stri, int32_t x)
{ c_ASSERT(c_LTu(x, shape[0])); return x; }
@@ -183,11 +189,27 @@ STC_INLINE intptr_t _cspan_idx3(const int32_t shape[3], const cspan_idx3 stri, i
return (intptr_t)stri.d[2]*(stri.d[1]*x + y) + z;
}
STC_INLINE intptr_t _cspan_idx4(const int32_t shape[4], const cspan_idx4 stri, int32_t x, int32_t y,
- int32_t z, int32_t w) {
+ int32_t z, int32_t w) {
c_ASSERT(c_LTu(x, shape[0]) && c_LTu(y, shape[1]) && c_LTu(z, shape[2]) && c_LTu(w, shape[3]));
return (intptr_t)stri.d[3]*(stri.d[2]*(stri.d[1]*x + y) + z) + w;
}
-STC_INLINE intptr_t _cspan_idxN(int rank, const int32_t shape[], const int32_t stri[], const int32_t a[]) {
+
+STC_API intptr_t _cspan_idxN(int rank, const int32_t shape[], const int32_t stri[], const int32_t a[]);
+STC_API intptr_t _cspan_next2(int rank, int32_t pos[], const int32_t shape[], const int32_t stride[]);
+#define _cspan_next1(r, pos, d, s) (++pos[0], 1)
+#define _cspan_next3 _cspan_next2
+#define _cspan_next4 _cspan_next2
+#define _cspan_next5 _cspan_next2
+#define _cspan_next6 _cspan_next2
+
+STC_API intptr_t _cspan_slice(int32_t odim[], int32_t ostri[], int* orank,
+ const int32_t shape[], const int32_t stri[],
+ int rank, const int32_t a[][2]);
+
+/* -------------------------- IMPLEMENTATION ------------------------- */
+#if defined(i_implement)
+
+STC_DEF intptr_t _cspan_idxN(int rank, const int32_t shape[], const int32_t stri[], const int32_t a[]) {
intptr_t off = a[0];
bool ok = c_LTu(a[0], shape[0]);
for (int i = 1; i < rank; ++i) {
@@ -199,19 +221,7 @@ STC_INLINE intptr_t _cspan_idxN(int rank, const int32_t shape[], const int32_t s
return off;
}
-STC_INLINE intptr_t _cspan_size(const int32_t shape[], int rank) {
- intptr_t sz = shape[0];
- while (rank-- > 1) sz *= shape[rank];
- return sz;
-}
-
-#define _cspan_next1(r, pos, d, s) (++pos[0], 1)
-#define _cspan_next3 _cspan_next2
-#define _cspan_next4 _cspan_next2
-#define _cspan_next5 _cspan_next2
-#define _cspan_next6 _cspan_next2
-
-STC_INLINE intptr_t _cspan_next2(int rank, int32_t pos[], const int32_t shape[], const int32_t stride[]) {
+STC_DEF intptr_t _cspan_next2(int rank, int32_t pos[], const int32_t shape[], const int32_t stride[]) {
intptr_t off = 1, rs = 1;
++pos[rank - 1];
while (--rank && pos[rank] == shape[rank]) {
@@ -223,9 +233,9 @@ STC_INLINE intptr_t _cspan_next2(int rank, int32_t pos[], const int32_t shape[],
return off;
}
-STC_INLINE intptr_t _cspan_slice(int32_t odim[], int32_t ostri[], int* orank,
- const int32_t shape[], const int32_t stri[],
- int rank, const int32_t a[][2]) {
+STC_DEF intptr_t _cspan_slice(int32_t odim[], int32_t ostri[], int* orank,
+ const int32_t shape[], const int32_t stri[],
+ int rank, const int32_t a[][2]) {
intptr_t off = 0;
int i = 0, j = 0, ok = true;
int32_t t, s = 1;
@@ -247,3 +257,9 @@ STC_INLINE intptr_t _cspan_slice(int32_t odim[], int32_t ostri[], int* orank,
return off;
}
#endif
+#endif
+#undef i_opt
+#undef i_header
+#undef i_implement
+#undef i_static
+#undef i_extern
diff --git a/include/stc/cstr.h b/include/stc/cstr.h
index 2966db81..c5808d02 100644
--- a/include/stc/cstr.h
+++ b/include/stc/cstr.h
@@ -36,7 +36,6 @@
#include <stdlib.h> /* malloc */
#include <stdarg.h>
#include <stdio.h> /* vsnprintf */
-#include <ctype.h>
/**************************** PRIVATE API **********************************/
diff --git a/src/cregex.c b/src/cregex.c
index c17e1967..def759ee 100644
--- a/src/cregex.c
+++ b/src/cregex.c
@@ -28,7 +28,6 @@ THE SOFTWARE.
#include <stc/cstr.h>
#include <stc/cregex.h> // header only
#include <setjmp.h>
-#include <ctype.h>
typedef uint32_t _Rune; /* Utf8 code point */
typedef int32_t _Token;
diff --git a/src/singleheader.py b/src/singleheader.py
index f5272cfb..2255568d 100644
--- a/src/singleheader.py
+++ b/src/singleheader.py
@@ -5,15 +5,15 @@ import sys
import os
from os.path import dirname, join as path_join, abspath, basename, exists
-extra_paths = [path_join(dirname(abspath(__file__)), "include")]
-
+top_dir = dirname(abspath(__file__))
+extra_paths = [path_join(top_dir, 'include'), path_join(top_dir, '..', 'include')]
def find_file(included_name, current_file):
current_dir = dirname(abspath(current_file))
for idir in [current_dir] + extra_paths:
try_path = path_join(idir, included_name)
if exists(try_path):
- return try_path
+ return abspath(try_path)
return None
diff --git a/src/utf8code.c b/src/utf8code.c
index a892f5fd..ecfdd24d 100644
--- a/src/utf8code.c
+++ b/src/utf8code.c
@@ -1,6 +1,5 @@
#ifndef UTF8_C_INCLUDED
#define UTF8_C_INCLUDED
-#include <ctype.h>
#include <stc/utf8.h> // header only
#include "utf8tabs.inc"