This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix C++ compilation on MinGW


Hi,

On 11/02/2016 09:53 AM, orgads@gmail.com wrote:
> From: Orgad Shaneh <orgads@gmail.com>
> 
> When compiling with MinGW, pyconfig.h renames hypot to _hypot.

Yeah, that's not a good idea in C++.  We have a similar
issue with gnulib's '#define foo rpl_foo' preventing use of
"foo" as class methods etc.  Particularly annoying for "open",
"close", etc.  (I plan to address that.)

> 
> If math.h is included later, hypot is not declared correctly.
> 
> When g++ is used, it has 'using ::hypot', which doesn't exist.

So due to the define, that actually expanded to:

 using ::_hypot;

Right?

Anyway, with your fix, IIUC, if someone adds a call to
std::hypot somewhere (or uses the "hypot" symbol for
something unrelated), we'll still have a problem.

I'm thinking that the patch below might be a better fix.
However, my cross mingw setup does not include Python, so I
can't verify it works.

WDYT?

>From 49f5b6892c959e9f1a3ea50240e8d83da63c6268 Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Tue, 8 Nov 2016 10:48:32 +0000
Subject: [PATCH] Fix Python hypot mingw

---
 gdb/python/python-internal.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 8545c7b..9d1a046 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -88,6 +88,18 @@
 /* Request clean size types from Python.  */
 #define PY_SSIZE_T_CLEAN
 
+/* When compiling with MinGW, pyconfig.h (included by other Python
+   headers) renames hypot to _hypot.  That conflicts with C++'s
+   std::hypot.  See <https://bugs.python.org/issue11566>.
+
+   In C++, it's not a good idea to define standard C functions as
+   macros.  Fortunately, pyconfig.h has double-inclusion guards, so
+   include it ourselves, and #undef any conflicting symbol it may have
+   defined.  Note libstdc++'s <c...> headers also #undef C-inherited
+   function-like macros, including "hypot".  */
+#include <pyconfig.h>
+#undef hypot
+
 /* Include the Python header files using angle brackets rather than
    double quotes.  On case-insensitive filesystems, this prevents us
    from including our python/python.h header file.  */
-- 
2.5.5


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]