ceval.h 5.8 KB

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