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 methane
Recipients methane, serhiy.storchaka, vstinner
Date 2019-12-19.10:04:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1576749870.0.0.934436255608.issue39087@roundup.psfhosted.org>
In-reply-to
Content
> 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);
}
History
Date User Action Args
2019-12-19 10:04:30methanesetrecipients: + methane, vstinner, serhiy.storchaka
2019-12-19 10:04:30methanesetmessageid: <1576749870.0.0.934436255608.issue39087@roundup.psfhosted.org>
2019-12-19 10:04:29methanelinkissue39087 messages
2019-12-19 10:04:29methanecreate