gettext: Don't export DllMain symbol

This commit is contained in:
مهدي شينون (Mehdi Chinoune) 2025-10-04 05:53:06 +01:00
parent ff94880fd7
commit 3756eb5ceb
3 changed files with 114 additions and 55 deletions

View File

@ -1,49 +0,0 @@
--- a/gettext-runtime/intl/compat.c
+++ b/gettext-runtime/intl/compat.c
@@ -23,3 +23,46 @@
libintl_set_relocation_prefix (const char *orig_prefix, const char *curr_prefix)
{
}
+
+#if (defined _WIN32 && defined DLL_EXPORT)
+#include <windows.h>
+
+# define HAS_DEVICE(P) \
+ ((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \
+ && (P)[1] == ':')
+#define IS_FILE_NAME_WITH_DIR(P) \
+ (strchr (P, '/') != NULL || strchr (P, '\\') != NULL || HAS_DEVICE (P))
+
+static char *shared_library_fullname;
+
+BOOL WINAPI
+DllMain (HINSTANCE module_handle, DWORD event, LPVOID reserved)
+{
+ (void) reserved;
+
+ if (event == DLL_PROCESS_ATTACH)
+ {
+ /* The DLL is being loaded into an application's address range. */
+ static char location[MAX_PATH];
+
+ if (!GetModuleFileName (module_handle, location, sizeof (location)))
+ /* Shouldn't happen. */
+ return FALSE;
+
+ if (!IS_FILE_NAME_WITH_DIR (location))
+ /* Shouldn't happen. */
+ return FALSE;
+
+ /* Avoid a memory leak when the same DLL get attached, detached,
+ attached, detached, and so on. This happens e.g. when a spell
+ checker DLL is used repeatedly by a mail program. */
+ if (!(shared_library_fullname != NULL
+ && strcmp (shared_library_fullname, location) == 0))
+ /* Remember the full pathname of the shared library. */
+ shared_library_fullname = strdup (location);
+ }
+
+ return TRUE;
+}
+
+#endif

View File

@ -0,0 +1,106 @@
--- a/gettext-tools/gnulib-lib/Makefile.gnulib
+++ b/gettext-tools/gnulib-lib/Makefile.gnulib
@@ -4640,7 +4640,15 @@ BUILT_SOURCES += $(STDCOUNTOF_H)
# doesn't have one that works with the given compiler.
if GL_GENERATE_STDCOUNTOF_H
stdcountof.h: stdcountof.in.h $(top_builddir)/config.status
- $(gl_V_at)$(SED_HEADER_STDOUT) $(srcdir)/stdcountof.in.h > $@-t
+ $(gl_V_at)$(SED_HEADER_STDOUT) \
+ -e 's|@''GUARD_PREFIX''@|${gl_include_guard_prefix}|g' \
+ -e 's/@''HAVE_STDCOUNTOF_H''@/$(HAVE_STDCOUNTOF_H)/g' \
+ -e 's/@''CXX_HAVE_STDCOUNTOF_H''@/$(CXX_HAVE_STDCOUNTOF_H)/g' \
+ -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+ -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+ -e 's|@''NEXT_STDCOUNTOF_H''@|$(NEXT_STDCOUNTOF_H)|g' \
+ $(srcdir)/stdcountof.in.h > $@-t
$(AM_V_at)mv $@-t $@
else
stdcountof.h: $(top_builddir)/config.status
--- a/gettext-tools/gnulib-lib/stdcountof.in.h
+++ b/gettext-tools/gnulib-lib/stdcountof.in.h
@@ -15,8 +15,20 @@
/* Written by Bruno Haible <bruno@clisp.org>, 2025. */
-#ifndef _GL_STDCOUNTOF_H
-#define _GL_STDCOUNTOF_H
+#ifndef _@GUARD_PREFIX@_STDCOUNTOF_H
+
+#if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
+#endif
+@PRAGMA_COLUMNS@
+
+/* The include_next requires a split double-inclusion guard. */
+#if (defined __cplusplus ? @CXX_HAVE_STDCOUNTOF_H@ : @HAVE_STDCOUNTOF_H@)
+# @INCLUDE_NEXT@ @NEXT_STDCOUNTOF_H@
+#else
+
+#ifndef _@GUARD_PREFIX@_STDCOUNTOF_H
+#define _@GUARD_PREFIX@_STDCOUNTOF_H
/* This file uses _GL_GNUC_PREREQ. */
#if !_GL_CONFIG_H_INCLUDED
@@ -96,4 +108,6 @@ template <typename T> _gl_array_type_test<T> _gl_array_type_test_helper(T&);
# endif
#endif
-#endif /* _GL_STDCOUNTOF_H */
+#endif /* _@GUARD_PREFIX@_STDCOUNTOF_H */
+#endif
+#endif /* _@GUARD_PREFIX@_STDCOUNTOF_H */
--- a/gettext-tools/gnulib-m4/stdcountof_h.m4
+++ b/gettext-tools/gnulib-m4/stdcountof_h.m4
@@ -1,5 +1,5 @@
# stdcountof_h.m4
-# serial 1
+# serial 2
dnl Copyright 2025 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -9,6 +9,7 @@ dnl This file is offered as-is, without any warranty.
AC_DEFUN_ONCE([gl_STDCOUNTOF_H],
[
AC_CHECK_HEADERS_ONCE([stdcountof.h])
+ gl_CHECK_NEXT_HEADERS([stdcountof.h])
if test $ac_cv_header_stdcountof_h = yes; then
HAVE_STDCOUNTOF_H=1
else
@@ -16,7 +17,35 @@ AC_DEFUN_ONCE([gl_STDCOUNTOF_H],
fi
AC_SUBST([HAVE_STDCOUNTOF_H])
- if test $HAVE_STDCOUNTOF_H = 1; then
+ dnl In clang 21, <stdcountof.h> exists but does not work in C++ mode, because
+ dnl it uses _Countof, which is not a compiler built-in in C++ mode.
+ m4_ifdef([gl_ANSI_CXX], [AC_REQUIRE([gl_ANSI_CXX])])
+ CXX_HAVE_STDCOUNTOF_H=1
+ if test "$CXX" != no; then
+ AC_CACHE_CHECK([whether the C++ compiler has <stdcountof.h>],
+ [gl_cv_cxx_have_stdcountof_h],
+ [dnl We can't use AC_LANG_PUSH([C++]) and AC_LANG_POP([C++]) here, due to
+ dnl an autoconf bug <https://savannah.gnu.org/support/?110294>.
+ cat > conftest.cpp <<\EOF
+#include <stdcountof.h>
+int a[] = { 86, 47 };
+unsigned int a_n = countof (a);
+EOF
+ gl_command="$CXX $CXXFLAGS $CPPFLAGS -c conftest.cpp"
+ if AC_TRY_EVAL([gl_command]); then
+ gl_cv_cxx_have_stdcountof_h=yes
+ else
+ gl_cv_cxx_have_stdcountof_h=no
+ fi
+ rm -fr conftest*
+ ])
+ if test $gl_cv_cxx_have_stdcountof_h != yes; then
+ CXX_HAVE_STDCOUNTOF_H=0
+ fi
+ fi
+ AC_SUBST([CXX_HAVE_STDCOUNTOF_H])
+
+ if test $HAVE_STDCOUNTOF_H = 1 && test $CXX_HAVE_STDCOUNTOF_H = 1; then
GL_GENERATE_STDCOUNTOF_H=false
else
GL_GENERATE_STDCOUNTOF_H=true

View File

@ -7,7 +7,7 @@ pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}-runtime"
"${MINGW_PACKAGE_PREFIX}-${_realname}-libtextstyle"
"${MINGW_PACKAGE_PREFIX}-${_realname}-tools")
pkgver=0.26
pkgrel=1
pkgrel=2
pkgdesc="GNU internationalization library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
@ -24,22 +24,22 @@ makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
"${MINGW_PACKAGE_PREFIX}-libiconv"
"groff")
source=(https://ftp.gnu.org/pub/gnu/${_realname}/${_realname}-${pkgver}.tar.lz{,.sig}
0001-restore-DllMain-symbol.patch
0005-Fix-compilation-of-pthread_sigmask.c.patch
122-Use-LF-as-newline-in-envsubst.patch
0021-replace-fsync.patch
0022-libasprintf.patch
0024-disable-gnu-format.patch
0030-fix-build-with-mingw-w64-clang.patch)
0030-fix-build-with-mingw-w64-clang.patch
0101-fix-build-with-clang-21.patch)
sha256sums=('a0151088dad8942374dc038e461b228352581defd7055e79297f156268b8d508'
'SKIP'
'bfd38442d899bee75dc5d919f2bfe4a8fd827eff3fdcf45966f9de5bb5d6f283'
'cbc2f533012d646521afa20f8b256917fce040741ff42cf53fb6dd7123a6670a'
'ec39103d851262c02c27b7038f3c538e03afaefc6aa050311d62519d192ff38c'
'380dbddee2f9e2feee4c1435e8a942b5d11d0125e60c3350ebb10c19b19011aa'
'c354f6a7021069c99b90f1c6d6f6a4ccf40a01e9f6742b866df2b5a7286cb868'
'ce7ccf6dd3a492cab322253cd67310899b546eccc25821c25cbc047a1a984633'
'9b1b4f0c65b3bc1a3103c921a02c203cecf533d145f0bd90023406e760f81749')
'9b1b4f0c65b3bc1a3103c921a02c203cecf533d145f0bd90023406e760f81749'
'0055847af8154f3b33858f724fdf0b2df92645c86f220ea79dac847c09f4d358')
validpgpkeys=('462225C3B46F34879FC8496CD605848ED7E69871' # Daiki Ueno
'9001B85AF9E1B83DF1BDA942F5BE8B267C6A406D' # Bruno Haible
'E0FFBD975397F77A32AB76ECB6301D9E1BBEAC08') # Bruno Haible (FSF) <bruno@clisp.org>
@ -57,7 +57,6 @@ prepare() {
cd "${srcdir}/${_realname}-${pkgver}"
apply_patch_with_msg \
0001-restore-DllMain-symbol.patch \
0005-Fix-compilation-of-pthread_sigmask.c.patch \
122-Use-LF-as-newline-in-envsubst.patch
@ -73,6 +72,9 @@ prepare() {
apply_patch_with_msg \
0030-fix-build-with-mingw-w64-clang.patch
apply_patch_with_msg \
0101-fix-build-with-clang-21.patch
libtoolize --automake --copy --force
WANT_AUTOMAKE=latest ./autogen.sh --skip-gnulib
}