Message109290
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);
} |
|
Date |
User |
Action |
Args |
2010-07-05 03:29:36 | vstinner | set | recipients:
+ vstinner, terrence, docs@python |
2010-07-05 03:29:36 | vstinner | set | messageid: <1278300576.51.0.579638884987.issue9158@psf.upfronthosting.co.za> |
2010-07-05 03:29:35 | vstinner | link | issue9158 messages |
2010-07-05 03:29:35 | vstinner | create | |
|