]> granicus.if.org Git - python/commitdiff
Fix %zd string formatting on Mac OS X so it prints negative numbers.
authorNeal Norwitz <nnorwitz@gmail.com>
Fri, 22 Sep 2006 08:16:26 +0000 (08:16 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Fri, 22 Sep 2006 08:16:26 +0000 (08:16 +0000)
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).

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

index be6c51fc5aade8fb5671150941b7a9abfccad6f5..16ee011272608a9031f6b30d7a2c4f6fe76757f3 100644 (file)
@@ -126,10 +126,10 @@ typedef Py_intptr_t       Py_ssize_t;
  * 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
index f0d78da2123b14d5a8f0c9419270c1e17dceb1be..e93a80e0cdd0654406f1853cdd7c6065045c5017 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 2.6 alpha 1?
 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
index b96349a4f596694cd46e11b019963cbf77f6791a..ecbdf26346b0a61e4d1b39b5f589517afbf5b27e 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.6.
 #
@@ -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 cff71941b51f6f8997bc268628f267323910360a..3a27294faa49d7fbfccd8e2311900c35fe8049f7 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)