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