perf/scripts: Tuple was set from long in both branches in python_process_event()
[linux-2.6.git] / tools / perf / util / scripting-engines / trace-event-python.c
index d402f64..6a72f14 100644 (file)
@@ -68,7 +68,7 @@ static void define_value(enum print_arg_type field_type,
        if (field_type == PRINT_SYMBOL)
                handler_name = "define_symbolic_value";
 
-       t = PyTuple_New(MAX_FIELDS);
+       t = PyTuple_New(4);
        if (!t)
                Py_FatalError("couldn't create Python tuple");
 
@@ -79,9 +79,6 @@ static void define_value(enum print_arg_type field_type,
        PyTuple_SetItem(t, n++, PyInt_FromLong(value));
        PyTuple_SetItem(t, n++, PyString_FromString(field_str));
 
-       if (_PyTuple_Resize(&t, n) == -1)
-               Py_FatalError("error resizing Python tuple");
-
        handler = PyDict_GetItemString(main_dict, handler_name);
        if (handler && PyCallable_Check(handler)) {
                retval = PyObject_CallObject(handler, t);
@@ -116,7 +113,10 @@ static void define_field(enum print_arg_type field_type,
        if (field_type == PRINT_SYMBOL)
                handler_name = "define_symbolic_field";
 
-       t = PyTuple_New(MAX_FIELDS);
+       if (field_type == PRINT_FLAGS)
+               t = PyTuple_New(3);
+       else
+               t = PyTuple_New(2);
        if (!t)
                Py_FatalError("couldn't create Python tuple");
 
@@ -125,9 +125,6 @@ static void define_field(enum print_arg_type field_type,
        if (field_type == PRINT_FLAGS)
                PyTuple_SetItem(t, n++, PyString_FromString(delim));
 
-       if (_PyTuple_Resize(&t, n) == -1)
-               Py_FatalError("error resizing Python tuple");
-
        handler = PyDict_GetItemString(main_dict, handler_name);
        if (handler && PyCallable_Check(handler)) {
                retval = PyObject_CallObject(handler, t);
@@ -211,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;
@@ -259,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)