Try to fix transient refleaks in test_xmlrpc.
[python.git] / Include / ceval.h
blobf4411977fb1da5b341f27de09cd2f41e53d8d560
1 #ifndef Py_CEVAL_H
2 #define Py_CEVAL_H
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
8 /* Interface to random parts in ceval.c */
10 PyAPI_FUNC(PyObject *) PyEval_CallObjectWithKeywords(
11 PyObject *, PyObject *, PyObject *);
13 /* DLL-level Backwards compatibility: */
14 #undef PyEval_CallObject
15 PyAPI_FUNC(PyObject *) PyEval_CallObject(PyObject *, PyObject *);
17 /* Inline this */
18 #define PyEval_CallObject(func,arg) \
19 PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL)
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, ...);
27 PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *);
28 PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *);
30 struct _frame; /* Avoid including frameobject.h */
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);
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);
43 PyAPI_FUNC(int) Py_FlushLine(void);
45 PyAPI_FUNC(int) Py_AddPendingCall(int (*func)(void *), void *arg);
46 PyAPI_FUNC(int) Py_MakePendingCalls(void);
48 /* Protection against deeply nested recursive calls */
49 PyAPI_FUNC(void) Py_SetRecursionLimit(int);
50 PyAPI_FUNC(int) Py_GetRecursionLimit(void);
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
65 PyAPI_FUNC(const char *) PyEval_GetFuncName(PyObject *);
66 PyAPI_FUNC(const char *) PyEval_GetFuncDesc(PyObject *);
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);
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;
76 /* Interface for threads.
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:
82 ...preparations here...
83 Py_BEGIN_ALLOW_THREADS
84 ...blocking system call here...
85 Py_END_ALLOW_THREADS
86 ...interpret result here...
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.
93 if (...premature_exit...) {
94 Py_BLOCK_THREADS
95 PyErr_SetFromErrno(PyExc_IOError);
96 return NULL;
99 An alternative is:
101 Py_BLOCK_THREADS
102 if (...premature_exit...) {
103 PyErr_SetFromErrno(PyExc_IOError);
104 return NULL;
106 Py_UNBLOCK_THREADS
108 For convenience, that the value of 'errno' is restored across
109 Py_END_ALLOW_THREADS and Py_BLOCK_THREADS.
111 WARNING: NEVER NEST CALLS TO Py_BEGIN_ALLOW_THREADS AND
112 Py_END_ALLOW_THREADS!!!
114 The function PyEval_InitThreads() should be called only from
115 initthread() in "threadmodule.c".
117 Note that not yet all candidates have been converted to use this
118 mechanism!
121 PyAPI_FUNC(PyThreadState *) PyEval_SaveThread(void);
122 PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *);
124 #ifdef WITH_THREAD
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);
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); \
142 #else /* !WITH_THREAD */
144 #define Py_BEGIN_ALLOW_THREADS {
145 #define Py_BLOCK_THREADS
146 #define Py_UNBLOCK_THREADS
147 #define Py_END_ALLOW_THREADS }
149 #endif /* !WITH_THREAD */
151 PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, Py_ssize_t *);
154 #ifdef __cplusplus
156 #endif
157 #endif /* !Py_CEVAL_H */