pystate.pxd 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # Thread and interpreter state structures and their interfaces
  2. from .object cimport PyObject
  3. cdef extern from "Python.h":
  4. # We make these an opaque types. If the user wants specific attributes,
  5. # they can be declared manually.
  6. ctypedef struct PyInterpreterState:
  7. pass
  8. ctypedef struct PyThreadState:
  9. pass
  10. ctypedef struct PyFrameObject:
  11. pass
  12. # This is not actually a struct, but make sure it can never be coerced to
  13. # an int or used in arithmetic expressions
  14. ctypedef struct PyGILState_STATE
  15. # The type of the trace function registered using PyEval_SetProfile() and
  16. # PyEval_SetTrace().
  17. # Py_tracefunc return -1 when raising an exception, or 0 for success.
  18. ctypedef int (*Py_tracefunc)(PyObject *, PyFrameObject *, int, PyObject *)
  19. # The following values are used for 'what' for tracefunc functions
  20. enum:
  21. PyTrace_CALL
  22. PyTrace_EXCEPTION
  23. PyTrace_LINE
  24. PyTrace_RETURN
  25. PyTrace_C_CALL
  26. PyTrace_C_EXCEPTION
  27. PyTrace_C_RETURN
  28. PyInterpreterState * PyInterpreterState_New()
  29. void PyInterpreterState_Clear(PyInterpreterState *)
  30. void PyInterpreterState_Delete(PyInterpreterState *)
  31. PyThreadState * PyThreadState_New(PyInterpreterState *)
  32. void PyThreadState_Clear(PyThreadState *)
  33. void PyThreadState_Delete(PyThreadState *)
  34. PyThreadState * PyThreadState_Get()
  35. PyThreadState * PyThreadState_Swap(PyThreadState *)
  36. PyObject * PyThreadState_GetDict()
  37. int PyThreadState_SetAsyncExc(long, PyObject *)
  38. # Ensure that the current thread is ready to call the Python
  39. # C API, regardless of the current state of Python, or of its
  40. # thread lock. This may be called as many times as desired
  41. # by a thread so long as each call is matched with a call to
  42. # PyGILState_Release(). In general, other thread-state APIs may
  43. # be used between _Ensure() and _Release() calls, so long as the
  44. # thread-state is restored to its previous state before the Release().
  45. # For example, normal use of the Py_BEGIN_ALLOW_THREADS/
  46. # Py_END_ALLOW_THREADS macros are acceptable.
  47. # The return value is an opaque "handle" to the thread state when
  48. # PyGILState_Ensure() was called, and must be passed to
  49. # PyGILState_Release() to ensure Python is left in the same state. Even
  50. # though recursive calls are allowed, these handles can *not* be shared -
  51. # each unique call to PyGILState_Ensure must save the handle for its
  52. # call to PyGILState_Release.
  53. # When the function returns, the current thread will hold the GIL.
  54. # Failure is a fatal error.
  55. PyGILState_STATE PyGILState_Ensure()
  56. # Release any resources previously acquired. After this call, Python's
  57. # state will be the same as it was prior to the corresponding
  58. # PyGILState_Ensure() call (but generally this state will be unknown to
  59. # the caller, hence the use of the GILState API.)
  60. # Every call to PyGILState_Ensure must be matched by a call to
  61. # PyGILState_Release on the same thread.
  62. void PyGILState_Release(PyGILState_STATE)
  63. # Routines for advanced debuggers, requested by David Beazley.
  64. # Don't use unless you know what you are doing!
  65. PyInterpreterState * PyInterpreterState_Head()
  66. PyInterpreterState * PyInterpreterState_Next(PyInterpreterState *)
  67. PyThreadState * PyInterpreterState_ThreadHead(PyInterpreterState *)
  68. PyThreadState * PyThreadState_Next(PyThreadState *)