[issue9158] PyArg_ParseTuple y* documentation is incorrect
STINNER Victor
report at bugs.python.org
Mon Jul 5 05:29:36 CEST 2010
STINNER Victor <victor.stinner at haypocalc.com> added the comment:
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);
}
----------
resolution: -> invalid
status: open -> closed
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9158>
_______________________________________
More information about the Python-bugs-list
mailing list