patch 9.1.0630: MS-Windows: build fails with VIMDLL and mzscheme
Problem: MS-Windows: build fails with VIMDLL and mzscheme
Solution: define scheme_register_tls_space() inside gvim.exe
and refer to it from the dll (Ken Takata).
`scheme_register_tls_space()` doesn't support a thread-local variable in
a DLL:
https://docs.racket-lang.org/inside/im_memoryalloc.html#%28cpp._scheme_register_tls_space%29
closes: #15363
Signed-off-by: Ken Takata <kentkt@csc.jp>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/if_mzsch.c b/src/if_mzsch.c
index 9a9c487..4a8644c 100644
--- a/src/if_mzsch.c
+++ b/src/if_mzsch.c
@@ -383,7 +383,7 @@
# define scheme_null dll_scheme_null
# define scheme_true dll_scheme_true
-// pointers are GetProceAddress'ed as pointers to pointer
+// pointers are GetProcAddress'ed as pointers to pointer
#if !defined(USE_THREAD_LOCAL) && !defined(LINK_EXTENSIONS_BY_TABLE)
# define scheme_current_thread (*dll_scheme_current_thread_ptr)
# endif
@@ -924,7 +924,7 @@
#endif
}
-#if HAVE_TLS_SPACE
+#if HAVE_TLS_SPACE && !defined(VIMDLL)
# if defined(_MSC_VER)
static __declspec(thread) void *tls_space;
extern intptr_t _tls_index;
@@ -960,7 +960,24 @@
}
#endif
#ifdef HAVE_TLS_SPACE
+# ifdef VIMDLL
+ void **ptls_space;
+ intptr_t tls_index;
+ void (*pget_tls_info)(void ***ptls_space, intptr_t *ptls_index);
+
+ // Get the address of get_tls_info() from (g)vim.exe.
+ pget_tls_info = (void *)GetProcAddress(
+ GetModuleHandle(NULL), "get_tls_info");
+ if (pget_tls_info == NULL)
+ {
+ disabled = TRUE;
+ return vim_main2();
+ }
+ pget_tls_info(&ptls_space, &tls_index);
+ scheme_register_tls_space(ptls_space, tls_index);
+# else
scheme_register_tls_space(&tls_space, _tls_index);
+# endif
#endif
#ifdef TRAMPOLINED_MZVIM_STARTUP
return scheme_main_setup(TRUE, mzscheme_env_main, argc, &argv);