Skip to content

Commit 77e08e5

Browse files
ser-vasilichsingaraiona
authored andcommitted
fix for symbols in read-csv
1 parent c4f5095 commit 77e08e5

4 files changed

Lines changed: 48 additions & 1 deletion

File tree

core/symbols.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ i64_t symbols_intern(lit_p str, i64_t len) {
147147
raw_p node = __atomic_load_n(&symbols->strings_node, __ATOMIC_ACQUIRE);
148148
i64_t rounds2 = 0;
149149

150-
while (slot_end > node) {
150+
while ((i64_t)node == NULL_I64 || slot_end > node) {
151151
if ((i64_t)node == NULL_I64) {
152152
backoff_spin(&rounds2);
153153
node = __atomic_load_n(&symbols->strings_node, __ATOMIC_ACQUIRE);

tests/lang.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5280,3 +5280,23 @@ test_result_t test_lang_safety() {
52805280

52815281
PASS();
52825282
}
5283+
5284+
// ==================== READ-CSV LARGE SYMBOLS ====================
5285+
test_result_t test_lang_read_csv() {
5286+
i64_t i;
5287+
FILE *f;
5288+
5289+
f = fopen("/tmp/rf_test_syms.csv", "w");
5290+
TEST_ASSERT(f != NULL, "failed to create temp CSV");
5291+
fprintf(f, "id,sym\n");
5292+
for (i = 0; i < 20000; i++)
5293+
fprintf(f, "%lld,s%lld\n", (long long)i, (long long)i);
5294+
fclose(f);
5295+
5296+
TEST_ASSERT_EQ(
5297+
"(count (read-csv [I64 SYMBOL] \"/tmp/rf_test_syms.csv\"))",
5298+
"20000");
5299+
5300+
remove("/tmp/rf_test_syms.csv");
5301+
PASS();
5302+
}

tests/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ test_entry_t tests[] = {
261261
{"test_lang_do_let", test_lang_do_let},
262262
{"test_lang_error", test_lang_error},
263263
{"test_lang_safety", test_lang_safety},
264+
{"test_lang_read_csv", test_lang_read_csv},
264265
// Parted table tests
265266
{"test_parted_load", test_parted_load},
266267
{"test_parted_select_where_date", test_parted_select_where_date},
@@ -455,6 +456,7 @@ test_entry_t tests[] = {
455456
{"test_string_list_ops", test_string_list_ops},
456457
{"test_string_where_in", test_string_where_in},
457458
{"test_string_combined", test_string_combined},
459+
{"test_symbols_intern_large", test_symbols_intern_large},
458460
// Vector operation tests
459461
{"test_vec_til", test_vec_til},
460462
{"test_vec_take", test_vec_take},

tests/string_ops.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,3 +432,28 @@ test_result_t test_string_combined() {
432432

433433
PASS();
434434
}
435+
436+
// ==================== SYMBOL INTERN LARGE ====================
437+
test_result_t test_symbols_intern_large() {
438+
symbols_p symbols = runtime_get()->symbols;
439+
i64_t i, id;
440+
char buf[32];
441+
442+
for (i = 0; i < 20000; i++) {
443+
i64_t len = snprintf(buf, sizeof(buf), "sym_%lld", (long long)i);
444+
id = symbols_intern(buf, len);
445+
TEST_ASSERT(id != NULL_I64, "symbols_intern returned NULL_I64");
446+
}
447+
448+
TEST_ASSERT(symbols_count(symbols) >= 20000, "expected >= 20000 symbols");
449+
450+
for (i = 0; i < 20000; i++) {
451+
i64_t len = snprintf(buf, sizeof(buf), "sym_%lld", (long long)i);
452+
id = symbols_intern(buf, len);
453+
str_p s = str_from_symbol(id);
454+
TEST_ASSERT(s != NULL, "str_from_symbol returned NULL");
455+
TEST_ASSERT(str_cmp(s, len, buf, len) == 0, "symbol string mismatch");
456+
}
457+
458+
PASS();
459+
}

0 commit comments

Comments
 (0)