[New-bugs-announce] [issue10320] printf %qd is nonstandard

Hallvard B Furuseth report at bugs.python.org
Fri Nov 5 09:38:09 CET 2010

New submission from Hallvard B Furuseth <h.b.furuseth at usit.uio.no>:

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)>",
-            "<cparam '%c' (%qd)>",
+        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.

assignee: theller
components: ctypes
messages: 120473
nosy: hfuru, theller
priority: normal
severity: normal
status: open
title: printf %qd is nonstandard
type: behavior
versions: Python 2.7, Python 3.1, Python 3.2

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list