8000 bpo-37781: use "z" for PY_FORMAT_SIZE_T (GH-15156) · python/cpython@d765d81 · GitHub
[go: up one dir, main page]

Skip to content

Commit d765d81

Browse files
authored
bpo-37781: use "z" for PY_FORMAT_SIZE_T (GH-15156)
MSVC 2015 supports %zd / %zu. "z" is portable enough nowadays.
1 parent 39d87b5 commit d765d81

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

Include/pyport.h

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,9 @@ typedef int Py_ssize_clean_t;
133133

134134
/* PY_FORMAT_SIZE_T is a platform-specific modifier for use in a printf
135135
* format to convert an argument with the width of a size_t or Py_ssize_t.
136-
* C99 introduced "z" for this purpose, but not all platforms support that;
137-
* e.g., MS compilers use "I" instead.
136+
* C99 introduced "z" for this purpose, but old MSVCs had not supported it.
137+
* Since MSVC supports "z" since (at least) 2015, we can just use "z"
138+
* for new code.
138139
*
139140
* These "high level" Python format functions interpret "z" correctly on
140141
* all platforms (Python interprets the format string itself, and does whatever
@@ -152,19 +153,11 @@ typedef int Py_ssize_clean_t;
152153
* Py_ssize_t index;
153154
* fprintf(stderr, "index %" PY_FORMAT_SIZE_T "d sucks\n", index);
154155
*
155-
* That will expand to %ld, or %Id, or to something else correct for a
156-
* Py_ssize_t on the platform.
156+
* That will expand to %zd or to something else correct for a Py_ssize_t on
157+
* the platform.
157158
*/
158159
#ifndef PY_FORMAT_SIZE_T
159-
# if SIZEOF_SIZE_T == SIZEOF_INT && !defined(__APPLE__)
160-
# define PY_FORMAT_SIZE_T ""
161-
# elif SIZEOF_SIZE_T == SIZEOF_LONG
162-
# define PY_FORMAT_SIZE_T "l"
163-
# elif defined(MS_WINDOWS)
164-
# define PY_FORMAT_SIZE_T "I"
165-
# else
166-
# error "This platform's pyconfig.h needs to define PY_FORMAT_SIZE_T"
167-
# endif
160+
# define PY_FORMAT_SIZE_T "z"
168161
#endif
169162

170163
/* Py_LOCAL can be used instead of static to get the fastest possible calling

0 commit comments

Comments
 (0)
0