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: PyArg_ParseTuple y* documentation is incorrect
Type: enhancement Stage: patch review
Components: Documentation Versions: Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, terrence, vstinner
Priority: normal Keywords: patch

Created on 2010-07-05 01:44 by terrence, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
PyArgs_ParseTuple_ystar_doc_fix.patch terrence, 2010-07-05 01:44 trivial patch
Messages (5)
msg109285 - (view) Author: Terrence Cole (terrence) Date: 2010-07-05 01:44
The documented C type for y* should be [Py_buffer], not [Py_buffer *], as with the documentation for z* and the convention followed by the other types.

I'm not sure what 'type' this issue should have.  I've set it at 'crash' initially, since that's how the bug manifested for me.
msg109290 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-07-05 03:29
y* and z* result is a Py_buffer, but in C you have to pass a reference to the result variable using &result. Full example:

static PyObject *
getargs_y_star(PyObject *self, PyObject *args)
{
    Py_buffer buffer;
    PyObject *bytes;
    if (!PyArg_ParseTuple(args, "y*", &buffer))
        return NULL;
    bytes = PyBytes_FromStringAndSize(buffer.buf, buffer.len);
    PyBuffer_Release(&buffer);
    return bytes;
}

Another example: "s" format result is char* (and not char**). You also have to pass a reference using &:

static PyObject *
getargs_s(PyObject *self, PyObject *args)
{
    char *str;
    if (!PyArg_ParseTuple(args, "s", &str))
        return NULL;
    return PyBytes_FromString(str);
}
msg109349 - (view) Author: Terrence Cole (terrence) Date: 2010-07-05 19:29
@Victor: "y* and z* result is a Py_buffer"

Correct, so why is z* documented as [Py_buffer] and y* documented as [Py_buffer*]?  If I make 'buffer' from your example a Py_buffer*, as documented, then python puts writes sizeof(Py_buffer) bytes into a random spot in memory.  Thus the attached patch.

Thanks for giving this a look, but I don't think this issue is closed -- the documentation for y* is still wrong.
msg109357 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-07-05 21:39
Oh ok, sorry. Fixed in r82597 (3.x) and r82598 (3.1).
msg109361 - (view) Author: Terrence Cole (terrence) Date: 2010-07-05 22:51
Awesome!  Thanks, and sorry for communicating the problem so poorly initially.
History
Date User Action Args
2022-04-11 14:57:03adminsetgithub: 53404
2010-07-05 22:51:12terrencesetmessages: + msg109361
2010-07-05 21:39:06vstinnersetresolution: not a bug -> fixed
messages: + msg109357
2010-07-05 19:29:46terrencesetmessages: + msg109349
2010-07-05 03:29:35vstinnersetstatus: open -> closed
resolution: not a bug
messages: + msg109290
2010-07-05 01:47:50ezio.melottisetnosy: + vstinner

type: crash -> enhancement
stage: patch review
2010-07-05 01:44:19terrencecreate