New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#define hypot _hypot conflicts with existing definition #64420
Comments
In pyconfig.h (line 216), there is this line:
#define hypot _hypot This conflicts with the definition of _hypot that ships with VS2010 (math.h, line 161): The result of the redefinition is that the following warning occurs during compilation: When compiling with warnings being treated as errors, this will obviously result in failed builds. The recommendation from Microsoft (see http://connect.microsoft.com/VisualStudio/feedback/details/633988/warning-in-math-h-line-162-re-nonstandard-extensions-used) is to change the definition to:
#if _MSC_VER < 1600
#define hypot _hypot
#endif |
How are you compiling to get that warning? I've never seen it, and none of the Windows buildbots do either. Also, which version of Python are you compiling on which version of Windows? |
v100 toolset, with compiler setting /W4. Microsoft recommends W4 for all new C++ projects (see http://msdn.microsoft.com/en-us/library/thxezb7y(v=vs.100).aspx). I'm using 3.3. |
Sorry, I realize I didn't mention this in the original post. I'm getting this compiler warning when building my Python extension, not when building Python itself. |
We have a similar issue in Blender (where Python is embedded), but it's actually causing a crash instead of only a compiler warning: https://developer.blender.org/T38256 The code in the Visual Studio 2013 math.h looks like this: __inline double __CRTDECL hypot(In double _X, _In_ double _Y) With the #define hypot _hypot that becomes: __inline double __CRTDECL _hypot(In double _X, _In_ double _Y) So you get infinite recursive calls when using hypot and the application crashes. The patch fix20221.patch that was attach here solves the issue. |
I'm having difficulty wrapping my head around why the math and cmath modules (both of which use hypot) compile fine, but your extensions don't. Anyone have any insight into why that is? |
My extension doesn't compile because I treat warnings as errors. I believe Blender compiles fine, but crashes at runtime because of the infinite recursion (see the second code snippet in Brecht's response (http://bugs.python.org/msg208981). |
Sorry, I wasn't entirely clear. By "compile fine", I meant "compiles without warnings, and actually works when you try to use it". Both math and cmath make use of hypot (as defined in pyconfig.h), but don't have any problems. They also have no problems with your patch applied, but I don't feel I understand the situation enough yet to move the patch forward. |
For Visual Studio 2013, here's how to redo the problem. Take this simple program: #include <Python.h>
int main(int argc, char **argv)
{
return (int)hypot(rand(), rand());
} And compile it: cl.exe test.c -I include/python3.3 lib/python33.lib /W4 c:\program files (x86)\microsoft visual studio 12.0\vc\include\math.h(566) : warning C4717: '_hypot' : recursive on all control paths, function will cause runtime stack overflow I don't know about the conditions to get a warning in VS 2010, never tried that version. |
Your test program works for VS2010 as well (/W4 is unnecessary, the default warning level gives the warning), but still doesn't answer the question of why the math module (specifically math.hypot) doesn't show the problem. I understand why both of your cases *don't* work, I want to understand why mathmodule.c and cmathmodule.c (and complexobject.c, for that matter) *do* work. Attempting to compile mathmodule.c alone results in the warning, and even picking through mathmodule.i as produced by preprocessing to file, it looks like math_hypot should always have the problem. The fact that math_hypot works when compiled with the rest of Python frankly frustrates me quite a lot, because I can see no reason why it should. |
Ok, I had missed that the warnings in your two separate cases were in fact different. I still don't understand why VC++ sees the two cases so differently (throwing different warnings), but it at least explains the different results in your two cases. I don't see how this change can actually break anything, so I'll go ahead and commit so this makes it into 3.3.5 (and hopefully 3.4.0, but that will be up to Larry Hastings). |
New changeset 9aedb876c2d7 by Zachary Ware in branch '3.3': New changeset bf413a97f1a9 by Zachary Ware in branch 'default': |
Fixed, thanks for the report and patch! |
New changeset 033d686af4c1 by Zachary Ware in branch '3.4': |
Any chance this would be merged to 2.7 as well? |
New changeset 430aaeaa8087 by Zachary Ware in branch '2.7': |
It grafted very easily, so it turns out to be "yes" :) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: