From c7438ca109057fa1de131382182d5e460d0e44f9 Mon Sep 17 00:00:00 2001 From: hanez Date: Mon, 27 Apr 2026 02:22:31 +0200 Subject: [PATCH] Fixed bug to make trhreading work again on alpine linux. (0.41.1) --- CMakeLists.txt | 2 +- src/vm.c | 8 ++++++-- src/vm/os/thread_common.c | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 43b39d0..3a9482a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.10) -project(fun VERSION 0.41.0 LANGUAGES C) +project(fun VERSION 0.41.1 LANGUAGES C) set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD_REQUIRED ON) diff --git a/src/vm.c b/src/vm.c index bb69443..ee3b568 100644 --- a/src/vm.c +++ b/src/vm.c @@ -79,7 +79,11 @@ extern int map_expanded_line_to_include_path(const char *path, int line, char *o #include "vm/os/thread_common.c" /* Track the currently running VM to annotate error messages */ -static VM *g_active_vm = NULL; +#ifdef _WIN32 +static __declspec(thread) VM *g_active_vm = NULL; +#else +static __thread VM *g_active_vm = NULL; +#endif /* fprintf wrapper that appends source line info for stderr messages */ static int fun_vm_vfprintf(FILE *stream, const char *fmt, va_list ap) { @@ -166,7 +170,7 @@ static int fun_vm_fprintf(FILE *stream, const char *fmt, ...) { /* Intercept exit() in this translation unit so VM errors don't terminate the process outright */ #include -static jmp_buf g_vm_err_jmp; +static __thread jmp_buf g_vm_err_jmp; static void fun_vm_exit(int code) { if (g_active_vm && g_active_vm->repl_on_error) { diff --git a/src/vm/os/thread_common.c b/src/vm/os/thread_common.c index 87019bd..7f4b780 100644 --- a/src/vm/os/thread_common.c +++ b/src/vm/os/thread_common.c @@ -96,7 +96,8 @@ static fun_thread_ret_t fun_thread_main(void *param) /* Build wrapper: LOAD_CONST ; LOAD_CONST ...; CALL argc; HALT */ Bytecode *wrap = bytecode_new(); - int cFn = bytecode_add_constant(wrap, copy_value(&(Value){.type = VAL_FUNCTION, .fn = task->fn})); + /* Use make_function constructor which correctly handles the pointer */ + int cFn = bytecode_add_constant(wrap, make_function(task->fn)); bytecode_add_instruction(wrap, OP_LOAD_CONST, cFn); for (int i = 0; i < task->argc; ++i) { int cArg = bytecode_add_constant(wrap, deep_copy_value(&task->args[i]));