Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 00de1bd

Browse files
committed
Merged revisions 75941 via svnmerge from
svn+ssh://[email protected]/python/branches/py3k ................ r75941 | mark.dickinson | 2009-10-29 09:58:06 +0000 (Thu, 29 Oct 2009) | 11 lines Merged revisions 75939 via svnmerge from svn+ssh://[email protected]/python/trunk ........ r75939 | mark.dickinson | 2009-10-29 09:46:04 +0000 (Thu, 29 Oct 2009) | 5 lines Roll back ill-considered attempts to fix printf specifier mismatch for off_t. The sensible solution seems to be to implement %lld for PyString_FromFormat(V) and PyErr_Format. See issue #7228. ........ ................
1 parent ab65087 commit 00de1bd

2 files changed

Lines changed: 9 additions & 26 deletions

File tree

Modules/_io/_iomodule.h

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,6 @@ PyAPI_DATA(PyObject *) PyExc_BlockingIOError;
7070
* Offset type for positioning.
7171
*/
7272

73-
/* Printing a variable of type off_t correctly and without producing
74-
compiler warnings is surprisingly painful. We identify an integer
75-
type whose size matches off_t and then: (1) cast the off_t to that
76-
integer type and (2) use the appropriate conversion specification
77-
for printf. The cast is necessary: gcc complains about formatting
78-
a long with "%lld" even when both long and long long have the same
79-
precision. */
80-
8173
#if defined(MS_WIN64) || defined(MS_WINDOWS)
8274

8375
/* Windows uses long long for offsets */
@@ -86,33 +78,26 @@ typedef PY_LONG_LONG Py_off_t;
8678
# define PyLong_FromOff_t PyLong_FromLongLong
8779
# define PY_OFF_T_MAX PY_LLONG_MAX
8880
# define PY_OFF_T_MIN PY_LLONG_MIN
89-
# define PY_PRIdOFF "I64d" /* format to use in printf with type off_t */
90-
# define PY_OFF_T_COMPAT PY_LONG_LONG /* type compatible with off_t */
81+
9182
#else
9283

9384
/* Other platforms use off_t */
9485
typedef off_t Py_off_t;
95-
#if (HAVE_LONG_LONG && SIZEOF_OFF_T == SIZEOF_LONG_LONG)
86+
#if (SIZEOF_OFF_T == SIZEOF_SIZE_T)
87+
# define PyLong_AsOff_t PyLong_AsSsize_t
88+
# define PyLong_FromOff_t PyLong_FromSsize_t
89+
# define PY_OFF_T_MAX PY_SSIZE_T_MAX
90+
# define PY_OFF_T_MIN PY_SSIZE_T_MIN
91+
#elif (SIZEOF_OFF_T == SIZEOF_LONG_LONG)
9692
# define PyLong_AsOff_t PyLong_AsLongLong
9793
# define PyLong_FromOff_t PyLong_FromLongLong
9894
# define PY_OFF_T_MAX PY_LLONG_MAX
9995
# define PY_OFF_T_MIN PY_LLONG_MIN
100-
# define PY_PRIdOFF "lld"
101-
# define PY_OFF_T_COMPAT PY_LONG_LONG
10296
#elif (SIZEOF_OFF_T == SIZEOF_LONG)
10397
# define PyLong_AsOff_t PyLong_AsLong
10498
# define PyLong_FromOff_t PyLong_FromLong
10599
# define PY_OFF_T_MAX LONG_MAX
106100
# define PY_OFF_T_MIN LONG_MIN
107-
# define PY_PRIdOFF "ld"
108-
# define PY_OFF_T_COMPAT long
109-
#elif (SIZEOF_OFF_T == SIZEOF_SIZE_T)
110-
# define PyLong_AsOff_t PyLong_AsSsize_t
111-
# define PyLong_FromOff_t PyLong_FromSsize_t
112-
# define PY_OFF_T_MAX PY_SSIZE_T_MAX
113-
# define PY_OFF_T_MIN PY_SSIZE_T_MIN
114-
# define PY_PRIdOFF "zd"
115-
# define PY_OFF_T_COMPAT Py_ssize_t
116101
#else
117102
# error off_t does not match either size_t, long, or long long!
118103
#endif

Modules/_io/bufferedio.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,7 @@ _buffered_raw_tell(buffered *self)
580580
if (n < 0) {
581581
if (!PyErr_Occurred())
582582
PyErr_Format(PyExc_IOError,
583-
"Raw stream returned invalid position %" PY_PRIdOFF,
584-
(PY_OFF_T_COMPAT)n);
583+
"Raw stream returned invalid position %zd", n);
585584
return -1;
586585
}
587586
self->abs_pos = n;
@@ -613,8 +612,7 @@ _buffered_raw_seek(buffered *self, Py_off_t target, int whence)
613612
if (n < 0) {
614613
if (!PyErr_Occurred())
615614
PyErr_Format(PyExc_IOError,
616-
"Raw stream returned invalid position %" PY_PRIdOFF,
617-
(PY_OFF_T_COMPAT)n);
615+
"Raw stream returned invalid position %zd", n);
618616
return -1;
619617
}
620618
self->abs_pos = n;

0 commit comments

Comments
 (0)