annotate Python/ceval.c @ 62743:2145593d108d legacy-trunk v2.7

move sections
author Benjamin Peterson <benjamin@python.org>
date Sat, 03 Jul 2010 13:57:30 +0000
parents ca4f2e9869b6
children 9774c11e03f6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
1
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2 /* Execute compiled code */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
9 /* enable more aggressive intra-module optimizations, where available */
38350
3bef24086ace needforspeed: added PY_LOCAL_AGGRESSIVE macro to enable "aggressive"
Fredrik Lundh <fredrik@pythonware.com>
parents: 38345
diff changeset
10 #define PY_LOCAL_AGGRESSIVE
3bef24086ace needforspeed: added PY_LOCAL_AGGRESSIVE macro to enable "aggressive"
Fredrik Lundh <fredrik@pythonware.com>
parents: 38345
diff changeset
11
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
12 #include "Python.h"
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
13
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35609
diff changeset
14 #include "code.h"
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
15 #include "frameobject.h"
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
16 #include "eval.h"
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 #include "opcode.h"
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 18611
diff changeset
18 #include "structmember.h"
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
19
1400
aac8231a715c * mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents: 1391
diff changeset
20 #include <ctype.h>
aac8231a715c * mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents: 1391
diff changeset
21
38418
708eaf0896bf Patch 1145039.
Tim Peters <tim.peters@gmail.com>
parents: 38352
diff changeset
22 #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
23
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 #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
25
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
26 #else
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
27
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
28 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
29
33104
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
30 #if defined(__ppc__) /* <- Don't know if this is the correct symbol; this
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
31 section should work for GCC on any PowerPC
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
32 platform, irrespective of OS.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
33 POWER? Who knows :-) */
33104
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
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
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
36
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
37 static void
33104
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
38 ppc_getcounter(uint64 *v)
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
39 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
40 register unsigned long tbu, tb, tbu2;
33104
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
41
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
42 loop:
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
43 asm volatile ("mftbu %0" : "=r" (tbu) );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
44 asm volatile ("mftb %0" : "=r" (tb) );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
45 asm volatile ("mftbu %0" : "=r" (tbu2));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
46 if (__builtin_expect(tbu != tbu2, 0)) goto loop;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
47
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
48 /* The slightly peculiar way of writing the next lines is
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
49 compiled better by GCC than any other way I tried. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
50 ((long*)(v))[0] = tbu;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
51 ((long*)(v))[1] = tb;
33104
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
52 }
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
53
57002
f594313b9364 Issue #6603: Fix --with-tsc build failures on x86-64 that resulted
Mark Dickinson <dickinsm@gmail.com>
parents: 55034
diff changeset
54 #elif defined(__i386__)
f594313b9364 Issue #6603: Fix --with-tsc build failures on x86-64 that resulted
Mark Dickinson <dickinsm@gmail.com>
parents: 55034
diff changeset
55
f594313b9364 Issue #6603: Fix --with-tsc build failures on x86-64 that resulted
Mark Dickinson <dickinsm@gmail.com>
parents: 55034
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
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
60
57002
f594313b9364 Issue #6603: Fix --with-tsc build failures on x86-64 that resulted
Mark Dickinson <dickinsm@gmail.com>
parents: 55034
diff changeset
61 #elif defined(__x86_64__)
f594313b9364 Issue #6603: Fix --with-tsc build failures on x86-64 that resulted
Mark Dickinson <dickinsm@gmail.com>
parents: 55034
diff changeset
62
f594313b9364 Issue #6603: Fix --with-tsc build failures on x86-64 that resulted
Mark Dickinson <dickinsm@gmail.com>
parents: 55034
diff changeset
63 /* for gcc/x86_64, the "A" constraint in DI mode means *either* rax *or* rdx;
f594313b9364 Issue #6603: Fix --with-tsc build failures on x86-64 that resulted
Mark Dickinson <dickinsm@gmail.com>
parents: 55034
diff changeset
64 not edx:eax as it does for i386. Since rdtsc puts its result in edx:eax
f594313b9364 Issue #6603: Fix --with-tsc build failures on x86-64 that resulted
Mark Dickinson <dickinsm@gmail.com>
parents: 55034
diff changeset
65 even in 64-bit mode, we need to use "a" and "d" for the lower and upper
f594313b9364 Issue #6603: Fix --with-tsc build failures on x86-64 that resulted
Mark Dickinson <dickinsm@gmail.com>
parents: 55034
diff changeset
66 32-bit pieces of the result. */
f594313b9364 Issue #6603: Fix --with-tsc build failures on x86-64 that resulted
Mark Dickinson <dickinsm@gmail.com>
parents: 55034
diff changeset
67
f594313b9364 Issue #6603: Fix --with-tsc build failures on x86-64 that resulted
Mark Dickinson <dickinsm@gmail.com>
parents: 55034
diff changeset
68 #define READ_TIMESTAMP(val) \
f594313b9364 Issue #6603: Fix --with-tsc build failures on x86-64 that resulted
Mark Dickinson <dickinsm@gmail.com>
parents: 55034
diff changeset
69 __asm__ __volatile__("rdtsc" : \
f594313b9364 Issue #6603: Fix --with-tsc build failures on x86-64 that resulted
Mark Dickinson <dickinsm@gmail.com>
parents: 55034
diff changeset
70 "=a" (((int*)&(val))[0]), "=d" (((int*)&(val))[1]));
f594313b9364 Issue #6603: Fix --with-tsc build failures on x86-64 that resulted
Mark Dickinson <dickinsm@gmail.com>
parents: 55034
diff changeset
71
f594313b9364 Issue #6603: Fix --with-tsc build failures on x86-64 that resulted
Mark Dickinson <dickinsm@gmail.com>
parents: 55034
diff changeset
72
f594313b9364 Issue #6603: Fix --with-tsc build failures on x86-64 that resulted
Mark Dickinson <dickinsm@gmail.com>
parents: 55034
diff changeset
73 #else
f594313b9364 Issue #6603: Fix --with-tsc build failures on x86-64 that resulted
Mark Dickinson <dickinsm@gmail.com>
parents: 55034
diff changeset
74
f594313b9364 Issue #6603: Fix --with-tsc build failures on x86-64 that resulted
Mark Dickinson <dickinsm@gmail.com>
parents: 55034
diff changeset
75 #error "Don't know how to implement timestamp counter for this architecture"
f594313b9364 Issue #6603: Fix --with-tsc build failures on x86-64 that resulted
Mark Dickinson <dickinsm@gmail.com>
parents: 55034
diff changeset
76
33104
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
77 #endif
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
78
38418
708eaf0896bf Patch 1145039.
Tim Peters <tim.peters@gmail.com>
parents: 38352
diff changeset
79 void dump_tsc(int opcode, int ticked, uint64 inst0, uint64 inst1,
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
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 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
82 uint64 intr, inst, loop;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
83 PyThreadState *tstate = PyThreadState_Get();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
84 if (!tstate->interp->tscdump)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
85 return;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
86 intr = intr1 - intr0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
87 inst = inst1 - inst0 - intr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
88 loop = loop1 - loop0 - intr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
89 fprintf(stderr, "opcode=%03d t=%d inst=%06lld loop=%06lld\n",
62457
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
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
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
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
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
99 /* For debugging the interpreter: */
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
100 #define LLTRACE 1 /* Low-level trace feature */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
101 #define CHECKEXC 1 /* Double-check exception checking */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 #endif
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
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
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
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
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
112 static PyObject * fast_function(PyObject *, PyObject ***, int, int, int);
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
113 static PyObject * do_call(PyObject *, PyObject ***, int, int);
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
114 static PyObject * ext_do_call(PyObject *, PyObject ***, int, int, int);
43416
dc39dddea330 Try harder to stay within the 79-column limit. There's still two places that go (way) over, but those are harder to fix without suffering in readability.
Thomas Wouters <thomas@python.org>
parents: 43408
diff changeset
115 static PyObject * update_keyword_args(PyObject *, int, PyObject ***,
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
116 PyObject *);
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
117 static PyObject * update_star_args(int, int, PyObject *, PyObject ***);
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
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
38352
9f7b1b7adf01 Py_LOCAL shouldn't be used for data; it works for some .NET 2003 compilers,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38350
diff changeset
123 static int lltrace;
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
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
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
126 static int call_trace(Py_tracefunc, PyObject *, PyFrameObject *,
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
127 int, PyObject *);
43845
76844a0a579f Merge from py3k branch:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 43784
diff changeset
128 static int call_trace_protected(Py_tracefunc, PyObject *,
62457
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
129 PyFrameObject *, int, PyObject *);
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
130 static void call_exc_trace(Py_tracefunc, PyObject *, PyFrameObject *);
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
131 static int maybe_call_line_trace(Py_tracefunc, PyObject *,
62457
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
132 PyFrameObject *, int *, int *, int *);
24844
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24718
diff changeset
133
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
134 static PyObject * apply_slice(PyObject *, PyObject *, PyObject *);
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
135 static int assign_slice(PyObject *, PyObject *,
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
136 PyObject *, PyObject *);
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
137 static PyObject * cmp_outcome(int, PyObject *, PyObject *);
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
138 static PyObject * import_from(PyObject *, PyObject *);
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
139 static int import_all_from(PyObject *, PyObject *);
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
140 static PyObject * build_class(PyObject *, PyObject *, PyObject *);
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
141 static int exec_statement(PyFrameObject *,
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
142 PyObject *, PyObject *, PyObject *);
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
143 static void set_exc_info(PyThreadState *, PyObject *, PyObject *, PyObject *);
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
144 static void reset_exc_info(PyThreadState *);
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
145 static void format_exc_check_arg(PyObject *, char *, PyObject *);
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
146 static PyObject * string_concatenate(PyObject *, PyObject *,
62457
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
147 PyFrameObject *, unsigned char *);
50936
dbc14acdde37 allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents: 50674
diff changeset
148 static PyObject * kwd_as_string(PyObject *);
54329
145376df3ad7 add a SETUP_WITH opcode
Benjamin Peterson <benjamin@python.org>
parents: 54297
diff changeset
149 static PyObject * special_lookup(PyObject *, char *, PyObject **);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
150
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
151 #define NAME_ERROR_MSG \
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
152 "name '%.200s' is not defined"
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
153 #define GLOBAL_NAME_ERROR_MSG \
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
154 "global name '%.200s' is not defined"
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
155 #define UNBOUNDLOCAL_ERROR_MSG \
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
156 "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
157 #define UNBOUNDFREE_ERROR_MSG \
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
158 "free variable '%.200s' referenced before assignment" \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
159 " in enclosing scope"
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
160
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
161 /* Dynamic execution profile */
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
162 #ifdef DYNAMIC_EXECUTION_PROFILE
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
163 #ifdef DXPAIRS
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
164 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
165 #define dxp dxpairs[256]
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
166 #else
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
167 static long dxp[256];
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
168 #endif
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
169 #endif
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
170
27712
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
171 /* 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
172 #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
173 #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
174 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
175
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_ALL 0
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
177 #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
178 #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
179 #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
180 #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
181 #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
182 #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
183 #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
184 #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
185 #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
186 #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
187
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
188 /* 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
189
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
190 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
191
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
192 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
193 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
194
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
195 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
196 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
197 twice.
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
198
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
199 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
200 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
201 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
202 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
203 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
204 */
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 #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
207
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
208 PyObject *
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
209 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
210 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
211 return Py_BuildValue("iiiiiiiiiii",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
212 pcall[0], pcall[1], pcall[2], pcall[3],
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
213 pcall[4], pcall[5], pcall[6], pcall[7],
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
214 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
215 }
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
216 #else
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
217 #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
218
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
219 PyObject *
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
220 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
221 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
222 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
223 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
224 }
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
225 #endif
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
226
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
227
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
228 #ifdef WITH_THREAD
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
229
38716
42808526511c Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 38536
diff changeset
230 #ifdef HAVE_ERRNO_H
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
231 #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
232 #endif
9203
07dae6fdae79 Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents: 9048
diff changeset
233 #include "pythread.h"
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
234
29643
fa97293533a9 Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents: 29349
diff changeset
235 static PyThread_type_lock interpreter_lock = 0; /* This is the GIL */
50674
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
236 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
237 static long main_thread = 0;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
238
33715
a46b76eb9053 SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents: 33501
diff changeset
239 int
a46b76eb9053 SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents: 33501
diff changeset
240 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
241 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
242 return interpreter_lock != 0;
33715
a46b76eb9053 SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents: 33501
diff changeset
243 }
a46b76eb9053 SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents: 33501
diff changeset
244
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
245 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
246 PyEval_InitThreads(void)
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
247 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
248 if (interpreter_lock)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
249 return;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
250 interpreter_lock = PyThread_allocate_lock();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
251 PyThread_acquire_lock(interpreter_lock, 1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
252 main_thread = PyThread_get_thread_ident();
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
253 }
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
254
5865
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
255 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
256 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
257 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
258 PyThread_acquire_lock(interpreter_lock, 1);
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5911
diff changeset
259 }
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5911
diff changeset
260
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5911
diff changeset
261 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
262 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
263 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
264 PyThread_release_lock(interpreter_lock);
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5911
diff changeset
265 }
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5911
diff changeset
266
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5911
diff changeset
267 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
268 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
269 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
270 if (tstate == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
271 Py_FatalError("PyEval_AcquireThread: NULL new thread state");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
272 /* Check someone has called PyEval_InitThreads() to create the lock */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
273 assert(interpreter_lock);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
274 PyThread_acquire_lock(interpreter_lock, 1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
275 if (PyThreadState_Swap(tstate) != NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
276 Py_FatalError(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
277 "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
278 }
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
279
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
280 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
281 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
282 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
283 if (tstate == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
284 Py_FatalError("PyEval_ReleaseThread: NULL thread state");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
285 if (PyThreadState_Swap(NULL) != tstate)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
286 Py_FatalError("PyEval_ReleaseThread: wrong thread state");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
287 PyThread_release_lock(interpreter_lock);
5865
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
288 }
14225
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
289
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
290 /* This function is called from PyOS_AfterFork to ensure that newly
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
291 created child processes don't hold locks referring to threads which
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
292 are not running in the child process. (This could also be done using
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
293 pthread_atfork mechanism, at least for the pthreads implementation.) */
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
294
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
295 void
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
296 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
297 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
298 PyObject *threading, *result;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
299 PyThreadState *tstate;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
300
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
301 if (!interpreter_lock)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
302 return;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
303 /*XXX Can't use PyThread_free_lock here because it does too
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
304 much error-checking. Doing this cleanly would require
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
305 adding a new function to each thread_*.h. Instead, just
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
306 create a new lock and waste a little bit of memory */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
307 interpreter_lock = PyThread_allocate_lock();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
308 pending_lock = PyThread_allocate_lock();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
309 PyThread_acquire_lock(interpreter_lock, 1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
310 main_thread = PyThread_get_thread_ident();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
311
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
312 /* Update the threading module with the new state.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
313 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
314 tstate = PyThreadState_GET();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
315 threading = PyMapping_GetItemString(tstate->interp->modules,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
316 "threading");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
317 if (threading == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
318 /* threading not imported */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
319 PyErr_Clear();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
320 return;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
321 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
322 result = PyObject_CallMethod(threading, "_after_fork", NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
323 if (result == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
324 PyErr_WriteUnraisable(threading);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
325 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
326 Py_DECREF(result);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
327 Py_DECREF(threading);
14225
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
328 }
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
329 #endif
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
330
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
331 /* Functions save_thread and restore_thread are always defined so
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
332 dynamically loaded modules needn't be compiled separately for use
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
333 with and without threads: */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
334
5846
852a1fa62a7c PyEval_SaveThread() and PyEval_RestoreThread() now return/take a
Guido van Rossum <guido@python.org>
parents: 5829
diff changeset
335 PyThreadState *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
336 PyEval_SaveThread(void)
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
337 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
338 PyThreadState *tstate = PyThreadState_Swap(NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
339 if (tstate == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
340 Py_FatalError("PyEval_SaveThread: NULL tstate");
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
341 #ifdef WITH_THREAD
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
342 if (interpreter_lock)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
343 PyThread_release_lock(interpreter_lock);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
344 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
345 return tstate;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
346 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
347
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
348 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
349 PyEval_RestoreThread(PyThreadState *tstate)
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
350 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
351 if (tstate == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
352 Py_FatalError("PyEval_RestoreThread: NULL tstate");
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
353 #ifdef WITH_THREAD
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
354 if (interpreter_lock) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
355 int err = errno;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
356 PyThread_acquire_lock(interpreter_lock, 1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
357 errno = err;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
358 }
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
359 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
360 PyThreadState_Swap(tstate);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
361 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
362
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
363
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
364 /* 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
365 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
366 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
367 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
368 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
369 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
370
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
371 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
372 (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
373 an exception condition).
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
374
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
375 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
376 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
377
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
378 #ifdef WITH_THREAD
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
379 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
380 will execute them.
50674
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
381 There is no facility to schedule calls to a particular thread, but
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
382 that should be easy to change, should that ever be required. In
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
383 that case, the static variables here should go into the python
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
384 threadstate.
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
385 #endif
50674
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
386 */
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
387
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
388 #ifdef WITH_THREAD
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
389
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
390 /* The WITH_THREAD implementation is thread-safe. It allows
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
391 scheduling to be made from any thread, and even from an executing
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
392 callback.
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
393 */
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
394
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
395 #define NPENDINGCALLS 32
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
396 static struct {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
397 int (*func)(void *);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
398 void *arg;
50674
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
399 } pendingcalls[NPENDINGCALLS];
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
400 static int pendingfirst = 0;
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
401 static int pendinglast = 0;
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
402 static volatile int pendingcalls_to_do = 1; /* trigger initialization of lock */
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
403 static char pendingbusy = 0;
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
404
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
405 int
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
406 Py_AddPendingCall(int (*func)(void *), void *arg)
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
407 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
408 int i, j, result=0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
409 PyThread_type_lock lock = pending_lock;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
410
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
411 /* try a few times for the lock. Since this mechanism is used
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
412 * for signal handling (on the main thread), there is a (slim)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
413 * chance that a signal is delivered on the same thread while we
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
414 * hold the lock during the Py_MakePendingCalls() function.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
415 * This avoids a deadlock in that case.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
416 * Note that signals can be delivered on any thread. In particular,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
417 * on Windows, a SIGINT is delivered on a system-created worker
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
418 * thread.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
419 * We also check for lock being NULL, in the unlikely case that
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
420 * this function is called before any bytecode evaluation takes place.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
421 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
422 if (lock != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
423 for (i = 0; i<100; i++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
424 if (PyThread_acquire_lock(lock, NOWAIT_LOCK))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
425 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
426 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
427 if (i == 100)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
428 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
429 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
430
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
431 i = pendinglast;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
432 j = (i + 1) % NPENDINGCALLS;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
433 if (j == pendingfirst) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
434 result = -1; /* Queue full */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
435 } else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
436 pendingcalls[i].func = func;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
437 pendingcalls[i].arg = arg;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
438 pendinglast = j;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
439 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
440 /* signal main loop */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
441 _Py_Ticker = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
442 pendingcalls_to_do = 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
443 if (lock != NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
444 PyThread_release_lock(lock);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
445 return result;
50674
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
446 }
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
447
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
448 int
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
449 Py_MakePendingCalls(void)
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
450 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
451 int i;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
452 int r = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
453
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
454 if (!pending_lock) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
455 /* initial allocation of the lock */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
456 pending_lock = PyThread_allocate_lock();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
457 if (pending_lock == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
458 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
459 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
460
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
461 /* only service pending calls on main thread */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
462 if (main_thread && PyThread_get_thread_ident() != main_thread)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
463 return 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
464 /* don't perform recursive pending calls */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
465 if (pendingbusy)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
466 return 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
467 pendingbusy = 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
468 /* perform a bounded number of calls, in case of recursion */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
469 for (i=0; i<NPENDINGCALLS; i++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
470 int j;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
471 int (*func)(void *);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
472 void *arg = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
473
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
474 /* pop one item off the queue while holding the lock */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
475 PyThread_acquire_lock(pending_lock, WAIT_LOCK);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
476 j = pendingfirst;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
477 if (j == pendinglast) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
478 func = NULL; /* Queue empty */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
479 } else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
480 func = pendingcalls[j].func;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
481 arg = pendingcalls[j].arg;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
482 pendingfirst = (j + 1) % NPENDINGCALLS;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
483 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
484 pendingcalls_to_do = pendingfirst != pendinglast;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
485 PyThread_release_lock(pending_lock);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
486 /* having released the lock, perform the callback */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
487 if (func == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
488 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
489 r = func(arg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
490 if (r)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
491 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
492 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
493 pendingbusy = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
494 return r;
50674
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
495 }
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
496
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
497 #else /* if ! defined WITH_THREAD */
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
498
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
499 /*
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
500 WARNING! ASYNCHRONOUSLY EXECUTING CODE!
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
501 This code is used for signal handling in python that isn't built
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
502 with WITH_THREAD.
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
503 Don't use this implementation when Py_AddPendingCalls() can happen
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
504 on a different thread!
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
505
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
506 There are two possible race conditions:
50674
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
507 (1) nested asynchronous calls to Py_AddPendingCall()
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
508 (2) AddPendingCall() calls made while pending calls are being processed.
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
509
50674
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
510 (1) is very unlikely because typically signal delivery
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
511 is blocked during signal handling. So it should be impossible.
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
512 (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
513 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
514 The safety against (2) is derived from the fact that only one
50674
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
515 thread is present, interrupted by signals, and that the critical
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
516 section is protected with the "busy" variable. On Windows, which
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
517 delivers SIGINT on a system thread, this does not hold and therefore
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
518 Windows really shouldn't use this version.
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
519 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
520 */
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
521
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
522 #define NPENDINGCALLS 32
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
523 static struct {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
524 int (*func)(void *);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
525 void *arg;
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
526 } pendingcalls[NPENDINGCALLS];
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
527 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
528 static volatile int pendinglast = 0;
50674
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
529 static volatile 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
530
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
531 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
532 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
533 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
534 static volatile int busy = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
535 int i, j;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
536 /* XXX Begin critical section */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
537 if (busy)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
538 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
539 busy = 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
540 i = pendinglast;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
541 j = (i + 1) % NPENDINGCALLS;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
542 if (j == pendingfirst) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
543 busy = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
544 return -1; /* Queue full */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
545 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
546 pendingcalls[i].func = func;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
547 pendingcalls[i].arg = arg;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
548 pendinglast = j;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
549
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
550 _Py_Ticker = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
551 pendingcalls_to_do = 1; /* Signal main loop */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
552 busy = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
553 /* XXX End critical section */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
554 return 0;
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
555 }
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
556
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
557 int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
558 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
559 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
560 static int busy = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
561 if (busy)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
562 return 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
563 busy = 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
564 pendingcalls_to_do = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
565 for (;;) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
566 int i;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
567 int (*func)(void *);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
568 void *arg;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
569 i = pendingfirst;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
570 if (i == pendinglast)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
571 break; /* Queue empty */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
572 func = pendingcalls[i].func;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
573 arg = pendingcalls[i].arg;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
574 pendingfirst = (i + 1) % NPENDINGCALLS;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
575 if (func(arg) < 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
576 busy = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
577 pendingcalls_to_do = 1; /* We're not done yet */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
578 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
579 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
580 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
581 busy = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
582 return 0;
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
583 }
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
584
50674
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
585 #endif /* WITH_THREAD */
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
586
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
587
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
588 /* The interpreter's recursion limit */
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
589
34863
71fd7ee4b7f5 Make a handy macro, Py_DEFAULT_RECURSION_LIMIT to allow to define
Hye-Shik Chang <hyeshik@gmail.com>
parents: 34442
diff changeset
590 #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
591 #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
592 #endif
71fd7ee4b7f5 Make a handy macro, Py_DEFAULT_RECURSION_LIMIT to allow to define
Hye-Shik Chang <hyeshik@gmail.com>
parents: 34442
diff changeset
593 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
594 int _Py_CheckRecursionLimit = Py_DEFAULT_RECURSION_LIMIT;
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
595
14348
6d0f64f7dedd Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 14333
diff changeset
596 int
6d0f64f7dedd Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 14333
diff changeset
597 Py_GetRecursionLimit(void)
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
598 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
599 return recursion_limit;
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
600 }
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
601
14348
6d0f64f7dedd Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 14333
diff changeset
602 void
6d0f64f7dedd Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 14333
diff changeset
603 Py_SetRecursionLimit(int new_limit)
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
604 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
605 recursion_limit = new_limit;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
606 _Py_CheckRecursionLimit = recursion_limit;
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
607 }
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
608
30801
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
609 /* the macro Py_EnterRecursiveCall() only calls _Py_CheckRecursiveCall()
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
610 if the recursion_depth reaches _Py_CheckRecursionLimit.
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
611 If USE_STACKCHECK, the macro decrements _Py_CheckRecursionLimit
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
612 to guarantee that _Py_CheckRecursiveCall() is regularly called.
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
613 Without USE_STACKCHECK, there is no need for this. */
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
614 int
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
615 _Py_CheckRecursiveCall(char *where)
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
616 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
617 PyThreadState *tstate = PyThreadState_GET();
30801
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
618
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
619 #ifdef USE_STACKCHECK
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
620 if (PyOS_CheckStack()) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
621 --tstate->recursion_depth;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
622 PyErr_SetString(PyExc_MemoryError, "Stack overflow");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
623 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
624 }
30801
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
625 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
626 if (tstate->recursion_depth > recursion_limit) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
627 --tstate->recursion_depth;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
628 PyErr_Format(PyExc_RuntimeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
629 "maximum recursion depth exceeded%s",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
630 where);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
631 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
632 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
633 _Py_CheckRecursionLimit = recursion_limit;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
634 return 0;
30801
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
635 }
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
636
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
637 /* 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
638 enum why_code {
62457
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
639 WHY_NOT = 0x0001, /* No error */
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
640 WHY_EXCEPTION = 0x0002, /* Exception occurred */
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
641 WHY_RERAISE = 0x0004, /* Exception re-raised by 'finally' */
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
642 WHY_RETURN = 0x0008, /* 'return' statement */
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
643 WHY_BREAK = 0x0010, /* 'break' statement */
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
644 WHY_CONTINUE = 0x0020, /* 'continue' statement */
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
645 WHY_YIELD = 0x0040 /* 'yield' operator */
31875
1fb2313ac3ce Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents: 31874
diff changeset
646 };
1fb2313ac3ce Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents: 31874
diff changeset
647
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
648 static enum why_code do_raise(PyObject *, PyObject *, PyObject *);
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
649 static int unpack_iterable(PyObject *, int, PyObject **);
5018
001a5042b181 Cleanup:
Guido van Rossum <guido@python.org>
parents: 5014
diff changeset
650
49940
3344804f327d Speed up Python (according to pybench and 2to3-on-itself) by 1-2% by caching
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 48077
diff changeset
651 /* Records whether tracing is on for any thread. Counts the number of
3344804f327d Speed up Python (according to pybench and 2to3-on-itself) by 1-2% by caching
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 48077
diff changeset
652 threads for which tstate->c_tracefunc is non-NULL, so if the value
3344804f327d Speed up Python (according to pybench and 2to3-on-itself) by 1-2% by caching
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 48077
diff changeset
653 is 0, we know we don't have to check this thread's c_tracefunc.
3344804f327d Speed up Python (according to pybench and 2to3-on-itself) by 1-2% by caching
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 48077
diff changeset
654 This speeds up the if statement in PyEval_EvalFrameEx() after
3344804f327d Speed up Python (according to pybench and 2to3-on-itself) by 1-2% by caching
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 48077
diff changeset
655 fast_next_opcode*/
3344804f327d Speed up Python (according to pybench and 2to3-on-itself) by 1-2% by caching
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 48077
diff changeset
656 static int _Py_TracingPossible = 0;
3344804f327d Speed up Python (according to pybench and 2to3-on-itself) by 1-2% by caching
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 48077
diff changeset
657
25108
3a26e352f0a6 replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents: 25078
diff changeset
658 /* for manipulating the thread switch and periodic "stuff" - used to be
3a26e352f0a6 replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents: 25078
diff changeset
659 per thread, now just a pair o' globals */
25109
00b6dd414b80 Bump default check interval to 100 instructions. Computers are much faster
Skip Montanaro <skip@pobox.com>
parents: 25108
diff changeset
660 int _Py_CheckInterval = 100;
50674
c8f793e159bb Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50204
diff changeset
661 volatile int _Py_Ticker = 0; /* so that we hit a "tick" first thing */
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
662
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
663 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
664 PyEval_EvalCode(PyCodeObject *co, PyObject *globals, PyObject *locals)
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
665 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
666 return PyEval_EvalCodeEx(co,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
667 globals, locals,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
668 (PyObject **)NULL, 0,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
669 (PyObject **)NULL, 0,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
670 (PyObject **)NULL, 0,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
671 NULL);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
672 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
673
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
674
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
675 /* Interpreter main loop */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
676
32421
485d2ef43419 Patch #966493: Cleanup generator/eval_frame exposure.
Martin v. Löwis <martin@v.loewis.de>
parents: 32412
diff changeset
677 PyObject *
35298
b2fe5f8fcfdd PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents: 35126
diff changeset
678 PyEval_EvalFrame(PyFrameObject *f) {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
679 /* This is for backward compatibility with extension modules that
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
680 used this API; core interpreter code should call
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
681 PyEval_EvalFrameEx() */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
682 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
683 }
b2fe5f8fcfdd PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents: 35126
diff changeset
684
b2fe5f8fcfdd PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents: 35126
diff changeset
685 PyObject *
37597
2b2e9c388fbb low-hanging fruit in Python/ - g++ still hates all the enum_kind declarations
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37564
diff changeset
686 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
687 {
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
688 #ifdef DXPAIRS
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
689 int lastopcode = 0;
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
690 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
691 register PyObject **stack_pointer; /* Next free slot in value stack */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
692 register unsigned char *next_instr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
693 register int opcode; /* Current opcode */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
694 register int oparg; /* Current opcode argument, if any */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
695 register enum why_code why; /* Reason for block stack unwind */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
696 register int err; /* Error status -- nonzero if error */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
697 register PyObject *x; /* Result object -- NULL if error */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
698 register PyObject *v; /* Temporary objects popped off stack */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
699 register PyObject *w;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
700 register PyObject *u;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
701 register PyObject *t;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
702 register PyObject *stream = NULL; /* for PRINT opcodes */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
703 register PyObject **fastlocals, **freevars;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
704 PyObject *retval = NULL; /* Return value */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
705 PyThreadState *tstate = PyThreadState_GET();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
706 PyCodeObject *co;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
707
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
708 /* when tracing we set things up so that
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
709
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
710 not (instr_lb <= current_bytecode_offset < instr_ub)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
711
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
712 is true when the line being executed has changed. The
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
713 initial values are such as to make this false the first
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
714 time it is tested. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
715 int instr_ub = -1, instr_lb = 0, instr_prev = -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
716
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
717 unsigned char *first_instr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
718 PyObject *names;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
719 PyObject *consts;
35745
407c3dacbd7c Fix some mods that got dropped from the AST merge
Neal Norwitz <nnorwitz@gmail.com>
parents: 35742
diff changeset
720 #if defined(Py_DEBUG) || defined(LLTRACE)
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
721 /* Make it easier to find out where we are with a debugger */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
722 char *filename;
1016
a41e3ba5b47d Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents: 974
diff changeset
723 #endif
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
724
24232
e06b1ab0bdb8 SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents: 24190
diff changeset
725 /* 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
726
e06b1ab0bdb8 SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents: 24190
diff changeset
727 #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
728 #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
729 #else
e06b1ab0bdb8 SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents: 24190
diff changeset
730 #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
731 #endif
e06b1ab0bdb8 SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents: 24190
diff changeset
732
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
733 #ifdef WITH_TSC
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
734 /* 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
735 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
736 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
737 loop0 -- the top of the mainloop
38418
708eaf0896bf Patch 1145039.
Tim Peters <tim.peters@gmail.com>
parents: 38352
diff changeset
738 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
739 (may be skipped)
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
740 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
741 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
742
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
743 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
744 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
745 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
746 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
747 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
748
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
749 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
750 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
751 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
752
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
753 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
754 cases:
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
755
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
756 EXEC_STMT
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
757 IMPORT_STAR
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
758 IMPORT_FROM
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
759 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
760
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
761 */
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
762 uint64 inst0, inst1, loop0, loop1, intr0 = 0, intr1 = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
763 int ticked = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
764
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
765 READ_TIMESTAMP(inst0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
766 READ_TIMESTAMP(inst1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
767 READ_TIMESTAMP(loop0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
768 READ_TIMESTAMP(loop1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
769
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
770 /* shut up the compiler */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
771 opcode = 0;
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
772 #endif
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
773
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
774 /* Code access macros */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
775
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
776 #define INSTR_OFFSET() ((int)(next_instr - first_instr))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
777 #define NEXTOP() (*next_instr++)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
778 #define NEXTARG() (next_instr += 2, (next_instr[-1]<<8) + next_instr[-2])
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
779 #define PEEKARG() ((next_instr[2]<<8) + next_instr[1])
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
780 #define JUMPTO(x) (next_instr = first_instr + (x))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
781 #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
782
28302
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
783 /* OpCode prediction macros
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
784 Some opcodes tend to come in pairs thus making it possible to
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
785 predict the second code when the first is run. For example,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
786 GET_ITER is often followed by FOR_ITER. And FOR_ITER is often
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
787 followed by STORE_FAST or UNPACK_SEQUENCE.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
788
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
789 Verifying the prediction costs a single high-speed test of a register
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
790 variable against a constant. If the pairing was good, then the
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
791 processor's own internal branch predication has a high likelihood of
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
792 success, resulting in a nearly zero-overhead transition to the
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
793 next opcode. A successful prediction saves a trip through the eval-loop
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
794 including its two unpredictable branches, the HAS_ARG test and the
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
795 switch-case. Combined with the processor's internal branch prediction,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
796 a successful PREDICT has the effect of making the two opcodes run as if
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
797 they were a single new opcode with the bodies combined.
47886
c93596ec1d3d Update comment on prediction macros.
Raymond Hettinger <python@rcn.com>
parents: 47868
diff changeset
798
c93596ec1d3d Update comment on prediction macros.
Raymond Hettinger <python@rcn.com>
parents: 47868
diff changeset
799 If collecting opcode statistics, your choices are to either keep the
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
800 predictions turned-on and interpret the results as if some opcodes
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
801 had been combined or turn-off predictions so that the opcode frequency
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
802 counter updates for both opcodes.
28302
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
803 */
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
804
31487
f57f5ce22c8d SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents: 31462
diff changeset
805 #ifdef DYNAMIC_EXECUTION_PROFILE
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
806 #define PREDICT(op) if (0) goto PRED_##op
31487
f57f5ce22c8d SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents: 31462
diff changeset
807 #else
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
808 #define PREDICT(op) if (*next_instr == op) goto PRED_##op
31487
f57f5ce22c8d SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents: 31462
diff changeset
809 #endif
f57f5ce22c8d SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents: 31462
diff changeset
810
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
811 #define PREDICTED(op) PRED_##op: next_instr++
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
812 #define PREDICTED_WITH_ARG(op) PRED_##op: oparg = PEEKARG(); next_instr += 3
28302
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
813
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
814 /* Stack manipulation macros */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
815
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36475
diff changeset
816 /* 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
817 co_stacksize are ints. */
62457
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
818 #define STACK_LEVEL() ((int)(stack_pointer - f->f_valuestack))
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
819 #define EMPTY() (STACK_LEVEL() == 0)
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
820 #define TOP() (stack_pointer[-1])
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
821 #define SECOND() (stack_pointer[-2])
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
822 #define THIRD() (stack_pointer[-3])
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
823 #define FOURTH() (stack_pointer[-4])
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
824 #define PEEK(n) (stack_pointer[-(n)])
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
825 #define SET_TOP(v) (stack_pointer[-1] = (v))
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
826 #define SET_SECOND(v) (stack_pointer[-2] = (v))
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
827 #define SET_THIRD(v) (stack_pointer[-3] = (v))
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
828 #define SET_FOURTH(v) (stack_pointer[-4] = (v))
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
829 #define SET_VALUE(n, v) (stack_pointer[-(n)] = (v))
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
830 #define BASIC_STACKADJ(n) (stack_pointer += n)
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
831 #define BASIC_PUSH(v) (*stack_pointer++ = (v))
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
832 #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
833
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
834 #ifdef LLTRACE
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
835 #define PUSH(v) { (void)(BASIC_PUSH(v), \
62457
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
836 lltrace && prtrace(TOP(), "push")); \
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
837 assert(STACK_LEVEL() <= co->co_stacksize); }
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
838 #define POP() ((void)(lltrace && prtrace(TOP(), "pop")), \
62457
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
839 BASIC_POP())
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
840 #define STACKADJ(n) { (void)(BASIC_STACKADJ(n), \
62457
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
841 lltrace && prtrace(TOP(), "stackadj")); \
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
842 assert(STACK_LEVEL() <= co->co_stacksize); }
44292
44c418b2bf7f Silence a warning about an unsed variable in debug builds
Christian Heimes <christian@cheimes.de>
parents: 44164
diff changeset
843 #define EXT_POP(STACK_POINTER) ((void)(lltrace && \
62457
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
844 prtrace((STACK_POINTER)[-1], "ext_pop")), \
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
845 *--(STACK_POINTER))
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
846 #else
62457
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
847 #define PUSH(v) BASIC_PUSH(v)
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
848 #define POP() BASIC_POP()
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
849 #define STACKADJ(n) BASIC_STACKADJ(n)
36695
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
850 #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
851 #endif
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
852
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
853 /* Local variable macros */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
854
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
855 #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
856
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
857 /* 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
858 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
859 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
860 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
861 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
862 variable would be pointing to already-freed memory. */
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
863 #define SETLOCAL(i, value) do { PyObject *tmp = GETLOCAL(i); \
62457
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
864 GETLOCAL(i) = value; \
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
865 Py_XDECREF(tmp); } while (0)
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
866
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
867 /* Start of code */
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
868
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
869 if (f == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
870 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
871
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
872 /* push frame */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
873 if (Py_EnterRecursiveCall(""))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
874 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
875
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
876 tstate->frame = f;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
877
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
878 if (tstate->use_tracing) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
879 if (tstate->c_tracefunc != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
880 /* tstate->c_tracefunc, if defined, is a
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
881 function that will be called on *every* entry
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
882 to a code block. Its return value, if not
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
883 None, is a function that will be called at
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
884 the start of each executed line of code.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
885 (Actually, the function must return itself
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
886 in order to continue tracing.) The trace
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
887 functions are called with three arguments:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
888 a pointer to the current frame, a string
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
889 indicating why the function is called, and
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
890 an argument which depends on the situation.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
891 The global trace function is also called
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
892 whenever an exception is detected. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
893 if (call_trace_protected(tstate->c_tracefunc,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
894 tstate->c_traceobj,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
895 f, PyTrace_CALL, Py_None)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
896 /* Trace function raised an error */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
897 goto exit_eval_frame;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
898 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
899 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
900 if (tstate->c_profilefunc != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
901 /* Similar for c_profilefunc, except it needn't
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
902 return itself and isn't called for "line" events */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
903 if (call_trace_protected(tstate->c_profilefunc,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
904 tstate->c_profileobj,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
905 f, PyTrace_CALL, Py_None)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
906 /* Profile function raised an error */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
907 goto exit_eval_frame;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
908 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
909 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
910 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
911
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
912 co = f->f_code;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
913 names = co->co_names;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
914 consts = co->co_consts;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
915 fastlocals = f->f_localsplus;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
916 freevars = f->f_localsplus + co->co_nlocals;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
917 first_instr = (unsigned char*) PyString_AS_STRING(co->co_code);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
918 /* An explanation is in order for the next line.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
919
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
920 f->f_lasti now refers to the index of the last instruction
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
921 executed. You might think this was obvious from the name, but
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
922 this wasn't always true before 2.3! PyFrame_New now sets
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
923 f->f_lasti to -1 (i.e. the index *before* the first instruction)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
924 and YIELD_VALUE doesn't fiddle with f_lasti any more. So this
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
925 does work. Promise.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
926
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
927 When the PREDICT() macros are enabled, some opcode pairs follow in
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
928 direct succession without updating f->f_lasti. A successful
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
929 prediction effectively links the two codes together as if they
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
930 were a single new opcode; accordingly,f->f_lasti will point to
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
931 the first code in the pair (for instance, GET_ITER followed by
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
932 FOR_ITER is effectively a single opcode and f->f_lasti will point
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
933 at to the beginning of the combined pair.)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
934 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
935 next_instr = first_instr + f->f_lasti + 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
936 stack_pointer = f->f_stacktop;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
937 assert(stack_pointer != NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
938 f->f_stacktop = NULL; /* remains NULL unless yield suspends frame */
26109
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 26079
diff changeset
939
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
940 #ifdef LLTRACE
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
941 lltrace = PyDict_GetItemString(f->f_globals, "__lltrace__") != 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
942 #endif
35745
407c3dacbd7c Fix some mods that got dropped from the AST merge
Neal Norwitz <nnorwitz@gmail.com>
parents: 35742
diff changeset
943 #if defined(Py_DEBUG) || defined(LLTRACE)
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
944 filename = PyString_AsString(co->co_filename);
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
945 #endif
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
946
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
947 why = WHY_NOT;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
948 err = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
949 x = Py_None; /* Not a reference, just anything non-NULL */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
950 w = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
951
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
952 if (throwflag) { /* support for generator.throw() */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
953 why = WHY_EXCEPTION;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
954 goto on_error;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
955 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
956
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
957 for (;;) {
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
958 #ifdef WITH_TSC
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
959 if (inst1 == 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
960 /* Almost surely, the opcode executed a break
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
961 or a continue, preventing inst1 from being set
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
962 on the way out of the loop.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
963 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
964 READ_TIMESTAMP(inst1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
965 loop1 = inst1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
966 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
967 dump_tsc(opcode, ticked, inst0, inst1, loop0, loop1,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
968 intr0, intr1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
969 ticked = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
970 inst1 = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
971 intr0 = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
972 intr1 = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
973 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
974 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
975 assert(stack_pointer >= f->f_valuestack); /* else underflow */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
976 assert(STACK_LEVEL() <= co->co_stacksize); /* else overflow */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
977
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
978 /* Do periodic things. Doing this every time through
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
979 the loop would add too much overhead, so we do it
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
980 only every Nth instruction. We also do it if
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
981 ``pendingcalls_to_do'' is set, i.e. when an asynchronous
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
982 event needs attention (e.g. a signal handler or
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
983 async I/O handler); see Py_AddPendingCall() and
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
984 Py_MakePendingCalls() above. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
985
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
986 if (--_Py_Ticker < 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
987 if (*next_instr == SETUP_FINALLY) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
988 /* Make the last opcode before
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
989 a try: finally: block uninterruptable. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
990 goto fast_next_opcode;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
991 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
992 _Py_Ticker = _Py_CheckInterval;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
993 tstate->tick_counter++;
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
994 #ifdef WITH_TSC
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
995 ticked = 1;
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
996 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
997 if (pendingcalls_to_do) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
998 if (Py_MakePendingCalls() < 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
999 why = WHY_EXCEPTION;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1000 goto on_error;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1001 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1002 if (pendingcalls_to_do)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1003 /* MakePendingCalls() didn't succeed.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1004 Force early re-execution of this
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1005 "periodic" code, possibly after
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1006 a thread switch */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1007 _Py_Ticker = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1008 }
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
1009 #ifdef WITH_THREAD
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1010 if (interpreter_lock) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1011 /* Give another thread a chance */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1012
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1013 if (PyThreadState_Swap(NULL) != tstate)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1014 Py_FatalError("ceval: tstate mix-up");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1015 PyThread_release_lock(interpreter_lock);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1016
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1017 /* Other threads may run now */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1018
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1019 PyThread_acquire_lock(interpreter_lock, 1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1020 if (PyThreadState_Swap(tstate) != NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1021 Py_FatalError("ceval: orphan tstate");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1022
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1023 /* Check for thread interrupts */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1024
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1025 if (tstate->async_exc != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1026 x = tstate->async_exc;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1027 tstate->async_exc = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1028 PyErr_SetNone(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1029 Py_DECREF(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1030 why = WHY_EXCEPTION;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1031 goto on_error;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1032 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1033 }
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
1034 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1035 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1036
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1037 fast_next_opcode:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1038 f->f_lasti = INSTR_OFFSET();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1039
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1040 /* line-by-line tracing support */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1041
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1042 if (_Py_TracingPossible &&
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1043 tstate->c_tracefunc != NULL && !tstate->tracing) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1044 /* see maybe_call_line_trace
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1045 for expository comments */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1046 f->f_stacktop = stack_pointer;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1047
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1048 err = maybe_call_line_trace(tstate->c_tracefunc,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1049 tstate->c_traceobj,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1050 f, &instr_lb, &instr_ub,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1051 &instr_prev);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1052 /* Reload possibly changed frame fields */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1053 JUMPTO(f->f_lasti);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1054 if (f->f_stacktop != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1055 stack_pointer = f->f_stacktop;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1056 f->f_stacktop = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1057 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1058 if (err) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1059 /* trace function raised an exception */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1060 goto on_error;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1061 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1062 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1063
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1064 /* Extract opcode and argument */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1065
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1066 opcode = NEXTOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1067 oparg = 0; /* allows oparg to be stored in a register because
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1068 it doesn't have to be remembered across a full loop */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1069 if (HAS_ARG(opcode))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1070 oparg = NEXTARG();
62457
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
1071 dispatch_opcode:
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
1072 #ifdef DYNAMIC_EXECUTION_PROFILE
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
1073 #ifdef DXPAIRS
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1074 dxpairs[lastopcode][opcode]++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1075 lastopcode = opcode;
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
1076 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1077 dxp[opcode]++;
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
1078 #endif
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1079
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1080 #ifdef LLTRACE
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1081 /* Instruction tracing */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1082
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1083 if (lltrace) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1084 if (HAS_ARG(opcode)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1085 printf("%d: %d, %d\n",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1086 f->f_lasti, opcode, oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1087 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1088 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1089 printf("%d: %d\n",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1090 f->f_lasti, opcode);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1091 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1092 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1093 #endif
24844
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24718
diff changeset
1094
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1095 /* Main switch on opcode */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1096 READ_TIMESTAMP(inst0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1097
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1098 switch (opcode) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1099
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1100 /* BEWARE!
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1101 It is essential that any operation that fails sets either
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1102 x to NULL, err to nonzero, or why to anything but WHY_NOT,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1103 and that no operation that succeeds does this! */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1104
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1105 /* case STOP_CODE: this is an error! */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1106
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1107 case NOP:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1108 goto fast_next_opcode;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1109
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1110 case LOAD_FAST:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1111 x = GETLOCAL(oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1112 if (x != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1113 Py_INCREF(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1114 PUSH(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1115 goto fast_next_opcode;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1116 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1117 format_exc_check_arg(PyExc_UnboundLocalError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1118 UNBOUNDLOCAL_ERROR_MSG,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1119 PyTuple_GetItem(co->co_varnames, oparg));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1120 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1121
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1122 case LOAD_CONST:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1123 x = GETITEM(consts, oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1124 Py_INCREF(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1125 PUSH(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1126 goto fast_next_opcode;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1127
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1128 PREDICTED_WITH_ARG(STORE_FAST);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1129 case STORE_FAST:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1130 v = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1131 SETLOCAL(oparg, v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1132 goto fast_next_opcode;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1133
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1134 case POP_TOP:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1135 v = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1136 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1137 goto fast_next_opcode;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1138
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1139 case ROT_TWO:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1140 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1141 w = SECOND();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1142 SET_TOP(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1143 SET_SECOND(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1144 goto fast_next_opcode;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1145
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1146 case ROT_THREE:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1147 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1148 w = SECOND();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1149 x = THIRD();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1150 SET_TOP(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1151 SET_SECOND(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1152 SET_THIRD(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1153 goto fast_next_opcode;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1154
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1155 case ROT_FOUR:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1156 u = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1157 v = SECOND();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1158 w = THIRD();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1159 x = FOURTH();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1160 SET_TOP(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1161 SET_SECOND(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1162 SET_THIRD(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1163 SET_FOURTH(u);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1164 goto fast_next_opcode;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1165
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1166 case DUP_TOP:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1167 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1168 Py_INCREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1169 PUSH(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1170 goto fast_next_opcode;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1171
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1172 case DUP_TOPX:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1173 if (oparg == 2) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1174 x = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1175 Py_INCREF(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1176 w = SECOND();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1177 Py_INCREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1178 STACKADJ(2);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1179 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1180 SET_SECOND(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1181 goto fast_next_opcode;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1182 } else if (oparg == 3) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1183 x = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1184 Py_INCREF(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1185 w = SECOND();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1186 Py_INCREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1187 v = THIRD();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1188 Py_INCREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1189 STACKADJ(3);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1190 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1191 SET_SECOND(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1192 SET_THIRD(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1193 goto fast_next_opcode;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1194 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1195 Py_FatalError("invalid argument to DUP_TOPX"
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1196 " (bytecode corruption?)");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1197 /* Never returns, so don't bother to set why. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1198 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1199
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1200 case UNARY_POSITIVE:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1201 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1202 x = PyNumber_Positive(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1203 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1204 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1205 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1206 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1207
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1208 case UNARY_NEGATIVE:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1209 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1210 x = PyNumber_Negative(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1211 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1212 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1213 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1214 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1215
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1216 case UNARY_NOT:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1217 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1218 err = PyObject_IsTrue(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1219 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1220 if (err == 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1221 Py_INCREF(Py_True);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1222 SET_TOP(Py_True);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1223 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1224 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1225 else if (err > 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1226 Py_INCREF(Py_False);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1227 SET_TOP(Py_False);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1228 err = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1229 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1230 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1231 STACKADJ(-1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1232 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1233
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1234 case UNARY_CONVERT:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1235 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1236 x = PyObject_Repr(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1237 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1238 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1239 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1240 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1241
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1242 case UNARY_INVERT:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1243 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1244 x = PyNumber_Invert(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1245 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1246 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1247 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1248 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1249
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1250 case BINARY_POWER:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1251 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1252 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1253 x = PyNumber_Power(v, w, Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1254 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1255 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1256 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1257 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1258 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1259
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1260 case BINARY_MULTIPLY:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1261 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1262 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1263 x = PyNumber_Multiply(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1264 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1265 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1266 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1267 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1268 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1269
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1270 case BINARY_DIVIDE:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1271 if (!_Py_QnewFlag) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1272 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1273 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1274 x = PyNumber_Divide(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1275 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1276 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1277 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1278 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1279 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1280 }
62457
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
1281 /* -Qnew is in effect: fall through to
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1282 BINARY_TRUE_DIVIDE */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1283 case BINARY_TRUE_DIVIDE:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1284 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1285 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1286 x = PyNumber_TrueDivide(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1287 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1288 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1289 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1290 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1291 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1292
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1293 case BINARY_FLOOR_DIVIDE:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1294 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1295 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1296 x = PyNumber_FloorDivide(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1297 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1298 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1299 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1300 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1301 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1302
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1303 case BINARY_MODULO:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1304 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1305 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1306 if (PyString_CheckExact(v))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1307 x = PyString_Format(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1308 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1309 x = PyNumber_Remainder(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1310 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1311 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1312 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1313 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1314 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1315
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1316 case BINARY_ADD:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1317 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1318 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1319 if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1320 /* INLINE: int + int */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1321 register long a, b, i;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1322 a = PyInt_AS_LONG(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1323 b = PyInt_AS_LONG(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1324 /* cast to avoid undefined behaviour
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1325 on overflow */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1326 i = (long)((unsigned long)a + b);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1327 if ((i^a) < 0 && (i^b) < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1328 goto slow_add;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1329 x = PyInt_FromLong(i);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1330 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1331 else if (PyString_CheckExact(v) &&
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1332 PyString_CheckExact(w)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1333 x = string_concatenate(v, w, f, next_instr);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1334 /* string_concatenate consumed the ref to v */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1335 goto skip_decref_vx;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1336 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1337 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1338 slow_add:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1339 x = PyNumber_Add(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1340 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1341 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1342 skip_decref_vx:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1343 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1344 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1345 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1346 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1347
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1348 case BINARY_SUBTRACT:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1349 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1350 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1351 if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1352 /* INLINE: int - int */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1353 register long a, b, i;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1354 a = PyInt_AS_LONG(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1355 b = PyInt_AS_LONG(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1356 /* cast to avoid undefined behaviour
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1357 on overflow */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1358 i = (long)((unsigned long)a - b);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1359 if ((i^a) < 0 && (i^~b) < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1360 goto slow_sub;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1361 x = PyInt_FromLong(i);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1362 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1363 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1364 slow_sub:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1365 x = PyNumber_Subtract(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1366 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1367 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1368 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1369 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1370 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1371 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1372
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1373 case BINARY_SUBSCR:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1374 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1375 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1376 if (PyList_CheckExact(v) && PyInt_CheckExact(w)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1377 /* INLINE: list[int] */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1378 Py_ssize_t i = PyInt_AsSsize_t(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1379 if (i < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1380 i += PyList_GET_SIZE(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1381 if (i >= 0 && i < PyList_GET_SIZE(v)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1382 x = PyList_GET_ITEM(v, i);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1383 Py_INCREF(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1384 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1385 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1386 goto slow_get;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1387 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1388 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1389 slow_get:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1390 x = PyObject_GetItem(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1391 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1392 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1393 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1394 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1395 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1396
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1397 case BINARY_LSHIFT:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1398 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1399 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1400 x = PyNumber_Lshift(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1401 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1402 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1403 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1404 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1405 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1406
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1407 case BINARY_RSHIFT:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1408 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1409 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1410 x = PyNumber_Rshift(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1411 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1412 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1413 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1414 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1415 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1416
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1417 case BINARY_AND:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1418 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1419 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1420 x = PyNumber_And(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1421 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1422 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1423 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1424 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1425 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1426
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1427 case BINARY_XOR:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1428 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1429 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1430 x = PyNumber_Xor(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1431 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1432 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1433 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1434 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1435 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1436
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1437 case BINARY_OR:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1438 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1439 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1440 x = PyNumber_Or(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1441 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1442 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1443 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1444 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1445 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1446
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1447 case LIST_APPEND:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1448 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1449 v = PEEK(oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1450 err = PyList_Append(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1451 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1452 if (err == 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1453 PREDICT(JUMP_ABSOLUTE);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1454 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1455 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1456 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1457
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1458 case SET_ADD:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1459 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1460 v = stack_pointer[-oparg];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1461 err = PySet_Add(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1462 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1463 if (err == 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1464 PREDICT(JUMP_ABSOLUTE);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1465 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1466 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1467 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1468
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1469 case INPLACE_POWER:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1470 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1471 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1472 x = PyNumber_InPlacePower(v, w, Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1473 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1474 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1475 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1476 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1477 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1478
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1479 case INPLACE_MULTIPLY:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1480 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1481 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1482 x = PyNumber_InPlaceMultiply(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1483 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1484 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1485 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1486 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1487 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1488
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1489 case INPLACE_DIVIDE:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1490 if (!_Py_QnewFlag) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1491 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1492 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1493 x = PyNumber_InPlaceDivide(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1494 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1495 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1496 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1497 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1498 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1499 }
62457
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
1500 /* -Qnew is in effect: fall through to
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1501 INPLACE_TRUE_DIVIDE */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1502 case INPLACE_TRUE_DIVIDE:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1503 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1504 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1505 x = PyNumber_InPlaceTrueDivide(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1506 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1507 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1508 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1509 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1510 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1511
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1512 case INPLACE_FLOOR_DIVIDE:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1513 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1514 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1515 x = PyNumber_InPlaceFloorDivide(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1516 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1517 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1518 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1519 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1520 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1521
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1522 case INPLACE_MODULO:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1523 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1524 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1525 x = PyNumber_InPlaceRemainder(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1526 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1527 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1528 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1529 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1530 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1531
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1532 case INPLACE_ADD:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1533 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1534 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1535 if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1536 /* INLINE: int + int */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1537 register long a, b, i;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1538 a = PyInt_AS_LONG(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1539 b = PyInt_AS_LONG(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1540 i = a + b;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1541 if ((i^a) < 0 && (i^b) < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1542 goto slow_iadd;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1543 x = PyInt_FromLong(i);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1544 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1545 else if (PyString_CheckExact(v) &&
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1546 PyString_CheckExact(w)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1547 x = string_concatenate(v, w, f, next_instr);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1548 /* string_concatenate consumed the ref to v */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1549 goto skip_decref_v;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1550 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1551 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1552 slow_iadd:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1553 x = PyNumber_InPlaceAdd(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1554 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1555 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1556 skip_decref_v:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1557 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1558 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1559 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1560 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1561
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1562 case INPLACE_SUBTRACT:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1563 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1564 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1565 if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1566 /* INLINE: int - int */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1567 register long a, b, i;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1568 a = PyInt_AS_LONG(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1569 b = PyInt_AS_LONG(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1570 i = a - b;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1571 if ((i^a) < 0 && (i^~b) < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1572 goto slow_isub;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1573 x = PyInt_FromLong(i);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1574 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1575 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1576 slow_isub:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1577 x = PyNumber_InPlaceSubtract(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1578 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1579 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1580 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1581 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1582 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1583 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1584
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1585 case INPLACE_LSHIFT:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1586 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1587 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1588 x = PyNumber_InPlaceLshift(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1589 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1590 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1591 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1592 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1593 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1594
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1595 case INPLACE_RSHIFT:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1596 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1597 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1598 x = PyNumber_InPlaceRshift(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1599 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1600 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1601 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1602 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1603 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1604
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1605 case INPLACE_AND:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1606 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1607 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1608 x = PyNumber_InPlaceAnd(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1609 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1610 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1611 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1612 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1613 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1614
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1615 case INPLACE_XOR:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1616 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1617 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1618 x = PyNumber_InPlaceXor(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1619 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1620 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1621 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1622 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1623 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1624
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1625 case INPLACE_OR:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1626 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1627 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1628 x = PyNumber_InPlaceOr(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1629 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1630 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1631 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1632 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1633 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1634
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1635 case SLICE+0:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1636 case SLICE+1:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1637 case SLICE+2:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1638 case SLICE+3:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1639 if ((opcode-SLICE) & 2)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1640 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1641 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1642 w = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1643 if ((opcode-SLICE) & 1)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1644 v = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1645 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1646 v = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1647 u = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1648 x = apply_slice(u, v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1649 Py_DECREF(u);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1650 Py_XDECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1651 Py_XDECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1652 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1653 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1654 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1655
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1656 case STORE_SLICE+0:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1657 case STORE_SLICE+1:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1658 case STORE_SLICE+2:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1659 case STORE_SLICE+3:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1660 if ((opcode-STORE_SLICE) & 2)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1661 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1662 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1663 w = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1664 if ((opcode-STORE_SLICE) & 1)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1665 v = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1666 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1667 v = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1668 u = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1669 t = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1670 err = assign_slice(u, v, w, t); /* u[v:w] = t */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1671 Py_DECREF(t);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1672 Py_DECREF(u);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1673 Py_XDECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1674 Py_XDECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1675 if (err == 0) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1676 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1677
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1678 case DELETE_SLICE+0:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1679 case DELETE_SLICE+1:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1680 case DELETE_SLICE+2:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1681 case DELETE_SLICE+3:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1682 if ((opcode-DELETE_SLICE) & 2)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1683 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1684 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1685 w = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1686 if ((opcode-DELETE_SLICE) & 1)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1687 v = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1688 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1689 v = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1690 u = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1691 err = assign_slice(u, v, w, (PyObject *)NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1692 /* del u[v:w] */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1693 Py_DECREF(u);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1694 Py_XDECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1695 Py_XDECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1696 if (err == 0) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1697 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1698
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1699 case STORE_SUBSCR:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1700 w = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1701 v = SECOND();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1702 u = THIRD();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1703 STACKADJ(-3);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1704 /* v[w] = u */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1705 err = PyObject_SetItem(v, w, u);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1706 Py_DECREF(u);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1707 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1708 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1709 if (err == 0) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1710 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1711
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1712 case DELETE_SUBSCR:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1713 w = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1714 v = SECOND();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1715 STACKADJ(-2);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1716 /* del v[w] */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1717 err = PyObject_DelItem(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1718 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1719 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1720 if (err == 0) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1721 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1722
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1723 case PRINT_EXPR:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1724 v = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1725 w = PySys_GetObject("displayhook");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1726 if (w == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1727 PyErr_SetString(PyExc_RuntimeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1728 "lost sys.displayhook");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1729 err = -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1730 x = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1731 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1732 if (err == 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1733 x = PyTuple_Pack(1, v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1734 if (x == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1735 err = -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1736 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1737 if (err == 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1738 w = PyEval_CallObject(w, x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1739 Py_XDECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1740 if (w == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1741 err = -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1742 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1743 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1744 Py_XDECREF(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1745 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1746
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1747 case PRINT_ITEM_TO:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1748 w = stream = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1749 /* fall through to PRINT_ITEM */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1750
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1751 case PRINT_ITEM:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1752 v = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1753 if (stream == NULL || stream == Py_None) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1754 w = PySys_GetObject("stdout");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1755 if (w == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1756 PyErr_SetString(PyExc_RuntimeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1757 "lost sys.stdout");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1758 err = -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1759 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1760 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1761 /* PyFile_SoftSpace() can exececute arbitrary code
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1762 if sys.stdout is an instance with a __getattr__.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1763 If __getattr__ raises an exception, w will
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1764 be freed, so we need to prevent that temporarily. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1765 Py_XINCREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1766 if (w != NULL && PyFile_SoftSpace(w, 0))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1767 err = PyFile_WriteString(" ", w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1768 if (err == 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1769 err = PyFile_WriteObject(v, w, Py_PRINT_RAW);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1770 if (err == 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1771 /* XXX move into writeobject() ? */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1772 if (PyString_Check(v)) {
62457
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
1773 char *s = PyString_AS_STRING(v);
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
1774 Py_ssize_t len = PyString_GET_SIZE(v);
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
1775 if (len == 0 ||
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
1776 !isspace(Py_CHARMASK(s[len-1])) ||
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
1777 s[len-1] == ' ')
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
1778 PyFile_SoftSpace(w, 1);
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1779 }
21475
aac23331a25d Patch #494384: Disable more Unicode API if Unicode is not used.
Martin v. Löwis <martin@v.loewis.de>
parents: 21441
diff changeset
1780 #ifdef Py_USING_UNICODE
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1781 else if (PyUnicode_Check(v)) {
62457
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
1782 Py_UNICODE *s = PyUnicode_AS_UNICODE(v);
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
1783 Py_ssize_t len = PyUnicode_GET_SIZE(v);
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
1784 if (len == 0 ||
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
1785 !Py_UNICODE_ISSPACE(s[len-1]) ||
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
1786 s[len-1] == ' ')
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
1787 PyFile_SoftSpace(w, 1);
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1788 }
23479
73249abed683 Fix for
Michael W. Hudson <mwh@python.net>
parents: 23156
diff changeset
1789 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1790 else
62457
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
1791 PyFile_SoftSpace(w, 1);
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1792 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1793 Py_XDECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1794 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1795 Py_XDECREF(stream);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1796 stream = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1797 if (err == 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1798 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1799 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1800
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1801 case PRINT_NEWLINE_TO:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1802 w = stream = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1803 /* fall through to PRINT_NEWLINE */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1804
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1805 case PRINT_NEWLINE:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1806 if (stream == NULL || stream == Py_None) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1807 w = PySys_GetObject("stdout");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1808 if (w == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1809 PyErr_SetString(PyExc_RuntimeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1810 "lost sys.stdout");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1811 why = WHY_EXCEPTION;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1812 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1813 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1814 if (w != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1815 /* w.write() may replace sys.stdout, so we
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1816 * have to keep our reference to it */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1817 Py_INCREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1818 err = PyFile_WriteString("\n", w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1819 if (err == 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1820 PyFile_SoftSpace(w, 0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1821 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1822 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1823 Py_XDECREF(stream);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1824 stream = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1825 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1826
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1827
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1828 #ifdef CASE_TOO_BIG
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1829 default: switch (opcode) {
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1830 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1831 case RAISE_VARARGS:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1832 u = v = w = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1833 switch (oparg) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1834 case 3:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1835 u = POP(); /* traceback */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1836 /* Fallthrough */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1837 case 2:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1838 v = POP(); /* value */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1839 /* Fallthrough */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1840 case 1:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1841 w = POP(); /* exc */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1842 case 0: /* Fallthrough */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1843 why = do_raise(w, v, u);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1844 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1845 default:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1846 PyErr_SetString(PyExc_SystemError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1847 "bad RAISE_VARARGS oparg");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1848 why = WHY_EXCEPTION;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1849 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1850 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1851 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1852
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1853 case LOAD_LOCALS:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1854 if ((x = f->f_locals) != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1855 Py_INCREF(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1856 PUSH(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1857 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1858 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1859 PyErr_SetString(PyExc_SystemError, "no locals");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1860 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1861
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1862 case RETURN_VALUE:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1863 retval = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1864 why = WHY_RETURN;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1865 goto fast_block_end;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1866
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1867 case YIELD_VALUE:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1868 retval = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1869 f->f_stacktop = stack_pointer;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1870 why = WHY_YIELD;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1871 goto fast_yield;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1872
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1873 case EXEC_STMT:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1874 w = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1875 v = SECOND();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1876 u = THIRD();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1877 STACKADJ(-3);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1878 READ_TIMESTAMP(intr0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1879 err = exec_statement(f, u, v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1880 READ_TIMESTAMP(intr1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1881 Py_DECREF(u);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1882 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1883 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1884 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1885
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1886 case POP_BLOCK:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1887 {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1888 PyTryBlock *b = PyFrame_BlockPop(f);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1889 while (STACK_LEVEL() > b->b_level) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1890 v = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1891 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1892 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1893 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1894 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1895
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1896 PREDICTED(END_FINALLY);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1897 case END_FINALLY:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1898 v = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1899 if (PyInt_Check(v)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1900 why = (enum why_code) PyInt_AS_LONG(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1901 assert(why != WHY_YIELD);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1902 if (why == WHY_RETURN ||
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1903 why == WHY_CONTINUE)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1904 retval = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1905 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1906 else if (PyExceptionClass_Check(v) ||
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1907 PyString_Check(v)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1908 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1909 u = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1910 PyErr_Restore(v, w, u);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1911 why = WHY_RERAISE;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1912 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1913 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1914 else if (v != Py_None) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1915 PyErr_SetString(PyExc_SystemError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1916 "'finally' pops bad exception");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1917 why = WHY_EXCEPTION;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1918 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1919 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1920 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1921
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1922 case BUILD_CLASS:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1923 u = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1924 v = SECOND();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1925 w = THIRD();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1926 STACKADJ(-2);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1927 x = build_class(u, v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1928 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1929 Py_DECREF(u);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1930 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1931 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1932 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1933
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1934 case STORE_NAME:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1935 w = GETITEM(names, oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1936 v = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1937 if ((x = f->f_locals) != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1938 if (PyDict_CheckExact(x))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1939 err = PyDict_SetItem(x, w, v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1940 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1941 err = PyObject_SetItem(x, w, v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1942 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1943 if (err == 0) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1944 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1945 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1946 PyErr_Format(PyExc_SystemError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1947 "no locals found when storing %s",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1948 PyObject_REPR(w));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1949 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1950
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1951 case DELETE_NAME:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1952 w = GETITEM(names, oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1953 if ((x = f->f_locals) != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1954 if ((err = PyObject_DelItem(x, w)) != 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1955 format_exc_check_arg(PyExc_NameError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1956 NAME_ERROR_MSG,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1957 w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1958 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1959 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1960 PyErr_Format(PyExc_SystemError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1961 "no locals when deleting %s",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1962 PyObject_REPR(w));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1963 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1964
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1965 PREDICTED_WITH_ARG(UNPACK_SEQUENCE);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1966 case UNPACK_SEQUENCE:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1967 v = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1968 if (PyTuple_CheckExact(v) &&
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1969 PyTuple_GET_SIZE(v) == oparg) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1970 PyObject **items = \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1971 ((PyTupleObject *)v)->ob_item;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1972 while (oparg--) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1973 w = items[oparg];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1974 Py_INCREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1975 PUSH(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1976 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1977 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1978 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1979 } else if (PyList_CheckExact(v) &&
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1980 PyList_GET_SIZE(v) == oparg) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1981 PyObject **items = \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1982 ((PyListObject *)v)->ob_item;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1983 while (oparg--) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1984 w = items[oparg];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1985 Py_INCREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1986 PUSH(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1987 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1988 } else if (unpack_iterable(v, oparg,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1989 stack_pointer + oparg)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1990 STACKADJ(oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1991 } else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1992 /* unpack_iterable() raised an exception */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1993 why = WHY_EXCEPTION;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1994 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1995 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1996 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1997
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1998 case STORE_ATTR:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
1999 w = GETITEM(names, oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2000 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2001 u = SECOND();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2002 STACKADJ(-2);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2003 err = PyObject_SetAttr(v, w, u); /* v.w = u */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2004 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2005 Py_DECREF(u);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2006 if (err == 0) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2007 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2008
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2009 case DELETE_ATTR:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2010 w = GETITEM(names, oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2011 v = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2012 err = PyObject_SetAttr(v, w, (PyObject *)NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2013 /* del v.w */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2014 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2015 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2016
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2017 case STORE_GLOBAL:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2018 w = GETITEM(names, oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2019 v = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2020 err = PyDict_SetItem(f->f_globals, w, v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2021 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2022 if (err == 0) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2023 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2024
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2025 case DELETE_GLOBAL:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2026 w = GETITEM(names, oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2027 if ((err = PyDict_DelItem(f->f_globals, w)) != 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2028 format_exc_check_arg(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2029 PyExc_NameError, GLOBAL_NAME_ERROR_MSG, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2030 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2031
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2032 case LOAD_NAME:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2033 w = GETITEM(names, oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2034 if ((v = f->f_locals) == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2035 PyErr_Format(PyExc_SystemError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2036 "no locals when loading %s",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2037 PyObject_REPR(w));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2038 why = WHY_EXCEPTION;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2039 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2040 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2041 if (PyDict_CheckExact(v)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2042 x = PyDict_GetItem(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2043 Py_XINCREF(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2044 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2045 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2046 x = PyObject_GetItem(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2047 if (x == NULL && PyErr_Occurred()) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2048 if (!PyErr_ExceptionMatches(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2049 PyExc_KeyError))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2050 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2051 PyErr_Clear();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2052 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2053 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2054 if (x == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2055 x = PyDict_GetItem(f->f_globals, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2056 if (x == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2057 x = PyDict_GetItem(f->f_builtins, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2058 if (x == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2059 format_exc_check_arg(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2060 PyExc_NameError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2061 NAME_ERROR_MSG, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2062 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2063 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2064 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2065 Py_INCREF(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2066 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2067 PUSH(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2068 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2069
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2070 case LOAD_GLOBAL:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2071 w = GETITEM(names, oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2072 if (PyString_CheckExact(w)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2073 /* Inline the PyDict_GetItem() calls.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2074 WARNING: this is an extreme speed hack.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2075 Do not try this at home. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2076 long hash = ((PyStringObject *)w)->ob_shash;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2077 if (hash != -1) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2078 PyDictObject *d;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2079 PyDictEntry *e;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2080 d = (PyDictObject *)(f->f_globals);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2081 e = d->ma_lookup(d, w, hash);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2082 if (e == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2083 x = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2084 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2085 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2086 x = e->me_value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2087 if (x != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2088 Py_INCREF(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2089 PUSH(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2090 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2091 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2092 d = (PyDictObject *)(f->f_builtins);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2093 e = d->ma_lookup(d, w, hash);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2094 if (e == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2095 x = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2096 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2097 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2098 x = e->me_value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2099 if (x != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2100 Py_INCREF(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2101 PUSH(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2102 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2103 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2104 goto load_global_error;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2105 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2106 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2107 /* This is the un-inlined version of the code above */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2108 x = PyDict_GetItem(f->f_globals, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2109 if (x == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2110 x = PyDict_GetItem(f->f_builtins, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2111 if (x == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2112 load_global_error:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2113 format_exc_check_arg(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2114 PyExc_NameError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2115 GLOBAL_NAME_ERROR_MSG, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2116 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2117 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2118 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2119 Py_INCREF(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2120 PUSH(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2121 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2122
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2123 case DELETE_FAST:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2124 x = GETLOCAL(oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2125 if (x != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2126 SETLOCAL(oparg, NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2127 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2128 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2129 format_exc_check_arg(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2130 PyExc_UnboundLocalError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2131 UNBOUNDLOCAL_ERROR_MSG,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2132 PyTuple_GetItem(co->co_varnames, oparg)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2133 );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2134 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2135
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2136 case LOAD_CLOSURE:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2137 x = freevars[oparg];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2138 Py_INCREF(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2139 PUSH(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2140 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2141 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2142
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2143 case LOAD_DEREF:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2144 x = freevars[oparg];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2145 w = PyCell_Get(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2146 if (w != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2147 PUSH(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2148 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2149 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2150 err = -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2151 /* Don't stomp existing exception */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2152 if (PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2153 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2154 if (oparg < PyTuple_GET_SIZE(co->co_cellvars)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2155 v = PyTuple_GET_ITEM(co->co_cellvars,
62457
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
2156 oparg);
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
2157 format_exc_check_arg(
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2158 PyExc_UnboundLocalError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2159 UNBOUNDLOCAL_ERROR_MSG,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2160 v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2161 } else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2162 v = PyTuple_GET_ITEM(co->co_freevars, oparg -
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2163 PyTuple_GET_SIZE(co->co_cellvars));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2164 format_exc_check_arg(PyExc_NameError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2165 UNBOUNDFREE_ERROR_MSG, v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2166 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2167 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2168
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2169 case STORE_DEREF:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2170 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2171 x = freevars[oparg];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2172 PyCell_Set(x, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2173 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2174 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2175
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2176 case BUILD_TUPLE:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2177 x = PyTuple_New(oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2178 if (x != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2179 for (; --oparg >= 0;) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2180 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2181 PyTuple_SET_ITEM(x, oparg, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2182 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2183 PUSH(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2184 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2185 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2186 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2187
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2188 case BUILD_LIST:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2189 x = PyList_New(oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2190 if (x != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2191 for (; --oparg >= 0;) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2192 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2193 PyList_SET_ITEM(x, oparg, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2194 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2195 PUSH(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2196 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2197 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2198 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2199
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2200 case BUILD_SET:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2201 x = PySet_New(NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2202 if (x != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2203 for (; --oparg >= 0;) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2204 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2205 if (err == 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2206 err = PySet_Add(x, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2207 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2208 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2209 if (err != 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2210 Py_DECREF(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2211 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2212 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2213 PUSH(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2214 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2215 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2216 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2217
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2218
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2219 case BUILD_MAP:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2220 x = _PyDict_NewPresized((Py_ssize_t)oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2221 PUSH(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2222 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2223 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2224
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2225 case STORE_MAP:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2226 w = TOP(); /* key */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2227 u = SECOND(); /* value */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2228 v = THIRD(); /* dict */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2229 STACKADJ(-2);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2230 assert (PyDict_CheckExact(v));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2231 err = PyDict_SetItem(v, w, u); /* v[w] = u */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2232 Py_DECREF(u);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2233 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2234 if (err == 0) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2235 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2236
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2237 case MAP_ADD:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2238 w = TOP(); /* key */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2239 u = SECOND(); /* value */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2240 STACKADJ(-2);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2241 v = stack_pointer[-oparg]; /* dict */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2242 assert (PyDict_CheckExact(v));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2243 err = PyDict_SetItem(v, w, u); /* v[w] = u */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2244 Py_DECREF(u);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2245 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2246 if (err == 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2247 PREDICT(JUMP_ABSOLUTE);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2248 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2249 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2250 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2251
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2252 case LOAD_ATTR:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2253 w = GETITEM(names, oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2254 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2255 x = PyObject_GetAttr(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2256 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2257 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2258 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2259 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2260
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2261 case COMPARE_OP:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2262 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2263 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2264 if (PyInt_CheckExact(w) && PyInt_CheckExact(v)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2265 /* INLINE: cmp(int, int) */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2266 register long a, b;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2267 register int res;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2268 a = PyInt_AS_LONG(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2269 b = PyInt_AS_LONG(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2270 switch (oparg) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2271 case PyCmp_LT: res = a < b; break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2272 case PyCmp_LE: res = a <= b; break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2273 case PyCmp_EQ: res = a == b; break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2274 case PyCmp_NE: res = a != b; break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2275 case PyCmp_GT: res = a > b; break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2276 case PyCmp_GE: res = a >= b; break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2277 case PyCmp_IS: res = v == w; break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2278 case PyCmp_IS_NOT: res = v != w; break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2279 default: goto slow_compare;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2280 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2281 x = res ? Py_True : Py_False;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2282 Py_INCREF(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2283 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2284 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2285 slow_compare:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2286 x = cmp_outcome(oparg, v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2287 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2288 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2289 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2290 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2291 if (x == NULL) break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2292 PREDICT(POP_JUMP_IF_FALSE);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2293 PREDICT(POP_JUMP_IF_TRUE);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2294 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2295
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2296 case IMPORT_NAME:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2297 w = GETITEM(names, oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2298 x = PyDict_GetItemString(f->f_builtins, "__import__");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2299 if (x == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2300 PyErr_SetString(PyExc_ImportError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2301 "__import__ not found");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2302 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2303 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2304 Py_INCREF(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2305 v = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2306 u = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2307 if (PyInt_AsLong(u) != -1 || PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2308 w = PyTuple_Pack(5,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2309 w,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2310 f->f_globals,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2311 f->f_locals == NULL ?
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2312 Py_None : f->f_locals,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2313 v,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2314 u);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2315 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2316 w = PyTuple_Pack(4,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2317 w,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2318 f->f_globals,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2319 f->f_locals == NULL ?
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2320 Py_None : f->f_locals,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2321 v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2322 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2323 Py_DECREF(u);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2324 if (w == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2325 u = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2326 Py_DECREF(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2327 x = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2328 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2329 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2330 READ_TIMESTAMP(intr0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2331 v = x;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2332 x = PyEval_CallObject(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2333 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2334 READ_TIMESTAMP(intr1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2335 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2336 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2337 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2338 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2339
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2340 case IMPORT_STAR:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2341 v = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2342 PyFrame_FastToLocals(f);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2343 if ((x = f->f_locals) == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2344 PyErr_SetString(PyExc_SystemError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2345 "no locals found during 'import *'");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2346 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2347 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2348 READ_TIMESTAMP(intr0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2349 err = import_all_from(x, v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2350 READ_TIMESTAMP(intr1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2351 PyFrame_LocalsToFast(f, 0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2352 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2353 if (err == 0) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2354 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2355
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2356 case IMPORT_FROM:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2357 w = GETITEM(names, oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2358 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2359 READ_TIMESTAMP(intr0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2360 x = import_from(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2361 READ_TIMESTAMP(intr1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2362 PUSH(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2363 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2364 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2365
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2366 case JUMP_FORWARD:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2367 JUMPBY(oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2368 goto fast_next_opcode;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2369
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2370 PREDICTED_WITH_ARG(POP_JUMP_IF_FALSE);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2371 case POP_JUMP_IF_FALSE:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2372 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2373 if (w == Py_True) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2374 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2375 goto fast_next_opcode;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2376 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2377 if (w == Py_False) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2378 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2379 JUMPTO(oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2380 goto fast_next_opcode;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2381 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2382 err = PyObject_IsTrue(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2383 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2384 if (err > 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2385 err = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2386 else if (err == 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2387 JUMPTO(oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2388 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2389 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2390 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2391
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2392 PREDICTED_WITH_ARG(POP_JUMP_IF_TRUE);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2393 case POP_JUMP_IF_TRUE:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2394 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2395 if (w == Py_False) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2396 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2397 goto fast_next_opcode;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2398 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2399 if (w == Py_True) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2400 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2401 JUMPTO(oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2402 goto fast_next_opcode;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2403 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2404 err = PyObject_IsTrue(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2405 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2406 if (err > 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2407 err = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2408 JUMPTO(oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2409 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2410 else if (err == 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2411 ;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2412 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2413 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2414 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2415
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2416 case JUMP_IF_FALSE_OR_POP:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2417 w = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2418 if (w == Py_True) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2419 STACKADJ(-1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2420 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2421 goto fast_next_opcode;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2422 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2423 if (w == Py_False) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2424 JUMPTO(oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2425 goto fast_next_opcode;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2426 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2427 err = PyObject_IsTrue(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2428 if (err > 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2429 STACKADJ(-1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2430 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2431 err = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2432 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2433 else if (err == 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2434 JUMPTO(oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2435 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2436 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2437 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2438
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2439 case JUMP_IF_TRUE_OR_POP:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2440 w = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2441 if (w == Py_False) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2442 STACKADJ(-1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2443 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2444 goto fast_next_opcode;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2445 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2446 if (w == Py_True) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2447 JUMPTO(oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2448 goto fast_next_opcode;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2449 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2450 err = PyObject_IsTrue(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2451 if (err > 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2452 err = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2453 JUMPTO(oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2454 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2455 else if (err == 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2456 STACKADJ(-1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2457 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2458 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2459 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2460 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2461 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2462
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2463 PREDICTED_WITH_ARG(JUMP_ABSOLUTE);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2464 case JUMP_ABSOLUTE:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2465 JUMPTO(oparg);
43784
8fcc3f46c69d Add build option for faster loop execution.
Raymond Hettinger <python@rcn.com>
parents: 43416
diff changeset
2466 #if FAST_LOOPS
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2467 /* Enabling this path speeds-up all while and for-loops by bypassing
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2468 the per-loop checks for signals. By default, this should be turned-off
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2469 because it prevents detection of a control-break in tight loops like
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2470 "while 1: pass". Compile with this option turned-on when you need
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2471 the speed-up and do not need break checking inside tight loops (ones
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2472 that contain only instructions ending with goto fast_next_opcode).
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2473 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2474 goto fast_next_opcode;
43784
8fcc3f46c69d Add build option for faster loop execution.
Raymond Hettinger <python@rcn.com>
parents: 43416
diff changeset
2475 #else
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2476 continue;
43784
8fcc3f46c69d Add build option for faster loop execution.
Raymond Hettinger <python@rcn.com>
parents: 43416
diff changeset
2477 #endif
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2478
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2479 case GET_ITER:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2480 /* before: [obj]; after [getiter(obj)] */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2481 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2482 x = PyObject_GetIter(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2483 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2484 if (x != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2485 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2486 PREDICT(FOR_ITER);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2487 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2488 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2489 STACKADJ(-1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2490 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2491
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2492 PREDICTED_WITH_ARG(FOR_ITER);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2493 case FOR_ITER:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2494 /* before: [iter]; after: [iter, iter()] *or* [] */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2495 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2496 x = (*v->ob_type->tp_iternext)(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2497 if (x != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2498 PUSH(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2499 PREDICT(STORE_FAST);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2500 PREDICT(UNPACK_SEQUENCE);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2501 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2502 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2503 if (PyErr_Occurred()) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2504 if (!PyErr_ExceptionMatches(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2505 PyExc_StopIteration))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2506 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2507 PyErr_Clear();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2508 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2509 /* iterator ended normally */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2510 x = v = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2511 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2512 JUMPBY(oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2513 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2514
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2515 case BREAK_LOOP:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2516 why = WHY_BREAK;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2517 goto fast_block_end;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2518
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2519 case CONTINUE_LOOP:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2520 retval = PyInt_FromLong(oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2521 if (!retval) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2522 x = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2523 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2524 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2525 why = WHY_CONTINUE;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2526 goto fast_block_end;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2527
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2528 case SETUP_LOOP:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2529 case SETUP_EXCEPT:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2530 case SETUP_FINALLY:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2531 /* NOTE: If you add any new block-setup opcodes that
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2532 are not try/except/finally handlers, you may need
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2533 to update the PyGen_NeedsFinalizing() function.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2534 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2535
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2536 PyFrame_BlockSetup(f, opcode, INSTR_OFFSET() + oparg,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2537 STACK_LEVEL());
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2538 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2539
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2540 case SETUP_WITH:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2541 {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2542 static PyObject *exit, *enter;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2543 w = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2544 x = special_lookup(w, "__exit__", &exit);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2545 if (!x)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2546 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2547 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2548 u = special_lookup(w, "__enter__", &enter);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2549 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2550 if (!u) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2551 x = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2552 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2553 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2554 x = PyObject_CallFunctionObjArgs(u, NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2555 Py_DECREF(u);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2556 if (!x)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2557 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2558 /* Setup a finally block (SETUP_WITH as a block is
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2559 equivalent to SETUP_FINALLY except it normalizes
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2560 the exception) before pushing the result of
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2561 __enter__ on the stack. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2562 PyFrame_BlockSetup(f, SETUP_WITH, INSTR_OFFSET() + oparg,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2563 STACK_LEVEL());
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2564
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2565 PUSH(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2566 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2567 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2568
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2569 case WITH_CLEANUP:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2570 {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2571 /* At the top of the stack are 1-3 values indicating
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2572 how/why we entered the finally clause:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2573 - TOP = None
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2574 - (TOP, SECOND) = (WHY_{RETURN,CONTINUE}), retval
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2575 - TOP = WHY_*; no retval below it
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2576 - (TOP, SECOND, THIRD) = exc_info()
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2577 Below them is EXIT, the context.__exit__ bound method.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2578 In the last case, we must call
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2579 EXIT(TOP, SECOND, THIRD)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2580 otherwise we must call
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2581 EXIT(None, None, None)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2582
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2583 In all cases, we remove EXIT from the stack, leaving
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2584 the rest in the same order.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2585
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2586 In addition, if the stack represents an exception,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2587 *and* the function call returns a 'true' value, we
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2588 "zap" this information, to prevent END_FINALLY from
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2589 re-raising the exception. (But non-local gotos
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2590 should still be resumed.)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2591 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2592
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2593 PyObject *exit_func;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2594
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2595 u = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2596 if (u == Py_None) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2597 exit_func = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2598 SET_TOP(u);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2599 v = w = Py_None;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2600 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2601 else if (PyInt_Check(u)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2602 switch(PyInt_AS_LONG(u)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2603 case WHY_RETURN:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2604 case WHY_CONTINUE:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2605 /* Retval in TOP. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2606 exit_func = SECOND();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2607 SET_SECOND(TOP());
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2608 SET_TOP(u);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2609 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2610 default:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2611 exit_func = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2612 SET_TOP(u);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2613 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2614 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2615 u = v = w = Py_None;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2616 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2617 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2618 v = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2619 w = SECOND();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2620 exit_func = THIRD();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2621 SET_TOP(u);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2622 SET_SECOND(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2623 SET_THIRD(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2624 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2625 /* XXX Not the fastest way to call it... */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2626 x = PyObject_CallFunctionObjArgs(exit_func, u, v, w,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2627 NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2628 Py_DECREF(exit_func);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2629 if (x == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2630 break; /* Go to error exit */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2631
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2632 if (u != Py_None)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2633 err = PyObject_IsTrue(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2634 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2635 err = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2636 Py_DECREF(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2637
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2638 if (err < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2639 break; /* Go to error exit */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2640 else if (err > 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2641 err = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2642 /* There was an exception and a true return */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2643 STACKADJ(-2);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2644 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2645 SET_TOP(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2646 Py_DECREF(u);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2647 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2648 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2649 } else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2650 /* The stack was rearranged to remove EXIT
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2651 above. Let END_FINALLY do its thing */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2652 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2653 PREDICT(END_FINALLY);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2654 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2655 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2656
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2657 case CALL_FUNCTION:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2658 {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2659 PyObject **sp;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2660 PCALL(PCALL_ALL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2661 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
2662 #ifdef WITH_TSC
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2663 x = 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
2664 #else
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2665 x = 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
2666 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2667 stack_pointer = sp;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2668 PUSH(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2669 if (x != NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2670 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2671 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2672 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2673
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2674 case CALL_FUNCTION_VAR:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2675 case CALL_FUNCTION_KW:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2676 case CALL_FUNCTION_VAR_KW:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2677 {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2678 int na = oparg & 0xff;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2679 int nk = (oparg>>8) & 0xff;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2680 int flags = (opcode - CALL_FUNCTION) & 3;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2681 int n = na + 2 * nk;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2682 PyObject **pfunc, *func, **sp;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2683 PCALL(PCALL_ALL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2684 if (flags & CALL_FLAG_VAR)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2685 n++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2686 if (flags & CALL_FLAG_KW)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2687 n++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2688 pfunc = stack_pointer - n - 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2689 func = *pfunc;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2690
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2691 if (PyMethod_Check(func)
62457
ca4f2e9869b6 Issue #8930: Remaining indentation fixes after the Grand Unified Indenting.
Stefan Krah <stefan@bytereef.org>
parents: 61463
diff changeset
2692 && PyMethod_GET_SELF(func) != NULL) {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2693 PyObject *self = PyMethod_GET_SELF(func);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2694 Py_INCREF(self);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2695 func = PyMethod_GET_FUNCTION(func);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2696 Py_INCREF(func);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2697 Py_DECREF(*pfunc);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2698 *pfunc = self;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2699 na++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2700 } else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2701 Py_INCREF(func);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2702 sp = stack_pointer;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2703 READ_TIMESTAMP(intr0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2704 x = ext_do_call(func, &sp, flags, na, nk);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2705 READ_TIMESTAMP(intr1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2706 stack_pointer = sp;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2707 Py_DECREF(func);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2708
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2709 while (stack_pointer > pfunc) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2710 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2711 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2712 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2713 PUSH(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2714 if (x != NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2715 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2716 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2717 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2718
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2719 case MAKE_FUNCTION:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2720 v = POP(); /* code object */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2721 x = PyFunction_New(v, f->f_globals);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2722 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2723 /* XXX Maybe this should be a separate opcode? */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2724 if (x != NULL && oparg > 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2725 v = PyTuple_New(oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2726 if (v == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2727 Py_DECREF(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2728 x = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2729 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2730 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2731 while (--oparg >= 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2732 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2733 PyTuple_SET_ITEM(v, oparg, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2734 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2735 err = PyFunction_SetDefaults(x, v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2736 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2737 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2738 PUSH(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2739 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2740
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2741 case MAKE_CLOSURE:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2742 {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2743 v = POP(); /* code object */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2744 x = PyFunction_New(v, f->f_globals);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2745 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2746 if (x != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2747 v = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2748 if (PyFunction_SetClosure(x, v) != 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2749 /* Can't happen unless bytecode is corrupt. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2750 why = WHY_EXCEPTION;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2751 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2752 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2753 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2754 if (x != NULL && oparg > 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2755 v = PyTuple_New(oparg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2756 if (v == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2757 Py_DECREF(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2758 x = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2759 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2760 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2761 while (--oparg >= 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2762 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2763 PyTuple_SET_ITEM(v, oparg, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2764 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2765 if (PyFunction_SetDefaults(x, v) != 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2766 /* Can't happen unless
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2767 PyFunction_SetDefaults changes. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2768 why = WHY_EXCEPTION;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2769 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2770 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2771 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2772 PUSH(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2773 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2774 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2775
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2776 case BUILD_SLICE:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2777 if (oparg == 3)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2778 w = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2779 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2780 w = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2781 v = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2782 u = TOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2783 x = PySlice_New(u, v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2784 Py_DECREF(u);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2785 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2786 Py_XDECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2787 SET_TOP(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2788 if (x != NULL) continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2789 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2790
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2791 case EXTENDED_ARG:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2792 opcode = NEXTOP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2793 oparg = oparg<<16 | NEXTARG();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2794 goto dispatch_opcode;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2795
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2796 default:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2797 fprintf(stderr,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2798 "XXX lineno: %d, opcode: %d\n",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2799 PyFrame_GetLineNumber(f),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2800 opcode);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2801 PyErr_SetString(PyExc_SystemError, "unknown opcode");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2802 why = WHY_EXCEPTION;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2803 break;
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2804
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2805 #ifdef CASE_TOO_BIG
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2806 }
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2807 #endif
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2808
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2809 } /* switch */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2810
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2811 on_error:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2812
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2813 READ_TIMESTAMP(inst1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2814
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2815 /* Quickly continue if no error occurred */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2816
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2817 if (why == WHY_NOT) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2818 if (err == 0 && x != NULL) {
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2819 #ifdef CHECKEXC
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2820 /* This check is expensive! */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2821 if (PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2822 fprintf(stderr,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2823 "XXX undetected error\n");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2824 else {
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
2825 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2826 READ_TIMESTAMP(loop1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2827 continue; /* Normal, fast path */
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
2828 #ifdef CHECKEXC
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2829 }
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
2830 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2831 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2832 why = WHY_EXCEPTION;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2833 x = Py_None;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2834 err = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2835 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2836
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2837 /* Double-check exception status */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2838
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2839 if (why == WHY_EXCEPTION || why == WHY_RERAISE) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2840 if (!PyErr_Occurred()) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2841 PyErr_SetString(PyExc_SystemError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2842 "error return without exception set");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2843 why = WHY_EXCEPTION;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2844 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2845 }
10363
4daab7a9f566 Always test for an error return (usually NULL or -1) without setting
Guido van Rossum <guido@python.org>
parents: 9679
diff changeset
2846 #ifdef CHECKEXC
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2847 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2848 /* This check is expensive! */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2849 if (PyErr_Occurred()) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2850 char buf[128];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2851 sprintf(buf, "Stack unwind with exception "
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2852 "set and why=%d", why);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2853 Py_FatalError(buf);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2854 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2855 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2856 #endif
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2857
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2858 /* Log traceback info if this is a real exception */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2859
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2860 if (why == WHY_EXCEPTION) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2861 PyTraceBack_Here(f);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2862
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2863 if (tstate->c_tracefunc != NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2864 call_exc_trace(tstate->c_tracefunc,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2865 tstate->c_traceobj, f);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2866 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2867
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2868 /* For the rest, treat WHY_RERAISE as WHY_EXCEPTION */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2869
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2870 if (why == WHY_RERAISE)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2871 why = WHY_EXCEPTION;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2872
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2873 /* Unwind stacks if a (pseudo) exception occurred */
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2874
31462
d5c047807c69 SF patch #864059: optimize eval_frame
Raymond Hettinger <python@rcn.com>
parents: 30979
diff changeset
2875 fast_block_end:
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2876 while (why != WHY_NOT && f->f_iblock > 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2877 /* Peek at the current block. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2878 PyTryBlock *b = &f->f_blockstack[f->f_iblock - 1];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2879
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2880 assert(why != WHY_YIELD);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2881 if (b->b_type == SETUP_LOOP && why == WHY_CONTINUE) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2882 why = WHY_NOT;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2883 JUMPTO(PyInt_AS_LONG(retval));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2884 Py_DECREF(retval);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2885 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2886 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2887
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2888 /* Now we have to pop the block. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2889 f->f_iblock--;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2890
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2891 while (STACK_LEVEL() > b->b_level) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2892 v = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2893 Py_XDECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2894 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2895 if (b->b_type == SETUP_LOOP && why == WHY_BREAK) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2896 why = WHY_NOT;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2897 JUMPTO(b->b_handler);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2898 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2899 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2900 if (b->b_type == SETUP_FINALLY ||
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2901 (b->b_type == SETUP_EXCEPT &&
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2902 why == WHY_EXCEPTION) ||
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2903 b->b_type == SETUP_WITH) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2904 if (why == WHY_EXCEPTION) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2905 PyObject *exc, *val, *tb;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2906 PyErr_Fetch(&exc, &val, &tb);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2907 if (val == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2908 val = Py_None;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2909 Py_INCREF(val);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2910 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2911 /* Make the raw exception data
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2912 available to the handler,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2913 so a program can emulate the
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2914 Python main loop. Don't do
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2915 this for 'finally'. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2916 if (b->b_type == SETUP_EXCEPT ||
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2917 b->b_type == SETUP_WITH) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2918 PyErr_NormalizeException(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2919 &exc, &val, &tb);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2920 set_exc_info(tstate,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2921 exc, val, tb);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2922 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2923 if (tb == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2924 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2925 PUSH(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2926 } else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2927 PUSH(tb);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2928 PUSH(val);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2929 PUSH(exc);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2930 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2931 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2932 if (why & (WHY_RETURN | WHY_CONTINUE))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2933 PUSH(retval);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2934 v = PyInt_FromLong((long)why);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2935 PUSH(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2936 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2937 why = WHY_NOT;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2938 JUMPTO(b->b_handler);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2939 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2940 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2941 } /* unwind stack */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2942
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2943 /* End the loop if we still have an error (or return) */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2944
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2945 if (why != WHY_NOT)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2946 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2947 READ_TIMESTAMP(loop1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2948
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2949 } /* main loop */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2950
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2951 assert(why != WHY_YIELD);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2952 /* Pop remaining stack entries. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2953 while (!EMPTY()) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2954 v = POP();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2955 Py_XDECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2956 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2957
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2958 if (why != WHY_RETURN)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2959 retval = NULL;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2960
31462
d5c047807c69 SF patch #864059: optimize eval_frame
Raymond Hettinger <python@rcn.com>
parents: 30979
diff changeset
2961 fast_yield:
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2962 if (tstate->use_tracing) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2963 if (tstate->c_tracefunc) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2964 if (why == WHY_RETURN || why == WHY_YIELD) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2965 if (call_trace(tstate->c_tracefunc,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2966 tstate->c_traceobj, f,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2967 PyTrace_RETURN, retval)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2968 Py_XDECREF(retval);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2969 retval = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2970 why = WHY_EXCEPTION;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2971 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2972 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2973 else if (why == WHY_EXCEPTION) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2974 call_trace_protected(tstate->c_tracefunc,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2975 tstate->c_traceobj, f,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2976 PyTrace_RETURN, NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2977 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2978 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2979 if (tstate->c_profilefunc) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2980 if (why == WHY_EXCEPTION)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2981 call_trace_protected(tstate->c_profilefunc,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2982 tstate->c_profileobj, f,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2983 PyTrace_RETURN, NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2984 else if (call_trace(tstate->c_profilefunc,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2985 tstate->c_profileobj, f,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2986 PyTrace_RETURN, retval)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2987 Py_XDECREF(retval);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2988 retval = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2989 why = WHY_EXCEPTION;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2990 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2991 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2992 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2993
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2994 if (tstate->frame->f_exc_type != NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2995 reset_exc_info(tstate);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2996 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2997 assert(tstate->frame->f_exc_value == NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2998 assert(tstate->frame->f_exc_traceback == NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
2999 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3000
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3001 /* pop frame */
43408
81478465fef3 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
3002 exit_eval_frame:
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3003 Py_LeaveRecursiveCall();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3004 tstate->frame = f->f_back;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3005
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3006 return retval;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
3007 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
3008
36695
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
3009 /* 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
3010 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
3011 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
3012
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 18611
diff changeset
3013 PyObject *
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 18611
diff changeset
3014 PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals,
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3015 PyObject **args, int argcount, PyObject **kws, int kwcount,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3016 PyObject **defs, int defcount, 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
3017 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3018 register PyFrameObject *f;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3019 register PyObject *retval = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3020 register PyObject **fastlocals, **freevars;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3021 PyThreadState *tstate = PyThreadState_GET();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3022 PyObject *x, *u;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3023
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3024 if (globals == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3025 PyErr_SetString(PyExc_SystemError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3026 "PyEval_EvalCodeEx: NULL globals");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3027 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3028 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3029
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3030 assert(tstate != NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3031 assert(globals != NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3032 f = PyFrame_New(tstate, co, globals, locals);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3033 if (f == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3034 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3035
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3036 fastlocals = f->f_localsplus;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3037 freevars = f->f_localsplus + co->co_nlocals;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3038
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3039 if (co->co_argcount > 0 ||
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3040 co->co_flags & (CO_VARARGS | CO_VARKEYWORDS)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3041 int i;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3042 int n = argcount;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3043 PyObject *kwdict = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3044 if (co->co_flags & CO_VARKEYWORDS) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3045 kwdict = PyDict_New();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3046 if (kwdict == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3047 goto fail;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3048 i = co->co_argcount;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3049 if (co->co_flags & CO_VARARGS)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3050 i++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3051 SETLOCAL(i, kwdict);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3052 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3053 if (argcount > co->co_argcount) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3054 if (!(co->co_flags & CO_VARARGS)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3055 PyErr_Format(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3056 "%.200s() takes %s %d "
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3057 "argument%s (%d given)",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3058 PyString_AsString(co->co_name),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3059 defcount ? "at most" : "exactly",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3060 co->co_argcount,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3061 co->co_argcount == 1 ? "" : "s",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3062 argcount + kwcount);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3063 goto fail;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3064 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3065 n = co->co_argcount;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3066 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3067 for (i = 0; i < n; i++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3068 x = args[i];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3069 Py_INCREF(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3070 SETLOCAL(i, x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3071 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3072 if (co->co_flags & CO_VARARGS) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3073 u = PyTuple_New(argcount - n);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3074 if (u == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3075 goto fail;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3076 SETLOCAL(co->co_argcount, u);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3077 for (i = n; i < argcount; i++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3078 x = args[i];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3079 Py_INCREF(x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3080 PyTuple_SET_ITEM(u, i-n, x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3081 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3082 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3083 for (i = 0; i < kwcount; i++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3084 PyObject **co_varnames;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3085 PyObject *keyword = kws[2*i];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3086 PyObject *value = kws[2*i + 1];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3087 int j;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3088 if (keyword == NULL || !(PyString_Check(keyword)
51032
551257c8058a fix building the core with --disable-unicode
Benjamin Peterson <benjamin@python.org>
parents: 50936
diff changeset
3089 #ifdef Py_USING_UNICODE
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3090 || PyUnicode_Check(keyword)
51032
551257c8058a fix building the core with --disable-unicode
Benjamin Peterson <benjamin@python.org>
parents: 50936
diff changeset
3091 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3092 )) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3093 PyErr_Format(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3094 "%.200s() keywords must be strings",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3095 PyString_AsString(co->co_name));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3096 goto fail;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3097 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3098 /* Speed hack: do raw pointer compares. As names are
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3099 normally interned this should almost always hit. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3100 co_varnames = ((PyTupleObject *)(co->co_varnames))->ob_item;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3101 for (j = 0; j < co->co_argcount; j++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3102 PyObject *nm = co_varnames[j];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3103 if (nm == keyword)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3104 goto kw_found;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3105 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3106 /* Slow fallback, just in case */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3107 for (j = 0; j < co->co_argcount; j++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3108 PyObject *nm = co_varnames[j];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3109 int cmp = PyObject_RichCompareBool(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3110 keyword, nm, Py_EQ);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3111 if (cmp > 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3112 goto kw_found;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3113 else if (cmp < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3114 goto fail;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3115 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3116 if (kwdict == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3117 PyObject *kwd_str = kwd_as_string(keyword);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3118 if (kwd_str) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3119 PyErr_Format(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3120 "%.200s() got an unexpected "
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3121 "keyword argument '%.400s'",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3122 PyString_AsString(co->co_name),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3123 PyString_AsString(kwd_str));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3124 Py_DECREF(kwd_str);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3125 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3126 goto fail;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3127 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3128 PyDict_SetItem(kwdict, keyword, value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3129 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3130 kw_found:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3131 if (GETLOCAL(j) != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3132 PyObject *kwd_str = kwd_as_string(keyword);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3133 if (kwd_str) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3134 PyErr_Format(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3135 "%.200s() got multiple "
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3136 "values for keyword "
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3137 "argument '%.400s'",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3138 PyString_AsString(co->co_name),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3139 PyString_AsString(kwd_str));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3140 Py_DECREF(kwd_str);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3141 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3142 goto fail;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3143 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3144 Py_INCREF(value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3145 SETLOCAL(j, value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3146 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3147 if (argcount < co->co_argcount) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3148 int m = co->co_argcount - defcount;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3149 for (i = argcount; i < m; i++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3150 if (GETLOCAL(i) == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3151 int j, given = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3152 for (j = 0; j < co->co_argcount; j++)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3153 if (GETLOCAL(j))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3154 given++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3155 PyErr_Format(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3156 "%.200s() takes %s %d "
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3157 "argument%s (%d given)",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3158 PyString_AsString(co->co_name),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3159 ((co->co_flags & CO_VARARGS) ||
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3160 defcount) ? "at least"
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3161 : "exactly",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3162 m, m == 1 ? "" : "s", given);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3163 goto fail;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3164 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3165 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3166 if (n > m)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3167 i = n - m;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3168 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3169 i = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3170 for (; i < defcount; i++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3171 if (GETLOCAL(m+i) == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3172 PyObject *def = defs[i];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3173 Py_INCREF(def);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3174 SETLOCAL(m+i, def);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3175 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3176 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3177 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3178 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3179 else if (argcount > 0 || kwcount > 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3180 PyErr_Format(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3181 "%.200s() takes no arguments (%d given)",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3182 PyString_AsString(co->co_name),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3183 argcount + kwcount);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3184 goto fail;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3185 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3186 /* Allocate and initialize storage for cell vars, and copy free
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3187 vars into frame. This isn't too efficient right now. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3188 if (PyTuple_GET_SIZE(co->co_cellvars)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3189 int i, j, nargs, found;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3190 char *cellname, *argname;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3191 PyObject *c;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3192
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3193 nargs = co->co_argcount;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3194 if (co->co_flags & CO_VARARGS)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3195 nargs++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3196 if (co->co_flags & CO_VARKEYWORDS)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3197 nargs++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3198
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3199 /* Initialize each cell var, taking into account
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3200 cell vars that are initialized from arguments.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3201
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3202 Should arrange for the compiler to put cellvars
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3203 that are arguments at the beginning of the cellvars
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3204 list so that we can march over it more efficiently?
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3205 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3206 for (i = 0; i < PyTuple_GET_SIZE(co->co_cellvars); ++i) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3207 cellname = PyString_AS_STRING(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3208 PyTuple_GET_ITEM(co->co_cellvars, i));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3209 found = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3210 for (j = 0; j < nargs; j++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3211 argname = PyString_AS_STRING(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3212 PyTuple_GET_ITEM(co->co_varnames, j));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3213 if (strcmp(cellname, argname) == 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3214 c = PyCell_New(GETLOCAL(j));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3215 if (c == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3216 goto fail;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3217 GETLOCAL(co->co_nlocals + i) = c;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3218 found = 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3219 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3220 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3221 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3222 if (found == 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3223 c = PyCell_New(NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3224 if (c == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3225 goto fail;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3226 SETLOCAL(co->co_nlocals + i, c);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3227 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3228 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3229 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3230 if (PyTuple_GET_SIZE(co->co_freevars)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3231 int i;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3232 for (i = 0; i < PyTuple_GET_SIZE(co->co_freevars); ++i) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3233 PyObject *o = PyTuple_GET_ITEM(closure, i);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3234 Py_INCREF(o);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3235 freevars[PyTuple_GET_SIZE(co->co_cellvars) + i] = o;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3236 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3237 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3238
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3239 if (co->co_flags & CO_GENERATOR) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3240 /* Don't need to keep the reference to f_back, it will be set
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3241 * when the generator is resumed. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3242 Py_XDECREF(f->f_back);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3243 f->f_back = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3244
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3245 PCALL(PCALL_GENERATOR);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3246
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3247 /* Create a new generator that owns the ready to run frame
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3248 * and return that as the value. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3249 return PyGen_New(f);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3250 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3251
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3252 retval = PyEval_EvalFrameEx(f,0);
43408
81478465fef3 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
3253
81478465fef3 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
3254 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
3255
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3256 /* decref'ing the frame can cause __del__ methods to get invoked,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3257 which can call back into Python. While we're done with the
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3258 current Python frame (f), the associated C stack is still in use,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3259 so recursion_depth must be boosted for the duration.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3260 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3261 assert(tstate != NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3262 ++tstate->recursion_depth;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3263 Py_DECREF(f);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3264 --tstate->recursion_depth;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3265 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
3266 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
3267
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
3268
54329
145376df3ad7 add a SETUP_WITH opcode
Benjamin Peterson <benjamin@python.org>
parents: 54297
diff changeset
3269 static PyObject *
145376df3ad7 add a SETUP_WITH opcode
Benjamin Peterson <benjamin@python.org>
parents: 54297
diff changeset
3270 special_lookup(PyObject *o, char *meth, PyObject **cache)
145376df3ad7 add a SETUP_WITH opcode
Benjamin Peterson <benjamin@python.org>
parents: 54297
diff changeset
3271 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3272 PyObject *res;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3273 if (PyInstance_Check(o)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3274 if (!*cache)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3275 return PyObject_GetAttrString(o, meth);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3276 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3277 return PyObject_GetAttr(o, *cache);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3278 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3279 res = _PyObject_LookupSpecial(o, meth, cache);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3280 if (res == NULL && !PyErr_Occurred()) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3281 PyErr_SetObject(PyExc_AttributeError, *cache);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3282 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3283 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3284 return res;
54329
145376df3ad7 add a SETUP_WITH opcode
Benjamin Peterson <benjamin@python.org>
parents: 54297
diff changeset
3285 }
145376df3ad7 add a SETUP_WITH opcode
Benjamin Peterson <benjamin@python.org>
parents: 54297
diff changeset
3286
51032
551257c8058a fix building the core with --disable-unicode
Benjamin Peterson <benjamin@python.org>
parents: 50936
diff changeset
3287
50936
dbc14acdde37 allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents: 50674
diff changeset
3288 static PyObject *
dbc14acdde37 allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents: 50674
diff changeset
3289 kwd_as_string(PyObject *kwd) {
51032
551257c8058a fix building the core with --disable-unicode
Benjamin Peterson <benjamin@python.org>
parents: 50936
diff changeset
3290 #ifdef Py_USING_UNICODE
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3291 if (PyString_Check(kwd)) {
51032
551257c8058a fix building the core with --disable-unicode
Benjamin Peterson <benjamin@python.org>
parents: 50936
diff changeset
3292 #else
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3293 assert(PyString_Check(kwd));
51032
551257c8058a fix building the core with --disable-unicode
Benjamin Peterson <benjamin@python.org>
parents: 50936
diff changeset
3294 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3295 Py_INCREF(kwd);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3296 return kwd;
51032
551257c8058a fix building the core with --disable-unicode
Benjamin Peterson <benjamin@python.org>
parents: 50936
diff changeset
3297 #ifdef Py_USING_UNICODE
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3298 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3299 return _PyUnicode_AsDefaultEncodedString(kwd, "replace");
51032
551257c8058a fix building the core with --disable-unicode
Benjamin Peterson <benjamin@python.org>
parents: 50936
diff changeset
3300 #endif
50936
dbc14acdde37 allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents: 50674
diff changeset
3301 }
dbc14acdde37 allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents: 50674
diff changeset
3302
dbc14acdde37 allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents: 50674
diff changeset
3303
28121
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3304 /* Implementation notes for set_exc_info() and reset_exc_info():
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3305
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3306 - Below, 'exc_ZZZ' stands for 'exc_type', 'exc_value' and
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3307 'exc_traceback'. These always travel together.
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3308
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3309 - tstate->curexc_ZZZ is the "hot" exception that is set by
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3310 PyErr_SetString(), cleared by PyErr_Clear(), and so on.
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3311
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3312 - Once an exception is caught by an except clause, it is transferred
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3313 from tstate->curexc_ZZZ to tstate->exc_ZZZ, from which sys.exc_info()
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3314 can pick it up. This is the primary task of set_exc_info().
38418
708eaf0896bf Patch 1145039.
Tim Peters <tim.peters@gmail.com>
parents: 38352
diff changeset
3315 XXX That can't be right: set_exc_info() doesn't look at tstate->curexc_ZZZ.
28121
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3316
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3317 - Now let me explain the complicated dance with frame->f_exc_ZZZ.
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3318
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3319 Long ago, when none of this existed, there were just a few globals:
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3320 one set corresponding to the "hot" exception, and one set
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3321 corresponding to sys.exc_ZZZ. (Actually, the latter weren't C
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3322 globals; they were simply stored as sys.exc_ZZZ. For backwards
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3323 compatibility, they still are!) The problem was that in code like
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3324 this:
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3325
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3326 try:
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3327 "something that may fail"
28121
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3328 except "some exception":
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3329 "do something else first"
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3330 "print the exception from sys.exc_ZZZ."
28121
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3331
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3332 if "do something else first" invoked something that raised and caught
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3333 an exception, sys.exc_ZZZ were overwritten. That was a frequent
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3334 cause of subtle bugs. I fixed this by changing the semantics as
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3335 follows:
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3336
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3337 - Within one frame, sys.exc_ZZZ will hold the last exception caught
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3338 *in that frame*.
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3339
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3340 - But initially, and as long as no exception is caught in a given
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3341 frame, sys.exc_ZZZ will hold the last exception caught in the
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3342 previous frame (or the frame before that, etc.).
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3343
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3344 The first bullet fixed the bug in the above example. The second
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3345 bullet was for backwards compatibility: it was (and is) common to
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3346 have a function that is called when an exception is caught, and to
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3347 have that function access the caught exception via sys.exc_ZZZ.
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3348 (Example: traceback.print_exc()).
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3349
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3350 At the same time I fixed the problem that sys.exc_ZZZ weren't
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3351 thread-safe, by introducing sys.exc_info() which gets it from tstate;
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3352 but that's really a separate improvement.
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3353
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3354 The reset_exc_info() function in ceval.c restores the tstate->exc_ZZZ
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3355 variables to what they were before the current frame was called. The
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3356 set_exc_info() function saves them on the frame so that
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3357 reset_exc_info() can restore them. The invariant is that
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3358 frame->f_exc_ZZZ is NULL iff the current frame never caught an
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3359 exception (where "catching" an exception applies only to successful
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3360 except clauses); and if the current frame ever caught an exception,
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3361 frame->f_exc_ZZZ is the exception that was stored in tstate->exc_ZZZ
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3362 at the start of the current frame.
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3363
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3364 */
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
3365
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
3366 static void
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3367 set_exc_info(PyThreadState *tstate,
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3368 PyObject *type, PyObject *value, PyObject *tb)
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3369 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3370 PyFrameObject *frame = tstate->frame;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3371 PyObject *tmp_type, *tmp_value, *tmp_tb;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3372
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3373 assert(type != NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3374 assert(frame != NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3375 if (frame->f_exc_type == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3376 assert(frame->f_exc_value == NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3377 assert(frame->f_exc_traceback == NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3378 /* This frame didn't catch an exception before. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3379 /* Save previous exception of this thread in this frame. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3380 if (tstate->exc_type == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3381 /* XXX Why is this set to Py_None? */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3382 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3383 tstate->exc_type = Py_None;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3384 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3385 Py_INCREF(tstate->exc_type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3386 Py_XINCREF(tstate->exc_value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3387 Py_XINCREF(tstate->exc_traceback);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3388 frame->f_exc_type = tstate->exc_type;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3389 frame->f_exc_value = tstate->exc_value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3390 frame->f_exc_traceback = tstate->exc_traceback;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3391 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3392 /* Set new exception for this thread. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3393 tmp_type = tstate->exc_type;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3394 tmp_value = tstate->exc_value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3395 tmp_tb = tstate->exc_traceback;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3396 Py_INCREF(type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3397 Py_XINCREF(value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3398 Py_XINCREF(tb);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3399 tstate->exc_type = type;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3400 tstate->exc_value = value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3401 tstate->exc_traceback = tb;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3402 Py_XDECREF(tmp_type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3403 Py_XDECREF(tmp_value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3404 Py_XDECREF(tmp_tb);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3405 /* For b/w compatibility */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3406 PySys_SetObject("exc_type", type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3407 PySys_SetObject("exc_value", value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3408 PySys_SetObject("exc_traceback", tb);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3409 }
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3410
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
3411 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3412 reset_exc_info(PyThreadState *tstate)
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3413 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3414 PyFrameObject *frame;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3415 PyObject *tmp_type, *tmp_value, *tmp_tb;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3416
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3417 /* It's a precondition that the thread state's frame caught an
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3418 * exception -- verify in a debug build.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3419 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3420 assert(tstate != NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3421 frame = tstate->frame;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3422 assert(frame != NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3423 assert(frame->f_exc_type != NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3424
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3425 /* Copy the frame's exception info back to the thread state. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3426 tmp_type = tstate->exc_type;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3427 tmp_value = tstate->exc_value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3428 tmp_tb = tstate->exc_traceback;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3429 Py_INCREF(frame->f_exc_type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3430 Py_XINCREF(frame->f_exc_value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3431 Py_XINCREF(frame->f_exc_traceback);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3432 tstate->exc_type = frame->f_exc_type;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3433 tstate->exc_value = frame->f_exc_value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3434 tstate->exc_traceback = frame->f_exc_traceback;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3435 Py_XDECREF(tmp_type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3436 Py_XDECREF(tmp_value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3437 Py_XDECREF(tmp_tb);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3438
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3439 /* For b/w compatibility */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3440 PySys_SetObject("exc_type", frame->f_exc_type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3441 PySys_SetObject("exc_value", frame->f_exc_value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3442 PySys_SetObject("exc_traceback", frame->f_exc_traceback);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3443
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3444 /* Clear the frame's exception info. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3445 tmp_type = frame->f_exc_type;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3446 tmp_value = frame->f_exc_value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3447 tmp_tb = frame->f_exc_traceback;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3448 frame->f_exc_type = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3449 frame->f_exc_value = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3450 frame->f_exc_traceback = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3451 Py_DECREF(tmp_type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3452 Py_XDECREF(tmp_value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3453 Py_XDECREF(tmp_tb);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3454 }
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3455
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
3456 /* 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
3457 This *consumes* a reference count to each of its arguments. */
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
3458 static enum why_code
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3459 do_raise(PyObject *type, PyObject *value, PyObject *tb)
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
3460 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3461 if (type == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3462 /* Reraise */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3463 PyThreadState *tstate = PyThreadState_GET();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3464 type = tstate->exc_type == NULL ? Py_None : tstate->exc_type;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3465 value = tstate->exc_value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3466 tb = tstate->exc_traceback;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3467 Py_XINCREF(type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3468 Py_XINCREF(value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3469 Py_XINCREF(tb);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3470 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3471
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3472 /* We support the following forms of raise:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3473 raise <class>, <classinstance>
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3474 raise <class>, <argument tuple>
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3475 raise <class>, None
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3476 raise <class>, <argument>
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3477 raise <classinstance>, None
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3478 raise <string>, <object>
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3479 raise <string>, None
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3480
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3481 An omitted second argument is the same as None.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3482
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3483 In addition, raise <tuple>, <anything> is the same as
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3484 raising the tuple's first item (and it better have one!);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3485 this rule is applied recursively.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3486
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3487 Finally, an optional third argument can be supplied, which
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3488 gives the traceback to be substituted (useful when
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3489 re-raising an exception after examining it). */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3490
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3491 /* First, check the traceback argument, replacing None with
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3492 NULL. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3493 if (tb == Py_None) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3494 Py_DECREF(tb);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3495 tb = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3496 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3497 else if (tb != NULL && !PyTraceBack_Check(tb)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3498 PyErr_SetString(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3499 "raise: arg 3 must be a traceback or None");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3500 goto raise_error;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3501 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3502
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3503 /* Next, replace a missing value with None */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3504 if (value == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3505 value = Py_None;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3506 Py_INCREF(value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3507 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3508
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3509 /* Next, repeatedly, replace a tuple exception with its first item */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3510 while (PyTuple_Check(type) && PyTuple_Size(type) > 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3511 PyObject *tmp = type;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3512 type = PyTuple_GET_ITEM(type, 0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3513 Py_INCREF(type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3514 Py_DECREF(tmp);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3515 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3516
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3517 if (PyExceptionClass_Check(type))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3518 PyErr_NormalizeException(&type, &value, &tb);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3519
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3520 else if (PyExceptionInstance_Check(type)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3521 /* Raising an instance. The value should be a dummy. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3522 if (value != Py_None) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3523 PyErr_SetString(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3524 "instance exception may not have a separate value");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3525 goto raise_error;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3526 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3527 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3528 /* Normalize to raise <class>, <instance> */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3529 Py_DECREF(value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3530 value = type;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3531 type = PyExceptionInstance_Class(type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3532 Py_INCREF(type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3533 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3534 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3535 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3536 /* Not something you can raise. You get an exception
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3537 anyway, just not what you specified :-) */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3538 PyErr_Format(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3539 "exceptions must be old-style classes or "
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3540 "derived from BaseException, not %s",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3541 type->ob_type->tp_name);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3542 goto raise_error;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3543 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3544
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3545 assert(PyExceptionClass_Check(type));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3546 if (Py_Py3kWarningFlag && PyClass_Check(type)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3547 if (PyErr_WarnEx(PyExc_DeprecationWarning,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3548 "exceptions must derive from BaseException "
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3549 "in 3.x", 1) < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3550 goto raise_error;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3551 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3552
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3553 PyErr_Restore(type, value, tb);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3554 if (tb == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3555 return WHY_EXCEPTION;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3556 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3557 return WHY_RERAISE;
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
3558 raise_error:
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3559 Py_XDECREF(value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3560 Py_XDECREF(type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3561 Py_XDECREF(tb);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3562 return WHY_EXCEPTION;
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
3563 }
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
3564
18195
36e825660a24 Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents: 18194
diff changeset
3565 /* Iterate v argcnt times and store the results on the stack (via decreasing
36e825660a24 Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents: 18194
diff changeset
3566 sp). Return 1 for success, 0 if error. */
36e825660a24 Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents: 18194
diff changeset
3567
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
3568 static int
18195
36e825660a24 Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents: 18194
diff changeset
3569 unpack_iterable(PyObject *v, int argcnt, PyObject **sp)
6157
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
3570 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3571 int i = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3572 PyObject *it; /* iter(v) */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3573 PyObject *w;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3574
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3575 assert(v != NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3576
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3577 it = PyObject_GetIter(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3578 if (it == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3579 goto Error;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3580
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3581 for (; i < argcnt; i++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3582 w = PyIter_Next(it);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3583 if (w == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3584 /* Iterator done, via error or exhaustion. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3585 if (!PyErr_Occurred()) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3586 PyErr_Format(PyExc_ValueError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3587 "need more than %d value%s to unpack",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3588 i, i == 1 ? "" : "s");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3589 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3590 goto Error;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3591 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3592 *--sp = w;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3593 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3594
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3595 /* We better have exhausted the iterator now. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3596 w = PyIter_Next(it);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3597 if (w == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3598 if (PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3599 goto Error;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3600 Py_DECREF(it);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3601 return 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3602 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3603 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3604 PyErr_SetString(PyExc_ValueError, "too many values to unpack");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3605 /* fall through */
18195
36e825660a24 Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents: 18194
diff changeset
3606 Error:
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3607 for (; i > 0; i--, sp++)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3608 Py_DECREF(*sp);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3609 Py_XDECREF(it);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3610 return 0;
6157
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
3611 }
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
3612
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
3613
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
3614 #ifdef LLTRACE
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
3615 static int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3616 prtrace(PyObject *v, char *str)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3617 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3618 printf("%s ", str);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3619 if (PyObject_Print(v, stdout, 0) != 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3620 PyErr_Clear(); /* Don't know what else to do */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3621 printf("\n");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3622 return 1;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3623 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3624 #endif
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3625
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
3626 static void
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18293
diff changeset
3627 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
3628 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3629 PyObject *type, *value, *traceback, *arg;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3630 int err;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3631 PyErr_Fetch(&type, &value, &traceback);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3632 if (value == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3633 value = Py_None;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3634 Py_INCREF(value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3635 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3636 arg = PyTuple_Pack(3, type, value, traceback);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3637 if (arg == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3638 PyErr_Restore(type, value, traceback);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3639 return;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3640 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3641 err = call_trace(func, self, f, PyTrace_EXCEPTION, arg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3642 Py_DECREF(arg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3643 if (err == 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3644 PyErr_Restore(type, value, traceback);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3645 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3646 Py_XDECREF(type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3647 Py_XDECREF(value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3648 Py_XDECREF(traceback);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3649 }
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
3650 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
3651
43845
76844a0a579f Merge from py3k branch:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 43784
diff changeset
3652 static int
20257
e3f63a95455f Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
3653 call_trace_protected(Py_tracefunc func, PyObject *obj, PyFrameObject *frame,
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3654 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
3655 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3656 PyObject *type, *value, *traceback;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3657 int err;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3658 PyErr_Fetch(&type, &value, &traceback);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3659 err = call_trace(func, obj, frame, what, arg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3660 if (err == 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3661 {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3662 PyErr_Restore(type, value, traceback);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3663 return 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3664 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3665 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3666 Py_XDECREF(type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3667 Py_XDECREF(value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3668 Py_XDECREF(traceback);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3669 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3670 }
20257
e3f63a95455f Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
3671 }
e3f63a95455f Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
3672
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
3673 static int
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18293
diff changeset
3674 call_trace(Py_tracefunc func, PyObject *obj, PyFrameObject *frame,
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3675 int what, PyObject *arg)
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
3676 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3677 register PyThreadState *tstate = frame->f_tstate;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3678 int result;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3679 if (tstate->tracing)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3680 return 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3681 tstate->tracing++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3682 tstate->use_tracing = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3683 result = func(obj, frame, what, arg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3684 tstate->use_tracing = ((tstate->c_tracefunc != NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3685 || (tstate->c_profilefunc != NULL));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3686 tstate->tracing--;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3687 return result;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
3688 }
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
3689
28556
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28304
diff changeset
3690 PyObject *
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28304
diff changeset
3691 _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
3692 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3693 PyFrameObject *frame = PyEval_GetFrame();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3694 PyThreadState *tstate = frame->f_tstate;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3695 int save_tracing = tstate->tracing;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3696 int save_use_tracing = tstate->use_tracing;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3697 PyObject *result;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3698
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3699 tstate->tracing = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3700 tstate->use_tracing = ((tstate->c_tracefunc != NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3701 || (tstate->c_profilefunc != NULL));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3702 result = PyObject_Call(func, args, NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3703 tstate->tracing = save_tracing;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3704 tstate->use_tracing = save_use_tracing;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3705 return result;
28556
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28304
diff changeset
3706 }
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28304
diff changeset
3707
54297
dddf424bd669 Issue #6042:
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 53931
diff changeset
3708 /* See Objects/lnotab_notes.txt for a description of how tracing works. */
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
3709 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
3710 maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3711 PyFrameObject *frame, int *instr_lb, int *instr_ub,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3712 int *instr_prev)
24844
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24718
diff changeset
3713 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3714 int result = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3715 int line = frame->f_lineno;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3716
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3717 /* If the last instruction executed isn't in the current
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3718 instruction window, reset the window.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3719 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3720 if (frame->f_lasti < *instr_lb || frame->f_lasti >= *instr_ub) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3721 PyAddrPair bounds;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3722 line = _PyCode_CheckLineNumber(frame->f_code, frame->f_lasti,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3723 &bounds);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3724 *instr_lb = bounds.ap_lower;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3725 *instr_ub = bounds.ap_upper;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3726 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3727 /* If the last instruction falls at the start of a line or if
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3728 it represents a jump backwards, update the frame's line
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3729 number and call the trace function. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3730 if (frame->f_lasti == *instr_lb || frame->f_lasti < *instr_prev) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3731 frame->f_lineno = line;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3732 result = call_trace(func, obj, frame, PyTrace_LINE, Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3733 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3734 *instr_prev = frame->f_lasti;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3735 return result;
24844
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24718
diff changeset
3736 }
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24718
diff changeset
3737
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18293
diff changeset
3738 void
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18293
diff changeset
3739 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
3740 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3741 PyThreadState *tstate = PyThreadState_GET();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3742 PyObject *temp = tstate->c_profileobj;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3743 Py_XINCREF(arg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3744 tstate->c_profilefunc = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3745 tstate->c_profileobj = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3746 /* Must make sure that tracing is not ignored if 'temp' is freed */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3747 tstate->use_tracing = tstate->c_tracefunc != NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3748 Py_XDECREF(temp);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3749 tstate->c_profilefunc = func;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3750 tstate->c_profileobj = arg;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3751 /* Flag that tracing or profiling is turned on */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3752 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
3753 }
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18293
diff changeset
3754
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18293
diff changeset
3755 void
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18293
diff changeset
3756 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
3757 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3758 PyThreadState *tstate = PyThreadState_GET();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3759 PyObject *temp = tstate->c_traceobj;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3760 _Py_TracingPossible += (func != NULL) - (tstate->c_tracefunc != NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3761 Py_XINCREF(arg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3762 tstate->c_tracefunc = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3763 tstate->c_traceobj = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3764 /* Must make sure that profiling is not ignored if 'temp' is freed */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3765 tstate->use_tracing = tstate->c_profilefunc != NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3766 Py_XDECREF(temp);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3767 tstate->c_tracefunc = func;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3768 tstate->c_traceobj = arg;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3769 /* Flag that tracing or profiling is turned on */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3770 tstate->use_tracing = ((func != NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3771 || (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
3772 }
4cb34314bd97 Instead of initializing & interning the strings passed to the profile
Fred Drake <fdrake@acm.org>
parents: 18128
diff changeset
3773
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3774 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3775 PyEval_GetBuiltins(void)
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
3776 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3777 PyFrameObject *current_frame = PyEval_GetFrame();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3778 if (current_frame == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3779 return PyThreadState_GET()->interp->builtins;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3780 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3781 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
3782 }
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
3783
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3784 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3785 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
3786 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3787 PyFrameObject *current_frame = PyEval_GetFrame();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3788 if (current_frame == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3789 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3790 PyFrame_FastToLocals(current_frame);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3791 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
3792 }
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
3793
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3794 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3795 PyEval_GetGlobals(void)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3796 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3797 PyFrameObject *current_frame = PyEval_GetFrame();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3798 if (current_frame == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3799 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3800 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3801 return current_frame->f_globals;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3802 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3803
27978
4b99a701defe - PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents: 27781
diff changeset
3804 PyFrameObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3805 PyEval_GetFrame(void)
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
3806 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3807 PyThreadState *tstate = PyThreadState_GET();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3808 return _PyThreadState_GetFrame(tstate);
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
3809 }
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
3810
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
3811 int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3812 PyEval_GetRestricted(void)
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
3813 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3814 PyFrameObject *current_frame = PyEval_GetFrame();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3815 return current_frame == NULL ? 0 : PyFrame_IsRestricted(current_frame);
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
3816 }
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
3817
5606
495fbde64a73 Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents: 5557
diff changeset
3818 int
18611
fdb36a0c7e6e Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents: 18513
diff changeset
3819 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
3820 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3821 PyFrameObject *current_frame = PyEval_GetFrame();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3822 int result = cf->cf_flags != 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3823
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3824 if (current_frame != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3825 const int codeflags = current_frame->f_code->co_flags;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3826 const int compilerflags = codeflags & PyCF_MASK;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3827 if (compilerflags) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3828 result = 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3829 cf->cf_flags |= compilerflags;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3830 }
22468
eebae4f60d05 Disable the parser hacks that enabled the "yield" keyword using a future
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22398
diff changeset
3831 #if 0 /* future keyword */
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3832 if (codeflags & CO_GENERATOR_ALLOWED) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3833 result = 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3834 cf->cf_flags |= CO_GENERATOR_ALLOWED;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3835 }
22468
eebae4f60d05 Disable the parser hacks that enabled the "yield" keyword using a future
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22398
diff changeset
3836 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3837 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3838 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
3839 }
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
3840
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
3841 int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3842 Py_FlushLine(void)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3843 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3844 PyObject *f = PySys_GetObject("stdout");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3845 if (f == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3846 return 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3847 if (!PyFile_SoftSpace(f, 0))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3848 return 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3849 return PyFile_WriteString("\n", f);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3850 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3851
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3852
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3853 /* External interface to call any callable object.
60129
6df6c19fbae3 Issue #8276: PyEval_CallObject() is now only available in macro form. The
Antoine Pitrou <solipsis@pitrou.net>
parents: 59855
diff changeset
3854 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
3855
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3856 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3857 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
3858 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3859 PyObject *result;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3860
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3861 if (arg == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3862 arg = PyTuple_New(0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3863 if (arg == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3864 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3865 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3866 else if (!PyTuple_Check(arg)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3867 PyErr_SetString(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3868 "argument list must be a tuple");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3869 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3870 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3871 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3872 Py_INCREF(arg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3873
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3874 if (kw != NULL && !PyDict_Check(kw)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3875 PyErr_SetString(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3876 "keyword list must be a dictionary");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3877 Py_DECREF(arg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3878 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3879 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3880
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3881 result = PyObject_Call(func, arg, kw);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3882 Py_DECREF(arg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3883 return result;
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3884 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3885
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35745
diff changeset
3886 const char *
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 18611
diff changeset
3887 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
3888 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3889 if (PyMethod_Check(func))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3890 return PyEval_GetFuncName(PyMethod_GET_FUNCTION(func));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3891 else if (PyFunction_Check(func))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3892 return PyString_AsString(((PyFunctionObject*)func)->func_name);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3893 else if (PyCFunction_Check(func))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3894 return ((PyCFunctionObject*)func)->m_ml->ml_name;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3895 else if (PyClass_Check(func))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3896 return PyString_AsString(((PyClassObject*)func)->cl_name);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3897 else if (PyInstance_Check(func)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3898 return PyString_AsString(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3899 ((PyInstanceObject*)func)->in_class->cl_name);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3900 } else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3901 return func->ob_type->tp_name;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3902 }
17406
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
3903 }
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
3904
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35745
diff changeset
3905 const char *
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 18611
diff changeset
3906 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
3907 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3908 if (PyMethod_Check(func))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3909 return "()";
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3910 else if (PyFunction_Check(func))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3911 return "()";
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3912 else if (PyCFunction_Check(func))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3913 return "()";
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3914 else if (PyClass_Check(func))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3915 return " constructor";
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3916 else if (PyInstance_Check(func)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3917 return " instance";
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3918 } else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3919 return " object";
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3920 }
17406
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
3921 }
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
3922
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
3923 static void
24870
df2326a4894d Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24868
diff changeset
3924 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
3925 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3926 if (flags & METH_NOARGS)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3927 PyErr_Format(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3928 "%.200s() takes no arguments (%d given)",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3929 ((PyCFunctionObject *)func)->m_ml->ml_name,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3930 nargs);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3931 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3932 PyErr_Format(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3933 "%.200s() takes exactly one argument (%d given)",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3934 ((PyCFunctionObject *)func)->m_ml->ml_name,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3935 nargs);
24870
df2326a4894d Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24868
diff changeset
3936 }
df2326a4894d Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24868
diff changeset
3937
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
3938 #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
3939 if (tstate->use_tracing && tstate->c_profilefunc) { \
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3940 if (call_trace(tstate->c_profilefunc, \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3941 tstate->c_profileobj, \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3942 tstate->frame, PyTrace_C_CALL, \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3943 func)) { \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3944 x = NULL; \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3945 } \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3946 else { \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3947 x = call; \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3948 if (tstate->c_profilefunc != NULL) { \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3949 if (x == NULL) { \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3950 call_trace_protected(tstate->c_profilefunc, \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3951 tstate->c_profileobj, \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3952 tstate->frame, PyTrace_C_EXCEPTION, \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3953 func); \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3954 /* XXX should pass (type, value, tb) */ \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3955 } else { \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3956 if (call_trace(tstate->c_profilefunc, \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3957 tstate->c_profileobj, \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3958 tstate->frame, PyTrace_C_RETURN, \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3959 func)) { \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3960 Py_DECREF(x); \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3961 x = NULL; \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3962 } \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3963 } \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3964 } \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3965 } \
32409
77913be294b9 Massive performance improvement for C extension and builtin tracing code
Nicholas Bastin <nick.bastin@gmail.com>
parents: 32398
diff changeset
3966 } else { \
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3967 x = call; \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3968 }
31796
1c117dbb2def Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31768
diff changeset
3969
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
3970 static PyObject *
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
3971 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
3972 #ifdef WITH_TSC
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3973 , 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
3974 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3975 )
24868
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3976 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3977 int na = oparg & 0xff;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3978 int nk = (oparg>>8) & 0xff;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3979 int n = na + 2 * nk;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3980 PyObject **pfunc = (*pp_stack) - n - 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3981 PyObject *func = *pfunc;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3982 PyObject *x, *w;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3983
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3984 /* Always dispatch PyCFunction first, because these are
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3985 presumed to be the most frequent callable object.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3986 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3987 if (PyCFunction_Check(func) && nk == 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3988 int flags = PyCFunction_GET_FLAGS(func);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3989 PyThreadState *tstate = PyThreadState_GET();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3990
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3991 PCALL(PCALL_CFUNCTION);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3992 if (flags & (METH_NOARGS | METH_O)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3993 PyCFunction meth = PyCFunction_GET_FUNCTION(func);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3994 PyObject *self = PyCFunction_GET_SELF(func);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3995 if (flags & METH_NOARGS && na == 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3996 C_TRACE(x, (*meth)(self,NULL));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3997 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3998 else if (flags & METH_O && na == 1) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
3999 PyObject *arg = EXT_POP(*pp_stack);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4000 C_TRACE(x, (*meth)(self,arg));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4001 Py_DECREF(arg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4002 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4003 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4004 err_args(func, flags, na);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4005 x = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4006 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4007 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4008 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4009 PyObject *callargs;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4010 callargs = load_args(pp_stack, na);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4011 READ_TIMESTAMP(*pintr0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4012 C_TRACE(x, PyCFunction_Call(func,callargs,NULL));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4013 READ_TIMESTAMP(*pintr1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4014 Py_XDECREF(callargs);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4015 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4016 } else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4017 if (PyMethod_Check(func) && PyMethod_GET_SELF(func) != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4018 /* optimize access to bound methods */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4019 PyObject *self = PyMethod_GET_SELF(func);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4020 PCALL(PCALL_METHOD);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4021 PCALL(PCALL_BOUND_METHOD);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4022 Py_INCREF(self);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4023 func = PyMethod_GET_FUNCTION(func);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4024 Py_INCREF(func);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4025 Py_DECREF(*pfunc);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4026 *pfunc = self;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4027 na++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4028 n++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4029 } else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4030 Py_INCREF(func);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4031 READ_TIMESTAMP(*pintr0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4032 if (PyFunction_Check(func))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4033 x = fast_function(func, pp_stack, n, na, nk);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4034 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4035 x = do_call(func, pp_stack, na, nk);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4036 READ_TIMESTAMP(*pintr1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4037 Py_DECREF(func);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4038 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4039
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4040 /* Clear the stack of the function object. Also removes
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4041 the arguments in case they weren't consumed already
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4042 (fast_function() and err_args() leave them on the stack).
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4043 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4044 while ((*pp_stack) > pfunc) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4045 w = EXT_POP(*pp_stack);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4046 Py_DECREF(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4047 PCALL(PCALL_POP);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4048 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4049 return x;
24868
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
4050 }
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
4051
24870
df2326a4894d Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24868
diff changeset
4052 /* 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
4053 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
4054 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
4055 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
4056 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
4057 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
4058 done before evaluating the frame.
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
4059 */
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
4060
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
4061 static PyObject *
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
4062 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
4063 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4064 PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4065 PyObject *globals = PyFunction_GET_GLOBALS(func);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4066 PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4067 PyObject **d = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4068 int nd = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4069
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4070 PCALL(PCALL_FUNCTION);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4071 PCALL(PCALL_FAST_FUNCTION);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4072 if (argdefs == NULL && co->co_argcount == n && nk==0 &&
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4073 co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4074 PyFrameObject *f;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4075 PyObject *retval = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4076 PyThreadState *tstate = PyThreadState_GET();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4077 PyObject **fastlocals, **stack;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4078 int i;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4079
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4080 PCALL(PCALL_FASTER_FUNCTION);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4081 assert(globals != NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4082 /* XXX Perhaps we should create a specialized
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4083 PyFrame_New() that doesn't take locals, but does
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4084 take builtins without sanity checking them.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4085 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4086 assert(tstate != NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4087 f = PyFrame_New(tstate, co, globals, NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4088 if (f == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4089 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4090
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4091 fastlocals = f->f_localsplus;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4092 stack = (*pp_stack) - n;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4093
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4094 for (i = 0; i < n; i++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4095 Py_INCREF(*stack);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4096 fastlocals[i] = *stack++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4097 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4098 retval = PyEval_EvalFrameEx(f,0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4099 ++tstate->recursion_depth;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4100 Py_DECREF(f);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4101 --tstate->recursion_depth;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4102 return retval;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4103 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4104 if (argdefs != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4105 d = &PyTuple_GET_ITEM(argdefs, 0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4106 nd = Py_SIZE(argdefs);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4107 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4108 return PyEval_EvalCodeEx(co, globals,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4109 (PyObject *)NULL, (*pp_stack)-n, na,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4110 (*pp_stack)-2*nk, nk, d, nd,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4111 PyFunction_GET_CLOSURE(func));
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
4112 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
4113
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
4114 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
4115 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
4116 PyObject *func)
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
4117 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4118 PyObject *kwdict = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4119 if (orig_kwdict == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4120 kwdict = PyDict_New();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4121 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4122 kwdict = PyDict_Copy(orig_kwdict);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4123 Py_DECREF(orig_kwdict);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4124 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4125 if (kwdict == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4126 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4127 while (--nk >= 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4128 int err;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4129 PyObject *value = EXT_POP(*pp_stack);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4130 PyObject *key = EXT_POP(*pp_stack);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4131 if (PyDict_GetItem(kwdict, key) != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4132 PyErr_Format(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4133 "%.200s%s got multiple values "
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4134 "for keyword argument '%.200s'",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4135 PyEval_GetFuncName(func),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4136 PyEval_GetFuncDesc(func),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4137 PyString_AsString(key));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4138 Py_DECREF(key);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4139 Py_DECREF(value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4140 Py_DECREF(kwdict);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4141 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4142 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4143 err = PyDict_SetItem(kwdict, key, value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4144 Py_DECREF(key);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4145 Py_DECREF(value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4146 if (err) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4147 Py_DECREF(kwdict);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4148 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4149 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4150 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4151 return kwdict;
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
4152 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
4153
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
4154 static PyObject *
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
4155 update_star_args(int nstack, int nstar, PyObject *stararg,
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4156 PyObject ***pp_stack)
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
4157 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4158 PyObject *callargs, *w;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4159
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4160 callargs = PyTuple_New(nstack + nstar);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4161 if (callargs == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4162 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4163 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4164 if (nstar) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4165 int i;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4166 for (i = 0; i < nstar; i++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4167 PyObject *a = PyTuple_GET_ITEM(stararg, i);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4168 Py_INCREF(a);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4169 PyTuple_SET_ITEM(callargs, nstack + i, a);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4170 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4171 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4172 while (--nstack >= 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4173 w = EXT_POP(*pp_stack);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4174 PyTuple_SET_ITEM(callargs, nstack, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4175 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4176 return callargs;
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
4177 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
4178
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
4179 static PyObject *
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
4180 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
4181 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4182 PyObject *args = PyTuple_New(na);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4183 PyObject *w;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4184
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4185 if (args == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4186 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4187 while (--na >= 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4188 w = EXT_POP(*pp_stack);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4189 PyTuple_SET_ITEM(args, na, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4190 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4191 return args;
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
4192 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
4193
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
4194 static PyObject *
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
4195 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
4196 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4197 PyObject *callargs = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4198 PyObject *kwdict = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4199 PyObject *result = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4200
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4201 if (nk > 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4202 kwdict = update_keyword_args(NULL, nk, pp_stack, func);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4203 if (kwdict == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4204 goto call_fail;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4205 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4206 callargs = load_args(pp_stack, na);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4207 if (callargs == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4208 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
4209 #ifdef CALL_PROFILE
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4210 /* At this point, we have to look at the type of func to
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4211 update the call stats properly. Do it here so as to avoid
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4212 exposing the call stats machinery outside ceval.c
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4213 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4214 if (PyFunction_Check(func))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4215 PCALL(PCALL_FUNCTION);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4216 else if (PyMethod_Check(func))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4217 PCALL(PCALL_METHOD);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4218 else if (PyType_Check(func))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4219 PCALL(PCALL_TYPE);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4220 else if (PyCFunction_Check(func))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4221 PCALL(PCALL_CFUNCTION);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4222 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4223 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
4224 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4225 if (PyCFunction_Check(func)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4226 PyThreadState *tstate = PyThreadState_GET();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4227 C_TRACE(result, PyCFunction_Call(func, callargs, kwdict));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4228 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4229 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4230 result = PyObject_Call(func, callargs, kwdict);
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
4231 call_fail:
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4232 Py_XDECREF(callargs);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4233 Py_XDECREF(kwdict);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4234 return result;
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
4235 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
4236
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
4237 static PyObject *
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
4238 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
4239 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4240 int nstar = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4241 PyObject *callargs = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4242 PyObject *stararg = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4243 PyObject *kwdict = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4244 PyObject *result = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4245
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4246 if (flags & CALL_FLAG_KW) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4247 kwdict = EXT_POP(*pp_stack);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4248 if (!PyDict_Check(kwdict)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4249 PyObject *d;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4250 d = PyDict_New();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4251 if (d == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4252 goto ext_call_fail;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4253 if (PyDict_Update(d, kwdict) != 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4254 Py_DECREF(d);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4255 /* PyDict_Update raises attribute
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4256 * error (percolated from an attempt
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4257 * to get 'keys' attribute) instead of
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4258 * a type error if its second argument
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4259 * is not a mapping.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4260 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4261 if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4262 PyErr_Format(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4263 "%.200s%.200s argument after ** "
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4264 "must be a mapping, not %.200s",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4265 PyEval_GetFuncName(func),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4266 PyEval_GetFuncDesc(func),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4267 kwdict->ob_type->tp_name);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4268 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4269 goto ext_call_fail;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4270 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4271 Py_DECREF(kwdict);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4272 kwdict = d;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4273 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4274 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4275 if (flags & CALL_FLAG_VAR) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4276 stararg = EXT_POP(*pp_stack);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4277 if (!PyTuple_Check(stararg)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4278 PyObject *t = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4279 t = PySequence_Tuple(stararg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4280 if (t == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4281 if (PyErr_ExceptionMatches(PyExc_TypeError)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4282 PyErr_Format(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4283 "%.200s%.200s argument after * "
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4284 "must be a sequence, not %200s",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4285 PyEval_GetFuncName(func),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4286 PyEval_GetFuncDesc(func),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4287 stararg->ob_type->tp_name);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4288 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4289 goto ext_call_fail;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4290 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4291 Py_DECREF(stararg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4292 stararg = t;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4293 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4294 nstar = PyTuple_GET_SIZE(stararg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4295 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4296 if (nk > 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4297 kwdict = update_keyword_args(kwdict, nk, pp_stack, func);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4298 if (kwdict == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4299 goto ext_call_fail;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4300 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4301 callargs = update_star_args(na, nstar, stararg, pp_stack);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4302 if (callargs == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4303 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
4304 #ifdef CALL_PROFILE
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4305 /* At this point, we have to look at the type of func to
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4306 update the call stats properly. Do it here so as to avoid
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4307 exposing the call stats machinery outside ceval.c
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4308 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4309 if (PyFunction_Check(func))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4310 PCALL(PCALL_FUNCTION);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4311 else if (PyMethod_Check(func))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4312 PCALL(PCALL_METHOD);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4313 else if (PyType_Check(func))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4314 PCALL(PCALL_TYPE);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4315 else if (PyCFunction_Check(func))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4316 PCALL(PCALL_CFUNCTION);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4317 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4318 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
4319 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4320 if (PyCFunction_Check(func)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4321 PyThreadState *tstate = PyThreadState_GET();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4322 C_TRACE(result, PyCFunction_Call(func, callargs, kwdict));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4323 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4324 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4325 result = PyObject_Call(func, callargs, kwdict);
43408
81478465fef3 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
4326 ext_call_fail:
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4327 Py_XDECREF(callargs);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4328 Py_XDECREF(kwdict);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4329 Py_XDECREF(stararg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4330 return result;
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
4331 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
4332
36882
6a9c7165b17b Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents: 36877
diff changeset
4333 /* 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
4334 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
4335 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
4336 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
4337 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
4338 */
21441
05ad7a69d933 _PyEval_SliceIndex(): explain why a NULL argument is allowed (thanks
Tim Peters <tim.peters@gmail.com>
parents: 21440
diff changeset
4339 /* 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
4340 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
4341 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
4342 */
12614
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
4343 int
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36475
diff changeset
4344 _PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4345 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4346 if (v != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4347 Py_ssize_t x;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4348 if (PyInt_Check(v)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4349 /* XXX(nnorwitz): I think PyInt_AS_LONG is correct,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4350 however, it looks like it should be AsSsize_t.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4351 There should be a comment here explaining why.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4352 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4353 x = PyInt_AS_LONG(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4354 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4355 else if (PyIndex_Check(v)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4356 x = PyNumber_AsSsize_t(v, NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4357 if (x == -1 && PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4358 return 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4359 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4360 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4361 PyErr_SetString(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4362 "slice indices must be integers or "
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4363 "None or have an __index__ method");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4364 return 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4365 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4366 *pi = x;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4367 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4368 return 1;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4369 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4370
36882
6a9c7165b17b Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents: 36877
diff changeset
4371 #undef ISINDEX
39463
6cafdc81cfde Patch #1538606, Patch to fix __index__() clipping.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39455
diff changeset
4372 #define ISINDEX(x) ((x) == NULL || \
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4373 PyInt_Check(x) || PyLong_Check(x) || PyIndex_Check(x))
19369
8c2a29b7548e Fix SF bug #443600:
Guido van Rossum <guido@python.org>
parents: 19350
diff changeset
4374
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
4375 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
4376 apply_slice(PyObject *u, PyObject *v, PyObject *w) /* return u[v:w] */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4377 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4378 PyTypeObject *tp = u->ob_type;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4379 PySequenceMethods *sq = tp->tp_as_sequence;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4380
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4381 if (sq && sq->sq_slice && ISINDEX(v) && ISINDEX(w)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4382 Py_ssize_t ilow = 0, ihigh = PY_SSIZE_T_MAX;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4383 if (!_PyEval_SliceIndex(v, &ilow))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4384 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4385 if (!_PyEval_SliceIndex(w, &ihigh))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4386 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4387 return PySequence_GetSlice(u, ilow, ihigh);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4388 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4389 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4390 PyObject *slice = PySlice_New(v, w, NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4391 if (slice != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4392 PyObject *res = PyObject_GetItem(u, slice);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4393 Py_DECREF(slice);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4394 return res;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4395 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4396 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4397 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4398 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4399 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
4400
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
4401 static int
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
4402 assign_slice(PyObject *u, PyObject *v, PyObject *w, PyObject *x)
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4403 /* u[v:w] = x */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4404 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4405 PyTypeObject *tp = u->ob_type;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4406 PySequenceMethods *sq = tp->tp_as_sequence;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4407
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4408 if (sq && sq->sq_ass_slice && ISINDEX(v) && ISINDEX(w)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4409 Py_ssize_t ilow = 0, ihigh = PY_SSIZE_T_MAX;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4410 if (!_PyEval_SliceIndex(v, &ilow))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4411 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4412 if (!_PyEval_SliceIndex(w, &ihigh))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4413 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4414 if (x == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4415 return PySequence_DelSlice(u, ilow, ihigh);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4416 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4417 return PySequence_SetSlice(u, ilow, ihigh, x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4418 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4419 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4420 PyObject *slice = PySlice_New(v, w, NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4421 if (slice != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4422 int res;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4423 if (x != NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4424 res = PyObject_SetItem(u, slice, x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4425 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4426 res = PyObject_DelItem(u, slice);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4427 Py_DECREF(slice);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4428 return res;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4429 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4430 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4431 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4432 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4433 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4434
45818
ff0ab7b28f49 - Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents: 45703
diff changeset
4435 #define Py3kExceptionClass_Check(x) \
ff0ab7b28f49 - Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents: 45703
diff changeset
4436 (PyType_Check((x)) && \
ff0ab7b28f49 - Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents: 45703
diff changeset
4437 PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS))
ff0ab7b28f49 - Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents: 45703
diff changeset
4438
ff0ab7b28f49 - Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents: 45703
diff changeset
4439 #define CANNOT_CATCH_MSG "catching classes that don't inherit from " \
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4440 "BaseException is not allowed in 3.x"
45818
ff0ab7b28f49 - Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents: 45703
diff changeset
4441
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
4442 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
4443 cmp_outcome(int op, register PyObject *v, register PyObject *w)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4444 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4445 int res = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4446 switch (op) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4447 case PyCmp_IS:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4448 res = (v == w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4449 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4450 case PyCmp_IS_NOT:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4451 res = (v != w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4452 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4453 case PyCmp_IN:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4454 res = PySequence_Contains(w, v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4455 if (res < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4456 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4457 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4458 case PyCmp_NOT_IN:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4459 res = PySequence_Contains(w, v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4460 if (res < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4461 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4462 res = !res;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4463 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4464 case PyCmp_EXC_MATCH:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4465 if (PyTuple_Check(w)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4466 Py_ssize_t i, length;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4467 length = PyTuple_Size(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4468 for (i = 0; i < length; i += 1) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4469 PyObject *exc = PyTuple_GET_ITEM(w, i);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4470 if (PyString_Check(exc)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4471 int ret_val;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4472 ret_val = PyErr_WarnEx(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4473 PyExc_DeprecationWarning,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4474 "catching of string "
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4475 "exceptions is deprecated", 1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4476 if (ret_val < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4477 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4478 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4479 else if (Py_Py3kWarningFlag &&
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4480 !PyTuple_Check(exc) &&
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4481 !Py3kExceptionClass_Check(exc))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4482 {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4483 int ret_val;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4484 ret_val = PyErr_WarnEx(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4485 PyExc_DeprecationWarning,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4486 CANNOT_CATCH_MSG, 1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4487 if (ret_val < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4488 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4489 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4490 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4491 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4492 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4493 if (PyString_Check(w)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4494 int ret_val;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4495 ret_val = PyErr_WarnEx(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4496 PyExc_DeprecationWarning,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4497 "catching of string "
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4498 "exceptions is deprecated", 1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4499 if (ret_val < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4500 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4501 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4502 else if (Py_Py3kWarningFlag &&
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4503 !PyTuple_Check(w) &&
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4504 !Py3kExceptionClass_Check(w))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4505 {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4506 int ret_val;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4507 ret_val = PyErr_WarnEx(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4508 PyExc_DeprecationWarning,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4509 CANNOT_CATCH_MSG, 1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4510 if (ret_val < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4511 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4512 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4513 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4514 res = PyErr_GivenExceptionMatches(v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4515 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4516 default:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4517 return PyObject_RichCompare(v, w, op);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4518 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4519 v = res ? Py_True : Py_False;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4520 Py_INCREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4521 return v;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4522 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4523
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
4524 static 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
4525 import_from(PyObject *v, PyObject *name)
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
4526 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4527 PyObject *x;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4528
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4529 x = PyObject_GetAttr(v, name);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4530 if (x == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4531 PyErr_Format(PyExc_ImportError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4532 "cannot import name %.230s",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4533 PyString_AsString(name));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4534 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4535 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
4536 }
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
4537
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
4538 static int
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
4539 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
4540 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4541 PyObject *all = PyObject_GetAttrString(v, "__all__");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4542 PyObject *dict, *name, *value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4543 int skip_leading_underscores = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4544 int pos, err;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4545
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4546 if (all == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4547 if (!PyErr_ExceptionMatches(PyExc_AttributeError))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4548 return -1; /* Unexpected error */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4549 PyErr_Clear();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4550 dict = PyObject_GetAttrString(v, "__dict__");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4551 if (dict == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4552 if (!PyErr_ExceptionMatches(PyExc_AttributeError))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4553 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4554 PyErr_SetString(PyExc_ImportError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4555 "from-import-* object has no __dict__ and no __all__");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4556 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4557 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4558 all = PyMapping_Keys(dict);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4559 Py_DECREF(dict);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4560 if (all == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4561 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4562 skip_leading_underscores = 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4563 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4564
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4565 for (pos = 0, err = 0; ; pos++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4566 name = PySequence_GetItem(all, pos);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4567 if (name == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4568 if (!PyErr_ExceptionMatches(PyExc_IndexError))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4569 err = -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4570 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4571 PyErr_Clear();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4572 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4573 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4574 if (skip_leading_underscores &&
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4575 PyString_Check(name) &&
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4576 PyString_AS_STRING(name)[0] == '_')
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4577 {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4578 Py_DECREF(name);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4579 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4580 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4581 value = PyObject_GetAttr(v, name);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4582 if (value == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4583 err = -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4584 else if (PyDict_CheckExact(locals))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4585 err = PyDict_SetItem(locals, name, value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4586 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4587 err = PyObject_SetItem(locals, name, value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4588 Py_DECREF(name);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4589 Py_XDECREF(value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4590 if (err != 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4591 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4592 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4593 Py_DECREF(all);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4594 return err;
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
4595 }
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
4596
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
4597 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
4598 build_class(PyObject *methods, PyObject *bases, PyObject *name)
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
4599 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4600 PyObject *metaclass = NULL, *result, *base;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4601
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4602 if (PyDict_Check(methods))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4603 metaclass = PyDict_GetItemString(methods, "__metaclass__");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4604 if (metaclass != NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4605 Py_INCREF(metaclass);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4606 else if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4607 base = PyTuple_GET_ITEM(bases, 0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4608 metaclass = PyObject_GetAttrString(base, "__class__");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4609 if (metaclass == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4610 PyErr_Clear();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4611 metaclass = (PyObject *)base->ob_type;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4612 Py_INCREF(metaclass);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4613 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4614 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4615 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4616 PyObject *g = PyEval_GetGlobals();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4617 if (g != NULL && PyDict_Check(g))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4618 metaclass = PyDict_GetItemString(g, "__metaclass__");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4619 if (metaclass == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4620 metaclass = (PyObject *) &PyClass_Type;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4621 Py_INCREF(metaclass);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4622 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4623 result = PyObject_CallFunctionObjArgs(metaclass, name, bases, methods,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4624 NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4625 Py_DECREF(metaclass);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4626 if (result == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4627 /* A type error here likely means that the user passed
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4628 in a base that was not a class (such the random module
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4629 instead of the random.random type). Help them out with
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4630 by augmenting the error message with more information.*/
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4631
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4632 PyObject *ptype, *pvalue, *ptraceback;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4633
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4634 PyErr_Fetch(&ptype, &pvalue, &ptraceback);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4635 if (PyString_Check(pvalue)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4636 PyObject *newmsg;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4637 newmsg = PyString_FromFormat(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4638 "Error when calling the metaclass bases\n"
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4639 " %s",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4640 PyString_AS_STRING(pvalue));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4641 if (newmsg != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4642 Py_DECREF(pvalue);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4643 pvalue = newmsg;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4644 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4645 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4646 PyErr_Restore(ptype, pvalue, ptraceback);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4647 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4648 return result;
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
4649 }
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
4650
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
4651 static int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
4652 exec_statement(PyFrameObject *f, PyObject *prog, PyObject *globals,
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4653 PyObject *locals)
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
4654 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4655 int n;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4656 PyObject *v;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4657 int plain = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4658
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4659 if (PyTuple_Check(prog) && globals == Py_None && locals == Py_None &&
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4660 ((n = PyTuple_Size(prog)) == 2 || n == 3)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4661 /* Backward compatibility hack */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4662 globals = PyTuple_GetItem(prog, 1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4663 if (n == 3)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4664 locals = PyTuple_GetItem(prog, 2);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4665 prog = PyTuple_GetItem(prog, 0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4666 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4667 if (globals == Py_None) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4668 globals = PyEval_GetGlobals();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4669 if (locals == Py_None) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4670 locals = PyEval_GetLocals();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4671 plain = 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4672 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4673 if (!globals || !locals) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4674 PyErr_SetString(PyExc_SystemError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4675 "globals and locals cannot be NULL");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4676 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4677 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4678 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4679 else if (locals == Py_None)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4680 locals = globals;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4681 if (!PyString_Check(prog) &&
51032
551257c8058a fix building the core with --disable-unicode
Benjamin Peterson <benjamin@python.org>
parents: 50936
diff changeset
4682 #ifdef Py_USING_UNICODE
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4683 !PyUnicode_Check(prog) &&
51032
551257c8058a fix building the core with --disable-unicode
Benjamin Peterson <benjamin@python.org>
parents: 50936
diff changeset
4684 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4685 !PyCode_Check(prog) &&
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4686 !PyFile_Check(prog)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4687 PyErr_SetString(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4688 "exec: arg 1 must be a string, file, or code object");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4689 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4690 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4691 if (!PyDict_Check(globals)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4692 PyErr_SetString(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4693 "exec: arg 2 must be a dictionary or None");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4694 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4695 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4696 if (!PyMapping_Check(locals)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4697 PyErr_SetString(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4698 "exec: arg 3 must be a mapping or None");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4699 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4700 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4701 if (PyDict_GetItemString(globals, "__builtins__") == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4702 PyDict_SetItemString(globals, "__builtins__", f->f_builtins);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4703 if (PyCode_Check(prog)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4704 if (PyCode_GetNumFree((PyCodeObject *)prog) > 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4705 PyErr_SetString(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4706 "code object passed to exec may not contain free variables");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4707 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4708 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4709 v = PyEval_EvalCode((PyCodeObject *) prog, globals, locals);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4710 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4711 else if (PyFile_Check(prog)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4712 FILE *fp = PyFile_AsFile(prog);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4713 char *name = PyString_AsString(PyFile_Name(prog));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4714 PyCompilerFlags cf;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4715 if (name == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4716 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4717 cf.cf_flags = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4718 if (PyEval_MergeCompilerFlags(&cf))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4719 v = PyRun_FileFlags(fp, name, Py_file_input, globals,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4720 locals, &cf);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4721 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4722 v = PyRun_File(fp, name, Py_file_input, globals,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4723 locals);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4724 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4725 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4726 PyObject *tmp = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4727 char *str;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4728 PyCompilerFlags cf;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4729 cf.cf_flags = 0;
27781
cc01fb654ce3 patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents: 27712
diff changeset
4730 #ifdef Py_USING_UNICODE
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4731 if (PyUnicode_Check(prog)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4732 tmp = PyUnicode_AsUTF8String(prog);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4733 if (tmp == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4734 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4735 prog = tmp;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4736 cf.cf_flags |= PyCF_SOURCE_IS_UTF8;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4737 }
27781
cc01fb654ce3 patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents: 27712
diff changeset
4738 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4739 if (PyString_AsStringAndSize(prog, &str, NULL))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4740 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4741 if (PyEval_MergeCompilerFlags(&cf))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4742 v = PyRun_StringFlags(str, Py_file_input, globals,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4743 locals, &cf);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4744 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4745 v = PyRun_String(str, Py_file_input, globals, locals);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4746 Py_XDECREF(tmp);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4747 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4748 if (plain)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4749 PyFrame_LocalsToFast(f, 0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4750 if (v == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4751 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4752 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4753 return 0;
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
4754 }
2338
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
4755
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
4756 static void
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
4757 format_exc_check_arg(PyObject *exc, char *format_str, PyObject *obj)
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
4758 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4759 char *obj_str;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4760
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4761 if (!obj)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4762 return;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4763
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4764 obj_str = PyString_AsString(obj);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4765 if (!obj_str)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4766 return;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4767
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4768 PyErr_Format(exc, format_str, obj_str);
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
4769 }
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4770
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
4771 static PyObject *
32974
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4772 string_concatenate(PyObject *v, PyObject *w,
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4773 PyFrameObject *f, unsigned char *next_instr)
32974
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4774 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4775 /* This function implements 'variable += expr' when both arguments
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4776 are strings. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4777 Py_ssize_t v_len = PyString_GET_SIZE(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4778 Py_ssize_t w_len = PyString_GET_SIZE(w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4779 Py_ssize_t new_len = v_len + w_len;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4780 if (new_len < 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4781 PyErr_SetString(PyExc_OverflowError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4782 "strings are too large to concat");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4783 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4784 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4785
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4786 if (v->ob_refcnt == 2) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4787 /* In the common case, there are 2 references to the value
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4788 * stored in 'variable' when the += is performed: one on the
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4789 * value stack (in 'v') and one still stored in the
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4790 * 'variable'. We try to delete the variable now to reduce
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4791 * the refcnt to 1.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4792 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4793 switch (*next_instr) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4794 case STORE_FAST:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4795 {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4796 int oparg = PEEKARG();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4797 PyObject **fastlocals = f->f_localsplus;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4798 if (GETLOCAL(oparg) == v)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4799 SETLOCAL(oparg, NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4800 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4801 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4802 case STORE_DEREF:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4803 {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4804 PyObject **freevars = (f->f_localsplus +
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4805 f->f_code->co_nlocals);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4806 PyObject *c = freevars[PEEKARG()];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4807 if (PyCell_GET(c) == v)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4808 PyCell_Set(c, NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4809 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4810 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4811 case STORE_NAME:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4812 {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4813 PyObject *names = f->f_code->co_names;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4814 PyObject *name = GETITEM(names, PEEKARG());
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4815 PyObject *locals = f->f_locals;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4816 if (PyDict_CheckExact(locals) &&
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4817 PyDict_GetItem(locals, name) == v) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4818 if (PyDict_DelItem(locals, name) != 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4819 PyErr_Clear();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4820 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4821 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4822 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4823 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4824 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4825 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4826
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4827 if (v->ob_refcnt == 1 && !PyString_CHECK_INTERNED(v)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4828 /* Now we own the last reference to 'v', so we can resize it
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4829 * in-place.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4830 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4831 if (_PyString_Resize(&v, new_len) != 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4832 /* XXX if _PyString_Resize() fails, 'v' has been
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4833 * deallocated so it cannot be put back into
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4834 * 'variable'. The MemoryError is raised when there
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4835 * is no value in 'variable', which might (very
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4836 * remotely) be a cause of incompatibilities.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4837 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4838 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4839 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4840 /* copy 'w' into the newly allocated area of 'v' */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4841 memcpy(PyString_AS_STRING(v) + v_len,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4842 PyString_AS_STRING(w), w_len);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4843 return v;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4844 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4845 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4846 /* When in-place resizing is not an option. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4847 PyString_Concat(&v, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4848 return v;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4849 }
32974
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4850 }
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4851
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4852 #ifdef DYNAMIC_EXECUTION_PROFILE
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4853
38425
ca657e0bd09c needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents: 38418
diff changeset
4854 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
4855 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
4856 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4857 int i;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4858 PyObject *l = PyList_New(256);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4859 if (l == NULL) return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4860 for (i = 0; i < 256; i++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4861 PyObject *x = PyInt_FromLong(a[i]);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4862 if (x == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4863 Py_DECREF(l);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4864 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4865 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4866 PyList_SetItem(l, i, x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4867 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4868 for (i = 0; i < 256; i++)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4869 a[i] = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4870 return l;
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4871 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4872
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4873 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
4874 _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
4875 {
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4876 #ifndef DXPAIRS
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4877 return getarray(dxp);
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4878 #else
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4879 int i;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4880 PyObject *l = PyList_New(257);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4881 if (l == NULL) return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4882 for (i = 0; i < 257; i++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4883 PyObject *x = getarray(dxpairs[i]);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4884 if (x == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4885 Py_DECREF(l);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4886 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4887 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4888 PyList_SetItem(l, i, x);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4889 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61271
diff changeset
4890 return l;
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4891 #endif
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4892 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4893
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4894 #endif