perf/scripts: Tuple was set from long in both branches in python_process_event()

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linux Kernel Mailing List
Date: Sunday, April 4, 2010 - 12:59 pm

Gitweb:     http://git.kernel.org/linus/b1dcc03cb8ee0f5718491e8c518257238dc64e00
Commit:     b1dcc03cb8ee0f5718491e8c518257238dc64e00
Parent:     8bb39f9aa068262732fe44b965d7a6eb5a5a7d67
Author:     Tom Zanussi <tzanussi@gmail.com>
AuthorDate: Thu Apr 1 23:58:25 2010 -0500
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Fri Apr 2 21:32:16 2010 +0200

    perf/scripts: Tuple was set from long in both branches in python_process_event()
    
    This is a fix to the signed/unsigned field handling in the
    Python scripting engine, based on a patch from Roel Kluin.
    
    Basically, Python wants to use a PyInt (which is internally a
    long) if it can i.e. if the value will fit into that type.  If
    not, it stores it into a PyLong, which isn't actually a long,
    but an arbitrary-precision integer variable.
    
    The code below is similar to to what Python does internally, and
    it seems to work as expected on the x86 and x86_64 sytems I
    tested it on.
    
    Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
    Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Roel Kluin <roel.kluin@gmail.com>
    Cc: Frederic Weisbecker <fweisbec@gmail.com>
    Cc: rostedt@goodmis.org
    LKML-Reference: <1270184305.6422.10.camel@tropicana>
    Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 .../util/scripting-engines/trace-event-python.c    |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index 33a414b..6a72f14 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -208,7 +208,7 @@ static void python_process_event(int cpu, void *data,
 				 int size __unused,
 				 unsigned long long nsecs, char *comm)
 {
-	PyObject *handler, *retval, *context, *t;
+	PyObject *handler, *retval, *context, *t, *obj;
 	static char handler_name[256];
 	struct format_field *field;
 	unsigned long long val;
@@ -256,16 +256,23 @@ static void python_process_event(int cpu, void *data,
 				offset &= 0xffff;
 			} else
 				offset = field->offset;
-			PyTuple_SetItem(t, n++,
-				PyString_FromString((char *)data + offset));
+			obj = PyString_FromString((char *)data + offset);
 		} else { /* FIELD_IS_NUMERIC */
 			val = read_size(data + field->offset, field->size);
 			if (field->flags & FIELD_IS_SIGNED) {
-				PyTuple_SetItem(t, n++, PyInt_FromLong(val));
+				if ((long long)val >= LONG_MIN &&
+				    (long long)val <= LONG_MAX)
+					obj = PyInt_FromLong(val);
+				else
+					obj = PyLong_FromLongLong(val);
 			} else {
-				PyTuple_SetItem(t, n++, PyInt_FromLong(val));
+				if (val <= LONG_MAX)
+					obj = PyInt_FromLong(val);
+				else
+					obj = PyLong_FromUnsignedLongLong(val);
 			}
 		}
+		PyTuple_SetItem(t, n++, obj);
 	}
 
 	if (_PyTuple_Resize(&t, n) == -1)
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
perf/scripts: Tuple was set from long in both branches in ..., Linux Kernel Mailing ..., (Sun Apr 4, 12:59 pm)