[New-bugs-announce] [issue10832] Add support of bytes objects in PyBytes_FromFormatV()

STINNER Victor report at bugs.python.org
Wed Jan 5 03:55:10 CET 2011

New submission from STINNER Victor <victor.stinner at haypocalc.com>:

It would be very practical use have a format, eg. '%y', to accept bytes object in PyBytes_FromFormatV().

Example (extracted from posixmodule.c):

        k = PyBytes_AsString(key2);
        v = PyBytes_AsString(val2);
        len = PyBytes_GET_SIZE(key2) + PyBytes_GET_SIZE(val2) + 2;
        p = PyMem_NEW(char, len);
        if (p == NULL) { PyErr_NoMemory(); ... }
        PyOS_snprintf(p, len, "%s=%s", k, v);

With %y, it can be written:

        p = PyBytes_FromFormat("%y=%y", key2, val2);
        if (p == NULL) { PyErr_NoMemory(); ... }

The '%y' may also accept bytearray and any object with the buffer interface (as the 'y' format of PyArg_Parse*() functions).

components: Interpreter Core
messages: 125398
nosy: haypo
priority: normal
severity: normal
status: open
title: Add support of bytes objects in PyBytes_FromFormatV()
versions: Python 3.3

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list