[Python-checkins] r51971 - in python/trunk: Include/pyport.h Misc/NEWS configure configure.in

neal.norwitz python-checkins at python.org
Fri Sep 22 10:16:27 CEST 2006


Author: neal.norwitz
Date: Fri Sep 22 10:16:26 2006
New Revision: 51971

Modified:
   python/trunk/Include/pyport.h
   python/trunk/Misc/NEWS
   python/trunk/configure
   python/trunk/configure.in
Log:
Fix %zd string formatting on Mac OS X so it prints negative numbers.

In addition to testing positive numbers, verify negative numbers work in configure.
In order to avoid compiler warnings on OS X 10.4, also change the order of the check
for the format character to use (PY_FORMAT_SIZE_T) in the sprintf format
for Py_ssize_t.  This patch changes PY_FORMAT_SIZE_T from "" to "l" if it wasn't
defined at configure time.  Need to verify the buildbot results.

Backport candidate (if everyone thinks this patch can't be improved).


Modified: python/trunk/Include/pyport.h
==============================================================================
--- python/trunk/Include/pyport.h	(original)
+++ python/trunk/Include/pyport.h	Fri Sep 22 10:16:26 2006
@@ -126,10 +126,10 @@
  * Py_ssize_t on the platform.
  */
 #ifndef PY_FORMAT_SIZE_T
-#   if SIZEOF_SIZE_T == SIZEOF_INT
-#       define PY_FORMAT_SIZE_T ""
-#   elif SIZEOF_SIZE_T == SIZEOF_LONG
+#   if SIZEOF_SIZE_T == SIZEOF_LONG
 #       define PY_FORMAT_SIZE_T "l"
+#   elif SIZEOF_SIZE_T == SIZEOF_INT
+#       define PY_FORMAT_SIZE_T ""
 #   elif defined(MS_WINDOWS)
 #       define PY_FORMAT_SIZE_T "I"
 #   else

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Fri Sep 22 10:16:26 2006
@@ -12,6 +12,8 @@
 Core and builtins
 -----------------
 
+- Fix %zd string formatting on Mac OS X so it prints negative numbers.
+
 - Allow exception instances to be directly sliced again.
 
 - Bug #1551432: Exceptions do not define an explicit __unicode__ method.  This

Modified: python/trunk/configure
==============================================================================
--- python/trunk/configure	(original)
+++ python/trunk/configure	Fri Sep 22 10:16:26 2006
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.in Revision: 51173 .
+# From configure.in Revision: 51727 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.59 for python 2.6.
 #
@@ -22110,12 +22110,26 @@
 
 int main()
 {
-    char buffer[4];
+    char buffer[256];
+
+#ifdef HAVE_SSIZE_T
+typedef ssize_t Py_ssize_t;
+#elif SIZEOF_VOID_P == SIZEOF_LONG
+typedef long Py_ssize_t;
+#else
+typedef int Py_ssize_t;
+#endif
 
     if(sprintf(buffer, "%zd", (size_t)123) < 0)
        	return 1;
 
-    if (strncmp(buffer, "123", 3))
+    if (strcmp(buffer, "123"))
+	return 1;
+
+    if (sprintf(buffer, "%zd", (Py_ssize_t)-123) < 0)
+       	return 1;
+
+    if (strcmp(buffer, "-123"))
 	return 1;
 
     return 0;

Modified: python/trunk/configure.in
==============================================================================
--- python/trunk/configure.in	(original)
+++ python/trunk/configure.in	Fri Sep 22 10:16:26 2006
@@ -3352,14 +3352,28 @@
 
 int main()
 {
-    char buffer[4];
+    char buffer[256];
+
+#ifdef HAVE_SSIZE_T
+typedef ssize_t Py_ssize_t;
+#elif SIZEOF_VOID_P == SIZEOF_LONG
+typedef long Py_ssize_t;
+#else
+typedef int Py_ssize_t;
+#endif
 
     if(sprintf(buffer, "%zd", (size_t)123) < 0)
        	return 1;
 
-    if (strncmp(buffer, "123", 3))
+    if (strcmp(buffer, "123"))
 	return 1;
-    
+
+    if (sprintf(buffer, "%zd", (Py_ssize_t)-123) < 0)
+       	return 1;
+
+    if (strcmp(buffer, "-123"))
+	return 1;
+
     return 0;
 }],
 [AC_MSG_RESULT(yes)


More information about the Python-checkins mailing list