LCOV - code coverage report
Current view: top level - Include/internal - pycore_ceval.h (source / functions) Hit Total Coverage
Test: CPython 3.12 LCOV report [commit 5e6661bce9] Lines: 14 18 77.8 %
Date: 2023-03-20 08:15:36 Functions: 5 6 83.3 %
Branches: 2 6 33.3 %

           Branch data     Line data    Source code
       1                 :            : #ifndef Py_INTERNAL_CEVAL_H
       2                 :            : #define Py_INTERNAL_CEVAL_H
       3                 :            : #ifdef __cplusplus
       4                 :            : extern "C" {
       5                 :            : #endif
       6                 :            : 
       7                 :            : #ifndef Py_BUILD_CORE
       8                 :            : #  error "this header requires Py_BUILD_CORE define"
       9                 :            : #endif
      10                 :            : 
      11                 :            : /* Forward declarations */
      12                 :            : struct pyruntimestate;
      13                 :            : struct _ceval_runtime_state;
      14                 :            : 
      15                 :            : #ifndef Py_DEFAULT_RECURSION_LIMIT
      16                 :            : #  define Py_DEFAULT_RECURSION_LIMIT 1000
      17                 :            : #endif
      18                 :            : 
      19                 :            : #include "pycore_interp.h"        // PyInterpreterState.eval_frame
      20                 :            : #include "pycore_pystate.h"       // _PyThreadState_GET()
      21                 :            : 
      22                 :            : 
      23                 :            : extern void _Py_FinishPendingCalls(PyThreadState *tstate);
      24                 :            : extern void _PyEval_InitRuntimeState(struct _ceval_runtime_state *);
      25                 :            : extern void _PyEval_InitState(struct _ceval_state *, PyThread_type_lock);
      26                 :            : extern void _PyEval_FiniState(struct _ceval_state *ceval);
      27                 :            : PyAPI_FUNC(void) _PyEval_SignalReceived(PyInterpreterState *interp);
      28                 :            : PyAPI_FUNC(int) _PyEval_AddPendingCall(
      29                 :            :     PyInterpreterState *interp,
      30                 :            :     int (*func)(void *),
      31                 :            :     void *arg);
      32                 :            : PyAPI_FUNC(void) _PyEval_SignalAsyncExc(PyInterpreterState *interp);
      33                 :            : #ifdef HAVE_FORK
      34                 :            : extern PyStatus _PyEval_ReInitThreads(PyThreadState *tstate);
      35                 :            : #endif
      36                 :            : 
      37                 :            : // Used by sys.call_tracing()
      38                 :            : extern PyObject* _PyEval_CallTracing(PyObject *func, PyObject *args);
      39                 :            : 
      40                 :            : // Used by sys.get_asyncgen_hooks()
      41                 :            : extern PyObject* _PyEval_GetAsyncGenFirstiter(void);
      42                 :            : extern PyObject* _PyEval_GetAsyncGenFinalizer(void);
      43                 :            : 
      44                 :            : // Used by sys.set_asyncgen_hooks()
      45                 :            : extern int _PyEval_SetAsyncGenFirstiter(PyObject *);
      46                 :            : extern int _PyEval_SetAsyncGenFinalizer(PyObject *);
      47                 :            : 
      48                 :            : // Used by sys.get_coroutine_origin_tracking_depth()
      49                 :            : // and sys.set_coroutine_origin_tracking_depth()
      50                 :            : extern int _PyEval_GetCoroutineOriginTrackingDepth(void);
      51                 :            : extern int _PyEval_SetCoroutineOriginTrackingDepth(int depth);
      52                 :            : 
      53                 :            : extern void _PyEval_Fini(void);
      54                 :            : 
      55                 :            : 
      56                 :            : extern PyObject* _PyEval_GetBuiltins(PyThreadState *tstate);
      57                 :            : extern PyObject* _PyEval_BuiltinsFromGlobals(
      58                 :            :     PyThreadState *tstate,
      59                 :            :     PyObject *globals);
      60                 :            : 
      61                 :            : // Trampoline API
      62                 :            : 
      63                 :            : typedef struct {
      64                 :            :     // Callback to initialize the trampoline state
      65                 :            :     void* (*init_state)(void);
      66                 :            :     // Callback to register every trampoline being created
      67                 :            :     void (*write_state)(void* state, const void *code_addr,
      68                 :            :                         unsigned int code_size, PyCodeObject* code);
      69                 :            :     // Callback to free the trampoline state
      70                 :            :     int (*free_state)(void* state);
      71                 :            : } _PyPerf_Callbacks;
      72                 :            : 
      73                 :            : extern int _PyPerfTrampoline_SetCallbacks(_PyPerf_Callbacks *);
      74                 :            : extern void _PyPerfTrampoline_GetCallbacks(_PyPerf_Callbacks *);
      75                 :            : extern int _PyPerfTrampoline_Init(int activate);
      76                 :            : extern int _PyPerfTrampoline_Fini(void);
      77                 :            : extern int _PyIsPerfTrampolineActive(void);
      78                 :            : extern PyStatus _PyPerfTrampoline_AfterFork_Child(void);
      79                 :            : #ifdef PY_HAVE_PERF_TRAMPOLINE
      80                 :            : extern _PyPerf_Callbacks _Py_perfmap_callbacks;
      81                 :            : #endif
      82                 :            : 
      83                 :            : static inline PyObject*
      84                 :    1676264 : _PyEval_EvalFrame(PyThreadState *tstate, struct _PyInterpreterFrame *frame, int throwflag)
      85                 :            : {
      86                 :            :     EVAL_CALL_STAT_INC(EVAL_CALL_TOTAL);
      87         [ +  - ]:    1676264 :     if (tstate->interp->eval_frame == NULL) {
      88                 :    1676264 :         return _PyEval_EvalFrameDefault(tstate, frame, throwflag);
      89                 :            :     }
      90                 :          0 :     return tstate->interp->eval_frame(tstate, frame, throwflag);
      91                 :            : }
      92                 :            : 
      93                 :            : extern PyObject*
      94                 :            : _PyEval_Vector(PyThreadState *tstate,
      95                 :            :             PyFunctionObject *func, PyObject *locals,
      96                 :            :             PyObject* const* args, size_t argcount,
      97                 :            :             PyObject *kwnames);
      98                 :            : 
      99                 :            : extern int _PyEval_ThreadsInitialized(struct pyruntimestate *runtime);
     100                 :            : extern PyStatus _PyEval_InitGIL(PyThreadState *tstate);
     101                 :            : extern void _PyEval_FiniGIL(PyInterpreterState *interp);
     102                 :            : 
     103                 :            : extern void _PyEval_ReleaseLock(PyThreadState *tstate);
     104                 :            : 
     105                 :            : extern void _PyEval_DeactivateOpCache(void);
     106                 :            : 
     107                 :            : 
     108                 :            : /* --- _Py_EnterRecursiveCall() ----------------------------------------- */
     109                 :            : 
     110                 :            : #ifdef USE_STACKCHECK
     111                 :            : /* With USE_STACKCHECK macro defined, trigger stack checks in
     112                 :            :    _Py_CheckRecursiveCall() on every 64th call to _Py_EnterRecursiveCall. */
     113                 :            : static inline int _Py_MakeRecCheck(PyThreadState *tstate)  {
     114                 :            :     return (tstate->c_recursion_remaining-- <= 0
     115                 :            :             || (tstate->c_recursion_remaining & 63) == 0);
     116                 :            : }
     117                 :            : #else
     118                 :   10963534 : static inline int _Py_MakeRecCheck(PyThreadState *tstate) {
     119                 :   10963534 :     return tstate->c_recursion_remaining-- <= 0;
     120                 :            : }
     121                 :            : #endif
     122                 :            : 
     123                 :            : PyAPI_FUNC(int) _Py_CheckRecursiveCall(
     124                 :            :     PyThreadState *tstate,
     125                 :            :     const char *where);
     126                 :            : 
     127                 :            : int _Py_CheckRecursiveCallPy(
     128                 :            :     PyThreadState *tstate);
     129                 :            : 
     130                 :   10963534 : static inline int _Py_EnterRecursiveCallTstate(PyThreadState *tstate,
     131                 :            :                                                const char *where) {
     132   [ -  +  -  - ]:   10963534 :     return (_Py_MakeRecCheck(tstate) && _Py_CheckRecursiveCall(tstate, where));
     133                 :            : }
     134                 :            : 
     135                 :          0 : static inline int _Py_EnterRecursiveCall(const char *where) {
     136                 :          0 :     PyThreadState *tstate = _PyThreadState_GET();
     137                 :          0 :     return _Py_EnterRecursiveCallTstate(tstate, where);
     138                 :            : }
     139                 :            : 
     140                 :   10963534 : static inline void _Py_LeaveRecursiveCallTstate(PyThreadState *tstate)  {
     141                 :   10963534 :     tstate->c_recursion_remaining++;
     142                 :   10963534 : }
     143                 :            : 
     144                 :    1454773 : static inline void _Py_LeaveRecursiveCall(void)  {
     145                 :    1454773 :     PyThreadState *tstate = _PyThreadState_GET();
     146                 :    1454773 :     _Py_LeaveRecursiveCallTstate(tstate);
     147                 :    1454773 : }
     148                 :            : 
     149                 :            : extern struct _PyInterpreterFrame* _PyEval_GetFrame(void);
     150                 :            : 
     151                 :            : extern PyObject* _Py_MakeCoro(PyFunctionObject *func);
     152                 :            : 
     153                 :            : extern int _Py_HandlePending(PyThreadState *tstate);
     154                 :            : 
     155                 :            : 
     156                 :            : 
     157                 :            : #ifdef __cplusplus
     158                 :            : }
     159                 :            : #endif
     160                 :            : #endif /* !Py_INTERNAL_CEVAL_H */

Generated by: LCOV version 1.14