Download Lib/site-packages/Cython/Utility/Profile.c from Kasamuday/object: direct link, hf CLI and curl.
- Browser
- Download file 18.6 kB
-
https://huggingface.co/spaces/Kasamuday/object/resolve/main/Lib/site-packages/Cython/Utility/Profile.c
- Command line
-
hf download hf://spaces/Kasamuday/object/Lib/site-packages/Cython/Utility/Profile.c
-
curl -L -o Profile.c https://huggingface.co/spaces/Kasamuday/object/resolve/main/Lib/site-packages/Cython/Utility/Profile.c
18.6 kB
| /////////////// Profile.proto /////////////// | |
| //@requires: Exceptions.c::PyErrFetchRestore | |
| //@substitute: naming | |
| // Note that cPython ignores PyTrace_EXCEPTION, | |
| // but maybe some other profilers don't. | |
| static PyCodeObject *$frame_code_cname = NULL; \ | |
| CYTHON_FRAME_MODIFIER PyFrameObject *$frame_cname = NULL; \ | |
| int __Pyx_use_tracing = 0; | |
| if (codeobj) $frame_code_cname = (PyCodeObject*) codeobj; | |
| ((!(check_tracing) || !(tstate)->tracing) && \ | |
| (!(check_funcs) || (tstate)->c_profilefunc || (CYTHON_TRACE && (tstate)->c_tracefunc))) | |
| (unlikely((tstate)->cframe->use_tracing) && \ | |
| (!(check_tracing) || !(tstate)->tracing) && \ | |
| (!(check_funcs) || (tstate)->c_profilefunc || (CYTHON_TRACE && (tstate)->c_tracefunc))) | |
| (unlikely((tstate)->cframe->use_tracing) && \ | |
| (!(check_tracing) || !(tstate)->tracing) && \ | |
| (!(check_funcs) || (tstate)->c_profilefunc || (CYTHON_TRACE && (tstate)->c_tracefunc))) | |
| do { tstate->tracing++; tstate->cframe->use_tracing = 0; } while (0) | |
| do { \ | |
| tstate->tracing--; \ | |
| tstate->cframe->use_tracing = ((CYTHON_TRACE && tstate->c_tracefunc != NULL) \ | |
| || tstate->c_profilefunc != NULL); \ | |
| } while (0) | |
| (unlikely((tstate)->use_tracing) && \ | |
| (!(check_tracing) || !(tstate)->tracing) && \ | |
| (!(check_funcs) || (tstate)->c_profilefunc || (CYTHON_TRACE && (tstate)->c_tracefunc))) | |
| do { tstate->tracing++; tstate->use_tracing = 0; } while (0) | |
| do { \ | |
| tstate->tracing--; \ | |
| tstate->use_tracing = ((CYTHON_TRACE && tstate->c_tracefunc != NULL) \ | |
| || tstate->c_profilefunc != NULL); \ | |
| } while (0) | |
| if (nogil) { \ | |
| if (CYTHON_TRACE_NOGIL) { \ | |
| PyThreadState *tstate; \ | |
| PyGILState_STATE state = PyGILState_Ensure(); \ | |
| tstate = __Pyx_PyThreadState_Current; \ | |
| if (__Pyx_IsTracing(tstate, 1, 1)) { \ | |
| __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&$frame_code_cname, &$frame_cname, tstate, funcname, srcfile, firstlineno); \ | |
| } \ | |
| PyGILState_Release(state); \ | |
| if (unlikely(__Pyx_use_tracing < 0)) goto_error; \ | |
| } \ | |
| } else { \ | |
| PyThreadState* tstate = PyThreadState_GET(); \ | |
| if (__Pyx_IsTracing(tstate, 1, 1)) { \ | |
| __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&$frame_code_cname, &$frame_cname, tstate, funcname, srcfile, firstlineno); \ | |
| if (unlikely(__Pyx_use_tracing < 0)) goto_error; \ | |
| } \ | |
| } | |
| { PyThreadState* tstate = PyThreadState_GET(); \ | |
| if (__Pyx_IsTracing(tstate, 1, 1)) { \ | |
| __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&$frame_code_cname, &$frame_cname, tstate, funcname, srcfile, firstlineno); \ | |
| if (unlikely(__Pyx_use_tracing < 0)) goto_error; \ | |
| } \ | |
| } | |
| if (likely(!__Pyx_use_tracing)); else { \ | |
| PyThreadState* tstate = __Pyx_PyThreadState_Current; \ | |
| if (__Pyx_IsTracing(tstate, 0, 1)) { \ | |
| __Pyx_EnterTracing(tstate); \ | |
| PyObject *exc_info = __Pyx_GetExceptionTuple(tstate); \ | |
| if (exc_info) { \ | |
| if (CYTHON_TRACE && tstate->c_tracefunc) \ | |
| tstate->c_tracefunc( \ | |
| tstate->c_traceobj, $frame_cname, PyTrace_EXCEPTION, exc_info); \ | |
| tstate->c_profilefunc( \ | |
| tstate->c_profileobj, $frame_cname, PyTrace_EXCEPTION, exc_info); \ | |
| 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); | |
| __Pyx_EnterTracing(tstate); | |
| if (CYTHON_TRACE && tstate->c_tracefunc) | |
| tstate->c_tracefunc(tstate->c_traceobj, frame, PyTrace_RETURN, result); | |
| if (tstate->c_profilefunc) | |
| tstate->c_profilefunc(tstate->c_profileobj, frame, PyTrace_RETURN, result); | |
| CYTHON_FRAME_DEL(frame); | |
| __Pyx_LeaveTracing(tstate); | |
| __Pyx_ErrRestoreInState(tstate, type, value, traceback); | |
| } | |
| if (likely(!__Pyx_use_tracing)); else { \ | |
| if (nogil) { \ | |
| if (CYTHON_TRACE_NOGIL) { \ | |
| PyThreadState *tstate; \ | |
| PyGILState_STATE state = PyGILState_Ensure(); \ | |
| tstate = __Pyx_PyThreadState_Current; \ | |
| if (__Pyx_IsTracing(tstate, 0, 0)) { \ | |
| __Pyx_call_return_trace_func(tstate, $frame_cname, (PyObject*)result); \ | |
| } \ | |
| PyGILState_Release(state); \ | |
| } \ | |
| } else { \ | |
| PyThreadState* tstate = __Pyx_PyThreadState_Current; \ | |
| if (__Pyx_IsTracing(tstate, 0, 0)) { \ | |
| __Pyx_call_return_trace_func(tstate, $frame_cname, (PyObject*)result); \ | |
| } \ | |
| } \ | |
| } | |
| if (likely(!__Pyx_use_tracing)); else { \ | |
| PyThreadState* tstate = __Pyx_PyThreadState_Current; \ | |
| if (__Pyx_IsTracing(tstate, 0, 0)) { \ | |
| __Pyx_call_return_trace_func(tstate, $frame_cname, (PyObject*)result); \ | |
| } \ | |
| } | |
| 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*/ | |
| // mark error label as used to avoid compiler warnings | |
| // see call_trace_protected() in CPython's ceval.c | |
| static int __Pyx_call_line_trace_func(PyThreadState *tstate, PyFrameObject *frame, int lineno) { | |
| int ret; | |
| PyObject *type, *value, *traceback; | |
| __Pyx_ErrFetchInState(tstate, &type, &value, &traceback); | |
| __Pyx_PyFrame_SetLineNumber(frame, lineno); | |
| __Pyx_EnterTracing(tstate); | |
| ret = tstate->c_tracefunc(tstate->c_traceobj, frame, PyTrace_LINE, NULL); | |
| __Pyx_LeaveTracing(tstate); | |
| if (likely(!ret)) { | |
| __Pyx_ErrRestoreInState(tstate, type, value, traceback); | |
| } else { | |
| Py_XDECREF(type); | |
| Py_XDECREF(value); | |
| Py_XDECREF(traceback); | |
| } | |
| return ret; | |
| } | |
| if (likely(!__Pyx_use_tracing)); else { \ | |
| if (nogil) { \ | |
| if (CYTHON_TRACE_NOGIL) { \ | |
| int ret = 0; \ | |
| PyThreadState *tstate; \ | |
| PyGILState_STATE state = __Pyx_PyGILState_Ensure(); \ | |
| tstate = __Pyx_PyThreadState_Current; \ | |
| if (__Pyx_IsTracing(tstate, 0, 0) && tstate->c_tracefunc && $frame_cname->f_trace) { \ | |
| ret = __Pyx_call_line_trace_func(tstate, $frame_cname, lineno); \ | |
| } \ | |
| __Pyx_PyGILState_Release(state); \ | |
| if (unlikely(ret)) goto_error; \ | |
| } \ | |
| } else { \ | |
| PyThreadState* tstate = __Pyx_PyThreadState_Current; \ | |
| if (__Pyx_IsTracing(tstate, 0, 0) && tstate->c_tracefunc && $frame_cname->f_trace) { \ | |
| int ret = __Pyx_call_line_trace_func(tstate, $frame_cname, lineno); \ | |
| if (unlikely(ret)) goto_error; \ | |
| } \ | |
| } \ | |
| } | |
| if (likely(!__Pyx_use_tracing)); else { \ | |
| PyThreadState* tstate = __Pyx_PyThreadState_Current; \ | |
| if (__Pyx_IsTracing(tstate, 0, 0) && tstate->c_tracefunc && $frame_cname->f_trace) { \ | |
| int ret = __Pyx_call_line_trace_func(tstate, $frame_cname, lineno); \ | |
| if (unlikely(ret)) goto_error; \ | |
| } \ | |
| } | |
| // mark error label as used to avoid compiler warnings | |
| /////////////// Profile /////////////// | |
| //@substitute: naming | |
| static int __Pyx_TraceSetupAndCall(PyCodeObject** code, | |
| PyFrameObject** frame, | |
| PyThreadState* tstate, | |
| 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; | |
| } | |
| } else { | |
| (*frame)->f_tstate = tstate; | |
| } | |
| __Pyx_PyFrame_SetLineNumber(*frame, firstlineno); | |
| retval = 1; | |
| __Pyx_EnterTracing(tstate); | |
| __Pyx_ErrFetchInState(tstate, &type, &value, &traceback); | |
| if (tstate->c_tracefunc) | |
| retval = tstate->c_tracefunc(tstate->c_traceobj, *frame, PyTrace_CALL, NULL) == 0; | |
| if (retval && tstate->c_profilefunc) | |
| retval = tstate->c_profilefunc(tstate->c_profileobj, *frame, PyTrace_CALL, NULL) == 0; | |
| __Pyx_LeaveTracing(tstate); | |
| if (retval) { | |
| __Pyx_ErrRestoreInState(tstate, type, value, traceback); | |
| return __Pyx_IsTracing(tstate, 0, 0) && retval; | |
| } else { | |
| Py_XDECREF(type); | |
| Py_XDECREF(value); | |
| Py_XDECREF(traceback); | |
| return -1; | |
| } | |
| } | |
| static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno) { | |
| PyCodeObject *py_code = 0; | |
| py_code = PyCode_NewEmpty(srcfile, funcname, firstlineno); | |
| // make CPython use a fresh dict for "f_locals" at need (see GH #1836) | |
| if (likely(py_code)) { | |
| py_code->co_flags |= CO_OPTIMIZED | CO_NEWLOCALS; | |
| } | |
| PyObject *py_srcfile = 0; | |
| PyObject *py_funcname = 0; | |
| py_funcname = PyString_FromString(funcname); | |
| if (unlikely(!py_funcname)) goto bad; | |
| py_srcfile = PyString_FromString(srcfile); | |
| if (unlikely(!py_srcfile)) goto bad; | |
| 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); | |
| return py_code; | |
| } | |