pystate.pxd 3.6 KB

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