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.

Author vstinner
Recipients docs@python, terrence, vstinner
Date 2010-07-05.03:29:34
SpamBayes Score 0.0048764744
Marked as misclassified No
Message-id <1278300576.51.0.579638884987.issue9158@psf.upfronthosting.co.za>
In-reply-to
Content
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);
}
History
Date User Action Args
2010-07-05 03:29:36vstinnersetrecipients: + vstinner, terrence, docs@python
2010-07-05 03:29:36vstinnersetmessageid: <1278300576.51.0.579638884987.issue9158@psf.upfronthosting.co.za>
2010-07-05 03:29:35vstinnerlinkissue9158 messages
2010-07-05 03:29:35vstinnercreate