Mercurial > cpython-lru_cache-weakref
annotate Include/ceval.h @ 78069:a8aa77458e12 3.2
Add c_size_t and c_ssize_t to the ctypes summary table.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Thu, 12 Jul 2012 20:31:50 +0200 |
| parents | 3c9232a684ae |
| children |
| rev | line source |
|---|---|
|
1329
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
1 #ifndef Py_CEVAL_H |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
2 #define Py_CEVAL_H |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
3 #ifdef __cplusplus |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
4 extern "C" { |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
5 #endif |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
6 |
| 145 | 7 |
| 926 | 8 /* Interface to random parts in ceval.c */ |
| 86 | 9 |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18933
diff
changeset
|
10 PyAPI_FUNC(PyObject *) PyEval_CallObjectWithKeywords( |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
11 PyObject *, PyObject *, PyObject *); |
|
315
aef7e0a9119e
Added call_object interface
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
12 |
|
6206
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
5919
diff
changeset
|
13 /* Inline this */ |
|
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
5919
diff
changeset
|
14 #define PyEval_CallObject(func,arg) \ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
15 PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL) |
|
6206
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
5919
diff
changeset
|
16 |
|
35999
9541369b0dca
Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
17 PyAPI_FUNC(PyObject *) PyEval_CallFunction(PyObject *obj, |
|
9541369b0dca
Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
18 const char *format, ...); |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18933
diff
changeset
|
19 PyAPI_FUNC(PyObject *) PyEval_CallMethod(PyObject *obj, |
|
35999
9541369b0dca
Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
20 const char *methodname, |
|
9541369b0dca
Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
21 const char *format, ...); |
|
8899
38544f828d74
Add missing prototypes for PyEval_CallFunction() and PyEval_CallMethod().
Guido van Rossum <guido@python.org>
parents:
6206
diff
changeset
|
22 |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
64709
diff
changeset
|
23 #ifndef Py_LIMITED_API |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18933
diff
changeset
|
24 PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18933
diff
changeset
|
25 PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *); |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
64709
diff
changeset
|
26 #endif |
|
18325
fb35b3a22604
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
17124
diff
changeset
|
27 |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27712
diff
changeset
|
28 struct _frame; /* Avoid including frameobject.h */ |
|
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27712
diff
changeset
|
29 |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18933
diff
changeset
|
30 PyAPI_FUNC(PyObject *) PyEval_GetBuiltins(void); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18933
diff
changeset
|
31 PyAPI_FUNC(PyObject *) PyEval_GetGlobals(void); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18933
diff
changeset
|
32 PyAPI_FUNC(PyObject *) PyEval_GetLocals(void); |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27712
diff
changeset
|
33 PyAPI_FUNC(struct _frame *) PyEval_GetFrame(void); |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18325
diff
changeset
|
34 |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18325
diff
changeset
|
35 /* Look at the current frame's (if any) code's co_flags, and turn on |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18325
diff
changeset
|
36 the corresponding compiler flags in cf->cf_flags. Return 1 if any |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18325
diff
changeset
|
37 flag was set, else return 0. */ |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
64709
diff
changeset
|
38 #ifndef Py_LIMITED_API |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18933
diff
changeset
|
39 PyAPI_FUNC(int) PyEval_MergeCompilerFlags(PyCompilerFlags *cf); |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
64709
diff
changeset
|
40 #endif |
| 86 | 41 |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18933
diff
changeset
|
42 PyAPI_FUNC(int) Py_AddPendingCall(int (*func)(void *), void *arg); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18933
diff
changeset
|
43 PyAPI_FUNC(int) Py_MakePendingCalls(void); |
|
1885
d3de2cad2c68
pythonrun.h: added run_pyc_file
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
44 |
|
48986
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
45 /* Protection against deeply nested recursive calls |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
46 |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
47 In Python 3.0, this protection has two levels: |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
48 * normal anti-recursion protection is triggered when the recursion level |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
49 exceeds the current recursion limit. It raises a RuntimeError, and sets |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
50 the "overflowed" flag in the thread state structure. This flag |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
51 temporarily *disables* the normal protection; this allows cleanup code |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
52 to potentially outgrow the recursion limit while processing the |
|
48986
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
53 RuntimeError. |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
54 * "last chance" anti-recursion protection is triggered when the recursion |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
55 level exceeds "current recursion limit + 50". By construction, this |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
56 protection can only be triggered when the "overflowed" flag is set. It |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
57 means the cleanup code has itself gone into an infinite loop, or the |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
58 RuntimeError has been mistakingly ignored. When this protection is |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
59 triggered, the interpreter aborts with a Fatal Error. |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
60 |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
61 In addition, the "overflowed" flag is automatically reset when the |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
62 recursion level drops below "current recursion limit - 50". This heuristic |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
63 is meant to ensure that the normal anti-recursion protection doesn't get |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
64 disabled too long. |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
65 |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
66 Please note: this scheme has its own limitations. See: |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
67 http://mail.python.org/pipermail/python-dev/2008-August/082106.html |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
68 for some observations. |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
69 */ |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18933
diff
changeset
|
70 PyAPI_FUNC(void) Py_SetRecursionLimit(int); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18933
diff
changeset
|
71 PyAPI_FUNC(int) Py_GetRecursionLimit(void); |
| 926 | 72 |
|
48986
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
73 #define Py_EnterRecursiveCall(where) \ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
74 (_Py_MakeRecCheck(PyThreadState_GET()->recursion_depth) && \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
75 _Py_CheckRecursiveCall(where)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
76 #define Py_LeaveRecursiveCall() \ |
|
48986
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
77 do{ if(_Py_MakeEndRecCheck(PyThreadState_GET()->recursion_depth)) \ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
78 PyThreadState_GET()->overflowed = 0; \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
79 } while(0) |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
27991
diff
changeset
|
80 PyAPI_FUNC(int) _Py_CheckRecursiveCall(char *where); |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
27991
diff
changeset
|
81 PyAPI_DATA(int) _Py_CheckRecursionLimit; |
|
48986
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
82 |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
27991
diff
changeset
|
83 #ifdef USE_STACKCHECK |
|
48986
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
84 /* With USE_STACKCHECK, we artificially decrement the recursion limit in order |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
85 to trigger regular stack checks in _Py_CheckRecursiveCall(), except if |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
86 the "overflowed" flag is set, in which case we need the true value |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
87 of _Py_CheckRecursionLimit for _Py_MakeEndRecCheck() to function properly. |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
88 */ |
|
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
89 # define _Py_MakeRecCheck(x) \ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
90 (++(x) > (_Py_CheckRecursionLimit += PyThreadState_GET()->overflowed - 1)) |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
27991
diff
changeset
|
91 #else |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
27991
diff
changeset
|
92 # define _Py_MakeRecCheck(x) (++(x) > _Py_CheckRecursionLimit) |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
27991
diff
changeset
|
93 #endif |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
27991
diff
changeset
|
94 |
|
52147
22747e874f46
Merged revisions 70344 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48986
diff
changeset
|
95 #define _Py_MakeEndRecCheck(x) \ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
96 (--(x) < ((_Py_CheckRecursionLimit > 100) \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
97 ? (_Py_CheckRecursionLimit - 50) \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
98 : (3 * (_Py_CheckRecursionLimit >> 2)))) |
|
48986
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
47266
diff
changeset
|
99 |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41715
diff
changeset
|
100 #define Py_ALLOW_RECURSION \ |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41715
diff
changeset
|
101 do { unsigned char _old = PyThreadState_GET()->recursion_critical;\ |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41715
diff
changeset
|
102 PyThreadState_GET()->recursion_critical = 1; |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41715
diff
changeset
|
103 |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41715
diff
changeset
|
104 #define Py_END_ALLOW_RECURSION \ |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41715
diff
changeset
|
105 PyThreadState_GET()->recursion_critical = _old; \ |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41715
diff
changeset
|
106 } while(0); |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41715
diff
changeset
|
107 |
|
35999
9541369b0dca
Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
108 PyAPI_FUNC(const char *) PyEval_GetFuncName(PyObject *); |
|
9541369b0dca
Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
109 PyAPI_FUNC(const char *) PyEval_GetFuncDesc(PyObject *); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
110 |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
25108
diff
changeset
|
111 PyAPI_FUNC(PyObject *) PyEval_GetCallStats(PyObject *); |
|
32421
485d2ef43419
Patch #966493: Cleanup generator/eval_frame exposure.
Martin v. Löwis <martin@v.loewis.de>
parents:
32175
diff
changeset
|
112 PyAPI_FUNC(PyObject *) PyEval_EvalFrame(struct _frame *); |
|
35298
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
33715
diff
changeset
|
113 PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(struct _frame *f, int exc); |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
25108
diff
changeset
|
114 |
| 926 | 115 /* Interface for threads. |
| 116 | |
| 117 A module that plans to do a blocking system call (or something else | |
| 118 that lasts a long time and doesn't touch Python data) can allow other | |
| 119 threads to run as follows: | |
| 120 | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
121 ...preparations here... |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
122 Py_BEGIN_ALLOW_THREADS |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
123 ...blocking system call here... |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
124 Py_END_ALLOW_THREADS |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
125 ...interpret result here... |
| 926 | 126 |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2098
diff
changeset
|
127 The Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS pair expands to a |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2098
diff
changeset
|
128 {}-surrounded block. |
| 926 | 129 To leave the block in the middle (e.g., with return), you must insert |
|
14599
49a041330461
RET_SAVE references should be Py_BLOCK_THREADS references
Skip Montanaro <skip@pobox.com>
parents:
14375
diff
changeset
|
130 a line containing Py_BLOCK_THREADS before the return, e.g. |
| 926 | 131 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
132 if (...premature_exit...) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
133 Py_BLOCK_THREADS |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
134 PyErr_SetFromErrno(PyExc_IOError); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
135 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
136 } |
| 926 | 137 |
| 138 An alternative is: | |
| 139 | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
140 Py_BLOCK_THREADS |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
141 if (...premature_exit...) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
142 PyErr_SetFromErrno(PyExc_IOError); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
143 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
144 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
145 Py_UNBLOCK_THREADS |
| 926 | 146 |
| 147 For convenience, that the value of 'errno' is restored across | |
|
14599
49a041330461
RET_SAVE references should be Py_BLOCK_THREADS references
Skip Montanaro <skip@pobox.com>
parents:
14375
diff
changeset
|
148 Py_END_ALLOW_THREADS and Py_BLOCK_THREADS. |
| 926 | 149 |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2098
diff
changeset
|
150 WARNING: NEVER NEST CALLS TO Py_BEGIN_ALLOW_THREADS AND |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2098
diff
changeset
|
151 Py_END_ALLOW_THREADS!!! |
| 926 | 152 |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2098
diff
changeset
|
153 The function PyEval_InitThreads() should be called only from |
|
47266
7fe3a8648ce2
Rename thread to _thread and dummy_thread to _dummy_thread. Issue #2875.
Georg Brandl <georg@python.org>
parents:
45301
diff
changeset
|
154 init_thread() in "_threadmodule.c". |
| 926 | 155 |
| 156 Note that not yet all candidates have been converted to use this | |
| 157 mechanism! | |
| 158 */ | |
| 159 | |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18933
diff
changeset
|
160 PyAPI_FUNC(PyThreadState *) PyEval_SaveThread(void); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18933
diff
changeset
|
161 PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *); |
| 926 | 162 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
163 #ifdef WITH_THREAD |
| 926 | 164 |
|
33715
a46b76eb9053
SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents:
32421
diff
changeset
|
165 PyAPI_FUNC(int) PyEval_ThreadsInitialized(void); |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18933
diff
changeset
|
166 PyAPI_FUNC(void) PyEval_InitThreads(void); |
|
64709
557e2537c9ae
Issue #9828: Destroy the GIL in Py_Finalize(), so that it gets properly
Antoine Pitrou <solipsis@pitrou.net>
parents:
61466
diff
changeset
|
167 PyAPI_FUNC(void) _PyEval_FiniThreads(void); |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18933
diff
changeset
|
168 PyAPI_FUNC(void) PyEval_AcquireLock(void); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18933
diff
changeset
|
169 PyAPI_FUNC(void) PyEval_ReleaseLock(void); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18933
diff
changeset
|
170 PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18933
diff
changeset
|
171 PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18933
diff
changeset
|
172 PyAPI_FUNC(void) PyEval_ReInitThreads(void); |
|
5846
852a1fa62a7c
PyEval_SaveThread() and PyEval_RestoreThread() now return/take a
Guido van Rossum <guido@python.org>
parents:
5604
diff
changeset
|
173 |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
64709
diff
changeset
|
174 #ifndef Py_LIMITED_API |
|
57175
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
175 PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds); |
|
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
176 PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void); |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
64709
diff
changeset
|
177 #endif |
|
57175
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
178 |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2098
diff
changeset
|
179 #define Py_BEGIN_ALLOW_THREADS { \ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
180 PyThreadState *_save; \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
181 _save = PyEval_SaveThread(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
182 #define Py_BLOCK_THREADS PyEval_RestoreThread(_save); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
183 #define Py_UNBLOCK_THREADS _save = PyEval_SaveThread(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
184 #define Py_END_ALLOW_THREADS PyEval_RestoreThread(_save); \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
185 } |
| 926 | 186 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
187 #else /* !WITH_THREAD */ |
| 926 | 188 |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2098
diff
changeset
|
189 #define Py_BEGIN_ALLOW_THREADS { |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2098
diff
changeset
|
190 #define Py_BLOCK_THREADS |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2098
diff
changeset
|
191 #define Py_UNBLOCK_THREADS |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2098
diff
changeset
|
192 #define Py_END_ALLOW_THREADS } |
| 926 | 193 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
194 #endif /* !WITH_THREAD */ |
|
1329
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
195 |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
64709
diff
changeset
|
196 #ifndef Py_LIMITED_API |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35999
diff
changeset
|
197 PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, Py_ssize_t *); |
|
57175
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
52147
diff
changeset
|
198 PyAPI_FUNC(void) _PyEval_SignalAsyncExc(void); |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
64709
diff
changeset
|
199 #endif |
| 12613 | 200 |
| 201 | |
|
1329
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
202 #ifdef __cplusplus |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
203 } |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
204 #endif |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
205 #endif /* !Py_CEVAL_H */ |
