aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt (VMware) <rostedt@goodmis.org>2019-07-19 18:46:15 -0400
committerSteven Rostedt (VMware) <rostedt@goodmis.org>2019-07-23 09:10:09 -0400
commitdbddc64834a7ab93a9ea47e0d2a8fb97185138ec (patch)
tree43f99d57dcc80fbcf69c0421cbfb0bfa2858439f
parentff3c2189ddbd17fb0a333bc8f9e23a2b8481ee61 (diff)
downloadtrace-cmd-dbddc64834a7ab93a9ea47e0d2a8fb97185138ec.tar.gz
trace-cmd: Use PyMemoryView_FromMemory() for Python 3
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 Link: http://lore.kernel.org/linux-trace-devel/20190719225030.345100829@goodmis.org Reported-by: Troy Engel <troyengel@gmail.com> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
-rw-r--r--python/ctracecmd.i13
1 files changed, 11 insertions, 2 deletions
diff --git a/python/ctracecmd.i b/python/ctracecmd.i
index 09d1d641..63e5dcb8 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)