ceval.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /* Interface to random parts in ceval.c */
  2. #ifndef Py_CEVAL_H
  3. #define Py_CEVAL_H
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. PyAPI_FUNC(PyObject *) PyEval_EvalCode(PyObject *, PyObject *, PyObject *);
  8. PyAPI_FUNC(PyObject *) PyEval_EvalCodeEx(PyObject *co,
  9. PyObject *globals,
  10. PyObject *locals,
  11. PyObject *const *args, int argc,
  12. PyObject *const *kwds, int kwdc,
  13. PyObject *const *defs, int defc,
  14. PyObject *kwdefs, PyObject *closure);
  15. /* PyEval_CallObjectWithKeywords(), PyEval_CallObject(), PyEval_CallFunction
  16. * and PyEval_CallMethod are deprecated. Since they are officially part of the
  17. * stable ABI (PEP 384), they must be kept for backward compatibility.
  18. * PyObject_Call(), PyObject_CallFunction() and PyObject_CallMethod() are
  19. * recommended to call a callable object.
  20. */
  21. Py_DEPRECATED(3.9) PyAPI_FUNC(PyObject *) PyEval_CallObjectWithKeywords(
  22. PyObject *callable,
  23. PyObject *args,
  24. PyObject *kwargs);
  25. /* Deprecated since PyEval_CallObjectWithKeywords is deprecated */
  26. #define PyEval_CallObject(callable, arg) \
  27. PyEval_CallObjectWithKeywords((callable), (arg), _PyObject_CAST(_Py_NULL))
  28. Py_DEPRECATED(3.9) PyAPI_FUNC(PyObject *) PyEval_CallFunction(
  29. PyObject *callable, const char *format, ...);
  30. Py_DEPRECATED(3.9) PyAPI_FUNC(PyObject *) PyEval_CallMethod(
  31. PyObject *obj, const char *name, const char *format, ...);
  32. PyAPI_FUNC(PyObject *) PyEval_GetBuiltins(void);
  33. PyAPI_FUNC(PyObject *) PyEval_GetGlobals(void);
  34. PyAPI_FUNC(PyObject *) PyEval_GetLocals(void);
  35. PyAPI_FUNC(PyFrameObject *) PyEval_GetFrame(void);
  36. PyAPI_FUNC(int) Py_AddPendingCall(int (*func)(void *), void *arg);
  37. PyAPI_FUNC(int) Py_MakePendingCalls(void);
  38. /* Protection against deeply nested recursive calls
  39. In Python 3.0, this protection has two levels:
  40. * normal anti-recursion protection is triggered when the recursion level
  41. exceeds the current recursion limit. It raises a RecursionError, and sets
  42. the "overflowed" flag in the thread state structure. This flag
  43. temporarily *disables* the normal protection; this allows cleanup code
  44. to potentially outgrow the recursion limit while processing the
  45. RecursionError.
  46. * "last chance" anti-recursion protection is triggered when the recursion
  47. level exceeds "current recursion limit + 50". By construction, this
  48. protection can only be triggered when the "overflowed" flag is set. It
  49. means the cleanup code has itself gone into an infinite loop, or the
  50. RecursionError has been mistakingly ignored. When this protection is
  51. triggered, the interpreter aborts with a Fatal Error.
  52. In addition, the "overflowed" flag is automatically reset when the
  53. recursion level drops below "current recursion limit - 50". This heuristic
  54. is meant to ensure that the normal anti-recursion protection doesn't get
  55. disabled too long.
  56. Please note: this scheme has its own limitations. See:
  57. http://mail.python.org/pipermail/python-dev/2008-August/082106.html
  58. for some observations.
  59. */
  60. PyAPI_FUNC(void) Py_SetRecursionLimit(int);
  61. PyAPI_FUNC(int) Py_GetRecursionLimit(void);
  62. PyAPI_FUNC(int) Py_EnterRecursiveCall(const char *where);
  63. PyAPI_FUNC(void) Py_LeaveRecursiveCall(void);
  64. PyAPI_FUNC(const char *) PyEval_GetFuncName(PyObject *);
  65. PyAPI_FUNC(const char *) PyEval_GetFuncDesc(PyObject *);
  66. PyAPI_FUNC(PyObject *) PyEval_EvalFrame(PyFrameObject *);
  67. PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(PyFrameObject *f, int exc);
  68. /* Interface for threads.
  69. A module that plans to do a blocking system call (or something else
  70. that lasts a long time and doesn't touch Python data) can allow other
  71. threads to run as follows:
  72. ...preparations here...
  73. Py_BEGIN_ALLOW_THREADS
  74. ...blocking system call here...
  75. Py_END_ALLOW_THREADS
  76. ...interpret result here...
  77. The Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS pair expands to a
  78. {}-surrounded block.
  79. To leave the block in the middle (e.g., with return), you must insert
  80. a line containing Py_BLOCK_THREADS before the return, e.g.
  81. if (...premature_exit...) {
  82. Py_BLOCK_THREADS
  83. PyErr_SetFromErrno(PyExc_OSError);
  84. return NULL;
  85. }
  86. An alternative is:
  87. Py_BLOCK_THREADS
  88. if (...premature_exit...) {
  89. PyErr_SetFromErrno(PyExc_OSError);
  90. return NULL;
  91. }
  92. Py_UNBLOCK_THREADS
  93. For convenience, that the value of 'errno' is restored across
  94. Py_END_ALLOW_THREADS and Py_BLOCK_THREADS.
  95. WARNING: NEVER NEST CALLS TO Py_BEGIN_ALLOW_THREADS AND
  96. Py_END_ALLOW_THREADS!!!
  97. Note that not yet all candidates have been converted to use this
  98. mechanism!
  99. */
  100. PyAPI_FUNC(PyThreadState *) PyEval_SaveThread(void);
  101. PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *);
  102. Py_DEPRECATED(3.9) PyAPI_FUNC(int) PyEval_ThreadsInitialized(void);
  103. Py_DEPRECATED(3.9) PyAPI_FUNC(void) PyEval_InitThreads(void);
  104. /* PyEval_AcquireLock() and PyEval_ReleaseLock() are part of stable ABI.
  105. * They will be removed from this header file in the future version.
  106. * But they will be remained in ABI until Python 4.0.
  107. */
  108. Py_DEPRECATED(3.2) PyAPI_FUNC(void) PyEval_AcquireLock(void);
  109. Py_DEPRECATED(3.2) PyAPI_FUNC(void) PyEval_ReleaseLock(void);
  110. PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate);
  111. PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate);
  112. #define Py_BEGIN_ALLOW_THREADS { \
  113. PyThreadState *_save; \
  114. _save = PyEval_SaveThread();
  115. #define Py_BLOCK_THREADS PyEval_RestoreThread(_save);
  116. #define Py_UNBLOCK_THREADS _save = PyEval_SaveThread();
  117. #define Py_END_ALLOW_THREADS PyEval_RestoreThread(_save); \
  118. }
  119. /* Masks and values used by FORMAT_VALUE opcode. */
  120. #define FVC_MASK 0x3
  121. #define FVC_NONE 0x0
  122. #define FVC_STR 0x1
  123. #define FVC_REPR 0x2
  124. #define FVC_ASCII 0x3
  125. #define FVS_MASK 0x4
  126. #define FVS_HAVE_SPEC 0x4
  127. #ifndef Py_LIMITED_API
  128. # define Py_CPYTHON_CEVAL_H
  129. # include "cpython/ceval.h"
  130. # undef Py_CPYTHON_CEVAL_H
  131. #endif
  132. #ifdef __cplusplus
  133. }
  134. #endif
  135. #endif /* !Py_CEVAL_H */