[New-bugs-announce] [issue28415] PyUnicode_FromFromat interger format handling different from printf about zeropad

Xiang Zhang report at bugs.python.org
Tue Oct 11 04:56:20 EDT 2016


New submission from Xiang Zhang:

Although declared *exactly equivalent* to printf in the doc, PyUnicode_FromFormat could generate different result from printf with the same format.

For example:

from ctypes import pythonapi, py_object, c_int
f = getattr(pythonapi, 'PyUnicode_FromFormat')
f.restype = py_object
f(b'%010.5d', c_int(100))
'0000000100'

while printf outputs:

printf("%010.5d\n", 100);
     00100

I use both gcc and clang to compile and get the same result. gcc gives me a warning:

warning: '0' flag ignored with precision and ‘%d’ gnu_printf format

I am not sure this should be fixed. It seems the change could break backwards compatibility.

----------
components: Interpreter Core
messages: 278467
nosy: haypo, serhiy.storchaka, xiang.zhang
priority: normal
severity: normal
status: open
title: PyUnicode_FromFromat interger format handling different from printf about zeropad
type: behavior
versions: Python 3.5, Python 3.6, Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28415>
_______________________________________


More information about the New-bugs-announce mailing list