在 2025-12-31 02:29, Pali Rohár 写道:
+}
+_Static_assert(__builtin_types_compatible_p(typeof(fallback_IsDBCSLeadByteEx), 
typeof(IsDBCSLeadByteEx)), "Functions fallback_IsDBCSLeadByteEx() and 
IsDBCSLeadByteEx() are compatible");

This is ling is so looong.

And why is there some times `typeof` but sometimes `__typeof`? Only `typeof` and `__typeof__` are documented [1]. As a matter of fact, `__typeof__` is supported by MSVC as well, so it definitely should be preferred.


[1] https://gcc.gnu.org/onlinedocs/gcc/Typeof.html


+
+int __cdecl __mingw_isleadbyte_cp(int c, unsigned int cp)
+{
+  static __typeof(IsDBCSLeadByteEx) *call_IsDBCSLeadByteEx = NULL;
+  if (!call_IsDBCSLeadByteEx) {
+    HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
+    __typeof(IsDBCSLeadByteEx) *kernel32_IsDBCSLeadByteEx = kernel32 ? 
(__typeof(IsDBCSLeadByteEx)*)GetProcAddress(kernel32, "IsDBCSLeadByteEx") : 
NULL;
+    (void)InterlockedExchangePointer((PVOID*)&call_IsDBCSLeadByteEx, 
kernel32_IsDBCSLeadByteEx ?: fallback_IsDBCSLeadByteEx);
+  }

These `? :` are over-complicated, and I don't like the GNU extension very much. Casting between function pointers requires an intermediate cast to `intptr_t` or `void*`, otherwise compilers will warn about it.

I have simplified this a little [2][3]:

    FARPROC farproc = NULL;
    HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
    if (kernel32)
      farproc = GetProcAddress(kernel32, "IsDBCSLeadByteEx");
    if (!farproc)
      farproc = (FARPROC)(PVOID)fallback_IsDBCSLeadByteEx;
    (void)InterlockedExchangePointer((PVOID*)&call_IsDBCSLeadByteEx, 
(PVOID)farproc);

Despite these issues, the changes are very simple and straight forward. If these changes pass the CI, I can push them tomorrow.

[2] 
https://github.com/lhmouse/mingw-w64/commit/a22c8e74f2ab108b18758aa2ae2a8334e999eca7
[3] 
https://github.com/lhmouse/mingw-w64/commit/cf3a23755035c82e4de4d620caf4f2882857d6d0


--
Best regards,
LIU Hao

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to