diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-06 15:39:00 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-06 15:39:00 -0400 |
| commit | 594d1a627f2d731d915bacc507174347594aa7bd (patch) | |
| tree | c6dbf724bd6d1718cc572b418bcfcdb28028faf8 | |
| parent | 9581231408ceb1e8c275217023ec1c17b3a14924 (diff) | |
Fix some C string and path resolving issues
| -rw-r--r-- | builtins/functions.c | 1 | ||||
| -rw-r--r-- | builtins/text.c | 4 | ||||
| -rw-r--r-- | builtins/text.h | 2 | ||||
| -rw-r--r-- | environment.c | 2 |
4 files changed, 5 insertions, 4 deletions
diff --git a/builtins/functions.c b/builtins/functions.c index 22347afb..bfa9465f 100644 --- a/builtins/functions.c +++ b/builtins/functions.c @@ -65,6 +65,7 @@ void print_stack_trace(FILE *out, int start, int stop) public void fail(const char *fmt, ...) { + fflush(stdout); if (USE_COLOR) fputs("\x1b[31;7m ==================== ERROR ==================== \n\n\x1b[0;1m", stderr); else fputs("==================== ERROR ====================\n\n", stderr); va_list args; diff --git a/builtins/text.c b/builtins/text.c index 0b3187f0..4cb7c7e9 100644 --- a/builtins/text.c +++ b/builtins/text.c @@ -648,7 +648,7 @@ public Text_t Text$from_strn(const char *str, size_t len) public Text_t Text$from_str(const char *str) { - return Text$from_strn(str, strlen(str)); + return str ? Text$from_strn(str, strlen(str)) : Text(""); } static void u8_buf_append(Text_t text, char **buf, int64_t *capacity, int64_t *i) @@ -706,7 +706,7 @@ static void u8_buf_append(Text_t text, char **buf, int64_t *capacity, int64_t *i } } -public const char *Text$as_c_string(Text_t text) +public char *Text$as_c_string(Text_t text) { int64_t capacity = text.length + 1; char *buf = GC_MALLOC_ATOMIC(capacity); diff --git a/builtins/text.h b/builtins/text.h index cb8f08ba..56473e3a 100644 --- a/builtins/text.h +++ b/builtins/text.h @@ -41,7 +41,7 @@ Int_t Text$find(Text_t text, Pattern_t pattern, Int_t i, int64_t *match_length); Array_t Text$find_all(Text_t text, Pattern_t pattern); bool Text$has(Text_t text, Pattern_t pattern); bool Text$matches(Text_t text, Pattern_t pattern); -const char *Text$as_c_string(Text_t text); +char *Text$as_c_string(Text_t text); public Text_t Text$format(const char *fmt, ...); Array_t Text$clusters(Text_t text); Array_t Text$utf32_codepoints(Text_t text); diff --git a/environment.c b/environment.c index 0c37b266..11304d2b 100644 --- a/environment.c +++ b/environment.c @@ -251,7 +251,7 @@ env_t *new_compilation_unit(CORD *libname) {"Text", TEXT_TYPE, "Text_t", "Text$info", TypedArray(ns_entry_t, {"find", "Text$find", "func(text:Text, pattern:Pattern, start=1, length=!&Int64)->Int"}, {"find_all", "Text$find_all", "func(text:Text, pattern:Pattern)->[Text]"}, - {"as_c_string", "CORD_to_char_star", "func(text:Text)->CString"}, + {"as_c_string", "Text$as_c_string", "func(text:Text)->CString"}, {"codepoint_names", "Text$codepoint_names", "func(text:Text)->[Text]"}, {"from_bytes", "Text$from_bytes", "func(bytes:[Int8])->Text"}, {"from_c_string", "Text$from_str", "func(str:CString)->Text"}, |
