1
0
Fork 0
forked from fun/fun

Fixed bug to make threading work again on alpine linux. (0.41.2)

This commit is contained in:
Johannes Findeisen 2026-04-27 02:29:03 +02:00
commit 40999fe7db
2 changed files with 20 additions and 6 deletions

View file

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
project(fun VERSION 0.41.1 LANGUAGES C) project(fun VERSION 0.41.2 LANGUAGES C)
set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_STANDARD_REQUIRED ON)

View file

@ -91,8 +91,20 @@ static fun_thread_ret_t fun_thread_main(void *param)
#endif #endif
{ {
FunTask *task = (FunTask *)param; FunTask *task = (FunTask *)param;
VM tvm; VM *tvm = (VM *)malloc(sizeof(VM));
vm_init(&tvm); if (!tvm) {
fprintf(stderr, "Runtime error: failed to allocate thread VM\n");
/* Minimal cleanup of task before exiting thread */
for (int i = 0; i < task->argc; ++i) free_value(task->args[i]);
free(task->args);
free(task);
#ifdef _WIN32
return 0;
#else
return NULL;
#endif
}
vm_init(tvm);
/* Build wrapper: LOAD_CONST <fn>; LOAD_CONST <arg0> ...; CALL argc; HALT */ /* Build wrapper: LOAD_CONST <fn>; LOAD_CONST <arg0> ...; CALL argc; HALT */
Bytecode *wrap = bytecode_new(); Bytecode *wrap = bytecode_new();
@ -106,12 +118,12 @@ static fun_thread_ret_t fun_thread_main(void *param)
bytecode_add_instruction(wrap, OP_CALL, task->argc); bytecode_add_instruction(wrap, OP_CALL, task->argc);
bytecode_add_instruction(wrap, OP_HALT, 0); bytecode_add_instruction(wrap, OP_HALT, 0);
vm_run(&tvm, wrap); vm_run(tvm, wrap);
/* Take the top of stack as result if present, else Nil */ /* Take the top of stack as result if present, else Nil */
Value res = make_nil(); Value res = make_nil();
if (tvm.sp >= 0) { if (tvm->sp >= 0) {
res = deep_copy_value(&tvm.stack[tvm.sp]); res = deep_copy_value(&tvm->stack[tvm->sp]);
} }
/* cleanup */ /* cleanup */
@ -120,6 +132,8 @@ static fun_thread_ret_t fun_thread_main(void *param)
} }
free(task->args); free(task->args);
bytecode_free(wrap); bytecode_free(wrap);
vm_reset(tvm);
free(tvm);
/* store result */ /* store result */
fun_lock(); fun_lock();