ceval.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. PyAPI_FUNC(PyObject *) PyEval_CallObjectWithKeywords(
  8. PyObject *, PyObject *, PyObject *);
  9. /* Inline this */
  10. #define PyEval_CallObject(func,arg) \
  11. PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL)
  12. PyAPI_FUNC(PyObject *) PyEval_CallFunction(PyObject *obj,
  13. const char *format, ...);
  14. PyAPI_FUNC(PyObject *) PyEval_CallMethod(PyObject *obj,
  15. const char *methodname,
  16. const char *format, ...);
  17. PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *);
  18. PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *);
  19. struct _frame; /* Avoid including frameobject.h */
  20. PyAPI_FUNC(PyObject *) PyEval_GetBuiltins(void);
  21. PyAPI_FUNC(PyObject *) PyEval_GetGlobals(void);
  22. PyAPI_FUNC(PyObject *) PyEval_GetLocals(void);
  23. PyAPI_FUNC(struct _frame *) PyEval_GetFrame(void);
  24. PyAPI_FUNC(int) PyEval_GetRestricted(void);
  25. /* Look at the current frame's (if any) code's co_flags, and turn on
  26. the corresponding compiler flags in cf->cf_flags. Return 1 if any
  27. flag was set, else return 0. */
  28. PyAPI_FUNC(int) PyEval_MergeCompilerFlags(PyCompilerFlags *cf);
  29. PyAPI_FUNC(int) Py_FlushLine(void);
  30. PyAPI_FUNC(int) Py_AddPendingCall(int (*func)(void *), void *arg);
  31. PyAPI_FUNC(int) Py_MakePendingCalls(void);
  32. /* Protection against deeply nested recursive calls */
  33. PyAPI_FUNC(void) Py_SetRecursionLimit(int);
  34. PyAPI_FUNC(int) Py_GetRecursionLimit(void);
  35. #define Py_EnterRecursiveCall(where) \
  36. (_Py_MakeRecCheck(PyThreadState_GET()->recursion_depth) && \
  37. _Py_CheckRecursiveCall(where))
  38. #define Py_LeaveRecursiveCall() \
  39. (--PyThreadState_GET()->recursion_depth)
  40. PyAPI_FUNC(int) _Py_CheckRecursiveCall(const char *where);
  41. PyAPI_DATA(int) _Py_CheckRecursionLimit;
  42. #ifdef USE_STACKCHECK
  43. # define _Py_MakeRecCheck(x) (++(x) > --_Py_CheckRecursionLimit)
  44. #else
  45. # define _Py_MakeRecCheck(x) (++(x) > _Py_CheckRecursionLimit)
  46. #endif
  47. PyAPI_FUNC(const char *) PyEval_GetFuncName(PyObject *);
  48. PyAPI_FUNC(const char *) PyEval_GetFuncDesc(PyObject *);
  49. PyAPI_FUNC(PyObject *) PyEval_GetCallStats(PyObject *);
  50. PyAPI_FUNC(PyObject *) PyEval_EvalFrame(struct _frame *);
  51. PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(struct _frame *f, int exc);
  52. /* this used to be handled on a per-thread basis - now just two globals */
  53. PyAPI_DATA(volatile int) _Py_Ticker;
  54. PyAPI_DATA(int) _Py_CheckInterval;
  55. /* Interface for threads.
  56. A module that plans to do a blocking system call (or something else
  57. that lasts a long time and doesn't touch Python data) can allow other
  58. threads to run as follows:
  59. ...preparations here...
  60. Py_BEGIN_ALLOW_THREADS
  61. ...blocking system call here...
  62. Py_END_ALLOW_THREADS
  63. ...interpret result here...
  64. The Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS pair expands to a
  65. {}-surrounded block.
  66. To leave the block in the middle (e.g., with return), you must insert
  67. a line containing Py_BLOCK_THREADS before the return, e.g.
  68. if (...premature_exit...) {
  69. Py_BLOCK_THREADS
  70. PyErr_SetFromErrno(PyExc_IOError);
  71. return NULL;
  72. }
  73. An alternative is:
  74. Py_BLOCK_THREADS
  75. if (...premature_exit...) {
  76. PyErr_SetFromErrno(PyExc_IOError);
  77. return NULL;
  78. }
  79. Py_UNBLOCK_THREADS
  80. For convenience, that the value of 'errno' is restored across
  81. Py_END_ALLOW_THREADS and Py_BLOCK_THREADS.
  82. WARNING: NEVER NEST CALLS TO Py_BEGIN_ALLOW_THREADS AND
  83. Py_END_ALLOW_THREADS!!!
  84. The function PyEval_InitThreads() should be called only from
  85. initthread() in "threadmodule.c".
  86. Note that not yet all candidates have been converted to use this
  87. mechanism!
  88. */
  89. PyAPI_FUNC(PyThreadState *) PyEval_SaveThread(void);
  90. PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *);
  91. #ifdef WITH_THREAD
  92. PyAPI_FUNC(int) PyEval_ThreadsInitialized(void);
  93. PyAPI_FUNC(void) PyEval_InitThreads(void);
  94. PyAPI_FUNC(void) PyEval_AcquireLock(void);
  95. PyAPI_FUNC(void) PyEval_ReleaseLock(void);
  96. PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate);
  97. PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate);
  98. PyAPI_FUNC(void) PyEval_ReInitThreads(void);
  99. #define Py_BEGIN_ALLOW_THREADS { \
  100. PyThreadState *_save; \
  101. _save = PyEval_SaveThread();
  102. #define Py_BLOCK_THREADS PyEval_RestoreThread(_save);
  103. #define Py_UNBLOCK_THREADS _save = PyEval_SaveThread();
  104. #define Py_END_ALLOW_THREADS PyEval_RestoreThread(_save); \
  105. }
  106. #else /* !WITH_THREAD */
  107. #define Py_BEGIN_ALLOW_THREADS {
  108. #define Py_BLOCK_THREADS
  109. #define Py_UNBLOCK_THREADS
  110. #define Py_END_ALLOW_THREADS }
  111. #endif /* !WITH_THREAD */
  112. PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, Py_ssize_t *);
  113. #ifdef __cplusplus
  114. }
  115. #endif
  116. #endif /* !Py_CEVAL_H */