From: "Steven Rostedt (VMware)" <rostedt@xxxxxxxxxxx> Python 3 has deprecated PyBuffer_FromMemory() and instead has PyMemoryView_FromMemory(). Add a helper function that uses the latter if Python 3 is detected. As Python 2 is going to be EOL soon, we need to support Python 3. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=204231 Reported-by: Troy Engel <troyengel@xxxxxxxxx> Signed-off-by: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx> --- python/ctracecmd.i | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/python/ctracecmd.i b/python/ctracecmd.i index 09d1d6414fc1..63e5dcb813f1 100644 --- a/python/ctracecmd.i +++ b/python/ctracecmd.i @@ -117,6 +117,15 @@ static PyObject *py_field_get_stack(struct tep_handle *pevent, return list; } +static PyObject *fromMemory(void *buf, size_t len) +{ +#if PY_MAJOR_VERSION >= 3 + return PyMemoryView_FromMemory(buf, len, PyBUF_READ); +#else + return PyBuffer_FromMemory(buf, len); +#endif +} + static PyObject *py_field_get_data(struct tep_format_field *f, struct tep_record *r) { if (!strncmp(f->type, "__data_loc ", 11)) { @@ -137,10 +146,10 @@ static PyObject *py_field_get_data(struct tep_format_field *f, struct tep_record offset = val & 0xffff; len = val >> 16; - return PyBuffer_FromMemory((char *)r->data + offset, len); + return fromMemory(r->data + offset, len); } - return PyBuffer_FromMemory((char *)r->data + f->offset, f->size); + return fromMemory(r->data + f->offset, f->size); } static PyObject *py_field_get_str(struct tep_format_field *f, struct tep_record *r) -- 2.20.1