This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: printf %qd is nonstandard
Type: behavior Stage: resolved
Components: ctypes Versions: Python 3.8, Python 3.7, Python 3.6, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: John.Malmberg, ZackerySpytz, amaury.forgeotdarc, belopolsky, bugs-python@vendor.thewrittenword.com, ezio.melotti, hfuru, meador.inge, miss-islington, serhiy.storchaka
Priority: low Keywords: patch

Created on 2010-11-05 08:38 by hfuru, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 10853 merged ZackerySpytz, 2018-12-03 02:38
PR 10856 merged miss-islington, 2018-12-03 08:31
PR 10857 merged miss-islington, 2018-12-03 08:32
PR 10858 closed miss-islington, 2018-12-03 08:32
PR 11228 merged miss-islington, 2018-12-18 23:38
PR 11230 merged ZackerySpytz, 2018-12-19 00:19
Messages (11)
msg120473 - (view) Author: Hallvard B Furuseth (hfuru) Date: 2010-11-05 08:38
Modules/_ctypes/callproc.c:PyCArg_repr() uses sprintf(%qd, long long),
which is a GNU (and more?) extension.  ISO C99 says %lld.

Instead, use "%" PY_FORMAT_LONG_LONG "d" from pyconfig.h/pyport.h.
Kills off #ifdef MS_WIN32 too.  If Python must support C libraries
that handle %qd but not %lld, configure.in seems the right place.

Index: ./Modules/_ctypes/callproc.c
@@ -468,8 +468,3 @@ PyCArg_repr(PyCArgObject *self)
     case 'Q':
-        sprintf(buffer,
-#ifdef MS_WIN32
-            "<cparam '%c' (%I64d)>",
-#else
-            "<cparam '%c' (%qd)>",
-#endif
+        sprintf(buffer, "<cparam '%c' (%" PY_FORMAT_LONG_LONG "d)>",
             self->tag, self->value.q);

pyport.h tests (defined(MS_WIN64) || defined(MS_WINDOWS)) instead of
#ifdef MS_WIN32 for when to use %I64d. I assume that's more up to date.
msg142299 - (view) Author: Meador Inge (meador.inge) * (Python committer) Date: 2011-08-18 02:14
I agree that this violates C99, but is this actually causing any real world problems with the platforms Python supports?  If so, then we need a test case.  This seems low priority
msg145773 - (view) Author: The Written Word (bugs-python@vendor.thewrittenword.com) Date: 2011-10-18 05:58
Objects/stringobject.c already does something similar:
                else if (longlongflag)
                    sprintf(s, "%" PY_FORMAT_LONG_LONG "d",
                        va_arg(vargs, PY_LONG_LONG));
so it makes sense to do the same in Modules/_ctypes/callproc.c.
msg235566 - (view) Author: John Malmberg (John.Malmberg) * Date: 2015-02-08 20:07
OpenVMS needs %lld or "%" PY_FORMAT_LONG_LONG "d" in order to build the _ctypes module.
msg235567 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2015-02-08 20:19
As VMS is not supported I doubt that people here are too bothered about what is needed to build the _ctypes module on it.
msg330905 - (view) Author: Zackery Spytz (ZackerySpytz) * (Python triager) Date: 2018-12-03 02:40
I've created a PR for this issue.
msg330911 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-12-03 08:31
New changeset 062cbb67726f26794b1b461853e40696b4a0b220 by Serhiy Storchaka (Zackery Spytz) in branch 'master':
bpo-10320: Replace nonstandard sprintf() length modifier in ctypes' PyCArg_repr(). (GH-10853)
https://github.com/python/cpython/commit/062cbb67726f26794b1b461853e40696b4a0b220
msg330919 - (view) Author: miss-islington (miss-islington) Date: 2018-12-03 09:11
New changeset a9f435e5d856fb62516b70a78217e40b90bec233 by Miss Islington (bot) in branch '3.7':
bpo-10320: Replace nonstandard sprintf() length modifier in ctypes' PyCArg_repr(). (GH-10853)
https://github.com/python/cpython/commit/a9f435e5d856fb62516b70a78217e40b90bec233
msg330920 - (view) Author: miss-islington (miss-islington) Date: 2018-12-03 09:11
New changeset f65ede3f8fa08493facf48177540d0ec26e59560 by Miss Islington (bot) in branch '3.6':
bpo-10320: Replace nonstandard sprintf() length modifier in ctypes' PyCArg_repr(). (GH-10853)
https://github.com/python/cpython/commit/f65ede3f8fa08493facf48177540d0ec26e59560
msg332102 - (view) Author: miss-islington (miss-islington) Date: 2018-12-18 23:51
New changeset 53e2248a94cd89e65326c5cfd400f74a88552d8c by Miss Islington (bot) in branch '2.7':
bpo-10320: Replace nonstandard sprintf() length modifier in ctypes' PyCArg_repr(). (GH-10853)
https://github.com/python/cpython/commit/53e2248a94cd89e65326c5cfd400f74a88552d8c
msg332109 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-12-19 06:01
New changeset 838645dc4191c4109e2b300cf9ed9d481b55509f by Serhiy Storchaka (Zackery Spytz) in branch '2.7':
bpo-10320: Use PY_FORMAT_LONG_LONG in ctypes' PyCArg_repr(). (GH-11230)
https://github.com/python/cpython/commit/838645dc4191c4109e2b300cf9ed9d481b55509f
History
Date User Action Args
2022-04-11 14:57:08adminsetgithub: 54529
2018-12-19 09:18:08serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-12-19 06:01:45serhiy.storchakasetmessages: + msg332109
2018-12-19 00:19:00ZackerySpytzsetpull_requests: + pull_request10465
2018-12-18 23:51:06miss-islingtonsetmessages: + msg332102
2018-12-18 23:38:46miss-islingtonsetpull_requests: + pull_request10463
2018-12-03 16:27:30BreamoreBoysetnosy: - BreamoreBoy
2018-12-03 09:11:39miss-islingtonsetmessages: + msg330920
2018-12-03 09:11:33miss-islingtonsetnosy: + miss-islington
messages: + msg330919
2018-12-03 08:32:15miss-islingtonsetpull_requests: + pull_request10093
2018-12-03 08:32:01miss-islingtonsetpull_requests: + pull_request10092
2018-12-03 08:31:48miss-islingtonsetpull_requests: + pull_request10091
2018-12-03 08:31:37serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg330911
2018-12-03 02:40:01ZackerySpytzsetnosy: + ZackerySpytz

messages: + msg330905
versions: + Python 3.6, Python 3.7, Python 3.8, - Python 3.4, Python 3.5
2018-12-03 02:38:34ZackerySpytzsetkeywords: + patch
stage: test needed -> patch review
pull_requests: + pull_request10088
2015-02-08 20:19:41BreamoreBoysetnosy: + BreamoreBoy

messages: + msg235567
versions: + Python 3.4, Python 3.5, - Python 3.1, Python 3.2
2015-02-08 20:07:49John.Malmbergsetnosy: + John.Malmberg
messages: + msg235566
2011-10-18 06:01:04ezio.melottisetnosy: + ezio.melotti
2011-10-18 05:58:12bugs-python@vendor.thewrittenword.comsetnosy: + bugs-python@vendor.thewrittenword.com
messages: + msg145773
2011-08-18 02:14:50meador.ingesetpriority: normal -> low

nosy: + amaury.forgeotdarc, meador.inge, belopolsky, - theller
messages: + msg142299

assignee: theller ->
stage: test needed
2010-11-05 08:38:07hfurucreate