/ lib / debugpy / _vendored / pydevd / _pydevd_frame_eval / pydevd_frame_evaluator.pxd
pydevd_frame_evaluator.pxd
  1  from cpython.mem cimport PyMem_Malloc, PyMem_Free
  2  
  3  cdef extern from *:
  4      ctypedef void PyObject
  5      ctypedef struct PyCodeObject:
  6          int co_argcount;		# arguments, except *args */
  7          int co_kwonlyargcount;	# keyword only arguments */
  8          int co_nlocals;		    # local variables */
  9          int co_stacksize;		# entries needed for evaluation stack */
 10          int co_flags;		    # CO_..., see below */
 11          int co_firstlineno;     # first source line number */
 12          PyObject *co_code;		# instruction opcodes */
 13          PyObject *co_consts;	# list (constants used) */
 14          PyObject *co_names;		# list of strings (names used) */
 15          PyObject *co_varnames;	# tuple of strings (local variable names) */
 16          PyObject *co_freevars;	# tuple of strings (free variable names) */
 17          PyObject *co_cellvars;  # tuple of strings (cell variable names) */
 18          unsigned char *co_cell2arg; # Maps cell vars which are arguments. */
 19          PyObject *co_filename;	# unicode (where it was loaded from) */
 20          PyObject *co_name;		# unicode (name, for reference) */
 21          PyObject *co_lnotab;	# string (encoding addr<->lineno mapping) See
 22                                  # Objects/lnotab_notes.txt for details. */
 23          void *co_zombieframe;   # for optimization only (see frameobject.c) */
 24          PyObject *co_weakreflist;   # to support weakrefs to code objects */
 25          void *co_extra;
 26  
 27  cdef extern from "frameobject.h":
 28      ctypedef struct PyFrameObject:
 29          PyFrameObject *f_back
 30          PyCodeObject *f_code       # code segment
 31          PyObject *f_builtins       # builtin symbol table (PyDictObject)
 32          PyObject *f_globals        # global symbol table (PyDictObject) */
 33          PyObject *f_locals         # local symbol table (any mapping) */
 34          PyObject **f_valuestack   #
 35          PyObject **f_stacktop
 36          PyObject *f_trace         # Trace function */
 37          PyObject *f_exc_type
 38          PyObject *f_exc_value
 39          PyObject *f_exc_traceback
 40          PyObject *f_gen;
 41  
 42          int f_lasti;                #/* Last instruction if called */
 43          int f_lineno;               #/* Current line number */
 44          int f_iblock;               #/* index in f_blockstack */
 45          char f_executing;           #/* whether the frame is still executing */
 46          PyObject *f_localsplus[1];
 47  
 48  cdef extern from "release_mem.h":
 49      void release_co_extra(void *)
 50  
 51  cdef extern from "code.h":
 52      ctypedef void freefunc(void *)
 53      int _PyCode_GetExtra(PyObject *code, Py_ssize_t index, void **extra)
 54      int _PyCode_SetExtra(PyObject *code, Py_ssize_t index, void *extra)
 55      
 56  # TODO: Things are in a different place for Python 3.11.
 57  # cdef extern from "cpython/code.h":
 58  #     ctypedef void freefunc(void *)
 59  #     int _PyCode_GetExtra(PyObject *code, Py_ssize_t index, void **extra)
 60  #     int _PyCode_SetExtra(PyObject *code, Py_ssize_t index, void *extra)
 61  
 62  cdef extern from "Python.h":
 63      void Py_INCREF(object o)
 64      void Py_DECREF(object o)
 65      object PyImport_ImportModule(char *name)
 66      PyObject* PyObject_CallFunction(PyObject *callable, const char *format, ...)
 67      object PyObject_GetAttrString(object o, char *attr_name)
 68  
 69  cdef extern from "pystate.h":
 70      # ctypedef PyObject* _PyFrameEvalFunction(PyThreadState* tstate, PyFrameObject *frame, int exc)
 71      # ctypedef PyObject* _PyFrameEvalFunction(PyFrameObject *frame, int exc)
 72      ctypedef PyObject* _PyFrameEvalFunction(...)
 73  
 74      ctypedef struct PyInterpreterState:
 75          PyInterpreterState *next
 76          PyInterpreterState *tstate_head
 77  
 78          PyObject *modules
 79  
 80          PyObject *modules_by_index
 81          PyObject *sysdict
 82          PyObject *builtins
 83          PyObject *importlib
 84  
 85          PyObject *codec_search_path
 86          PyObject *codec_search_cache
 87          PyObject *codec_error_registry
 88          int codecs_initialized
 89          int fscodec_initialized
 90  
 91          int dlopenflags
 92  
 93          PyObject *builtins_copy
 94          PyObject *import_func
 95          # Initialized to PyEval_EvalFrameDefault().
 96          _PyFrameEvalFunction eval_frame
 97  
 98      ctypedef struct PyThreadState:
 99          PyThreadState *prev
100          PyThreadState *next
101          PyInterpreterState *interp
102          # ...
103  
104      PyThreadState *PyThreadState_Get()
105  
106  cdef extern from "ceval.h":
107      '''
108  #if PY_VERSION_HEX >= 0x03090000
109  PyObject * noop(PyFrameObject *frame, int exc) {
110      return NULL;
111  }
112  #define CALL_EvalFrameDefault_38(a, b)    noop(a, b)
113  #define CALL_EvalFrameDefault_39(a, b, c)    _PyEval_EvalFrameDefault(a, b, c)
114  #else
115  PyObject * noop(PyThreadState* tstate, PyFrameObject *frame, int exc) {
116      return NULL;
117  }
118  #define CALL_EvalFrameDefault_39(a, b, c)    noop(a, b, c)
119  #define CALL_EvalFrameDefault_38(a, b)    _PyEval_EvalFrameDefault(a, b)
120  #endif
121      '''
122  
123      int _PyEval_RequestCodeExtraIndex(freefunc)
124      PyFrameObject *PyEval_GetFrame()
125      PyObject* PyEval_CallFunction(PyObject *callable, const char *format, ...)
126  
127      # PyObject* _PyEval_EvalFrameDefault(PyThreadState* tstate, PyFrameObject *frame, int exc)
128      # PyObject* _PyEval_EvalFrameDefault(PyFrameObject *frame, int exc)
129      PyObject* _PyEval_EvalFrameDefault(...)
130      PyObject* CALL_EvalFrameDefault_38(PyFrameObject *frame, int exc)  # Actually a macro.
131      PyObject* CALL_EvalFrameDefault_39(PyThreadState* tstate, PyFrameObject *frame, int exc)  # Actually a macro.