gh-93202: Always use %zd printf formatter (#93201)

Python now always use the ``%zu`` and ``%zd`` printf formats to
format a size_t or Py_ssize_t number. Building Python 3.12 requires a
C11 compiler, so these printf formats are now always supported.

* PyObject_Print() and _PyObject_Dump() now use the printf %zd format
  to display an object reference count.
* Update PY_FORMAT_SIZE_T comment.
* Remove outdated notes about the %zd format in PyBytes_FromFormat()
  and PyUnicode_FromFormat() documentations.
* configure no longer checks for the %zd format and no longer defines
  PY_FORMAT_SIZE_T macro in pyconfig.h.
* pymacconfig.h no longer undefines PY_FORMAT_SIZE_T: macOS 10.4 is
  no longer supported. Python 3.12 now requires macOS 10.6 (Snow
  Leopard) or newer.
This commit is contained in:
Victor Stinner 2022-05-25 14:21:36 +02:00 committed by GitHub
parent 9485a0dbdd
commit 71d8775fee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 11 additions and 168 deletions

View file

@ -186,32 +186,10 @@ typedef Py_ssize_t Py_ssize_clean_t;
/* Largest possible value of size_t. */
#define PY_SIZE_MAX SIZE_MAX
/* Macro kept for backward compatibility: use "z" in new code.
/* Macro kept for backward compatibility: use directly "z" in new code.
*
* PY_FORMAT_SIZE_T is a platform-specific modifier for use in a printf
* format to convert an argument with the width of a size_t or Py_ssize_t.
* C99 introduced "z" for this purpose, but old MSVCs had not supported it.
* Since MSVC supports "z" since (at least) 2015, we can just use "z"
* for new code.
*
* These "high level" Python format functions interpret "z" correctly on
* all platforms (Python interprets the format string itself, and does whatever
* the platform C requires to convert a size_t/Py_ssize_t argument):
*
* PyBytes_FromFormat
* PyErr_Format
* PyBytes_FromFormatV
* PyUnicode_FromFormatV
*
* Lower-level uses require that you interpolate the correct format modifier
* yourself (e.g., calling printf, fprintf, sprintf, PyOS_snprintf); for
* example,
*
* Py_ssize_t index;
* fprintf(stderr, "index %" PY_FORMAT_SIZE_T "d sucks\n", index);
*
* That will expand to %zd or to something else correct for a Py_ssize_t on
* the platform.
* PY_FORMAT_SIZE_T is a modifier for use in a printf format to convert an
* argument with the width of a size_t or Py_ssize_t: "z" (C99).
*/
#ifndef PY_FORMAT_SIZE_T
# define PY_FORMAT_SIZE_T "z"