patch 9.1.0630: MS-Windows: build fails with VIMDLL and mzscheme

Commit: 
https://github.com/vim/vim/commit/f0ce176b5ff631cbc4d149e9f6ba03e78a9bf2a6
Author: Ken Takata <ken...@csc.jp>
Date:   Sat Jul 27 13:25:34 2024 +0200

    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 <ken...@csc.jp>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/Make_cyg_ming.mak b/src/Make_cyg_ming.mak
index f082c960d..7c324fb64 100644
--- a/src/Make_cyg_ming.mak
+++ b/src/Make_cyg_ming.mak
@@ -1006,7 +1006,7 @@ EXELFLAGS += -s
  endif
  ifeq ($(COVERAGE),yes)
 EXELFLAGS += --coverage
- else
+ else ifndef MZSCHEME
 EXELFLAGS += -nostdlib
 EXECFLAGS = -DUSE_OWNSTARTUP
  endif
@@ -1141,12 +1141,14 @@ $(EXEOBJC): | $(OUTDIR)
 
 ifeq ($(VIMDLL),yes)
  ifneq ($(COVERAGE),yes)
-  ifeq ($(ARCH),x86-64)
+  ifndef MZSCHEME
+   ifeq ($(ARCH),x86-64)
 EXEENTRYC = -Wl,--entry=wmainCRTStartup
 EXEENTRYG = -Wl,--entry=wWinMainCRTStartup
-  else ifeq ($(ARCH),i686)
+   else ifeq ($(ARCH),i686)
 EXEENTRYC = -Wl,--entry=_wmainCRTStartup
 EXEENTRYG = -Wl,--entry=_wWinMainCRTStartup@0
+   endif
   endif
  endif
 
diff --git a/src/Make_mvc.mak b/src/Make_mvc.mak
index c750311d2..3454a20fc 100644
--- a/src/Make_mvc.mak
+++ b/src/Make_mvc.mak
@@ -801,6 +801,13 @@ OBJ = $(OBJ) $(OUTDIR)\os_w32dll.obj $(OUTDIR) imd.res
 EXEOBJC = $(OUTDIR)\os_w32exec.obj $(OUTDIR) imc.res
 EXEOBJG = $(OUTDIR)\os_w32exeg.obj $(OUTDIR) img.res
 CFLAGS = $(CFLAGS) -DVIMDLL
+! ifdef MZSCHEME
+EXECFLAGS =
+EXELIBC = $(LIBC)
+! else
+EXECFLAGS = -DUSE_OWNSTARTUP /GS-
+EXELIBC =
+! endif
 !else
 OBJ = $(OBJ) $(OUTDIR)\os_w32exe.obj $(OUTDIR) im.res
 !endif
@@ -1302,11 +1309,11 @@ $(NETBEANS_OBJ) $(CHANNEL_OBJ) $(XPM_OBJ) $(OUTDIR) 
ersion.obj $(LINKARGS2)
 
 $(GVIM).exe: $(OUTDIR) $(EXEOBJG) $(VIMDLLBASE).dll
        $(LINK) $(LINKARGS1) /subsystem:$(SUBSYSTEM) -out:$(GVIM).exe \
-               $(EXEOBJG) $(VIMDLLBASE).lib
+               $(EXEOBJG) $(VIMDLLBASE).lib $(EXELIBC)
 
 $(VIM).exe: $(OUTDIR) $(EXEOBJC) $(VIMDLLBASE).dll
        $(LINK) $(LINKARGS1) /subsystem:$(SUBSYSTEM_CON) -out:$(VIM).exe \
-               $(EXEOBJC) $(VIMDLLBASE).lib
+               $(EXEOBJC) $(VIMDLLBASE).lib $(EXELIBC)
 
 !else
 
@@ -1380,12 +1387,16 @@ clean: testclean
        - if exist $(OUTDIR)/nul $(DEL_TREE) $(OUTDIR)
        - if exist *.obj del *.obj
        - if exist $(VIM).exe del $(VIM).exe
+       - if exist $(VIM).exp del $(VIM).exp
+       - if exist $(VIM).lib del $(VIM).lib
        - if exist $(VIM).ilk del $(VIM).ilk
        - if exist $(VIM).pdb del $(VIM).pdb
        - if exist $(VIM).map del $(VIM).map
        - if exist $(VIM).ncb del $(VIM).ncb
 !if "$(VIMDLL)" == "yes"
        - if exist $(GVIM).exe del $(GVIM).exe
+       - if exist $(GVIM).exp del $(GVIM).exp
+       - if exist $(GVIM).lib del $(GVIM).lib
        - if exist $(GVIM).map del $(GVIM).map
        - if exist $(VIMDLLBASE).dll del $(VIMDLLBASE).dll
        - if exist $(VIMDLLBASE).ilk del $(VIMDLLBASE).ilk
@@ -1715,10 +1726,10 @@ $(OUTDIR)/os_w32dll.obj:        $(OUTDIR) os_w32dll.c
 $(OUTDIR)/os_w32exe.obj:       $(OUTDIR) os_w32exe.c  $(INCL)
 
 $(OUTDIR)/os_w32exec.obj:      $(OUTDIR) os_w32exe.c  $(INCL)
-       $(CC) $(CFLAGS:-DFEAT_GUI_MSWIN=) /DUSE_OWNSTARTUP /GS- /Fo$@ 
os_w32exe.c
+       $(CC) $(CFLAGS:-DFEAT_GUI_MSWIN=) $(EXECFLAGS) /Fo$@ os_w32exe.c
 
 $(OUTDIR)/os_w32exeg.obj:      $(OUTDIR) os_w32exe.c  $(INCL)
-       $(CC) $(CFLAGS) /DUSE_OWNSTARTUP /GS- /Fo$@ os_w32exe.c
+       $(CC) $(CFLAGS) $(EXECFLAGS) /Fo$@ os_w32exe.c
 
 $(OUTDIR)/pathdef.obj: $(OUTDIR) $(PATHDEF_SRC) $(INCL)
        $(CC) $(CFLAGS_OUTDIR) $(PATHDEF_SRC)
diff --git a/src/if_mzsch.c b/src/if_mzsch.c
index 9a9c48732..4a8644c50 100644
--- a/src/if_mzsch.c
+++ b/src/if_mzsch.c
@@ -383,7 +383,7 @@ static void (*dll_scheme_set_config_path)(Scheme_Object *p);
 # 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 @@ mzscheme_end(void)
 #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 @@ mzscheme_main(void)
     }
 #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);
diff --git a/src/os_w32exe.c b/src/os_w32exe.c
index 85bbfbcd2..7aa4ead99 100644
--- a/src/os_w32exe.c
+++ b/src/os_w32exe.c
@@ -70,3 +70,24 @@ wmainCRTStartup(void)
 }
 # endif
 #endif // USE_OWNSTARTUP
+
+
+#if defined(VIMDLL) && defined(FEAT_MZSCHEME)
+
+# if defined(_MSC_VER)
+static __declspec(thread) void *tls_space;
+extern intptr_t _tls_index;
+# elif defined(__MINGW32__)
+static __thread void *tls_space;
+extern intptr_t _tls_index;
+# endif
+
+// Get TLS information that is needed for if_mzsch.
+    __declspec(dllexport) void
+get_tls_info(void ***ptls_space, intptr_t *ptls_index)
+{
+    *ptls_space = &tls_space;
+    *ptls_index = _tls_index;
+    return;
+}
+#endif
diff --git a/src/version.c b/src/version.c
index a7b5405e4..417e4003a 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    630,
 /**/
     629,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1sXfcs-00EK50-60%40256bit.org.

Raspunde prin e-mail lui