[vlc-commits] contrib: gettext: Backport a gettext patch for fixing building on latest mingw-w64

Martin Storsjö git at videolan.org
Tue May 5 21:27:21 CEST 2020


vlc | branch: master | Martin Storsjö <martin at martin.st> | Tue May  5 20:33:48 2020 +0300| [f419823685f95e196f7a1ef8821b401b5bce89ea] | committer: Martin Storsjö

contrib: gettext: Backport a gettext patch for fixing building on latest mingw-w64

The current git master version of mingw-w64 activates
__USE_MINGW_ANSI_STDIO by default if targeting C99 (which is the
default C version in both GCC and Clang), unless using UCRT.

This patch (a backport of ca6f6cfbb4c78c063f2a50bb758edfc95c9d64a2
from gettext git) fixes building gettext when __USE_MINGW_ANSI_STDIO
is enabled - i.e. fixing building gettext with latest mingw-w64 when
using msvcrt.dll.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f419823685f95e196f7a1ef8821b401b5bce89ea
---

 ...-On-mingw-really-use-our-vasprintf-functi.patch | 105 +++++++++++++++++++++
 ...-Avoid-compilation-error-on-mingw-with-D_.patch |  43 +++++++++
 contrib/src/gettext/rules.mak                      |   2 +
 3 files changed, 150 insertions(+)

