diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /contrib/tools/cython/Cython/Utility/Profile.c | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/tools/cython/Cython/Utility/Profile.c')
-rw-r--r-- | contrib/tools/cython/Cython/Utility/Profile.c | 254 |
1 files changed, 127 insertions, 127 deletions
diff --git a/contrib/tools/cython/Cython/Utility/Profile.c b/contrib/tools/cython/Cython/Utility/Profile.c index 921eb67529..56c5a08e1f 100644 --- a/contrib/tools/cython/Cython/Utility/Profile.c +++ b/contrib/tools/cython/Cython/Utility/Profile.c @@ -1,18 +1,18 @@ -/////////////// Profile.proto /////////////// +/////////////// Profile.proto /////////////// //@requires: Exceptions.c::PyErrFetchRestore -//@substitute: naming - -// Note that cPython ignores PyTrace_EXCEPTION, -// but maybe some other profilers don't. - -#ifndef CYTHON_PROFILE +//@substitute: naming + +// Note that cPython ignores PyTrace_EXCEPTION, +// but maybe some other profilers don't. + +#ifndef CYTHON_PROFILE #if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_PYSTON #define CYTHON_PROFILE 0 #else - #define CYTHON_PROFILE 1 -#endif + #define CYTHON_PROFILE 1 +#endif #endif - + #ifndef CYTHON_TRACE_NOGIL #define CYTHON_TRACE_NOGIL 0 #else @@ -21,37 +21,37 @@ #endif #endif -#ifndef CYTHON_TRACE - #define CYTHON_TRACE 0 -#endif - -#if CYTHON_TRACE - #undef CYTHON_PROFILE_REUSE_FRAME -#endif - -#ifndef CYTHON_PROFILE_REUSE_FRAME - #define CYTHON_PROFILE_REUSE_FRAME 0 -#endif - -#if CYTHON_PROFILE || CYTHON_TRACE - - #include "compile.h" - #include "frameobject.h" - #include "traceback.h" - - #if CYTHON_PROFILE_REUSE_FRAME - #define CYTHON_FRAME_MODIFIER static +#ifndef CYTHON_TRACE + #define CYTHON_TRACE 0 +#endif + +#if CYTHON_TRACE + #undef CYTHON_PROFILE_REUSE_FRAME +#endif + +#ifndef CYTHON_PROFILE_REUSE_FRAME + #define CYTHON_PROFILE_REUSE_FRAME 0 +#endif + +#if CYTHON_PROFILE || CYTHON_TRACE + + #include "compile.h" + #include "frameobject.h" + #include "traceback.h" + + #if CYTHON_PROFILE_REUSE_FRAME + #define CYTHON_FRAME_MODIFIER static #define CYTHON_FRAME_DEL(frame) - #else - #define CYTHON_FRAME_MODIFIER + #else + #define CYTHON_FRAME_MODIFIER #define CYTHON_FRAME_DEL(frame) Py_CLEAR(frame) - #endif - + #endif + #define __Pyx_TraceDeclarations \ static PyCodeObject *$frame_code_cname = NULL; \ CYTHON_FRAME_MODIFIER PyFrameObject *$frame_cname = NULL; \ int __Pyx_use_tracing = 0; - + #define __Pyx_TraceFrameInit(codeobj) \ if (codeobj) $frame_code_cname = (PyCodeObject*) codeobj; @@ -118,7 +118,7 @@ __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&$frame_code_cname, &$frame_cname, tstate, funcname, srcfile, firstlineno); \ if (unlikely(__Pyx_use_tracing < 0)) goto_error; \ } \ - } + } #else #define __Pyx_TraceCall(funcname, srcfile, firstlineno, nogil, goto_error) \ { PyThreadState* tstate = PyThreadState_GET(); \ @@ -128,8 +128,8 @@ } \ } #endif - - #define __Pyx_TraceException() \ + + #define __Pyx_TraceException() \ if (likely(!__Pyx_use_tracing)); else { \ PyThreadState* tstate = __Pyx_PyThreadState_Current; \ if (__Pyx_IsTracing(tstate, 0, 1)) { \ @@ -144,9 +144,9 @@ Py_DECREF(exc_info); \ } \ __Pyx_LeaveTracing(tstate); \ - } \ - } - + } \ + } + static void __Pyx_call_return_trace_func(PyThreadState *tstate, PyFrameObject *frame, PyObject *result) { PyObject *type, *value, *traceback; __Pyx_ErrFetchInState(tstate, &type, &value, &traceback); @@ -158,8 +158,8 @@ CYTHON_FRAME_DEL(frame); __Pyx_LeaveTracing(tstate); __Pyx_ErrRestoreInState(tstate, type, value, traceback); - } - + } + #ifdef WITH_THREAD #define __Pyx_TraceReturn(result, nogil) \ if (likely(!__Pyx_use_tracing)); else { \ @@ -190,21 +190,21 @@ } #endif - static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno); /*proto*/ + static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno); /*proto*/ static int __Pyx_TraceSetupAndCall(PyCodeObject** code, PyFrameObject** frame, PyThreadState* tstate, const char *funcname, const char *srcfile, int firstlineno); /*proto*/ - -#else - - #define __Pyx_TraceDeclarations + +#else + + #define __Pyx_TraceDeclarations #define __Pyx_TraceFrameInit(codeobj) // mark error label as used to avoid compiler warnings #define __Pyx_TraceCall(funcname, srcfile, firstlineno, nogil, goto_error) if ((1)); else goto_error; - #define __Pyx_TraceException() + #define __Pyx_TraceException() #define __Pyx_TraceReturn(result, nogil) - -#endif /* CYTHON_PROFILE */ - -#if CYTHON_TRACE + +#endif /* CYTHON_PROFILE */ + +#if CYTHON_TRACE // see call_trace_protected() in CPython's ceval.c static int __Pyx_call_line_trace_func(PyThreadState *tstate, PyFrameObject *frame, int lineno) { int ret; @@ -264,60 +264,60 @@ // XXX https://github.com/cython/cython/issues/2274 \ if (unlikely(ret)) { fprintf(stderr, "cython: line_trace_func returned %d\n", ret); } \ } \ - } + } #endif -#else +#else // mark error label as used to avoid compiler warnings #define __Pyx_TraceLine(lineno, nogil, goto_error) if ((1)); else goto_error; -#endif - -/////////////// Profile /////////////// -//@substitute: naming - -#if CYTHON_PROFILE - -static int __Pyx_TraceSetupAndCall(PyCodeObject** code, - PyFrameObject** frame, +#endif + +/////////////// Profile /////////////// +//@substitute: naming + +#if CYTHON_PROFILE + +static int __Pyx_TraceSetupAndCall(PyCodeObject** code, + PyFrameObject** frame, PyThreadState* tstate, - const char *funcname, - const char *srcfile, - int firstlineno) { + const char *funcname, + const char *srcfile, + int firstlineno) { PyObject *type, *value, *traceback; - int retval; - if (*frame == NULL || !CYTHON_PROFILE_REUSE_FRAME) { - if (*code == NULL) { - *code = __Pyx_createFrameCodeObject(funcname, srcfile, firstlineno); - if (*code == NULL) return 0; - } - *frame = PyFrame_New( - tstate, /*PyThreadState *tstate*/ - *code, /*PyCodeObject *code*/ - $moddict_cname, /*PyObject *globals*/ - 0 /*PyObject *locals*/ - ); - if (*frame == NULL) return 0; - if (CYTHON_TRACE && (*frame)->f_trace == NULL) { - // this enables "f_lineno" lookup, at least in CPython ... - Py_INCREF(Py_None); - (*frame)->f_trace = Py_None; - } -#if PY_VERSION_HEX < 0x030400B1 - } else { - (*frame)->f_tstate = tstate; -#endif - } + int retval; + if (*frame == NULL || !CYTHON_PROFILE_REUSE_FRAME) { + if (*code == NULL) { + *code = __Pyx_createFrameCodeObject(funcname, srcfile, firstlineno); + if (*code == NULL) return 0; + } + *frame = PyFrame_New( + tstate, /*PyThreadState *tstate*/ + *code, /*PyCodeObject *code*/ + $moddict_cname, /*PyObject *globals*/ + 0 /*PyObject *locals*/ + ); + if (*frame == NULL) return 0; + if (CYTHON_TRACE && (*frame)->f_trace == NULL) { + // this enables "f_lineno" lookup, at least in CPython ... + Py_INCREF(Py_None); + (*frame)->f_trace = Py_None; + } +#if PY_VERSION_HEX < 0x030400B1 + } else { + (*frame)->f_tstate = tstate; +#endif + } __Pyx_PyFrame_SetLineNumber(*frame, firstlineno); retval = 1; __Pyx_EnterTracing(tstate); __Pyx_ErrFetchInState(tstate, &type, &value, &traceback); - #if CYTHON_TRACE - if (tstate->c_tracefunc) + #if CYTHON_TRACE + if (tstate->c_tracefunc) retval = tstate->c_tracefunc(tstate->c_traceobj, *frame, PyTrace_CALL, NULL) == 0; if (retval && tstate->c_profilefunc) - #endif - retval = tstate->c_profilefunc(tstate->c_profileobj, *frame, PyTrace_CALL, NULL) == 0; + #endif + retval = tstate->c_profilefunc(tstate->c_profileobj, *frame, PyTrace_CALL, NULL) == 0; __Pyx_LeaveTracing(tstate); if (retval) { @@ -329,9 +329,9 @@ static int __Pyx_TraceSetupAndCall(PyCodeObject** code, Py_XDECREF(traceback); return -1; } -} - -static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno) { +} + +static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno) { PyCodeObject *py_code = 0; #if PY_MAJOR_VERSION >= 3 @@ -341,38 +341,38 @@ static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const cha py_code->co_flags |= CO_OPTIMIZED | CO_NEWLOCALS; } #else - PyObject *py_srcfile = 0; - PyObject *py_funcname = 0; - - py_funcname = PyString_FromString(funcname); + PyObject *py_srcfile = 0; + PyObject *py_funcname = 0; + + py_funcname = PyString_FromString(funcname); if (unlikely(!py_funcname)) goto bad; - py_srcfile = PyString_FromString(srcfile); + py_srcfile = PyString_FromString(srcfile); if (unlikely(!py_srcfile)) goto bad; - - py_code = PyCode_New( - 0, /*int argcount,*/ - 0, /*int nlocals,*/ - 0, /*int stacksize,*/ + + py_code = PyCode_New( + 0, /*int argcount,*/ + 0, /*int nlocals,*/ + 0, /*int stacksize,*/ // make CPython use a fresh dict for "f_locals" at need (see GH #1836) CO_OPTIMIZED | CO_NEWLOCALS, /*int flags,*/ - $empty_bytes, /*PyObject *code,*/ - $empty_tuple, /*PyObject *consts,*/ - $empty_tuple, /*PyObject *names,*/ - $empty_tuple, /*PyObject *varnames,*/ - $empty_tuple, /*PyObject *freevars,*/ - $empty_tuple, /*PyObject *cellvars,*/ - py_srcfile, /*PyObject *filename,*/ - py_funcname, /*PyObject *name,*/ - firstlineno, /*int firstlineno,*/ - $empty_bytes /*PyObject *lnotab*/ - ); - -bad: - Py_XDECREF(py_srcfile); - Py_XDECREF(py_funcname); + $empty_bytes, /*PyObject *code,*/ + $empty_tuple, /*PyObject *consts,*/ + $empty_tuple, /*PyObject *names,*/ + $empty_tuple, /*PyObject *varnames,*/ + $empty_tuple, /*PyObject *freevars,*/ + $empty_tuple, /*PyObject *cellvars,*/ + py_srcfile, /*PyObject *filename,*/ + py_funcname, /*PyObject *name,*/ + firstlineno, /*int firstlineno,*/ + $empty_bytes /*PyObject *lnotab*/ + ); + +bad: + Py_XDECREF(py_srcfile); + Py_XDECREF(py_funcname); #endif - - return py_code; -} - -#endif /* CYTHON_PROFILE */ + + return py_code; +} + +#endif /* CYTHON_PROFILE */ |