]> sourceware.org Git - systemtap.git/commitdiff
Add constants to the python C extension module.
authorDavid Smith <dsmith@redhat.com>
Thu, 27 Oct 2016 17:56:58 +0000 (12:56 -0500)
committerDavid Smith <dsmith@redhat.com>
Thu, 27 Oct 2016 17:56:58 +0000 (12:56 -0500)
* python/HelperSDT/_HelperSDT.c (init_HelperSDT): Export PyTrace_*
  constants.
* python/HelperSDT/__init__.py (Dispatcher.pytrace_dispatch): Use
  PyTrace_* constants.

python/HelperSDT/_HelperSDT.c
python/HelperSDT/__init__.py

index ba16d61d66ab3aaf822f1717bb6041e629ae2364..af8c0ecca3aba93251ae80711215c2b23c1b30b8 100644 (file)
@@ -21,35 +21,31 @@ trace_callback(PyObject *self, PyObject *args)
 
     /* We want to name the probes with the same name as the
      * define. This is tricky, so, we'll just save the define,
-     * undefine it, call the STAP_PROBE2 macro, then redfine it. */
+     * undefine it, call the STAP_PROBE macro, then redfine it. */
     switch (what) {
     case PyTrace_CALL:
-#define _PyTrace_CALL PyTrace_CALL
+#pragma push_macro("PyTrace_CALL")
 #undef PyTrace_CALL
        STAP_PROBE2(HelperSDT, PyTrace_CALL, frame_obj, arg_obj);
-#define PyTrace_CALL _PyTrace_CALL
-#undef _PyTrace_CALL
+#pragma pop_macro("PyTrace_CALL")
        break;
     case PyTrace_EXCEPTION:
-#define _PyTrace_EXCEPTION PyTrace_EXCEPTION
+#pragma push_macro("PyTrace_EXCEPTION")
 #undef PyTrace_EXCEPTION
        STAP_PROBE2(HelperSDT, PyTrace_EXCEPTION, frame_obj, arg_obj);
-#define PyTrace_EXCEPTION _PyTrace_EXCEPTION
-#undef _PyTrace_EXCEPTION
+#pragma pop_macro("PyTrace_EXCEPTION")
        break;
     case PyTrace_LINE:
-#define _PyTrace_LINE PyTrace_LINE
+#pragma push_macro("PyTrace_LINE")
 #undef PyTrace_LINE
        STAP_PROBE2(HelperSDT, PyTrace_LINE, frame_obj, arg_obj);
-#define PyTrace_LINE _PyTrace_LINE
-#undef _PyTrace_LINE
+#pragma pop_macro("PyTrace_LINE")
        break;
     case PyTrace_RETURN:
-#define _PyTrace_RETURN PyTrace_RETURN
+#pragma push_macro("PyTrace_RETURN")
 #undef PyTrace_RETURN
        STAP_PROBE2(HelperSDT, PyTrace_RETURN, frame_obj, arg_obj);
-#define PyTrace_RETURN _PyTrace_RETURN
-#undef _PyTrace_RETURN
+#pragma pop_macro("PyTrace_RETURN")
        break;
     // FIXME: What about PyTrace_C_CALL, PyTrace_C_EXCEPTION,
     // PyTrace_C_RETURN? Fold them into their non-'_C_' versions or
@@ -122,11 +118,20 @@ init_HelperSDT(void)
     module = PyModule_Create(&moduledef);
     if (module == NULL)
        return NULL;
-    return module;
 #else
     module = Py_InitModule3("_HelperSDT", HelperSDT_methods,
                            HelperSDT_doc);
     if (module == NULL)
        return;
 #endif
+
+    // Add constants for the PyTrace_* values we use.
+    PyModule_AddIntMacro(module, PyTrace_CALL);
+    PyModule_AddIntMacro(module, PyTrace_EXCEPTION);
+    PyModule_AddIntMacro(module, PyTrace_LINE);
+    PyModule_AddIntMacro(module, PyTrace_RETURN);
+
+#if PY_MAJOR_VERSION >= 3
+    return module;
+#endif
 }
index 8e4c7b5623833fcfb2b51268bd0b9c7d8ceda8b9..552d48e1f8ac975188b47e24af4ce3a7260ca54e 100644 (file)
@@ -156,7 +156,8 @@ class Dispatcher(cmd.Cmd):
                     sys.stdout.write("CALL: %s %s\n"
                                      % (frame.f_code.co_filename,
                                         frame.f_code.co_name))
-                    _HelperSDT.trace_callback(0, frame, arg)
+                    _HelperSDT.trace_callback(_HelperSDT.PyTrace_CALL,
+                                              frame, arg)
             return self.pytrace_dispatch
         elif event == 'line':
             bplist = self._bplist.break_here(frame, event)
@@ -165,7 +166,8 @@ class Dispatcher(cmd.Cmd):
                     sys.stdout.write("LINE: %s %s %d\n"
                                      % (frame.f_code.co_filename,
                                         frame.f_code.co_name, frame.f_lineno))
-                    _HelperSDT.trace_callback(2, frame, arg)
+                    _HelperSDT.trace_callback(_HelperSDT.PyTrace_LINE,
+                                              frame, arg)
             return self.pytrace_dispatch
         elif event == 'return':
             bplist = self._bplist.break_here(frame, event)
@@ -174,7 +176,8 @@ class Dispatcher(cmd.Cmd):
                     sys.stdout.write("RETURN: %s %s %d\n"
                                      % (frame.f_code.co_filename,
                                         frame.f_code.co_name, frame.f_lineno))
-                    _HelperSDT.trace_callback(3, frame, arg)
+                    _HelperSDT.trace_callback(_HelperSDT.PyTrace_RETURN,
+                                              frame, arg)
             return self.pytrace_dispatch
         return self.pytrace_dispatch
 
This page took 0.028774 seconds and 5 git commands to generate.