Mercurial > cpython-lru_cache-weakref
annotate Python/ceval.c @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | 8f556ee0f6ba |
| children |
| rev | line source |
|---|---|
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
119
diff
changeset
|
1 |
| 86 | 2 /* Execute compiled code */ |
| 69 | 3 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4 /* XXX TO DO: |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
5 XXX speed up searching for keywords by using a dictionary |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
6 XXX document it! |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
7 */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
8 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
9 /* enable more aggressive intra-module optimizations, where available */ |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
10 #define PY_LOCAL_AGGRESSIVE |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
11 |
| 5368 | 12 #include "Python.h" |
| 86 | 13 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
14 #include "code.h" |
| 86 | 15 #include "frameobject.h" |
| 69 | 16 #include "opcode.h" |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
17 #include "structmember.h" |
| 69 | 18 |
|
1400
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
19 #include <ctype.h> |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
20 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
21 #ifndef WITH_TSC |
|
34442
683719e04218
Change the name of the macro used by --with-tsc builds to the less
Michael W. Hudson <mwh@python.net>
parents:
34371
diff
changeset
|
22 |
|
683719e04218
Change the name of the macro used by --with-tsc builds to the less
Michael W. Hudson <mwh@python.net>
parents:
34371
diff
changeset
|
23 #define READ_TIMESTAMP(var) |
|
683719e04218
Change the name of the macro used by --with-tsc builds to the less
Michael W. Hudson <mwh@python.net>
parents:
34371
diff
changeset
|
24 |
|
683719e04218
Change the name of the macro used by --with-tsc builds to the less
Michael W. Hudson <mwh@python.net>
parents:
34371
diff
changeset
|
25 #else |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
26 |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
27 typedef unsigned long long uint64; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
28 |
|
68585
bf94b6a73fc8
#11565: Fix several typos. Patch by Piotr Kasprzyk.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
67414
diff
changeset
|
29 /* PowerPC support. |
|
67414
7e7fc94fd0d4
Merged revisions 87796 via svnmerge from
David Malcolm <dmalcolm@redhat.com>
parents:
62462
diff
changeset
|
30 "__ppc__" appears to be the preprocessor definition to detect on OS X, whereas |
|
7e7fc94fd0d4
Merged revisions 87796 via svnmerge from
David Malcolm <dmalcolm@redhat.com>
parents:
62462
diff
changeset
|
31 "__powerpc__" appears to be the correct one for Linux with GCC |
|
7e7fc94fd0d4
Merged revisions 87796 via svnmerge from
David Malcolm <dmalcolm@redhat.com>
parents:
62462
diff
changeset
|
32 */ |
|
7e7fc94fd0d4
Merged revisions 87796 via svnmerge from
David Malcolm <dmalcolm@redhat.com>
parents:
62462
diff
changeset
|
33 #if defined(__ppc__) || defined (__powerpc__) |
| 33104 | 34 |
|
34442
683719e04218
Change the name of the macro used by --with-tsc builds to the less
Michael W. Hudson <mwh@python.net>
parents:
34371
diff
changeset
|
35 #define READ_TIMESTAMP(var) ppc_getcounter(&var) |
| 33104 | 36 |
| 37 static void | |
| 38 ppc_getcounter(uint64 *v) | |
| 39 { | |
|
85157
e7f6cef7a4cc
Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85046
diff
changeset
|
40 unsigned long tbu, tb, tbu2; |
| 33104 | 41 |
| 42 loop: | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
43 asm volatile ("mftbu %0" : "=r" (tbu) ); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
44 asm volatile ("mftb %0" : "=r" (tb) ); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
45 asm volatile ("mftbu %0" : "=r" (tbu2)); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
46 if (__builtin_expect(tbu != tbu2, 0)) goto loop; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
47 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
48 /* The slightly peculiar way of writing the next lines is |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
49 compiled better by GCC than any other way I tried. */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
50 ((long*)(v))[0] = tbu; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
51 ((long*)(v))[1] = tb; |
| 33104 | 52 } |
| 53 | |
|
57005
264a735a8af7
Merged revisions 75984 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54459
diff
changeset
|
54 #elif defined(__i386__) |
|
264a735a8af7
Merged revisions 75984 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54459
diff
changeset
|
55 |
|
264a735a8af7
Merged revisions 75984 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54459
diff
changeset
|
56 /* this is for linux/x86 (and probably any other GCC/x86 combo) */ |
|
34442
683719e04218
Change the name of the macro used by --with-tsc builds to the less
Michael W. Hudson <mwh@python.net>
parents:
34371
diff
changeset
|
57 |
|
683719e04218
Change the name of the macro used by --with-tsc builds to the less
Michael W. Hudson <mwh@python.net>
parents:
34371
diff
changeset
|
58 #define READ_TIMESTAMP(val) \ |
|
683719e04218
Change the name of the macro used by --with-tsc builds to the less
Michael W. Hudson <mwh@python.net>
parents:
34371
diff
changeset
|
59 __asm__ __volatile__("rdtsc" : "=A" (val)) |
| 33104 | 60 |
|
57005
264a735a8af7
Merged revisions 75984 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54459
diff
changeset
|
61 #elif defined(__x86_64__) |
|
264a735a8af7
Merged revisions 75984 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54459
diff
changeset
|
62 |
|
264a735a8af7
Merged revisions 75984 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54459
diff
changeset
|
63 /* for gcc/x86_64, the "A" constraint in DI mode means *either* rax *or* rdx; |
|
264a735a8af7
Merged revisions 75984 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54459
diff
changeset
|
64 not edx:eax as it does for i386. Since rdtsc puts its result in edx:eax |
|
264a735a8af7
Merged revisions 75984 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54459
diff
changeset
|
65 even in 64-bit mode, we need to use "a" and "d" for the lower and upper |
|
264a735a8af7
Merged revisions 75984 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54459
diff
changeset
|
66 32-bit pieces of the result. */ |
|
264a735a8af7
Merged revisions 75984 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54459
diff
changeset
|
67 |
|
264a735a8af7
Merged revisions 75984 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54459
diff
changeset
|
68 #define READ_TIMESTAMP(val) \ |
|
264a735a8af7
Merged revisions 75984 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54459
diff
changeset
|
69 __asm__ __volatile__("rdtsc" : \ |
|
264a735a8af7
Merged revisions 75984 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54459
diff
changeset
|
70 "=a" (((int*)&(val))[0]), "=d" (((int*)&(val))[1])); |
|
264a735a8af7
Merged revisions 75984 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54459
diff
changeset
|
71 |
|
264a735a8af7
Merged revisions 75984 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54459
diff
changeset
|
72 |
|
264a735a8af7
Merged revisions 75984 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54459
diff
changeset
|
73 #else |
|
264a735a8af7
Merged revisions 75984 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54459
diff
changeset
|
74 |
|
264a735a8af7
Merged revisions 75984 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54459
diff
changeset
|
75 #error "Don't know how to implement timestamp counter for this architecture" |
|
264a735a8af7
Merged revisions 75984 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54459
diff
changeset
|
76 |
| 33104 | 77 #endif |
| 78 | |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
79 void dump_tsc(int opcode, int ticked, uint64 inst0, uint64 inst1, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
80 uint64 loop0, uint64 loop1, uint64 intr0, uint64 intr1) |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
81 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
82 uint64 intr, inst, loop; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
83 PyThreadState *tstate = PyThreadState_Get(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
84 if (!tstate->interp->tscdump) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
85 return; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
86 intr = intr1 - intr0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
87 inst = inst1 - inst0 - intr; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
88 loop = loop1 - loop0 - intr; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
89 fprintf(stderr, "opcode=%03d t=%d inst=%06lld loop=%06lld\n", |
|
62462
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
90 opcode, ticked, inst, loop); |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
91 } |
| 33104 | 92 |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
93 #endif |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
94 |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
95 /* Turn this on if your compiler chokes on the big switch: */ |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
96 /* #define CASE_TOO_BIG 1 */ |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
97 |
|
4839
4567e158d20c
Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents:
4667
diff
changeset
|
98 #ifdef Py_DEBUG |
| 567 | 99 /* For debugging the interpreter: */ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
100 #define LLTRACE 1 /* Low-level trace feature */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
101 #define CHECKEXC 1 /* Double-check exception checking */ |
| 69 | 102 #endif |
| 103 | |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
104 typedef PyObject *(*callproc)(PyObject *, PyObject *, PyObject *); |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
105 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
106 /* Forward declarations */ |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
107 #ifdef WITH_TSC |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
108 static PyObject * call_function(PyObject ***, int, uint64*, uint64*); |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
109 #else |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
110 static PyObject * call_function(PyObject ***, int); |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
111 #endif |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
112 static PyObject * fast_function(PyObject *, PyObject ***, int, int, int); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
113 static PyObject * do_call(PyObject *, PyObject ***, int, int); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
114 static PyObject * ext_do_call(PyObject *, PyObject ***, int, int, int); |
|
43418
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
115 static PyObject * update_keyword_args(PyObject *, int, PyObject ***, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
116 PyObject *); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
117 static PyObject * update_star_args(int, int, PyObject *, PyObject ***); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
118 static PyObject * load_args(PyObject ***, int); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
119 #define CALL_FLAG_VAR 1 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
120 #define CALL_FLAG_KW 2 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
121 |
|
746
6c0f16008bd9
lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents:
708
diff
changeset
|
122 #ifdef LLTRACE |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
123 static int lltrace; |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
124 static int prtrace(PyObject *, char *); |
|
746
6c0f16008bd9
lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents:
708
diff
changeset
|
125 #endif |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
126 static int call_trace(Py_tracefunc, PyObject *, PyFrameObject *, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
127 int, PyObject *); |
|
43840
73c8e27eb9ce
Correction for issue1265 (pdb bug with "with" statement).
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43815
diff
changeset
|
128 static int call_trace_protected(Py_tracefunc, PyObject *, |
|
62462
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
129 PyFrameObject *, int, PyObject *); |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
130 static void call_exc_trace(Py_tracefunc, PyObject *, PyFrameObject *); |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
131 static int maybe_call_line_trace(Py_tracefunc, PyObject *, |
|
62462
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
132 PyFrameObject *, int *, int *, int *); |
| 24844 | 133 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
134 static PyObject * cmp_outcome(int, PyObject *, PyObject *); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
135 static PyObject * import_from(PyObject *, PyObject *); |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
136 static int import_all_from(PyObject *, PyObject *); |
| 42860 | 137 static void format_exc_check_arg(PyObject *, const char *, PyObject *); |
|
64620
25cc226dc9bd
#4617: Previously it was illegal to delete a name from the local
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64439
diff
changeset
|
138 static void format_exc_unbound(PyCodeObject *co, int oparg); |
|
72605
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
139 static PyObject * unicode_concatenate(PyObject *, PyObject *, |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
140 PyFrameObject *, unsigned char *); |
|
74578
7d96679c5d46
use the static identifier api for looking up special methods
Benjamin Peterson <benjamin@python.org>
parents:
74367
diff
changeset
|
141 static PyObject * special_lookup(PyObject *, _Py_Identifier *); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
142 |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
143 #define NAME_ERROR_MSG \ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
144 "name '%.200s' is not defined" |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
145 #define UNBOUNDLOCAL_ERROR_MSG \ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
146 "local variable '%.200s' referenced before assignment" |
|
17494
a34293ced63b
Change error message raised when free variable is not yet bound. It
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17490
diff
changeset
|
147 #define UNBOUNDFREE_ERROR_MSG \ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
148 "free variable '%.200s' referenced before assignment" \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
149 " in enclosing scope" |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
150 |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
151 /* Dynamic execution profile */ |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
152 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
153 #ifdef DXPAIRS |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
154 static long dxpairs[257][256]; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
155 #define dxp dxpairs[256] |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
156 #else |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
157 static long dxp[256]; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
158 #endif |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
159 #endif |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
160 |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
161 /* Function call profile */ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
162 #ifdef CALL_PROFILE |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
163 #define PCALL_NUM 11 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
164 static int pcall[PCALL_NUM]; |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
165 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
166 #define PCALL_ALL 0 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
167 #define PCALL_FUNCTION 1 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
168 #define PCALL_FAST_FUNCTION 2 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
169 #define PCALL_FASTER_FUNCTION 3 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
170 #define PCALL_METHOD 4 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
171 #define PCALL_BOUND_METHOD 5 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
172 #define PCALL_CFUNCTION 6 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
173 #define PCALL_TYPE 7 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
174 #define PCALL_GENERATOR 8 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
175 #define PCALL_OTHER 9 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
176 #define PCALL_POP 10 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
177 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
178 /* Notes about the statistics |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
179 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
180 PCALL_FAST stats |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
181 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
182 FAST_FUNCTION means no argument tuple needs to be created. |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
183 FASTER_FUNCTION means that the fast-path frame setup code is used. |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
184 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
185 If there is a method call where the call can be optimized by changing |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
186 the argument tuple and calling the function directly, it gets recorded |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
187 twice. |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
188 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
189 As a result, the relationship among the statistics appears to be |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
190 PCALL_ALL == PCALL_FUNCTION + PCALL_METHOD - PCALL_BOUND_METHOD + |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
191 PCALL_CFUNCTION + PCALL_TYPE + PCALL_GENERATOR + PCALL_OTHER |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
192 PCALL_FUNCTION > PCALL_FAST_FUNCTION > PCALL_FASTER_FUNCTION |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
193 PCALL_METHOD > PCALL_BOUND_METHOD |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
194 */ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
195 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
196 #define PCALL(POS) pcall[POS]++ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
197 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
198 PyObject * |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
199 PyEval_GetCallStats(PyObject *self) |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
200 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
201 return Py_BuildValue("iiiiiiiiiii", |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
202 pcall[0], pcall[1], pcall[2], pcall[3], |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
203 pcall[4], pcall[5], pcall[6], pcall[7], |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
204 pcall[8], pcall[9], pcall[10]); |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
205 } |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
206 #else |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
207 #define PCALL(O) |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
208 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
209 PyObject * |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
210 PyEval_GetCallStats(PyObject *self) |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
211 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
212 Py_INCREF(Py_None); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
213 return Py_None; |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
214 } |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
215 #endif |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
216 |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
217 |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
218 #ifdef WITH_THREAD |
|
64628
56844b716cd7
remove gil_drop_request in --without-threads
Benjamin Peterson <benjamin@python.org>
parents:
64624
diff
changeset
|
219 #define GIL_REQUEST _Py_atomic_load_relaxed(&gil_drop_request) |
|
56844b716cd7
remove gil_drop_request in --without-threads
Benjamin Peterson <benjamin@python.org>
parents:
64624
diff
changeset
|
220 #else |
|
56844b716cd7
remove gil_drop_request in --without-threads
Benjamin Peterson <benjamin@python.org>
parents:
64624
diff
changeset
|
221 #define GIL_REQUEST 0 |
|
56844b716cd7
remove gil_drop_request in --without-threads
Benjamin Peterson <benjamin@python.org>
parents:
64624
diff
changeset
|
222 #endif |
|
56844b716cd7
remove gil_drop_request in --without-threads
Benjamin Peterson <benjamin@python.org>
parents:
64624
diff
changeset
|
223 |
|
61184
4fd3ab5fa71d
Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
60130
diff
changeset
|
224 /* This can set eval_breaker to 0 even though gil_drop_request became |
|
4fd3ab5fa71d
Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
60130
diff
changeset
|
225 1. We believe this is all right because the eval loop will release |
|
4fd3ab5fa71d
Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
60130
diff
changeset
|
226 the GIL eventually anyway. */ |
|
57175
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
227 #define COMPUTE_EVAL_BREAKER() \ |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
228 _Py_atomic_store_relaxed( \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
229 &eval_breaker, \ |
|
64628
56844b716cd7
remove gil_drop_request in --without-threads
Benjamin Peterson <benjamin@python.org>
parents:
64624
diff
changeset
|
230 GIL_REQUEST | \ |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
231 _Py_atomic_load_relaxed(&pendingcalls_to_do) | \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
232 pending_async_exc) |
|
57175
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
233 |
|
64628
56844b716cd7
remove gil_drop_request in --without-threads
Benjamin Peterson <benjamin@python.org>
parents:
64624
diff
changeset
|
234 #ifdef WITH_THREAD |
|
56844b716cd7
remove gil_drop_request in --without-threads
Benjamin Peterson <benjamin@python.org>
parents:
64624
diff
changeset
|
235 |
|
57175
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
236 #define SET_GIL_DROP_REQUEST() \ |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
237 do { \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
238 _Py_atomic_store_relaxed(&gil_drop_request, 1); \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
239 _Py_atomic_store_relaxed(&eval_breaker, 1); \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
240 } while (0) |
|
57175
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
241 |
|
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
242 #define RESET_GIL_DROP_REQUEST() \ |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
243 do { \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
244 _Py_atomic_store_relaxed(&gil_drop_request, 0); \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
245 COMPUTE_EVAL_BREAKER(); \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
246 } while (0) |
|
61184
4fd3ab5fa71d
Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
60130
diff
changeset
|
247 |
|
64628
56844b716cd7
remove gil_drop_request in --without-threads
Benjamin Peterson <benjamin@python.org>
parents:
64624
diff
changeset
|
248 #endif |
|
56844b716cd7
remove gil_drop_request in --without-threads
Benjamin Peterson <benjamin@python.org>
parents:
64624
diff
changeset
|
249 |
|
61184
4fd3ab5fa71d
Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
60130
diff
changeset
|
250 /* Pending calls are only modified under pending_lock */ |
|
57175
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
251 #define SIGNAL_PENDING_CALLS() \ |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
252 do { \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
253 _Py_atomic_store_relaxed(&pendingcalls_to_do, 1); \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
254 _Py_atomic_store_relaxed(&eval_breaker, 1); \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
255 } while (0) |
|
57175
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
256 |
|
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
257 #define UNSIGNAL_PENDING_CALLS() \ |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
258 do { \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
259 _Py_atomic_store_relaxed(&pendingcalls_to_do, 0); \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
260 COMPUTE_EVAL_BREAKER(); \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
261 } while (0) |
|
57175
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
262 |
|
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
263 #define SIGNAL_ASYNC_EXC() \ |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
264 do { \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
265 pending_async_exc = 1; \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
266 _Py_atomic_store_relaxed(&eval_breaker, 1); \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
267 } while (0) |
|
57175
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
268 |
|
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
269 #define UNSIGNAL_ASYNC_EXC() \ |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
270 do { pending_async_exc = 0; COMPUTE_EVAL_BREAKER(); } while (0) |
|
57175
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
271 |
|
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
272 |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
273 #ifdef WITH_THREAD |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
274 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
275 #ifdef HAVE_ERRNO_H |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
276 #include <errno.h> |
|
10530
d834ecdf8c26
Changes by Mark Hammond for Windows CE. Mostly of the form
Guido van Rossum <guido@python.org>
parents:
10363
diff
changeset
|
277 #endif |
|
9203
07dae6fdae79
Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents:
9048
diff
changeset
|
278 #include "pythread.h" |
| 926 | 279 |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
280 static PyThread_type_lock pending_lock = 0; /* for pending calls */ |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
281 static long main_thread = 0; |
|
57175
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
282 /* This single variable consolidates all requests to break out of the fast path |
|
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
283 in the eval loop. */ |
|
61184
4fd3ab5fa71d
Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
60130
diff
changeset
|
284 static _Py_atomic_int eval_breaker = {0}; |
|
4fd3ab5fa71d
Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
60130
diff
changeset
|
285 /* Request for dropping the GIL */ |
|
4fd3ab5fa71d
Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
60130
diff
changeset
|
286 static _Py_atomic_int gil_drop_request = {0}; |
|
4fd3ab5fa71d
Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
60130
diff
changeset
|
287 /* Request for running pending calls. */ |
|
4fd3ab5fa71d
Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
60130
diff
changeset
|
288 static _Py_atomic_int pendingcalls_to_do = {0}; |
|
4fd3ab5fa71d
Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
60130
diff
changeset
|
289 /* Request for looking at the `async_exc` field of the current thread state. |
|
4fd3ab5fa71d
Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
60130
diff
changeset
|
290 Guarded by the GIL. */ |
|
4fd3ab5fa71d
Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
60130
diff
changeset
|
291 static int pending_async_exc = 0; |
|
57175
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
292 |
|
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
293 #include "ceval_gil.h" |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
294 |
|
33715
a46b76eb9053
SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents:
33501
diff
changeset
|
295 int |
|
a46b76eb9053
SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents:
33501
diff
changeset
|
296 PyEval_ThreadsInitialized(void) |
|
a46b76eb9053
SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents:
33501
diff
changeset
|
297 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
298 return gil_created(); |
|
33715
a46b76eb9053
SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents:
33501
diff
changeset
|
299 } |
|
a46b76eb9053
SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents:
33501
diff
changeset
|
300 |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
301 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
302 PyEval_InitThreads(void) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
303 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
304 if (gil_created()) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
305 return; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
306 create_gil(); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
307 take_gil(PyThreadState_GET()); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
308 main_thread = PyThread_get_thread_ident(); |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
309 if (!pending_lock) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
310 pending_lock = PyThread_allocate_lock(); |
| 926 | 311 } |
| 312 | |
|
5865
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
313 void |
|
64709
557e2537c9ae
Issue #9828: Destroy the GIL in Py_Finalize(), so that it gets properly
Antoine Pitrou <solipsis@pitrou.net>
parents:
64634
diff
changeset
|
314 _PyEval_FiniThreads(void) |
|
557e2537c9ae
Issue #9828: Destroy the GIL in Py_Finalize(), so that it gets properly
Antoine Pitrou <solipsis@pitrou.net>
parents:
64634
diff
changeset
|
315 { |
|
557e2537c9ae
Issue #9828: Destroy the GIL in Py_Finalize(), so that it gets properly
Antoine Pitrou <solipsis@pitrou.net>
parents:
64634
diff
changeset
|
316 if (!gil_created()) |
|
557e2537c9ae
Issue #9828: Destroy the GIL in Py_Finalize(), so that it gets properly
Antoine Pitrou <solipsis@pitrou.net>
parents:
64634
diff
changeset
|
317 return; |
|
557e2537c9ae
Issue #9828: Destroy the GIL in Py_Finalize(), so that it gets properly
Antoine Pitrou <solipsis@pitrou.net>
parents:
64634
diff
changeset
|
318 destroy_gil(); |
|
557e2537c9ae
Issue #9828: Destroy the GIL in Py_Finalize(), so that it gets properly
Antoine Pitrou <solipsis@pitrou.net>
parents:
64634
diff
changeset
|
319 assert(!gil_created()); |
| 926 | 320 } |
| 321 | |
|
5865
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
322 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
323 PyEval_AcquireLock(void) |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
324 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
325 PyThreadState *tstate = PyThreadState_GET(); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
326 if (tstate == NULL) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
327 Py_FatalError("PyEval_AcquireLock: current thread state is NULL"); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
328 take_gil(tstate); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
329 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
330 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
331 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
332 PyEval_ReleaseLock(void) |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
333 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
334 /* This function must succeed when the current thread state is NULL. |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
335 We therefore avoid PyThreadState_GET() which dumps a fatal error |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
336 in debug mode. |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
337 */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
338 drop_gil((PyThreadState*)_Py_atomic_load_relaxed( |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
339 &_PyThreadState_Current)); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
340 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
341 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
342 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
343 PyEval_AcquireThread(PyThreadState *tstate) |
|
5865
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
344 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
345 if (tstate == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
346 Py_FatalError("PyEval_AcquireThread: NULL new thread state"); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
347 /* Check someone has called PyEval_InitThreads() to create the lock */ |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
348 assert(gil_created()); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
349 take_gil(tstate); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
350 if (PyThreadState_Swap(tstate) != NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
351 Py_FatalError( |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
352 "PyEval_AcquireThread: non-NULL old thread state"); |
|
5865
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
353 } |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
354 |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
355 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
356 PyEval_ReleaseThread(PyThreadState *tstate) |
|
5865
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
357 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
358 if (tstate == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
359 Py_FatalError("PyEval_ReleaseThread: NULL thread state"); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
360 if (PyThreadState_Swap(NULL) != tstate) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
361 Py_FatalError("PyEval_ReleaseThread: wrong thread state"); |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
362 drop_gil(tstate); |
|
5865
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
363 } |
|
14225
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
364 |
|
83630
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83572
diff
changeset
|
365 /* This function is called from PyOS_AfterFork to destroy all threads which are |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83572
diff
changeset
|
366 * not running in the child process, and clear internal locks which might be |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83572
diff
changeset
|
367 * held by those threads. (This could also be done using pthread_atfork |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83572
diff
changeset
|
368 * mechanism, at least for the pthreads implementation.) */ |
|
14225
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
369 |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
370 void |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
371 PyEval_ReInitThreads(void) |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
372 { |
|
72925
7109f31300fb
Rename _Py_identifier to _Py_IDENTIFIER.
Martin v. Löwis <martin@v.loewis.de>
parents:
72835
diff
changeset
|
373 _Py_IDENTIFIER(_after_fork); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
374 PyObject *threading, *result; |
|
83630
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83572
diff
changeset
|
375 PyThreadState *current_tstate = PyThreadState_GET(); |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
376 |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
377 if (!gil_created()) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
378 return; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
379 recreate_gil(); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
380 pending_lock = PyThread_allocate_lock(); |
|
83630
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83572
diff
changeset
|
381 take_gil(current_tstate); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
382 main_thread = PyThread_get_thread_ident(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
383 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
384 /* Update the threading module with the new state. |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
385 */ |
|
83630
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83572
diff
changeset
|
386 threading = PyMapping_GetItemString(current_tstate->interp->modules, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
387 "threading"); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
388 if (threading == NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
389 /* threading not imported */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
390 PyErr_Clear(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
391 return; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
392 } |
|
72835
5e33219492bc
Add API for static strings, primarily good for identifiers.
Martin v. Löwis <martin@v.loewis.de>
parents:
72605
diff
changeset
|
393 result = _PyObject_CallMethodId(threading, &PyId__after_fork, NULL); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
394 if (result == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
395 PyErr_WriteUnraisable(threading); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
396 else |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
397 Py_DECREF(result); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
398 Py_DECREF(threading); |
|
83630
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83572
diff
changeset
|
399 |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83572
diff
changeset
|
400 /* Destroy all threads except the current one */ |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83572
diff
changeset
|
401 _PyThreadState_DeleteExcept(current_tstate); |
|
14225
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
402 } |
|
57175
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
403 |
|
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
404 #else |
|
61184
4fd3ab5fa71d
Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
60130
diff
changeset
|
405 static _Py_atomic_int eval_breaker = {0}; |
|
57175
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
406 static int pending_async_exc = 0; |
|
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
407 #endif /* WITH_THREAD */ |
|
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
408 |
|
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
409 /* This function is used to signal that async exceptions are waiting to be |
|
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
410 raised, therefore it is also useful in non-threaded builds. */ |
|
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
411 |
|
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
412 void |
|
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
413 _PyEval_SignalAsyncExc(void) |
|
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
414 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
415 SIGNAL_ASYNC_EXC(); |
|
57175
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
416 } |
| 926 | 417 |
| 418 /* Functions save_thread and restore_thread are always defined so | |
| 419 dynamically loaded modules needn't be compiled separately for use | |
| 420 with and without threads: */ | |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
421 |
|
5846
852a1fa62a7c
PyEval_SaveThread() and PyEval_RestoreThread() now return/take a
Guido van Rossum <guido@python.org>
parents:
5829
diff
changeset
|
422 PyThreadState * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
423 PyEval_SaveThread(void) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
424 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
425 PyThreadState *tstate = PyThreadState_Swap(NULL); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
426 if (tstate == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
427 Py_FatalError("PyEval_SaveThread: NULL tstate"); |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
428 #ifdef WITH_THREAD |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
429 if (gil_created()) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
430 drop_gil(tstate); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
431 #endif |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
432 return tstate; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
433 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
434 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
435 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
436 PyEval_RestoreThread(PyThreadState *tstate) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
437 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
438 if (tstate == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
439 Py_FatalError("PyEval_RestoreThread: NULL tstate"); |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
440 #ifdef WITH_THREAD |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
441 if (gil_created()) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
442 int err = errno; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
443 take_gil(tstate); |
|
69832
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
68586
diff
changeset
|
444 /* _Py_Finalizing is protected by the GIL */ |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
68586
diff
changeset
|
445 if (_Py_Finalizing && tstate != _Py_Finalizing) { |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
68586
diff
changeset
|
446 drop_gil(tstate); |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
68586
diff
changeset
|
447 PyThread_exit_thread(); |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
68586
diff
changeset
|
448 assert(0); /* unreachable */ |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
68586
diff
changeset
|
449 } |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
450 errno = err; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
451 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
452 #endif |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
453 PyThreadState_Swap(tstate); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
454 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
455 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
456 |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
457 /* Mechanism whereby asynchronously executing callbacks (e.g. UNIX |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
458 signal handlers or Mac I/O completion routines) can schedule calls |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
459 to a function to be called synchronously. |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
460 The synchronous function is called with one void* argument. |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
461 It should return 0 for success or -1 for failure -- failure should |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
462 be accompanied by an exception. |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
463 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
464 If registry succeeds, the registry function returns 0; if it fails |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
465 (e.g. due to too many pending calls) it returns -1 (without setting |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
466 an exception condition). |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
467 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
468 Note that because registry may occur from within signal handlers, |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
469 or other asynchronous events, calling malloc() is unsafe! |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
470 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
471 #ifdef WITH_THREAD |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
472 Any thread can schedule pending calls, but only the main thread |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
473 will execute them. |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
474 There is no facility to schedule calls to a particular thread, but |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
475 that should be easy to change, should that ever be required. In |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
476 that case, the static variables here should go into the python |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
477 threadstate. |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
478 #endif |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
479 */ |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
480 |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
481 #ifdef WITH_THREAD |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
482 |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
483 /* The WITH_THREAD implementation is thread-safe. It allows |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
484 scheduling to be made from any thread, and even from an executing |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
485 callback. |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
486 */ |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
487 |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
488 #define NPENDINGCALLS 32 |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
489 static struct { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
490 int (*func)(void *); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
491 void *arg; |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
492 } pendingcalls[NPENDINGCALLS]; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
493 static int pendingfirst = 0; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
494 static int pendinglast = 0; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
495 |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
496 int |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
497 Py_AddPendingCall(int (*func)(void *), void *arg) |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
498 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
499 int i, j, result=0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
500 PyThread_type_lock lock = pending_lock; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
501 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
502 /* try a few times for the lock. Since this mechanism is used |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
503 * for signal handling (on the main thread), there is a (slim) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
504 * chance that a signal is delivered on the same thread while we |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
505 * hold the lock during the Py_MakePendingCalls() function. |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
506 * This avoids a deadlock in that case. |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
507 * Note that signals can be delivered on any thread. In particular, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
508 * on Windows, a SIGINT is delivered on a system-created worker |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
509 * thread. |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
510 * We also check for lock being NULL, in the unlikely case that |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
511 * this function is called before any bytecode evaluation takes place. |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
512 */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
513 if (lock != NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
514 for (i = 0; i<100; i++) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
515 if (PyThread_acquire_lock(lock, NOWAIT_LOCK)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
516 break; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
517 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
518 if (i == 100) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
519 return -1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
520 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
521 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
522 i = pendinglast; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
523 j = (i + 1) % NPENDINGCALLS; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
524 if (j == pendingfirst) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
525 result = -1; /* Queue full */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
526 } else { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
527 pendingcalls[i].func = func; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
528 pendingcalls[i].arg = arg; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
529 pendinglast = j; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
530 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
531 /* signal main loop */ |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
532 SIGNAL_PENDING_CALLS(); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
533 if (lock != NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
534 PyThread_release_lock(lock); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
535 return result; |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
536 } |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
537 |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
538 int |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
539 Py_MakePendingCalls(void) |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
540 { |
|
71481
cda93720c06d
Issue 12620: Make pendingbusy flag static to Py_MakePendingCalls().
Charles-François Natali <neologix@free.fr>
parents:
71402
diff
changeset
|
541 static int busy = 0; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
542 int i; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
543 int r = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
544 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
545 if (!pending_lock) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
546 /* initial allocation of the lock */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
547 pending_lock = PyThread_allocate_lock(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
548 if (pending_lock == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
549 return -1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
550 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
551 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
552 /* only service pending calls on main thread */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
553 if (main_thread && PyThread_get_thread_ident() != main_thread) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
554 return 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
555 /* don't perform recursive pending calls */ |
|
71481
cda93720c06d
Issue 12620: Make pendingbusy flag static to Py_MakePendingCalls().
Charles-François Natali <neologix@free.fr>
parents:
71402
diff
changeset
|
556 if (busy) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
557 return 0; |
|
71481
cda93720c06d
Issue 12620: Make pendingbusy flag static to Py_MakePendingCalls().
Charles-François Natali <neologix@free.fr>
parents:
71402
diff
changeset
|
558 busy = 1; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
559 /* perform a bounded number of calls, in case of recursion */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
560 for (i=0; i<NPENDINGCALLS; i++) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
561 int j; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
562 int (*func)(void *); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
563 void *arg = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
564 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
565 /* pop one item off the queue while holding the lock */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
566 PyThread_acquire_lock(pending_lock, WAIT_LOCK); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
567 j = pendingfirst; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
568 if (j == pendinglast) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
569 func = NULL; /* Queue empty */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
570 } else { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
571 func = pendingcalls[j].func; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
572 arg = pendingcalls[j].arg; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
573 pendingfirst = (j + 1) % NPENDINGCALLS; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
574 } |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
575 if (pendingfirst != pendinglast) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
576 SIGNAL_PENDING_CALLS(); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
577 else |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
578 UNSIGNAL_PENDING_CALLS(); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
579 PyThread_release_lock(pending_lock); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
580 /* having released the lock, perform the callback */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
581 if (func == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
582 break; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
583 r = func(arg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
584 if (r) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
585 break; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
586 } |
|
71481
cda93720c06d
Issue 12620: Make pendingbusy flag static to Py_MakePendingCalls().
Charles-François Natali <neologix@free.fr>
parents:
71402
diff
changeset
|
587 busy = 0; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
588 return r; |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
589 } |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
590 |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
591 #else /* if ! defined WITH_THREAD */ |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
592 |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
593 /* |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
594 WARNING! ASYNCHRONOUSLY EXECUTING CODE! |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
595 This code is used for signal handling in python that isn't built |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
596 with WITH_THREAD. |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
597 Don't use this implementation when Py_AddPendingCalls() can happen |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
598 on a different thread! |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
599 |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
600 There are two possible race conditions: |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
601 (1) nested asynchronous calls to Py_AddPendingCall() |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
602 (2) AddPendingCall() calls made while pending calls are being processed. |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
603 |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
604 (1) is very unlikely because typically signal delivery |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
605 is blocked during signal handling. So it should be impossible. |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
606 (2) is a real possibility. |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
607 The current code is safe against (2), but not against (1). |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
608 The safety against (2) is derived from the fact that only one |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
609 thread is present, interrupted by signals, and that the critical |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
610 section is protected with the "busy" variable. On Windows, which |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
611 delivers SIGINT on a system thread, this does not hold and therefore |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
612 Windows really shouldn't use this version. |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
613 The two threads could theoretically wiggle around the "busy" variable. |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
614 */ |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
615 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
616 #define NPENDINGCALLS 32 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
617 static struct { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
618 int (*func)(void *); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
619 void *arg; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
620 } pendingcalls[NPENDINGCALLS]; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
621 static volatile int pendingfirst = 0; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
622 static volatile int pendinglast = 0; |
|
61993
e766c0d86cff
use atomic structures in non-thread version
Benjamin Peterson <benjamin@python.org>
parents:
61466
diff
changeset
|
623 static _Py_atomic_int pendingcalls_to_do = {0}; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
624 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
625 int |
|
13709
4e2aaf1e722a
Use 'void' directly instead of the ANY #define, now that all code is ANSI C.
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
626 Py_AddPendingCall(int (*func)(void *), void *arg) |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
627 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
628 static volatile int busy = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
629 int i, j; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
630 /* XXX Begin critical section */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
631 if (busy) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
632 return -1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
633 busy = 1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
634 i = pendinglast; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
635 j = (i + 1) % NPENDINGCALLS; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
636 if (j == pendingfirst) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
637 busy = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
638 return -1; /* Queue full */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
639 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
640 pendingcalls[i].func = func; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
641 pendingcalls[i].arg = arg; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
642 pendinglast = j; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
643 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
644 SIGNAL_PENDING_CALLS(); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
645 busy = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
646 /* XXX End critical section */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
647 return 0; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
648 } |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
649 |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
650 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
651 Py_MakePendingCalls(void) |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
652 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
653 static int busy = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
654 if (busy) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
655 return 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
656 busy = 1; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
657 UNSIGNAL_PENDING_CALLS(); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
658 for (;;) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
659 int i; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
660 int (*func)(void *); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
661 void *arg; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
662 i = pendingfirst; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
663 if (i == pendinglast) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
664 break; /* Queue empty */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
665 func = pendingcalls[i].func; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
666 arg = pendingcalls[i].arg; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
667 pendingfirst = (i + 1) % NPENDINGCALLS; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
668 if (func(arg) < 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
669 busy = 0; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
670 SIGNAL_PENDING_CALLS(); /* We're not done yet */ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
671 return -1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
672 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
673 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
674 busy = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
675 return 0; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
676 } |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
677 |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
678 #endif /* WITH_THREAD */ |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
679 |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
680 |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
681 /* The interpreter's recursion limit */ |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
682 |
|
34863
71fd7ee4b7f5
Make a handy macro, Py_DEFAULT_RECURSION_LIMIT to allow to define
Hye-Shik Chang <hyeshik@gmail.com>
parents:
34442
diff
changeset
|
683 #ifndef Py_DEFAULT_RECURSION_LIMIT |
|
71fd7ee4b7f5
Make a handy macro, Py_DEFAULT_RECURSION_LIMIT to allow to define
Hye-Shik Chang <hyeshik@gmail.com>
parents:
34442
diff
changeset
|
684 #define Py_DEFAULT_RECURSION_LIMIT 1000 |
|
71fd7ee4b7f5
Make a handy macro, Py_DEFAULT_RECURSION_LIMIT to allow to define
Hye-Shik Chang <hyeshik@gmail.com>
parents:
34442
diff
changeset
|
685 #endif |
|
71fd7ee4b7f5
Make a handy macro, Py_DEFAULT_RECURSION_LIMIT to allow to define
Hye-Shik Chang <hyeshik@gmail.com>
parents:
34442
diff
changeset
|
686 static int recursion_limit = Py_DEFAULT_RECURSION_LIMIT; |
|
71fd7ee4b7f5
Make a handy macro, Py_DEFAULT_RECURSION_LIMIT to allow to define
Hye-Shik Chang <hyeshik@gmail.com>
parents:
34442
diff
changeset
|
687 int _Py_CheckRecursionLimit = Py_DEFAULT_RECURSION_LIMIT; |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
688 |
|
14348
6d0f64f7dedd
Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14333
diff
changeset
|
689 int |
|
6d0f64f7dedd
Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14333
diff
changeset
|
690 Py_GetRecursionLimit(void) |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
691 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
692 return recursion_limit; |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
693 } |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
694 |
|
14348
6d0f64f7dedd
Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14333
diff
changeset
|
695 void |
|
6d0f64f7dedd
Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14333
diff
changeset
|
696 Py_SetRecursionLimit(int new_limit) |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
697 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
698 recursion_limit = new_limit; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
699 _Py_CheckRecursionLimit = recursion_limit; |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
700 } |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
701 |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
702 /* the macro Py_EnterRecursiveCall() only calls _Py_CheckRecursiveCall() |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
703 if the recursion_depth reaches _Py_CheckRecursionLimit. |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
704 If USE_STACKCHECK, the macro decrements _Py_CheckRecursionLimit |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
705 to guarantee that _Py_CheckRecursiveCall() is regularly called. |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
706 Without USE_STACKCHECK, there is no need for this. */ |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
707 int |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
708 _Py_CheckRecursiveCall(char *where) |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
709 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
710 PyThreadState *tstate = PyThreadState_GET(); |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
711 |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
712 #ifdef USE_STACKCHECK |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
713 if (PyOS_CheckStack()) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
714 --tstate->recursion_depth; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
715 PyErr_SetString(PyExc_MemoryError, "Stack overflow"); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
716 return -1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
717 } |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
718 #endif |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
719 _Py_CheckRecursionLimit = recursion_limit; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
720 if (tstate->recursion_critical) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
721 /* Somebody asked that we don't check for recursion. */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
722 return 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
723 if (tstate->overflowed) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
724 if (tstate->recursion_depth > recursion_limit + 50) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
725 /* Overflowing while handling an overflow. Give up. */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
726 Py_FatalError("Cannot recover from stack overflow."); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
727 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
728 return 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
729 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
730 if (tstate->recursion_depth > recursion_limit) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
731 --tstate->recursion_depth; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
732 tstate->overflowed = 1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
733 PyErr_Format(PyExc_RuntimeError, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
734 "maximum recursion depth exceeded%s", |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
735 where); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
736 return -1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
737 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
738 return 0; |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
739 } |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
740 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
741 /* Status code for main loop (reason for stack unwind) */ |
|
31875
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
742 enum why_code { |
|
62462
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
743 WHY_NOT = 0x0001, /* No error */ |
|
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
744 WHY_EXCEPTION = 0x0002, /* Exception occurred */ |
|
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
745 WHY_RETURN = 0x0008, /* 'return' statement */ |
|
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
746 WHY_BREAK = 0x0010, /* 'break' statement */ |
|
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
747 WHY_CONTINUE = 0x0020, /* 'continue' statement */ |
|
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
748 WHY_YIELD = 0x0040, /* 'yield' operator */ |
|
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
749 WHY_SILENCED = 0x0080 /* Exception silenced by 'with' */ |
|
31875
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
750 }; |
|
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
751 |
|
71159
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
752 static void save_exc_state(PyThreadState *, PyFrameObject *); |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
753 static void swap_exc_state(PyThreadState *, PyFrameObject *); |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
754 static void restore_and_clear_exc_state(PyThreadState *, PyFrameObject *); |
| 79693 | 755 static int do_raise(PyObject *, PyObject *); |
|
41699
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
756 static int unpack_iterable(PyObject *, int, int, PyObject **); |
| 5018 | 757 |
|
50045
ba8fe3a40a5b
Merged revisions 67494 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
48986
diff
changeset
|
758 /* Records whether tracing is on for any thread. Counts the number of |
|
ba8fe3a40a5b
Merged revisions 67494 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
48986
diff
changeset
|
759 threads for which tstate->c_tracefunc is non-NULL, so if the value |
|
ba8fe3a40a5b
Merged revisions 67494 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
48986
diff
changeset
|
760 is 0, we know we don't have to check this thread's c_tracefunc. |
|
ba8fe3a40a5b
Merged revisions 67494 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
48986
diff
changeset
|
761 This speeds up the if statement in PyEval_EvalFrameEx() after |
|
ba8fe3a40a5b
Merged revisions 67494 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
48986
diff
changeset
|
762 fast_next_opcode*/ |
|
ba8fe3a40a5b
Merged revisions 67494 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
48986
diff
changeset
|
763 static int _Py_TracingPossible = 0; |
|
ba8fe3a40a5b
Merged revisions 67494 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
48986
diff
changeset
|
764 |
|
57175
fdd6484f1210
Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
57004
diff
changeset
|
765 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
766 |
| 5368 | 767 PyObject * |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
66556
diff
changeset
|
768 PyEval_EvalCode(PyObject *co, PyObject *globals, PyObject *locals) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
769 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
770 return PyEval_EvalCodeEx(co, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
771 globals, locals, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
772 (PyObject **)NULL, 0, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
773 (PyObject **)NULL, 0, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
774 (PyObject **)NULL, 0, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
775 NULL, NULL); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
776 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
777 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
778 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
779 /* Interpreter main loop */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
780 |
|
32421
485d2ef43419
Patch #966493: Cleanup generator/eval_frame exposure.
Martin v. Löwis <martin@v.loewis.de>
parents:
32412
diff
changeset
|
781 PyObject * |
|
35298
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
782 PyEval_EvalFrame(PyFrameObject *f) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
783 /* This is for backward compatibility with extension modules that |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
784 used this API; core interpreter code should call |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
785 PyEval_EvalFrameEx() */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
786 return PyEval_EvalFrameEx(f, 0); |
|
35298
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
787 } |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
788 |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
789 PyObject * |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
790 PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
791 { |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
792 #ifdef DXPAIRS |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
793 int lastopcode = 0; |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
794 #endif |
|
85157
e7f6cef7a4cc
Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85046
diff
changeset
|
795 PyObject **stack_pointer; /* Next free slot in value stack */ |
|
e7f6cef7a4cc
Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85046
diff
changeset
|
796 unsigned char *next_instr; |
|
e7f6cef7a4cc
Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85046
diff
changeset
|
797 int opcode; /* Current opcode */ |
|
e7f6cef7a4cc
Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85046
diff
changeset
|
798 int oparg; /* Current opcode argument, if any */ |
|
e7f6cef7a4cc
Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85046
diff
changeset
|
799 enum why_code why; /* Reason for block stack unwind */ |
|
e7f6cef7a4cc
Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85046
diff
changeset
|
800 PyObject **fastlocals, **freevars; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
801 PyObject *retval = NULL; /* Return value */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
802 PyThreadState *tstate = PyThreadState_GET(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
803 PyCodeObject *co; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
804 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
805 /* when tracing we set things up so that |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
806 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
807 not (instr_lb <= current_bytecode_offset < instr_ub) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
808 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
809 is true when the line being executed has changed. The |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
810 initial values are such as to make this false the first |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
811 time it is tested. */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
812 int instr_ub = -1, instr_lb = 0, instr_prev = -1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
813 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
814 unsigned char *first_instr; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
815 PyObject *names; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
816 PyObject *consts; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
817 |
|
76072
bac033e488b4
Guard an LLTRACE variable to silence an unused variable warning.
Brett Cannon <brett@python.org>
parents:
75959
diff
changeset
|
818 #ifdef LLTRACE |
|
75959
c67f3681e032
Issue #14383: Add _PyDict_GetItemId() and _PyDict_SetItemId() functions
Victor Stinner <victor.stinner@gmail.com>
parents:
75852
diff
changeset
|
819 _Py_IDENTIFIER(__ltrace__); |
|
76072
bac033e488b4
Guard an LLTRACE variable to silence an unused variable warning.
Brett Cannon <brett@python.org>
parents:
75959
diff
changeset
|
820 #endif |
|
75959
c67f3681e032
Issue #14383: Add _PyDict_GetItemId() and _PyDict_SetItemId() functions
Victor Stinner <victor.stinner@gmail.com>
parents:
75852
diff
changeset
|
821 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
822 /* Computed GOTOs, or |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
823 the-optimization-commonly-but-improperly-known-as-"threaded code" |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
824 using gcc's labels-as-values extension |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
825 (http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html). |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
826 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
827 The traditional bytecode evaluation loop uses a "switch" statement, which |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
828 decent compilers will optimize as a single indirect branch instruction |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
829 combined with a lookup table of jump addresses. However, since the |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
830 indirect jump instruction is shared by all opcodes, the CPU will have a |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
831 hard time making the right prediction for where to jump next (actually, |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
832 it will be always wrong except in the uncommon case of a sequence of |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
833 several identical opcodes). |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
834 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
835 "Threaded code" in contrast, uses an explicit jump table and an explicit |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
836 indirect jump instruction at the end of each opcode. Since the jump |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
837 instruction is at a different address for each opcode, the CPU will make a |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
838 separate prediction for each of these instructions, which is equivalent to |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
839 predicting the second opcode of each opcode pair. These predictions have |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
840 a much better chance to turn out valid, especially in small bytecode loops. |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
841 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
842 A mispredicted branch on a modern CPU flushes the whole pipeline and |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
843 can cost several CPU cycles (depending on the pipeline depth), |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
844 and potentially many more instructions (depending on the pipeline width). |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
845 A correctly predicted branch, however, is nearly free. |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
846 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
847 At the time of this writing, the "threaded code" version is up to 15-20% |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
848 faster than the normal "switch" version, depending on the compiler and the |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
849 CPU architecture. |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
850 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
851 We disable the optimization if DYNAMIC_EXECUTION_PROFILE is defined, |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
852 because it would render the measurements invalid. |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
853 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
854 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
855 NOTE: care must be taken that the compiler doesn't try to "optimize" the |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
856 indirect jumps by sharing them between all opcodes. Such optimizations |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
857 can be disabled on gcc by using the -fno-gcse flag (or possibly |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
858 -fno-crossjumping). |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
859 */ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
860 |
|
63959
e54baebbd6ff
Issue #9203: Computed gotos are now enabled by default on supported
Antoine Pitrou <solipsis@pitrou.net>
parents:
63114
diff
changeset
|
861 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
862 #undef USE_COMPUTED_GOTOS |
|
63959
e54baebbd6ff
Issue #9203: Computed gotos are now enabled by default on supported
Antoine Pitrou <solipsis@pitrou.net>
parents:
63114
diff
changeset
|
863 #define USE_COMPUTED_GOTOS 0 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
864 #endif |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
865 |
|
63959
e54baebbd6ff
Issue #9203: Computed gotos are now enabled by default on supported
Antoine Pitrou <solipsis@pitrou.net>
parents:
63114
diff
changeset
|
866 #ifdef HAVE_COMPUTED_GOTOS |
|
e54baebbd6ff
Issue #9203: Computed gotos are now enabled by default on supported
Antoine Pitrou <solipsis@pitrou.net>
parents:
63114
diff
changeset
|
867 #ifndef USE_COMPUTED_GOTOS |
|
e54baebbd6ff
Issue #9203: Computed gotos are now enabled by default on supported
Antoine Pitrou <solipsis@pitrou.net>
parents:
63114
diff
changeset
|
868 #define USE_COMPUTED_GOTOS 1 |
|
e54baebbd6ff
Issue #9203: Computed gotos are now enabled by default on supported
Antoine Pitrou <solipsis@pitrou.net>
parents:
63114
diff
changeset
|
869 #endif |
|
e54baebbd6ff
Issue #9203: Computed gotos are now enabled by default on supported
Antoine Pitrou <solipsis@pitrou.net>
parents:
63114
diff
changeset
|
870 #else |
|
e54baebbd6ff
Issue #9203: Computed gotos are now enabled by default on supported
Antoine Pitrou <solipsis@pitrou.net>
parents:
63114
diff
changeset
|
871 #if defined(USE_COMPUTED_GOTOS) && USE_COMPUTED_GOTOS |
|
e54baebbd6ff
Issue #9203: Computed gotos are now enabled by default on supported
Antoine Pitrou <solipsis@pitrou.net>
parents:
63114
diff
changeset
|
872 #error "Computed gotos are not supported on this compiler." |
|
e54baebbd6ff
Issue #9203: Computed gotos are now enabled by default on supported
Antoine Pitrou <solipsis@pitrou.net>
parents:
63114
diff
changeset
|
873 #endif |
|
e54baebbd6ff
Issue #9203: Computed gotos are now enabled by default on supported
Antoine Pitrou <solipsis@pitrou.net>
parents:
63114
diff
changeset
|
874 #undef USE_COMPUTED_GOTOS |
|
e54baebbd6ff
Issue #9203: Computed gotos are now enabled by default on supported
Antoine Pitrou <solipsis@pitrou.net>
parents:
63114
diff
changeset
|
875 #define USE_COMPUTED_GOTOS 0 |
|
e54baebbd6ff
Issue #9203: Computed gotos are now enabled by default on supported
Antoine Pitrou <solipsis@pitrou.net>
parents:
63114
diff
changeset
|
876 #endif |
|
e54baebbd6ff
Issue #9203: Computed gotos are now enabled by default on supported
Antoine Pitrou <solipsis@pitrou.net>
parents:
63114
diff
changeset
|
877 |
|
e54baebbd6ff
Issue #9203: Computed gotos are now enabled by default on supported
Antoine Pitrou <solipsis@pitrou.net>
parents:
63114
diff
changeset
|
878 #if USE_COMPUTED_GOTOS |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
879 /* Import the static jump table */ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
880 #include "opcode_targets.h" |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
881 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
882 /* This macro is used when several opcodes defer to the same implementation |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
883 (e.g. SETUP_LOOP, SETUP_FINALLY) */ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
884 #define TARGET_WITH_IMPL(op, impl) \ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
885 TARGET_##op: \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
886 opcode = op; \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
887 if (HAS_ARG(op)) \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
888 oparg = NEXTARG(); \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
889 case op: \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
890 goto impl; \ |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
891 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
892 #define TARGET(op) \ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
893 TARGET_##op: \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
894 opcode = op; \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
895 if (HAS_ARG(op)) \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
896 oparg = NEXTARG(); \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
897 case op: |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
898 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
899 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
900 #define DISPATCH() \ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
901 { \ |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
902 if (!_Py_atomic_load_relaxed(&eval_breaker)) { \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
903 FAST_DISPATCH(); \ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
904 } \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
905 continue; \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
906 } |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
907 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
908 #ifdef LLTRACE |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
909 #define FAST_DISPATCH() \ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
910 { \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
911 if (!lltrace && !_Py_TracingPossible) { \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
912 f->f_lasti = INSTR_OFFSET(); \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
913 goto *opcode_targets[*next_instr++]; \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
914 } \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
915 goto fast_next_opcode; \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
916 } |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
917 #else |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
918 #define FAST_DISPATCH() \ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
919 { \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
920 if (!_Py_TracingPossible) { \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
921 f->f_lasti = INSTR_OFFSET(); \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
922 goto *opcode_targets[*next_instr++]; \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
923 } \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
924 goto fast_next_opcode; \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
925 } |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
926 #endif |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
927 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
928 #else |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
929 #define TARGET(op) \ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
930 case op: |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
931 #define TARGET_WITH_IMPL(op, impl) \ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
932 /* silence compiler warnings about `impl` unused */ \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
933 if (0) goto impl; \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
934 case op: |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
935 #define DISPATCH() continue |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
936 #define FAST_DISPATCH() goto fast_next_opcode |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
937 #endif |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
938 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
939 |
|
24232
e06b1ab0bdb8
SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents:
24190
diff
changeset
|
940 /* Tuple access macros */ |
|
e06b1ab0bdb8
SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents:
24190
diff
changeset
|
941 |
|
e06b1ab0bdb8
SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents:
24190
diff
changeset
|
942 #ifndef Py_DEBUG |
|
e06b1ab0bdb8
SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents:
24190
diff
changeset
|
943 #define GETITEM(v, i) PyTuple_GET_ITEM((PyTupleObject *)(v), (i)) |
|
e06b1ab0bdb8
SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents:
24190
diff
changeset
|
944 #else |
|
e06b1ab0bdb8
SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents:
24190
diff
changeset
|
945 #define GETITEM(v, i) PyTuple_GetItem((v), (i)) |
|
e06b1ab0bdb8
SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents:
24190
diff
changeset
|
946 #endif |
|
e06b1ab0bdb8
SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents:
24190
diff
changeset
|
947 |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
948 #ifdef WITH_TSC |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
949 /* Use Pentium timestamp counter to mark certain events: |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
950 inst0 -- beginning of switch statement for opcode dispatch |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
951 inst1 -- end of switch statement (may be skipped) |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
952 loop0 -- the top of the mainloop |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
953 loop1 -- place where control returns again to top of mainloop |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
954 (may be skipped) |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
955 intr1 -- beginning of long interruption |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
956 intr2 -- end of long interruption |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
957 |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
958 Many opcodes call out to helper C functions. In some cases, the |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
959 time in those functions should be counted towards the time for the |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
960 opcode, but not in all cases. For example, a CALL_FUNCTION opcode |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
961 calls another Python function; there's no point in charge all the |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
962 bytecode executed by the called function to the caller. |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
963 |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
964 It's hard to make a useful judgement statically. In the presence |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
965 of operator overloading, it's impossible to tell if a call will |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
966 execute new Python code or not. |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
967 |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
968 It's a case-by-case judgement. I'll use intr1 for the following |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
969 cases: |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
970 |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
971 IMPORT_STAR |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
972 IMPORT_FROM |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
973 CALL_FUNCTION (and friends) |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
974 |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
975 */ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
976 uint64 inst0, inst1, loop0, loop1, intr0 = 0, intr1 = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
977 int ticked = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
978 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
979 READ_TIMESTAMP(inst0); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
980 READ_TIMESTAMP(inst1); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
981 READ_TIMESTAMP(loop0); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
982 READ_TIMESTAMP(loop1); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
983 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
984 /* shut up the compiler */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
985 opcode = 0; |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
986 #endif |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
987 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
988 /* Code access macros */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
989 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
990 #define INSTR_OFFSET() ((int)(next_instr - first_instr)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
991 #define NEXTOP() (*next_instr++) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
992 #define NEXTARG() (next_instr += 2, (next_instr[-1]<<8) + next_instr[-2]) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
993 #define PEEKARG() ((next_instr[2]<<8) + next_instr[1]) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
994 #define JUMPTO(x) (next_instr = first_instr + (x)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
995 #define JUMPBY(x) (next_instr += (x)) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
996 |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
997 /* OpCode prediction macros |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
998 Some opcodes tend to come in pairs thus making it possible to |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
999 predict the second code when the first is run. For example, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1000 COMPARE_OP is often followed by JUMP_IF_FALSE or JUMP_IF_TRUE. And, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1001 those opcodes are often followed by a POP_TOP. |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1002 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1003 Verifying the prediction costs a single high-speed test of a register |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1004 variable against a constant. If the pairing was good, then the |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1005 processor's own internal branch predication has a high likelihood of |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1006 success, resulting in a nearly zero-overhead transition to the |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1007 next opcode. A successful prediction saves a trip through the eval-loop |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1008 including its two unpredictable branches, the HAS_ARG test and the |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1009 switch-case. Combined with the processor's internal branch prediction, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1010 a successful PREDICT has the effect of making the two opcodes run as if |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1011 they were a single new opcode with the bodies combined. |
|
48494
aca5b2e6a66f
Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47729
diff
changeset
|
1012 |
|
aca5b2e6a66f
Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47729
diff
changeset
|
1013 If collecting opcode statistics, your choices are to either keep the |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1014 predictions turned-on and interpret the results as if some opcodes |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1015 had been combined or turn-off predictions so that the opcode frequency |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1016 counter updates for both opcodes. |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1017 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1018 Opcode prediction is disabled with threaded code, since the latter allows |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1019 the CPU to record separate branch prediction information for each |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1020 opcode. |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1021 |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
1022 */ |
|
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
1023 |
|
63959
e54baebbd6ff
Issue #9203: Computed gotos are now enabled by default on supported
Antoine Pitrou <solipsis@pitrou.net>
parents:
63114
diff
changeset
|
1024 #if defined(DYNAMIC_EXECUTION_PROFILE) || USE_COMPUTED_GOTOS |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1025 #define PREDICT(op) if (0) goto PRED_##op |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1026 #define PREDICTED(op) PRED_##op: |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1027 #define PREDICTED_WITH_ARG(op) PRED_##op: |
|
31487
f57f5ce22c8d
SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents:
31462
diff
changeset
|
1028 #else |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1029 #define PREDICT(op) if (*next_instr == op) goto PRED_##op |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1030 #define PREDICTED(op) PRED_##op: next_instr++ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1031 #define PREDICTED_WITH_ARG(op) PRED_##op: oparg = PEEKARG(); next_instr += 3 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1032 #endif |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1033 |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
1034 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1035 /* Stack manipulation macros */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1036 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36475
diff
changeset
|
1037 /* The stack can grow at most MAXINT deep, as co_nlocals and |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36475
diff
changeset
|
1038 co_stacksize are ints. */ |
|
62462
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1039 #define STACK_LEVEL() ((int)(stack_pointer - f->f_valuestack)) |
|
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1040 #define EMPTY() (STACK_LEVEL() == 0) |
|
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1041 #define TOP() (stack_pointer[-1]) |
|
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1042 #define SECOND() (stack_pointer[-2]) |
|
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1043 #define THIRD() (stack_pointer[-3]) |
|
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1044 #define FOURTH() (stack_pointer[-4]) |
|
62461
c8d5d1205fe8
Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents:
61993
diff
changeset
|
1045 #define PEEK(n) (stack_pointer[-(n)]) |
|
62462
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1046 #define SET_TOP(v) (stack_pointer[-1] = (v)) |
|
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1047 #define SET_SECOND(v) (stack_pointer[-2] = (v)) |
|
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1048 #define SET_THIRD(v) (stack_pointer[-3] = (v)) |
|
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1049 #define SET_FOURTH(v) (stack_pointer[-4] = (v)) |
|
62461
c8d5d1205fe8
Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents:
61993
diff
changeset
|
1050 #define SET_VALUE(n, v) (stack_pointer[-(n)] = (v)) |
|
62462
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1051 #define BASIC_STACKADJ(n) (stack_pointer += n) |
|
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1052 #define BASIC_PUSH(v) (*stack_pointer++ = (v)) |
|
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1053 #define BASIC_POP() (*--stack_pointer) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1054 |
| 567 | 1055 #ifdef LLTRACE |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1056 #define PUSH(v) { (void)(BASIC_PUSH(v), \ |
|
62462
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1057 lltrace && prtrace(TOP(), "push")); \ |
|
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1058 assert(STACK_LEVEL() <= co->co_stacksize); } |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1059 #define POP() ((void)(lltrace && prtrace(TOP(), "pop")), \ |
|
62462
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1060 BASIC_POP()) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1061 #define STACKADJ(n) { (void)(BASIC_STACKADJ(n), \ |
|
62462
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1062 lltrace && prtrace(TOP(), "stackadj")); \ |
|
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1063 assert(STACK_LEVEL() <= co->co_stacksize); } |
|
44310
e70acbf26cda
Merged revisions 59488-59511 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44187
diff
changeset
|
1064 #define EXT_POP(STACK_POINTER) ((void)(lltrace && \ |
|
62462
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1065 prtrace((STACK_POINTER)[-1], "ext_pop")), \ |
|
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1066 *--(STACK_POINTER)) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1067 #else |
|
62462
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1068 #define PUSH(v) BASIC_PUSH(v) |
|
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1069 #define POP() BASIC_POP() |
|
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1070 #define STACKADJ(n) BASIC_STACKADJ(n) |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
1071 #define EXT_POP(STACK_POINTER) (*--(STACK_POINTER)) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1072 #endif |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1073 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1074 /* Local variable macros */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1075 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1076 #define GETLOCAL(i) (fastlocals[i]) |
|
22621
830c829a7eb2
Fix an issue that was reported in but unrelated to the main problem of
Guido van Rossum <guido@python.org>
parents:
22499
diff
changeset
|
1077 |
|
830c829a7eb2
Fix an issue that was reported in but unrelated to the main problem of
Guido van Rossum <guido@python.org>
parents:
22499
diff
changeset
|
1078 /* The SETLOCAL() macro must not DECREF the local variable in-place and |
|
830c829a7eb2
Fix an issue that was reported in but unrelated to the main problem of
Guido van Rossum <guido@python.org>
parents:
22499
diff
changeset
|
1079 then store the new value; it must copy the old value to a temporary |
|
830c829a7eb2
Fix an issue that was reported in but unrelated to the main problem of
Guido van Rossum <guido@python.org>
parents:
22499
diff
changeset
|
1080 value, then store the new value, and then DECREF the temporary value. |
|
830c829a7eb2
Fix an issue that was reported in but unrelated to the main problem of
Guido van Rossum <guido@python.org>
parents:
22499
diff
changeset
|
1081 This is because it is possible that during the DECREF the frame is |
|
830c829a7eb2
Fix an issue that was reported in but unrelated to the main problem of
Guido van Rossum <guido@python.org>
parents:
22499
diff
changeset
|
1082 accessed by other code (e.g. a __del__ method or gc.collect()) and the |
|
830c829a7eb2
Fix an issue that was reported in but unrelated to the main problem of
Guido van Rossum <guido@python.org>
parents:
22499
diff
changeset
|
1083 variable would be pointing to already-freed memory. */ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1084 #define SETLOCAL(i, value) do { PyObject *tmp = GETLOCAL(i); \ |
|
62462
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1085 GETLOCAL(i) = value; \ |
|
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1086 Py_XDECREF(tmp); } while (0) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1087 |
|
47594
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1088 |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1089 #define UNWIND_BLOCK(b) \ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1090 while (STACK_LEVEL() > (b)->b_level) { \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1091 PyObject *v = POP(); \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1092 Py_XDECREF(v); \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1093 } |
|
47594
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1094 |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1095 #define UNWIND_EXCEPT_HANDLER(b) \ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1096 { \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1097 PyObject *type, *value, *traceback; \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1098 assert(STACK_LEVEL() >= (b)->b_level + 3); \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1099 while (STACK_LEVEL() > (b)->b_level + 3) { \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1100 value = POP(); \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1101 Py_XDECREF(value); \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1102 } \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1103 type = tstate->exc_type; \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1104 value = tstate->exc_value; \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1105 traceback = tstate->exc_traceback; \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1106 tstate->exc_type = POP(); \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1107 tstate->exc_value = POP(); \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1108 tstate->exc_traceback = POP(); \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1109 Py_XDECREF(type); \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1110 Py_XDECREF(value); \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1111 Py_XDECREF(traceback); \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1112 } |
|
47594
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1113 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1114 /* Start of code */ |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1115 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1116 /* push frame */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1117 if (Py_EnterRecursiveCall("")) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1118 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1119 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1120 tstate->frame = f; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1121 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1122 if (tstate->use_tracing) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1123 if (tstate->c_tracefunc != NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1124 /* tstate->c_tracefunc, if defined, is a |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1125 function that will be called on *every* entry |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1126 to a code block. Its return value, if not |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1127 None, is a function that will be called at |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1128 the start of each executed line of code. |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1129 (Actually, the function must return itself |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1130 in order to continue tracing.) The trace |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1131 functions are called with three arguments: |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1132 a pointer to the current frame, a string |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1133 indicating why the function is called, and |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1134 an argument which depends on the situation. |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1135 The global trace function is also called |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1136 whenever an exception is detected. */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1137 if (call_trace_protected(tstate->c_tracefunc, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1138 tstate->c_traceobj, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1139 f, PyTrace_CALL, Py_None)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1140 /* Trace function raised an error */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1141 goto exit_eval_frame; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1142 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1143 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1144 if (tstate->c_profilefunc != NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1145 /* Similar for c_profilefunc, except it needn't |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1146 return itself and isn't called for "line" events */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1147 if (call_trace_protected(tstate->c_profilefunc, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1148 tstate->c_profileobj, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1149 f, PyTrace_CALL, Py_None)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1150 /* Profile function raised an error */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1151 goto exit_eval_frame; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1152 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1153 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1154 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1155 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1156 co = f->f_code; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1157 names = co->co_names; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1158 consts = co->co_consts; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1159 fastlocals = f->f_localsplus; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1160 freevars = f->f_localsplus + co->co_nlocals; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1161 first_instr = (unsigned char*) PyBytes_AS_STRING(co->co_code); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1162 /* An explanation is in order for the next line. |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1163 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1164 f->f_lasti now refers to the index of the last instruction |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1165 executed. You might think this was obvious from the name, but |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1166 this wasn't always true before 2.3! PyFrame_New now sets |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1167 f->f_lasti to -1 (i.e. the index *before* the first instruction) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1168 and YIELD_VALUE doesn't fiddle with f_lasti any more. So this |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1169 does work. Promise. |
|
75714
72556ff86828
perform yield from delegation by repeating YIELD_FROM opcode (closes #14230)
Benjamin Peterson <benjamin@python.org>
parents:
75292
diff
changeset
|
1170 YIELD_FROM sets f_lasti to itself, in order to repeated yield |
|
72556ff86828
perform yield from delegation by repeating YIELD_FROM opcode (closes #14230)
Benjamin Peterson <benjamin@python.org>
parents:
75292
diff
changeset
|
1171 multiple values. |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1172 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1173 When the PREDICT() macros are enabled, some opcode pairs follow in |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1174 direct succession without updating f->f_lasti. A successful |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1175 prediction effectively links the two codes together as if they |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1176 were a single new opcode; accordingly,f->f_lasti will point to |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1177 the first code in the pair (for instance, GET_ITER followed by |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1178 FOR_ITER is effectively a single opcode and f->f_lasti will point |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1179 at to the beginning of the combined pair.) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1180 */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1181 next_instr = first_instr + f->f_lasti + 1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1182 stack_pointer = f->f_stacktop; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1183 assert(stack_pointer != NULL); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1184 f->f_stacktop = NULL; /* remains NULL unless yield suspends frame */ |
|
85046
862ab99ab570
Issue #17934: Add a clear() method to frame objects, to help clean up expensive details (local variables) and break reference cycles.
Antoine Pitrou <solipsis@pitrou.net>
parents:
84727
diff
changeset
|
1185 f->f_executing = 1; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1186 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1187 if (co->co_flags & CO_GENERATOR && !throwflag) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1188 if (f->f_exc_type != NULL && f->f_exc_type != Py_None) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1189 /* We were in an except handler when we left, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1190 restore the exception state which was put aside |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1191 (see YIELD_VALUE). */ |
|
71159
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
1192 swap_exc_state(tstate, f); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1193 } |
|
71159
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
1194 else |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
1195 save_exc_state(tstate, f); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1196 } |
|
47594
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1197 |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
1198 #ifdef LLTRACE |
|
75959
c67f3681e032
Issue #14383: Add _PyDict_GetItemId() and _PyDict_SetItemId() functions
Victor Stinner <victor.stinner@gmail.com>
parents:
75852
diff
changeset
|
1199 lltrace = _PyDict_GetItemId(f->f_globals, &PyId___ltrace__) != NULL; |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
1200 #endif |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1201 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1202 why = WHY_NOT; |
| 79693 | 1203 |
| 1204 if (throwflag) /* support for generator.throw() */ | |
| 1205 goto error; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1206 |
|
84704
48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
Victor Stinner <victor.stinner@gmail.com>
parents:
84648
diff
changeset
|
1207 #ifdef Py_DEBUG |
|
48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
Victor Stinner <victor.stinner@gmail.com>
parents:
84648
diff
changeset
|
1208 /* PyEval_EvalFrameEx() must not be called with an exception set, |
|
48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
Victor Stinner <victor.stinner@gmail.com>
parents:
84648
diff
changeset
|
1209 because it may clear it (directly or indirectly) and so the |
|
48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
Victor Stinner <victor.stinner@gmail.com>
parents:
84648
diff
changeset
|
1210 caller looses its exception */ |
|
48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
Victor Stinner <victor.stinner@gmail.com>
parents:
84648
diff
changeset
|
1211 assert(!PyErr_Occurred()); |
|
48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
Victor Stinner <victor.stinner@gmail.com>
parents:
84648
diff
changeset
|
1212 #endif |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1213 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1214 for (;;) { |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
1215 #ifdef WITH_TSC |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1216 if (inst1 == 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1217 /* Almost surely, the opcode executed a break |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1218 or a continue, preventing inst1 from being set |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1219 on the way out of the loop. |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1220 */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1221 READ_TIMESTAMP(inst1); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1222 loop1 = inst1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1223 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1224 dump_tsc(opcode, ticked, inst0, inst1, loop0, loop1, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1225 intr0, intr1); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1226 ticked = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1227 inst1 = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1228 intr0 = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1229 intr1 = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1230 READ_TIMESTAMP(loop0); |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
1231 #endif |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1232 assert(stack_pointer >= f->f_valuestack); /* else underflow */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1233 assert(STACK_LEVEL() <= co->co_stacksize); /* else overflow */ |
|
84704
48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
Victor Stinner <victor.stinner@gmail.com>
parents:
84648
diff
changeset
|
1234 assert(!PyErr_Occurred()); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1235 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1236 /* Do periodic things. Doing this every time through |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1237 the loop would add too much overhead, so we do it |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1238 only every Nth instruction. We also do it if |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1239 ``pendingcalls_to_do'' is set, i.e. when an asynchronous |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1240 event needs attention (e.g. a signal handler or |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1241 async I/O handler); see Py_AddPendingCall() and |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1242 Py_MakePendingCalls() above. */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1243 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
1244 if (_Py_atomic_load_relaxed(&eval_breaker)) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1245 if (*next_instr == SETUP_FINALLY) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1246 /* Make the last opcode before |
|
68585
bf94b6a73fc8
#11565: Fix several typos. Patch by Piotr Kasprzyk.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
67414
diff
changeset
|
1247 a try: finally: block uninterruptible. */ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1248 goto fast_next_opcode; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1249 } |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
1250 #ifdef WITH_TSC |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1251 ticked = 1; |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
1252 #endif |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
1253 if (_Py_atomic_load_relaxed(&pendingcalls_to_do)) { |
| 79693 | 1254 if (Py_MakePendingCalls() < 0) |
| 1255 goto error; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1256 } |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
1257 #ifdef WITH_THREAD |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
1258 if (_Py_atomic_load_relaxed(&gil_drop_request)) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1259 /* Give another thread a chance */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1260 if (PyThreadState_Swap(NULL) != tstate) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1261 Py_FatalError("ceval: tstate mix-up"); |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
1262 drop_gil(tstate); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1263 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1264 /* Other threads may run now */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1265 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
1266 take_gil(tstate); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1267 if (PyThreadState_Swap(tstate) != NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1268 Py_FatalError("ceval: orphan tstate"); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1269 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
1270 #endif |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
1271 /* Check for asynchronous exceptions. */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
1272 if (tstate->async_exc != NULL) { |
| 79693 | 1273 PyObject *exc = tstate->async_exc; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
1274 tstate->async_exc = NULL; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
1275 UNSIGNAL_ASYNC_EXC(); |
| 79693 | 1276 PyErr_SetNone(exc); |
| 1277 Py_DECREF(exc); | |
| 1278 goto error; | |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
1279 } |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1280 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1281 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1282 fast_next_opcode: |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1283 f->f_lasti = INSTR_OFFSET(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1284 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1285 /* line-by-line tracing support */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1286 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1287 if (_Py_TracingPossible && |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1288 tstate->c_tracefunc != NULL && !tstate->tracing) { |
| 79693 | 1289 int err; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1290 /* see maybe_call_line_trace |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1291 for expository comments */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1292 f->f_stacktop = stack_pointer; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1293 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1294 err = maybe_call_line_trace(tstate->c_tracefunc, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1295 tstate->c_traceobj, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1296 f, &instr_lb, &instr_ub, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1297 &instr_prev); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1298 /* Reload possibly changed frame fields */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1299 JUMPTO(f->f_lasti); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1300 if (f->f_stacktop != NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1301 stack_pointer = f->f_stacktop; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1302 f->f_stacktop = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1303 } |
| 79693 | 1304 if (err) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1305 /* trace function raised an exception */ |
| 79693 | 1306 goto error; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1307 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1308 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1309 /* Extract opcode and argument */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1310 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1311 opcode = NEXTOP(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1312 oparg = 0; /* allows oparg to be stored in a register because |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1313 it doesn't have to be remembered across a full loop */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1314 if (HAS_ARG(opcode)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1315 oparg = NEXTARG(); |
|
62462
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
1316 dispatch_opcode: |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
1317 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
1318 #ifdef DXPAIRS |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1319 dxpairs[lastopcode][opcode]++; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1320 lastopcode = opcode; |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
1321 #endif |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1322 dxp[opcode]++; |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
1323 #endif |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1324 |
| 567 | 1325 #ifdef LLTRACE |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1326 /* Instruction tracing */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1327 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1328 if (lltrace) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1329 if (HAS_ARG(opcode)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1330 printf("%d: %d, %d\n", |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1331 f->f_lasti, opcode, oparg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1332 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1333 else { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1334 printf("%d: %d\n", |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1335 f->f_lasti, opcode); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1336 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1337 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1338 #endif |
| 24844 | 1339 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1340 /* Main switch on opcode */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1341 READ_TIMESTAMP(inst0); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1342 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1343 switch (opcode) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1344 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1345 /* BEWARE! |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1346 It is essential that any operation that fails sets either |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1347 x to NULL, err to nonzero, or why to anything but WHY_NOT, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1348 and that no operation that succeeds does this! */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1349 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1350 TARGET(NOP) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1351 FAST_DISPATCH(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1352 |
| 79693 | 1353 TARGET(LOAD_FAST) { |
| 1354 PyObject *value = GETLOCAL(oparg); | |
| 1355 if (value == NULL) { | |
| 1356 format_exc_check_arg(PyExc_UnboundLocalError, | |
| 1357 UNBOUNDLOCAL_ERROR_MSG, | |
| 1358 PyTuple_GetItem(co->co_varnames, oparg)); | |
| 1359 goto error; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1360 } |
| 79693 | 1361 Py_INCREF(value); |
| 1362 PUSH(value); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1363 FAST_DISPATCH(); |
| 79693 | 1364 } |
| 1365 | |
| 1366 TARGET(LOAD_CONST) { | |
| 1367 PyObject *value = GETITEM(consts, oparg); | |
| 1368 Py_INCREF(value); | |
| 1369 PUSH(value); | |
| 1370 FAST_DISPATCH(); | |
| 1371 } | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1372 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1373 PREDICTED_WITH_ARG(STORE_FAST); |
| 79693 | 1374 TARGET(STORE_FAST) { |
| 1375 PyObject *value = POP(); | |
| 1376 SETLOCAL(oparg, value); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1377 FAST_DISPATCH(); |
| 79693 | 1378 } |
| 1379 | |
| 1380 TARGET(POP_TOP) { | |
| 1381 PyObject *value = POP(); | |
| 1382 Py_DECREF(value); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1383 FAST_DISPATCH(); |
| 79693 | 1384 } |
| 1385 | |
| 1386 TARGET(ROT_TWO) { | |
| 1387 PyObject *top = TOP(); | |
| 1388 PyObject *second = SECOND(); | |
| 1389 SET_TOP(second); | |
| 1390 SET_SECOND(top); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1391 FAST_DISPATCH(); |
| 79693 | 1392 } |
| 1393 | |
| 1394 TARGET(ROT_THREE) { | |
| 1395 PyObject *top = TOP(); | |
| 1396 PyObject *second = SECOND(); | |
| 1397 PyObject *third = THIRD(); | |
| 1398 SET_TOP(second); | |
| 1399 SET_SECOND(third); | |
| 1400 SET_THIRD(top); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1401 FAST_DISPATCH(); |
| 79693 | 1402 } |
| 1403 | |
| 1404 TARGET(DUP_TOP) { | |
| 1405 PyObject *top = TOP(); | |
| 1406 Py_INCREF(top); | |
| 1407 PUSH(top); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1408 FAST_DISPATCH(); |
| 79693 | 1409 } |
| 1410 | |
| 1411 TARGET(DUP_TOP_TWO) { | |
| 1412 PyObject *top = TOP(); | |
|
79694
6ca52f901fc1
move declaration to top of block
Benjamin Peterson <benjamin@python.org>
parents:
79693
diff
changeset
|
1413 PyObject *second = SECOND(); |
| 79693 | 1414 Py_INCREF(top); |
| 1415 Py_INCREF(second); | |
|
64439
725231211273
Issue #9225: Remove the ROT_FOUR and DUP_TOPX opcode, the latter replaced
Antoine Pitrou <solipsis@pitrou.net>
parents:
64092
diff
changeset
|
1416 STACKADJ(2); |
| 79693 | 1417 SET_TOP(top); |
| 1418 SET_SECOND(second); | |
|
64439
725231211273
Issue #9225: Remove the ROT_FOUR and DUP_TOPX opcode, the latter replaced
Antoine Pitrou <solipsis@pitrou.net>
parents:
64092
diff
changeset
|
1419 FAST_DISPATCH(); |
| 79693 | 1420 } |
| 1421 | |
| 1422 TARGET(UNARY_POSITIVE) { | |
| 1423 PyObject *value = TOP(); | |
| 1424 PyObject *res = PyNumber_Positive(value); | |
| 1425 Py_DECREF(value); | |
| 1426 SET_TOP(res); | |
| 1427 if (res == NULL) | |
| 1428 goto error; | |
| 1429 DISPATCH(); | |
| 1430 } | |
| 1431 | |
| 1432 TARGET(UNARY_NEGATIVE) { | |
| 1433 PyObject *value = TOP(); | |
| 1434 PyObject *res = PyNumber_Negative(value); | |
| 1435 Py_DECREF(value); | |
| 1436 SET_TOP(res); | |
| 1437 if (res == NULL) | |
| 1438 goto error; | |
| 1439 DISPATCH(); | |
| 1440 } | |
| 1441 | |
| 1442 TARGET(UNARY_NOT) { | |
| 1443 PyObject *value = TOP(); | |
| 1444 int err = PyObject_IsTrue(value); | |
| 1445 Py_DECREF(value); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1446 if (err == 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1447 Py_INCREF(Py_True); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1448 SET_TOP(Py_True); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1449 DISPATCH(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1450 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1451 else if (err > 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1452 Py_INCREF(Py_False); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1453 SET_TOP(Py_False); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1454 err = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1455 DISPATCH(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1456 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1457 STACKADJ(-1); |
| 79693 | 1458 goto error; |
| 1459 } | |
| 1460 | |
| 1461 TARGET(UNARY_INVERT) { | |
| 1462 PyObject *value = TOP(); | |
| 1463 PyObject *res = PyNumber_Invert(value); | |
| 1464 Py_DECREF(value); | |
| 1465 SET_TOP(res); | |
| 1466 if (res == NULL) | |
| 1467 goto error; | |
| 1468 DISPATCH(); | |
| 1469 } | |
| 1470 | |
| 1471 TARGET(BINARY_POWER) { | |
| 1472 PyObject *exp = POP(); | |
| 1473 PyObject *base = TOP(); | |
| 1474 PyObject *res = PyNumber_Power(base, exp, Py_None); | |
| 1475 Py_DECREF(base); | |
| 1476 Py_DECREF(exp); | |
| 1477 SET_TOP(res); | |
| 1478 if (res == NULL) | |
| 1479 goto error; | |
| 1480 DISPATCH(); | |
| 1481 } | |
| 1482 | |
| 1483 TARGET(BINARY_MULTIPLY) { | |
| 1484 PyObject *right = POP(); | |
| 1485 PyObject *left = TOP(); | |
| 1486 PyObject *res = PyNumber_Multiply(left, right); | |
| 1487 Py_DECREF(left); | |
| 1488 Py_DECREF(right); | |
| 1489 SET_TOP(res); | |
| 1490 if (res == NULL) | |
| 1491 goto error; | |
| 1492 DISPATCH(); | |
| 1493 } | |
| 1494 | |
| 1495 TARGET(BINARY_TRUE_DIVIDE) { | |
| 1496 PyObject *divisor = POP(); | |
| 1497 PyObject *dividend = TOP(); | |
| 1498 PyObject *quotient = PyNumber_TrueDivide(dividend, divisor); | |
| 1499 Py_DECREF(dividend); | |
| 1500 Py_DECREF(divisor); | |
| 1501 SET_TOP(quotient); | |
| 1502 if (quotient == NULL) | |
| 1503 goto error; | |
| 1504 DISPATCH(); | |
| 1505 } | |
| 1506 | |
| 1507 TARGET(BINARY_FLOOR_DIVIDE) { | |
| 1508 PyObject *divisor = POP(); | |
| 1509 PyObject *dividend = TOP(); | |
| 1510 PyObject *quotient = PyNumber_FloorDivide(dividend, divisor); | |
| 1511 Py_DECREF(dividend); | |
| 1512 Py_DECREF(divisor); | |
| 1513 SET_TOP(quotient); | |
| 1514 if (quotient == NULL) | |
| 1515 goto error; | |
| 1516 DISPATCH(); | |
| 1517 } | |
| 1518 | |
| 1519 TARGET(BINARY_MODULO) { | |
| 1520 PyObject *divisor = POP(); | |
| 1521 PyObject *dividend = TOP(); | |
| 1522 PyObject *res = PyUnicode_CheckExact(dividend) ? | |
| 1523 PyUnicode_Format(dividend, divisor) : | |
| 1524 PyNumber_Remainder(dividend, divisor); | |
| 1525 Py_DECREF(divisor); | |
| 1526 Py_DECREF(dividend); | |
| 1527 SET_TOP(res); | |
| 1528 if (res == NULL) | |
| 1529 goto error; | |
| 1530 DISPATCH(); | |
| 1531 } | |
| 1532 | |
| 1533 TARGET(BINARY_ADD) { | |
| 1534 PyObject *right = POP(); | |
| 1535 PyObject *left = TOP(); | |
| 1536 PyObject *sum; | |
| 1537 if (PyUnicode_CheckExact(left) && | |
| 1538 PyUnicode_CheckExact(right)) { | |
| 1539 sum = unicode_concatenate(left, right, f, next_instr); | |
|
72605
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
1540 /* unicode_concatenate consumed the ref to v */ |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
1541 } |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
1542 else { |
| 79693 | 1543 sum = PyNumber_Add(left, right); |
| 1544 Py_DECREF(left); | |
|
72605
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
1545 } |
| 79693 | 1546 Py_DECREF(right); |
| 1547 SET_TOP(sum); | |
| 1548 if (sum == NULL) | |
| 1549 goto error; | |
| 1550 DISPATCH(); | |
| 1551 } | |
| 1552 | |
| 1553 TARGET(BINARY_SUBTRACT) { | |
| 1554 PyObject *right = POP(); | |
| 1555 PyObject *left = TOP(); | |
| 1556 PyObject *diff = PyNumber_Subtract(left, right); | |
| 1557 Py_DECREF(right); | |
| 1558 Py_DECREF(left); | |
| 1559 SET_TOP(diff); | |
| 1560 if (diff == NULL) | |
| 1561 goto error; | |
| 1562 DISPATCH(); | |
| 1563 } | |
| 1564 | |
| 1565 TARGET(BINARY_SUBSCR) { | |
| 1566 PyObject *sub = POP(); | |
| 1567 PyObject *container = TOP(); | |
| 1568 PyObject *res = PyObject_GetItem(container, sub); | |
| 1569 Py_DECREF(container); | |
| 1570 Py_DECREF(sub); | |
| 1571 SET_TOP(res); | |
| 1572 if (res == NULL) | |
| 1573 goto error; | |
| 1574 DISPATCH(); | |
| 1575 } | |
| 1576 | |
| 1577 TARGET(BINARY_LSHIFT) { | |
| 1578 PyObject *right = POP(); | |
| 1579 PyObject *left = TOP(); | |
| 1580 PyObject *res = PyNumber_Lshift(left, right); | |
| 1581 Py_DECREF(left); | |
| 1582 Py_DECREF(right); | |
| 1583 SET_TOP(res); | |
| 1584 if (res == NULL) | |
| 1585 goto error; | |
| 1586 DISPATCH(); | |
| 1587 } | |
| 1588 | |
| 1589 TARGET(BINARY_RSHIFT) { | |
| 1590 PyObject *right = POP(); | |
| 1591 PyObject *left = TOP(); | |
| 1592 PyObject *res = PyNumber_Rshift(left, right); | |
| 1593 Py_DECREF(left); | |
| 1594 Py_DECREF(right); | |
| 1595 SET_TOP(res); | |
| 1596 if (res == NULL) | |
| 1597 goto error; | |
| 1598 DISPATCH(); | |
| 1599 } | |
| 1600 | |
| 1601 TARGET(BINARY_AND) { | |
| 1602 PyObject *right = POP(); | |
| 1603 PyObject *left = TOP(); | |
| 1604 PyObject *res = PyNumber_And(left, right); | |
| 1605 Py_DECREF(left); | |
| 1606 Py_DECREF(right); | |
| 1607 SET_TOP(res); | |
| 1608 if (res == NULL) | |
| 1609 goto error; | |
| 1610 DISPATCH(); | |
| 1611 } | |
| 1612 | |
| 1613 TARGET(BINARY_XOR) { | |
| 1614 PyObject *right = POP(); | |
| 1615 PyObject *left = TOP(); | |
| 1616 PyObject *res = PyNumber_Xor(left, right); | |
| 1617 Py_DECREF(left); | |
| 1618 Py_DECREF(right); | |
| 1619 SET_TOP(res); | |
| 1620 if (res == NULL) | |
| 1621 goto error; | |
| 1622 DISPATCH(); | |
| 1623 } | |
| 1624 | |
| 1625 TARGET(BINARY_OR) { | |
| 1626 PyObject *right = POP(); | |
| 1627 PyObject *left = TOP(); | |
| 1628 PyObject *res = PyNumber_Or(left, right); | |
| 1629 Py_DECREF(left); | |
| 1630 Py_DECREF(right); | |
| 1631 SET_TOP(res); | |
| 1632 if (res == NULL) | |
| 1633 goto error; | |
| 1634 DISPATCH(); | |
| 1635 } | |
| 1636 | |
| 1637 TARGET(LIST_APPEND) { | |
| 1638 PyObject *v = POP(); | |
| 1639 PyObject *list = PEEK(oparg); | |
| 1640 int err; | |
| 1641 err = PyList_Append(list, v); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1642 Py_DECREF(v); |
| 79693 | 1643 if (err != 0) |
| 1644 goto error; | |
| 1645 PREDICT(JUMP_ABSOLUTE); | |
| 1646 DISPATCH(); | |
| 1647 } | |
| 1648 | |
| 1649 TARGET(SET_ADD) { | |
| 1650 PyObject *v = POP(); | |
| 1651 PyObject *set = stack_pointer[-oparg]; | |
| 1652 int err; | |
| 1653 err = PySet_Add(set, v); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1654 Py_DECREF(v); |
| 79693 | 1655 if (err != 0) |
| 1656 goto error; | |
| 1657 PREDICT(JUMP_ABSOLUTE); | |
| 1658 DISPATCH(); | |
| 1659 } | |
| 1660 | |
| 1661 TARGET(INPLACE_POWER) { | |
| 1662 PyObject *exp = POP(); | |
| 1663 PyObject *base = TOP(); | |
| 1664 PyObject *res = PyNumber_InPlacePower(base, exp, Py_None); | |
| 1665 Py_DECREF(base); | |
| 1666 Py_DECREF(exp); | |
| 1667 SET_TOP(res); | |
| 1668 if (res == NULL) | |
| 1669 goto error; | |
| 1670 DISPATCH(); | |
| 1671 } | |
| 1672 | |
| 1673 TARGET(INPLACE_MULTIPLY) { | |
| 1674 PyObject *right = POP(); | |
| 1675 PyObject *left = TOP(); | |
| 1676 PyObject *res = PyNumber_InPlaceMultiply(left, right); | |
| 1677 Py_DECREF(left); | |
| 1678 Py_DECREF(right); | |
| 1679 SET_TOP(res); | |
| 1680 if (res == NULL) | |
| 1681 goto error; | |
| 1682 DISPATCH(); | |
| 1683 } | |
| 1684 | |
| 1685 TARGET(INPLACE_TRUE_DIVIDE) { | |
| 1686 PyObject *divisor = POP(); | |
| 1687 PyObject *dividend = TOP(); | |
| 1688 PyObject *quotient = PyNumber_InPlaceTrueDivide(dividend, divisor); | |
| 1689 Py_DECREF(dividend); | |
| 1690 Py_DECREF(divisor); | |
| 1691 SET_TOP(quotient); | |
| 1692 if (quotient == NULL) | |
| 1693 goto error; | |
| 1694 DISPATCH(); | |
| 1695 } | |
| 1696 | |
| 1697 TARGET(INPLACE_FLOOR_DIVIDE) { | |
| 1698 PyObject *divisor = POP(); | |
| 1699 PyObject *dividend = TOP(); | |
| 1700 PyObject *quotient = PyNumber_InPlaceFloorDivide(dividend, divisor); | |
| 1701 Py_DECREF(dividend); | |
| 1702 Py_DECREF(divisor); | |
| 1703 SET_TOP(quotient); | |
| 1704 if (quotient == NULL) | |
| 1705 goto error; | |
| 1706 DISPATCH(); | |
| 1707 } | |
| 1708 | |
| 1709 TARGET(INPLACE_MODULO) { | |
| 1710 PyObject *right = POP(); | |
| 1711 PyObject *left = TOP(); | |
| 1712 PyObject *mod = PyNumber_InPlaceRemainder(left, right); | |
| 1713 Py_DECREF(left); | |
| 1714 Py_DECREF(right); | |
| 1715 SET_TOP(mod); | |
| 1716 if (mod == NULL) | |
| 1717 goto error; | |
| 1718 DISPATCH(); | |
| 1719 } | |
| 1720 | |
| 1721 TARGET(INPLACE_ADD) { | |
| 1722 PyObject *right = POP(); | |
| 1723 PyObject *left = TOP(); | |
| 1724 PyObject *sum; | |
| 1725 if (PyUnicode_CheckExact(left) && PyUnicode_CheckExact(right)) { | |
| 1726 sum = unicode_concatenate(left, right, f, next_instr); | |
|
72605
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
1727 /* unicode_concatenate consumed the ref to v */ |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
1728 } |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
1729 else { |
| 79693 | 1730 sum = PyNumber_InPlaceAdd(left, right); |
| 1731 Py_DECREF(left); | |
|
72605
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
1732 } |
| 79693 | 1733 Py_DECREF(right); |
| 1734 SET_TOP(sum); | |
| 1735 if (sum == NULL) | |
| 1736 goto error; | |
| 1737 DISPATCH(); | |
| 1738 } | |
| 1739 | |
| 1740 TARGET(INPLACE_SUBTRACT) { | |
| 1741 PyObject *right = POP(); | |
| 1742 PyObject *left = TOP(); | |
| 1743 PyObject *diff = PyNumber_InPlaceSubtract(left, right); | |
| 1744 Py_DECREF(left); | |
| 1745 Py_DECREF(right); | |
| 1746 SET_TOP(diff); | |
| 1747 if (diff == NULL) | |
| 1748 goto error; | |
| 1749 DISPATCH(); | |
| 1750 } | |
| 1751 | |
| 1752 TARGET(INPLACE_LSHIFT) { | |
| 1753 PyObject *right = POP(); | |
| 1754 PyObject *left = TOP(); | |
| 1755 PyObject *res = PyNumber_InPlaceLshift(left, right); | |
| 1756 Py_DECREF(left); | |
| 1757 Py_DECREF(right); | |
| 1758 SET_TOP(res); | |
| 1759 if (res == NULL) | |
| 1760 goto error; | |
| 1761 DISPATCH(); | |
| 1762 } | |
| 1763 | |
| 1764 TARGET(INPLACE_RSHIFT) { | |
| 1765 PyObject *right = POP(); | |
| 1766 PyObject *left = TOP(); | |
| 1767 PyObject *res = PyNumber_InPlaceRshift(left, right); | |
| 1768 Py_DECREF(left); | |
| 1769 Py_DECREF(right); | |
| 1770 SET_TOP(res); | |
| 1771 if (res == NULL) | |
| 1772 goto error; | |
| 1773 DISPATCH(); | |
| 1774 } | |
| 1775 | |
| 1776 TARGET(INPLACE_AND) { | |
| 1777 PyObject *right = POP(); | |
| 1778 PyObject *left = TOP(); | |
| 1779 PyObject *res = PyNumber_InPlaceAnd(left, right); | |
| 1780 Py_DECREF(left); | |
| 1781 Py_DECREF(right); | |
| 1782 SET_TOP(res); | |
| 1783 if (res == NULL) | |
| 1784 goto error; | |
| 1785 DISPATCH(); | |
| 1786 } | |
| 1787 | |
| 1788 TARGET(INPLACE_XOR) { | |
| 1789 PyObject *right = POP(); | |
| 1790 PyObject *left = TOP(); | |
| 1791 PyObject *res = PyNumber_InPlaceXor(left, right); | |
| 1792 Py_DECREF(left); | |
| 1793 Py_DECREF(right); | |
| 1794 SET_TOP(res); | |
| 1795 if (res == NULL) | |
| 1796 goto error; | |
| 1797 DISPATCH(); | |
| 1798 } | |
| 1799 | |
| 1800 TARGET(INPLACE_OR) { | |
| 1801 PyObject *right = POP(); | |
| 1802 PyObject *left = TOP(); | |
| 1803 PyObject *res = PyNumber_InPlaceOr(left, right); | |
| 1804 Py_DECREF(left); | |
| 1805 Py_DECREF(right); | |
| 1806 SET_TOP(res); | |
| 1807 if (res == NULL) | |
| 1808 goto error; | |
| 1809 DISPATCH(); | |
| 1810 } | |
| 1811 | |
| 1812 TARGET(STORE_SUBSCR) { | |
| 1813 PyObject *sub = TOP(); | |
| 1814 PyObject *container = SECOND(); | |
| 1815 PyObject *v = THIRD(); | |
| 1816 int err; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1817 STACKADJ(-3); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1818 /* v[w] = u */ |
| 79693 | 1819 err = PyObject_SetItem(container, sub, v); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1820 Py_DECREF(v); |
| 79693 | 1821 Py_DECREF(container); |
| 1822 Py_DECREF(sub); | |
| 1823 if (err != 0) | |
| 1824 goto error; | |
| 1825 DISPATCH(); | |
| 1826 } | |
| 1827 | |
| 1828 TARGET(DELETE_SUBSCR) { | |
| 1829 PyObject *sub = TOP(); | |
| 1830 PyObject *container = SECOND(); | |
| 1831 int err; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1832 STACKADJ(-2); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1833 /* del v[w] */ |
| 79693 | 1834 err = PyObject_DelItem(container, sub); |
| 1835 Py_DECREF(container); | |
| 1836 Py_DECREF(sub); | |
| 1837 if (err != 0) | |
| 1838 goto error; | |
| 1839 DISPATCH(); | |
| 1840 } | |
| 1841 | |
| 1842 TARGET(PRINT_EXPR) { | |
|
86972
cca13dd603a9
Issue #19512: PRINT_EXPR bytecode now uses an identifier to get sys.displayhook
Victor Stinner <victor.stinner@gmail.com>
parents:
86773
diff
changeset
|
1843 _Py_IDENTIFIER(displayhook); |
| 79693 | 1844 PyObject *value = POP(); |
|
86972
cca13dd603a9
Issue #19512: PRINT_EXPR bytecode now uses an identifier to get sys.displayhook
Victor Stinner <victor.stinner@gmail.com>
parents:
86773
diff
changeset
|
1845 PyObject *hook = _PySys_GetObjectId(&PyId_displayhook); |
|
79695
fb40d0ab0c77
move more variable declarations to the top of blocks
Benjamin Peterson <benjamin@python.org>
parents:
79694
diff
changeset
|
1846 PyObject *res; |
| 79693 | 1847 if (hook == NULL) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1848 PyErr_SetString(PyExc_RuntimeError, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1849 "lost sys.displayhook"); |
| 79693 | 1850 Py_DECREF(value); |
| 1851 goto error; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1852 } |
|
79695
fb40d0ab0c77
move more variable declarations to the top of blocks
Benjamin Peterson <benjamin@python.org>
parents:
79694
diff
changeset
|
1853 res = PyObject_CallFunctionObjArgs(hook, value, NULL); |
| 79693 | 1854 Py_DECREF(value); |
| 1855 if (res == NULL) | |
| 1856 goto error; | |
| 1857 Py_DECREF(res); | |
| 1858 DISPATCH(); | |
| 1859 } | |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1860 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1861 #ifdef CASE_TOO_BIG |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1862 default: switch (opcode) { |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1863 #endif |
| 79693 | 1864 TARGET(RAISE_VARARGS) { |
| 1865 PyObject *cause = NULL, *exc = NULL; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1866 switch (oparg) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1867 case 2: |
| 79693 | 1868 cause = POP(); /* cause */ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1869 case 1: |
| 79693 | 1870 exc = POP(); /* exc */ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1871 case 0: /* Fallthrough */ |
| 79693 | 1872 if (do_raise(exc, cause)) { |
| 1873 why = WHY_EXCEPTION; | |
| 1874 goto fast_block_end; | |
| 1875 } | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1876 break; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1877 default: |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1878 PyErr_SetString(PyExc_SystemError, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1879 "bad RAISE_VARARGS oparg"); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1880 break; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1881 } |
| 79693 | 1882 goto error; |
| 1883 } | |
| 1884 | |
| 1885 TARGET(RETURN_VALUE) { | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1886 retval = POP(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1887 why = WHY_RETURN; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1888 goto fast_block_end; |
| 79693 | 1889 } |
| 1890 | |
| 1891 TARGET(YIELD_FROM) { | |
| 1892 PyObject *v = POP(); | |
| 1893 PyObject *reciever = TOP(); | |
| 1894 int err; | |
| 1895 if (PyGen_CheckExact(reciever)) { | |
| 1896 retval = _PyGen_Send((PyGenObject *)reciever, v); | |
|
75714
72556ff86828
perform yield from delegation by repeating YIELD_FROM opcode (closes #14230)
Benjamin Peterson <benjamin@python.org>
parents:
75292
diff
changeset
|
1897 } else { |
|
75852
5fae5be91849
use identifier api
Benjamin Peterson <benjamin@python.org>
parents:
75714
diff
changeset
|
1898 _Py_IDENTIFIER(send); |
| 79693 | 1899 if (v == Py_None) |
| 1900 retval = Py_TYPE(reciever)->tp_iternext(reciever); | |
|
75714
72556ff86828
perform yield from delegation by repeating YIELD_FROM opcode (closes #14230)
Benjamin Peterson <benjamin@python.org>
parents:
75292
diff
changeset
|
1901 else |
| 79693 | 1902 retval = _PyObject_CallMethodId(reciever, &PyId_send, "O", v); |
|
75714
72556ff86828
perform yield from delegation by repeating YIELD_FROM opcode (closes #14230)
Benjamin Peterson <benjamin@python.org>
parents:
75292
diff
changeset
|
1903 } |
| 79693 | 1904 Py_DECREF(v); |
| 1905 if (retval == NULL) { | |
|
75714
72556ff86828
perform yield from delegation by repeating YIELD_FROM opcode (closes #14230)
Benjamin Peterson <benjamin@python.org>
parents:
75292
diff
changeset
|
1906 PyObject *val; |
|
87318
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
86972
diff
changeset
|
1907 if (tstate->c_tracefunc != NULL |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
86972
diff
changeset
|
1908 && PyErr_ExceptionMatches(PyExc_StopIteration)) |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
86972
diff
changeset
|
1909 call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj, f); |
|
77476
cfbf6aa5c9e3
Issue #13783: the PEP 380 implementation no longer expands the public C API
Nick Coghlan <ncoghlan@gmail.com>
parents:
77283
diff
changeset
|
1910 err = _PyGen_FetchStopIterationValue(&val); |
| 79693 | 1911 if (err < 0) |
| 1912 goto error; | |
| 1913 Py_DECREF(reciever); | |
| 1914 SET_TOP(val); | |
| 1915 DISPATCH(); | |
|
74356
d64ac9ab4cd0
Implement PEP 380 - 'yield from' (closes #11682)
Nick Coghlan <ncoghlan@gmail.com>
parents:
73738
diff
changeset
|
1916 } |
|
75714
72556ff86828
perform yield from delegation by repeating YIELD_FROM opcode (closes #14230)
Benjamin Peterson <benjamin@python.org>
parents:
75292
diff
changeset
|
1917 /* x remains on stack, retval is value to be yielded */ |
|
74356
d64ac9ab4cd0
Implement PEP 380 - 'yield from' (closes #11682)
Nick Coghlan <ncoghlan@gmail.com>
parents:
73738
diff
changeset
|
1918 f->f_stacktop = stack_pointer; |
|
d64ac9ab4cd0
Implement PEP 380 - 'yield from' (closes #11682)
Nick Coghlan <ncoghlan@gmail.com>
parents:
73738
diff
changeset
|
1919 why = WHY_YIELD; |
|
75714
72556ff86828
perform yield from delegation by repeating YIELD_FROM opcode (closes #14230)
Benjamin Peterson <benjamin@python.org>
parents:
75292
diff
changeset
|
1920 /* and repeat... */ |
|
72556ff86828
perform yield from delegation by repeating YIELD_FROM opcode (closes #14230)
Benjamin Peterson <benjamin@python.org>
parents:
75292
diff
changeset
|
1921 f->f_lasti--; |
|
74356
d64ac9ab4cd0
Implement PEP 380 - 'yield from' (closes #11682)
Nick Coghlan <ncoghlan@gmail.com>
parents:
73738
diff
changeset
|
1922 goto fast_yield; |
| 79693 | 1923 } |
| 1924 | |
| 1925 TARGET(YIELD_VALUE) { | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1926 retval = POP(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1927 f->f_stacktop = stack_pointer; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1928 why = WHY_YIELD; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1929 goto fast_yield; |
| 79693 | 1930 } |
| 1931 | |
| 1932 TARGET(POP_EXCEPT) { | |
| 1933 PyTryBlock *b = PyFrame_BlockPop(f); | |
| 1934 if (b->b_type != EXCEPT_HANDLER) { | |
| 1935 PyErr_SetString(PyExc_SystemError, | |
| 1936 "popped block is not an except handler"); | |
| 1937 goto error; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1938 } |
| 79693 | 1939 UNWIND_EXCEPT_HANDLER(b); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1940 DISPATCH(); |
| 79693 | 1941 } |
| 1942 | |
| 1943 TARGET(POP_BLOCK) { | |
| 1944 PyTryBlock *b = PyFrame_BlockPop(f); | |
| 1945 UNWIND_BLOCK(b); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1946 DISPATCH(); |
| 79693 | 1947 } |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1948 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1949 PREDICTED(END_FINALLY); |
| 79693 | 1950 TARGET(END_FINALLY) { |
| 1951 PyObject *status = POP(); | |
| 1952 if (PyLong_Check(status)) { | |
| 1953 why = (enum why_code) PyLong_AS_LONG(status); | |
| 1954 assert(why != WHY_YIELD && why != WHY_EXCEPTION); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1955 if (why == WHY_RETURN || |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1956 why == WHY_CONTINUE) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1957 retval = POP(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1958 if (why == WHY_SILENCED) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1959 /* An exception was silenced by 'with', we must |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1960 manually unwind the EXCEPT_HANDLER block which was |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1961 created when the exception was caught, otherwise |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1962 the stack will be in an inconsistent state. */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1963 PyTryBlock *b = PyFrame_BlockPop(f); |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
1964 assert(b->b_type == EXCEPT_HANDLER); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
1965 UNWIND_EXCEPT_HANDLER(b); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
1966 why = WHY_NOT; |
| 79693 | 1967 Py_DECREF(status); |
| 1968 DISPATCH(); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1969 } |
| 79693 | 1970 Py_DECREF(status); |
| 1971 goto fast_block_end; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1972 } |
| 79693 | 1973 else if (PyExceptionClass_Check(status)) { |
| 1974 PyObject *exc = POP(); | |
| 1975 PyObject *tb = POP(); | |
| 1976 PyErr_Restore(status, exc, tb); | |
| 1977 why = WHY_EXCEPTION; | |
| 1978 goto fast_block_end; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1979 } |
| 79693 | 1980 else if (status != Py_None) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1981 PyErr_SetString(PyExc_SystemError, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1982 "'finally' pops bad exception"); |
| 79693 | 1983 Py_DECREF(status); |
| 1984 goto error; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
1985 } |
| 79693 | 1986 Py_DECREF(status); |
| 1987 DISPATCH(); | |
| 1988 } | |
| 1989 | |
| 1990 TARGET(LOAD_BUILD_CLASS) { | |
|
75959
c67f3681e032
Issue #14383: Add _PyDict_GetItemId() and _PyDict_SetItemId() functions
Victor Stinner <victor.stinner@gmail.com>
parents:
75852
diff
changeset
|
1991 _Py_IDENTIFIER(__build_class__); |
|
76411
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
1992 |
| 79693 | 1993 PyObject *bc; |
|
76411
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
1994 if (PyDict_CheckExact(f->f_builtins)) { |
| 79693 | 1995 bc = _PyDict_GetItemId(f->f_builtins, &PyId___build_class__); |
| 1996 if (bc == NULL) { | |
|
76411
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
1997 PyErr_SetString(PyExc_NameError, |
|
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
1998 "__build_class__ not found"); |
| 79693 | 1999 goto error; |
|
76411
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
2000 } |
| 79693 | 2001 Py_INCREF(bc); |
|
76411
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
2002 } |
|
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
2003 else { |
|
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
2004 PyObject *build_class_str = _PyUnicode_FromId(&PyId___build_class__); |
|
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
2005 if (build_class_str == NULL) |
|
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
2006 break; |
| 79693 | 2007 bc = PyObject_GetItem(f->f_builtins, build_class_str); |
| 2008 if (bc == NULL) { | |
|
76411
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
2009 if (PyErr_ExceptionMatches(PyExc_KeyError)) |
|
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
2010 PyErr_SetString(PyExc_NameError, |
|
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
2011 "__build_class__ not found"); |
| 79693 | 2012 goto error; |
|
76411
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
2013 } |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2014 } |
| 79693 | 2015 PUSH(bc); |
| 2016 DISPATCH(); | |
|
75959
c67f3681e032
Issue #14383: Add _PyDict_GetItemId() and _PyDict_SetItemId() functions
Victor Stinner <victor.stinner@gmail.com>
parents:
75852
diff
changeset
|
2017 } |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2018 |
| 79693 | 2019 TARGET(STORE_NAME) { |
| 2020 PyObject *name = GETITEM(names, oparg); | |
| 2021 PyObject *v = POP(); | |
| 2022 PyObject *ns = f->f_locals; | |
| 2023 int err; | |
| 2024 if (ns == NULL) { | |
| 2025 PyErr_Format(PyExc_SystemError, | |
| 2026 "no locals found when storing %R", name); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2027 Py_DECREF(v); |
| 79693 | 2028 goto error; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2029 } |
| 79693 | 2030 if (PyDict_CheckExact(ns)) |
| 2031 err = PyDict_SetItem(ns, name, v); | |
| 2032 else | |
| 2033 err = PyObject_SetItem(ns, name, v); | |
| 2034 Py_DECREF(v); | |
| 2035 if (err != 0) | |
| 2036 goto error; | |
|
79650
5a13f9b842b1
add some missing DISPATCH()
Benjamin Peterson <benjamin@python.org>
parents:
78458
diff
changeset
|
2037 DISPATCH(); |
|
75959
c67f3681e032
Issue #14383: Add _PyDict_GetItemId() and _PyDict_SetItemId() functions
Victor Stinner <victor.stinner@gmail.com>
parents:
75852
diff
changeset
|
2038 } |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2039 |
| 79693 | 2040 TARGET(DELETE_NAME) { |
| 2041 PyObject *name = GETITEM(names, oparg); | |
| 2042 PyObject *ns = f->f_locals; | |
| 2043 int err; | |
| 2044 if (ns == NULL) { | |
| 2045 PyErr_Format(PyExc_SystemError, | |
| 2046 "no locals when deleting %R", name); | |
| 2047 goto error; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2048 } |
| 79693 | 2049 err = PyObject_DelItem(ns, name); |
| 2050 if (err != 0) { | |
| 2051 format_exc_check_arg(PyExc_NameError, | |
| 2052 NAME_ERROR_MSG, | |
| 2053 name); | |
| 2054 goto error; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2055 } |
| 79693 | 2056 DISPATCH(); |
| 2057 } | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2058 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2059 PREDICTED_WITH_ARG(UNPACK_SEQUENCE); |
| 79693 | 2060 TARGET(UNPACK_SEQUENCE) { |
| 2061 PyObject *seq = POP(), *item, **items; | |
| 2062 if (PyTuple_CheckExact(seq) && | |
| 2063 PyTuple_GET_SIZE(seq) == oparg) { | |
| 2064 items = ((PyTupleObject *)seq)->ob_item; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2065 while (oparg--) { |
| 79693 | 2066 item = items[oparg]; |
| 2067 Py_INCREF(item); | |
| 2068 PUSH(item); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2069 } |
| 79693 | 2070 } else if (PyList_CheckExact(seq) && |
| 2071 PyList_GET_SIZE(seq) == oparg) { | |
| 2072 items = ((PyListObject *)seq)->ob_item; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2073 while (oparg--) { |
| 79693 | 2074 item = items[oparg]; |
| 2075 Py_INCREF(item); | |
| 2076 PUSH(item); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2077 } |
| 79693 | 2078 } else if (unpack_iterable(seq, oparg, -1, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2079 stack_pointer + oparg)) { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2080 STACKADJ(oparg); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2081 } else { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2082 /* unpack_iterable() raised an exception */ |
| 79693 | 2083 Py_DECREF(seq); |
| 2084 goto error; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2085 } |
| 79693 | 2086 Py_DECREF(seq); |
|
79650
5a13f9b842b1
add some missing DISPATCH()
Benjamin Peterson <benjamin@python.org>
parents:
78458
diff
changeset
|
2087 DISPATCH(); |
| 79693 | 2088 } |
| 2089 | |
| 2090 TARGET(UNPACK_EX) { | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2091 int totalargs = 1 + (oparg & 0xFF) + (oparg >> 8); |
| 79693 | 2092 PyObject *seq = POP(); |
| 2093 | |
| 2094 if (unpack_iterable(seq, oparg & 0xFF, oparg >> 8, | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2095 stack_pointer + totalargs)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2096 stack_pointer += totalargs; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2097 } else { |
| 79693 | 2098 Py_DECREF(seq); |
| 2099 goto error; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2100 } |
| 79693 | 2101 Py_DECREF(seq); |
| 2102 DISPATCH(); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2103 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2104 |
| 79693 | 2105 TARGET(STORE_ATTR) { |
| 2106 PyObject *name = GETITEM(names, oparg); | |
| 2107 PyObject *owner = TOP(); | |
| 2108 PyObject *v = SECOND(); | |
| 2109 int err; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2110 STACKADJ(-2); |
| 79693 | 2111 err = PyObject_SetAttr(owner, name, v); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2112 Py_DECREF(v); |
| 79693 | 2113 Py_DECREF(owner); |
| 2114 if (err != 0) | |
| 2115 goto error; | |
| 2116 DISPATCH(); | |
| 2117 } | |
| 2118 | |
| 2119 TARGET(DELETE_ATTR) { | |
| 2120 PyObject *name = GETITEM(names, oparg); | |
| 2121 PyObject *owner = POP(); | |
| 2122 int err; | |
| 2123 err = PyObject_SetAttr(owner, name, (PyObject *)NULL); | |
| 2124 Py_DECREF(owner); | |
| 2125 if (err != 0) | |
| 2126 goto error; | |
|
79650
5a13f9b842b1
add some missing DISPATCH()
Benjamin Peterson <benjamin@python.org>
parents:
78458
diff
changeset
|
2127 DISPATCH(); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2128 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2129 |
| 79693 | 2130 TARGET(STORE_GLOBAL) { |
| 2131 PyObject *name = GETITEM(names, oparg); | |
| 2132 PyObject *v = POP(); | |
| 2133 int err; | |
| 2134 err = PyDict_SetItem(f->f_globals, name, v); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2135 Py_DECREF(v); |
| 79693 | 2136 if (err != 0) |
| 2137 goto error; | |
| 2138 DISPATCH(); | |
| 2139 } | |
| 2140 | |
| 2141 TARGET(DELETE_GLOBAL) { | |
| 2142 PyObject *name = GETITEM(names, oparg); | |
| 2143 int err; | |
| 2144 err = PyDict_DelItem(f->f_globals, name); | |
| 2145 if (err != 0) { | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2146 format_exc_check_arg( |
|
82459
f1d3fbcd837d
#17032: The "global" in the "NameError: global name 'x' is not defined" error message has been removed. Patch by Ram Rachum.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
82133
diff
changeset
|
2147 PyExc_NameError, NAME_ERROR_MSG, name); |
| 79693 | 2148 goto error; |
|
79650
5a13f9b842b1
add some missing DISPATCH()
Benjamin Peterson <benjamin@python.org>
parents:
78458
diff
changeset
|
2149 } |
|
5a13f9b842b1
add some missing DISPATCH()
Benjamin Peterson <benjamin@python.org>
parents:
78458
diff
changeset
|
2150 DISPATCH(); |
| 79693 | 2151 } |
| 2152 | |
| 2153 TARGET(LOAD_NAME) { | |
| 2154 PyObject *name = GETITEM(names, oparg); | |
| 2155 PyObject *locals = f->f_locals; | |
| 2156 PyObject *v; | |
| 2157 if (locals == NULL) { | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2158 PyErr_Format(PyExc_SystemError, |
| 79693 | 2159 "no locals when loading %R", name); |
| 2160 goto error; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2161 } |
| 79693 | 2162 if (PyDict_CheckExact(locals)) { |
| 2163 v = PyDict_GetItem(locals, name); | |
| 2164 Py_XINCREF(v); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2165 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2166 else { |
| 79693 | 2167 v = PyObject_GetItem(locals, name); |
|
86141
19954e5dbef5
Fix macro expansion of _PyErr_OCCURRED(), and make sure to use it in at least one place so as to avoid regressions.
Antoine Pitrou <solipsis@pitrou.net>
diff
changeset
|
2168 if (v == NULL && _PyErr_OCCURRED()) { |
|
80857
bb6fd6f021e7
use error label instead of breaking eval loop (closes #16693)
Benjamin Peterson <benjamin@python.org>
parents:
79695
diff
changeset
|
2169 if (!PyErr_ExceptionMatches(PyExc_KeyError)) |
|
bb6fd6f021e7
use error label instead of breaking eval loop (closes #16693)
Benjamin Peterson <benjamin@python.org>
parents:
79695
diff
changeset
|
2170 goto error; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2171 PyErr_Clear(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2172 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2173 } |
| 79693 | 2174 if (v == NULL) { |
| 2175 v = PyDict_GetItem(f->f_globals, name); | |
| 2176 Py_XINCREF(v); | |
| 2177 if (v == NULL) { | |
|
76411
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
2178 if (PyDict_CheckExact(f->f_builtins)) { |
| 79693 | 2179 v = PyDict_GetItem(f->f_builtins, name); |
| 2180 if (v == NULL) { | |
|
76411
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
2181 format_exc_check_arg( |
|
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
2182 PyExc_NameError, |
| 79693 | 2183 NAME_ERROR_MSG, name); |
| 2184 goto error; | |
|
76411
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
2185 } |
| 79693 | 2186 Py_INCREF(v); |
|
76411
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
2187 } |
|
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
2188 else { |
| 79693 | 2189 v = PyObject_GetItem(f->f_builtins, name); |
| 2190 if (v == NULL) { | |
|
76411
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
2191 if (PyErr_ExceptionMatches(PyExc_KeyError)) |
|
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
2192 format_exc_check_arg( |
|
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
2193 PyExc_NameError, |
| 79693 | 2194 NAME_ERROR_MSG, name); |
| 2195 goto error; | |
|
76411
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
2196 } |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2197 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2198 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2199 } |
| 79693 | 2200 PUSH(v); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2201 DISPATCH(); |
| 79693 | 2202 } |
| 2203 | |
| 2204 TARGET(LOAD_GLOBAL) { | |
| 2205 PyObject *name = GETITEM(names, oparg); | |
| 2206 PyObject *v; | |
|
76411
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
2207 if (PyDict_CheckExact(f->f_globals) |
|
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
2208 && PyDict_CheckExact(f->f_builtins)) { |
| 79693 | 2209 v = _PyDict_LoadGlobal((PyDictObject *)f->f_globals, |
|
76485
6e5855854a2e
Implement PEP 412: Key-sharing dictionaries (closes #13903)
Benjamin Peterson <benjamin@python.org>
parents:
76419
diff
changeset
|
2210 (PyDictObject *)f->f_builtins, |
| 79693 | 2211 name); |
| 2212 if (v == NULL) { | |
|
86140
2aee9c41bb79
Fix macro expansion of _PyErr_OCCURRED(), and make sure to use it in at least one place so as to avoid regressions.
Antoine Pitrou <solipsis@pitrou.net>
parents:
84726
diff
changeset
|
2213 if (!_PyErr_OCCURRED()) |
|
76485
6e5855854a2e
Implement PEP 412: Key-sharing dictionaries (closes #13903)
Benjamin Peterson <benjamin@python.org>
parents:
76419
diff
changeset
|
2214 format_exc_check_arg(PyExc_NameError, |
|
82459
f1d3fbcd837d
#17032: The "global" in the "NameError: global name 'x' is not defined" error message has been removed. Patch by Ram Rachum.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
82133
diff
changeset
|
2215 NAME_ERROR_MSG, name); |
| 79693 | 2216 goto error; |
|
76411
e3ab8aa0216c
Issue #14385: Support other types than dict for __builtins__
Victor Stinner <victor.stinner@gmail.com>
parents:
76072
diff
changeset
|
2217 } |
| 79693 | 2218 Py_INCREF(v); |
|
76485
6e5855854a2e
Implement PEP 412: Key-sharing dictionaries (closes #13903)
Benjamin Peterson <benjamin@python.org>
parents:
76419
diff
changeset
|
2219 } |
|
6e5855854a2e
Implement PEP 412: Key-sharing dictionaries (closes #13903)
Benjamin Peterson <benjamin@python.org>
parents:
76419
diff
changeset
|
2220 else { |
|
6e5855854a2e
Implement PEP 412: Key-sharing dictionaries (closes #13903)
Benjamin Peterson <benjamin@python.org>
parents:
76419
diff
changeset
|
2221 /* Slow-path if globals or builtins is not a dict */ |
| 79693 | 2222 v = PyObject_GetItem(f->f_globals, name); |
| 2223 if (v == NULL) { | |
| 2224 v = PyObject_GetItem(f->f_builtins, name); | |
| 2225 if (v == NULL) { | |
|
76485
6e5855854a2e
Implement PEP 412: Key-sharing dictionaries (closes #13903)
Benjamin Peterson <benjamin@python.org>
parents:
76419
diff
changeset
|
2226 if (PyErr_ExceptionMatches(PyExc_KeyError)) |
|
6e5855854a2e
Implement PEP 412: Key-sharing dictionaries (closes #13903)
Benjamin Peterson <benjamin@python.org>
parents:
76419
diff
changeset
|
2227 format_exc_check_arg( |
|
6e5855854a2e
Implement PEP 412: Key-sharing dictionaries (closes #13903)
Benjamin Peterson <benjamin@python.org>
parents:
76419
diff
changeset
|
2228 PyExc_NameError, |
|
82459
f1d3fbcd837d
#17032: The "global" in the "NameError: global name 'x' is not defined" error message has been removed. Patch by Ram Rachum.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
82133
diff
changeset
|
2229 NAME_ERROR_MSG, name); |
| 79693 | 2230 goto error; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2231 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2232 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2233 } |
| 79693 | 2234 PUSH(v); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2235 DISPATCH(); |
| 79693 | 2236 } |
| 2237 | |
| 2238 TARGET(DELETE_FAST) { | |
| 2239 PyObject *v = GETLOCAL(oparg); | |
| 2240 if (v != NULL) { | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2241 SETLOCAL(oparg, NULL); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2242 DISPATCH(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2243 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2244 format_exc_check_arg( |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2245 PyExc_UnboundLocalError, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2246 UNBOUNDLOCAL_ERROR_MSG, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2247 PyTuple_GetItem(co->co_varnames, oparg) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2248 ); |
| 79693 | 2249 goto error; |
| 2250 } | |
| 2251 | |
| 2252 TARGET(DELETE_DEREF) { | |
| 2253 PyObject *cell = freevars[oparg]; | |
| 2254 if (PyCell_GET(cell) != NULL) { | |
| 2255 PyCell_Set(cell, NULL); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2256 DISPATCH(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2257 } |
| 79693 | 2258 format_exc_unbound(co, oparg); |
| 2259 goto error; | |
| 2260 } | |
| 2261 | |
| 2262 TARGET(LOAD_CLOSURE) { | |
| 2263 PyObject *cell = freevars[oparg]; | |
| 2264 Py_INCREF(cell); | |
| 2265 PUSH(cell); | |
| 2266 DISPATCH(); | |
| 2267 } | |
| 2268 | |
|
83572
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2269 TARGET(LOAD_CLASSDEREF) { |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2270 PyObject *name, *value, *locals = f->f_locals; |
|
83800
e5dc97fb304d
Fix a compilater warning on Windows 64-bit
Victor Stinner <victor.stinner@gmail.com>
parents:
83791
diff
changeset
|
2271 Py_ssize_t idx; |
|
83572
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2272 assert(locals); |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2273 assert(oparg >= PyTuple_GET_SIZE(co->co_cellvars)); |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2274 idx = oparg - PyTuple_GET_SIZE(co->co_cellvars); |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2275 assert(idx >= 0 && idx < PyTuple_GET_SIZE(co->co_freevars)); |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2276 name = PyTuple_GET_ITEM(co->co_freevars, idx); |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2277 if (PyDict_CheckExact(locals)) { |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2278 value = PyDict_GetItem(locals, name); |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2279 Py_XINCREF(value); |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2280 } |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2281 else { |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2282 value = PyObject_GetItem(locals, name); |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2283 if (value == NULL && PyErr_Occurred()) { |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2284 if (!PyErr_ExceptionMatches(PyExc_KeyError)) |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2285 goto error; |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2286 PyErr_Clear(); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2287 } |
|
83572
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2288 } |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2289 if (!value) { |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2290 PyObject *cell = freevars[oparg]; |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2291 value = PyCell_GET(cell); |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2292 if (value == NULL) { |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2293 format_exc_unbound(co, oparg); |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2294 goto error; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2295 } |
|
83572
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2296 Py_INCREF(value); |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2297 } |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2298 PUSH(value); |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2299 DISPATCH(); |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2300 } |
|
cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
Benjamin Peterson <benjamin@python.org>
parents:
83456
diff
changeset
|
2301 |
| 79693 | 2302 TARGET(LOAD_DEREF) { |
| 2303 PyObject *cell = freevars[oparg]; | |
| 2304 PyObject *value = PyCell_GET(cell); | |
| 2305 if (value == NULL) { | |
| 2306 format_exc_unbound(co, oparg); | |
| 2307 goto error; | |
| 2308 } | |
| 2309 Py_INCREF(value); | |
| 2310 PUSH(value); | |
| 2311 DISPATCH(); | |
| 2312 } | |
| 2313 | |
| 2314 TARGET(STORE_DEREF) { | |
| 2315 PyObject *v = POP(); | |
| 2316 PyObject *cell = freevars[oparg]; | |
| 2317 PyCell_Set(cell, v); | |
| 2318 Py_DECREF(v); | |
| 2319 DISPATCH(); | |
| 2320 } | |
| 2321 | |
| 2322 TARGET(BUILD_TUPLE) { | |
| 2323 PyObject *tup = PyTuple_New(oparg); | |
| 2324 if (tup == NULL) | |
| 2325 goto error; | |
| 2326 while (--oparg >= 0) { | |
| 2327 PyObject *item = POP(); | |
| 2328 PyTuple_SET_ITEM(tup, oparg, item); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2329 } |
| 79693 | 2330 PUSH(tup); |
| 2331 DISPATCH(); | |
| 2332 } | |
| 2333 | |
| 2334 TARGET(BUILD_LIST) { | |
| 2335 PyObject *list = PyList_New(oparg); | |
| 2336 if (list == NULL) | |
| 2337 goto error; | |
| 2338 while (--oparg >= 0) { | |
| 2339 PyObject *item = POP(); | |
| 2340 PyList_SET_ITEM(list, oparg, item); | |
| 2341 } | |
| 2342 PUSH(list); | |
| 2343 DISPATCH(); | |
| 2344 } | |
| 2345 | |
| 2346 TARGET(BUILD_SET) { | |
| 2347 PyObject *set = PySet_New(NULL); | |
| 2348 int err = 0; | |
| 2349 if (set == NULL) | |
| 2350 goto error; | |
| 2351 while (--oparg >= 0) { | |
| 2352 PyObject *item = POP(); | |
| 2353 if (err == 0) | |
| 2354 err = PySet_Add(set, item); | |
| 2355 Py_DECREF(item); | |
| 2356 } | |
| 2357 if (err != 0) { | |
| 2358 Py_DECREF(set); | |
| 2359 goto error; | |
| 2360 } | |
| 2361 PUSH(set); | |
| 2362 DISPATCH(); | |
| 2363 } | |
| 2364 | |
| 2365 TARGET(BUILD_MAP) { | |
| 2366 PyObject *map = _PyDict_NewPresized((Py_ssize_t)oparg); | |
| 2367 if (map == NULL) | |
| 2368 goto error; | |
| 2369 PUSH(map); | |
| 2370 DISPATCH(); | |
| 2371 } | |
| 2372 | |
| 2373 TARGET(STORE_MAP) { | |
| 2374 PyObject *key = TOP(); | |
| 2375 PyObject *value = SECOND(); | |
| 2376 PyObject *map = THIRD(); | |
| 2377 int err; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2378 STACKADJ(-2); |
| 79693 | 2379 assert(PyDict_CheckExact(map)); |
| 2380 err = PyDict_SetItem(map, key, value); | |
| 2381 Py_DECREF(value); | |
| 2382 Py_DECREF(key); | |
| 2383 if (err != 0) | |
| 2384 goto error; | |
| 2385 DISPATCH(); | |
| 2386 } | |
| 2387 | |
| 2388 TARGET(MAP_ADD) { | |
| 2389 PyObject *key = TOP(); | |
| 2390 PyObject *value = SECOND(); | |
| 2391 PyObject *map; | |
| 2392 int err; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2393 STACKADJ(-2); |
| 79693 | 2394 map = stack_pointer[-oparg]; /* dict */ |
| 2395 assert(PyDict_CheckExact(map)); | |
| 2396 err = PyDict_SetItem(map, key, value); /* v[w] = u */ | |
| 2397 Py_DECREF(value); | |
| 2398 Py_DECREF(key); | |
| 2399 if (err != 0) | |
| 2400 goto error; | |
| 2401 PREDICT(JUMP_ABSOLUTE); | |
| 2402 DISPATCH(); | |
| 2403 } | |
| 2404 | |
| 2405 TARGET(LOAD_ATTR) { | |
| 2406 PyObject *name = GETITEM(names, oparg); | |
| 2407 PyObject *owner = TOP(); | |
| 2408 PyObject *res = PyObject_GetAttr(owner, name); | |
| 2409 Py_DECREF(owner); | |
| 2410 SET_TOP(res); | |
| 2411 if (res == NULL) | |
| 2412 goto error; | |
| 2413 DISPATCH(); | |
| 2414 } | |
| 2415 | |
| 2416 TARGET(COMPARE_OP) { | |
| 2417 PyObject *right = POP(); | |
| 2418 PyObject *left = TOP(); | |
| 2419 PyObject *res = cmp_outcome(oparg, left, right); | |
| 2420 Py_DECREF(left); | |
| 2421 Py_DECREF(right); | |
| 2422 SET_TOP(res); | |
| 2423 if (res == NULL) | |
| 2424 goto error; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2425 PREDICT(POP_JUMP_IF_FALSE); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2426 PREDICT(POP_JUMP_IF_TRUE); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2427 DISPATCH(); |
| 79693 | 2428 } |
| 2429 | |
| 2430 TARGET(IMPORT_NAME) { | |
|
75959
c67f3681e032
Issue #14383: Add _PyDict_GetItemId() and _PyDict_SetItemId() functions
Victor Stinner <victor.stinner@gmail.com>
parents:
75852
diff
changeset
|
2431 _Py_IDENTIFIER(__import__); |
| 79693 | 2432 PyObject *name = GETITEM(names, oparg); |
| 2433 PyObject *func = _PyDict_GetItemId(f->f_builtins, &PyId___import__); | |
|
79695
fb40d0ab0c77
move more variable declarations to the top of blocks
Benjamin Peterson <benjamin@python.org>
parents:
79694
diff
changeset
|
2434 PyObject *from, *level, *args, *res; |
| 79693 | 2435 if (func == NULL) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2436 PyErr_SetString(PyExc_ImportError, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2437 "__import__ not found"); |
| 79693 | 2438 goto error; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2439 } |
| 79693 | 2440 Py_INCREF(func); |
| 2441 from = POP(); | |
| 2442 level = TOP(); | |
| 2443 if (PyLong_AsLong(level) != -1 || PyErr_Occurred()) | |
| 2444 args = PyTuple_Pack(5, | |
| 2445 name, | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2446 f->f_globals, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2447 f->f_locals == NULL ? |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2448 Py_None : f->f_locals, |
| 79693 | 2449 from, |
| 2450 level); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2451 else |
| 79693 | 2452 args = PyTuple_Pack(4, |
| 2453 name, | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2454 f->f_globals, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2455 f->f_locals == NULL ? |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2456 Py_None : f->f_locals, |
| 79693 | 2457 from); |
| 2458 Py_DECREF(level); | |
| 2459 Py_DECREF(from); | |
| 2460 if (args == NULL) { | |
| 2461 Py_DECREF(func); | |
| 2462 STACKADJ(-1); | |
| 2463 goto error; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2464 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2465 READ_TIMESTAMP(intr0); |
|
79695
fb40d0ab0c77
move more variable declarations to the top of blocks
Benjamin Peterson <benjamin@python.org>
parents:
79694
diff
changeset
|
2466 res = PyEval_CallObject(func, args); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2467 READ_TIMESTAMP(intr1); |
| 79693 | 2468 Py_DECREF(args); |
| 2469 Py_DECREF(func); | |
| 2470 SET_TOP(res); | |
| 2471 if (res == NULL) | |
| 2472 goto error; | |
| 2473 DISPATCH(); | |
|
75959
c67f3681e032
Issue #14383: Add _PyDict_GetItemId() and _PyDict_SetItemId() functions
Victor Stinner <victor.stinner@gmail.com>
parents:
75852
diff
changeset
|
2474 } |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2475 |
| 79693 | 2476 TARGET(IMPORT_STAR) { |
| 2477 PyObject *from = POP(), *locals; | |
| 2478 int err; | |
|
86715
4ef4578db38a
Issue #18408: Add a new PyFrame_FastToLocalsWithError() function to handle
Victor Stinner <victor.stinner@gmail.com>
parents:
86185
diff
changeset
|
2479 if (PyFrame_FastToLocalsWithError(f) < 0) |
|
4ef4578db38a
Issue #18408: Add a new PyFrame_FastToLocalsWithError() function to handle
Victor Stinner <victor.stinner@gmail.com>
parents:
86185
diff
changeset
|
2480 goto error; |
|
4ef4578db38a
Issue #18408: Add a new PyFrame_FastToLocalsWithError() function to handle
Victor Stinner <victor.stinner@gmail.com>
parents:
86185
diff
changeset
|
2481 |
| 79693 | 2482 locals = f->f_locals; |
| 2483 if (locals == NULL) { | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2484 PyErr_SetString(PyExc_SystemError, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2485 "no locals found during 'import *'"); |
| 79693 | 2486 goto error; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2487 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2488 READ_TIMESTAMP(intr0); |
| 79693 | 2489 err = import_all_from(locals, from); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2490 READ_TIMESTAMP(intr1); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2491 PyFrame_LocalsToFast(f, 0); |
| 79693 | 2492 Py_DECREF(from); |
| 2493 if (err != 0) | |
| 2494 goto error; | |
| 2495 DISPATCH(); | |
| 2496 } | |
| 2497 | |
| 2498 TARGET(IMPORT_FROM) { | |
| 2499 PyObject *name = GETITEM(names, oparg); | |
| 2500 PyObject *from = TOP(); | |
| 2501 PyObject *res; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2502 READ_TIMESTAMP(intr0); |
| 79693 | 2503 res = import_from(from, name); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2504 READ_TIMESTAMP(intr1); |
| 79693 | 2505 PUSH(res); |
| 2506 if (res == NULL) | |
| 2507 goto error; | |
| 2508 DISPATCH(); | |
| 2509 } | |
| 2510 | |
| 2511 TARGET(JUMP_FORWARD) { | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2512 JUMPBY(oparg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2513 FAST_DISPATCH(); |
| 79693 | 2514 } |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2515 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2516 PREDICTED_WITH_ARG(POP_JUMP_IF_FALSE); |
| 79693 | 2517 TARGET(POP_JUMP_IF_FALSE) { |
| 2518 PyObject *cond = POP(); | |
| 2519 int err; | |
| 2520 if (cond == Py_True) { | |
| 2521 Py_DECREF(cond); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2522 FAST_DISPATCH(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2523 } |
| 79693 | 2524 if (cond == Py_False) { |
| 2525 Py_DECREF(cond); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2526 JUMPTO(oparg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2527 FAST_DISPATCH(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2528 } |
| 79693 | 2529 err = PyObject_IsTrue(cond); |
| 2530 Py_DECREF(cond); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2531 if (err > 0) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2532 err = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2533 else if (err == 0) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2534 JUMPTO(oparg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2535 else |
| 79693 | 2536 goto error; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2537 DISPATCH(); |
| 79693 | 2538 } |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2539 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2540 PREDICTED_WITH_ARG(POP_JUMP_IF_TRUE); |
| 79693 | 2541 TARGET(POP_JUMP_IF_TRUE) { |
| 2542 PyObject *cond = POP(); | |
| 2543 int err; | |
| 2544 if (cond == Py_False) { | |
| 2545 Py_DECREF(cond); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2546 FAST_DISPATCH(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2547 } |
| 79693 | 2548 if (cond == Py_True) { |
| 2549 Py_DECREF(cond); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2550 JUMPTO(oparg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2551 FAST_DISPATCH(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2552 } |
| 79693 | 2553 err = PyObject_IsTrue(cond); |
| 2554 Py_DECREF(cond); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2555 if (err > 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2556 err = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2557 JUMPTO(oparg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2558 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2559 else if (err == 0) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2560 ; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2561 else |
| 79693 | 2562 goto error; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2563 DISPATCH(); |
| 79693 | 2564 } |
| 2565 | |
| 2566 TARGET(JUMP_IF_FALSE_OR_POP) { | |
| 2567 PyObject *cond = TOP(); | |
| 2568 int err; | |
| 2569 if (cond == Py_True) { | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2570 STACKADJ(-1); |
| 79693 | 2571 Py_DECREF(cond); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2572 FAST_DISPATCH(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2573 } |
| 79693 | 2574 if (cond == Py_False) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2575 JUMPTO(oparg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2576 FAST_DISPATCH(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2577 } |
| 79693 | 2578 err = PyObject_IsTrue(cond); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2579 if (err > 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2580 STACKADJ(-1); |
| 79693 | 2581 Py_DECREF(cond); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2582 err = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2583 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2584 else if (err == 0) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2585 JUMPTO(oparg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2586 else |
| 79693 | 2587 goto error; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2588 DISPATCH(); |
| 79693 | 2589 } |
| 2590 | |
| 2591 TARGET(JUMP_IF_TRUE_OR_POP) { | |
| 2592 PyObject *cond = TOP(); | |
| 2593 int err; | |
| 2594 if (cond == Py_False) { | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2595 STACKADJ(-1); |
| 79693 | 2596 Py_DECREF(cond); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2597 FAST_DISPATCH(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2598 } |
| 79693 | 2599 if (cond == Py_True) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2600 JUMPTO(oparg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2601 FAST_DISPATCH(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2602 } |
| 79693 | 2603 err = PyObject_IsTrue(cond); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2604 if (err > 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2605 err = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2606 JUMPTO(oparg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2607 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2608 else if (err == 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2609 STACKADJ(-1); |
| 79693 | 2610 Py_DECREF(cond); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2611 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2612 else |
| 79693 | 2613 goto error; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2614 DISPATCH(); |
| 79693 | 2615 } |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2616 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2617 PREDICTED_WITH_ARG(JUMP_ABSOLUTE); |
| 79693 | 2618 TARGET(JUMP_ABSOLUTE) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2619 JUMPTO(oparg); |
|
43815
85cf334b32c3
Merged revisions 58886-58929 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
2620 #if FAST_LOOPS |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2621 /* Enabling this path speeds-up all while and for-loops by bypassing |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2622 the per-loop checks for signals. By default, this should be turned-off |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2623 because it prevents detection of a control-break in tight loops like |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2624 "while 1: pass". Compile with this option turned-on when you need |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2625 the speed-up and do not need break checking inside tight loops (ones |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2626 that contain only instructions ending with FAST_DISPATCH). |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2627 */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2628 FAST_DISPATCH(); |
|
43815
85cf334b32c3
Merged revisions 58886-58929 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
2629 #else |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2630 DISPATCH(); |
|
43815
85cf334b32c3
Merged revisions 58886-58929 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
2631 #endif |
| 79693 | 2632 } |
| 2633 | |
| 2634 TARGET(GET_ITER) { | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2635 /* before: [obj]; after [getiter(obj)] */ |
| 79693 | 2636 PyObject *iterable = TOP(); |
| 2637 PyObject *iter = PyObject_GetIter(iterable); | |
| 2638 Py_DECREF(iterable); | |
| 2639 SET_TOP(iter); | |
| 2640 if (iter == NULL) | |
| 2641 goto error; | |
| 2642 PREDICT(FOR_ITER); | |
| 2643 DISPATCH(); | |
| 2644 } | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2645 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2646 PREDICTED_WITH_ARG(FOR_ITER); |
| 79693 | 2647 TARGET(FOR_ITER) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2648 /* before: [iter]; after: [iter, iter()] *or* [] */ |
| 79693 | 2649 PyObject *iter = TOP(); |
| 2650 PyObject *next = (*iter->ob_type->tp_iternext)(iter); | |
| 2651 if (next != NULL) { | |
| 2652 PUSH(next); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2653 PREDICT(STORE_FAST); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2654 PREDICT(UNPACK_SEQUENCE); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2655 DISPATCH(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2656 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2657 if (PyErr_Occurred()) { |
| 79693 | 2658 if (!PyErr_ExceptionMatches(PyExc_StopIteration)) |
| 2659 goto error; | |
|
87318
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
86972
diff
changeset
|
2660 else if (tstate->c_tracefunc != NULL) |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
86972
diff
changeset
|
2661 call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj, f); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2662 PyErr_Clear(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2663 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2664 /* iterator ended normally */ |
| 79693 | 2665 STACKADJ(-1); |
| 2666 Py_DECREF(iter); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2667 JUMPBY(oparg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2668 DISPATCH(); |
| 79693 | 2669 } |
| 2670 | |
| 2671 TARGET(BREAK_LOOP) { | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2672 why = WHY_BREAK; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2673 goto fast_block_end; |
| 79693 | 2674 } |
| 2675 | |
| 2676 TARGET(CONTINUE_LOOP) { | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2677 retval = PyLong_FromLong(oparg); |
| 79693 | 2678 if (retval == NULL) |
| 2679 goto error; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2680 why = WHY_CONTINUE; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2681 goto fast_block_end; |
| 79693 | 2682 } |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2683 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2684 TARGET_WITH_IMPL(SETUP_LOOP, _setup_finally) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2685 TARGET_WITH_IMPL(SETUP_EXCEPT, _setup_finally) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2686 TARGET(SETUP_FINALLY) |
| 79693 | 2687 _setup_finally: { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2688 /* NOTE: If you add any new block-setup opcodes that |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2689 are not try/except/finally handlers, you may need |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2690 to update the PyGen_NeedsFinalizing() function. |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2691 */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2692 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2693 PyFrame_BlockSetup(f, opcode, INSTR_OFFSET() + oparg, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2694 STACK_LEVEL()); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2695 DISPATCH(); |
| 79693 | 2696 } |
| 2697 | |
| 2698 TARGET(SETUP_WITH) { | |
|
74578
7d96679c5d46
use the static identifier api for looking up special methods
Benjamin Peterson <benjamin@python.org>
parents:
74367
diff
changeset
|
2699 _Py_IDENTIFIER(__exit__); |
|
7d96679c5d46
use the static identifier api for looking up special methods
Benjamin Peterson <benjamin@python.org>
parents:
74367
diff
changeset
|
2700 _Py_IDENTIFIER(__enter__); |
| 79693 | 2701 PyObject *mgr = TOP(); |
| 2702 PyObject *exit = special_lookup(mgr, &PyId___exit__), *enter; | |
| 2703 PyObject *res; | |
| 2704 if (exit == NULL) | |
| 2705 goto error; | |
| 2706 SET_TOP(exit); | |
| 2707 enter = special_lookup(mgr, &PyId___enter__); | |
| 2708 Py_DECREF(mgr); | |
| 2709 if (enter == NULL) | |
| 2710 goto error; | |
| 2711 res = PyObject_CallFunctionObjArgs(enter, NULL); | |
| 2712 Py_DECREF(enter); | |
| 2713 if (res == NULL) | |
| 2714 goto error; | |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2715 /* Setup the finally block before pushing the result |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2716 of __enter__ on the stack. */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2717 PyFrame_BlockSetup(f, SETUP_FINALLY, INSTR_OFFSET() + oparg, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2718 STACK_LEVEL()); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2719 |
| 79693 | 2720 PUSH(res); |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2721 DISPATCH(); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2722 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2723 |
| 79693 | 2724 TARGET(WITH_CLEANUP) { |
| 86772 | 2725 /* At the top of the stack are 1-6 values indicating |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2726 how/why we entered the finally clause: |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2727 - TOP = None |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2728 - (TOP, SECOND) = (WHY_{RETURN,CONTINUE}), retval |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2729 - TOP = WHY_*; no retval below it |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2730 - (TOP, SECOND, THIRD) = exc_info() |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2731 (FOURTH, FITH, SIXTH) = previous exception for EXCEPT_HANDLER |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2732 Below them is EXIT, the context.__exit__ bound method. |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2733 In the last case, we must call |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2734 EXIT(TOP, SECOND, THIRD) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2735 otherwise we must call |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2736 EXIT(None, None, None) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2737 |
| 86772 | 2738 In the first three cases, we remove EXIT from the |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2739 stack, leaving the rest in the same order. In the |
| 86772 | 2740 fourth case, we shift the bottom 3 values of the |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2741 stack down, and replace the empty spot with NULL. |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2742 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2743 In addition, if the stack represents an exception, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2744 *and* the function call returns a 'true' value, we |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2745 push WHY_SILENCED onto the stack. END_FINALLY will |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2746 then not re-raise the exception. (But non-local |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2747 gotos should still be resumed.) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2748 */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2749 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2750 PyObject *exit_func; |
| 79693 | 2751 PyObject *exc = TOP(), *val = Py_None, *tb = Py_None, *res; |
| 2752 int err; | |
| 2753 if (exc == Py_None) { | |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2754 (void)POP(); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2755 exit_func = TOP(); |
| 79693 | 2756 SET_TOP(exc); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2757 } |
| 79693 | 2758 else if (PyLong_Check(exc)) { |
| 2759 STACKADJ(-1); | |
| 2760 switch (PyLong_AsLong(exc)) { | |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2761 case WHY_RETURN: |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2762 case WHY_CONTINUE: |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2763 /* Retval in TOP. */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2764 exit_func = SECOND(); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2765 SET_SECOND(TOP()); |
| 79693 | 2766 SET_TOP(exc); |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2767 break; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2768 default: |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2769 exit_func = TOP(); |
| 79693 | 2770 SET_TOP(exc); |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2771 break; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2772 } |
| 79693 | 2773 exc = Py_None; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2774 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2775 else { |
| 79693 | 2776 PyObject *tp2, *exc2, *tb2; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2777 PyTryBlock *block; |
| 79693 | 2778 val = SECOND(); |
| 2779 tb = THIRD(); | |
| 2780 tp2 = FOURTH(); | |
| 2781 exc2 = PEEK(5); | |
| 2782 tb2 = PEEK(6); | |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2783 exit_func = PEEK(7); |
| 79693 | 2784 SET_VALUE(7, tb2); |
| 2785 SET_VALUE(6, exc2); | |
| 2786 SET_VALUE(5, tp2); | |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2787 /* UNWIND_EXCEPT_HANDLER will pop this off. */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2788 SET_FOURTH(NULL); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2789 /* We just shifted the stack down, so we have |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2790 to tell the except handler block that the |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2791 values are lower than it expects. */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2792 block = &f->f_blockstack[f->f_iblock - 1]; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2793 assert(block->b_type == EXCEPT_HANDLER); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2794 block->b_level--; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2795 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2796 /* XXX Not the fastest way to call it... */ |
| 79693 | 2797 res = PyObject_CallFunctionObjArgs(exit_func, exc, val, tb, NULL); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2798 Py_DECREF(exit_func); |
| 79693 | 2799 if (res == NULL) |
| 2800 goto error; | |
| 2801 | |
| 2802 if (exc != Py_None) | |
| 2803 err = PyObject_IsTrue(res); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2804 else |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2805 err = 0; |
| 79693 | 2806 Py_DECREF(res); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2807 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2808 if (err < 0) |
| 79693 | 2809 goto error; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2810 else if (err > 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2811 err = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2812 /* There was an exception and a True return */ |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
2813 PUSH(PyLong_FromLong((long) WHY_SILENCED)); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2814 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2815 PREDICT(END_FINALLY); |
| 79693 | 2816 DISPATCH(); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2817 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2818 |
| 79693 | 2819 TARGET(CALL_FUNCTION) { |
| 2820 PyObject **sp, *res; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2821 PCALL(PCALL_ALL); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2822 sp = stack_pointer; |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
2823 #ifdef WITH_TSC |
| 79693 | 2824 res = call_function(&sp, oparg, &intr0, &intr1); |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
2825 #else |
| 79693 | 2826 res = call_function(&sp, oparg); |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
2827 #endif |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2828 stack_pointer = sp; |
| 79693 | 2829 PUSH(res); |
| 2830 if (res == NULL) | |
| 2831 goto error; | |
| 2832 DISPATCH(); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2833 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2834 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2835 TARGET_WITH_IMPL(CALL_FUNCTION_VAR, _call_function_var_kw) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2836 TARGET_WITH_IMPL(CALL_FUNCTION_KW, _call_function_var_kw) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2837 TARGET(CALL_FUNCTION_VAR_KW) |
| 79693 | 2838 _call_function_var_kw: { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2839 int na = oparg & 0xff; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2840 int nk = (oparg>>8) & 0xff; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2841 int flags = (opcode - CALL_FUNCTION) & 3; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2842 int n = na + 2 * nk; |
| 79693 | 2843 PyObject **pfunc, *func, **sp, *res; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2844 PCALL(PCALL_ALL); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2845 if (flags & CALL_FLAG_VAR) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2846 n++; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2847 if (flags & CALL_FLAG_KW) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2848 n++; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2849 pfunc = stack_pointer - n - 1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2850 func = *pfunc; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2851 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2852 if (PyMethod_Check(func) |
|
62462
0e4637ea20d0
Merged revisions 82181 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
61467
diff
changeset
|
2853 && PyMethod_GET_SELF(func) != NULL) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2854 PyObject *self = PyMethod_GET_SELF(func); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2855 Py_INCREF(self); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2856 func = PyMethod_GET_FUNCTION(func); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2857 Py_INCREF(func); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2858 Py_DECREF(*pfunc); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2859 *pfunc = self; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2860 na++; |
|
68102
e2f96bd29252
Issue #8914: fix various warnings from the Clang static analyzer v254.
Brett Cannon <bcannon@gmail.com>
parents:
68086
diff
changeset
|
2861 /* n++; */ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2862 } else |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2863 Py_INCREF(func); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2864 sp = stack_pointer; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2865 READ_TIMESTAMP(intr0); |
| 79693 | 2866 res = ext_do_call(func, &sp, flags, na, nk); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2867 READ_TIMESTAMP(intr1); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2868 stack_pointer = sp; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2869 Py_DECREF(func); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2870 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2871 while (stack_pointer > pfunc) { |
| 79693 | 2872 PyObject *o = POP(); |
| 2873 Py_DECREF(o); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2874 } |
| 79693 | 2875 PUSH(res); |
| 2876 if (res == NULL) | |
| 2877 goto error; | |
| 2878 DISPATCH(); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2879 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2880 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2881 TARGET_WITH_IMPL(MAKE_CLOSURE, _make_function) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2882 TARGET(MAKE_FUNCTION) |
| 79693 | 2883 _make_function: { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2884 int posdefaults = oparg & 0xff; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2885 int kwdefaults = (oparg>>8) & 0xff; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2886 int num_annotations = (oparg >> 16) & 0x7fff; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2887 |
| 79693 | 2888 PyObject *qualname = POP(); /* qualname */ |
| 2889 PyObject *code = POP(); /* code object */ | |
| 2890 PyObject *func = PyFunction_NewWithQualName(code, f->f_globals, qualname); | |
| 2891 Py_DECREF(code); | |
| 2892 Py_DECREF(qualname); | |
| 2893 | |
| 2894 if (func == NULL) | |
| 2895 goto error; | |
| 2896 | |
| 2897 if (opcode == MAKE_CLOSURE) { | |
| 2898 PyObject *closure = POP(); | |
| 2899 if (PyFunction_SetClosure(func, closure) != 0) { | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2900 /* Can't happen unless bytecode is corrupt. */ |
| 79693 | 2901 Py_DECREF(func); |
| 2902 Py_DECREF(closure); | |
| 2903 goto error; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2904 } |
| 79693 | 2905 Py_DECREF(closure); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2906 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2907 |
| 79693 | 2908 if (num_annotations > 0) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2909 Py_ssize_t name_ix; |
| 79693 | 2910 PyObject *names = POP(); /* names of args with annotations */ |
| 2911 PyObject *anns = PyDict_New(); | |
| 2912 if (anns == NULL) { | |
| 2913 Py_DECREF(func); | |
| 2914 goto error; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2915 } |
| 79693 | 2916 name_ix = PyTuple_Size(names); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2917 assert(num_annotations == name_ix+1); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2918 while (name_ix > 0) { |
| 79693 | 2919 PyObject *name, *value; |
| 2920 int err; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2921 --name_ix; |
| 79693 | 2922 name = PyTuple_GET_ITEM(names, name_ix); |
| 2923 value = POP(); | |
| 2924 err = PyDict_SetItem(anns, name, value); | |
| 2925 Py_DECREF(value); | |
| 2926 if (err != 0) { | |
| 2927 Py_DECREF(anns); | |
| 2928 Py_DECREF(func); | |
| 2929 goto error; | |
| 2930 } | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2931 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2932 |
| 79693 | 2933 if (PyFunction_SetAnnotations(func, anns) != 0) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2934 /* Can't happen unless |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2935 PyFunction_SetAnnotations changes. */ |
| 79693 | 2936 Py_DECREF(anns); |
| 2937 Py_DECREF(func); | |
| 2938 goto error; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2939 } |
| 79693 | 2940 Py_DECREF(anns); |
| 2941 Py_DECREF(names); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2942 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2943 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2944 /* XXX Maybe this should be a separate opcode? */ |
| 79693 | 2945 if (kwdefaults > 0) { |
| 2946 PyObject *defs = PyDict_New(); | |
| 2947 if (defs == NULL) { | |
| 2948 Py_DECREF(func); | |
| 2949 goto error; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2950 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2951 while (--kwdefaults >= 0) { |
| 79693 | 2952 PyObject *v = POP(); /* default value */ |
| 2953 PyObject *key = POP(); /* kw only arg name */ | |
| 2954 int err = PyDict_SetItem(defs, key, v); | |
| 2955 Py_DECREF(v); | |
| 2956 Py_DECREF(key); | |
| 2957 if (err != 0) { | |
| 2958 Py_DECREF(defs); | |
| 2959 Py_DECREF(func); | |
| 2960 goto error; | |
| 2961 } | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2962 } |
| 79693 | 2963 if (PyFunction_SetKwDefaults(func, defs) != 0) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2964 /* Can't happen unless |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2965 PyFunction_SetKwDefaults changes. */ |
| 79693 | 2966 Py_DECREF(func); |
| 2967 Py_DECREF(defs); | |
| 2968 goto error; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2969 } |
| 79693 | 2970 Py_DECREF(defs); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2971 } |
|
82133
d296cf1600a8
evaluate positional defaults before keyword-only defaults (closes #16967)
Benjamin Peterson <benjamin@python.org>
parents:
81677
diff
changeset
|
2972 if (posdefaults > 0) { |
|
d296cf1600a8
evaluate positional defaults before keyword-only defaults (closes #16967)
Benjamin Peterson <benjamin@python.org>
parents:
81677
diff
changeset
|
2973 PyObject *defs = PyTuple_New(posdefaults); |
|
d296cf1600a8
evaluate positional defaults before keyword-only defaults (closes #16967)
Benjamin Peterson <benjamin@python.org>
parents:
81677
diff
changeset
|
2974 if (defs == NULL) { |
|
d296cf1600a8
evaluate positional defaults before keyword-only defaults (closes #16967)
Benjamin Peterson <benjamin@python.org>
parents:
81677
diff
changeset
|
2975 Py_DECREF(func); |
|
d296cf1600a8
evaluate positional defaults before keyword-only defaults (closes #16967)
Benjamin Peterson <benjamin@python.org>
parents:
81677
diff
changeset
|
2976 goto error; |
|
d296cf1600a8
evaluate positional defaults before keyword-only defaults (closes #16967)
Benjamin Peterson <benjamin@python.org>
parents:
81677
diff
changeset
|
2977 } |
|
d296cf1600a8
evaluate positional defaults before keyword-only defaults (closes #16967)
Benjamin Peterson <benjamin@python.org>
parents:
81677
diff
changeset
|
2978 while (--posdefaults >= 0) |
|
d296cf1600a8
evaluate positional defaults before keyword-only defaults (closes #16967)
Benjamin Peterson <benjamin@python.org>
parents:
81677
diff
changeset
|
2979 PyTuple_SET_ITEM(defs, posdefaults, POP()); |
|
d296cf1600a8
evaluate positional defaults before keyword-only defaults (closes #16967)
Benjamin Peterson <benjamin@python.org>
parents:
81677
diff
changeset
|
2980 if (PyFunction_SetDefaults(func, defs) != 0) { |
|
d296cf1600a8
evaluate positional defaults before keyword-only defaults (closes #16967)
Benjamin Peterson <benjamin@python.org>
parents:
81677
diff
changeset
|
2981 /* Can't happen unless |
|
d296cf1600a8
evaluate positional defaults before keyword-only defaults (closes #16967)
Benjamin Peterson <benjamin@python.org>
parents:
81677
diff
changeset
|
2982 PyFunction_SetDefaults changes. */ |
|
d296cf1600a8
evaluate positional defaults before keyword-only defaults (closes #16967)
Benjamin Peterson <benjamin@python.org>
parents:
81677
diff
changeset
|
2983 Py_DECREF(defs); |
|
d296cf1600a8
evaluate positional defaults before keyword-only defaults (closes #16967)
Benjamin Peterson <benjamin@python.org>
parents:
81677
diff
changeset
|
2984 Py_DECREF(func); |
|
d296cf1600a8
evaluate positional defaults before keyword-only defaults (closes #16967)
Benjamin Peterson <benjamin@python.org>
parents:
81677
diff
changeset
|
2985 goto error; |
|
d296cf1600a8
evaluate positional defaults before keyword-only defaults (closes #16967)
Benjamin Peterson <benjamin@python.org>
parents:
81677
diff
changeset
|
2986 } |
|
d296cf1600a8
evaluate positional defaults before keyword-only defaults (closes #16967)
Benjamin Peterson <benjamin@python.org>
parents:
81677
diff
changeset
|
2987 Py_DECREF(defs); |
|
d296cf1600a8
evaluate positional defaults before keyword-only defaults (closes #16967)
Benjamin Peterson <benjamin@python.org>
parents:
81677
diff
changeset
|
2988 } |
| 79693 | 2989 PUSH(func); |
| 2990 DISPATCH(); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2991 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2992 |
| 79693 | 2993 TARGET(BUILD_SLICE) { |
| 2994 PyObject *start, *stop, *step, *slice; | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2995 if (oparg == 3) |
| 79693 | 2996 step = POP(); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
2997 else |
| 79693 | 2998 step = NULL; |
| 2999 stop = POP(); | |
| 3000 start = TOP(); | |
| 3001 slice = PySlice_New(start, stop, step); | |
| 3002 Py_DECREF(start); | |
| 3003 Py_DECREF(stop); | |
| 3004 Py_XDECREF(step); | |
| 3005 SET_TOP(slice); | |
| 3006 if (slice == NULL) | |
| 3007 goto error; | |
| 3008 DISPATCH(); | |
| 3009 } | |
| 3010 | |
| 3011 TARGET(EXTENDED_ARG) { | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3012 opcode = NEXTOP(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3013 oparg = oparg<<16 | NEXTARG(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3014 goto dispatch_opcode; |
| 79693 | 3015 } |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
3016 |
|
63959
e54baebbd6ff
Issue #9203: Computed gotos are now enabled by default on supported
Antoine Pitrou <solipsis@pitrou.net>
parents:
63114
diff
changeset
|
3017 #if USE_COMPUTED_GOTOS |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3018 _unknown_opcode: |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
3019 #endif |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3020 default: |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3021 fprintf(stderr, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3022 "XXX lineno: %d, opcode: %d\n", |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
3023 PyFrame_GetLineNumber(f), |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3024 opcode); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3025 PyErr_SetString(PyExc_SystemError, "unknown opcode"); |
| 79693 | 3026 goto error; |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
3027 |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
3028 #ifdef CASE_TOO_BIG |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3029 } |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
3030 #endif |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
3031 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3032 } /* switch */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3033 |
| 79693 | 3034 /* This should never be reached. Every opcode should end with DISPATCH() |
| 3035 or goto error. */ | |
| 3036 assert(0); | |
| 3037 | |
| 3038 error: | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3039 READ_TIMESTAMP(inst1); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3040 |
| 79693 | 3041 assert(why == WHY_NOT); |
| 3042 why = WHY_EXCEPTION; | |
| 3043 | |
| 3044 /* Double-check exception status. */ | |
|
84573
d9446c2a2fd4
Issue #18408: ceval.c: in debug mode, convert the PyErr_Occurred() check on
Victor Stinner <victor.stinner@gmail.com>
parents:
84529
diff
changeset
|
3045 #ifdef NDEBUG |
| 79693 | 3046 if (!PyErr_Occurred()) |
| 3047 PyErr_SetString(PyExc_SystemError, | |
| 3048 "error return without exception set"); | |
|
84573
d9446c2a2fd4
Issue #18408: ceval.c: in debug mode, convert the PyErr_Occurred() check on
Victor Stinner <victor.stinner@gmail.com>
parents:
84529
diff
changeset
|
3049 #else |
|
d9446c2a2fd4
Issue #18408: ceval.c: in debug mode, convert the PyErr_Occurred() check on
Victor Stinner <victor.stinner@gmail.com>
parents:
84529
diff
changeset
|
3050 assert(PyErr_Occurred()); |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
3051 #endif |
| 79693 | 3052 |
| 3053 /* Log traceback info. */ | |
| 3054 PyTraceBack_Here(f); | |
| 3055 | |
|
81677
cd87afe18ff8
revert #16672 for incorrect semantics
Benjamin Peterson <benjamin@python.org>
parents:
81015
diff
changeset
|
3056 if (tstate->c_tracefunc != NULL) |
| 79693 | 3057 call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj, f); |
| 3058 | |
| 3059 fast_block_end: | |
| 3060 assert(why != WHY_NOT); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3061 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3062 /* Unwind stacks if a (pseudo) exception occurred */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3063 while (why != WHY_NOT && f->f_iblock > 0) { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
3064 /* Peek at the current block. */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
3065 PyTryBlock *b = &f->f_blockstack[f->f_iblock - 1]; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3066 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3067 assert(why != WHY_YIELD); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3068 if (b->b_type == SETUP_LOOP && why == WHY_CONTINUE) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3069 why = WHY_NOT; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3070 JUMPTO(PyLong_AS_LONG(retval)); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3071 Py_DECREF(retval); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3072 break; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3073 } |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
3074 /* Now we have to pop the block. */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
3075 f->f_iblock--; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3076 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3077 if (b->b_type == EXCEPT_HANDLER) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3078 UNWIND_EXCEPT_HANDLER(b); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3079 continue; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3080 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3081 UNWIND_BLOCK(b); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3082 if (b->b_type == SETUP_LOOP && why == WHY_BREAK) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3083 why = WHY_NOT; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3084 JUMPTO(b->b_handler); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3085 break; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3086 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3087 if (why == WHY_EXCEPTION && (b->b_type == SETUP_EXCEPT |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3088 || b->b_type == SETUP_FINALLY)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3089 PyObject *exc, *val, *tb; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3090 int handler = b->b_handler; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3091 /* Beware, this invalidates all b->b_* fields */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3092 PyFrame_BlockSetup(f, EXCEPT_HANDLER, -1, STACK_LEVEL()); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3093 PUSH(tstate->exc_traceback); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3094 PUSH(tstate->exc_value); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3095 if (tstate->exc_type != NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3096 PUSH(tstate->exc_type); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3097 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3098 else { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3099 Py_INCREF(Py_None); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3100 PUSH(Py_None); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3101 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3102 PyErr_Fetch(&exc, &val, &tb); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3103 /* Make the raw exception data |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3104 available to the handler, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3105 so a program can emulate the |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3106 Python main loop. */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3107 PyErr_NormalizeException( |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3108 &exc, &val, &tb); |
|
84646
71a572a516f9
Issue #18408: Fix PyEval_EvalFrameEx() for MemoryError
Victor Stinner <victor.stinner@gmail.com>
parents:
84583
diff
changeset
|
3109 if (tb != NULL) |
|
71a572a516f9
Issue #18408: Fix PyEval_EvalFrameEx() for MemoryError
Victor Stinner <victor.stinner@gmail.com>
parents:
84583
diff
changeset
|
3110 PyException_SetTraceback(val, tb); |
|
71a572a516f9
Issue #18408: Fix PyEval_EvalFrameEx() for MemoryError
Victor Stinner <victor.stinner@gmail.com>
parents:
84583
diff
changeset
|
3111 else |
|
71a572a516f9
Issue #18408: Fix PyEval_EvalFrameEx() for MemoryError
Victor Stinner <victor.stinner@gmail.com>
parents:
84583
diff
changeset
|
3112 PyException_SetTraceback(val, Py_None); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3113 Py_INCREF(exc); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3114 tstate->exc_type = exc; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3115 Py_INCREF(val); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3116 tstate->exc_value = val; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3117 tstate->exc_traceback = tb; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3118 if (tb == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3119 tb = Py_None; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3120 Py_INCREF(tb); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3121 PUSH(tb); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3122 PUSH(val); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3123 PUSH(exc); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3124 why = WHY_NOT; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3125 JUMPTO(handler); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3126 break; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3127 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3128 if (b->b_type == SETUP_FINALLY) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3129 if (why & (WHY_RETURN | WHY_CONTINUE)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3130 PUSH(retval); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3131 PUSH(PyLong_FromLong((long)why)); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3132 why = WHY_NOT; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3133 JUMPTO(b->b_handler); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3134 break; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3135 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3136 } /* unwind stack */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3137 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3138 /* End the loop if we still have an error (or return) */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3139 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3140 if (why != WHY_NOT) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3141 break; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3142 READ_TIMESTAMP(loop1); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3143 |
|
84704
48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
Victor Stinner <victor.stinner@gmail.com>
parents:
84648
diff
changeset
|
3144 assert(!PyErr_Occurred()); |
|
48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
Victor Stinner <victor.stinner@gmail.com>
parents:
84648
diff
changeset
|
3145 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3146 } /* main loop */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3147 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3148 assert(why != WHY_YIELD); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3149 /* Pop remaining stack entries. */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3150 while (!EMPTY()) { |
| 79693 | 3151 PyObject *o = POP(); |
| 3152 Py_XDECREF(o); | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3153 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3154 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3155 if (why != WHY_RETURN) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3156 retval = NULL; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3157 |
|
84704
48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
Victor Stinner <victor.stinner@gmail.com>
parents:
84648
diff
changeset
|
3158 assert((retval != NULL && !PyErr_Occurred()) |
|
48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
Victor Stinner <victor.stinner@gmail.com>
parents:
84648
diff
changeset
|
3159 || (retval == NULL && PyErr_Occurred())); |
|
48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
Victor Stinner <victor.stinner@gmail.com>
parents:
84648
diff
changeset
|
3160 |
|
31462
d5c047807c69
SF patch #864059: optimize eval_frame
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
3161 fast_yield: |
|
71157
419871c62bb3
never retain a generator's caller's exception state on the generator after a yield/return
Benjamin Peterson <benjamin@python.org>
parents:
71151
diff
changeset
|
3162 if (co->co_flags & CO_GENERATOR && (why == WHY_YIELD || why == WHY_RETURN)) { |
|
419871c62bb3
never retain a generator's caller's exception state on the generator after a yield/return
Benjamin Peterson <benjamin@python.org>
parents:
71151
diff
changeset
|
3163 /* The purpose of this block is to put aside the generator's exception |
|
419871c62bb3
never retain a generator's caller's exception state on the generator after a yield/return
Benjamin Peterson <benjamin@python.org>
parents:
71151
diff
changeset
|
3164 state and restore that of the calling frame. If the current |
|
419871c62bb3
never retain a generator's caller's exception state on the generator after a yield/return
Benjamin Peterson <benjamin@python.org>
parents:
71151
diff
changeset
|
3165 exception state is from the caller, we clear the exception values |
|
419871c62bb3
never retain a generator's caller's exception state on the generator after a yield/return
Benjamin Peterson <benjamin@python.org>
parents:
71151
diff
changeset
|
3166 on the generator frame, so they are not swapped back in latter. The |
|
419871c62bb3
never retain a generator's caller's exception state on the generator after a yield/return
Benjamin Peterson <benjamin@python.org>
parents:
71151
diff
changeset
|
3167 origin of the current exception state is determined by checking for |
|
419871c62bb3
never retain a generator's caller's exception state on the generator after a yield/return
Benjamin Peterson <benjamin@python.org>
parents:
71151
diff
changeset
|
3168 except handler blocks, which we must be in iff a new exception |
|
419871c62bb3
never retain a generator's caller's exception state on the generator after a yield/return
Benjamin Peterson <benjamin@python.org>
parents:
71151
diff
changeset
|
3169 state came into existence in this frame. (An uncaught exception |
|
419871c62bb3
never retain a generator's caller's exception state on the generator after a yield/return
Benjamin Peterson <benjamin@python.org>
parents:
71151
diff
changeset
|
3170 would have why == WHY_EXCEPTION, and we wouldn't be here). */ |
|
419871c62bb3
never retain a generator's caller's exception state on the generator after a yield/return
Benjamin Peterson <benjamin@python.org>
parents:
71151
diff
changeset
|
3171 int i; |
|
419871c62bb3
never retain a generator's caller's exception state on the generator after a yield/return
Benjamin Peterson <benjamin@python.org>
parents:
71151
diff
changeset
|
3172 for (i = 0; i < f->f_iblock; i++) |
|
419871c62bb3
never retain a generator's caller's exception state on the generator after a yield/return
Benjamin Peterson <benjamin@python.org>
parents:
71151
diff
changeset
|
3173 if (f->f_blockstack[i].b_type == EXCEPT_HANDLER) |
|
419871c62bb3
never retain a generator's caller's exception state on the generator after a yield/return
Benjamin Peterson <benjamin@python.org>
parents:
71151
diff
changeset
|
3174 break; |
|
419871c62bb3
never retain a generator's caller's exception state on the generator after a yield/return
Benjamin Peterson <benjamin@python.org>
parents:
71151
diff
changeset
|
3175 if (i == f->f_iblock) |
|
419871c62bb3
never retain a generator's caller's exception state on the generator after a yield/return
Benjamin Peterson <benjamin@python.org>
parents:
71151
diff
changeset
|
3176 /* We did not create this exception. */ |
|
71159
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3177 restore_and_clear_exc_state(tstate, f); |
|
71157
419871c62bb3
never retain a generator's caller's exception state on the generator after a yield/return
Benjamin Peterson <benjamin@python.org>
parents:
71151
diff
changeset
|
3178 else |
|
71159
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3179 swap_exc_state(tstate, f); |
|
71157
419871c62bb3
never retain a generator's caller's exception state on the generator after a yield/return
Benjamin Peterson <benjamin@python.org>
parents:
71151
diff
changeset
|
3180 } |
|
71151
cc7ae81cfe91
restore a generator's caller's exception state both on yield and (last) return
Benjamin Peterson <benjamin@python.org>
parents:
69832
diff
changeset
|
3181 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3182 if (tstate->use_tracing) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3183 if (tstate->c_tracefunc) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3184 if (why == WHY_RETURN || why == WHY_YIELD) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3185 if (call_trace(tstate->c_tracefunc, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3186 tstate->c_traceobj, f, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3187 PyTrace_RETURN, retval)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3188 Py_XDECREF(retval); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3189 retval = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3190 why = WHY_EXCEPTION; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3191 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3192 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3193 else if (why == WHY_EXCEPTION) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3194 call_trace_protected(tstate->c_tracefunc, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3195 tstate->c_traceobj, f, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3196 PyTrace_RETURN, NULL); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3197 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3198 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3199 if (tstate->c_profilefunc) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3200 if (why == WHY_EXCEPTION) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3201 call_trace_protected(tstate->c_profilefunc, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3202 tstate->c_profileobj, f, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3203 PyTrace_RETURN, NULL); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3204 else if (call_trace(tstate->c_profilefunc, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3205 tstate->c_profileobj, f, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3206 PyTrace_RETURN, retval)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3207 Py_XDECREF(retval); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3208 retval = NULL; |
|
68102
e2f96bd29252
Issue #8914: fix various warnings from the Clang static analyzer v254.
Brett Cannon <bcannon@gmail.com>
parents:
68086
diff
changeset
|
3209 /* why = WHY_EXCEPTION; */ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3210 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3211 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3212 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3213 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3214 /* pop frame */ |
|
43410
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
3215 exit_eval_frame: |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3216 Py_LeaveRecursiveCall(); |
|
85046
862ab99ab570
Issue #17934: Add a clear() method to frame objects, to help clean up expensive details (local variables) and break reference cycles.
Antoine Pitrou <solipsis@pitrou.net>
parents:
84727
diff
changeset
|
3217 f->f_executing = 0; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3218 tstate->frame = f->f_back; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3219 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3220 return retval; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
3221 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
3222 |
|
70652
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3223 static void |
|
70940
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3224 format_missing(const char *kind, PyCodeObject *co, PyObject *names) |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3225 { |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3226 int err; |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3227 Py_ssize_t len = PyList_GET_SIZE(names); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3228 PyObject *name_str, *comma, *tail, *tmp; |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3229 |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3230 assert(PyList_CheckExact(names)); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3231 assert(len >= 1); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3232 /* Deal with the joys of natural language. */ |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3233 switch (len) { |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3234 case 1: |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3235 name_str = PyList_GET_ITEM(names, 0); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3236 Py_INCREF(name_str); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3237 break; |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3238 case 2: |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3239 name_str = PyUnicode_FromFormat("%U and %U", |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3240 PyList_GET_ITEM(names, len - 2), |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3241 PyList_GET_ITEM(names, len - 1)); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3242 break; |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3243 default: |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3244 tail = PyUnicode_FromFormat(", %U, and %U", |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3245 PyList_GET_ITEM(names, len - 2), |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3246 PyList_GET_ITEM(names, len - 1)); |
|
77283
2285a82504dc
check return for error
Benjamin Peterson <benjamin@python.org>
parents:
76942
diff
changeset
|
3247 if (tail == NULL) |
|
2285a82504dc
check return for error
Benjamin Peterson <benjamin@python.org>
parents:
76942
diff
changeset
|
3248 return; |
|
70940
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3249 /* Chop off the last two objects in the list. This shouldn't actually |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3250 fail, but we can't be too careful. */ |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3251 err = PyList_SetSlice(names, len - 2, len, NULL); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3252 if (err == -1) { |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3253 Py_DECREF(tail); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3254 return; |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3255 } |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3256 /* Stitch everything up into a nice comma-separated list. */ |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3257 comma = PyUnicode_FromString(", "); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3258 if (comma == NULL) { |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3259 Py_DECREF(tail); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3260 return; |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3261 } |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3262 tmp = PyUnicode_Join(comma, names); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3263 Py_DECREF(comma); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3264 if (tmp == NULL) { |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3265 Py_DECREF(tail); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3266 return; |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3267 } |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3268 name_str = PyUnicode_Concat(tmp, tail); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3269 Py_DECREF(tmp); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3270 Py_DECREF(tail); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3271 break; |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3272 } |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3273 if (name_str == NULL) |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3274 return; |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3275 PyErr_Format(PyExc_TypeError, |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3276 "%U() missing %i required %s argument%s: %U", |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3277 co->co_name, |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3278 len, |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3279 kind, |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3280 len == 1 ? "" : "s", |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3281 name_str); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3282 Py_DECREF(name_str); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3283 } |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3284 |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3285 static void |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3286 missing_arguments(PyCodeObject *co, int missing, int defcount, |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3287 PyObject **fastlocals) |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3288 { |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3289 int i, j = 0; |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3290 int start, end; |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3291 int positional = defcount != -1; |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3292 const char *kind = positional ? "positional" : "keyword-only"; |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3293 PyObject *missing_names; |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3294 |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3295 /* Compute the names of the arguments that are missing. */ |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3296 missing_names = PyList_New(missing); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3297 if (missing_names == NULL) |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3298 return; |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3299 if (positional) { |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3300 start = 0; |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3301 end = co->co_argcount - defcount; |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3302 } |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3303 else { |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3304 start = co->co_argcount; |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3305 end = start + co->co_kwonlyargcount; |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3306 } |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3307 for (i = start; i < end; i++) { |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3308 if (GETLOCAL(i) == NULL) { |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3309 PyObject *raw = PyTuple_GET_ITEM(co->co_varnames, i); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3310 PyObject *name = PyObject_Repr(raw); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3311 if (name == NULL) { |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3312 Py_DECREF(missing_names); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3313 return; |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3314 } |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3315 PyList_SET_ITEM(missing_names, j++, name); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3316 } |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3317 } |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3318 assert(j == missing); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3319 format_missing(kind, co, missing_names); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3320 Py_DECREF(missing_names); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3321 } |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3322 |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3323 static void |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3324 too_many_positional(PyCodeObject *co, int given, int defcount, PyObject **fastlocals) |
|
70652
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3325 { |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3326 int plural; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3327 int kwonly_given = 0; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3328 int i; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3329 PyObject *sig, *kwonly_sig; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3330 |
|
70940
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3331 assert((co->co_flags & CO_VARARGS) == 0); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3332 /* Count missing keyword-only args. */ |
|
70652
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3333 for (i = co->co_argcount; i < co->co_argcount + co->co_kwonlyargcount; i++) |
|
70940
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3334 if (GETLOCAL(i) != NULL) |
|
70652
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3335 kwonly_given++; |
|
70940
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3336 if (defcount) { |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3337 int atleast = co->co_argcount - defcount; |
|
70652
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3338 plural = 1; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3339 sig = PyUnicode_FromFormat("from %d to %d", atleast, co->co_argcount); |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3340 } |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3341 else { |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3342 plural = co->co_argcount != 1; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3343 sig = PyUnicode_FromFormat("%d", co->co_argcount); |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3344 } |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3345 if (sig == NULL) |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3346 return; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3347 if (kwonly_given) { |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3348 const char *format = " positional argument%s (and %d keyword-only argument%s)"; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3349 kwonly_sig = PyUnicode_FromFormat(format, given != 1 ? "s" : "", kwonly_given, |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3350 kwonly_given != 1 ? "s" : ""); |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3351 if (kwonly_sig == NULL) { |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3352 Py_DECREF(sig); |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3353 return; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3354 } |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3355 } |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3356 else { |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3357 /* This will not fail. */ |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3358 kwonly_sig = PyUnicode_FromString(""); |
|
70940
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3359 assert(kwonly_sig != NULL); |
|
70652
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3360 } |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3361 PyErr_Format(PyExc_TypeError, |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3362 "%U() takes %U positional argument%s but %d%U %s given", |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3363 co->co_name, |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3364 sig, |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3365 plural ? "s" : "", |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3366 given, |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3367 kwonly_sig, |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3368 given == 1 && !kwonly_given ? "was" : "were"); |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3369 Py_DECREF(sig); |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3370 Py_DECREF(kwonly_sig); |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3371 } |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3372 |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
3373 /* This is gonna seem *real weird*, but if you put some other code between |
|
32421
485d2ef43419
Patch #966493: Cleanup generator/eval_frame exposure.
Martin v. Löwis <martin@v.loewis.de>
parents:
32412
diff
changeset
|
3374 PyEval_EvalFrame() and PyEval_EvalCodeEx() you will need to adjust |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
3375 the test in the if statements in Misc/gdbinit (pystack and pystackv). */ |
|
31606
fd2103ae6f29
Add pystack definition to Misc/gdbinit with some explanation of its behavior
Skip Montanaro <skip@pobox.com>
parents:
31514
diff
changeset
|
3376 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3377 PyObject * |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
66556
diff
changeset
|
3378 PyEval_EvalCodeEx(PyObject *_co, PyObject *globals, PyObject *locals, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3379 PyObject **args, int argcount, PyObject **kws, int kwcount, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3380 PyObject **defs, int defcount, PyObject *kwdefs, PyObject *closure) |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3381 { |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
66556
diff
changeset
|
3382 PyCodeObject* co = (PyCodeObject*)_co; |
|
85157
e7f6cef7a4cc
Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85046
diff
changeset
|
3383 PyFrameObject *f; |
|
e7f6cef7a4cc
Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85046
diff
changeset
|
3384 PyObject *retval = NULL; |
|
e7f6cef7a4cc
Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85046
diff
changeset
|
3385 PyObject **fastlocals, **freevars; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3386 PyThreadState *tstate = PyThreadState_GET(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3387 PyObject *x, *u; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
3388 int total_args = co->co_argcount + co->co_kwonlyargcount; |
|
70652
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3389 int i; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3390 int n = argcount; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3391 PyObject *kwdict = NULL; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3392 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3393 if (globals == NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3394 PyErr_SetString(PyExc_SystemError, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3395 "PyEval_EvalCodeEx: NULL globals"); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3396 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3397 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3398 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3399 assert(tstate != NULL); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3400 assert(globals != NULL); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3401 f = PyFrame_New(tstate, co, globals, locals); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3402 if (f == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3403 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3404 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3405 fastlocals = f->f_localsplus; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3406 freevars = f->f_localsplus + co->co_nlocals; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3407 |
|
70652
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3408 /* Parse arguments. */ |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3409 if (co->co_flags & CO_VARKEYWORDS) { |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3410 kwdict = PyDict_New(); |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3411 if (kwdict == NULL) |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3412 goto fail; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3413 i = total_args; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3414 if (co->co_flags & CO_VARARGS) |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3415 i++; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3416 SETLOCAL(i, kwdict); |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3417 } |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3418 if (argcount > co->co_argcount) |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3419 n = co->co_argcount; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3420 for (i = 0; i < n; i++) { |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3421 x = args[i]; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3422 Py_INCREF(x); |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3423 SETLOCAL(i, x); |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3424 } |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3425 if (co->co_flags & CO_VARARGS) { |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3426 u = PyTuple_New(argcount - n); |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3427 if (u == NULL) |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3428 goto fail; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3429 SETLOCAL(total_args, u); |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3430 for (i = n; i < argcount; i++) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3431 x = args[i]; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3432 Py_INCREF(x); |
|
70652
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3433 PyTuple_SET_ITEM(u, i-n, x); |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3434 } |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3435 } |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3436 for (i = 0; i < kwcount; i++) { |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3437 PyObject **co_varnames; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3438 PyObject *keyword = kws[2*i]; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3439 PyObject *value = kws[2*i + 1]; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3440 int j; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3441 if (keyword == NULL || !PyUnicode_Check(keyword)) { |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3442 PyErr_Format(PyExc_TypeError, |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3443 "%U() keywords must be strings", |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3444 co->co_name); |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3445 goto fail; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3446 } |
|
70652
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3447 /* Speed hack: do raw pointer compares. As names are |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3448 normally interned this should almost always hit. */ |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3449 co_varnames = ((PyTupleObject *)(co->co_varnames))->ob_item; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3450 for (j = 0; j < total_args; j++) { |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3451 PyObject *nm = co_varnames[j]; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3452 if (nm == keyword) |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3453 goto kw_found; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3454 } |
|
70652
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3455 /* Slow fallback, just in case */ |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3456 for (j = 0; j < total_args; j++) { |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3457 PyObject *nm = co_varnames[j]; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3458 int cmp = PyObject_RichCompareBool( |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3459 keyword, nm, Py_EQ); |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3460 if (cmp > 0) |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3461 goto kw_found; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3462 else if (cmp < 0) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3463 goto fail; |
|
70652
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3464 } |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3465 if (j >= total_args && kwdict == NULL) { |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3466 PyErr_Format(PyExc_TypeError, |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3467 "%U() got an unexpected " |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3468 "keyword argument '%S'", |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3469 co->co_name, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3470 keyword); |
|
70652
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3471 goto fail; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3472 } |
|
84726
13d5b245ca14
Add missing check of PyDict_SetItem()'s return value in PyEval_EvalCodeEx()
Christian Heimes <christian@cheimes.de>
parents:
83772
diff
changeset
|
3473 if (PyDict_SetItem(kwdict, keyword, value) == -1) { |
|
13d5b245ca14
Add missing check of PyDict_SetItem()'s return value in PyEval_EvalCodeEx()
Christian Heimes <christian@cheimes.de>
parents:
83772
diff
changeset
|
3474 goto fail; |
|
13d5b245ca14
Add missing check of PyDict_SetItem()'s return value in PyEval_EvalCodeEx()
Christian Heimes <christian@cheimes.de>
parents:
83772
diff
changeset
|
3475 } |
|
70652
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3476 continue; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3477 kw_found: |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3478 if (GETLOCAL(j) != NULL) { |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3479 PyErr_Format(PyExc_TypeError, |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3480 "%U() got multiple " |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3481 "values for argument '%S'", |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3482 co->co_name, |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3483 keyword); |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3484 goto fail; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3485 } |
|
70652
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3486 Py_INCREF(value); |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3487 SETLOCAL(j, value); |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3488 } |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3489 if (argcount > co->co_argcount && !(co->co_flags & CO_VARARGS)) { |
|
70940
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3490 too_many_positional(co, argcount, defcount, fastlocals); |
|
70652
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3491 goto fail; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3492 } |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3493 if (argcount < co->co_argcount) { |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3494 int m = co->co_argcount - defcount; |
|
70940
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3495 int missing = 0; |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3496 for (i = argcount; i < m; i++) |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3497 if (GETLOCAL(i) == NULL) |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3498 missing++; |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3499 if (missing) { |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3500 missing_arguments(co, missing, defcount, fastlocals); |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3501 goto fail; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3502 } |
|
70652
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3503 if (n > m) |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3504 i = n - m; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3505 else |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3506 i = 0; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3507 for (; i < defcount; i++) { |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3508 if (GETLOCAL(m+i) == NULL) { |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3509 PyObject *def = defs[i]; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3510 Py_INCREF(def); |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3511 SETLOCAL(m+i, def); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3512 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3513 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3514 } |
|
70652
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3515 if (co->co_kwonlyargcount > 0) { |
|
70940
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3516 int missing = 0; |
|
70652
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3517 for (i = co->co_argcount; i < total_args; i++) { |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3518 PyObject *name; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3519 if (GETLOCAL(i) != NULL) |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3520 continue; |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3521 name = PyTuple_GET_ITEM(co->co_varnames, i); |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3522 if (kwdefs != NULL) { |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3523 PyObject *def = PyDict_GetItem(kwdefs, name); |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3524 if (def) { |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3525 Py_INCREF(def); |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3526 SETLOCAL(i, def); |
|
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3527 continue; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3528 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3529 } |
|
70940
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3530 missing++; |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3531 } |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3532 if (missing) { |
|
52744a5a9260
give the names of missing positional or keyword-only arguments (closes #12356)
Benjamin Peterson <benjamin@python.org>
parents:
70652
diff
changeset
|
3533 missing_arguments(co, missing, -1, fastlocals); |
|
70652
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3534 goto fail; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3535 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3536 } |
|
70652
44d46d74ef4f
greatly improve argument parsing error messages (closes #12265)
Benjamin Peterson <benjamin@python.org>
parents:
69833
diff
changeset
|
3537 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3538 /* Allocate and initialize storage for cell vars, and copy free |
|
70987
c5b0585624ef
map cells to arg slots at code creation time (closes #12399)
Benjamin Peterson <benjamin@python.org>
parents:
70940
diff
changeset
|
3539 vars into frame. */ |
|
c5b0585624ef
map cells to arg slots at code creation time (closes #12399)
Benjamin Peterson <benjamin@python.org>
parents:
70940
diff
changeset
|
3540 for (i = 0; i < PyTuple_GET_SIZE(co->co_cellvars); ++i) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3541 PyObject *c; |
|
70987
c5b0585624ef
map cells to arg slots at code creation time (closes #12399)
Benjamin Peterson <benjamin@python.org>
parents:
70940
diff
changeset
|
3542 int arg; |
|
c5b0585624ef
map cells to arg slots at code creation time (closes #12399)
Benjamin Peterson <benjamin@python.org>
parents:
70940
diff
changeset
|
3543 /* Possibly account for the cell variable being an argument. */ |
|
c5b0585624ef
map cells to arg slots at code creation time (closes #12399)
Benjamin Peterson <benjamin@python.org>
parents:
70940
diff
changeset
|
3544 if (co->co_cell2arg != NULL && |
|
83772
2b4b289c1abb
when arguments are cells clear the locals slot (backport of #17927)
Benjamin Peterson <benjamin@python.org>
parents:
83455
diff
changeset
|
3545 (arg = co->co_cell2arg[i]) != CO_CELL_NOT_AN_ARG) { |
|
70987
c5b0585624ef
map cells to arg slots at code creation time (closes #12399)
Benjamin Peterson <benjamin@python.org>
parents:
70940
diff
changeset
|
3546 c = PyCell_New(GETLOCAL(arg)); |
|
83772
2b4b289c1abb
when arguments are cells clear the locals slot (backport of #17927)
Benjamin Peterson <benjamin@python.org>
parents:
83455
diff
changeset
|
3547 /* Clear the local copy. */ |
|
2b4b289c1abb
when arguments are cells clear the locals slot (backport of #17927)
Benjamin Peterson <benjamin@python.org>
parents:
83455
diff
changeset
|
3548 SETLOCAL(arg, NULL); |
|
2b4b289c1abb
when arguments are cells clear the locals slot (backport of #17927)
Benjamin Peterson <benjamin@python.org>
parents:
83455
diff
changeset
|
3549 } |
|
2b4b289c1abb
when arguments are cells clear the locals slot (backport of #17927)
Benjamin Peterson <benjamin@python.org>
parents:
83455
diff
changeset
|
3550 else { |
|
70987
c5b0585624ef
map cells to arg slots at code creation time (closes #12399)
Benjamin Peterson <benjamin@python.org>
parents:
70940
diff
changeset
|
3551 c = PyCell_New(NULL); |
|
83772
2b4b289c1abb
when arguments are cells clear the locals slot (backport of #17927)
Benjamin Peterson <benjamin@python.org>
parents:
83455
diff
changeset
|
3552 } |
|
70987
c5b0585624ef
map cells to arg slots at code creation time (closes #12399)
Benjamin Peterson <benjamin@python.org>
parents:
70940
diff
changeset
|
3553 if (c == NULL) |
|
c5b0585624ef
map cells to arg slots at code creation time (closes #12399)
Benjamin Peterson <benjamin@python.org>
parents:
70940
diff
changeset
|
3554 goto fail; |
|
c5b0585624ef
map cells to arg slots at code creation time (closes #12399)
Benjamin Peterson <benjamin@python.org>
parents:
70940
diff
changeset
|
3555 SETLOCAL(co->co_nlocals + i, c); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3556 } |
|
70987
c5b0585624ef
map cells to arg slots at code creation time (closes #12399)
Benjamin Peterson <benjamin@python.org>
parents:
70940
diff
changeset
|
3557 for (i = 0; i < PyTuple_GET_SIZE(co->co_freevars); ++i) { |
|
c5b0585624ef
map cells to arg slots at code creation time (closes #12399)
Benjamin Peterson <benjamin@python.org>
parents:
70940
diff
changeset
|
3558 PyObject *o = PyTuple_GET_ITEM(closure, i); |
|
c5b0585624ef
map cells to arg slots at code creation time (closes #12399)
Benjamin Peterson <benjamin@python.org>
parents:
70940
diff
changeset
|
3559 Py_INCREF(o); |
|
c5b0585624ef
map cells to arg slots at code creation time (closes #12399)
Benjamin Peterson <benjamin@python.org>
parents:
70940
diff
changeset
|
3560 freevars[PyTuple_GET_SIZE(co->co_cellvars) + i] = o; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3561 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3562 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3563 if (co->co_flags & CO_GENERATOR) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3564 /* Don't need to keep the reference to f_back, it will be set |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3565 * when the generator is resumed. */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3566 Py_XDECREF(f->f_back); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3567 f->f_back = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3568 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3569 PCALL(PCALL_GENERATOR); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3570 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3571 /* Create a new generator that owns the ready to run frame |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3572 * and return that as the value. */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3573 return PyGen_New(f); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3574 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3575 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3576 retval = PyEval_EvalFrameEx(f,0); |
|
43410
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
3577 |
|
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
3578 fail: /* Jump here from prelude on failure */ |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3579 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3580 /* decref'ing the frame can cause __del__ methods to get invoked, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3581 which can call back into Python. While we're done with the |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3582 current Python frame (f), the associated C stack is still in use, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3583 so recursion_depth must be boosted for the duration. |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3584 */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3585 assert(tstate != NULL); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3586 ++tstate->recursion_depth; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3587 Py_DECREF(f); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3588 --tstate->recursion_depth; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3589 return retval; |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3590 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3591 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3592 |
|
54889
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
3593 static PyObject * |
|
74578
7d96679c5d46
use the static identifier api for looking up special methods
Benjamin Peterson <benjamin@python.org>
parents:
74367
diff
changeset
|
3594 special_lookup(PyObject *o, _Py_Identifier *id) |
|
54889
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
3595 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
3596 PyObject *res; |
|
74578
7d96679c5d46
use the static identifier api for looking up special methods
Benjamin Peterson <benjamin@python.org>
parents:
74367
diff
changeset
|
3597 res = _PyObject_LookupSpecial(o, id); |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
3598 if (res == NULL && !PyErr_Occurred()) { |
|
74578
7d96679c5d46
use the static identifier api for looking up special methods
Benjamin Peterson <benjamin@python.org>
parents:
74367
diff
changeset
|
3599 PyErr_SetObject(PyExc_AttributeError, id->object); |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
3600 return NULL; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
3601 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
3602 return res; |
|
54889
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
3603 } |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
3604 |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
3605 |
|
71159
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3606 /* These 3 functions deal with the exception state of generators. */ |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3607 |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3608 static void |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3609 save_exc_state(PyThreadState *tstate, PyFrameObject *f) |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3610 { |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3611 PyObject *type, *value, *traceback; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3612 Py_XINCREF(tstate->exc_type); |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3613 Py_XINCREF(tstate->exc_value); |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3614 Py_XINCREF(tstate->exc_traceback); |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3615 type = f->f_exc_type; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3616 value = f->f_exc_value; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3617 traceback = f->f_exc_traceback; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3618 f->f_exc_type = tstate->exc_type; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3619 f->f_exc_value = tstate->exc_value; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3620 f->f_exc_traceback = tstate->exc_traceback; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3621 Py_XDECREF(type); |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3622 Py_XDECREF(value); |
|
72605
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
3623 Py_XDECREF(traceback); |
|
71159
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3624 } |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3625 |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3626 static void |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3627 swap_exc_state(PyThreadState *tstate, PyFrameObject *f) |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3628 { |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3629 PyObject *tmp; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3630 tmp = tstate->exc_type; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3631 tstate->exc_type = f->f_exc_type; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3632 f->f_exc_type = tmp; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3633 tmp = tstate->exc_value; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3634 tstate->exc_value = f->f_exc_value; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3635 f->f_exc_value = tmp; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3636 tmp = tstate->exc_traceback; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3637 tstate->exc_traceback = f->f_exc_traceback; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3638 f->f_exc_traceback = tmp; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3639 } |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3640 |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3641 static void |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3642 restore_and_clear_exc_state(PyThreadState *tstate, PyFrameObject *f) |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3643 { |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3644 PyObject *type, *value, *tb; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3645 type = tstate->exc_type; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3646 value = tstate->exc_value; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3647 tb = tstate->exc_traceback; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3648 tstate->exc_type = f->f_exc_type; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3649 tstate->exc_value = f->f_exc_value; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3650 tstate->exc_traceback = f->f_exc_traceback; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3651 f->f_exc_type = NULL; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3652 f->f_exc_value = NULL; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3653 f->f_exc_traceback = NULL; |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3654 Py_XDECREF(type); |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3655 Py_XDECREF(value); |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3656 Py_XDECREF(tb); |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3657 } |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3658 |
|
95784a617d05
convert generator exc state functions into static functions
Benjamin Peterson <benjamin@python.org>
parents:
71158
diff
changeset
|
3659 |
|
4667
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
3660 /* Logic for the raise statement (too complicated for inlining). |
|
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
3661 This *consumes* a reference count to each of its arguments. */ |
| 79693 | 3662 static int |
|
43102
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
3663 do_raise(PyObject *exc, PyObject *cause) |
|
4667
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
3664 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3665 PyObject *type = NULL, *value = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3666 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3667 if (exc == NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3668 /* Reraise */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3669 PyThreadState *tstate = PyThreadState_GET(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3670 PyObject *tb; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3671 type = tstate->exc_type; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3672 value = tstate->exc_value; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3673 tb = tstate->exc_traceback; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3674 if (type == Py_None) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3675 PyErr_SetString(PyExc_RuntimeError, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3676 "No active exception to reraise"); |
| 79693 | 3677 return 0; |
| 3678 } | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3679 Py_XINCREF(type); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3680 Py_XINCREF(value); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3681 Py_XINCREF(tb); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3682 PyErr_Restore(type, value, tb); |
| 79693 | 3683 return 1; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3684 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3685 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3686 /* We support the following forms of raise: |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3687 raise |
|
43102
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
3688 raise <instance> |
|
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
3689 raise <type> */ |
|
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
3690 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3691 if (PyExceptionClass_Check(exc)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3692 type = exc; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3693 value = PyObject_CallObject(exc, NULL); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3694 if (value == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3695 goto raise_error; |
|
71349
8d05f697acd4
catch nasty exception classes with __new__ that doesn't return a exception (closes #11627)
Benjamin Peterson <benjamin@python.org>
parents:
71157
diff
changeset
|
3696 if (!PyExceptionInstance_Check(value)) { |
|
8d05f697acd4
catch nasty exception classes with __new__ that doesn't return a exception (closes #11627)
Benjamin Peterson <benjamin@python.org>
parents:
71157
diff
changeset
|
3697 PyErr_Format(PyExc_TypeError, |
|
8d05f697acd4
catch nasty exception classes with __new__ that doesn't return a exception (closes #11627)
Benjamin Peterson <benjamin@python.org>
parents:
71157
diff
changeset
|
3698 "calling %R should have returned an instance of " |
|
8d05f697acd4
catch nasty exception classes with __new__ that doesn't return a exception (closes #11627)
Benjamin Peterson <benjamin@python.org>
parents:
71157
diff
changeset
|
3699 "BaseException, not %R", |
|
8d05f697acd4
catch nasty exception classes with __new__ that doesn't return a exception (closes #11627)
Benjamin Peterson <benjamin@python.org>
parents:
71157
diff
changeset
|
3700 type, Py_TYPE(value)); |
|
8d05f697acd4
catch nasty exception classes with __new__ that doesn't return a exception (closes #11627)
Benjamin Peterson <benjamin@python.org>
parents:
71157
diff
changeset
|
3701 goto raise_error; |
|
8d05f697acd4
catch nasty exception classes with __new__ that doesn't return a exception (closes #11627)
Benjamin Peterson <benjamin@python.org>
parents:
71157
diff
changeset
|
3702 } |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3703 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3704 else if (PyExceptionInstance_Check(exc)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3705 value = exc; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3706 type = PyExceptionInstance_Class(exc); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3707 Py_INCREF(type); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3708 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3709 else { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3710 /* Not something you can raise. You get an exception |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3711 anyway, just not what you specified :-) */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3712 Py_DECREF(exc); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3713 PyErr_SetString(PyExc_TypeError, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3714 "exceptions must derive from BaseException"); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3715 goto raise_error; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3716 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3717 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3718 if (cause) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3719 PyObject *fixed_cause; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3720 if (PyExceptionClass_Check(cause)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3721 fixed_cause = PyObject_CallObject(cause, NULL); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3722 if (fixed_cause == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3723 goto raise_error; |
|
76942
b0eb7d2a9542
PEP 415: Implement suppression of __context__ display with an exception attribute
Benjamin Peterson <benjamin@python.org>
parents:
76567
diff
changeset
|
3724 Py_DECREF(cause); |
|
b0eb7d2a9542
PEP 415: Implement suppression of __context__ display with an exception attribute
Benjamin Peterson <benjamin@python.org>
parents:
76567
diff
changeset
|
3725 } |
|
b0eb7d2a9542
PEP 415: Implement suppression of __context__ display with an exception attribute
Benjamin Peterson <benjamin@python.org>
parents:
76567
diff
changeset
|
3726 else if (PyExceptionInstance_Check(cause)) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3727 fixed_cause = cause; |
|
76942
b0eb7d2a9542
PEP 415: Implement suppression of __context__ display with an exception attribute
Benjamin Peterson <benjamin@python.org>
parents:
76567
diff
changeset
|
3728 } |
|
b0eb7d2a9542
PEP 415: Implement suppression of __context__ display with an exception attribute
Benjamin Peterson <benjamin@python.org>
parents:
76567
diff
changeset
|
3729 else if (cause == Py_None) { |
|
b0eb7d2a9542
PEP 415: Implement suppression of __context__ display with an exception attribute
Benjamin Peterson <benjamin@python.org>
parents:
76567
diff
changeset
|
3730 Py_DECREF(cause); |
|
b0eb7d2a9542
PEP 415: Implement suppression of __context__ display with an exception attribute
Benjamin Peterson <benjamin@python.org>
parents:
76567
diff
changeset
|
3731 fixed_cause = NULL; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3732 } |
|
76942
b0eb7d2a9542
PEP 415: Implement suppression of __context__ display with an exception attribute
Benjamin Peterson <benjamin@python.org>
parents:
76567
diff
changeset
|
3733 else { |
|
b0eb7d2a9542
PEP 415: Implement suppression of __context__ display with an exception attribute
Benjamin Peterson <benjamin@python.org>
parents:
76567
diff
changeset
|
3734 PyErr_SetString(PyExc_TypeError, |
|
b0eb7d2a9542
PEP 415: Implement suppression of __context__ display with an exception attribute
Benjamin Peterson <benjamin@python.org>
parents:
76567
diff
changeset
|
3735 "exception causes must derive from " |
|
b0eb7d2a9542
PEP 415: Implement suppression of __context__ display with an exception attribute
Benjamin Peterson <benjamin@python.org>
parents:
76567
diff
changeset
|
3736 "BaseException"); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3737 goto raise_error; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3738 } |
|
76942
b0eb7d2a9542
PEP 415: Implement suppression of __context__ display with an exception attribute
Benjamin Peterson <benjamin@python.org>
parents:
76567
diff
changeset
|
3739 PyException_SetCause(value, fixed_cause); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3740 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3741 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3742 PyErr_SetObject(type, value); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3743 /* PyErr_SetObject incref's its arguments */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3744 Py_XDECREF(value); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3745 Py_XDECREF(type); |
| 79693 | 3746 return 0; |
|
43102
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
3747 |
|
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
3748 raise_error: |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3749 Py_XDECREF(value); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3750 Py_XDECREF(type); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3751 Py_XDECREF(cause); |
| 79693 | 3752 return 0; |
|
4667
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
3753 } |
|
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
3754 |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3755 /* Iterate v argcnt times and store the results on the stack (via decreasing |
|
41699
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3756 sp). Return 1 for success, 0 if error. |
|
48574
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3757 |
|
41699
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3758 If argcntafter == -1, do a simple unpack. If it is >= 0, do an unpack |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3759 with a variable target. |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3760 */ |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3761 |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3762 static int |
|
41699
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3763 unpack_iterable(PyObject *v, int argcnt, int argcntafter, PyObject **sp) |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3764 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3765 int i = 0, j = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3766 Py_ssize_t ll = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3767 PyObject *it; /* iter(v) */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3768 PyObject *w; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3769 PyObject *l = NULL; /* variable list */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3770 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3771 assert(v != NULL); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3772 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3773 it = PyObject_GetIter(v); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3774 if (it == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3775 goto Error; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3776 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3777 for (; i < argcnt; i++) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3778 w = PyIter_Next(it); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3779 if (w == NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3780 /* Iterator done, via error or exhaustion. */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3781 if (!PyErr_Occurred()) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3782 PyErr_Format(PyExc_ValueError, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3783 "need more than %d value%s to unpack", |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3784 i, i == 1 ? "" : "s"); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3785 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3786 goto Error; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3787 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3788 *--sp = w; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3789 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3790 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3791 if (argcntafter == -1) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3792 /* We better have exhausted the iterator now. */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3793 w = PyIter_Next(it); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3794 if (w == NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3795 if (PyErr_Occurred()) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3796 goto Error; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3797 Py_DECREF(it); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3798 return 1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3799 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3800 Py_DECREF(w); |
|
62914
983e2c0bf8dc
#3071: tell how many values were expected when unpacking too many.
Georg Brandl <georg@python.org>
parents:
62492
diff
changeset
|
3801 PyErr_Format(PyExc_ValueError, "too many values to unpack " |
|
983e2c0bf8dc
#3071: tell how many values were expected when unpacking too many.
Georg Brandl <georg@python.org>
parents:
62492
diff
changeset
|
3802 "(expected %d)", argcnt); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3803 goto Error; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3804 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3805 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3806 l = PySequence_List(it); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3807 if (l == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3808 goto Error; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3809 *--sp = l; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3810 i++; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3811 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3812 ll = PyList_GET_SIZE(l); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3813 if (ll < argcntafter) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3814 PyErr_Format(PyExc_ValueError, "need more than %zd values to unpack", |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3815 argcnt + ll); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3816 goto Error; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3817 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3818 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3819 /* Pop the "after-variable" args off the list. */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3820 for (j = argcntafter; j > 0; j--, i++) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3821 *--sp = PyList_GET_ITEM(l, ll - j); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3822 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3823 /* Resize the list. */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3824 Py_SIZE(l) = ll - argcntafter; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3825 Py_DECREF(it); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3826 return 1; |
|
41699
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3827 |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3828 Error: |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3829 for (; i > 0; i--, sp++) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3830 Py_DECREF(*sp); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3831 Py_XDECREF(it); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3832 return 0; |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3833 } |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3834 |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3835 |
| 567 | 3836 #ifdef LLTRACE |
| 86 | 3837 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3838 prtrace(PyObject *v, char *str) |
| 69 | 3839 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3840 printf("%s ", str); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3841 if (PyObject_Print(v, stdout, 0) != 0) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3842 PyErr_Clear(); /* Don't know what else to do */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3843 printf("\n"); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3844 return 1; |
| 69 | 3845 } |
| 86 | 3846 #endif |
| 69 | 3847 |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3848 static void |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3849 call_exc_trace(Py_tracefunc func, PyObject *self, PyFrameObject *f) |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3850 { |
|
84529
4f730c045f5f
Issue #18408: Fix call_exc_trace(): if the traceback is NULL, use None when
Victor Stinner <vstinner@wyplay.com>
parents:
84513
diff
changeset
|
3851 PyObject *type, *value, *traceback, *orig_traceback, *arg; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3852 int err; |
|
87407
8f556ee0f6ba
Fix refleak introduced by 4f730c045f5f (issue #18408) and unveiled by 95eea8624d05 (issue #16596).
Antoine Pitrou <solipsis@pitrou.net>
parents:
87318
diff
changeset
|
3853 PyErr_Fetch(&type, &value, &orig_traceback); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3854 if (value == NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3855 value = Py_None; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3856 Py_INCREF(value); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3857 } |
|
87407
8f556ee0f6ba
Fix refleak introduced by 4f730c045f5f (issue #18408) and unveiled by 95eea8624d05 (issue #16596).
Antoine Pitrou <solipsis@pitrou.net>
parents:
87318
diff
changeset
|
3858 PyErr_NormalizeException(&type, &value, &orig_traceback); |
|
8f556ee0f6ba
Fix refleak introduced by 4f730c045f5f (issue #18408) and unveiled by 95eea8624d05 (issue #16596).
Antoine Pitrou <solipsis@pitrou.net>
parents:
87318
diff
changeset
|
3859 traceback = (orig_traceback != NULL) ? orig_traceback : Py_None; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3860 arg = PyTuple_Pack(3, type, value, traceback); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3861 if (arg == NULL) { |
|
87407
8f556ee0f6ba
Fix refleak introduced by 4f730c045f5f (issue #18408) and unveiled by 95eea8624d05 (issue #16596).
Antoine Pitrou <solipsis@pitrou.net>
parents:
87318
diff
changeset
|
3862 PyErr_Restore(type, value, orig_traceback); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3863 return; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3864 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3865 err = call_trace(func, self, f, PyTrace_EXCEPTION, arg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3866 Py_DECREF(arg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3867 if (err == 0) |
|
84529
4f730c045f5f
Issue #18408: Fix call_exc_trace(): if the traceback is NULL, use None when
Victor Stinner <vstinner@wyplay.com>
parents:
84513
diff
changeset
|
3868 PyErr_Restore(type, value, orig_traceback); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3869 else { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3870 Py_XDECREF(type); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3871 Py_XDECREF(value); |
|
84529
4f730c045f5f
Issue #18408: Fix call_exc_trace(): if the traceback is NULL, use None when
Victor Stinner <vstinner@wyplay.com>
parents:
84513
diff
changeset
|
3872 Py_XDECREF(orig_traceback); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3873 } |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3874 } |
|
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3875 |
|
43840
73c8e27eb9ce
Correction for issue1265 (pdb bug with "with" statement).
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43815
diff
changeset
|
3876 static int |
|
20257
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3877 call_trace_protected(Py_tracefunc func, PyObject *obj, PyFrameObject *frame, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3878 int what, PyObject *arg) |
|
20257
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3879 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3880 PyObject *type, *value, *traceback; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3881 int err; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3882 PyErr_Fetch(&type, &value, &traceback); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3883 err = call_trace(func, obj, frame, what, arg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3884 if (err == 0) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3885 { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3886 PyErr_Restore(type, value, traceback); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3887 return 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3888 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3889 else { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3890 Py_XDECREF(type); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3891 Py_XDECREF(value); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3892 Py_XDECREF(traceback); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3893 return -1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3894 } |
|
20257
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3895 } |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3896 |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3897 static int |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3898 call_trace(Py_tracefunc func, PyObject *obj, PyFrameObject *frame, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3899 int what, PyObject *arg) |
| 567 | 3900 { |
|
85157
e7f6cef7a4cc
Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85046
diff
changeset
|
3901 PyThreadState *tstate = frame->f_tstate; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3902 int result; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3903 if (tstate->tracing) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3904 return 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3905 tstate->tracing++; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3906 tstate->use_tracing = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3907 result = func(obj, frame, what, arg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3908 tstate->use_tracing = ((tstate->c_tracefunc != NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3909 || (tstate->c_profilefunc != NULL)); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3910 tstate->tracing--; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3911 return result; |
| 567 | 3912 } |
| 3913 | |
|
28556
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3914 PyObject * |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3915 _PyEval_CallTracing(PyObject *func, PyObject *args) |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3916 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3917 PyFrameObject *frame = PyEval_GetFrame(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3918 PyThreadState *tstate = frame->f_tstate; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3919 int save_tracing = tstate->tracing; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3920 int save_use_tracing = tstate->use_tracing; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3921 PyObject *result; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3922 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3923 tstate->tracing = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3924 tstate->use_tracing = ((tstate->c_tracefunc != NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3925 || (tstate->c_profilefunc != NULL)); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3926 result = PyObject_Call(func, args, NULL); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3927 tstate->tracing = save_tracing; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3928 tstate->use_tracing = save_use_tracing; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3929 return result; |
|
28556
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3930 } |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3931 |
|
55372
79718ee03986
Merged revisions 72487-72488,72879 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54909
diff
changeset
|
3932 /* See Objects/lnotab_notes.txt for a description of how tracing works. */ |
|
26110
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
3933 static int |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
3934 maybe_call_line_trace(Py_tracefunc func, PyObject *obj, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3935 PyFrameObject *frame, int *instr_lb, int *instr_ub, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3936 int *instr_prev) |
| 24844 | 3937 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3938 int result = 0; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
3939 int line = frame->f_lineno; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3940 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3941 /* If the last instruction executed isn't in the current |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
3942 instruction window, reset the window. |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3943 */ |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
3944 if (frame->f_lasti < *instr_lb || frame->f_lasti >= *instr_ub) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3945 PyAddrPair bounds; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
3946 line = _PyCode_CheckLineNumber(frame->f_code, frame->f_lasti, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
3947 &bounds); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3948 *instr_lb = bounds.ap_lower; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3949 *instr_ub = bounds.ap_upper; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3950 } |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
3951 /* If the last instruction falls at the start of a line or if |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
3952 it represents a jump backwards, update the frame's line |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
3953 number and call the trace function. */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
3954 if (frame->f_lasti == *instr_lb || frame->f_lasti < *instr_prev) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61186
diff
changeset
|
3955 frame->f_lineno = line; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3956 result = call_trace(func, obj, frame, PyTrace_LINE, Py_None); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3957 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3958 *instr_prev = frame->f_lasti; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3959 return result; |
| 24844 | 3960 } |
| 3961 | |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3962 void |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3963 PyEval_SetProfile(Py_tracefunc func, PyObject *arg) |
|
18136
4cb34314bd97
Instead of initializing & interning the strings passed to the profile
Fred Drake <fdrake@acm.org>
parents:
18128
diff
changeset
|
3964 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3965 PyThreadState *tstate = PyThreadState_GET(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3966 PyObject *temp = tstate->c_profileobj; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3967 Py_XINCREF(arg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3968 tstate->c_profilefunc = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3969 tstate->c_profileobj = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3970 /* Must make sure that tracing is not ignored if 'temp' is freed */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3971 tstate->use_tracing = tstate->c_tracefunc != NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3972 Py_XDECREF(temp); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3973 tstate->c_profilefunc = func; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3974 tstate->c_profileobj = arg; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3975 /* Flag that tracing or profiling is turned on */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3976 tstate->use_tracing = (func != NULL) || (tstate->c_tracefunc != NULL); |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3977 } |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3978 |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3979 void |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3980 PyEval_SetTrace(Py_tracefunc func, PyObject *arg) |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3981 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3982 PyThreadState *tstate = PyThreadState_GET(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3983 PyObject *temp = tstate->c_traceobj; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3984 _Py_TracingPossible += (func != NULL) - (tstate->c_tracefunc != NULL); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3985 Py_XINCREF(arg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3986 tstate->c_tracefunc = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3987 tstate->c_traceobj = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3988 /* Must make sure that profiling is not ignored if 'temp' is freed */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3989 tstate->use_tracing = tstate->c_profilefunc != NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3990 Py_XDECREF(temp); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3991 tstate->c_tracefunc = func; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3992 tstate->c_traceobj = arg; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3993 /* Flag that tracing or profiling is turned on */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3994 tstate->use_tracing = ((func != NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
3995 || (tstate->c_profilefunc != NULL)); |
|
18136
4cb34314bd97
Instead of initializing & interning the strings passed to the profile
Fred Drake <fdrake@acm.org>
parents:
18128
diff
changeset
|
3996 } |
|
4cb34314bd97
Instead of initializing & interning the strings passed to the profile
Fred Drake <fdrake@acm.org>
parents:
18128
diff
changeset
|
3997 |
| 5368 | 3998 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3999 PyEval_GetBuiltins(void) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
4000 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4001 PyFrameObject *current_frame = PyEval_GetFrame(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4002 if (current_frame == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4003 return PyThreadState_GET()->interp->builtins; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4004 else |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4005 return current_frame->f_builtins; |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
4006 } |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
4007 |
| 5368 | 4008 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4009 PyEval_GetLocals(void) |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
4010 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4011 PyFrameObject *current_frame = PyEval_GetFrame(); |
|
86715
4ef4578db38a
Issue #18408: Add a new PyFrame_FastToLocalsWithError() function to handle
Victor Stinner <victor.stinner@gmail.com>
parents:
86185
diff
changeset
|
4012 if (current_frame == NULL) { |
|
4ef4578db38a
Issue #18408: Add a new PyFrame_FastToLocalsWithError() function to handle
Victor Stinner <victor.stinner@gmail.com>
parents:
86185
diff
changeset
|
4013 PyErr_SetString(PyExc_SystemError, "frame does not exist"); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4014 return NULL; |
|
86715
4ef4578db38a
Issue #18408: Add a new PyFrame_FastToLocalsWithError() function to handle
Victor Stinner <victor.stinner@gmail.com>
parents:
86185
diff
changeset
|
4015 } |
|
4ef4578db38a
Issue #18408: Add a new PyFrame_FastToLocalsWithError() function to handle
Victor Stinner <victor.stinner@gmail.com>
parents:
86185
diff
changeset
|
4016 |
|
4ef4578db38a
Issue #18408: Add a new PyFrame_FastToLocalsWithError() function to handle
Victor Stinner <victor.stinner@gmail.com>
parents:
86185
diff
changeset
|
4017 if (PyFrame_FastToLocalsWithError(current_frame) < 0) |
|
4ef4578db38a
Issue #18408: Add a new PyFrame_FastToLocalsWithError() function to handle
Victor Stinner <victor.stinner@gmail.com>
parents:
86185
diff
changeset
|
4018 return NULL; |
|
4ef4578db38a
Issue #18408: Add a new PyFrame_FastToLocalsWithError() function to handle
Victor Stinner <victor.stinner@gmail.com>
parents:
86185
diff
changeset
|
4019 |
|
4ef4578db38a
Issue #18408: Add a new PyFrame_FastToLocalsWithError() function to handle
Victor Stinner <victor.stinner@gmail.com>
parents:
86185
diff
changeset
|
4020 assert(current_frame->f_locals != NULL); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4021 return current_frame->f_locals; |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
4022 } |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
4023 |
| 5368 | 4024 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4025 PyEval_GetGlobals(void) |
| 69 | 4026 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4027 PyFrameObject *current_frame = PyEval_GetFrame(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4028 if (current_frame == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4029 return NULL; |
|
86715
4ef4578db38a
Issue #18408: Add a new PyFrame_FastToLocalsWithError() function to handle
Victor Stinner <victor.stinner@gmail.com>
parents:
86185
diff
changeset
|
4030 |
|
4ef4578db38a
Issue #18408: Add a new PyFrame_FastToLocalsWithError() function to handle
Victor Stinner <victor.stinner@gmail.com>
parents:
86185
diff
changeset
|
4031 assert(current_frame->f_globals != NULL); |
|
4ef4578db38a
Issue #18408: Add a new PyFrame_FastToLocalsWithError() function to handle
Victor Stinner <victor.stinner@gmail.com>
parents:
86185
diff
changeset
|
4032 return current_frame->f_globals; |
| 69 | 4033 } |
| 4034 | |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
4035 PyFrameObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4036 PyEval_GetFrame(void) |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
4037 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4038 PyThreadState *tstate = PyThreadState_GET(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4039 return _PyThreadState_GetFrame(tstate); |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
4040 } |
|
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
4041 |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
4042 int |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
4043 PyEval_MergeCompilerFlags(PyCompilerFlags *cf) |
|
17124
a8301d4ed2b1
If a code object is compiled with nested scopes, define the CO_NESTED flag.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17114
diff
changeset
|
4044 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4045 PyFrameObject *current_frame = PyEval_GetFrame(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4046 int result = cf->cf_flags != 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4047 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4048 if (current_frame != NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4049 const int codeflags = current_frame->f_code->co_flags; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4050 const int compilerflags = codeflags & PyCF_MASK; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4051 if (compilerflags) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4052 result = 1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4053 cf->cf_flags |= compilerflags; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4054 } |
|
22468
eebae4f60d05
Disable the parser hacks that enabled the "yield" keyword using a future
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22398
diff
changeset
|
4055 #if 0 /* future keyword */ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4056 if (codeflags & CO_GENERATOR_ALLOWED) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4057 result = 1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4058 cf->cf_flags |= CO_GENERATOR_ALLOWED; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4059 } |
|
22468
eebae4f60d05
Disable the parser hacks that enabled the "yield" keyword using a future
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22398
diff
changeset
|
4060 #endif |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4061 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4062 return result; |
|
17124
a8301d4ed2b1
If a code object is compiled with nested scopes, define the CO_NESTED flag.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17114
diff
changeset
|
4063 } |
|
a8301d4ed2b1
If a code object is compiled with nested scopes, define the CO_NESTED flag.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17114
diff
changeset
|
4064 |
| 86 | 4065 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4066 /* External interface to call any callable object. |
|
60130
04e775b33e9e
Merged revisions 79555 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59863
diff
changeset
|
4067 The arg must be a tuple or NULL. The kw must be a dict or NULL. */ |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4068 |
| 5368 | 4069 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4070 PyEval_CallObjectWithKeywords(PyObject *func, PyObject *arg, PyObject *kw) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4071 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4072 PyObject *result; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4073 |
|
84704
48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
Victor Stinner <victor.stinner@gmail.com>
parents:
84648
diff
changeset
|
4074 #ifdef Py_DEBUG |
|
48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
Victor Stinner <victor.stinner@gmail.com>
parents:
84648
diff
changeset
|
4075 /* PyEval_CallObjectWithKeywords() must not be called with an exception |
|
48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
Victor Stinner <victor.stinner@gmail.com>
parents:
84648
diff
changeset
|
4076 set, because it may clear it (directly or indirectly) |
|
48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
Victor Stinner <victor.stinner@gmail.com>
parents:
84648
diff
changeset
|
4077 and so the caller looses its exception */ |
|
48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
Victor Stinner <victor.stinner@gmail.com>
parents:
84648
diff
changeset
|
4078 assert(!PyErr_Occurred()); |
|
48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
Victor Stinner <victor.stinner@gmail.com>
parents:
84648
diff
changeset
|
4079 #endif |
|
48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
Victor Stinner <victor.stinner@gmail.com>
parents:
84648
diff
changeset
|
4080 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4081 if (arg == NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4082 arg = PyTuple_New(0); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4083 if (arg == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4084 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4085 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4086 else if (!PyTuple_Check(arg)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4087 PyErr_SetString(PyExc_TypeError, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4088 "argument list must be a tuple"); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4089 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4090 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4091 else |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4092 Py_INCREF(arg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4093 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4094 if (kw != NULL && !PyDict_Check(kw)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4095 PyErr_SetString(PyExc_TypeError, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4096 "keyword list must be a dictionary"); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4097 Py_DECREF(arg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4098 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4099 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4100 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4101 result = PyObject_Call(func, arg, kw); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4102 Py_DECREF(arg); |
|
84704
48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
Victor Stinner <victor.stinner@gmail.com>
parents:
84648
diff
changeset
|
4103 |
|
48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
Victor Stinner <victor.stinner@gmail.com>
parents:
84648
diff
changeset
|
4104 assert((result != NULL && !PyErr_Occurred()) |
|
48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
Victor Stinner <victor.stinner@gmail.com>
parents:
84648
diff
changeset
|
4105 || (result == NULL && PyErr_Occurred())); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4106 return result; |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4107 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4108 |
|
35999
9541369b0dca
Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35745
diff
changeset
|
4109 const char * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
4110 PyEval_GetFuncName(PyObject *func) |
|
17406
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
4111 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4112 if (PyMethod_Check(func)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4113 return PyEval_GetFuncName(PyMethod_GET_FUNCTION(func)); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4114 else if (PyFunction_Check(func)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4115 return _PyUnicode_AsString(((PyFunctionObject*)func)->func_name); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4116 else if (PyCFunction_Check(func)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4117 return ((PyCFunctionObject*)func)->m_ml->ml_name; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4118 else |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4119 return func->ob_type->tp_name; |
|
17406
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
4120 } |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
4121 |
|
35999
9541369b0dca
Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35745
diff
changeset
|
4122 const char * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
4123 PyEval_GetFuncDesc(PyObject *func) |
|
17406
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
4124 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4125 if (PyMethod_Check(func)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4126 return "()"; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4127 else if (PyFunction_Check(func)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4128 return "()"; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4129 else if (PyCFunction_Check(func)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4130 return "()"; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4131 else |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4132 return " object"; |
|
17406
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
4133 } |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
4134 |
|
26141
6ce9228a3da2
Make private functions static so we don't pollute the namespace
Neal Norwitz <nnorwitz@gmail.com>
parents:
26110
diff
changeset
|
4135 static void |
|
24870
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
4136 err_args(PyObject *func, int flags, int nargs) |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
4137 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4138 if (flags & METH_NOARGS) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4139 PyErr_Format(PyExc_TypeError, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4140 "%.200s() takes no arguments (%d given)", |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4141 ((PyCFunctionObject *)func)->m_ml->ml_name, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4142 nargs); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4143 else |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4144 PyErr_Format(PyExc_TypeError, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4145 "%.200s() takes exactly one argument (%d given)", |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4146 ((PyCFunctionObject *)func)->m_ml->ml_name, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4147 nargs); |
|
24870
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
4148 } |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
4149 |
|
35609
23dda92de993
clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents:
35345
diff
changeset
|
4150 #define C_TRACE(x, call) \ |
|
32409
77913be294b9
Massive performance improvement for C extension and builtin tracing code
Nicholas Bastin <nick.bastin@gmail.com>
parents:
32398
diff
changeset
|
4151 if (tstate->use_tracing && tstate->c_profilefunc) { \ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4152 if (call_trace(tstate->c_profilefunc, \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4153 tstate->c_profileobj, \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4154 tstate->frame, PyTrace_C_CALL, \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4155 func)) { \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4156 x = NULL; \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4157 } \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4158 else { \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4159 x = call; \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4160 if (tstate->c_profilefunc != NULL) { \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4161 if (x == NULL) { \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4162 call_trace_protected(tstate->c_profilefunc, \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4163 tstate->c_profileobj, \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4164 tstate->frame, PyTrace_C_EXCEPTION, \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4165 func); \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4166 /* XXX should pass (type, value, tb) */ \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4167 } else { \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4168 if (call_trace(tstate->c_profilefunc, \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4169 tstate->c_profileobj, \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4170 tstate->frame, PyTrace_C_RETURN, \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4171 func)) { \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4172 Py_DECREF(x); \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4173 x = NULL; \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4174 } \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4175 } \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4176 } \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4177 } \ |
|
32409
77913be294b9
Massive performance improvement for C extension and builtin tracing code
Nicholas Bastin <nick.bastin@gmail.com>
parents:
32398
diff
changeset
|
4178 } else { \ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4179 x = call; \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4180 } |
|
31796
1c117dbb2def
Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31768
diff
changeset
|
4181 |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
4182 static PyObject * |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
4183 call_function(PyObject ***pp_stack, int oparg |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
4184 #ifdef WITH_TSC |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4185 , uint64* pintr0, uint64* pintr1 |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
4186 #endif |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4187 ) |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
4188 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4189 int na = oparg & 0xff; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4190 int nk = (oparg>>8) & 0xff; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4191 int n = na + 2 * nk; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4192 PyObject **pfunc = (*pp_stack) - n - 1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4193 PyObject *func = *pfunc; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4194 PyObject *x, *w; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4195 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4196 /* Always dispatch PyCFunction first, because these are |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4197 presumed to be the most frequent callable object. |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4198 */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4199 if (PyCFunction_Check(func) && nk == 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4200 int flags = PyCFunction_GET_FLAGS(func); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4201 PyThreadState *tstate = PyThreadState_GET(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4202 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4203 PCALL(PCALL_CFUNCTION); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4204 if (flags & (METH_NOARGS | METH_O)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4205 PyCFunction meth = PyCFunction_GET_FUNCTION(func); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4206 PyObject *self = PyCFunction_GET_SELF(func); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4207 if (flags & METH_NOARGS && na == 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4208 C_TRACE(x, (*meth)(self,NULL)); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4209 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4210 else if (flags & METH_O && na == 1) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4211 PyObject *arg = EXT_POP(*pp_stack); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4212 C_TRACE(x, (*meth)(self,arg)); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4213 Py_DECREF(arg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4214 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4215 else { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4216 err_args(func, flags, na); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4217 x = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4218 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4219 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4220 else { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4221 PyObject *callargs; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4222 callargs = load_args(pp_stack, na); |
|
84513
f4311870e329
Issue #18408: Fix call_function() of ceval.c to handle PyTuple_New() failure
Victor Stinner <victor.stinner@gmail.com>
parents:
84445
diff
changeset
|
4223 if (callargs != NULL) { |
|
f4311870e329
Issue #18408: Fix call_function() of ceval.c to handle PyTuple_New() failure
Victor Stinner <victor.stinner@gmail.com>
parents:
84445
diff
changeset
|
4224 READ_TIMESTAMP(*pintr0); |
|
f4311870e329
Issue #18408: Fix call_function() of ceval.c to handle PyTuple_New() failure
Victor Stinner <victor.stinner@gmail.com>
parents:
84445
diff
changeset
|
4225 C_TRACE(x, PyCFunction_Call(func,callargs,NULL)); |
|
f4311870e329
Issue #18408: Fix call_function() of ceval.c to handle PyTuple_New() failure
Victor Stinner <victor.stinner@gmail.com>
parents:
84445
diff
changeset
|
4226 READ_TIMESTAMP(*pintr1); |
|
f4311870e329
Issue #18408: Fix call_function() of ceval.c to handle PyTuple_New() failure
Victor Stinner <victor.stinner@gmail.com>
parents:
84445
diff
changeset
|
4227 Py_XDECREF(callargs); |
|
f4311870e329
Issue #18408: Fix call_function() of ceval.c to handle PyTuple_New() failure
Victor Stinner <victor.stinner@gmail.com>
parents:
84445
diff
changeset
|
4228 } |
|
f4311870e329
Issue #18408: Fix call_function() of ceval.c to handle PyTuple_New() failure
Victor Stinner <victor.stinner@gmail.com>
parents:
84445
diff
changeset
|
4229 else { |
|
f4311870e329
Issue #18408: Fix call_function() of ceval.c to handle PyTuple_New() failure
Victor Stinner <victor.stinner@gmail.com>
parents:
84445
diff
changeset
|
4230 x = NULL; |
|
f4311870e329
Issue #18408: Fix call_function() of ceval.c to handle PyTuple_New() failure
Victor Stinner <victor.stinner@gmail.com>
parents:
84445
diff
changeset
|
4231 } |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4232 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4233 } else { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4234 if (PyMethod_Check(func) && PyMethod_GET_SELF(func) != NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4235 /* optimize access to bound methods */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4236 PyObject *self = PyMethod_GET_SELF(func); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4237 PCALL(PCALL_METHOD); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4238 PCALL(PCALL_BOUND_METHOD); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4239 Py_INCREF(self); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4240 func = PyMethod_GET_FUNCTION(func); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4241 Py_INCREF(func); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4242 Py_DECREF(*pfunc); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4243 *pfunc = self; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4244 na++; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4245 n++; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4246 } else |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4247 Py_INCREF(func); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4248 READ_TIMESTAMP(*pintr0); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4249 if (PyFunction_Check(func)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4250 x = fast_function(func, pp_stack, n, na, nk); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4251 else |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4252 x = do_call(func, pp_stack, na, nk); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4253 READ_TIMESTAMP(*pintr1); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4254 Py_DECREF(func); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4255 } |
|
84648
92a9ccb2a521
Issue #18408: add more assertions on PyErr_Occurred() in ceval.c to detect bugs
Victor Stinner <victor.stinner@gmail.com>
parents:
84646
diff
changeset
|
4256 assert((x != NULL && !PyErr_Occurred()) |
|
92a9ccb2a521
Issue #18408: add more assertions on PyErr_Occurred() in ceval.c to detect bugs
Victor Stinner <victor.stinner@gmail.com>
parents:
84646
diff
changeset
|
4257 || (x == NULL && PyErr_Occurred())); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4258 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4259 /* Clear the stack of the function object. Also removes |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4260 the arguments in case they weren't consumed already |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4261 (fast_function() and err_args() leave them on the stack). |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4262 */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4263 while ((*pp_stack) > pfunc) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4264 w = EXT_POP(*pp_stack); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4265 Py_DECREF(w); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4266 PCALL(PCALL_POP); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4267 } |
|
84704
48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
Victor Stinner <victor.stinner@gmail.com>
parents:
84648
diff
changeset
|
4268 |
|
48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
Victor Stinner <victor.stinner@gmail.com>
parents:
84648
diff
changeset
|
4269 assert((x != NULL && !PyErr_Occurred()) |
|
48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
Victor Stinner <victor.stinner@gmail.com>
parents:
84648
diff
changeset
|
4270 || (x == NULL && PyErr_Occurred())); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4271 return x; |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
4272 } |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
4273 |
|
24870
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
4274 /* The fast_function() function optimize calls for which no argument |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4275 tuple is necessary; the objects are passed directly from the stack. |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4276 For the simplest case -- a function that takes only positional |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4277 arguments and is called with only positional arguments -- it |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4278 inlines the most primitive frame setup code from |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4279 PyEval_EvalCodeEx(), which vastly reduces the checks that must be |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4280 done before evaluating the frame. |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4281 */ |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4282 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4283 static PyObject * |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
4284 fast_function(PyObject *func, PyObject ***pp_stack, int n, int na, int nk) |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4285 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4286 PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4287 PyObject *globals = PyFunction_GET_GLOBALS(func); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4288 PyObject *argdefs = PyFunction_GET_DEFAULTS(func); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4289 PyObject *kwdefs = PyFunction_GET_KW_DEFAULTS(func); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4290 PyObject **d = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4291 int nd = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4292 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4293 PCALL(PCALL_FUNCTION); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4294 PCALL(PCALL_FAST_FUNCTION); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4295 if (argdefs == NULL && co->co_argcount == n && |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4296 co->co_kwonlyargcount == 0 && nk==0 && |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4297 co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4298 PyFrameObject *f; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4299 PyObject *retval = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4300 PyThreadState *tstate = PyThreadState_GET(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4301 PyObject **fastlocals, **stack; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4302 int i; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4303 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4304 PCALL(PCALL_FASTER_FUNCTION); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4305 assert(globals != NULL); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4306 /* XXX Perhaps we should create a specialized |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4307 PyFrame_New() that doesn't take locals, but does |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4308 take builtins without sanity checking them. |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4309 */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4310 assert(tstate != NULL); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4311 f = PyFrame_New(tstate, co, globals, NULL); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4312 if (f == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4313 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4314 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4315 fastlocals = f->f_localsplus; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4316 stack = (*pp_stack) - n; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4317 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4318 for (i = 0; i < n; i++) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4319 Py_INCREF(*stack); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4320 fastlocals[i] = *stack++; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4321 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4322 retval = PyEval_EvalFrameEx(f,0); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4323 ++tstate->recursion_depth; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4324 Py_DECREF(f); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4325 --tstate->recursion_depth; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4326 return retval; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4327 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4328 if (argdefs != NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4329 d = &PyTuple_GET_ITEM(argdefs, 0); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4330 nd = Py_SIZE(argdefs); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4331 } |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
66556
diff
changeset
|
4332 return PyEval_EvalCodeEx((PyObject*)co, globals, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4333 (PyObject *)NULL, (*pp_stack)-n, na, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4334 (*pp_stack)-2*nk, nk, d, nd, kwdefs, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4335 PyFunction_GET_CLOSURE(func)); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4336 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4337 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4338 static PyObject * |
|
15899
152814f6cd11
This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents:
15830
diff
changeset
|
4339 update_keyword_args(PyObject *orig_kwdict, int nk, PyObject ***pp_stack, |
|
152814f6cd11
This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents:
15830
diff
changeset
|
4340 PyObject *func) |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4341 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4342 PyObject *kwdict = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4343 if (orig_kwdict == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4344 kwdict = PyDict_New(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4345 else { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4346 kwdict = PyDict_Copy(orig_kwdict); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4347 Py_DECREF(orig_kwdict); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4348 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4349 if (kwdict == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4350 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4351 while (--nk >= 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4352 int err; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4353 PyObject *value = EXT_POP(*pp_stack); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4354 PyObject *key = EXT_POP(*pp_stack); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4355 if (PyDict_GetItem(kwdict, key) != NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4356 PyErr_Format(PyExc_TypeError, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4357 "%.200s%s got multiple values " |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4358 "for keyword argument '%U'", |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4359 PyEval_GetFuncName(func), |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4360 PyEval_GetFuncDesc(func), |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4361 key); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4362 Py_DECREF(key); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4363 Py_DECREF(value); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4364 Py_DECREF(kwdict); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4365 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4366 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4367 err = PyDict_SetItem(kwdict, key, value); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4368 Py_DECREF(key); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4369 Py_DECREF(value); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4370 if (err) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4371 Py_DECREF(kwdict); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4372 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4373 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4374 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4375 return kwdict; |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4376 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4377 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4378 static PyObject * |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4379 update_star_args(int nstack, int nstar, PyObject *stararg, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4380 PyObject ***pp_stack) |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4381 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4382 PyObject *callargs, *w; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4383 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4384 callargs = PyTuple_New(nstack + nstar); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4385 if (callargs == NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4386 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4387 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4388 if (nstar) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4389 int i; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4390 for (i = 0; i < nstar; i++) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4391 PyObject *a = PyTuple_GET_ITEM(stararg, i); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4392 Py_INCREF(a); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4393 PyTuple_SET_ITEM(callargs, nstack + i, a); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4394 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4395 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4396 while (--nstack >= 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4397 w = EXT_POP(*pp_stack); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4398 PyTuple_SET_ITEM(callargs, nstack, w); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4399 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4400 return callargs; |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4401 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4402 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4403 static PyObject * |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4404 load_args(PyObject ***pp_stack, int na) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4405 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4406 PyObject *args = PyTuple_New(na); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4407 PyObject *w; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4408 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4409 if (args == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4410 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4411 while (--na >= 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4412 w = EXT_POP(*pp_stack); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4413 PyTuple_SET_ITEM(args, na, w); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4414 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4415 return args; |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4416 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4417 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4418 static PyObject * |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4419 do_call(PyObject *func, PyObject ***pp_stack, int na, int nk) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4420 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4421 PyObject *callargs = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4422 PyObject *kwdict = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4423 PyObject *result = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4424 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4425 if (nk > 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4426 kwdict = update_keyword_args(NULL, nk, pp_stack, func); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4427 if (kwdict == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4428 goto call_fail; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4429 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4430 callargs = load_args(pp_stack, na); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4431 if (callargs == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4432 goto call_fail; |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4433 #ifdef CALL_PROFILE |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4434 /* At this point, we have to look at the type of func to |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4435 update the call stats properly. Do it here so as to avoid |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4436 exposing the call stats machinery outside ceval.c |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4437 */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4438 if (PyFunction_Check(func)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4439 PCALL(PCALL_FUNCTION); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4440 else if (PyMethod_Check(func)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4441 PCALL(PCALL_METHOD); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4442 else if (PyType_Check(func)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4443 PCALL(PCALL_TYPE); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4444 else if (PyCFunction_Check(func)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4445 PCALL(PCALL_CFUNCTION); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4446 else |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4447 PCALL(PCALL_OTHER); |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4448 #endif |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4449 if (PyCFunction_Check(func)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4450 PyThreadState *tstate = PyThreadState_GET(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4451 C_TRACE(result, PyCFunction_Call(func, callargs, kwdict)); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4452 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4453 else |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4454 result = PyObject_Call(func, callargs, kwdict); |
| 43411 | 4455 call_fail: |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4456 Py_XDECREF(callargs); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4457 Py_XDECREF(kwdict); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4458 return result; |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4459 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4460 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4461 static PyObject * |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4462 ext_do_call(PyObject *func, PyObject ***pp_stack, int flags, int na, int nk) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4463 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4464 int nstar = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4465 PyObject *callargs = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4466 PyObject *stararg = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4467 PyObject *kwdict = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4468 PyObject *result = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4469 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4470 if (flags & CALL_FLAG_KW) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4471 kwdict = EXT_POP(*pp_stack); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4472 if (!PyDict_Check(kwdict)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4473 PyObject *d; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4474 d = PyDict_New(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4475 if (d == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4476 goto ext_call_fail; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4477 if (PyDict_Update(d, kwdict) != 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4478 Py_DECREF(d); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4479 /* PyDict_Update raises attribute |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4480 * error (percolated from an attempt |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4481 * to get 'keys' attribute) instead of |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4482 * a type error if its second argument |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4483 * is not a mapping. |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4484 */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4485 if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4486 PyErr_Format(PyExc_TypeError, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4487 "%.200s%.200s argument after ** " |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4488 "must be a mapping, not %.200s", |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4489 PyEval_GetFuncName(func), |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4490 PyEval_GetFuncDesc(func), |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4491 kwdict->ob_type->tp_name); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4492 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4493 goto ext_call_fail; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4494 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4495 Py_DECREF(kwdict); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4496 kwdict = d; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4497 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4498 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4499 if (flags & CALL_FLAG_VAR) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4500 stararg = EXT_POP(*pp_stack); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4501 if (!PyTuple_Check(stararg)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4502 PyObject *t = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4503 t = PySequence_Tuple(stararg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4504 if (t == NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4505 if (PyErr_ExceptionMatches(PyExc_TypeError)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4506 PyErr_Format(PyExc_TypeError, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4507 "%.200s%.200s argument after * " |
|
68822
d3ae3fe3eb97
Issue #7330, #10833: Replace %100s by %.100s and %200s by %.200s
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68587
diff
changeset
|
4508 "must be a sequence, not %.200s", |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4509 PyEval_GetFuncName(func), |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4510 PyEval_GetFuncDesc(func), |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4511 stararg->ob_type->tp_name); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4512 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4513 goto ext_call_fail; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4514 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4515 Py_DECREF(stararg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4516 stararg = t; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4517 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4518 nstar = PyTuple_GET_SIZE(stararg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4519 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4520 if (nk > 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4521 kwdict = update_keyword_args(kwdict, nk, pp_stack, func); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4522 if (kwdict == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4523 goto ext_call_fail; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4524 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4525 callargs = update_star_args(na, nstar, stararg, pp_stack); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4526 if (callargs == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4527 goto ext_call_fail; |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4528 #ifdef CALL_PROFILE |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4529 /* At this point, we have to look at the type of func to |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4530 update the call stats properly. Do it here so as to avoid |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4531 exposing the call stats machinery outside ceval.c |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4532 */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4533 if (PyFunction_Check(func)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4534 PCALL(PCALL_FUNCTION); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4535 else if (PyMethod_Check(func)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4536 PCALL(PCALL_METHOD); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4537 else if (PyType_Check(func)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4538 PCALL(PCALL_TYPE); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4539 else if (PyCFunction_Check(func)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4540 PCALL(PCALL_CFUNCTION); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4541 else |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4542 PCALL(PCALL_OTHER); |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4543 #endif |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4544 if (PyCFunction_Check(func)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4545 PyThreadState *tstate = PyThreadState_GET(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4546 C_TRACE(result, PyCFunction_Call(func, callargs, kwdict)); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4547 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4548 else |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4549 result = PyObject_Call(func, callargs, kwdict); |
|
43410
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
4550 ext_call_fail: |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4551 Py_XDECREF(callargs); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4552 Py_XDECREF(kwdict); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4553 Py_XDECREF(stararg); |
|
84648
92a9ccb2a521
Issue #18408: add more assertions on PyErr_Occurred() in ceval.c to detect bugs
Victor Stinner <victor.stinner@gmail.com>
parents:
84646
diff
changeset
|
4554 assert((result != NULL && !PyErr_Occurred()) |
|
92a9ccb2a521
Issue #18408: add more assertions on PyErr_Occurred() in ceval.c to detect bugs
Victor Stinner <victor.stinner@gmail.com>
parents:
84646
diff
changeset
|
4555 || (result == NULL && PyErr_Occurred())); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4556 return result; |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4557 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4558 |
|
36882
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4559 /* Extract a slice index from a PyInt or PyLong or an object with the |
|
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4560 nb_index slot defined, and store in *pi. |
|
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4561 Silently reduce values larger than PY_SSIZE_T_MAX to PY_SSIZE_T_MAX, |
|
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4562 and silently boost values less than -PY_SSIZE_T_MAX-1 to -PY_SSIZE_T_MAX-1. |
|
36558
d3685f9b7b71
Remove size constraints in SLICE opcodes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
4563 Return 0 on error, 1 on success. |
|
21440
30efe46f8e3c
_PyEval_SliceIndex(): Repaired the comments, and added XXX comments
Tim Peters <tim.peters@gmail.com>
parents:
21398
diff
changeset
|
4564 */ |
|
21441
05ad7a69d933
_PyEval_SliceIndex(): explain why a NULL argument is allowed (thanks
Tim Peters <tim.peters@gmail.com>
parents:
21440
diff
changeset
|
4565 /* Note: If v is NULL, return success without storing into *pi. This |
|
05ad7a69d933
_PyEval_SliceIndex(): explain why a NULL argument is allowed (thanks
Tim Peters <tim.peters@gmail.com>
parents:
21440
diff
changeset
|
4566 is because_PyEval_SliceIndex() is called by apply_slice(), which can be |
|
05ad7a69d933
_PyEval_SliceIndex(): explain why a NULL argument is allowed (thanks
Tim Peters <tim.peters@gmail.com>
parents:
21440
diff
changeset
|
4567 called by the SLICE opcode with v and/or w equal to NULL. |
|
21440
30efe46f8e3c
_PyEval_SliceIndex(): Repaired the comments, and added XXX comments
Tim Peters <tim.peters@gmail.com>
parents:
21398
diff
changeset
|
4568 */ |
| 12614 | 4569 int |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36475
diff
changeset
|
4570 _PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi) |
| 69 | 4571 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4572 if (v != NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4573 Py_ssize_t x; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4574 if (PyIndex_Check(v)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4575 x = PyNumber_AsSsize_t(v, NULL); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4576 if (x == -1 && PyErr_Occurred()) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4577 return 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4578 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4579 else { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4580 PyErr_SetString(PyExc_TypeError, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4581 "slice indices must be integers or " |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4582 "None or have an __index__ method"); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4583 return 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4584 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4585 *pi = x; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4586 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4587 return 1; |
| 69 | 4588 } |
| 4589 | |
|
42132
863ed7cd45dc
Merged revisions 56020-56124 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42013
diff
changeset
|
4590 #define CANNOT_CATCH_MSG "catching classes that do not inherit from "\ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4591 "BaseException is not allowed" |
|
40942
4b9d0dac79cc
You can no longer catch non-BaseException objects; TypeError is raised if such
Brett Cannon <bcannon@gmail.com>
parents:
40937
diff
changeset
|
4592 |
| 5368 | 4593 static PyObject * |
|
85157
e7f6cef7a4cc
Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85046
diff
changeset
|
4594 cmp_outcome(int op, PyObject *v, PyObject *w) |
| 69 | 4595 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4596 int res = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4597 switch (op) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4598 case PyCmp_IS: |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4599 res = (v == w); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4600 break; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4601 case PyCmp_IS_NOT: |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4602 res = (v != w); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4603 break; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4604 case PyCmp_IN: |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4605 res = PySequence_Contains(w, v); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4606 if (res < 0) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4607 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4608 break; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4609 case PyCmp_NOT_IN: |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4610 res = PySequence_Contains(w, v); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4611 if (res < 0) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4612 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4613 res = !res; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4614 break; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4615 case PyCmp_EXC_MATCH: |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4616 if (PyTuple_Check(w)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4617 Py_ssize_t i, length; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4618 length = PyTuple_Size(w); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4619 for (i = 0; i < length; i += 1) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4620 PyObject *exc = PyTuple_GET_ITEM(w, i); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4621 if (!PyExceptionClass_Check(exc)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4622 PyErr_SetString(PyExc_TypeError, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4623 CANNOT_CATCH_MSG); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4624 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4625 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4626 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4627 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4628 else { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4629 if (!PyExceptionClass_Check(w)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4630 PyErr_SetString(PyExc_TypeError, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4631 CANNOT_CATCH_MSG); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4632 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4633 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4634 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4635 res = PyErr_GivenExceptionMatches(v, w); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4636 break; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4637 default: |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4638 return PyObject_RichCompare(v, w, op); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4639 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4640 v = res ? Py_True : Py_False; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4641 Py_INCREF(v); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4642 return v; |
| 69 | 4643 } |
| 4644 | |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
4645 static PyObject * |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
4646 import_from(PyObject *v, PyObject *name) |
|
72
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
4647 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4648 PyObject *x; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4649 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4650 x = PyObject_GetAttr(v, name); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4651 if (x == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) { |
|
84583
c3f9292c8efe
Issue #18342: Use the repr of a module name for ``from ... import
Brett Cannon <brett@python.org>
parents:
84573
diff
changeset
|
4652 PyErr_Format(PyExc_ImportError, "cannot import name %R", name); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4653 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4654 return x; |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
4655 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
4656 |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
4657 static int |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
4658 import_all_from(PyObject *locals, PyObject *v) |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
4659 { |
|
72926
db4aa878cea2
Port SetAttrString/HasAttrString to SetAttrId/GetAttrId.
Martin v. Löwis <martin@v.loewis.de>
parents:
72925
diff
changeset
|
4660 _Py_IDENTIFIER(__all__); |
|
db4aa878cea2
Port SetAttrString/HasAttrString to SetAttrId/GetAttrId.
Martin v. Löwis <martin@v.loewis.de>
parents:
72925
diff
changeset
|
4661 _Py_IDENTIFIER(__dict__); |
|
db4aa878cea2
Port SetAttrString/HasAttrString to SetAttrId/GetAttrId.
Martin v. Löwis <martin@v.loewis.de>
parents:
72925
diff
changeset
|
4662 PyObject *all = _PyObject_GetAttrId(v, &PyId___all__); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4663 PyObject *dict, *name, *value; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4664 int skip_leading_underscores = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4665 int pos, err; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4666 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4667 if (all == NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4668 if (!PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4669 return -1; /* Unexpected error */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4670 PyErr_Clear(); |
|
72926
db4aa878cea2
Port SetAttrString/HasAttrString to SetAttrId/GetAttrId.
Martin v. Löwis <martin@v.loewis.de>
parents:
72925
diff
changeset
|
4671 dict = _PyObject_GetAttrId(v, &PyId___dict__); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4672 if (dict == NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4673 if (!PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4674 return -1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4675 PyErr_SetString(PyExc_ImportError, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4676 "from-import-* object has no __dict__ and no __all__"); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4677 return -1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4678 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4679 all = PyMapping_Keys(dict); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4680 Py_DECREF(dict); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4681 if (all == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4682 return -1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4683 skip_leading_underscores = 1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4684 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4685 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4686 for (pos = 0, err = 0; ; pos++) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4687 name = PySequence_GetItem(all, pos); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4688 if (name == NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4689 if (!PyErr_ExceptionMatches(PyExc_IndexError)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4690 err = -1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4691 else |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4692 PyErr_Clear(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4693 break; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4694 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4695 if (skip_leading_underscores && |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4696 PyUnicode_Check(name) && |
| 72475 | 4697 PyUnicode_READY(name) != -1 && |
| 4698 PyUnicode_READ_CHAR(name, 0) == '_') | |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4699 { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4700 Py_DECREF(name); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4701 continue; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4702 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4703 value = PyObject_GetAttr(v, name); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4704 if (value == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4705 err = -1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4706 else if (PyDict_CheckExact(locals)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4707 err = PyDict_SetItem(locals, name, value); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4708 else |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4709 err = PyObject_SetItem(locals, name, value); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4710 Py_DECREF(name); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4711 Py_XDECREF(value); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4712 if (err != 0) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4713 break; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4714 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4715 Py_DECREF(all); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4716 return err; |
|
72
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
4717 } |
|
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
4718 |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
4719 static void |
| 42860 | 4720 format_exc_check_arg(PyObject *exc, const char *format_str, PyObject *obj) |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4721 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4722 const char *obj_str; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4723 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4724 if (!obj) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4725 return; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4726 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4727 obj_str = _PyUnicode_AsString(obj); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4728 if (!obj_str) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4729 return; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4730 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4731 PyErr_Format(exc, format_str, obj_str); |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4732 } |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4733 |
|
64620
25cc226dc9bd
#4617: Previously it was illegal to delete a name from the local
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64439
diff
changeset
|
4734 static void |
|
25cc226dc9bd
#4617: Previously it was illegal to delete a name from the local
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64439
diff
changeset
|
4735 format_exc_unbound(PyCodeObject *co, int oparg) |
|
25cc226dc9bd
#4617: Previously it was illegal to delete a name from the local
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64439
diff
changeset
|
4736 { |
|
25cc226dc9bd
#4617: Previously it was illegal to delete a name from the local
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64439
diff
changeset
|
4737 PyObject *name; |
|
25cc226dc9bd
#4617: Previously it was illegal to delete a name from the local
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64439
diff
changeset
|
4738 /* Don't stomp existing exception */ |
|
25cc226dc9bd
#4617: Previously it was illegal to delete a name from the local
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64439
diff
changeset
|
4739 if (PyErr_Occurred()) |
|
25cc226dc9bd
#4617: Previously it was illegal to delete a name from the local
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64439
diff
changeset
|
4740 return; |
|
25cc226dc9bd
#4617: Previously it was illegal to delete a name from the local
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64439
diff
changeset
|
4741 if (oparg < PyTuple_GET_SIZE(co->co_cellvars)) { |
|
25cc226dc9bd
#4617: Previously it was illegal to delete a name from the local
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64439
diff
changeset
|
4742 name = PyTuple_GET_ITEM(co->co_cellvars, |
|
25cc226dc9bd
#4617: Previously it was illegal to delete a name from the local
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64439
diff
changeset
|
4743 oparg); |
|
25cc226dc9bd
#4617: Previously it was illegal to delete a name from the local
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64439
diff
changeset
|
4744 format_exc_check_arg( |
|
25cc226dc9bd
#4617: Previously it was illegal to delete a name from the local
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64439
diff
changeset
|
4745 PyExc_UnboundLocalError, |
|
25cc226dc9bd
#4617: Previously it was illegal to delete a name from the local
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64439
diff
changeset
|
4746 UNBOUNDLOCAL_ERROR_MSG, |
|
25cc226dc9bd
#4617: Previously it was illegal to delete a name from the local
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64439
diff
changeset
|
4747 name); |
|
25cc226dc9bd
#4617: Previously it was illegal to delete a name from the local
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64439
diff
changeset
|
4748 } else { |
|
25cc226dc9bd
#4617: Previously it was illegal to delete a name from the local
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64439
diff
changeset
|
4749 name = PyTuple_GET_ITEM(co->co_freevars, oparg - |
|
25cc226dc9bd
#4617: Previously it was illegal to delete a name from the local
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64439
diff
changeset
|
4750 PyTuple_GET_SIZE(co->co_cellvars)); |
|
25cc226dc9bd
#4617: Previously it was illegal to delete a name from the local
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64439
diff
changeset
|
4751 format_exc_check_arg(PyExc_NameError, |
|
25cc226dc9bd
#4617: Previously it was illegal to delete a name from the local
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64439
diff
changeset
|
4752 UNBOUNDFREE_ERROR_MSG, name); |
|
25cc226dc9bd
#4617: Previously it was illegal to delete a name from the local
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64439
diff
changeset
|
4753 } |
|
25cc226dc9bd
#4617: Previously it was illegal to delete a name from the local
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64439
diff
changeset
|
4754 } |
|
25cc226dc9bd
#4617: Previously it was illegal to delete a name from the local
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64439
diff
changeset
|
4755 |
|
72605
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4756 static PyObject * |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4757 unicode_concatenate(PyObject *v, PyObject *w, |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4758 PyFrameObject *f, unsigned char *next_instr) |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4759 { |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4760 PyObject *res; |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4761 if (Py_REFCNT(v) == 2) { |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4762 /* In the common case, there are 2 references to the value |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4763 * stored in 'variable' when the += is performed: one on the |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4764 * value stack (in 'v') and one still stored in the |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4765 * 'variable'. We try to delete the variable now to reduce |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4766 * the refcnt to 1. |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4767 */ |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4768 switch (*next_instr) { |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4769 case STORE_FAST: |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4770 { |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4771 int oparg = PEEKARG(); |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4772 PyObject **fastlocals = f->f_localsplus; |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4773 if (GETLOCAL(oparg) == v) |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4774 SETLOCAL(oparg, NULL); |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4775 break; |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4776 } |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4777 case STORE_DEREF: |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4778 { |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4779 PyObject **freevars = (f->f_localsplus + |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4780 f->f_code->co_nlocals); |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4781 PyObject *c = freevars[PEEKARG()]; |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4782 if (PyCell_GET(c) == v) |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4783 PyCell_Set(c, NULL); |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4784 break; |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4785 } |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4786 case STORE_NAME: |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4787 { |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4788 PyObject *names = f->f_code->co_names; |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4789 PyObject *name = GETITEM(names, PEEKARG()); |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4790 PyObject *locals = f->f_locals; |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4791 if (PyDict_CheckExact(locals) && |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4792 PyDict_GetItem(locals, name) == v) { |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4793 if (PyDict_DelItem(locals, name) != 0) { |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4794 PyErr_Clear(); |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4795 } |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4796 } |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4797 break; |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4798 } |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4799 } |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4800 } |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4801 res = v; |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4802 PyUnicode_Append(&res, w); |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4803 return res; |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4804 } |
|
07d27d865e2c
ceval.c: restore str+=str optimization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
4805 |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4806 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4807 |
|
20438
08d7a6756bfe
make getarray static - it's only called from ceval.c and is not an
Skip Montanaro <skip@pobox.com>
parents:
20409
diff
changeset
|
4808 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4809 getarray(long a[256]) |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4810 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4811 int i; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4812 PyObject *l = PyList_New(256); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4813 if (l == NULL) return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4814 for (i = 0; i < 256; i++) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4815 PyObject *x = PyLong_FromLong(a[i]); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4816 if (x == NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4817 Py_DECREF(l); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4818 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4819 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4820 PyList_SetItem(l, i, x); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4821 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4822 for (i = 0; i < 256; i++) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4823 a[i] = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4824 return l; |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4825 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4826 |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4827 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4828 _Py_GetDXProfile(PyObject *self, PyObject *args) |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4829 { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4830 #ifndef DXPAIRS |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4831 return getarray(dxp); |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4832 #else |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4833 int i; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4834 PyObject *l = PyList_New(257); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4835 if (l == NULL) return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4836 for (i = 0; i < 257; i++) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4837 PyObject *x = getarray(dxpairs[i]); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4838 if (x == NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4839 Py_DECREF(l); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4840 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4841 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4842 PyList_SetItem(l, i, x); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4843 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59858
diff
changeset
|
4844 return l; |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4845 #endif |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4846 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4847 |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4848 #endif |
