From f81a00fbdfc3f3b541c77044879e8511cea79ea8 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Tue, 5 Jul 2022 22:48:53 +0100 Subject: [PATCH] Remove safe_symbol_str --- src/cgen.c | 8 ++++---- src/rt/jit.c | 2 +- src/util.c | 12 ------------ src/util.h | 1 - test/test_misc.c | 3 ++- 5 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/cgen.c b/src/cgen.c index d29164dc..09592617 100644 --- a/src/cgen.c +++ b/src/cgen.c @@ -2264,8 +2264,8 @@ static void cgen_op_protected_init(int op, cgen_ctx_t *ctx) ident_t func = vcode_get_func(op); vcode_reg_t result = vcode_get_result(op); - char *resetfn LOCAL = xasprintf("%s_reset", istr(func)); - LOCAL_TEXT_BUF symbol = safe_symbol_str(resetfn); + LOCAL_TEXT_BUF symbol = safe_symbol(func); + tb_cat(symbol, "_reset"); LLVMValueRef fn = LLVMGetNamedFunction(module, tb_get(symbol)); if (fn == NULL) { @@ -3314,8 +3314,8 @@ static void cgen_op_package_init(int op, cgen_ctx_t *ctx) ident_t func = vcode_get_func(op); vcode_reg_t result = vcode_get_result(op); - char *resetfn LOCAL = xasprintf("%s_reset", istr(func)); - LOCAL_TEXT_BUF symbol = safe_symbol_str(resetfn); + LOCAL_TEXT_BUF symbol = safe_symbol(func); + tb_cat(symbol, "_reset"); LLVMValueRef context; if (vcode_count_args(op) > 0) diff --git a/src/rt/jit.c b/src/rt/jit.c index 2187443c..3faffa15 100644 --- a/src/rt/jit.c +++ b/src/rt/jit.c @@ -65,7 +65,7 @@ void *jit_find_symbol(const char *name, bool required) name++; // Remove leading underscore on 32-bit Windows #endif - LOCAL_TEXT_BUF tb = safe_symbol_str(name); + LOCAL_TEXT_BUF tb = safe_symbol(ident_new(name)); const char *symbol_name = tb_get(tb); #ifdef __MINGW32__ diff --git a/src/util.c b/src/util.c index f717f38f..d0a5d81d 100644 --- a/src/util.c +++ b/src/util.c @@ -1613,18 +1613,6 @@ text_buf_t *safe_symbol(ident_t id) #endif } -text_buf_t *safe_symbol_str(const char *text) -{ -#if defined _WIN32 || defined __CYGWIN__ - if (strpbrk(text, "()\"[]*+=") != NULL) - return safe_symbol_win32(text); -#endif - - text_buf_t *tb = tb_new(); - tb_cat(tb, text); - return tb; -} - text_buf_t *unsafe_symbol(const char *text) { // Restore original symbol from safe_symbol diff --git a/src/util.h b/src/util.h index 336d5424..ffb4b06c 100644 --- a/src/util.h +++ b/src/util.h @@ -181,7 +181,6 @@ void *mmap_guarded(size_t sz, guard_fault_fn_t fn, void *ctx); void run_program(const char *const *args, size_t n_args); text_buf_t *safe_symbol(ident_t id); -text_buf_t *safe_symbol_str(const char *text); text_buf_t *unsafe_symbol(const char *text); #define LOCAL_TEXT_BUF __attribute__((cleanup(_tb_cleanup))) text_buf_t * diff --git a/test/test_misc.c b/test/test_misc.c index cc8537de..6ea998c6 100644 --- a/test/test_misc.c +++ b/test/test_misc.c @@ -18,6 +18,7 @@ #include "test_util.h" #include "hash.h" #include "mask.h" +#include "ident.h" #include "rt/heap.h" #include @@ -226,7 +227,7 @@ END_TEST; START_TEST(test_safe_symbol) { const char *orig = "foo[]()+*\"=bar"; - LOCAL_TEXT_BUF enc = safe_symbol_str(orig); + LOCAL_TEXT_BUF enc = safe_symbol(ident_new(orig)); LOCAL_TEXT_BUF dec = unsafe_symbol(tb_get(enc)); ck_assert_str_eq(orig, tb_get(dec)); -- 2.39.2