diff --git a/Include/pyport.h b/Include/pyport.h index be6c51fc5aa..16ee0112726 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -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 diff --git a/Misc/NEWS b/Misc/NEWS index f0d78da2123..e93a80e0cdd 100644 --- 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 diff --git a/configure b/configure index b96349a4f59..ecbdf26346b 100755 --- 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; diff --git a/configure.in b/configure.in index cff71941b51..3a27294faa4 100644 --- a/configure.in +++ b/configure.in @@ -3352,14 +3352,28 @@ AC_TRY_RUN([#include 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)