From 491440e2b86410d7041cf7e8d658907d7e54fac8 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Thu, 16 Sep 2021 11:09:11 -0400 Subject: [PATCH] export `jl_setjmp` on windows (#42267) fix #42245 --- cli/jl_exports.h | 12 ++++++++++++ cli/list_strip_symbols.h | 3 +++ cli/trampolines/common.h | 2 ++ cli/trampolines/trampolines_aarch64.S | 3 +++ cli/trampolines/trampolines_arm.S | 3 +++ cli/trampolines/trampolines_i686.S | 3 +++ cli/trampolines/trampolines_x86_64.S | 3 +++ src/jl_exported_funcs.inc | 2 ++ src/julia.h | 4 ++-- test/embedding/embedding-test.jl | 4 ++-- test/embedding/embedding.c | 7 +++++++ 11 files changed, 42 insertions(+), 4 deletions(-) diff --git a/cli/jl_exports.h b/cli/jl_exports.h index 35d2767726865a..709cab4cde42e2 100644 --- a/cli/jl_exports.h +++ b/cli/jl_exports.h @@ -19,17 +19,26 @@ JL_EXPORTED_DATA_SYMBOLS(XX) #define XX(name) JL_DLLEXPORT void name(void); typedef void (anonfunc)(void); JL_EXPORTED_FUNCS(XX) +#ifdef _OS_WINDOWS_ +JL_EXPORTED_FUNCS_WIN(XX) +#endif #undef XX // Define holder locations for function addresses as `const void * $(name)_addr = & $(name);` #define XX(name) JL_HIDDEN anonfunc * name##_addr = (anonfunc*)&name; JL_EXPORTED_FUNCS(XX) +#ifdef _OS_WINDOWS_ +JL_EXPORTED_FUNCS_WIN(XX) +#endif #undef XX // Generate lists of function names and addresses #define XX(name) #name, static const char *const jl_exported_func_names[] = { JL_EXPORTED_FUNCS(XX) +#ifdef _OS_WINDOWS_ + JL_EXPORTED_FUNCS_WIN(XX) +#endif NULL }; #undef XX @@ -37,6 +46,9 @@ static const char *const jl_exported_func_names[] = { #define XX(name) &name##_addr, static anonfunc **const jl_exported_func_addrs[] = { JL_EXPORTED_FUNCS(XX) +#ifdef _OS_WINDOWS_ + JL_EXPORTED_FUNCS_WIN(XX) +#endif NULL }; #undef XX diff --git a/cli/list_strip_symbols.h b/cli/list_strip_symbols.h index e1a96261fe05ac..0ea0f7ac9f6ac6 100644 --- a/cli/list_strip_symbols.h +++ b/cli/list_strip_symbols.h @@ -4,4 +4,7 @@ #include "trampolines/common.h" #define XX(x) --strip-symbol=CNAME(x) JL_EXPORTED_FUNCS(XX) +#ifdef _OS_WINDOWS_ +JL_EXPORTED_FUNCS_WIN(XX) +#endif #undef XX diff --git a/cli/trampolines/common.h b/cli/trampolines/common.h index 06d7b9e236971d..51f51a1bf7ab86 100644 --- a/cli/trampolines/common.h +++ b/cli/trampolines/common.h @@ -1,3 +1,5 @@ +#include "../../src/support/platform.h" + // Preprocessor annoyances #define CONCAT_(x,y) x##y #define CONCAT(x,y) CONCAT_(x, y) diff --git a/cli/trampolines/trampolines_aarch64.S b/cli/trampolines/trampolines_aarch64.S index bffeab76c17636..0baac5a367aa5a 100644 --- a/cli/trampolines/trampolines_aarch64.S +++ b/cli/trampolines/trampolines_aarch64.S @@ -12,4 +12,7 @@ CNAME(name)##: SEP \ .cfi_endproc SEP \ JL_EXPORTED_FUNCS(XX) +#ifdef _OS_WINDOWS_ +JL_EXPORTED_FUNCS_WIN(XX) +#endif #undef XX diff --git a/cli/trampolines/trampolines_arm.S b/cli/trampolines/trampolines_arm.S index f99b7820360b24..c35ca16660fb11 100644 --- a/cli/trampolines/trampolines_arm.S +++ b/cli/trampolines/trampolines_arm.S @@ -15,4 +15,7 @@ CONCAT(.L,CNAMEADDR(name))##: ; \ .cfi_endproc; \ JL_EXPORTED_FUNCS(XX) +#ifdef _OS_WINDOWS_ +JL_EXPORTED_FUNCS_WIN(XX) +#endif #undef XX diff --git a/cli/trampolines/trampolines_i686.S b/cli/trampolines/trampolines_i686.S index f27949afa47b8c..6bb52ec81cf242 100644 --- a/cli/trampolines/trampolines_i686.S +++ b/cli/trampolines/trampolines_i686.S @@ -13,4 +13,7 @@ CNAME(name)##:; \ EXPORT(name); \ JL_EXPORTED_FUNCS(XX) +#ifdef _OS_WINDOWS_ +JL_EXPORTED_FUNCS_WIN(XX) +#endif #undef XX diff --git a/cli/trampolines/trampolines_x86_64.S b/cli/trampolines/trampolines_x86_64.S index e06434cf540e50..f0c80e3cffb451 100644 --- a/cli/trampolines/trampolines_x86_64.S +++ b/cli/trampolines/trampolines_x86_64.S @@ -17,4 +17,7 @@ SEH_END(); \ EXPORT(name); \ JL_EXPORTED_FUNCS(XX) +#ifdef _OS_WINDOWS_ +JL_EXPORTED_FUNCS_WIN(XX) +#endif #undef XX diff --git a/src/jl_exported_funcs.inc b/src/jl_exported_funcs.inc index 877c603c7ac3ed..ba11436e51eaa9 100644 --- a/src/jl_exported_funcs.inc +++ b/src/jl_exported_funcs.inc @@ -552,3 +552,5 @@ XX(jl_wakeup_thread) \ XX(jl_yield) \ +#define JL_EXPORTED_FUNCS_WIN(XX) \ + XX(jl_setjmp) diff --git a/src/julia.h b/src/julia.h index dcc5b3510b9086..3d5f92dbfd51ef 100644 --- a/src/julia.h +++ b/src/julia.h @@ -1879,10 +1879,10 @@ JL_DLLEXPORT void jl_restore_excstack(size_t state) JL_NOTSAFEPOINT; #if defined(_OS_WINDOWS_) #if defined(_COMPILER_GCC_) -int __attribute__ ((__nothrow__,__returns_twice__)) (jl_setjmp)(jmp_buf _Buf); +JL_DLLEXPORT int __attribute__ ((__nothrow__,__returns_twice__)) (jl_setjmp)(jmp_buf _Buf); __declspec(noreturn) __attribute__ ((__nothrow__)) void (jl_longjmp)(jmp_buf _Buf, int _Value); #else -int (jl_setjmp)(jmp_buf _Buf); +JL_DLLEXPORT int (jl_setjmp)(jmp_buf _Buf); void (jl_longjmp)(jmp_buf _Buf, int _Value); #endif #define jl_setjmp_f jl_setjmp diff --git a/test/embedding/embedding-test.jl b/test/embedding/embedding-test.jl index f358ff2a74cdf6..797f6dabd9a89f 100644 --- a/test/embedding/embedding-test.jl +++ b/test/embedding/embedding-test.jl @@ -20,8 +20,7 @@ end close(out.in) close(err.in) out_task = @async readlines(out) - err = read(err, String) - @test err == "MethodError: no method matching this_function_has_no_methods()\n" + @test readline(err) == "MethodError: no method matching this_function_has_no_methods()" @test success(p) lines = fetch(out_task) @test length(lines) == 10 @@ -29,4 +28,5 @@ end @test lines[8] == "called bar" @test lines[9] == "calling new bar" @test lines[10] == " From worker 2:\tTaking over the world..." + @test readline(err) == "exception caught from C" end diff --git a/test/embedding/embedding.c b/test/embedding/embedding.c index d1816947f38568..659ddde3f72dfa 100644 --- a/test/embedding/embedding.c +++ b/test/embedding/embedding.c @@ -175,6 +175,13 @@ int main() checked_eval_string("f28825()"); } + JL_TRY { + jl_error("exception thrown"); + } + JL_CATCH { + jl_printf(jl_stderr_stream(), "exception caught from C\n"); + } + int ret = 0; jl_atexit_hook(ret); return ret;