aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-03-28 15:31:53 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-03-28 15:31:53 -0400
commitca76fb335ae7b3f820beeeed5667950e7489711e (patch)
treee0ef48cce92aeeb92241ef98c65bf3af84c05ca4 /src/stdlib
parent4de0fee8f694503b453e04084caaab55f8670b6c (diff)
Add compiler guards for GCC directives
Diffstat (limited to 'src/stdlib')
-rw-r--r--src/stdlib/integers.h4
-rw-r--r--src/stdlib/nums.h8
-rw-r--r--src/stdlib/rng.c5
-rw-r--r--src/stdlib/rng.h5
-rw-r--r--src/stdlib/siphash.c4
-rw-r--r--src/stdlib/stdlib.c4
-rw-r--r--src/stdlib/structs.c4
-rw-r--r--src/stdlib/tables.c8
-rw-r--r--src/stdlib/text.c4
9 files changed, 46 insertions, 0 deletions
diff --git a/src/stdlib/integers.h b/src/stdlib/integers.h
index 356e791c..779bee1f 100644
--- a/src/stdlib/integers.h
+++ b/src/stdlib/integers.h
@@ -277,8 +277,10 @@ MACROLIKE PUREFUNC bool Int$is_negative(Int_t x) {
// Constructors/conversion functions:
// Int constructors:
+#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
+#endif
MACROLIKE PUREFUNC Int_t Int$from_num(double n, bool truncate) {
mpz_t result;
mpz_init_set_d(result, n);
@@ -425,6 +427,8 @@ MACROLIKE PUREFUNC Int8_t Int8$from_int16(Int16_t i16, bool truncate) {
fail("Integer is too big to fit in a 8-bit integer: ", i16);
return i8;
}
+#ifdef __GNUC__
#pragma GCC diagnostic pop
+#endif
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/src/stdlib/nums.h b/src/stdlib/nums.h
index 3f0cccc8..f3de9dc5 100644
--- a/src/stdlib/nums.h
+++ b/src/stdlib/nums.h
@@ -36,8 +36,10 @@ MACROLIKE CONSTFUNC double Num$clamped(double x, double low, double high) {
return (x <= low) ? low : (x >= high ? high : x);
}
MACROLIKE CONSTFUNC double Num$from_num32(Num32_t n) { return (double)n; }
+#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
+#endif
MACROLIKE CONSTFUNC double Num$from_int(Int_t i, bool truncate) {
if likely (i.small & 0x1) {
double ret = (double)(i.small >> 2);
@@ -55,7 +57,9 @@ MACROLIKE CONSTFUNC double Num$from_int(Int_t i, bool truncate) {
return ret;
}
}
+#ifdef __GNUC__
#pragma GCC diagnostic pop
+#endif
MACROLIKE CONSTFUNC double Num$from_int64(Int64_t i, bool truncate) {
double n = (double)i;
if unlikely (!truncate && (Int64_t)n != i)
@@ -88,8 +92,10 @@ MACROLIKE CONSTFUNC float Num32$clamped(float x, float low, float high) {
return (x <= low) ? low : (x >= high ? high : x);
}
MACROLIKE CONSTFUNC float Num32$from_num(Num_t n) { return (float)n; }
+#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
+#endif
MACROLIKE CONSTFUNC float Num32$from_int(Int_t i, bool truncate) {
if likely (i.small & 0x1) {
float ret = (float)(i.small >> 2);
@@ -107,7 +113,9 @@ MACROLIKE CONSTFUNC float Num32$from_int(Int_t i, bool truncate) {
return ret;
}
}
+#ifdef __GNUC__
#pragma GCC diagnostic pop
+#endif
MACROLIKE CONSTFUNC float Num32$from_int64(Int64_t i, bool truncate) {
float n = (float)i;
if unlikely (!truncate && (Int64_t)n != i)
diff --git a/src/stdlib/rng.c b/src/stdlib/rng.c
index 82dd65d2..0221fa6b 100644
--- a/src/stdlib/rng.c
+++ b/src/stdlib/rng.c
@@ -24,7 +24,12 @@ struct RNGState_t {
uint8_t random_bytes[1024];
};
+#ifdef __TINYC__
+// TinyCC doesn't implement _Thread_local
public _Thread_local RNG_t default_rng = (struct RNGState_t[1]){};
+#else
+public RNG_t default_rng = (struct RNGState_t[1]){};
+#endif
PUREFUNC static Text_t RNG$as_text(const void *rng, bool colorize, const TypeInfo_t*)
{
diff --git a/src/stdlib/rng.h b/src/stdlib/rng.h
index 5bc4794f..34f1ca03 100644
--- a/src/stdlib/rng.h
+++ b/src/stdlib/rng.h
@@ -26,6 +26,11 @@ Num_t RNG$num(RNG_t rng, Num_t min, Num_t max);
Num32_t RNG$num32(RNG_t rng, Num32_t min, Num32_t max);
extern const TypeInfo_t RNG$info;
+// TinyCC doesn't implement _Thread_local
+#ifdef __TINYC__
+extern RNG_t default_rng;
+#else
extern _Thread_local RNG_t default_rng;
+#endif
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/src/stdlib/siphash.c b/src/stdlib/siphash.c
index 44e8b6eb..274b3195 100644
--- a/src/stdlib/siphash.c
+++ b/src/stdlib/siphash.c
@@ -49,13 +49,17 @@ public uint64_t TOMO_HASH_KEY[2] = {23, 42}; // Randomized in tomo_init()
PUREFUNC public uint64_t siphash24(const uint8_t *src, size_t src_sz) {
siphash sh;
if ((uint64_t)src % __alignof__(uint64_t) == 0) {
+#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
+#endif
const uint64_t *in = (uint64_t*)src;
/* Find largest src_sz evenly divisible by 8 bytes. */
const ptrdiff_t src_sz_nearest_8bits = ((ptrdiff_t)src_sz >> 3) << 3;
const uint64_t *goal = (uint64_t*)(src + src_sz_nearest_8bits);
+#ifdef __GNUC__
#pragma GCC diagnostic pop
+#endif
siphashinit(&sh, src_sz);
src_sz -= (size_t)src_sz_nearest_8bits;
while (in < goal) {
diff --git a/src/stdlib/stdlib.c b/src/stdlib/stdlib.c
index 8e652aa5..fc79dd6b 100644
--- a/src/stdlib/stdlib.c
+++ b/src/stdlib/stdlib.c
@@ -231,8 +231,10 @@ static Table_t parse_table(const TypeInfo_t *table, int n, char *args[])
return Table$from_entries(entries, table);
}
+#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstack-protector"
+#endif
public void _tomo_parse_args(int argc, char *argv[], Text_t usage, Text_t help, int spec_len, cli_arg_t spec[spec_len])
{
bool populated_args[spec_len];
@@ -442,7 +444,9 @@ public void _tomo_parse_args(int argc, char *argv[], Text_t usage, Text_t help,
}
}
}
+#ifdef __GNUC__
#pragma GCC diagnostic pop
+#endif
static void print_stack_line(FILE *out, OptionalText_t fn_name, const char *filename, int64_t line_num)
{
diff --git a/src/stdlib/structs.c b/src/stdlib/structs.c
index ca88262c..53b0e0a4 100644
--- a/src/stdlib/structs.c
+++ b/src/stdlib/structs.c
@@ -14,8 +14,10 @@
#include "text.h"
#include "util.h"
+#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstack-protector"
+#endif
PUREFUNC public uint64_t Struct$hash(const void *obj, const TypeInfo_t *type)
{
if (type->StructInfo.num_fields == 0)
@@ -50,7 +52,9 @@ PUREFUNC public uint64_t Struct$hash(const void *obj, const TypeInfo_t *type)
}
return siphash24((void*)field_hashes, sizeof(field_hashes));
}
+#ifdef __GNUC__
#pragma GCC diagnostic pop
+#endif
PUREFUNC public uint64_t PackedData$hash(const void *obj, const TypeInfo_t *type)
{
diff --git a/src/stdlib/tables.c b/src/stdlib/tables.c
index da754847..dfa35236 100644
--- a/src/stdlib/tables.c
+++ b/src/stdlib/tables.c
@@ -215,8 +215,10 @@ static void hashmap_resize_buckets(Table_t *t, uint32_t new_capacity, const Type
}
// Return address of value
+#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstack-protector"
+#endif
public void *Table$reserve(Table_t *t, const void *key, const void *value, const TypeInfo_t *type)
{
assert(type->tag == TableInfo);
@@ -278,7 +280,9 @@ public void *Table$reserve(Table_t *t, const void *key, const void *value, const
Table$set_bucket(t, entry, entry_index, type);
return entry + value_offset(type);
}
+#ifdef __GNUC__
#pragma GCC diagnostic pop
+#endif
public void Table$set(Table_t *t, const void *key, const void *value, const TypeInfo_t *type)
{
@@ -768,8 +772,10 @@ public void Table$serialize(const void *obj, FILE *out, Table_t *pointers, const
Optional$serialize(&t->fallback, out, pointers, Optional$info(sizeof(void*), __alignof__(void*), Pointer$info("&", type)));
}
+#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstack-protector"
+#endif
public void Table$deserialize(FILE *in, void *outval, Array_t *pointers, const TypeInfo_t *type)
{
int64_t len;
@@ -788,6 +794,8 @@ public void Table$deserialize(FILE *in, void *outval, Array_t *pointers, const T
*(Table_t*)outval = t;
}
+#ifdef __GNUC__
#pragma GCC diagnostic pop
+#endif
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1
diff --git a/src/stdlib/text.c b/src/stdlib/text.c
index 254ed567..177a9130 100644
--- a/src/stdlib/text.c
+++ b/src/stdlib/text.c
@@ -134,8 +134,10 @@ static const TypeInfo_t GraphemeClusterInfo = {
},
};
+#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstack-protector"
+#endif
public int32_t get_synthetic_grapheme(const ucs4_t *codepoints, int64_t utf32_len)
{
ucs4_t length_prefixed[1+utf32_len];
@@ -224,7 +226,9 @@ public int32_t get_synthetic_grapheme(const ucs4_t *codepoints, int64_t utf32_le
last_grapheme = grapheme_id;
return grapheme_id;
}
+#ifdef __GNUC__
#pragma GCC diagnostic pop
+#endif
int text_visualize(FILE *stream, Text_t t, int depth)
{