-devel mergeback
[cython.git] / Cython / Compiler / Nodes.py
index b0ba4da1e08db3e6b53cb6e54d0e6fb068264f8a..a3e78a9f7976db801363e0a294d67ad274e1d607 100644 (file)
@@ -1029,14 +1029,11 @@ class FuncDefNode(StatNode, BlockNode):
         is_getbuffer_slot = (self.entry.name == "__getbuffer__" and
                              self.entry.scope.is_c_class_scope)
         
-        if code.globalstate.directives['profile'] is None:
-            profile = 'inline' not in self.modifiers and not lenv.nogil
-        else:
-            profile = code.globalstate.directives['profile']
-            if profile and lenv.nogil:
-                error(self.pos, "Cannot profile nogil function.")
+        profile = code.globalstate.directives['profile']
         if profile:
-            code.globalstate.use_utility_code(trace_utility_code)
+            if lenv.nogil:
+                error(self.pos, "Cannot profile nogil function.")
+            code.globalstate.use_utility_code(profile_utility_code)
 
         # Generate C code for header and body of function
         code.enter_cfunc_scope()
@@ -5655,22 +5652,22 @@ proto="""
 # Note that cPython ignores PyTrace_EXCEPTION, 
 # but maybe some other profilers don't. 
 
-trace_utility_code = UtilityCode(proto="""
-#ifndef CYTHON_TRACING
-#define CYTHON_TRACING 1
+profile_utility_code = UtilityCode(proto="""
+#ifndef CYTHON_PROFILE
+#define CYTHON_PROFILE 1
 #endif
 
-#ifndef CYTHON_TRACING_REUSE_FRAME
-#define CYTHON_TRACING_REUSE_FRAME 0
+#ifndef CYTHON_PROFILE_REUSE_FRAME
+#define CYTHON_PROFILE_REUSE_FRAME 0
 #endif
 
-#if CYTHON_TRACING
+#if CYTHON_PROFILE
 
 #include "compile.h"
 #include "frameobject.h"
 #include "traceback.h"
 
-#if CYTHON_TRACING_REUSE_FRAME
+#if CYTHON_PROFILE_REUSE_FRAME
 #define CYTHON_FRAME_MODIFIER static
 #define CYTHON_FRAME_DEL
 #else
@@ -5682,12 +5679,12 @@ trace_utility_code = UtilityCode(proto="""
 static PyCodeObject *%(FRAME_CODE)s = NULL;                                        \\
 CYTHON_FRAME_MODIFIER PyFrameObject *%(FRAME)s = NULL;                             \\
 int __Pyx_use_tracing = 0;                                                         \\
-if (PyThreadState_GET()->use_tracing && PyThreadState_GET()->c_profilefunc) {      \\
+if (unlikely(PyThreadState_GET()->use_tracing && PyThreadState_GET()->c_profilefunc)) {      \\
     __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&%(FRAME_CODE)s, &%(FRAME)s, funcname, srcfile, firstlineno);  \\
 }
 
 #define __Pyx_TraceException()                                                           \\
-if (__Pyx_use_tracing && PyThreadState_GET()->use_tracing && PyThreadState_GET()->c_profilefunc) {  \\
+if (unlikely(__Pyx_use_tracing( && PyThreadState_GET()->use_tracing && PyThreadState_GET()->c_profilefunc) {  \\
     PyObject *exc_info = __Pyx_GetExceptionTuple();                                      \\
     if (exc_info) {                                                                      \\
         PyThreadState_GET()->c_profilefunc(                                              \\
@@ -5697,7 +5694,7 @@ if (__Pyx_use_tracing && PyThreadState_GET()->use_tracing && PyThreadState_GET()
 }
 
 #define __Pyx_TraceReturn(result)                                                  \\
-if (__Pyx_use_tracing && PyThreadState_GET()->use_tracing && PyThreadState_GET()->c_profilefunc) {  \\
+if (unlikely(__Pyx_use_tracing) && PyThreadState_GET()->use_tracing && PyThreadState_GET()->c_profilefunc) {  \\
     PyThreadState_GET()->c_profilefunc(                                            \\
         PyThreadState_GET()->c_profileobj, %(FRAME)s, PyTrace_RETURN, (PyObject*)result);     \\
     CYTHON_FRAME_DEL;                                                               \\
@@ -5710,7 +5707,7 @@ static int __Pyx_TraceSetupAndCall(PyCodeObject** code, PyFrameObject** frame, c
 #define __Pyx_TraceCall(funcname, srcfile, firstlineno) 
 #define __Pyx_TraceException() 
 #define __Pyx_TraceReturn(result) 
-#endif /* CYTHON_TRACING */
+#endif /* CYTHON_PROFILE */
 """ 
 % {
     "FRAME": Naming.frame_cname,
@@ -5718,14 +5715,14 @@ static int __Pyx_TraceSetupAndCall(PyCodeObject** code, PyFrameObject** frame, c
 },
 impl = """
 
-#if CYTHON_TRACING
+#if CYTHON_PROFILE
 
 static int __Pyx_TraceSetupAndCall(PyCodeObject** code,
                                    PyFrameObject** frame,
                                    const char *funcname,
                                    const char *srcfile,
                                    int firstlineno) {
-    if (*frame == NULL || !CYTHON_TRACING_REUSE_FRAME) {
+    if (*frame == NULL || !CYTHON_PROFILE_REUSE_FRAME) {
         if (*code == NULL) {
             *code = __Pyx_createFrameCodeObject(funcname, srcfile, firstlineno);
             if (*code == NULL) return 0;
@@ -5785,7 +5782,7 @@ bad:
     return py_code;
 }
 
-#endif /* CYTHON_TRACING */
+#endif /* CYTHON_PROFILE */
 """ % {
     'EMPTY_TUPLE' : Naming.empty_tuple,
     'EMPTY_BYTES' : Naming.empty_bytes,