/ lib / debugpy / _vendored / pydevd / pydevd_attach_to_process / common / py_custom_pyeval_settrace_common.hpp
py_custom_pyeval_settrace_common.hpp
1 #ifndef _PY_CUSTOM_PYEVAL_SETTRACE_COMMON_HPP_ 2 #define _PY_CUSTOM_PYEVAL_SETTRACE_COMMON_HPP_ 3 4 #include "python.h" 5 #include "py_utils.hpp" 6 7 struct InternalInitializeCustomPyEvalSetTrace { 8 PyObject* pyNone; 9 PyTuple_New* pyTuple_New; 10 _PyObject_FastCallDict* pyObject_FastCallDict; 11 PyEval_CallObjectWithKeywords* pyEval_CallObjectWithKeywords; 12 PyUnicode_InternFromString* pyUnicode_InternFromString; // Note: in Py2 will be PyString_InternFromString. 13 PyTraceBack_Here* pyTraceBack_Here; 14 PyEval_SetTrace* pyEval_SetTrace; 15 bool isDebug; 16 PyUnicode_AsUTF8* pyUnicode_AsUTF8; 17 PyObject_Repr* pyObject_Repr; 18 }; 19 20 /** 21 * Helper information to access CPython internals. 22 */ 23 static InternalInitializeCustomPyEvalSetTrace *internalInitializeCustomPyEvalSetTrace = NULL; 24 25 /* 26 * Cached interned string objects used for calling the profile and 27 * trace functions. Initialized by InternalTraceInit(). 28 */ 29 static PyObject *InternalWhatstrings_37[8] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; 30 31 32 static int 33 InternalIsTraceInitialized() 34 { 35 return internalInitializeCustomPyEvalSetTrace != NULL; 36 } 37 38 39 40 static int 41 InternalTraceInit(InternalInitializeCustomPyEvalSetTrace *p_internalInitializeSettrace_37) 42 { 43 internalInitializeCustomPyEvalSetTrace = p_internalInitializeSettrace_37; 44 static const char * const whatnames[8] = { 45 "call", "exception", "line", "return", 46 "c_call", "c_exception", "c_return", 47 "opcode" 48 }; 49 PyObject *name; 50 int i; 51 for (i = 0; i < 8; ++i) { 52 if (InternalWhatstrings_37[i] == NULL) { 53 name = internalInitializeCustomPyEvalSetTrace->pyUnicode_InternFromString(whatnames[i]); 54 if (name == NULL) 55 return -1; 56 InternalWhatstrings_37[i] = name; 57 } 58 } 59 return 0; 60 } 61 62 #endif //_PY_CUSTOM_PYEVAL_SETTRACE_COMMON_HPP_