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