Message ID | 20190719225030.187908166@goodmis.org (mailing list archive) |
---|---|
State | Accepted |
Commit | ff3c2189ddbd17fb0a333bc8f9e23a2b8481ee61 |
Headers | show |
Series | trace-cmd: Update python plugin for Python 3 | expand |
On Fri, 2019-07-19 at 18:46 -0400, Steven Rostedt wrote: > --- a/python/ctracecmd.i > +++ b/python/ctracecmd.i > @@ -108,7 +108,7 @@ static PyObject *py_field_get_stack(struct tep_handle *pevent, > ((int)addr == -1)) > break; > func = tep_find_function(event->tep, addr); > - if (PyList_Append(list, PyString_FromString(func))) { > + if (PyList_Append(list, PyUnicode_FromString(func))) { > Py_DECREF(list); This assumes that the source code is not using extended identifiers (per C99, gcc -fextended-identifiers). I think that's probably a reasonable assumption :-) In theory, a bit safer would be to use PyBytes_FromString() and let the python plugin worry about the encoding. That really applies to all of the instances here, I think, since the strings eventually come from (macros in the) code. Reviewed-by: Johannes Berg <johannes@sipsolutions.net> johannes
diff --git a/python/ctracecmd.i b/python/ctracecmd.i index 65a3d5144b88..09d1d6414fc1 100644 --- a/python/ctracecmd.i +++ b/python/ctracecmd.i @@ -108,7 +108,7 @@ static PyObject *py_field_get_stack(struct tep_handle *pevent, ((int)addr == -1)) break; func = tep_find_function(event->tep, addr); - if (PyList_Append(list, PyString_FromString(func))) { + if (PyList_Append(list, PyUnicode_FromString(func))) { Py_DECREF(list); return NULL; } @@ -162,10 +162,10 @@ static PyObject *py_field_get_str(struct tep_format_field *f, struct tep_record */ offset = val & 0xffff; - return PyString_FromString((char *)r->data + offset); + return PyUnicode_FromString((char *)r->data + offset); } - return PyString_FromStringAndSize((char *)r->data + f->offset, + return PyUnicode_FromStringAndSize((char *)r->data + f->offset, strnlen((char *)r->data + f->offset, f->size)); } @@ -177,7 +177,7 @@ static PyObject *py_format_get_keys(struct tep_event *ef) list = PyList_New(0); for (f = ef->format.fields; f; f = f->next) { - if (PyList_Append(list, PyString_FromString(f->name))) { + if (PyList_Append(list, PyUnicode_FromString(f->name))) { Py_DECREF(list); return NULL; }