Michael, If I build python 2.4.3 with the default compiler flags under gcc trunk on MacOS X 10.4.7, I get the following...
Python 2.4.3 (#1, Aug 23 2006, 17:39:08) [GCC 4.2.0 20060822 (experimental)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> divmod(-sys.maxint-1, -1) (0, -2147483648) >>> (sys.maxint+1, 0) (2147483648L, 0) >>> divmod(-sys.maxint-1, -1) == (sys.maxint+1, 0) False If I add the -fwrapv flag to BASECFLAGS in the Makefile, I get... Python 2.4.3 (#2, Aug 23 2006, 17:54:19) [GCC 4.2.0 20060822 (experimental)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> divmod(-sys.maxint-1, -1) (2147483648L, 0L) >>> (sys.maxint+1, 0) (2147483648L, 0) >>> divmod(-sys.maxint-1, -1) == (sys.maxint+1, 0) True So your analysis appears to be correct. Even more interesting is that if I build python 2.4.3 with Apple's gcc from Xcode 2.3, the correct results are obtained without the need to resort to the -fwrapv flag. So either we have a regression in gcc trunk or Apple has a patch in their branch which was never moved over that resolves this issue. The only difference I can see between the builds with gcc trunk and Apple's gcc is that I have to remove the -Wno-long-double -no-cpp-precomp flags the build with gcc trunk (because they don't exist). Jack ps Mike and Geoff, any comments?