From 937d799aa019610fe03f2a5526cfd8d96229cca6 Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Thu, 3 Apr 2025 13:58:26 +1100 Subject: [PATCH 1/5] win32: build without threads but still with implicit sys Discovered while trying to test #17601 since the build failed with: perllib.c(62): error C2039: 'cur_tid': is not a member of 'interp_intern' ...\perl\win32\win32.h(566): note: see declaration of 'interp_intern' perllib.c(68): error C2039: 'cur_tid': is not a member of 'interp_intern' ...\perl\win32\win32.h(566): note: see declaration of 'interp_intern' --- win32/perllib.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/win32/perllib.c b/win32/perllib.c index 1200a351bea9..a787e231ec56 100644 --- a/win32/perllib.c +++ b/win32/perllib.c @@ -51,6 +51,7 @@ xs_init(pTHX) void win32_checkTLS(PerlInterpreter *host_perl) { +#ifdef USE_ITHREADS /* GCurThdId() is lightweight, but b/c of the ctrl-c/signals sometimes firing in other random WinOS threads, that make the TIDs go out of sync. This isn't always an error, although high chance of a SEGV in the next @@ -67,6 +68,13 @@ win32_checkTLS(PerlInterpreter *host_perl) } host_perl->Isys_intern.cur_tid = tid; } +#else + dTHX; + if (host_perl != my_perl) { + int *nowhere = NULL; + abort(); + } +#endif } EXTERN_C void From 8d33f0f797698ffae210a9716b81fb2e9588d031 Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Mon, 7 Apr 2025 13:11:07 +1000 Subject: [PATCH 2/5] perldelta for Win32 -Dusethreads builds fix --- pod/perldelta.pod | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pod/perldelta.pod b/pod/perldelta.pod index baf1d278054a..875de427f34c 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -330,9 +330,10 @@ L section. =over 4 -=item XXX-some-platform +=item Win32 -XXX +Fix builds with C defined but C not +defined. =back From 29a96c3aff3c3512692deb0950e3fd7526cd2037 Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Tue, 8 Apr 2025 09:49:23 +1000 Subject: [PATCH 3/5] win32_checkTLS: eliminate no longer used variable This was used rather questionably to crash perl, stopping in the debugger if there is one, but that was removed in 7bd379e8. --- win32/perllib.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/win32/perllib.c b/win32/perllib.c index a787e231ec56..c85016a08c54 100644 --- a/win32/perllib.c +++ b/win32/perllib.c @@ -63,7 +63,6 @@ win32_checkTLS(PerlInterpreter *host_perl) if(tid != host_perl->Isys_intern.cur_tid) { dTHX; /* heavyweight */ if (host_perl != my_perl) { - int *nowhere = NULL; abort(); } host_perl->Isys_intern.cur_tid = tid; @@ -71,7 +70,6 @@ win32_checkTLS(PerlInterpreter *host_perl) #else dTHX; if (host_perl != my_perl) { - int *nowhere = NULL; abort(); } #endif From 8ecfcfb2b1073865a1980871c9595be7ae1f4963 Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Wed, 9 Apr 2025 09:19:05 +1000 Subject: [PATCH 4/5] win32_checkTLS: add a panic message and break into the debugger if there is one. Previously this would exit silently and mysteriously, and unlike POSIX-likes abort() doesn't generally break into the debugger on Win32. --- win32/perllib.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/win32/perllib.c b/win32/perllib.c index c85016a08c54..cb20c0a3f2c2 100644 --- a/win32/perllib.c +++ b/win32/perllib.c @@ -48,6 +48,13 @@ xs_init(pTHX) #include "perlhost.h" +#define PANIC_THREAD_ID_MSG "panic: thread id mismatch\n" + +#define panic_thread_id() \ + (void)WriteFile(GetStdHandle(STD_ERROR_HANDLE), \ + PANIC_THREAD_ID_MSG, sizeof(PANIC_THREAD_ID_MSG)-1, \ + NULL, NULL) + void win32_checkTLS(PerlInterpreter *host_perl) { @@ -63,6 +70,8 @@ win32_checkTLS(PerlInterpreter *host_perl) if(tid != host_perl->Isys_intern.cur_tid) { dTHX; /* heavyweight */ if (host_perl != my_perl) { + panic_thread_id(); + DebugBreak(); abort(); } host_perl->Isys_intern.cur_tid = tid; @@ -70,6 +79,8 @@ win32_checkTLS(PerlInterpreter *host_perl) #else dTHX; if (host_perl != my_perl) { + panic_thread_id(); + DebugBreak(); abort(); } #endif From 3ff321eb48d6a3d15a9fdc90df33bc77ff71cdea Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Wed, 9 Apr 2025 15:21:20 +1000 Subject: [PATCH 5/5] win32_checkTLS(): nothing to do without at least multiplicity --- win32/perllib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/win32/perllib.c b/win32/perllib.c index cb20c0a3f2c2..efae2d817b8d 100644 --- a/win32/perllib.c +++ b/win32/perllib.c @@ -76,7 +76,7 @@ win32_checkTLS(PerlInterpreter *host_perl) } host_perl->Isys_intern.cur_tid = tid; } -#else +#elif defined(PERL_MULTIPLICITY) dTHX; if (host_perl != my_perl) { panic_thread_id();