Linux-Trace-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/3] trace-cmd: More Python 3 cleanups
@ 2019-07-25 17:41 Patrick McLean
  2019-07-25 17:41 ` [PATCH 1/3] trace-cmd: in python plugin, use PyUnicode_FromString on Python 3 Patrick McLean
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Patrick McLean @ 2019-07-25 17:41 UTC (permalink / raw)
  To: linux-trace-devel

Some more cleanups for Python 3, these mostly fix warnings that are
generated when building the Python portions of the code for Python 3.

Patrick McLean (3):
      trace-cmd: in python plugin, use PyUnicode_FromString on Python 3
      trace-cmd: Add missing headers to Python template
      trace-cmd: In the ctracecmdgui use PyLong on Python 3



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] trace-cmd: in python plugin, use PyUnicode_FromString on Python 3
  2019-07-25 17:41 [PATCH 0/3] trace-cmd: More Python 3 cleanups Patrick McLean
@ 2019-07-25 17:41 ` Patrick McLean
  2019-07-25 18:04   ` Steven Rostedt
  2019-07-25 17:41 ` [PATCH 2/3] trace-cmd: Add missing headers to Python template Patrick McLean
  2019-07-25 17:41 ` [PATCH 3/3] trace-cmd: In the ctracecmdgui use PyLong on Python 3 Patrick McLean
  2 siblings, 1 reply; 6+ messages in thread
From: Patrick McLean @ 2019-07-25 17:41 UTC (permalink / raw)
  To: linux-trace-devel

From: Patrick McLean <patrick.mclean@sony.com>

All strings are unicode in Python 3, so PyString_* is no longer
reccommended. This uses PyUnicode_* instead.

Signed-off-by: Patrick McLean <patrick.mclean@sony.com>
---
 plugins/plugin_python.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/plugins/plugin_python.c b/plugins/plugin_python.c
index e725ad8..dc7932e 100644
--- a/plugins/plugin_python.c
+++ b/plugins/plugin_python.c
@@ -81,7 +81,11 @@ int TEP_PLUGIN_LOADER(struct tep_handle *pevent)
 	} else
 		Py_DECREF(res);
 
+#if PY_MAJOR_VERSION >= 3
+	str = PyUnicode_FromString("pevent");
+#else
 	str = PyString_FromString("pevent");
+#endif
 	if (!str)
 		return -ENOMEM;
 
-- 
2.22.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/3] trace-cmd: Add missing headers to Python template
  2019-07-25 17:41 [PATCH 0/3] trace-cmd: More Python 3 cleanups Patrick McLean
  2019-07-25 17:41 ` [PATCH 1/3] trace-cmd: in python plugin, use PyUnicode_FromString on Python 3 Patrick McLean
@ 2019-07-25 17:41 ` Patrick McLean
  2019-07-25 17:41 ` [PATCH 3/3] trace-cmd: In the ctracecmdgui use PyLong on Python 3 Patrick McLean
  2 siblings, 0 replies; 6+ messages in thread
From: Patrick McLean @ 2019-07-25 17:41 UTC (permalink / raw)
  To: linux-trace-devel

From: Patrick McLean <patrick.mclean@sony.com>

The templates that generate Python bindings are missing some headers
that result in compile-time warnings. This adds the missing headers
where needed.

Signed-off-by: Patrick McLean <patrick.mclean@sony.com>
---
 python/ctracecmd.i    | 1 +
 python/ctracecmdgui.i | 1 +
 2 files changed, 2 insertions(+)

diff --git a/python/ctracecmd.i b/python/ctracecmd.i
index 2601d39..01cd0d5 100644
--- a/python/ctracecmd.i
+++ b/python/ctracecmd.i
@@ -16,6 +16,7 @@
 %{
 #include "trace-cmd.h"
 #include "event-utils.h"
+#include <Python.h>
 %}
 
 
diff --git a/python/ctracecmdgui.i b/python/ctracecmdgui.i
index 1dcdab0..032f3ff 100644
--- a/python/ctracecmdgui.i
+++ b/python/ctracecmdgui.i
@@ -7,6 +7,7 @@
 #include <pygobject.h>
 #include <pyglib.h>
 #include <Python.h>
+#include <memoryobject.h>
 
 extern GtkTreeModel *trace_view_store_as_gtk_tree_model(struct trace_view_store *store);
 
-- 
2.22.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/3] trace-cmd: In the ctracecmdgui use PyLong on Python 3
  2019-07-25 17:41 [PATCH 0/3] trace-cmd: More Python 3 cleanups Patrick McLean
  2019-07-25 17:41 ` [PATCH 1/3] trace-cmd: in python plugin, use PyUnicode_FromString on Python 3 Patrick McLean
  2019-07-25 17:41 ` [PATCH 2/3] trace-cmd: Add missing headers to Python template Patrick McLean
