Backport rev. 51971:
authorGeorg Brandl <georg@python.org>
Mon, 25 Sep 2006 06:58:00 +0000 (06:58 +0000)
committerGeorg Brandl <georg@python.org>
Mon, 25 Sep 2006 06:58:00 +0000 (06:58 +0000)
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.

Include/pyport.h
Misc/NEWS
configure
configure.in

index be6c51fc5aade8fb5671150941b7a9abfccad6f5..8f8e514c349c633e4f65ee9888566196c8f0833e 100644 (file)
@@ -126,7 +126,7 @@ typedef Py_intptr_t Py_ssize_t;
  * Py_ssize_t on the platform.
  */
 #ifndef PY_FORMAT_SIZE_T
-#   if SIZEOF_SIZE_T == SIZEOF_INT
+#   if SIZEOF_SIZE_T == SIZEOF_INT && !defined(__APPLE__)
 #       define PY_FORMAT_SIZE_T ""
 #   elif SIZEOF_SIZE_T == SIZEOF_LONG
 #       define PY_FORMAT_SIZE_T "l"
index 685daf682323dd5988fda03ed3b914403c28e744..42b366d6680abef0ed88518e255b2aea31ba5d06 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -16,6 +16,8 @@ Core and builtins
   not being recognized as a keyword after, e.g., this statement:
   from __future__ import division, with_statement
 
+- Fix %zd string formatting on Mac OS X so it prints negative numbers.
+
 - Allow exception instances to be directly sliced again.
 
 
index 794a0be5cea3a79af14b9fe8e812a5e97f45ff36..6b96c77bbaaa6de10992fbf8155e736bcdd02b88 100755 (executable)
--- a/configure
+++ b/configure
@@ -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.5.
 #
@@ -22110,12 +22110,26 @@ cat >>conftest.$ac_ext <<_ACEOF
 
 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;
index 410f1afad8650a75e553c635aebb8cf89629433e..711e19e52d9c8cc41baaf829f64b59e54c861208 100644 (file)
@@ -3352,14 +3352,28 @@ AC_TRY_RUN([#include <stdio.h>
 
 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)