aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-03-21 15:37:51 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-03-21 15:37:51 -0400
commit0b76011a45b421b1473e9be75e538d3ceadf1140 (patch)
tree5738f89e0fb55235e0a3fda861db1a2dde2bd063
parent013995b146a5984a7bd053ad33aae88d42838868 (diff)
Remove some less-supported code features like static initializers for
variable-sized arrays
-rw-r--r--parse.c2
-rw-r--r--repl.c6
-rw-r--r--stdlib/arrays.c2
-rw-r--r--stdlib/patterns.c10
-rw-r--r--stdlib/stdlib.c6
-rw-r--r--stdlib/structs.c2
-rw-r--r--stdlib/text.c9
-rw-r--r--stdlib/threads.c2
8 files changed, 25 insertions, 14 deletions
diff --git a/parse.c b/parse.c
index 93876cfd..325131e5 100644
--- a/parse.c
+++ b/parse.c
@@ -207,7 +207,7 @@ static const char *unescape(parse_ctx_t *ctx, const char **out) {
size_t len = strcspn(&escape[2], "\r\n}");
if (escape[2+len] != '}')
parser_err(ctx, escape, escape + 2 + len, "Missing closing '}'");
- char name[len+1] = {};
+ char name[len+1];
memcpy(name, &escape[2], len);
name[len] = '\0';
uint32_t codepoint = unicode_name_character(name);
diff --git a/repl.c b/repl.c
index 25242f5a..39fe30fa 100644
--- a/repl.c
+++ b/repl.c
@@ -504,7 +504,7 @@ void eval(env_t *env, ast_t *ast, void *dest)
assert(t->tag == ArrayType);
Array_t arr = {};
size_t item_size = type_size(Match(t, ArrayType)->item_type);
- char item_buf[item_size] = {};
+ char item_buf[item_size];
for (ast_list_t *item = Match(ast, Array)->items; item; item = item->next) {
eval(env, item->ast, item_buf);
Array$insert(&arr, item_buf, I(0), (int64_t)type_size(Match(t, ArrayType)->item_type));
@@ -518,8 +518,8 @@ void eval(env_t *env, ast_t *ast, void *dest)
Table_t table = {};
size_t key_size = type_size(Match(t, TableType)->key_type);
size_t value_size = type_size(Match(t, TableType)->value_type);
- char key_buf[key_size] = {};
- char value_buf[value_size] = {};
+ char key_buf[key_size];
+ char value_buf[value_size];
const TypeInfo_t *table_info = type_to_type_info(t);
assert(table_info->tag == TableInfo);
for (ast_list_t *entry = table_ast->entries; entry; entry = entry->next) {
diff --git a/stdlib/arrays.c b/stdlib/arrays.c
index 41d46741..cd403c5f 100644
--- a/stdlib/arrays.c
+++ b/stdlib/arrays.c
@@ -348,7 +348,7 @@ public Array_t Array$sample(Array_t arr, Int_t int_n, Array_t weights, RNG_t rng
struct {
int64_t alias;
double odds;
- } aliases[arr.length] = {};
+ } aliases[arr.length];
for (int64_t i = 0; i < arr.length; i++) {
double weight = i >= weights.length ? 0.0 : *(double*)(weights.data + weights.stride*i);
diff --git a/stdlib/patterns.c b/stdlib/patterns.c
index 7a165836..7f7d711b 100644
--- a/stdlib/patterns.c
+++ b/stdlib/patterns.c
@@ -1267,10 +1267,18 @@ public const TypeInfo_t Pattern$info = {
.metamethods=Text$metamethods,
};
+static const TypeInfo_t _text_array = {
+ .size=sizeof(Array_t),
+ .align=__alignof__(Array_t),
+ .tag=ArrayInfo,
+ .ArrayInfo.item=&Text$info,
+ .metamethods=Array$metamethods,
+};
+
static NamedType_t _match_fields[3] = {
{"text", &Text$info},
{"index", &Int$info},
- {"captures", Array$info(&Text$info)},
+ {"captures", &_text_array},
};
static bool Match$is_none(const void *m, const TypeInfo_t*)
diff --git a/stdlib/stdlib.c b/stdlib/stdlib.c
index 9b117a24..9103e4dd 100644
--- a/stdlib/stdlib.c
+++ b/stdlib/stdlib.c
@@ -224,8 +224,10 @@ static Table_t parse_table(const TypeInfo_t *table, int n, char *args[])
#pragma GCC diagnostic ignored "-Wstack-protector"
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] = {};
- bool used_args[argc] = {};
+ bool populated_args[spec_len];
+ bool used_args[argc];
+ memset(populated_args, 0, sizeof(populated_args));
+ memset(used_args, 0, sizeof(used_args));
for (int i = 1; i < argc; ) {
if (argv[i][0] == '-' && argv[i][1] == '-') {
if (argv[i][2] == '\0') { // "--" signals the rest of the arguments are literal
diff --git a/stdlib/structs.c b/stdlib/structs.c
index 0b1385ee..ca88262c 100644
--- a/stdlib/structs.c
+++ b/stdlib/structs.c
@@ -24,7 +24,7 @@ PUREFUNC public uint64_t Struct$hash(const void *obj, const TypeInfo_t *type)
if (type->StructInfo.num_fields == 1)
return generic_hash(obj, type->StructInfo.fields[0].type);
- uint64_t field_hashes[type->StructInfo.num_fields] = {};
+ uint64_t field_hashes[type->StructInfo.num_fields];
ptrdiff_t byte_offset = 0;
ptrdiff_t bit_offset = 0;
for (int i = 0; i < type->StructInfo.num_fields; i++) {
diff --git a/stdlib/text.c b/stdlib/text.c
index 9abab57b..966f6ac3 100644
--- a/stdlib/text.c
+++ b/stdlib/text.c
@@ -138,7 +138,7 @@ static const TypeInfo_t GraphemeClusterInfo = {
#pragma GCC diagnostic ignored "-Wstack-protector"
public int32_t get_synthetic_grapheme(const ucs4_t *codepoints, int64_t utf32_len)
{
- ucs4_t length_prefixed[1+utf32_len] = {};
+ ucs4_t length_prefixed[1+utf32_len];
length_prefixed[0] = (ucs4_t)utf32_len;
for (int i = 0; i < utf32_len; i++)
length_prefixed[i+1] = codepoints[i];
@@ -330,7 +330,8 @@ static void insert_balanced_recursive(Text_t balanced_texts[MAX_TEXT_DEPTH], Tex
static Text_t rebalanced(Text_t a, Text_t b)
{
- Text_t balanced_texts[MAX_TEXT_DEPTH] = {};
+ Text_t balanced_texts[MAX_TEXT_DEPTH];
+ memset(balanced_texts, 0, sizeof(balanced_texts));
insert_balanced_recursive(balanced_texts, a);
insert_balanced_recursive(balanced_texts, b);
@@ -436,7 +437,7 @@ static Text_t concat2(Text_t a, Text_t b)
size_t len = (last_a >= 0) ? 1 : NUM_GRAPHEME_CODEPOINTS(last_a);
len += (first_b >= 0) ? 1 : NUM_GRAPHEME_CODEPOINTS(first_b);
- ucs4_t codepoints[len] = {};
+ ucs4_t codepoints[len];
ucs4_t *dest = codepoints;
if (last_a < 0)
dest = mempcpy(dest, GRAPHEME_CODEPOINTS(last_a), sizeof(ucs4_t[NUM_GRAPHEME_CODEPOINTS(last_a)]));
@@ -451,7 +452,7 @@ static Text_t concat2(Text_t a, Text_t b)
// Do a normalization run for these two codepoints and see if it looks different.
// Normalization should not exceed 3x in the input length (but if it does, it will be
// handled gracefully)
- ucs4_t norm_buf[3*len] = {};
+ ucs4_t norm_buf[3*len];
size_t norm_length = sizeof(norm_buf)/sizeof(norm_buf[0]);
ucs4_t *normalized = u32_normalize(UNINORM_NFC, codepoints, len, norm_buf, &norm_length);
bool stable = (norm_length == len && memcmp(codepoints, normalized, sizeof(codepoints)) == 0);
diff --git a/stdlib/threads.c b/stdlib/threads.c
index efd23546..9ad68c81 100644
--- a/stdlib/threads.c
+++ b/stdlib/threads.c
@@ -33,7 +33,7 @@ static void *run_thread(Closure_t *closure)
public Thread_t Thread$new(Closure_t fn)
{
- Thread_t thread = new(pthread_t);
+ Thread_t thread = GC_MALLOC(sizeof(pthread_t));
Closure_t *closure = new(Closure_t, .fn=fn.fn, .userdata=fn.userdata);
pthread_create(thread, NULL, (void*)run_thread, closure);
return thread;