diff --git a/contrib/src/gettext/0001-libasprintf-On-mingw-really-use-our-vasprintf-functi.patch b/contrib/src/gettext/0001-libasprintf-On-mingw-really-use-our-vasprintf-functi.patch
new file mode 100644
index 0000000000..d25a4d2348
--- /dev/null
+++ b/contrib/src/gettext/0001-libasprintf-On-mingw-really-use-our-vasprintf-functi.patch
@@ -0,0 +1,105 @@
+From 69105728ea5e1ce289498865b81e5ffeacebd840 Mon Sep 17 00:00:00 2001
+From: Bruno Haible <bruno at clisp.org>
+Date: Sun, 25 Nov 2018 02:10:44 +0100
+Subject: [PATCH 1/2] libasprintf: On mingw, really use our vasprintf function,
+ not mingw_vasprintf.
+
+mingw now has a definition of 'vasprintf' in <stdio.h> that redirects to
+mingw_vasprintf, which does not support argument reordering (i.e.
+HAVE_POSIX_PRINTF is not defined). Make sure to avoid this function and use
+the one defined in our lib-asprintf.c instead.
+
+* gettext-runtime/libasprintf/lib-asprintf.h (asprintf): Define as macro
+redirecting to libasprintf_asprintf.
+(vasprintf): Define as macro redirecting to libasprintf_vasprintf.
+* gettext-runtime/libasprintf/lib-asprintf.c: Define also libasprintf_asprintf
+and libasprintf_vasprintf.
+* gettext-runtime/libasprintf/autosprintf.cc: Include lib-asprintf.h last.
+
+(cherry picked from commit 63295aac24c693d2d902eadd272259b7bdd7eae3)
+---
+ gettext-runtime/libasprintf/autosprintf.cc |  5 ++++-
+ gettext-runtime/libasprintf/lib-asprintf.c | 13 ++++++++++++-
+ gettext-runtime/libasprintf/lib-asprintf.h |  7 ++++++-
+ 3 files changed, 22 insertions(+), 3 deletions(-)
+
+diff --git a/gettext-runtime/libasprintf/autosprintf.cc b/gettext-runtime/libasprintf/autosprintf.cc
+index 0c8bff1f1..57295aebd 100644
+--- a/gettext-runtime/libasprintf/autosprintf.cc
++++ b/gettext-runtime/libasprintf/autosprintf.cc
+@@ -28,7 +28,6 @@
+ #include <stdarg.h>
+ #include <stdlib.h>
+ #include <string.h>
+-#include "lib-asprintf.h"
+ 
+ /* std::swap() is in <utility> since C++11.  */
+ #if __cplusplus >= 201103L
+@@ -37,6 +36,10 @@
+ # include <algorithm>
+ #endif
+ 
++/* This include must come last, since it contains overrides of functions that
++   the system may provide (namely, vasprintf).  */
++#include "lib-asprintf.h"
++
+ namespace gnu
+ {
+ 
+diff --git a/gettext-runtime/libasprintf/lib-asprintf.c b/gettext-runtime/libasprintf/lib-asprintf.c
+index afa04dda8..927fe7779 100644
+--- a/gettext-runtime/libasprintf/lib-asprintf.c
++++ b/gettext-runtime/libasprintf/lib-asprintf.c
+@@ -1,5 +1,5 @@
+ /* Library functions for class autosprintf.
+-   Copyright (C) 2002-2003, 2006, 2015-2016 Free Software Foundation, Inc.
++   Copyright (C) 2002-2003, 2006, 2018 Free Software Foundation, Inc.
+    Written by Bruno Haible <bruno at clisp.org>, 2002.
+ 
+    This program is free software: you can redistribute it and/or modify
+@@ -31,8 +31,19 @@
+ #include "vasnprintf.c"
+ #include "asnprintf.c"
+ 
++/* Define to the same symbols as in lib-asprintf.h.  */
++#define asprintf libasprintf_asprintf
++#define vasprintf libasprintf_vasprintf
++
+ /* Define functions declared in "vasprintf.h".  */
+ #include "vasprintf.c"
+ #include "asprintf.c"
+ 
++/* Define the same functions also without the 'libasprintf_' prefix,
++   for binary backward-compatibility.  */
++#undef asprintf
++#undef vasprintf
++#include "vasprintf.c"
++#include "asprintf.c"
++
+ #endif
+diff --git a/gettext-runtime/libasprintf/lib-asprintf.h b/gettext-runtime/libasprintf/lib-asprintf.h
+index 22874f289..c55c988c8 100644
+--- a/gettext-runtime/libasprintf/lib-asprintf.h
++++ b/gettext-runtime/libasprintf/lib-asprintf.h
+@@ -1,5 +1,5 @@
+ /* Library functions for class autosprintf.
+-   Copyright (C) 2002-2003, 2015-2016 Free Software Foundation, Inc.
++   Copyright (C) 2002-2003, 2018 Free Software Foundation, Inc.
+    Written by Bruno Haible <bruno at clisp.org>, 2002.
+ 
+    This program is free software: you can redistribute it and/or modify
+@@ -26,6 +26,11 @@
+ 
+ #else
+ 
++/* Define to symbols that are guaranteed to not be defined by the system
++   header files.  */
++#define asprintf libasprintf_asprintf
++#define vasprintf libasprintf_vasprintf
++
+ /* Get asprintf(), vasprintf() declarations.  */
+ #include "vasprintf.h"
+ 
+-- 
+2.17.1
+
diff --git a/contrib/src/gettext/0002-libasprintf-Avoid-compilation-error-on-mingw-with-D_.patch b/contrib/src/gettext/0002-libasprintf-Avoid-compilation-error-on-mingw-with-D_.patch
new file mode 100644
index 0000000000..faa6ded9cf
--- /dev/null
+++ b/contrib/src/gettext/0002-libasprintf-Avoid-compilation-error-on-mingw-with-D_.patch
@@ -0,0 +1,43 @@
+From 27b39c7a632b85966bbe0776e6a6e2d34fcee018 Mon Sep 17 00:00:00 2001
+From: Bruno Haible <bruno at clisp.org>
+Date: Sat, 18 May 2019 17:25:10 +0200
+Subject: [PATCH 2/2] libasprintf: Avoid compilation error on mingw with
+ -D__USE_MINGW_ANSI_STDIO=1.
+
+* gettext-runtime/libasprintf/lib-asprintf.c (asprintf, vasprintf): Don't define
+on mingw when __USE_MINGW_ANSI_STDIO is non-zero.
+
+(cherry picked from commit ca6f6cfbb4c78c063f2a50bb758edfc95c9d64a2)
+---
+ gettext-runtime/libasprintf/lib-asprintf.c | 7 +++++--
+ 1 file changed, 5 insertions(+), 2 deletions(-)
+
+diff --git a/gettext-runtime/libasprintf/lib-asprintf.c b/gettext-runtime/libasprintf/lib-asprintf.c
+index 927fe7779..93d75bcf7 100644
+--- a/gettext-runtime/libasprintf/lib-asprintf.c
++++ b/gettext-runtime/libasprintf/lib-asprintf.c
+@@ -1,5 +1,5 @@
+ /* Library functions for class autosprintf.
+-   Copyright (C) 2002-2003, 2006, 2018 Free Software Foundation, Inc.
++   Copyright (C) 2002-2003, 2006, 2018-2019 Free Software Foundation, Inc.
+    Written by Bruno Haible <bruno at clisp.org>, 2002.
+ 
+    This program is free software: you can redistribute it and/or modify
+@@ -40,10 +40,13 @@
+ #include "asprintf.c"
+ 
+ /* Define the same functions also without the 'libasprintf_' prefix,
+-   for binary backward-compatibility.  */
++   for binary backward-compatibility.
++   But don't redefine functions already defined by mingw.  */
++#if !(defined __MINGW32__ && __USE_MINGW_ANSI_STDIO)
+ #undef asprintf
+ #undef vasprintf
+ #include "vasprintf.c"
+ #include "asprintf.c"
++#endif
+ 
+ #endif
+-- 
+2.17.1
+
diff --git a/contrib/src/gettext/rules.mak b/contrib/src/gettext/rules.mak
index 8e8dbbebaa..aa2ffc2244 100644
--- a/contrib/src/gettext/rules.mak
+++ b/contrib/src/gettext/rules.mak
@@ -17,6 +17,8 @@ $(TARBALLS)/gettext-$(GETTEXT_VERSION).tar.gz:
 
 gettext: gettext-$(GETTEXT_VERSION).tar.gz .sum-gettext
 	$(UNPACK)
+	$(APPLY) $(SRC)/gettext/0001-libasprintf-On-mingw-really-use-our-vasprintf-functi.patch
+	$(APPLY) $(SRC)/gettext/0002-libasprintf-Avoid-compilation-error-on-mingw-with-D_.patch
 	$(MOVE)
 
 DEPS_gettext = iconv $(DEPS_iconv) libxml2 $(DEPS_libxml2)



More information about the vlc-commits mailing list