@ 2019-07-25 17:41 ` Patrick McLean
  2 siblings, 0 replies; 6+ messages in thread
From: Patrick McLean @ 2019-07-25 17:41 UTC (permalink / raw)
  To: linux-trace-devel

From: Patrick McLean <patrick.mclean@sony.com>

Python 3 does not have PyInt anymore, so use the PyLong_* functions when
building on Python 3.

Signed-off-by: Patrick McLean <patrick.mclean@sony.com>
---
 python/ctracecmdgui.i | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/python/ctracecmdgui.i b/python/ctracecmdgui.i
index 032f3ff..4a7c6ac 100644
--- a/python/ctracecmdgui.i
+++ b/python/ctracecmdgui.i
@@ -37,12 +37,21 @@ pytype_from_gtype(GType gtype)
 }
 
 /* help swig cope with g* types */
+#if PY_MAJOR_VERSION >= 3
+%typemap(in) gint {
+    $1 = PyLong_AsLong($input);
+}
+%typemap(out) gint {
+    $result = PyLong_FromLong($1);
+}
+#else
 %typemap(in) gint {
     $1 = PyInt_AsLong($input);
 }
 %typemap(out) gint {
     $result = PyInt_FromLong($1);
 }
+#endif
 %typemap(in) guint {
     $1 = PyLong_AsUnsignedLong($input);
 }
-- 
2.22.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] trace-cmd: in python plugin, use PyUnicode_FromString on Python 3
  2019-07-25 17:41 ` [PATCH 1/3] trace-cmd: in python plugin, use PyUnicode_FromString on Python 3 Patrick McLean
@ 2019-07-25 18:04   ` Steven Rostedt
  2019-07-25 19:28     ` Steven Rostedt
  0 siblings, 1 reply; 6+ messages in thread
From: Steven Rostedt @ 2019-07-25 18:04 UTC (permalink / raw)
  To: Patrick McLean; +Cc: linux-trace-devel

On Thu, 25 Jul 2019 10:41:36 -0700
Patrick McLean <chutzpah@gentoo.org> wrote:

> From: Patrick McLean <patrick.mclean@sony.com>
> 
> All strings are unicode in Python 3, so PyString_* is no longer
> reccommended. This uses PyUnicode_* instead.
> 
> Signed-off-by: Patrick McLean <patrick.mclean@sony.com>
> ---
>  plugins/plugin_python.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/plugins/plugin_python.c b/plugins/plugin_python.c
> index e725ad8..dc7932e 100644
> --- a/plugins/plugin_python.c
> +++ b/plugins/plugin_python.c
> @@ -81,7 +81,11 @@ int TEP_PLUGIN_LOADER(struct tep_handle *pevent)
>  	} else
>  		Py_DECREF(res);
>  
> +#if PY_MAJOR_VERSION >= 3
> +	str = PyUnicode_FromString("pevent");
> +#else
>  	str = PyString_FromString("pevent");
> +#endif

I believe using just PyUnicode_FromString() will work for both v2 and
v3. That's what I did in my other patches.

-- Steve

>  	if (!str)
>  		return -ENOMEM;
>  


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] trace-cmd: in python plugin, use PyUnicode_FromString on Python 3
  2019-07-25 18:04   ` Steven Rostedt
@ 2019-07-25 19:28     ` Steven Rostedt
  0 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2019-07-25 19:28 UTC (permalink / raw)
  To: Patrick McLean; +Cc: linux-trace-devel

On Thu, 25 Jul 2019 14:04:09 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:

> > --- a/plugins/plugin_python.c
> > +++ b/plugins/plugin_python.c
> > @@ -81,7 +81,11 @@ int TEP_PLUGIN_LOADER(struct tep_handle *pevent)
> >  	} else
> >  		Py_DECREF(res);
> >  
> > +#if PY_MAJOR_VERSION >= 3
> > +	str = PyUnicode_FromString("pevent");
> > +#else
> >  	str = PyString_FromString("pevent");
> > +#endif  
> 
> I believe using just PyUnicode_FromString() will work for both v2 and
> v3. That's what I did in my other patches.

FYI, I applied this instead:

-- Steve

From ccca93c8f24b66beea1d68b7207e8de1ede8d108 Mon Sep 17 00:00:00 2001
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
Date: Thu, 25 Jul 2019 15:20:10 -0400
Subject: [PATCH] trace-cmd: Replace PyString_FromString() with
 PyUnicode_FromString()

As PyString_FromString() is no longer available with Python 3, use
PyUnicode_FromString() which is available in both Python 2 and 3.

Link: http://lkml.kernel.org/r/20190725174138.3724131-2-chutzpah@gentoo.org

Reported-by: Patrick McLean <patrick.mclean@sony.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 plugins/plugin_python.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/plugins/plugin_python.c b/plugins/plugin_python.c
index e725ad84..196b8256 100644
--- a/plugins/plugin_python.c
+++ b/plugins/plugin_python.c
@@ -81,7 +81,7 @@ int TEP_PLUGIN_LOADER(struct tep_handle *pevent)
 	} else
 		Py_DECREF(res);
 
-	str = PyString_FromString("pevent");
+	str = PyUnicode_FromString("pevent");
 	if (!str)
 		return -ENOMEM;
 
-- 
2.20.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-25 17:41 [PATCH 0/3] trace-cmd: More Python 3 cleanups Patrick McLean
2019-07-25 17:41 ` [PATCH 1/3] trace-cmd: in python plugin, use PyUnicode_FromString on Python 3 Patrick McLean
2019-07-25 18:04   ` Steven Rostedt
2019-07-25 19:28     ` Steven Rostedt
2019-07-25 17:41 ` [PATCH 2/3] trace-cmd: Add missing headers to Python template Patrick McLean
2019-07-25 17:41 ` [PATCH 3/3] trace-cmd: In the ctracecmdgui use PyLong on Python 3 Patrick McLean

Linux-Trace-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-trace-devel/0 linux-trace-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-trace-devel linux-trace-devel/ https://lore.kernel.org/linux-trace-devel \
		linux-trace-devel@vger.kernel.org linux-trace-devel@archiver.kernel.org
	public-inbox-index linux-trace-devel


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-trace-devel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox