Message358665
> Would it be possible to use a "container" object like a Py_buffer? Is there a way to customize the code executed when a Py_buffer is "released"?
It looks nice idea! Py_buffer.obj is decref-ed when releasing the buffer.
https://docs.python.org/3/c-api/buffer.html#c.PyBuffer_Release
int PyUnicode_GetUTF8Buffer(PyObject *unicode, Py_buffer *view)
{
if (!PyUnicode_Check(unicode)) {
PyErr_BadArgument();
return NULL;
}
if (PyUnicode_READY(unicode) == -1) {
return NULL;
}
if (PyUnicode_UTF8(unicode) != NULL) {
return PyBuffer_FillInfo(view, unicode,
PyUnicode_UTF8(unicode),
PyUnicode_UTF8_LENGTH(unicode),
1, PyBUF_CONTIG_RO);
}
PyObject *bytes = _PyUnicode_AsUTF8String(unicode, NULL);
if (bytes == NULL) {
return NULL;
}
return PyBytesType.tp_as_buffer(bytes, view, PyBUF_CONTIG_RO);
} |
|
Date |
User |
Action |
Args |
2019-12-19 10:04:30 | methane | set | recipients:
+ methane, vstinner, serhiy.storchaka |
2019-12-19 10:04:30 | methane | set | messageid: <1576749870.0.0.934436255608.issue39087@roundup.psfhosted.org> |
2019-12-19 10:04:29 | methane | link | issue39087 messages |
2019-12-19 10:04:29 | methane | create | |
|