Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
6.1 KiB

  1. /* Thread and interpreter state structures and their interfaces */
  2. #ifndef Py_PYSTATE_H
  3. #define Py_PYSTATE_H
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. /* State shared between threads */
  8. struct _ts; /* Forward */
  9. struct _is; /* Forward */
  10. typedef struct _is {
  11. struct _is *next;
  12. struct _ts *tstate_head;
  13. PyObject *modules;
  14. PyObject *sysdict;
  15. PyObject *builtins;
  16. PyObject *modules_reloading;
  17. PyObject *codec_search_path;
  18. PyObject *codec_search_cache;
  19. PyObject *codec_error_registry;
  20. #ifdef HAVE_DLOPEN
  21. int dlopenflags;
  22. #endif
  23. #ifdef WITH_TSC
  24. int tscdump;
  25. #endif
  26. } PyInterpreterState;
  27. /* State unique per thread */
  28. struct _frame; /* Avoid including frameobject.h */
  29. /* Py_tracefunc return -1 when raising an exception, or 0 for success. */
  30. typedef int (*Py_tracefunc)(PyObject *, struct _frame *, int, PyObject *);
  31. /* The following values are used for 'what' for tracefunc functions: */
  32. #define PyTrace_CALL 0
  33. #define PyTrace_EXCEPTION 1
  34. #define PyTrace_LINE 2
  35. #define PyTrace_RETURN 3
  36. #define PyTrace_C_CALL 4
  37. #define PyTrace_C_EXCEPTION 5
  38. #define PyTrace_C_RETURN 6
  39. typedef struct _ts {
  40. /* See Python/ceval.c for comments explaining most fields */
  41. struct _ts *next;
  42. PyInterpreterState *interp;
  43. struct _frame *frame;
  44. int recursion_depth;
  45. /* 'tracing' keeps track of the execution depth when tracing/profiling.
  46. This is to prevent the actual trace/profile code from being recorded in
  47. the trace/profile. */
  48. int tracing;
  49. int use_tracing;
  50. Py_tracefunc c_profilefunc;
  51. Py_tracefunc c_tracefunc;
  52. PyObject *c_profileobj;
  53. PyObject *c_traceobj;
  54. PyObject *curexc_type;
  55. PyObject *curexc_value;
  56. PyObject *curexc_traceback;
  57. PyObject *exc_type;
  58. PyObject *exc_value;
  59. PyObject *exc_traceback;
  60. PyObject *dict; /* Stores per-thread state */
  61. /* tick_counter is incremented whenever the check_interval ticker
  62. * reaches zero. The purpose is to give a useful measure of the number
  63. * of interpreted bytecode instructions in a given thread. This
  64. * extremely lightweight statistic collector may be of interest to
  65. * profilers (like psyco.jit()), although nothing in the core uses it.
  66. */
  67. int tick_counter;
  68. int gilstate_counter;
  69. PyObject *async_exc; /* Asynchronous exception to raise */
  70. long thread_id; /* Thread id where this tstate was created */
  71. /* XXX signal handlers should also be here */
  72. } PyThreadState;
  73. PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_New(void);
  74. PyAPI_FUNC(void) PyInterpreterState_Clear(PyInterpreterState *);
  75. PyAPI_FUNC(void) PyInterpreterState_Delete(PyInterpreterState *);
  76. PyAPI_FUNC(PyThreadState *) PyThreadState_New(PyInterpreterState *);
  77. PyAPI_FUNC(void) PyThreadState_Clear(PyThreadState *);
  78. PyAPI_FUNC(void) PyThreadState_Delete(PyThreadState *);
  79. #ifdef WITH_THREAD
  80. PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);
  81. #endif
  82. PyAPI_FUNC(PyThreadState *) PyThreadState_Get(void);
  83. PyAPI_FUNC(PyThreadState *) PyThreadState_Swap(PyThreadState *);
  84. PyAPI_FUNC(PyObject *) PyThreadState_GetDict(void);
  85. PyAPI_FUNC(int) PyThreadState_SetAsyncExc(long, PyObject *);
  86. /* Variable and macro for in-line access to current thread state */
  87. PyAPI_DATA(PyThreadState *) _PyThreadState_Current;
  88. #ifdef Py_DEBUG
  89. #define PyThreadState_GET() PyThreadState_Get()
  90. #else
  91. #define PyThreadState_GET() (_PyThreadState_Current)
  92. #endif
  93. typedef
  94. enum {PyGILState_LOCKED, PyGILState_UNLOCKED}
  95. PyGILState_STATE;
  96. /* Ensure that the current thread is ready to call the Python
  97. C API, regardless of the current state of Python, or of its
  98. thread lock. This may be called as many times as desired
  99. by a thread so long as each call is matched with a call to
  100. PyGILState_Release(). In general, other thread-state APIs may
  101. be used between _Ensure() and _Release() calls, so long as the
  102. thread-state is restored to its previous state before the Release().
  103. For example, normal use of the Py_BEGIN_ALLOW_THREADS/
  104. Py_END_ALLOW_THREADS macros are acceptable.
  105. The return value is an opaque "handle" to the thread state when
  106. PyGILState_Ensure() was called, and must be passed to
  107. PyGILState_Release() to ensure Python is left in the same state. Even
  108. though recursive calls are allowed, these handles can *not* be shared -
  109. each unique call to PyGILState_Ensure must save the handle for its
  110. call to PyGILState_Release.
  111. When the function returns, the current thread will hold the GIL.
  112. Failure is a fatal error.
  113. */
  114. PyAPI_FUNC(PyGILState_STATE) PyGILState_Ensure(void);
  115. /* Release any resources previously acquired. After this call, Python's
  116. state will be the same as it was prior to the corresponding
  117. PyGILState_Ensure() call (but generally this state will be unknown to
  118. the caller, hence the use of the GILState API.)
  119. Every call to PyGILState_Ensure must be matched by a call to
  120. PyGILState_Release on the same thread.
  121. */
  122. PyAPI_FUNC(void) PyGILState_Release(PyGILState_STATE);
  123. /* Helper/diagnostic function - get the current thread state for
  124. this thread. May return NULL if no GILState API has been used
  125. on the current thread. Note the main thread always has such a
  126. thread-state, even if no auto-thread-state call has been made
  127. on the main thread.
  128. */
  129. PyAPI_FUNC(PyThreadState *) PyGILState_GetThisThreadState(void);
  130. /* The implementation of sys._current_frames() Returns a dict mapping
  131. thread id to that thread's current frame.
  132. */
  133. PyAPI_FUNC(PyObject *) _PyThread_CurrentFrames(void);
  134. /* Routines for advanced debuggers, requested by David Beazley.
  135. Don't use unless you know what you are doing! */
  136. PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Head(void);
  137. PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Next(PyInterpreterState *);
  138. PyAPI_FUNC(PyThreadState *) PyInterpreterState_ThreadHead(PyInterpreterState *);
  139. PyAPI_FUNC(PyThreadState *) PyThreadState_Next(PyThreadState *);
  140. typedef struct _frame *(*PyThreadFrameGetter)(PyThreadState *self_);
  141. /* hook for PyEval_GetFrame(), requested for Psyco */
  142. PyAPI_DATA(PyThreadFrameGetter) _PyThreadState_GetFrame;
  143. #ifdef __cplusplus
  144. }
  145. #endif
  146. #endif /* !Py_PYSTATE_H */