Mercurial > cpython-lru_cache-weakref
annotate Python/ceval.c @ 54297:dddf424bd669 legacy-trunk
Issue #6042:
lnotab-based tracing is very complicated and isn't documented very well. There
were at least 3 comment blocks purporting to document co_lnotab, and none did a
very good job. This patch unifies them into Objects/lnotab_notes.txt which
tries to completely capture the current state of affairs.
I also discovered that we've attached 2 layers of patches to the basic tracing
scheme. The first layer avoids jumping to instructions that don't start a line,
to avoid problems in if statements and while loops. The second layer
discovered that jumps backward do need to trace at instructions that don't
start a line, so it added extra lnotab entries for 'while' and 'for' loops, and
added a special case for backward jumps within the same line. I replaced these
patches by just treating forward and backward jumps differently.
| author | Jeffrey Yasskin <jyasskin@gmail.com> |
|---|---|
| date | Sat, 23 May 2009 23:23:01 +0000 |
| parents | 9ef683d41c9b |
| children | 145376df3ad7 |
| rev | line source |
|---|---|
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
119
diff
changeset
|
1 |
| 86 | 2 /* Execute compiled code */ |
| 69 | 3 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4 /* XXX TO DO: |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
5 XXX speed up searching for keywords by using a dictionary |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
6 XXX document it! |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
7 */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
8 |
|
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 | 12 #include "Python.h" |
| 86 | 13 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
14 #include "code.h" |
| 86 | 15 #include "frameobject.h" |
| 926 | 16 #include "eval.h" |
| 69 | 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 | 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 | 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 | 30 #if defined(__ppc__) /* <- Don't know if this is the correct symbol; this |
|
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
|
31 section should work for GCC on any PowerPC |
|
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
|
32 platform, irrespective of OS. |
|
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
|
33 POWER? Who knows :-) */ |
| 33104 | 34 |
|
34442
683719e04218
Change the name of the macro used by --with-tsc builds to the less
Michael W. Hudson <mwh@python.net>
parents:
34371
diff
changeset
|
35 #define READ_TIMESTAMP(var) ppc_getcounter(&var) |
| 33104 | 36 |
|
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 | 38 ppc_getcounter(uint64 *v) |
| 39 { | |
| 40 register unsigned long tbu, tb, tbu2; | |
| 41 | |
| 42 loop: | |
| 43 asm volatile ("mftbu %0" : "=r" (tbu) ); | |
| 44 asm volatile ("mftb %0" : "=r" (tb) ); | |
| 45 asm volatile ("mftbu %0" : "=r" (tbu2)); | |
| 46 if (__builtin_expect(tbu != tbu2, 0)) goto loop; | |
| 47 | |
| 38418 | 48 /* The slightly peculiar way of writing the next lines is |
| 33104 | 49 compiled better by GCC than any other way I tried. */ |
| 50 ((long*)(v))[0] = tbu; | |
| 51 ((long*)(v))[1] = tb; | |
| 52 } | |
| 53 | |
|
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
|
54 #else /* this is for linux/x86 (and probably any other GCC/x86 combo) */ |
|
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
|
55 |
|
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
|
56 #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
|
57 __asm__ __volatile__("rdtsc" : "=A" (val)) |
| 33104 | 58 |
| 59 #endif | |
| 60 | |
| 38418 | 61 void dump_tsc(int opcode, int ticked, uint64 inst0, uint64 inst1, |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
62 uint64 loop0, uint64 loop1, uint64 intr0, uint64 intr1) |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
63 { |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
64 uint64 intr, inst, loop; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
65 PyThreadState *tstate = PyThreadState_Get(); |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
66 if (!tstate->interp->tscdump) |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
67 return; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
68 intr = intr1 - intr0; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
69 inst = inst1 - inst0 - intr; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
70 loop = loop1 - loop0 - intr; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
71 fprintf(stderr, "opcode=%03d t=%d inst=%06lld loop=%06lld\n", |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
72 opcode, ticked, inst, loop); |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
73 } |
| 33104 | 74 |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
75 #endif |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
76 |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
77 /* 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
|
78 /* #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
|
79 |
|
4839
4567e158d20c
Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents:
4667
diff
changeset
|
80 #ifdef Py_DEBUG |
| 567 | 81 /* For debugging the interpreter: */ |
| 82 #define LLTRACE 1 /* Low-level trace feature */ | |
| 83 #define CHECKEXC 1 /* Double-check exception checking */ | |
| 69 | 84 #endif |
| 85 | |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
86 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
|
87 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
88 /* Forward declarations */ |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
89 #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
|
90 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
|
91 #else |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
92 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
|
93 #endif |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
94 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
|
95 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
|
96 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
|
97 static PyObject * update_keyword_args(PyObject *, int, PyObject ***, |
|
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
|
98 PyObject *); |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
99 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
|
100 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
|
101 #define CALL_FLAG_VAR 1 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
102 #define CALL_FLAG_KW 2 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
103 |
|
746
6c0f16008bd9
lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents:
708
diff
changeset
|
104 #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
|
105 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
|
106 static int prtrace(PyObject *, char *); |
|
746
6c0f16008bd9
lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents:
708
diff
changeset
|
107 #endif |
|
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 int call_trace(Py_tracefunc, PyObject *, PyFrameObject *, |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
109 int, PyObject *); |
|
43845
76844a0a579f
Merge from py3k branch:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43784
diff
changeset
|
110 static int call_trace_protected(Py_tracefunc, PyObject *, |
|
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
|
111 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
|
112 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
|
113 static int maybe_call_line_trace(Py_tracefunc, PyObject *, |
| 31768 | 114 PyFrameObject *, int *, int *, int *); |
| 24844 | 115 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
116 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
|
117 static int assign_slice(PyObject *, PyObject *, |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
118 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 static int exec_statement(PyFrameObject *, |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
124 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
|
125 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
|
126 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
|
127 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
|
128 static PyObject * string_concatenate(PyObject *, PyObject *, |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
129 PyFrameObject *, unsigned char *); |
|
50936
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
130 static PyObject * kwd_as_string(PyObject *); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
131 |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
132 #define NAME_ERROR_MSG \ |
| 15318 | 133 "name '%.200s' is not defined" |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
134 #define GLOBAL_NAME_ERROR_MSG \ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
135 "global name '%.200s' is not defined" |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
136 #define UNBOUNDLOCAL_ERROR_MSG \ |
| 15318 | 137 "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
|
138 #define UNBOUNDFREE_ERROR_MSG \ |
|
a34293ced63b
Change error message raised when free variable is not yet bound. It
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17490
diff
changeset
|
139 "free variable '%.200s' referenced before assignment" \ |
|
a34293ced63b
Change error message raised when free variable is not yet bound. It
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17490
diff
changeset
|
140 " in enclosing scope" |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
141 |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
142 /* Dynamic execution profile */ |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
143 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
144 #ifdef DXPAIRS |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
145 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
|
146 #define dxp dxpairs[256] |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
147 #else |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
148 static long dxp[256]; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
149 #endif |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
150 #endif |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
151 |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
152 /* 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
|
153 #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
|
154 #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
|
155 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
|
156 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
157 #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
|
158 #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
|
159 #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
|
160 #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
|
161 #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
|
162 #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
|
163 #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
|
164 #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
|
165 #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
|
166 #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
|
167 #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
|
168 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
169 /* 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
|
170 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
171 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
|
172 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
173 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
|
174 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
|
175 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
176 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
|
177 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
|
178 twice. |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
179 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
180 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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 */ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
186 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
187 #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
|
188 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
189 PyObject * |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
190 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
|
191 { |
|
40193
e2e80a016945
[Bug #1542016] Report PCALL_POP value. This makes the return value of sys.callstats() match its docstring.
Andrew M. Kuchling <amk@amk.ca>
parents:
39466
diff
changeset
|
192 return Py_BuildValue("iiiiiiiiiii", |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
193 pcall[0], pcall[1], pcall[2], pcall[3], |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
194 pcall[4], pcall[5], pcall[6], pcall[7], |
|
40193
e2e80a016945
[Bug #1542016] Report PCALL_POP value. This makes the return value of sys.callstats() match its docstring.
Andrew M. Kuchling <amk@amk.ca>
parents:
39466
diff
changeset
|
195 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
|
196 } |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
197 #else |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
198 #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
|
199 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
200 PyObject * |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
201 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
|
202 { |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
203 Py_INCREF(Py_None); |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
204 return Py_None; |
|
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 #endif |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
207 |
|
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
|
208 |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
209 #ifdef WITH_THREAD |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
210 |
|
38716
42808526511c
Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents:
38536
diff
changeset
|
211 #ifdef HAVE_ERRNO_H |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
212 #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
|
213 #endif |
|
9203
07dae6fdae79
Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents:
9048
diff
changeset
|
214 #include "pythread.h" |
| 926 | 215 |
|
29643
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
216 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
|
217 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
|
218 static long main_thread = 0; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
219 |
|
33715
a46b76eb9053
SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents:
33501
diff
changeset
|
220 int |
|
a46b76eb9053
SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents:
33501
diff
changeset
|
221 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
|
222 { |
|
a46b76eb9053
SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents:
33501
diff
changeset
|
223 return interpreter_lock != 0; |
|
a46b76eb9053
SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents:
33501
diff
changeset
|
224 } |
|
a46b76eb9053
SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents:
33501
diff
changeset
|
225 |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
226 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
227 PyEval_InitThreads(void) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
228 { |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
229 if (interpreter_lock) |
| 1179 | 230 return; |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
231 interpreter_lock = PyThread_allocate_lock(); |
|
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
232 PyThread_acquire_lock(interpreter_lock, 1); |
|
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
233 main_thread = PyThread_get_thread_ident(); |
| 926 | 234 } |
| 235 | |
|
5865
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
236 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
237 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
|
238 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
239 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
|
240 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
241 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
242 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
243 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
|
244 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
245 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
|
246 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
247 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
248 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
249 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
|
250 { |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
251 if (tstate == NULL) |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
252 Py_FatalError("PyEval_AcquireThread: NULL new thread state"); |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28556
diff
changeset
|
253 /* Check someone has called PyEval_InitThreads() to create the lock */ |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28556
diff
changeset
|
254 assert(interpreter_lock); |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
255 PyThread_acquire_lock(interpreter_lock, 1); |
|
5865
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
256 if (PyThreadState_Swap(tstate) != NULL) |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
257 Py_FatalError( |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
258 "PyEval_AcquireThread: non-NULL old thread state"); |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
259 } |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
260 |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
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_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
|
263 { |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
264 if (tstate == NULL) |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
265 Py_FatalError("PyEval_ReleaseThread: NULL thread state"); |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
266 if (PyThreadState_Swap(NULL) != tstate) |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
267 Py_FatalError("PyEval_ReleaseThread: wrong thread state"); |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
268 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
|
269 } |
|
14225
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
270 |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
271 /* 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
|
272 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
|
273 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
|
274 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
|
275 |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
276 void |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
277 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
|
278 { |
|
47985
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
279 PyObject *threading, *result; |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
280 PyThreadState *tstate; |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
281 |
|
14225
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
282 if (!interpreter_lock) |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
283 return; |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
284 /*XXX Can't use PyThread_free_lock here because it does too |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
285 much error-checking. Doing this cleanly would require |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
286 adding a new function to each thread_*.h. Instead, just |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
287 create a new lock and waste a little bit of memory */ |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
288 interpreter_lock = PyThread_allocate_lock(); |
|
50674
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
289 pending_lock = PyThread_allocate_lock(); |
|
14225
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
290 PyThread_acquire_lock(interpreter_lock, 1); |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
291 main_thread = PyThread_get_thread_ident(); |
|
47985
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
292 |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
293 /* Update the threading module with the new state. |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
294 */ |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
295 tstate = PyThreadState_GET(); |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
296 threading = PyMapping_GetItemString(tstate->interp->modules, |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
297 "threading"); |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
298 if (threading == NULL) { |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
299 /* threading not imported */ |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
300 PyErr_Clear(); |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
301 return; |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
302 } |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
303 result = PyObject_CallMethod(threading, "_after_fork", NULL); |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
304 if (result == NULL) |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
305 PyErr_WriteUnraisable(threading); |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
306 else |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
307 Py_DECREF(result); |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
308 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
|
309 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
310 #endif |
| 926 | 311 |
| 312 /* Functions save_thread and restore_thread are always defined so | |
| 313 dynamically loaded modules needn't be compiled separately for use | |
| 314 with and without threads: */ | |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
315 |
|
5846
852a1fa62a7c
PyEval_SaveThread() and PyEval_RestoreThread() now return/take a
Guido van Rossum <guido@python.org>
parents:
5829
diff
changeset
|
316 PyThreadState * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
317 PyEval_SaveThread(void) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
318 { |
|
6365
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
319 PyThreadState *tstate = PyThreadState_Swap(NULL); |
|
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
320 if (tstate == NULL) |
|
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
321 Py_FatalError("PyEval_SaveThread: NULL tstate"); |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
322 #ifdef WITH_THREAD |
|
6365
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
323 if (interpreter_lock) |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
324 PyThread_release_lock(interpreter_lock); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
325 #endif |
|
6365
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
326 return tstate; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
327 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
328 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
329 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
330 PyEval_RestoreThread(PyThreadState *tstate) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
331 { |
|
6365
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
332 if (tstate == NULL) |
|
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
333 Py_FatalError("PyEval_RestoreThread: NULL tstate"); |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
334 #ifdef WITH_THREAD |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
335 if (interpreter_lock) { |
|
6365
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
336 int err = errno; |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
337 PyThread_acquire_lock(interpreter_lock, 1); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
338 errno = err; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
339 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
340 #endif |
|
6365
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
341 PyThreadState_Swap(tstate); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
342 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
343 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
344 |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
345 /* 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
|
346 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
|
347 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
|
348 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
|
349 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
|
350 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
|
351 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
352 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
|
353 (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
|
354 an exception condition). |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
355 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
356 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
|
357 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
|
358 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
359 #ifdef WITH_THREAD |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
360 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
|
361 will execute them. |
|
50674
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
362 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
|
363 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
|
364 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
|
365 threadstate. |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
366 #endif |
|
50674
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
367 */ |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
368 |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
369 #ifdef WITH_THREAD |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
370 |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
371 /* 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
|
372 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
|
373 callback. |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
374 */ |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
375 |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
376 #define NPENDINGCALLS 32 |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
377 static struct { |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
378 int (*func)(void *); |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
379 void *arg; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
380 } pendingcalls[NPENDINGCALLS]; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
381 static int pendingfirst = 0; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
382 static int pendinglast = 0; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
383 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
|
384 static char pendingbusy = 0; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
385 |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
386 int |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
387 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
|
388 { |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
389 int i, j, result=0; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
390 PyThread_type_lock lock = pending_lock; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
391 |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
392 /* try a few times for the lock. Since this mechanism is used |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
393 * for signal handling (on the main thread), there is a (slim) |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
394 * chance that a signal is delivered on the same thread while we |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
395 * hold the lock during the Py_MakePendingCalls() function. |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
396 * This avoids a deadlock in that case. |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
397 * Note that signals can be delivered on any thread. In particular, |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
398 * on Windows, a SIGINT is delivered on a system-created worker |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
399 * thread. |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
400 * We also check for lock being NULL, in the unlikely case that |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
401 * this function is called before any bytecode evaluation takes place. |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
402 */ |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
403 if (lock != NULL) { |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
404 for (i = 0; i<100; i++) { |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
405 if (PyThread_acquire_lock(lock, NOWAIT_LOCK)) |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
406 break; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
407 } |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
408 if (i == 100) |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
409 return -1; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
410 } |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
411 |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
412 i = pendinglast; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
413 j = (i + 1) % NPENDINGCALLS; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
414 if (j == pendingfirst) { |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
415 result = -1; /* Queue full */ |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
416 } else { |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
417 pendingcalls[i].func = func; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
418 pendingcalls[i].arg = arg; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
419 pendinglast = j; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
420 } |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
421 /* signal main loop */ |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
422 _Py_Ticker = 0; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
423 pendingcalls_to_do = 1; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
424 if (lock != NULL) |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
425 PyThread_release_lock(lock); |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
426 return result; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
427 } |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
428 |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
429 int |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
430 Py_MakePendingCalls(void) |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
431 { |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
432 int i; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
433 int r = 0; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
434 |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
435 if (!pending_lock) { |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
436 /* initial allocation of the lock */ |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
437 pending_lock = PyThread_allocate_lock(); |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
438 if (pending_lock == NULL) |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
439 return -1; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
440 } |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
441 |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
442 /* only service pending calls on main thread */ |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
443 if (main_thread && PyThread_get_thread_ident() != main_thread) |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
444 return 0; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
445 /* don't perform recursive pending calls */ |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
446 if (pendingbusy) |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
447 return 0; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
448 pendingbusy = 1; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
449 /* perform a bounded number of calls, in case of recursion */ |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
450 for (i=0; i<NPENDINGCALLS; i++) { |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
451 int j; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
452 int (*func)(void *); |
|
51472
994fe4df4af7
Silence 'arg may be used uninitialized in this function' warning from gcc.
Mark Dickinson <dickinsm@gmail.com>
parents:
51032
diff
changeset
|
453 void *arg = NULL; |
|
50674
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
454 |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
455 /* pop one item off the queue while holding the lock */ |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
456 PyThread_acquire_lock(pending_lock, WAIT_LOCK); |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
457 j = pendingfirst; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
458 if (j == pendinglast) { |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
459 func = NULL; /* Queue empty */ |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
460 } else { |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
461 func = pendingcalls[j].func; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
462 arg = pendingcalls[j].arg; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
463 pendingfirst = (j + 1) % NPENDINGCALLS; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
464 } |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
465 pendingcalls_to_do = pendingfirst != pendinglast; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
466 PyThread_release_lock(pending_lock); |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
467 /* having released the lock, perform the callback */ |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
468 if (func == NULL) |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
469 break; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
470 r = func(arg); |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
471 if (r) |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
472 break; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
473 } |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
474 pendingbusy = 0; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
475 return r; |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
476 } |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
477 |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
478 #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
|
479 |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
480 /* |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
481 WARNING! ASYNCHRONOUSLY EXECUTING CODE! |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
482 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
|
483 with WITH_THREAD. |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
484 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
|
485 on a different thread! |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
486 |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
487 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
|
488 (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
|
489 (2) AddPendingCall() calls made while pending calls are being processed. |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
490 |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
491 (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
|
492 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
|
493 (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
|
494 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
|
495 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
|
496 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
|
497 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
|
498 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
|
499 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
|
500 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
|
501 */ |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
502 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
503 #define NPENDINGCALLS 32 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
504 static struct { |
|
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
|
505 int (*func)(void *); |
|
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
|
506 void *arg; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
507 } pendingcalls[NPENDINGCALLS]; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
508 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
|
509 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
|
510 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
|
511 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
512 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
|
513 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
|
514 { |
| 32526 | 515 static volatile int busy = 0; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
516 int i, j; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
517 /* XXX Begin critical section */ |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
518 if (busy) |
|
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
519 return -1; |
|
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
520 busy = 1; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
521 i = pendinglast; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
522 j = (i + 1) % NPENDINGCALLS; |
|
24284
d8909792005a
SF patch 552161 - Py_AddPendingCall doesn't unlock on fail (Daniel
Guido van Rossum <guido@python.org>
parents:
24283
diff
changeset
|
523 if (j == pendingfirst) { |
|
d8909792005a
SF patch 552161 - Py_AddPendingCall doesn't unlock on fail (Daniel
Guido van Rossum <guido@python.org>
parents:
24283
diff
changeset
|
524 busy = 0; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
525 return -1; /* Queue full */ |
|
24284
d8909792005a
SF patch 552161 - Py_AddPendingCall doesn't unlock on fail (Daniel
Guido van Rossum <guido@python.org>
parents:
24283
diff
changeset
|
526 } |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
527 pendingcalls[i].func = func; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
528 pendingcalls[i].arg = arg; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
529 pendinglast = j; |
|
25108
3a26e352f0a6
replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents:
25078
diff
changeset
|
530 |
|
3a26e352f0a6
replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents:
25078
diff
changeset
|
531 _Py_Ticker = 0; |
|
50674
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
532 pendingcalls_to_do = 1; /* Signal main loop */ |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
533 busy = 0; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
534 /* XXX End critical section */ |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
535 return 0; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
536 } |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
537 |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
538 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
539 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
|
540 { |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
541 static int busy = 0; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
542 if (busy) |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
543 return 0; |
|
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
544 busy = 1; |
|
50674
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
545 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
|
546 for (;;) { |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
547 int i; |
|
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
|
548 int (*func)(void *); |
|
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
|
549 void *arg; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
550 i = pendingfirst; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
551 if (i == pendinglast) |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
552 break; /* Queue empty */ |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
553 func = pendingcalls[i].func; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
554 arg = pendingcalls[i].arg; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
555 pendingfirst = (i + 1) % NPENDINGCALLS; |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
556 if (func(arg) < 0) { |
|
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
557 busy = 0; |
|
50674
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
558 pendingcalls_to_do = 1; /* We're not done yet */ |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
559 return -1; |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
560 } |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
561 } |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
562 busy = 0; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
563 return 0; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
564 } |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
565 |
|
50674
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
566 #endif /* WITH_THREAD */ |
|
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
567 |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
568 |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
569 /* The interpreter's recursion limit */ |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
570 |
|
34863
71fd7ee4b7f5
Make a handy macro, Py_DEFAULT_RECURSION_LIMIT to allow to define
Hye-Shik Chang <hyeshik@gmail.com>
parents:
34442
diff
changeset
|
571 #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
|
572 #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
|
573 #endif |
|
71fd7ee4b7f5
Make a handy macro, Py_DEFAULT_RECURSION_LIMIT to allow to define
Hye-Shik Chang <hyeshik@gmail.com>
parents:
34442
diff
changeset
|
574 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
|
575 int _Py_CheckRecursionLimit = Py_DEFAULT_RECURSION_LIMIT; |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
576 |
|
14348
6d0f64f7dedd
Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14333
diff
changeset
|
577 int |
|
6d0f64f7dedd
Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14333
diff
changeset
|
578 Py_GetRecursionLimit(void) |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
579 { |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
580 return recursion_limit; |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
581 } |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
582 |
|
14348
6d0f64f7dedd
Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14333
diff
changeset
|
583 void |
|
6d0f64f7dedd
Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14333
diff
changeset
|
584 Py_SetRecursionLimit(int new_limit) |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
585 { |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
586 recursion_limit = new_limit; |
| 43408 | 587 _Py_CheckRecursionLimit = recursion_limit; |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
588 } |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
589 |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
590 /* the macro Py_EnterRecursiveCall() only calls _Py_CheckRecursiveCall() |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
591 if the recursion_depth reaches _Py_CheckRecursionLimit. |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
592 If USE_STACKCHECK, the macro decrements _Py_CheckRecursionLimit |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
593 to guarantee that _Py_CheckRecursiveCall() is regularly called. |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
594 Without USE_STACKCHECK, there is no need for this. */ |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
595 int |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
596 _Py_CheckRecursiveCall(char *where) |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
597 { |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
598 PyThreadState *tstate = PyThreadState_GET(); |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
599 |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
600 #ifdef USE_STACKCHECK |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
601 if (PyOS_CheckStack()) { |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
602 --tstate->recursion_depth; |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
603 PyErr_SetString(PyExc_MemoryError, "Stack overflow"); |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
604 return -1; |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
605 } |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
606 #endif |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
607 if (tstate->recursion_depth > recursion_limit) { |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
608 --tstate->recursion_depth; |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
609 PyErr_Format(PyExc_RuntimeError, |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
610 "maximum recursion depth exceeded%s", |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
611 where); |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
612 return -1; |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
613 } |
| 43408 | 614 _Py_CheckRecursionLimit = recursion_limit; |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
615 return 0; |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
616 } |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
617 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
618 /* 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
|
619 enum why_code { |
|
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
620 WHY_NOT = 0x0001, /* No error */ |
|
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
621 WHY_EXCEPTION = 0x0002, /* Exception occurred */ |
|
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
622 WHY_RERAISE = 0x0004, /* Exception re-raised by 'finally' */ |
|
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
623 WHY_RETURN = 0x0008, /* 'return' statement */ |
|
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
624 WHY_BREAK = 0x0010, /* 'break' statement */ |
|
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
625 WHY_CONTINUE = 0x0020, /* 'continue' statement */ |
|
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
626 WHY_YIELD = 0x0040 /* 'yield' operator */ |
|
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
627 }; |
|
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
628 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
629 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
|
630 static int unpack_iterable(PyObject *, int, PyObject **); |
| 5018 | 631 |
|
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
|
632 /* 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
|
633 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
|
634 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
|
635 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
|
636 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
|
637 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
|
638 |
|
25108
3a26e352f0a6
replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents:
25078
diff
changeset
|
639 /* 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
|
640 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
|
641 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
|
642 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
|
643 |
| 5368 | 644 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
645 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
|
646 { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
647 return PyEval_EvalCodeEx(co, |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
648 globals, locals, |
| 5368 | 649 (PyObject **)NULL, 0, |
| 650 (PyObject **)NULL, 0, | |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
651 (PyObject **)NULL, 0, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
652 NULL); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
653 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
654 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
655 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
656 /* Interpreter main loop */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
657 |
|
32421
485d2ef43419
Patch #966493: Cleanup generator/eval_frame exposure.
Martin v. Löwis <martin@v.loewis.de>
parents:
32412
diff
changeset
|
658 PyObject * |
|
35298
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
659 PyEval_EvalFrame(PyFrameObject *f) { |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
660 /* This is for backward compatibility with extension modules that |
|
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
|
661 used this API; core interpreter code should call |
|
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
|
662 PyEval_EvalFrameEx() */ |
|
35298
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
663 return PyEval_EvalFrameEx(f, 0); |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
664 } |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
665 |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
666 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
|
667 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
|
668 { |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
669 #ifdef DXPAIRS |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
670 int lastopcode = 0; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
671 #endif |
|
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
|
672 register PyObject **stack_pointer; /* Next free slot in value stack */ |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
673 register unsigned char *next_instr; |
|
32359
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
674 register int opcode; /* Current opcode */ |
|
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
675 register int oparg; /* Current opcode argument, if any */ |
|
31875
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
676 register enum why_code why; /* Reason for block stack unwind */ |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
677 register int err; /* Error status -- nonzero if error */ |
| 5368 | 678 register PyObject *x; /* Result object -- NULL if error */ |
| 679 register PyObject *v; /* Temporary objects popped off stack */ | |
| 680 register PyObject *w; | |
| 681 register PyObject *u; | |
| 682 register PyObject *t; | |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
683 register PyObject *stream = NULL; /* for PRINT opcodes */ |
|
16355
e4420c2468f9
Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16257
diff
changeset
|
684 register PyObject **fastlocals, **freevars; |
|
9513
350f24180dcb
Whoops! One the "redundant" initializations removed by Vladimir in
Guido van Rossum <guido@python.org>
parents:
9490
diff
changeset
|
685 PyObject *retval = NULL; /* Return value */ |
|
9671
1d40bc25703a
Use PyThreadState_GET() macro.
Guido van Rossum <guido@python.org>
parents:
9591
diff
changeset
|
686 PyThreadState *tstate = PyThreadState_GET(); |
|
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
|
687 PyCodeObject *co; |
| 24844 | 688 |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
689 /* when tracing we set things up so that |
| 24844 | 690 |
| 691 not (instr_lb <= current_bytecode_offset < instr_ub) | |
| 692 | |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
693 is true when the line being executed has changed. The |
| 24844 | 694 initial values are such as to make this false the first |
| 695 time it is tested. */ | |
| 31768 | 696 int instr_ub = -1, instr_lb = 0, instr_prev = -1; |
| 24844 | 697 |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
698 unsigned char *first_instr; |
|
24545
d2f41c8a81f0
small speedup for constant and name access
Skip Montanaro <skip@pobox.com>
parents:
24284
diff
changeset
|
699 PyObject *names; |
|
d2f41c8a81f0
small speedup for constant and name access
Skip Montanaro <skip@pobox.com>
parents:
24284
diff
changeset
|
700 PyObject *consts; |
|
35745
407c3dacbd7c
Fix some mods that got dropped from the AST merge
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
701 #if defined(Py_DEBUG) || defined(LLTRACE) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
702 /* Make it easier to find out where we are with a debugger */ |
|
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
|
703 char *filename; |
|
1016
a41e3ba5b47d
Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents:
974
diff
changeset
|
704 #endif |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
705 |
|
24232
e06b1ab0bdb8
SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents:
24190
diff
changeset
|
706 /* 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
|
707 |
|
e06b1ab0bdb8
SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents:
24190
diff
changeset
|
708 #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
|
709 #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
|
710 #else |
|
e06b1ab0bdb8
SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents:
24190
diff
changeset
|
711 #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
|
712 #endif |
|
e06b1ab0bdb8
SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents:
24190
diff
changeset
|
713 |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
714 #ifdef WITH_TSC |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
715 /* 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
|
716 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
|
717 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
|
718 loop0 -- the top of the mainloop |
| 38418 | 719 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
|
720 (may be skipped) |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
721 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
|
722 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
|
723 |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
724 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
|
725 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
|
726 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
|
727 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
|
728 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
|
729 |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
730 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
|
731 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
|
732 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
|
733 |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
734 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
|
735 cases: |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
736 |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
737 EXEC_STMT |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
738 IMPORT_STAR |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
739 IMPORT_FROM |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
740 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
|
741 |
|
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 uint64 inst0, inst1, loop0, loop1, intr0 = 0, intr1 = 0; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
744 int ticked = 0; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
745 |
|
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
|
746 READ_TIMESTAMP(inst0); |
|
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
|
747 READ_TIMESTAMP(inst1); |
|
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
|
748 READ_TIMESTAMP(loop0); |
|
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
|
749 READ_TIMESTAMP(loop1); |
| 33104 | 750 |
| 751 /* shut up the compiler */ | |
| 752 opcode = 0; | |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
753 #endif |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
754 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
755 /* Code access macros */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
756 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36475
diff
changeset
|
757 #define INSTR_OFFSET() ((int)(next_instr - first_instr)) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
758 #define NEXTOP() (*next_instr++) |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
759 #define NEXTARG() (next_instr += 2, (next_instr[-1]<<8) + next_instr[-2]) |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
760 #define PEEKARG() ((next_instr[2]<<8) + next_instr[1]) |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
761 #define JUMPTO(x) (next_instr = first_instr + (x)) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
762 #define JUMPBY(x) (next_instr += (x)) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
763 |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
764 /* OpCode prediction macros |
|
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
|
765 Some opcodes tend to come in pairs thus making it possible to |
|
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
|
766 predict the second code when the first is run. For example, |
|
51920
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
767 GET_ITER is often followed by FOR_ITER. And FOR_ITER is often |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
768 followed by STORE_FAST or UNPACK_SEQUENCE. |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
769 |
|
47886
c93596ec1d3d
Update comment on prediction macros.
Raymond Hettinger <python@rcn.com>
parents:
47868
diff
changeset
|
770 Verifying the prediction costs a single high-speed test of a register |
|
28303
470504ef578b
Fix comment and whitespace.
Raymond Hettinger <python@rcn.com>
parents:
28302
diff
changeset
|
771 variable against a constant. If the pairing was good, then the |
|
47886
c93596ec1d3d
Update comment on prediction macros.
Raymond Hettinger <python@rcn.com>
parents:
47868
diff
changeset
|
772 processor's own internal branch predication has a high likelihood of |
|
c93596ec1d3d
Update comment on prediction macros.
Raymond Hettinger <python@rcn.com>
parents:
47868
diff
changeset
|
773 success, resulting in a nearly zero-overhead transition to the |
|
c93596ec1d3d
Update comment on prediction macros.
Raymond Hettinger <python@rcn.com>
parents:
47868
diff
changeset
|
774 next opcode. A successful prediction saves a trip through the eval-loop |
|
48077
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
775 including its two unpredictable branches, the HAS_ARG test and the |
|
47886
c93596ec1d3d
Update comment on prediction macros.
Raymond Hettinger <python@rcn.com>
parents:
47868
diff
changeset
|
776 switch-case. Combined with the processor's internal branch prediction, |
|
48077
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
777 a successful PREDICT has the effect of making the two opcodes run as if |
|
47886
c93596ec1d3d
Update comment on prediction macros.
Raymond Hettinger <python@rcn.com>
parents:
47868
diff
changeset
|
778 they were a single new opcode with the bodies combined. |
|
c93596ec1d3d
Update comment on prediction macros.
Raymond Hettinger <python@rcn.com>
parents:
47868
diff
changeset
|
779 |
|
c93596ec1d3d
Update comment on prediction macros.
Raymond Hettinger <python@rcn.com>
parents:
47868
diff
changeset
|
780 If collecting opcode statistics, your choices are to either keep the |
|
c93596ec1d3d
Update comment on prediction macros.
Raymond Hettinger <python@rcn.com>
parents:
47868
diff
changeset
|
781 predictions turned-on and interpret the results as if some opcodes |
|
c93596ec1d3d
Update comment on prediction macros.
Raymond Hettinger <python@rcn.com>
parents:
47868
diff
changeset
|
782 had been combined or turn-off predictions so that the opcode frequency |
|
c93596ec1d3d
Update comment on prediction macros.
Raymond Hettinger <python@rcn.com>
parents:
47868
diff
changeset
|
783 counter updates for both opcodes. |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
784 */ |
|
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
785 |
|
31487
f57f5ce22c8d
SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents:
31462
diff
changeset
|
786 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
f57f5ce22c8d
SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents:
31462
diff
changeset
|
787 #define PREDICT(op) if (0) goto PRED_##op |
|
f57f5ce22c8d
SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents:
31462
diff
changeset
|
788 #else |
|
28303
470504ef578b
Fix comment and whitespace.
Raymond Hettinger <python@rcn.com>
parents:
28302
diff
changeset
|
789 #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
|
790 #endif |
|
f57f5ce22c8d
SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents:
31462
diff
changeset
|
791 |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
792 #define PREDICTED(op) PRED_##op: next_instr++ |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
793 #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
|
794 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
795 /* Stack manipulation macros */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
796 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36475
diff
changeset
|
797 /* 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
|
798 co_stacksize are ints. */ |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36475
diff
changeset
|
799 #define STACK_LEVEL() ((int)(stack_pointer - f->f_valuestack)) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
800 #define EMPTY() (STACK_LEVEL() == 0) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
801 #define TOP() (stack_pointer[-1]) |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
802 #define SECOND() (stack_pointer[-2]) |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
803 #define THIRD() (stack_pointer[-3]) |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
804 #define FOURTH() (stack_pointer[-4]) |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
805 #define SET_TOP(v) (stack_pointer[-1] = (v)) |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
806 #define SET_SECOND(v) (stack_pointer[-2] = (v)) |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
807 #define SET_THIRD(v) (stack_pointer[-3] = (v)) |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
808 #define SET_FOURTH(v) (stack_pointer[-4] = (v)) |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
809 #define BASIC_STACKADJ(n) (stack_pointer += n) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
810 #define BASIC_PUSH(v) (*stack_pointer++ = (v)) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
811 #define BASIC_POP() (*--stack_pointer) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
812 |
| 567 | 813 #ifdef LLTRACE |
|
20492
bf4ff05eab52
For debug build, check that the stack pointer never exceeds the stack size.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20438
diff
changeset
|
814 #define PUSH(v) { (void)(BASIC_PUSH(v), \ |
|
bf4ff05eab52
For debug build, check that the stack pointer never exceeds the stack size.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20438
diff
changeset
|
815 lltrace && prtrace(TOP(), "push")); \ |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38217
diff
changeset
|
816 assert(STACK_LEVEL() <= co->co_stacksize); } |
|
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
|
817 #define POP() ((void)(lltrace && prtrace(TOP(), "pop")), \ |
|
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
|
818 BASIC_POP()) |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
819 #define STACKADJ(n) { (void)(BASIC_STACKADJ(n), \ |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
820 lltrace && prtrace(TOP(), "stackadj")); \ |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38217
diff
changeset
|
821 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
|
822 #define EXT_POP(STACK_POINTER) ((void)(lltrace && \ |
|
44c418b2bf7f
Silence a warning about an unsed variable in debug builds
Christian Heimes <christian@cheimes.de>
parents:
44164
diff
changeset
|
823 prtrace((STACK_POINTER)[-1], "ext_pop")), \ |
|
44c418b2bf7f
Silence a warning about an unsed variable in debug builds
Christian Heimes <christian@cheimes.de>
parents:
44164
diff
changeset
|
824 *--(STACK_POINTER)) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
825 #else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
826 #define PUSH(v) BASIC_PUSH(v) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
827 #define POP() BASIC_POP() |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
828 #define STACKADJ(n) BASIC_STACKADJ(n) |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
829 #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
|
830 #endif |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
831 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
832 /* Local variable macros */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
833 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
834 #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
|
835 |
|
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
|
836 /* 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
|
837 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
|
838 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
|
839 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
|
840 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
|
841 variable would be pointing to already-freed memory. */ |
|
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
|
842 #define SETLOCAL(i, value) do { PyObject *tmp = GETLOCAL(i); \ |
|
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
|
843 GETLOCAL(i) = 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
|
844 Py_XDECREF(tmp); } while (0) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
845 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
846 /* Start of code */ |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
847 |
|
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
|
848 if (f == NULL) |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
849 return NULL; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
850 |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
851 /* push frame */ |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
852 if (Py_EnterRecursiveCall("")) |
|
30782
f51dc9026e4d
oh dear. Wrong manipulation. Committed a version of ceval.c from my
Armin Rigo <arigo@tunes.org>
parents:
30781
diff
changeset
|
853 return NULL; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
854 |
|
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
|
855 tstate->frame = f; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
856 |
|
19692
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
857 if (tstate->use_tracing) { |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
858 if (tstate->c_tracefunc != NULL) { |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
859 /* tstate->c_tracefunc, if defined, is a |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
860 function that will be called on *every* entry |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
861 to a code block. Its return value, if not |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
862 None, is a function that will be called at |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
863 the start of each executed line of code. |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
864 (Actually, the function must return itself |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
865 in order to continue tracing.) The trace |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
866 functions are called with three arguments: |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
867 a pointer to the current frame, a string |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
868 indicating why the function is called, and |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
869 an argument which depends on the situation. |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
870 The global trace function is also called |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
871 whenever an exception is detected. */ |
|
48077
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
872 if (call_trace_protected(tstate->c_tracefunc, |
|
43845
76844a0a579f
Merge from py3k branch:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43784
diff
changeset
|
873 tstate->c_traceobj, |
|
76844a0a579f
Merge from py3k branch:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43784
diff
changeset
|
874 f, PyTrace_CALL, Py_None)) { |
|
19692
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
875 /* Trace function raised an error */ |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
876 goto exit_eval_frame; |
|
19692
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
877 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
878 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
879 if (tstate->c_profilefunc != NULL) { |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
880 /* Similar for c_profilefunc, except it needn't |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
881 return itself and isn't called for "line" events */ |
|
43845
76844a0a579f
Merge from py3k branch:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43784
diff
changeset
|
882 if (call_trace_protected(tstate->c_profilefunc, |
|
76844a0a579f
Merge from py3k branch:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43784
diff
changeset
|
883 tstate->c_profileobj, |
|
76844a0a579f
Merge from py3k branch:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43784
diff
changeset
|
884 f, PyTrace_CALL, Py_None)) { |
|
19692
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
885 /* Profile function raised an error */ |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
886 goto exit_eval_frame; |
|
19692
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
887 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
888 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
889 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
890 |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
891 co = f->f_code; |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
892 names = co->co_names; |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
893 consts = co->co_consts; |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
894 fastlocals = f->f_localsplus; |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38217
diff
changeset
|
895 freevars = f->f_localsplus + co->co_nlocals; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
896 first_instr = (unsigned char*) PyString_AS_STRING(co->co_code); |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
897 /* An explanation is in order for the next line. |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
898 |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
899 f->f_lasti now refers to the index of the last instruction |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
900 executed. You might think this was obvious from the name, but |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
901 this wasn't always true before 2.3! PyFrame_New now sets |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
902 f->f_lasti to -1 (i.e. the index *before* the first instruction) |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
903 and YIELD_VALUE doesn't fiddle with f_lasti any more. So this |
|
48077
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
904 does work. Promise. |
|
40560
07c4702020dc
SF# 1409443: Expand comment to cover the interaction between f->f_lasti and the PREDICT macros.
Raymond Hettinger <python@rcn.com>
parents:
40405
diff
changeset
|
905 |
|
07c4702020dc
SF# 1409443: Expand comment to cover the interaction between f->f_lasti and the PREDICT macros.
Raymond Hettinger <python@rcn.com>
parents:
40405
diff
changeset
|
906 When the PREDICT() macros are enabled, some opcode pairs follow in |
|
48077
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
907 direct succession without updating f->f_lasti. A successful |
|
40560
07c4702020dc
SF# 1409443: Expand comment to cover the interaction between f->f_lasti and the PREDICT macros.
Raymond Hettinger <python@rcn.com>
parents:
40405
diff
changeset
|
908 prediction effectively links the two codes together as if they |
|
07c4702020dc
SF# 1409443: Expand comment to cover the interaction between f->f_lasti and the PREDICT macros.
Raymond Hettinger <python@rcn.com>
parents:
40405
diff
changeset
|
909 were a single new opcode; accordingly,f->f_lasti will point to |
|
07c4702020dc
SF# 1409443: Expand comment to cover the interaction between f->f_lasti and the PREDICT macros.
Raymond Hettinger <python@rcn.com>
parents:
40405
diff
changeset
|
910 the first code in the pair (for instance, GET_ITER followed by |
|
07c4702020dc
SF# 1409443: Expand comment to cover the interaction between f->f_lasti and the PREDICT macros.
Raymond Hettinger <python@rcn.com>
parents:
40405
diff
changeset
|
911 FOR_ITER is effectively a single opcode and f->f_lasti will point |
|
07c4702020dc
SF# 1409443: Expand comment to cover the interaction between f->f_lasti and the PREDICT macros.
Raymond Hettinger <python@rcn.com>
parents:
40405
diff
changeset
|
912 at to the beginning of the combined pair.) |
|
07c4702020dc
SF# 1409443: Expand comment to cover the interaction between f->f_lasti and the PREDICT macros.
Raymond Hettinger <python@rcn.com>
parents:
40405
diff
changeset
|
913 */ |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
914 next_instr = first_instr + f->f_lasti + 1; |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
915 stack_pointer = f->f_stacktop; |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
916 assert(stack_pointer != NULL); |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
917 f->f_stacktop = NULL; /* remains NULL unless yield suspends frame */ |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
918 |
|
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
|
919 #ifdef LLTRACE |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
920 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
|
921 #endif |
|
35745
407c3dacbd7c
Fix some mods that got dropped from the AST merge
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
922 #if defined(Py_DEBUG) || defined(LLTRACE) |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
923 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
|
924 #endif |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
925 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
926 why = WHY_NOT; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
927 err = 0; |
| 5368 | 928 x = Py_None; /* Not a reference, just anything non-NULL */ |
|
15152
ed49a67869e9
Remove the last gcc -Wall warning about possible use of an uninitialized
Fred Drake <fdrake@acm.org>
parents:
15151
diff
changeset
|
929 w = NULL; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
930 |
|
37597
2b2e9c388fbb
low-hanging fruit in Python/ - g++ still hates all the enum_kind declarations
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37564
diff
changeset
|
931 if (throwflag) { /* support for generator.throw() */ |
|
35298
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
932 why = WHY_EXCEPTION; |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
933 goto on_error; |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
934 } |
| 38418 | 935 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
936 for (;;) { |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
937 #ifdef WITH_TSC |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
938 if (inst1 == 0) { |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
939 /* Almost surely, the opcode executed a break |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
940 or a continue, preventing inst1 from being set |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
941 on the way out of the loop. |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
942 */ |
|
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
|
943 READ_TIMESTAMP(inst1); |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
944 loop1 = inst1; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
945 } |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
946 dump_tsc(opcode, ticked, inst0, inst1, loop0, loop1, |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
947 intr0, intr1); |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
948 ticked = 0; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
949 inst1 = 0; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
950 intr0 = 0; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
951 intr1 = 0; |
|
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
|
952 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
|
953 #endif |
| 24844 | 954 assert(stack_pointer >= f->f_valuestack); /* else underflow */ |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38217
diff
changeset
|
955 assert(STACK_LEVEL() <= co->co_stacksize); /* else overflow */ |
| 24844 | 956 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
957 /* Do periodic things. Doing this every time through |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
958 the loop would add too much overhead, so we do it |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
959 only every Nth instruction. We also do it if |
|
50674
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
960 ``pendingcalls_to_do'' is set, i.e. when an asynchronous |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
961 event needs attention (e.g. a signal handler or |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
962 async I/O handler); see Py_AddPendingCall() and |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
963 Py_MakePendingCalls() above. */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
964 |
|
25108
3a26e352f0a6
replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents:
25078
diff
changeset
|
965 if (--_Py_Ticker < 0) { |
| 43408 | 966 if (*next_instr == SETUP_FINALLY) { |
| 967 /* Make the last opcode before | |
| 968 a try: finally: block uninterruptable. */ | |
| 969 goto fast_next_opcode; | |
| 970 } | |
|
25108
3a26e352f0a6
replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents:
25078
diff
changeset
|
971 _Py_Ticker = _Py_CheckInterval; |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
972 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
|
973 #ifdef WITH_TSC |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
974 ticked = 1; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
975 #endif |
|
50674
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
976 if (pendingcalls_to_do) { |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
977 if (Py_MakePendingCalls() < 0) { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
978 why = WHY_EXCEPTION; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
979 goto on_error; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
980 } |
|
50674
c8f793e159bb
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50204
diff
changeset
|
981 if (pendingcalls_to_do) |
|
34020
be370abb020f
Hye-Shik Chang's fix for Bug 875692.
Kurt B. Kaiser <kbk@shore.net>
parents:
33715
diff
changeset
|
982 /* MakePendingCalls() didn't succeed. |
|
be370abb020f
Hye-Shik Chang's fix for Bug 875692.
Kurt B. Kaiser <kbk@shore.net>
parents:
33715
diff
changeset
|
983 Force early re-execution of this |
|
be370abb020f
Hye-Shik Chang's fix for Bug 875692.
Kurt B. Kaiser <kbk@shore.net>
parents:
33715
diff
changeset
|
984 "periodic" code, possibly after |
|
be370abb020f
Hye-Shik Chang's fix for Bug 875692.
Kurt B. Kaiser <kbk@shore.net>
parents:
33715
diff
changeset
|
985 a thread switch */ |
|
be370abb020f
Hye-Shik Chang's fix for Bug 875692.
Kurt B. Kaiser <kbk@shore.net>
parents:
33715
diff
changeset
|
986 _Py_Ticker = 0; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
987 } |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
988 #ifdef WITH_THREAD |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
989 if (interpreter_lock) { |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
990 /* Give another thread a chance */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
991 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
992 if (PyThreadState_Swap(NULL) != tstate) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
993 Py_FatalError("ceval: tstate mix-up"); |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
994 PyThread_release_lock(interpreter_lock); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
995 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
996 /* Other threads may run now */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
997 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
998 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
|
999 if (PyThreadState_Swap(tstate) != NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
1000 Py_FatalError("ceval: orphan tstate"); |
|
29643
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
1001 |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
1002 /* Check for thread interrupts */ |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
1003 |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
1004 if (tstate->async_exc != NULL) { |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
1005 x = tstate->async_exc; |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
1006 tstate->async_exc = NULL; |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
1007 PyErr_SetNone(x); |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
1008 Py_DECREF(x); |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
1009 why = WHY_EXCEPTION; |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
1010 goto on_error; |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
1011 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
1012 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
1013 #endif |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1014 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
1015 |
|
21974
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1016 fast_next_opcode: |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1017 f->f_lasti = INSTR_OFFSET(); |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1018 |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1019 /* line-by-line tracing support */ |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1020 |
|
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
|
1021 if (_Py_TracingPossible && |
|
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
|
1022 tstate->c_tracefunc != NULL && !tstate->tracing) { |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1023 /* see maybe_call_line_trace |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1024 for expository comments */ |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1025 f->f_stacktop = stack_pointer; |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
1026 |
|
28886
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
1027 err = maybe_call_line_trace(tstate->c_tracefunc, |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
1028 tstate->c_traceobj, |
| 31768 | 1029 f, &instr_lb, &instr_ub, |
| 1030 &instr_prev); | |
|
28886
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
1031 /* Reload possibly changed frame fields */ |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
1032 JUMPTO(f->f_lasti); |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
1033 if (f->f_stacktop != NULL) { |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
1034 stack_pointer = f->f_stacktop; |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
1035 f->f_stacktop = NULL; |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
1036 } |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
1037 if (err) { |
|
26110
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
1038 /* trace function raised an exception */ |
|
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
1039 goto on_error; |
|
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
1040 } |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1041 } |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1042 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1043 /* Extract opcode and argument */ |
|
1016
a41e3ba5b47d
Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents:
974
diff
changeset
|
1044 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1045 opcode = NEXTOP(); |
|
32359
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
1046 oparg = 0; /* allows oparg to be stored in a register because |
|
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
1047 it doesn't have to be remembered across a full loop */ |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
1048 if (HAS_ARG(opcode)) |
|
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
1049 oparg = NEXTARG(); |
|
14147
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
1050 dispatch_opcode: |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
1051 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
1052 #ifdef DXPAIRS |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
1053 dxpairs[lastopcode][opcode]++; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
1054 lastopcode = opcode; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
1055 #endif |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
1056 dxp[opcode]++; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
1057 #endif |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1058 |
| 567 | 1059 #ifdef LLTRACE |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1060 /* Instruction tracing */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1061 |
| 567 | 1062 if (lltrace) { |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1063 if (HAS_ARG(opcode)) { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1064 printf("%d: %d, %d\n", |
| 24844 | 1065 f->f_lasti, opcode, oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1066 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1067 else { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1068 printf("%d: %d\n", |
| 24844 | 1069 f->f_lasti, opcode); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1070 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1071 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1072 #endif |
| 24844 | 1073 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1074 /* Main switch on opcode */ |
|
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
|
1075 READ_TIMESTAMP(inst0); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1076 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1077 switch (opcode) { |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1078 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1079 /* BEWARE! |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1080 It is essential that any operation that fails sets either |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1081 x to NULL, err to nonzero, or why to anything but WHY_NOT, |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1082 and that no operation that succeeds does this! */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1083 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1084 /* case STOP_CODE: this is an error! */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1085 |
|
32395
6bc6abba8659
Install two code generation optimizations that depend on NOP.
Raymond Hettinger <python@rcn.com>
parents:
32359
diff
changeset
|
1086 case NOP: |
|
6bc6abba8659
Install two code generation optimizations that depend on NOP.
Raymond Hettinger <python@rcn.com>
parents:
32359
diff
changeset
|
1087 goto fast_next_opcode; |
|
6bc6abba8659
Install two code generation optimizations that depend on NOP.
Raymond Hettinger <python@rcn.com>
parents:
32359
diff
changeset
|
1088 |
|
21974
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1089 case LOAD_FAST: |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1090 x = GETLOCAL(oparg); |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1091 if (x != NULL) { |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1092 Py_INCREF(x); |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1093 PUSH(x); |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1094 goto fast_next_opcode; |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1095 } |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1096 format_exc_check_arg(PyExc_UnboundLocalError, |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1097 UNBOUNDLOCAL_ERROR_MSG, |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1098 PyTuple_GetItem(co->co_varnames, oparg)); |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1099 break; |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1100 |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1101 case LOAD_CONST: |
|
24545
d2f41c8a81f0
small speedup for constant and name access
Skip Montanaro <skip@pobox.com>
parents:
24284
diff
changeset
|
1102 x = GETITEM(consts, oparg); |
|
21974
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1103 Py_INCREF(x); |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1104 PUSH(x); |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1105 goto fast_next_opcode; |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1106 |
|
28304
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
1107 PREDICTED_WITH_ARG(STORE_FAST); |
|
21974
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1108 case STORE_FAST: |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1109 v = POP(); |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1110 SETLOCAL(oparg, v); |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1111 goto fast_next_opcode; |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1112 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1113 case POP_TOP: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1114 v = POP(); |
| 5368 | 1115 Py_DECREF(v); |
|
21974
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1116 goto fast_next_opcode; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1117 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1118 case ROT_TWO: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1119 v = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1120 w = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1121 SET_TOP(w); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1122 SET_SECOND(v); |
|
28296
7654c24decc4
SF patch #701907: More use of fast_next_opcode
Raymond Hettinger <python@rcn.com>
parents:
28121
diff
changeset
|
1123 goto fast_next_opcode; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1124 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1125 case ROT_THREE: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1126 v = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1127 w = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1128 x = THIRD(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1129 SET_TOP(w); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1130 SET_SECOND(x); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1131 SET_THIRD(v); |
|
28296
7654c24decc4
SF patch #701907: More use of fast_next_opcode
Raymond Hettinger <python@rcn.com>
parents:
28121
diff
changeset
|
1132 goto fast_next_opcode; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1133 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1134 case ROT_FOUR: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1135 u = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1136 v = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1137 w = THIRD(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1138 x = FOURTH(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1139 SET_TOP(v); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1140 SET_SECOND(w); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1141 SET_THIRD(x); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1142 SET_FOURTH(u); |
|
28296
7654c24decc4
SF patch #701907: More use of fast_next_opcode
Raymond Hettinger <python@rcn.com>
parents:
28121
diff
changeset
|
1143 goto fast_next_opcode; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1144 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1145 case DUP_TOP: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1146 v = TOP(); |
| 5368 | 1147 Py_INCREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1148 PUSH(v); |
|
28296
7654c24decc4
SF patch #701907: More use of fast_next_opcode
Raymond Hettinger <python@rcn.com>
parents:
28121
diff
changeset
|
1149 goto fast_next_opcode; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1150 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1151 case DUP_TOPX: |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
1152 if (oparg == 2) { |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1153 x = TOP(); |
|
15151
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
1154 Py_INCREF(x); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1155 w = SECOND(); |
|
15151
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
1156 Py_INCREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1157 STACKADJ(2); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1158 SET_TOP(x); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1159 SET_SECOND(w); |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
1160 goto fast_next_opcode; |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
1161 } else if (oparg == 3) { |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1162 x = TOP(); |
|
15151
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
1163 Py_INCREF(x); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1164 w = SECOND(); |
|
15151
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
1165 Py_INCREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1166 v = THIRD(); |
|
15151
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
1167 Py_INCREF(v); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1168 STACKADJ(3); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1169 SET_TOP(x); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1170 SET_SECOND(w); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1171 SET_THIRD(v); |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
1172 goto fast_next_opcode; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1173 } |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
1174 Py_FatalError("invalid argument to DUP_TOPX" |
|
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
1175 " (bytecode corruption?)"); |
|
50092
dc696deb2cf2
Issue 4597: Fix several cases in EvalFrameEx where an exception could be
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49940
diff
changeset
|
1176 /* Never returns, so don't bother to set why. */ |
|
15151
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
1177 break; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1178 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1179 case UNARY_POSITIVE: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1180 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1181 x = PyNumber_Positive(v); |
| 5368 | 1182 Py_DECREF(v); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1183 SET_TOP(x); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1184 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1185 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1186 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1187 case UNARY_NEGATIVE: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1188 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1189 x = PyNumber_Negative(v); |
| 5368 | 1190 Py_DECREF(v); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1191 SET_TOP(x); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1192 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1193 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1194 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1195 case UNARY_NOT: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1196 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1197 err = PyObject_IsTrue(v); |
| 5368 | 1198 Py_DECREF(v); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1199 if (err == 0) { |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1200 Py_INCREF(Py_True); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1201 SET_TOP(Py_True); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1202 continue; |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1203 } |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1204 else if (err > 0) { |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1205 Py_INCREF(Py_False); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1206 SET_TOP(Py_False); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1207 err = 0; |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1208 continue; |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1209 } |
|
27243
3afbd55fb18f
Replaced POP() with STACKADJ(-1) on lines where the result wasn't used.
Raymond Hettinger <python@rcn.com>
parents:
27201
diff
changeset
|
1210 STACKADJ(-1); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1211 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1212 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1213 case UNARY_CONVERT: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1214 v = TOP(); |
| 5368 | 1215 x = PyObject_Repr(v); |
| 1216 Py_DECREF(v); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1217 SET_TOP(x); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1218 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1219 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1220 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1221 case UNARY_INVERT: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1222 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1223 x = PyNumber_Invert(v); |
| 5368 | 1224 Py_DECREF(v); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1225 SET_TOP(x); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1226 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1227 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1228 |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3294
diff
changeset
|
1229 case BINARY_POWER: |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3294
diff
changeset
|
1230 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1231 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1232 x = PyNumber_Power(v, w, Py_None); |
| 5368 | 1233 Py_DECREF(v); |
| 1234 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1235 SET_TOP(x); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1236 if (x != NULL) continue; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3294
diff
changeset
|
1237 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1238 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1239 case BINARY_MULTIPLY: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1240 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1241 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1242 x = PyNumber_Multiply(v, w); |
| 5368 | 1243 Py_DECREF(v); |
| 1244 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1245 SET_TOP(x); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1246 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1247 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1248 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1249 case BINARY_DIVIDE: |
|
21251
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1250 if (!_Py_QnewFlag) { |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1251 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1252 v = TOP(); |
|
21251
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1253 x = PyNumber_Divide(v, w); |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1254 Py_DECREF(v); |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1255 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1256 SET_TOP(x); |
|
21251
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1257 if (x != NULL) continue; |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1258 break; |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1259 } |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1260 /* -Qnew is in effect: fall through to |
|
21251
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1261 BINARY_TRUE_DIVIDE */ |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1262 case BINARY_TRUE_DIVIDE: |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1263 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1264 v = TOP(); |
|
21251
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1265 x = PyNumber_TrueDivide(v, w); |
| 5368 | 1266 Py_DECREF(v); |
| 1267 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1268 SET_TOP(x); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1269 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1270 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1271 |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1272 case BINARY_FLOOR_DIVIDE: |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1273 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1274 v = TOP(); |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1275 x = PyNumber_FloorDivide(v, w); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1276 Py_DECREF(v); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1277 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1278 SET_TOP(x); |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1279 if (x != NULL) continue; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1280 break; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1281 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1282 case BINARY_MODULO: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1283 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1284 v = TOP(); |
|
51759
0848ebb8f9c8
Issue 5176: special-case string formatting in BINARY_MODULO implementation. This shows a modest (1-3%) speed-up in templating systems, for example.
Collin Winter <collinw@gmail.com>
parents:
51472
diff
changeset
|
1285 if (PyString_CheckExact(v)) |
|
0848ebb8f9c8
Issue 5176: special-case string formatting in BINARY_MODULO implementation. This shows a modest (1-3%) speed-up in templating systems, for example.
Collin Winter <collinw@gmail.com>
parents:
51472
diff
changeset
|
1286 x = PyString_Format(v, w); |
|
0848ebb8f9c8
Issue 5176: special-case string formatting in BINARY_MODULO implementation. This shows a modest (1-3%) speed-up in templating systems, for example.
Collin Winter <collinw@gmail.com>
parents:
51472
diff
changeset
|
1287 else |
|
0848ebb8f9c8
Issue 5176: special-case string formatting in BINARY_MODULO implementation. This shows a modest (1-3%) speed-up in templating systems, for example.
Collin Winter <collinw@gmail.com>
parents:
51472
diff
changeset
|
1288 x = PyNumber_Remainder(v, w); |
| 5368 | 1289 Py_DECREF(v); |
| 1290 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1291 SET_TOP(x); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1292 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1293 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1294 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1295 case BINARY_ADD: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1296 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1297 v = TOP(); |
|
20273
2269cb371e05
Get rid of unique local ISSTRICTINT macro in favor of std PyInt_CheckExact.
Tim Peters <tim.peters@gmail.com>
parents:
20257
diff
changeset
|
1298 if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) { |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1299 /* INLINE: int + int */ |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1300 register long a, b, i; |
|
9591
7f90736701a3
Use PyInt_AS_LONG macro instead of explicit inlining.
Guido van Rossum <guido@python.org>
parents:
9513
diff
changeset
|
1301 a = PyInt_AS_LONG(v); |
|
7f90736701a3
Use PyInt_AS_LONG macro instead of explicit inlining.
Guido van Rossum <guido@python.org>
parents:
9513
diff
changeset
|
1302 b = PyInt_AS_LONG(w); |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1303 i = a + b; |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1304 if ((i^a) < 0 && (i^b) < 0) |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1305 goto slow_add; |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1306 x = PyInt_FromLong(i); |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1307 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1308 else if (PyString_CheckExact(v) && |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1309 PyString_CheckExact(w)) { |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1310 x = string_concatenate(v, w, f, next_instr); |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1311 /* string_concatenate consumed the ref to v */ |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1312 goto skip_decref_vx; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1313 } |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1314 else { |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1315 slow_add: |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1316 x = PyNumber_Add(v, w); |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1317 } |
| 5368 | 1318 Py_DECREF(v); |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1319 skip_decref_vx: |
| 5368 | 1320 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1321 SET_TOP(x); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1322 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1323 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1324 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1325 case BINARY_SUBTRACT: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1326 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1327 v = TOP(); |
|
20273
2269cb371e05
Get rid of unique local ISSTRICTINT macro in favor of std PyInt_CheckExact.
Tim Peters <tim.peters@gmail.com>
parents:
20257
diff
changeset
|
1328 if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) { |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1329 /* INLINE: int - int */ |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1330 register long a, b, i; |
|
9591
7f90736701a3
Use PyInt_AS_LONG macro instead of explicit inlining.
Guido van Rossum <guido@python.org>
parents:
9513
diff
changeset
|
1331 a = PyInt_AS_LONG(v); |
|
7f90736701a3
Use PyInt_AS_LONG macro instead of explicit inlining.
Guido van Rossum <guido@python.org>
parents:
9513
diff
changeset
|
1332 b = PyInt_AS_LONG(w); |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1333 i = a - b; |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1334 if ((i^a) < 0 && (i^~b) < 0) |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1335 goto slow_sub; |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1336 x = PyInt_FromLong(i); |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1337 } |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1338 else { |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1339 slow_sub: |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1340 x = PyNumber_Subtract(v, w); |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1341 } |
| 5368 | 1342 Py_DECREF(v); |
| 1343 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1344 SET_TOP(x); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1345 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1346 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1347 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1348 case BINARY_SUBSCR: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1349 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1350 v = TOP(); |
|
20275
167e7f98b51f
Introduced the oddly-missing PyList_CheckExact(), and used it to replace
Tim Peters <tim.peters@gmail.com>
parents:
20273
diff
changeset
|
1351 if (PyList_CheckExact(v) && PyInt_CheckExact(w)) { |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1352 /* INLINE: list[int] */ |
|
36803
8eaf9531a2de
Use Py_ssize_t since we are working with list size below
Neal Norwitz <nnorwitz@gmail.com>
parents:
36756
diff
changeset
|
1353 Py_ssize_t i = PyInt_AsSsize_t(w); |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1354 if (i < 0) |
|
8652
97a1108b0eb2
# In case BINARY_SUBSCR, use proper PyList_GET* macros instead of inlining.
Guido van Rossum <guido@python.org>
parents:
8651
diff
changeset
|
1355 i += PyList_GET_SIZE(v); |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1356 if (i >= 0 && i < PyList_GET_SIZE(v)) { |
|
8652
97a1108b0eb2
# In case BINARY_SUBSCR, use proper PyList_GET* macros instead of inlining.
Guido van Rossum <guido@python.org>
parents:
8651
diff
changeset
|
1357 x = PyList_GET_ITEM(v, i); |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1358 Py_INCREF(x); |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1359 } |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1360 else |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1361 goto slow_get; |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1362 } |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1363 else |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1364 slow_get: |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1365 x = PyObject_GetItem(v, w); |
| 5368 | 1366 Py_DECREF(v); |
| 1367 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1368 SET_TOP(x); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1369 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1370 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1371 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1372 case BINARY_LSHIFT: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1373 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1374 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1375 x = PyNumber_Lshift(v, w); |
| 5368 | 1376 Py_DECREF(v); |
| 1377 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1378 SET_TOP(x); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1379 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1380 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1381 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1382 case BINARY_RSHIFT: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1383 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1384 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1385 x = PyNumber_Rshift(v, w); |
| 5368 | 1386 Py_DECREF(v); |
| 1387 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1388 SET_TOP(x); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1389 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1390 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1391 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1392 case BINARY_AND: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1393 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1394 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1395 x = PyNumber_And(v, w); |
| 5368 | 1396 Py_DECREF(v); |
| 1397 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1398 SET_TOP(x); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1399 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1400 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1401 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1402 case BINARY_XOR: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1403 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1404 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1405 x = PyNumber_Xor(v, w); |
| 5368 | 1406 Py_DECREF(v); |
| 1407 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1408 SET_TOP(x); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1409 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1410 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1411 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1412 case BINARY_OR: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1413 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1414 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1415 x = PyNumber_Or(v, w); |
| 5368 | 1416 Py_DECREF(v); |
| 1417 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1418 SET_TOP(x); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1419 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1420 break; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1421 |
|
31618
bc006682acb2
SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents:
31606
diff
changeset
|
1422 case LIST_APPEND: |
|
bc006682acb2
SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents:
31606
diff
changeset
|
1423 w = POP(); |
|
50204
94e79d78dff0
Issue #2183: Simplify and optimize bytecode for list comprehensions.
Antoine Pitrou <solipsis@pitrou.net>
parents:
50103
diff
changeset
|
1424 v = stack_pointer[-oparg]; |
|
31618
bc006682acb2
SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents:
31606
diff
changeset
|
1425 err = PyList_Append(v, w); |
|
bc006682acb2
SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents:
31606
diff
changeset
|
1426 Py_DECREF(w); |
|
31649
243642bbd03f
LIST_APPEND is predicably followed by JUMP_ABSOLUTE.
Raymond Hettinger <python@rcn.com>
parents:
31647
diff
changeset
|
1427 if (err == 0) { |
|
243642bbd03f
LIST_APPEND is predicably followed by JUMP_ABSOLUTE.
Raymond Hettinger <python@rcn.com>
parents:
31647
diff
changeset
|
1428 PREDICT(JUMP_ABSOLUTE); |
|
243642bbd03f
LIST_APPEND is predicably followed by JUMP_ABSOLUTE.
Raymond Hettinger <python@rcn.com>
parents:
31647
diff
changeset
|
1429 continue; |
|
243642bbd03f
LIST_APPEND is predicably followed by JUMP_ABSOLUTE.
Raymond Hettinger <python@rcn.com>
parents:
31647
diff
changeset
|
1430 } |
|
31618
bc006682acb2
SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents:
31606
diff
changeset
|
1431 break; |
|
bc006682acb2
SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents:
31606
diff
changeset
|
1432 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1433 case INPLACE_POWER: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1434 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1435 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1436 x = PyNumber_InPlacePower(v, w, Py_None); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1437 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1438 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1439 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1440 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1441 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1442 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1443 case INPLACE_MULTIPLY: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1444 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1445 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1446 x = PyNumber_InPlaceMultiply(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1447 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1448 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1449 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1450 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1451 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1452 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1453 case INPLACE_DIVIDE: |
|
21537
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1454 if (!_Py_QnewFlag) { |
|
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1455 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1456 v = TOP(); |
|
21537
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1457 x = PyNumber_InPlaceDivide(v, w); |
|
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1458 Py_DECREF(v); |
|
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1459 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1460 SET_TOP(x); |
|
21537
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1461 if (x != NULL) continue; |
|
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1462 break; |
|
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1463 } |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1464 /* -Qnew is in effect: fall through to |
|
21537
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1465 INPLACE_TRUE_DIVIDE */ |
|
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1466 case INPLACE_TRUE_DIVIDE: |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1467 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1468 v = TOP(); |
|
21537
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1469 x = PyNumber_InPlaceTrueDivide(v, w); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1470 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1471 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1472 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1473 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1474 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1475 |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1476 case INPLACE_FLOOR_DIVIDE: |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1477 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1478 v = TOP(); |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1479 x = PyNumber_InPlaceFloorDivide(v, w); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1480 Py_DECREF(v); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1481 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1482 SET_TOP(x); |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1483 if (x != NULL) continue; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1484 break; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1485 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1486 case INPLACE_MODULO: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1487 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1488 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1489 x = PyNumber_InPlaceRemainder(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1490 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1491 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1492 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1493 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1494 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1495 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1496 case INPLACE_ADD: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1497 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1498 v = TOP(); |
|
20273
2269cb371e05
Get rid of unique local ISSTRICTINT macro in favor of std PyInt_CheckExact.
Tim Peters <tim.peters@gmail.com>
parents:
20257
diff
changeset
|
1499 if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) { |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1500 /* INLINE: int + int */ |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1501 register long a, b, i; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1502 a = PyInt_AS_LONG(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1503 b = PyInt_AS_LONG(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1504 i = a + b; |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1505 if ((i^a) < 0 && (i^b) < 0) |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1506 goto slow_iadd; |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1507 x = PyInt_FromLong(i); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1508 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1509 else if (PyString_CheckExact(v) && |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1510 PyString_CheckExact(w)) { |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1511 x = string_concatenate(v, w, f, next_instr); |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1512 /* string_concatenate consumed the ref to v */ |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1513 goto skip_decref_v; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1514 } |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1515 else { |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1516 slow_iadd: |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1517 x = PyNumber_InPlaceAdd(v, w); |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1518 } |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1519 Py_DECREF(v); |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1520 skip_decref_v: |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1521 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1522 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1523 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1524 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1525 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1526 case INPLACE_SUBTRACT: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1527 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1528 v = TOP(); |
|
20273
2269cb371e05
Get rid of unique local ISSTRICTINT macro in favor of std PyInt_CheckExact.
Tim Peters <tim.peters@gmail.com>
parents:
20257
diff
changeset
|
1529 if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) { |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1530 /* INLINE: int - int */ |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1531 register long a, b, i; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1532 a = PyInt_AS_LONG(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1533 b = PyInt_AS_LONG(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1534 i = a - b; |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1535 if ((i^a) < 0 && (i^~b) < 0) |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1536 goto slow_isub; |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1537 x = PyInt_FromLong(i); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1538 } |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1539 else { |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1540 slow_isub: |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1541 x = PyNumber_InPlaceSubtract(v, w); |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1542 } |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1543 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1544 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1545 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1546 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1547 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1548 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1549 case INPLACE_LSHIFT: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1550 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1551 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1552 x = PyNumber_InPlaceLshift(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1553 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1554 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1555 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1556 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1557 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1558 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1559 case INPLACE_RSHIFT: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1560 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1561 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1562 x = PyNumber_InPlaceRshift(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1563 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1564 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1565 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1566 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1567 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1568 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1569 case INPLACE_AND: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1570 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1571 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1572 x = PyNumber_InPlaceAnd(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1573 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1574 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1575 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1576 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1577 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1578 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1579 case INPLACE_XOR: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1580 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1581 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1582 x = PyNumber_InPlaceXor(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1583 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1584 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1585 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1586 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1587 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1588 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1589 case INPLACE_OR: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1590 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1591 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1592 x = PyNumber_InPlaceOr(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1593 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1594 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1595 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1596 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1597 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1598 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1599 case SLICE+0: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1600 case SLICE+1: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1601 case SLICE+2: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1602 case SLICE+3: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1603 if ((opcode-SLICE) & 2) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1604 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1605 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1606 w = NULL; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1607 if ((opcode-SLICE) & 1) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1608 v = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1609 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1610 v = NULL; |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1611 u = TOP(); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1612 x = apply_slice(u, v, w); |
| 5368 | 1613 Py_DECREF(u); |
| 1614 Py_XDECREF(v); | |
| 1615 Py_XDECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1616 SET_TOP(x); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1617 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1618 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1619 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1620 case STORE_SLICE+0: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1621 case STORE_SLICE+1: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1622 case STORE_SLICE+2: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1623 case STORE_SLICE+3: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1624 if ((opcode-STORE_SLICE) & 2) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1625 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1626 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1627 w = NULL; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1628 if ((opcode-STORE_SLICE) & 1) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1629 v = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1630 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1631 v = NULL; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1632 u = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1633 t = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1634 err = assign_slice(u, v, w, t); /* u[v:w] = t */ |
| 5368 | 1635 Py_DECREF(t); |
| 1636 Py_DECREF(u); | |
| 1637 Py_XDECREF(v); | |
| 1638 Py_XDECREF(w); | |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1639 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1640 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1641 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1642 case DELETE_SLICE+0: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1643 case DELETE_SLICE+1: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1644 case DELETE_SLICE+2: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1645 case DELETE_SLICE+3: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1646 if ((opcode-DELETE_SLICE) & 2) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1647 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1648 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1649 w = NULL; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1650 if ((opcode-DELETE_SLICE) & 1) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1651 v = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1652 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1653 v = NULL; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1654 u = POP(); |
| 5368 | 1655 err = assign_slice(u, v, w, (PyObject *)NULL); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1656 /* del u[v:w] */ |
| 5368 | 1657 Py_DECREF(u); |
| 1658 Py_XDECREF(v); | |
| 1659 Py_XDECREF(w); | |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1660 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1661 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1662 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1663 case STORE_SUBSCR: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1664 w = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1665 v = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1666 u = THIRD(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1667 STACKADJ(-3); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1668 /* v[w] = u */ |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1669 err = PyObject_SetItem(v, w, u); |
| 5368 | 1670 Py_DECREF(u); |
| 1671 Py_DECREF(v); | |
| 1672 Py_DECREF(w); | |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1673 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1674 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1675 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1676 case DELETE_SUBSCR: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1677 w = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1678 v = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1679 STACKADJ(-2); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1680 /* del v[w] */ |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1681 err = PyObject_DelItem(v, w); |
| 5368 | 1682 Py_DECREF(v); |
| 1683 Py_DECREF(w); | |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1684 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1685 break; |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1686 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1687 case PRINT_EXPR: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1688 v = POP(); |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1689 w = PySys_GetObject("displayhook"); |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1690 if (w == NULL) { |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1691 PyErr_SetString(PyExc_RuntimeError, |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1692 "lost sys.displayhook"); |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1693 err = -1; |
|
15814
faaf9f10d849
Fixed bugs noted by Greg Stein
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15811
diff
changeset
|
1694 x = NULL; |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1695 } |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1696 if (err == 0) { |
|
30683
3b59fa5d25b1
Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents:
29669
diff
changeset
|
1697 x = PyTuple_Pack(1, v); |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1698 if (x == NULL) |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1699 err = -1; |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1700 } |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1701 if (err == 0) { |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1702 w = PyEval_CallObject(w, x); |
|
15814
faaf9f10d849
Fixed bugs noted by Greg Stein
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15811
diff
changeset
|
1703 Py_XDECREF(w); |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1704 if (w == NULL) |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1705 err = -1; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1706 } |
| 5368 | 1707 Py_DECREF(v); |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1708 Py_XDECREF(x); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1709 break; |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1710 |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1711 case PRINT_ITEM_TO: |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1712 w = stream = POP(); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1713 /* fall through to PRINT_ITEM */ |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1714 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1715 case PRINT_ITEM: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1716 v = POP(); |
|
14238
74f7f237f739
eval_code2(): Guido provides this patch for his suggested elaboration
Barry Warsaw <barry@python.org>
parents:
14232
diff
changeset
|
1717 if (stream == NULL || stream == Py_None) { |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1718 w = PySys_GetObject("stdout"); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1719 if (w == NULL) { |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1720 PyErr_SetString(PyExc_RuntimeError, |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1721 "lost sys.stdout"); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1722 err = -1; |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1723 } |
|
7014
c75d899e666f
Last-minute fix for Jim H: don't die after del sys.stdout
Guido van Rossum <guido@python.org>
parents:
6945
diff
changeset
|
1724 } |
|
29669
96ecaab4cba6
Fix SF #762455, segfault when sys.stdout is changed in getattr
Neal Norwitz <nnorwitz@gmail.com>
parents:
29643
diff
changeset
|
1725 /* PyFile_SoftSpace() can exececute arbitrary code |
|
96ecaab4cba6
Fix SF #762455, segfault when sys.stdout is changed in getattr
Neal Norwitz <nnorwitz@gmail.com>
parents:
29643
diff
changeset
|
1726 if sys.stdout is an instance with a __getattr__. |
|
96ecaab4cba6
Fix SF #762455, segfault when sys.stdout is changed in getattr
Neal Norwitz <nnorwitz@gmail.com>
parents:
29643
diff
changeset
|
1727 If __getattr__ raises an exception, w will |
|
96ecaab4cba6
Fix SF #762455, segfault when sys.stdout is changed in getattr
Neal Norwitz <nnorwitz@gmail.com>
parents:
29643
diff
changeset
|
1728 be freed, so we need to prevent that temporarily. */ |
|
96ecaab4cba6
Fix SF #762455, segfault when sys.stdout is changed in getattr
Neal Norwitz <nnorwitz@gmail.com>
parents:
29643
diff
changeset
|
1729 Py_XINCREF(w); |
|
22499
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1730 if (w != NULL && PyFile_SoftSpace(w, 0)) |
|
5606
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
1731 err = PyFile_WriteString(" ", w); |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
1732 if (err == 0) |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
1733 err = PyFile_WriteObject(v, w, Py_PRINT_RAW); |
|
21027
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1734 if (err == 0) { |
|
22499
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1735 /* XXX move into writeobject() ? */ |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1736 if (PyString_Check(v)) { |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1737 char *s = PyString_AS_STRING(v); |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1738 Py_ssize_t len = PyString_GET_SIZE(v); |
|
22499
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1739 if (len == 0 || |
|
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1740 !isspace(Py_CHARMASK(s[len-1])) || |
|
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1741 s[len-1] == ' ') |
|
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1742 PyFile_SoftSpace(w, 1); |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
1743 } |
|
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
|
1744 #ifdef Py_USING_UNICODE |
|
21027
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1745 else if (PyUnicode_Check(v)) { |
|
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1746 Py_UNICODE *s = PyUnicode_AS_UNICODE(v); |
|
37920
ce5585afc20f
Fix more ssize_t issues.
Martin v. Löwis <martin@v.loewis.de>
parents:
37856
diff
changeset
|
1747 Py_ssize_t len = PyUnicode_GET_SIZE(v); |
|
22499
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1748 if (len == 0 || |
|
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1749 !Py_UNICODE_ISSPACE(s[len-1]) || |
|
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1750 s[len-1] == ' ') |
|
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1751 PyFile_SoftSpace(w, 1); |
|
21027
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1752 } |
| 23479 | 1753 #endif |
|
22499
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1754 else |
|
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1755 PyFile_SoftSpace(w, 1); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1756 } |
|
29669
96ecaab4cba6
Fix SF #762455, segfault when sys.stdout is changed in getattr
Neal Norwitz <nnorwitz@gmail.com>
parents:
29643
diff
changeset
|
1757 Py_XDECREF(w); |
| 5368 | 1758 Py_DECREF(v); |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1759 Py_XDECREF(stream); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1760 stream = NULL; |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1761 if (err == 0) |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1762 continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1763 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1764 |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1765 case PRINT_NEWLINE_TO: |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1766 w = stream = POP(); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1767 /* fall through to PRINT_NEWLINE */ |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1768 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1769 case PRINT_NEWLINE: |
|
14238
74f7f237f739
eval_code2(): Guido provides this patch for his suggested elaboration
Barry Warsaw <barry@python.org>
parents:
14232
diff
changeset
|
1770 if (stream == NULL || stream == Py_None) { |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1771 w = PySys_GetObject("stdout"); |
|
50092
dc696deb2cf2
Issue 4597: Fix several cases in EvalFrameEx where an exception could be
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49940
diff
changeset
|
1772 if (w == NULL) { |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1773 PyErr_SetString(PyExc_RuntimeError, |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1774 "lost sys.stdout"); |
|
50092
dc696deb2cf2
Issue 4597: Fix several cases in EvalFrameEx where an exception could be
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49940
diff
changeset
|
1775 why = WHY_EXCEPTION; |
|
dc696deb2cf2
Issue 4597: Fix several cases in EvalFrameEx where an exception could be
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49940
diff
changeset
|
1776 } |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1777 } |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1778 if (w != NULL) { |
|
47868
4a8329535234
Add a comment about incref'ing w.
Georg Brandl <georg@python.org>
parents:
47864
diff
changeset
|
1779 /* w.write() may replace sys.stdout, so we |
|
4a8329535234
Add a comment about incref'ing w.
Georg Brandl <georg@python.org>
parents:
47864
diff
changeset
|
1780 * have to keep our reference to it */ |
|
47864
7dbd6b607706
#3242: fix a crash in "print", if sys.stdout is set to a custom object,
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47527
diff
changeset
|
1781 Py_INCREF(w); |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1782 err = PyFile_WriteString("\n", w); |
|
5606
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
1783 if (err == 0) |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1784 PyFile_SoftSpace(w, 0); |
|
47864
7dbd6b607706
#3242: fix a crash in "print", if sys.stdout is set to a custom object,
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47527
diff
changeset
|
1785 Py_DECREF(w); |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1016
diff
changeset
|
1786 } |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1787 Py_XDECREF(stream); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1788 stream = NULL; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1789 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1790 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1791 |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1792 #ifdef CASE_TOO_BIG |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1793 default: switch (opcode) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1794 #endif |
|
2813
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
1795 case RAISE_VARARGS: |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
1796 u = v = w = NULL; |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
1797 switch (oparg) { |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
1798 case 3: |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
1799 u = POP(); /* traceback */ |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
1800 /* Fallthrough */ |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
1801 case 2: |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
1802 v = POP(); /* value */ |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
1803 /* Fallthrough */ |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
1804 case 1: |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
1805 w = POP(); /* exc */ |
|
7946
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
1806 case 0: /* Fallthrough */ |
|
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
|
1807 why = do_raise(w, v, u); |
|
2813
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
1808 break; |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
1809 default: |
| 5368 | 1810 PyErr_SetString(PyExc_SystemError, |
|
2813
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
1811 "bad RAISE_VARARGS oparg"); |
|
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
|
1812 why = WHY_EXCEPTION; |
|
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
|
1813 break; |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1814 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1815 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1816 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1817 case LOAD_LOCALS: |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1818 if ((x = f->f_locals) != NULL) { |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1819 Py_INCREF(x); |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1820 PUSH(x); |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1821 continue; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1822 } |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1823 PyErr_SetString(PyExc_SystemError, "no locals"); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1824 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1825 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1826 case RETURN_VALUE: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1827 retval = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1828 why = WHY_RETURN; |
|
31462
d5c047807c69
SF patch #864059: optimize eval_frame
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1829 goto fast_block_end; |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1830 |
|
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
|
1831 case YIELD_VALUE: |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
1832 retval = POP(); |
|
18237
f02605b8fdc1
PyFrameObject: rename f_stackbottom to f_stacktop, since it points to
Tim Peters <tim.peters@gmail.com>
parents:
18195
diff
changeset
|
1833 f->f_stacktop = stack_pointer; |
|
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
|
1834 why = WHY_YIELD; |
|
31462
d5c047807c69
SF patch #864059: optimize eval_frame
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1835 goto fast_yield; |
|
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
|
1836 |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1837 case EXEC_STMT: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1838 w = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1839 v = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1840 u = THIRD(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1841 STACKADJ(-3); |
|
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
|
1842 READ_TIMESTAMP(intr0); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1843 err = exec_statement(f, u, v, w); |
|
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
|
1844 READ_TIMESTAMP(intr1); |
| 5368 | 1845 Py_DECREF(u); |
| 1846 Py_DECREF(v); | |
| 1847 Py_DECREF(w); | |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1848 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1849 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1850 case POP_BLOCK: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1851 { |
| 5368 | 1852 PyTryBlock *b = PyFrame_BlockPop(f); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1853 while (STACK_LEVEL() > b->b_level) { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1854 v = POP(); |
| 5368 | 1855 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1856 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1857 } |
|
31880
4c6fdeb8e2e0
Use continue instead of break whereever possible.
Raymond Hettinger <python@rcn.com>
parents:
31879
diff
changeset
|
1858 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1859 |
|
45624
6068b75ec27a
compile.c always emits END_FINALLY after WITH_CLEANUP, so predict that in
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
45011
diff
changeset
|
1860 PREDICTED(END_FINALLY); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1861 case END_FINALLY: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1862 v = POP(); |
| 5368 | 1863 if (PyInt_Check(v)) { |
|
31875
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
1864 why = (enum why_code) PyInt_AS_LONG(v); |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
1865 assert(why != WHY_YIELD); |
|
31900
0265bf9912ea
Some (but not all) of the why code bitfield tests ran faster as
Raymond Hettinger <python@rcn.com>
parents:
31894
diff
changeset
|
1866 if (why == WHY_RETURN || |
|
0265bf9912ea
Some (but not all) of the why code bitfield tests ran faster as
Raymond Hettinger <python@rcn.com>
parents:
31894
diff
changeset
|
1867 why == WHY_CONTINUE) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1868 retval = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1869 } |
|
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
|
1870 else if (PyExceptionClass_Check(v) || |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1871 PyString_Check(v)) { |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1872 w = POP(); |
|
2813
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
1873 u = POP(); |
| 5368 | 1874 PyErr_Restore(v, w, u); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1875 why = WHY_RERAISE; |
|
2872
d3b07ba3e12d
fix bogus DECREF in finally clause
Guido van Rossum <guido@python.org>
parents:
2866
diff
changeset
|
1876 break; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1877 } |
| 5368 | 1878 else if (v != Py_None) { |
| 1879 PyErr_SetString(PyExc_SystemError, | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1880 "'finally' pops bad exception"); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1881 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1882 } |
| 5368 | 1883 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1884 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1885 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1886 case BUILD_CLASS: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1887 u = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1888 v = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1889 w = THIRD(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1890 STACKADJ(-2); |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
1891 x = build_class(u, v, w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1892 SET_TOP(x); |
| 5368 | 1893 Py_DECREF(u); |
| 1894 Py_DECREF(v); | |
| 1895 Py_DECREF(w); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1896 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1897 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1898 case STORE_NAME: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1899 w = GETITEM(names, oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1900 v = POP(); |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1901 if ((x = f->f_locals) != NULL) { |
|
32890
b8c2aa2be19a
Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents:
32531
diff
changeset
|
1902 if (PyDict_CheckExact(x)) |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
1903 err = PyDict_SetItem(x, w, v); |
|
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
1904 else |
|
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
1905 err = PyObject_SetItem(x, w, v); |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1906 Py_DECREF(v); |
|
31880
4c6fdeb8e2e0
Use continue instead of break whereever possible.
Raymond Hettinger <python@rcn.com>
parents:
31879
diff
changeset
|
1907 if (err == 0) continue; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1908 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1909 } |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1910 PyErr_Format(PyExc_SystemError, |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1911 "no locals found when storing %s", |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1912 PyObject_REPR(w)); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1913 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1914 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1915 case DELETE_NAME: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1916 w = GETITEM(names, oparg); |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1917 if ((x = f->f_locals) != NULL) { |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
1918 if ((err = PyObject_DelItem(x, w)) != 0) |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1919 format_exc_check_arg(PyExc_NameError, |
|
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
|
1920 NAME_ERROR_MSG, |
|
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
|
1921 w); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1922 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1923 } |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1924 PyErr_Format(PyExc_SystemError, |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1925 "no locals when deleting %s", |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1926 PyObject_REPR(w)); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1927 break; |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
1928 |
|
28304
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
1929 PREDICTED_WITH_ARG(UNPACK_SEQUENCE); |
|
13930
4eaa463c031a
Merge UNPACK_LIST and UNPACK_TUPLE into a single UNPACK_SEQUENCE, since they
Thomas Wouters <thomas@python.org>
parents:
13881
diff
changeset
|
1930 case UNPACK_SEQUENCE: |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1931 v = POP(); |
|
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
|
1932 if (PyTuple_CheckExact(v) && |
|
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
|
1933 PyTuple_GET_SIZE(v) == oparg) { |
|
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
|
1934 PyObject **items = \ |
|
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
|
1935 ((PyTupleObject *)v)->ob_item; |
|
31630
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1936 while (oparg--) { |
|
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1937 w = items[oparg]; |
|
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1938 Py_INCREF(w); |
|
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1939 PUSH(w); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1940 } |
|
31880
4c6fdeb8e2e0
Use continue instead of break whereever possible.
Raymond Hettinger <python@rcn.com>
parents:
31879
diff
changeset
|
1941 Py_DECREF(v); |
|
4c6fdeb8e2e0
Use continue instead of break whereever possible.
Raymond Hettinger <python@rcn.com>
parents:
31879
diff
changeset
|
1942 continue; |
|
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
|
1943 } else if (PyList_CheckExact(v) && |
|
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
|
1944 PyList_GET_SIZE(v) == oparg) { |
|
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
|
1945 PyObject **items = \ |
|
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
|
1946 ((PyListObject *)v)->ob_item; |
|
31630
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1947 while (oparg--) { |
|
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1948 w = items[oparg]; |
|
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1949 Py_INCREF(w); |
|
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1950 PUSH(w); |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1951 } |
|
31630
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1952 } else if (unpack_iterable(v, oparg, |
|
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
|
1953 stack_pointer + oparg)) { |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
1954 stack_pointer += oparg; |
|
41256
9cf22c5eee3d
Patch #1682205: a TypeError while unpacking an iterable is no longer
Georg Brandl <georg@python.org>
parents:
41007
diff
changeset
|
1955 } else { |
|
9cf22c5eee3d
Patch #1682205: a TypeError while unpacking an iterable is no longer
Georg Brandl <georg@python.org>
parents:
41007
diff
changeset
|
1956 /* unpack_iterable() raised an exception */ |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1957 why = WHY_EXCEPTION; |
|
20183
c6b6189a8397
SF bug [#466173] unpack TypeError unclear
Tim Peters <tim.peters@gmail.com>
parents:
20114
diff
changeset
|
1958 } |
| 5368 | 1959 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1960 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1961 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1962 case STORE_ATTR: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1963 w = GETITEM(names, oparg); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1964 v = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1965 u = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1966 STACKADJ(-2); |
| 5368 | 1967 err = PyObject_SetAttr(v, w, u); /* v.w = u */ |
| 1968 Py_DECREF(v); | |
| 1969 Py_DECREF(u); | |
|
31880
4c6fdeb8e2e0
Use continue instead of break whereever possible.
Raymond Hettinger <python@rcn.com>
parents:
31879
diff
changeset
|
1970 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1971 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1972 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1973 case DELETE_ATTR: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1974 w = GETITEM(names, oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1975 v = POP(); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1976 err = PyObject_SetAttr(v, w, (PyObject *)NULL); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1977 /* del v.w */ |
| 5368 | 1978 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1979 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1980 |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1981 case STORE_GLOBAL: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1982 w = GETITEM(names, oparg); |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1983 v = POP(); |
| 5368 | 1984 err = PyDict_SetItem(f->f_globals, w, v); |
| 1985 Py_DECREF(v); | |
|
31880
4c6fdeb8e2e0
Use continue instead of break whereever possible.
Raymond Hettinger <python@rcn.com>
parents:
31879
diff
changeset
|
1986 if (err == 0) continue; |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1987 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1988 |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1989 case DELETE_GLOBAL: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1990 w = GETITEM(names, oparg); |
| 5368 | 1991 if ((err = PyDict_DelItem(f->f_globals, w)) != 0) |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1992 format_exc_check_arg( |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1993 PyExc_NameError, GLOBAL_NAME_ERROR_MSG, w); |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1994 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1995 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1996 case LOAD_NAME: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1997 w = GETITEM(names, oparg); |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
1998 if ((v = f->f_locals) == NULL) { |
|
16017
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15948
diff
changeset
|
1999 PyErr_Format(PyExc_SystemError, |
|
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15948
diff
changeset
|
2000 "no locals when loading %s", |
|
16394
f700e6b8de1f
Undo recent change that banned using import to bind a global, as per
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16365
diff
changeset
|
2001 PyObject_REPR(w)); |
|
50092
dc696deb2cf2
Issue 4597: Fix several cases in EvalFrameEx where an exception could be
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49940
diff
changeset
|
2002 why = WHY_EXCEPTION; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2003 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2004 } |
|
32900
ac73f6662e11
Fix for the unfortunate fact that PyDict_GetItem and PyObject_GetItem
Michael W. Hudson <mwh@python.net>
parents:
32890
diff
changeset
|
2005 if (PyDict_CheckExact(v)) { |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
2006 x = PyDict_GetItem(v, w); |
|
32900
ac73f6662e11
Fix for the unfortunate fact that PyDict_GetItem and PyObject_GetItem
Michael W. Hudson <mwh@python.net>
parents:
32890
diff
changeset
|
2007 Py_XINCREF(x); |
|
ac73f6662e11
Fix for the unfortunate fact that PyDict_GetItem and PyObject_GetItem
Michael W. Hudson <mwh@python.net>
parents:
32890
diff
changeset
|
2008 } |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
2009 else { |
|
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
2010 x = PyObject_GetItem(v, w); |
|
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
2011 if (x == NULL && PyErr_Occurred()) { |
|
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
|
2012 if (!PyErr_ExceptionMatches( |
|
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
|
2013 PyExc_KeyError)) |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
2014 break; |
|
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
2015 PyErr_Clear(); |
|
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
2016 } |
|
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
2017 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2018 if (x == NULL) { |
| 5368 | 2019 x = PyDict_GetItem(f->f_globals, w); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2020 if (x == NULL) { |
| 5368 | 2021 x = PyDict_GetItem(f->f_builtins, w); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2022 if (x == NULL) { |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
2023 format_exc_check_arg( |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2024 PyExc_NameError, |
|
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
|
2025 NAME_ERROR_MSG, w); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2026 break; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2027 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2028 } |
|
32900
ac73f6662e11
Fix for the unfortunate fact that PyDict_GetItem and PyObject_GetItem
Michael W. Hudson <mwh@python.net>
parents:
32890
diff
changeset
|
2029 Py_INCREF(x); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2030 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2031 PUSH(x); |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2032 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2033 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2034 case LOAD_GLOBAL: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
2035 w = GETITEM(names, oparg); |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2036 if (PyString_CheckExact(w)) { |
|
24900
2cdf3d0dfabd
Add a warning comment to the LOAD_GLOBAL inline code.
Guido van Rossum <guido@python.org>
parents:
24899
diff
changeset
|
2037 /* Inline the PyDict_GetItem() calls. |
|
2cdf3d0dfabd
Add a warning comment to the LOAD_GLOBAL inline code.
Guido van Rossum <guido@python.org>
parents:
24899
diff
changeset
|
2038 WARNING: this is an extreme speed hack. |
|
2cdf3d0dfabd
Add a warning comment to the LOAD_GLOBAL inline code.
Guido van Rossum <guido@python.org>
parents:
24899
diff
changeset
|
2039 Do not try this at home. */ |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2040 long hash = ((PyStringObject *)w)->ob_shash; |
|
24899
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2041 if (hash != -1) { |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2042 PyDictObject *d; |
|
38536
175cbdf9a5fb
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
Armin Rigo <arigo@tunes.org>
parents:
38425
diff
changeset
|
2043 PyDictEntry *e; |
|
24899
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2044 d = (PyDictObject *)(f->f_globals); |
|
38536
175cbdf9a5fb
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
Armin Rigo <arigo@tunes.org>
parents:
38425
diff
changeset
|
2045 e = d->ma_lookup(d, w, hash); |
|
175cbdf9a5fb
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
Armin Rigo <arigo@tunes.org>
parents:
38425
diff
changeset
|
2046 if (e == NULL) { |
|
175cbdf9a5fb
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
Armin Rigo <arigo@tunes.org>
parents:
38425
diff
changeset
|
2047 x = NULL; |
|
175cbdf9a5fb
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
Armin Rigo <arigo@tunes.org>
parents:
38425
diff
changeset
|
2048 break; |
|
175cbdf9a5fb
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
Armin Rigo <arigo@tunes.org>
parents:
38425
diff
changeset
|
2049 } |
|
175cbdf9a5fb
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
Armin Rigo <arigo@tunes.org>
parents:
38425
diff
changeset
|
2050 x = e->me_value; |
|
24899
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2051 if (x != NULL) { |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2052 Py_INCREF(x); |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2053 PUSH(x); |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2054 continue; |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2055 } |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2056 d = (PyDictObject *)(f->f_builtins); |
|
38536
175cbdf9a5fb
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
Armin Rigo <arigo@tunes.org>
parents:
38425
diff
changeset
|
2057 e = d->ma_lookup(d, w, hash); |
|
175cbdf9a5fb
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
Armin Rigo <arigo@tunes.org>
parents:
38425
diff
changeset
|
2058 if (e == NULL) { |
|
175cbdf9a5fb
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
Armin Rigo <arigo@tunes.org>
parents:
38425
diff
changeset
|
2059 x = NULL; |
|
175cbdf9a5fb
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
Armin Rigo <arigo@tunes.org>
parents:
38425
diff
changeset
|
2060 break; |
|
175cbdf9a5fb
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
Armin Rigo <arigo@tunes.org>
parents:
38425
diff
changeset
|
2061 } |
|
175cbdf9a5fb
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
Armin Rigo <arigo@tunes.org>
parents:
38425
diff
changeset
|
2062 x = e->me_value; |
|
24899
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2063 if (x != NULL) { |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2064 Py_INCREF(x); |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2065 PUSH(x); |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2066 continue; |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2067 } |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2068 goto load_global_error; |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2069 } |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2070 } |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2071 /* This is the un-inlined version of the code above */ |
| 5368 | 2072 x = PyDict_GetItem(f->f_globals, w); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2073 if (x == NULL) { |
| 5368 | 2074 x = PyDict_GetItem(f->f_builtins, w); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2075 if (x == NULL) { |
|
24899
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2076 load_global_error: |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
2077 format_exc_check_arg( |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2078 PyExc_NameError, |
|
24899
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2079 GLOBAL_NAME_ERROR_MSG, w); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2080 break; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2081 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2082 } |
| 5368 | 2083 Py_INCREF(x); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2084 PUSH(x); |
|
31880
4c6fdeb8e2e0
Use continue instead of break whereever possible.
Raymond Hettinger <python@rcn.com>
parents:
31879
diff
changeset
|
2085 continue; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2086 |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
2087 case DELETE_FAST: |
|
8318
ec87b62466d3
DELETE_FAST should issue an exception when the local variable is undefined.
Guido van Rossum <guido@python.org>
parents:
7982
diff
changeset
|
2088 x = GETLOCAL(oparg); |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2089 if (x != NULL) { |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2090 SETLOCAL(oparg, NULL); |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2091 continue; |
|
8318
ec87b62466d3
DELETE_FAST should issue an exception when the local variable is undefined.
Guido van Rossum <guido@python.org>
parents:
7982
diff
changeset
|
2092 } |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2093 format_exc_check_arg( |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2094 PyExc_UnboundLocalError, |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2095 UNBOUNDLOCAL_ERROR_MSG, |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2096 PyTuple_GetItem(co->co_varnames, oparg) |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2097 ); |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2098 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2099 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2100 case LOAD_CLOSURE: |
|
16355
e4420c2468f9
Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16257
diff
changeset
|
2101 x = freevars[oparg]; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2102 Py_INCREF(x); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2103 PUSH(x); |
|
31880
4c6fdeb8e2e0
Use continue instead of break whereever possible.
Raymond Hettinger <python@rcn.com>
parents:
31879
diff
changeset
|
2104 if (x != NULL) continue; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2105 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2106 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2107 case LOAD_DEREF: |
|
16355
e4420c2468f9
Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16257
diff
changeset
|
2108 x = freevars[oparg]; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2109 w = PyCell_Get(x); |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2110 if (w != NULL) { |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2111 PUSH(w); |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2112 continue; |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2113 } |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2114 err = -1; |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2115 /* Don't stomp existing exception */ |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2116 if (PyErr_Occurred()) |
|
16453
2e3dd62ceac5
SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16398
diff
changeset
|
2117 break; |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38217
diff
changeset
|
2118 if (oparg < PyTuple_GET_SIZE(co->co_cellvars)) { |
|
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38217
diff
changeset
|
2119 v = PyTuple_GET_ITEM(co->co_cellvars, |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2120 oparg); |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2121 format_exc_check_arg( |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2122 PyExc_UnboundLocalError, |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2123 UNBOUNDLOCAL_ERROR_MSG, |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2124 v); |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2125 } else { |
|
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
|
2126 v = PyTuple_GET_ITEM(co->co_freevars, oparg - |
|
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
|
2127 PyTuple_GET_SIZE(co->co_cellvars)); |
|
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
|
2128 format_exc_check_arg(PyExc_NameError, |
|
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
|
2129 UNBOUNDFREE_ERROR_MSG, v); |
|
16453
2e3dd62ceac5
SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16398
diff
changeset
|
2130 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2131 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2132 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2133 case STORE_DEREF: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2134 w = POP(); |
|
16355
e4420c2468f9
Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16257
diff
changeset
|
2135 x = freevars[oparg]; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2136 PyCell_Set(x, w); |
|
17034
ba81d79dc3a3
Variety of small INC/DECREF patches that fix reported memory leaks
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16631
diff
changeset
|
2137 Py_DECREF(w); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2138 continue; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2139 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2140 case BUILD_TUPLE: |
| 5368 | 2141 x = PyTuple_New(oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2142 if (x != NULL) { |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
2143 for (; --oparg >= 0;) { |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2144 w = POP(); |
| 5368 | 2145 PyTuple_SET_ITEM(x, oparg, w); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2146 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2147 PUSH(x); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2148 continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2149 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2150 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2151 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2152 case BUILD_LIST: |
| 5368 | 2153 x = PyList_New(oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2154 if (x != NULL) { |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
2155 for (; --oparg >= 0;) { |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2156 w = POP(); |
|
8811
e58a614fb8e4
In BUILD_LIST, use PyList_SET_ITEM() instead of PyList_SetItem(); and
Guido van Rossum <guido@python.org>
parents:
8652
diff
changeset
|
2157 PyList_SET_ITEM(x, oparg, w); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2158 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2159 PUSH(x); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2160 continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2161 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2162 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2163 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2164 case BUILD_MAP: |
|
44339
7ac117b3be37
Give meaning to the oparg for BUILD_MAP: estimated size of the dictionary.
Raymond Hettinger <python@rcn.com>
parents:
44334
diff
changeset
|
2165 x = _PyDict_NewPresized((Py_ssize_t)oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2166 PUSH(x); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2167 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2168 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2169 |
|
44334
07aa19170a67
Speed-up dictionary constructor by about 10%.
Raymond Hettinger <python@rcn.com>
parents:
44292
diff
changeset
|
2170 case STORE_MAP: |
|
07aa19170a67
Speed-up dictionary constructor by about 10%.
Raymond Hettinger <python@rcn.com>
parents:
44292
diff
changeset
|
2171 w = TOP(); /* key */ |
|
07aa19170a67
Speed-up dictionary constructor by about 10%.
Raymond Hettinger <python@rcn.com>
parents:
44292
diff
changeset
|
2172 u = SECOND(); /* value */ |
|
07aa19170a67
Speed-up dictionary constructor by about 10%.
Raymond Hettinger <python@rcn.com>
parents:
44292
diff
changeset
|
2173 v = THIRD(); /* dict */ |
|
07aa19170a67
Speed-up dictionary constructor by about 10%.
Raymond Hettinger <python@rcn.com>
parents:
44292
diff
changeset
|
2174 STACKADJ(-2); |
|
07aa19170a67
Speed-up dictionary constructor by about 10%.
Raymond Hettinger <python@rcn.com>
parents:
44292
diff
changeset
|
2175 assert (PyDict_CheckExact(v)); |
|
07aa19170a67
Speed-up dictionary constructor by about 10%.
Raymond Hettinger <python@rcn.com>
parents:
44292
diff
changeset
|
2176 err = PyDict_SetItem(v, w, u); /* v[w] = u */ |
|
07aa19170a67
Speed-up dictionary constructor by about 10%.
Raymond Hettinger <python@rcn.com>
parents:
44292
diff
changeset
|
2177 Py_DECREF(u); |
|
07aa19170a67
Speed-up dictionary constructor by about 10%.
Raymond Hettinger <python@rcn.com>
parents:
44292
diff
changeset
|
2178 Py_DECREF(w); |
|
07aa19170a67
Speed-up dictionary constructor by about 10%.
Raymond Hettinger <python@rcn.com>
parents:
44292
diff
changeset
|
2179 if (err == 0) continue; |
|
07aa19170a67
Speed-up dictionary constructor by about 10%.
Raymond Hettinger <python@rcn.com>
parents:
44292
diff
changeset
|
2180 break; |
|
07aa19170a67
Speed-up dictionary constructor by about 10%.
Raymond Hettinger <python@rcn.com>
parents:
44292
diff
changeset
|
2181 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2182 case LOAD_ATTR: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
2183 w = GETITEM(names, oparg); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2184 v = TOP(); |
| 5368 | 2185 x = PyObject_GetAttr(v, w); |
| 2186 Py_DECREF(v); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2187 SET_TOP(x); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2188 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2189 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2190 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2191 case COMPARE_OP: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2192 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2193 v = TOP(); |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
2194 if (PyInt_CheckExact(w) && PyInt_CheckExact(v)) { |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2195 /* INLINE: cmp(int, int) */ |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2196 register long a, b; |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2197 register int res; |
|
9591
7f90736701a3
Use PyInt_AS_LONG macro instead of explicit inlining.
Guido van Rossum <guido@python.org>
parents:
9513
diff
changeset
|
2198 a = PyInt_AS_LONG(v); |
|
7f90736701a3
Use PyInt_AS_LONG macro instead of explicit inlining.
Guido van Rossum <guido@python.org>
parents:
9513
diff
changeset
|
2199 b = PyInt_AS_LONG(w); |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2200 switch (oparg) { |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
2201 case PyCmp_LT: res = a < b; break; |
|
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
2202 case PyCmp_LE: res = a <= b; break; |
|
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
2203 case PyCmp_EQ: res = a == b; break; |
|
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
2204 case PyCmp_NE: res = a != b; break; |
|
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
2205 case PyCmp_GT: res = a > b; break; |
|
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
2206 case PyCmp_GE: res = a >= b; break; |
|
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
2207 case PyCmp_IS: res = v == w; break; |
|
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
2208 case PyCmp_IS_NOT: res = v != w; break; |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2209 default: goto slow_compare; |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2210 } |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2211 x = res ? Py_True : Py_False; |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2212 Py_INCREF(x); |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2213 } |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2214 else { |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2215 slow_compare: |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2216 x = cmp_outcome(oparg, v, w); |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2217 } |
| 5368 | 2218 Py_DECREF(v); |
| 2219 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2220 SET_TOP(x); |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2221 if (x == NULL) break; |
|
51920
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2222 PREDICT(POP_JUMP_IF_FALSE); |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2223 PREDICT(POP_JUMP_IF_TRUE); |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2224 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2225 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2226 case IMPORT_NAME: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
2227 w = GETITEM(names, oparg); |
| 5368 | 2228 x = PyDict_GetItemString(f->f_builtins, "__import__"); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
2229 if (x == NULL) { |
| 5368 | 2230 PyErr_SetString(PyExc_ImportError, |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
2231 "__import__ not found"); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
2232 break; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
2233 } |
| 44894 | 2234 Py_INCREF(x); |
|
36712
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2235 v = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2236 u = TOP(); |
|
36712
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2237 if (PyInt_AsLong(u) != -1 || PyErr_Occurred()) |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2238 w = PyTuple_Pack(5, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2239 w, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2240 f->f_globals, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2241 f->f_locals == NULL ? |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2242 Py_None : f->f_locals, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2243 v, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2244 u); |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2245 else |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2246 w = PyTuple_Pack(4, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2247 w, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2248 f->f_globals, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2249 f->f_locals == NULL ? |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2250 Py_None : f->f_locals, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2251 v); |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2252 Py_DECREF(v); |
| 5368 | 2253 Py_DECREF(u); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
2254 if (w == NULL) { |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2255 u = POP(); |
| 44894 | 2256 Py_DECREF(x); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
2257 x = NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
2258 break; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
2259 } |
|
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
|
2260 READ_TIMESTAMP(intr0); |
| 44894 | 2261 v = x; |
| 2262 x = PyEval_CallObject(v, w); | |
| 2263 Py_DECREF(v); | |
|
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
|
2264 READ_TIMESTAMP(intr1); |
| 5368 | 2265 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2266 SET_TOP(x); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2267 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2268 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2269 |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
2270 case IMPORT_STAR: |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
2271 v = POP(); |
| 5368 | 2272 PyFrame_FastToLocals(f); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2273 if ((x = f->f_locals) == NULL) { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2274 PyErr_SetString(PyExc_SystemError, |
|
16017
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15948
diff
changeset
|
2275 "no locals found during 'import *'"); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2276 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2277 } |
|
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
|
2278 READ_TIMESTAMP(intr0); |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
2279 err = import_all_from(x, v); |
|
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
|
2280 READ_TIMESTAMP(intr1); |
| 5368 | 2281 PyFrame_LocalsToFast(f, 0); |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
2282 Py_DECREF(v); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2283 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2284 break; |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
2285 |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
2286 case IMPORT_FROM: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
2287 w = GETITEM(names, oparg); |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
2288 v = TOP(); |
|
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
|
2289 READ_TIMESTAMP(intr0); |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
2290 x = import_from(v, w); |
|
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
|
2291 READ_TIMESTAMP(intr1); |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
2292 PUSH(x); |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
2293 if (x != NULL) continue; |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
2294 break; |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
2295 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2296 case JUMP_FORWARD: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2297 JUMPBY(oparg); |
|
29349
2f731c57cdc6
Use fast_next_opcode shortcut for forward jump opcodes (it's safe and
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
29339
diff
changeset
|
2298 goto fast_next_opcode; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2299 |
|
51920
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2300 PREDICTED_WITH_ARG(POP_JUMP_IF_FALSE); |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2301 case POP_JUMP_IF_FALSE: |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2302 w = POP(); |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2303 if (w == Py_True) { |
|
51920
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2304 Py_DECREF(w); |
|
29349
2f731c57cdc6
Use fast_next_opcode shortcut for forward jump opcodes (it's safe and
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
29339
diff
changeset
|
2305 goto fast_next_opcode; |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2306 } |
| 28077 | 2307 if (w == Py_False) { |
|
51920
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2308 Py_DECREF(w); |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2309 JUMPTO(oparg); |
|
29349
2f731c57cdc6
Use fast_next_opcode shortcut for forward jump opcodes (it's safe and
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
29339
diff
changeset
|
2310 goto fast_next_opcode; |
| 28077 | 2311 } |
| 2312 err = PyObject_IsTrue(w); | |
|
51920
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2313 Py_DECREF(w); |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2314 if (err > 0) |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2315 err = 0; |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2316 else if (err == 0) |
|
51920
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2317 JUMPTO(oparg); |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2318 else |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2319 break; |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2320 continue; |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2321 |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2322 PREDICTED_WITH_ARG(POP_JUMP_IF_TRUE); |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2323 case POP_JUMP_IF_TRUE: |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2324 w = POP(); |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2325 if (w == Py_False) { |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2326 Py_DECREF(w); |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2327 goto fast_next_opcode; |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2328 } |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2329 if (w == Py_True) { |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2330 Py_DECREF(w); |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2331 JUMPTO(oparg); |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2332 goto fast_next_opcode; |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2333 } |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2334 err = PyObject_IsTrue(w); |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2335 Py_DECREF(w); |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2336 if (err > 0) { |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2337 err = 0; |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2338 JUMPTO(oparg); |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2339 } |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2340 else if (err == 0) |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2341 ; |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2342 else |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2343 break; |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2344 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2345 |
|
51920
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2346 case JUMP_IF_FALSE_OR_POP: |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2347 w = TOP(); |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2348 if (w == Py_True) { |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2349 STACKADJ(-1); |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2350 Py_DECREF(w); |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2351 goto fast_next_opcode; |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2352 } |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2353 if (w == Py_False) { |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2354 JUMPTO(oparg); |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2355 goto fast_next_opcode; |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2356 } |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2357 err = PyObject_IsTrue(w); |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2358 if (err > 0) { |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2359 STACKADJ(-1); |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2360 Py_DECREF(w); |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2361 err = 0; |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2362 } |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2363 else if (err == 0) |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2364 JUMPTO(oparg); |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2365 else |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2366 break; |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2367 continue; |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2368 |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2369 case JUMP_IF_TRUE_OR_POP: |
| 28077 | 2370 w = TOP(); |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2371 if (w == Py_False) { |
|
51920
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2372 STACKADJ(-1); |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2373 Py_DECREF(w); |
|
29349
2f731c57cdc6
Use fast_next_opcode shortcut for forward jump opcodes (it's safe and
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
29339
diff
changeset
|
2374 goto fast_next_opcode; |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2375 } |
| 28077 | 2376 if (w == Py_True) { |
|
51920
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2377 JUMPTO(oparg); |
|
29349
2f731c57cdc6
Use fast_next_opcode shortcut for forward jump opcodes (it's safe and
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
29339
diff
changeset
|
2378 goto fast_next_opcode; |
| 28077 | 2379 } |
| 2380 err = PyObject_IsTrue(w); | |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2381 if (err > 0) { |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2382 err = 0; |
|
51920
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2383 JUMPTO(oparg); |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2384 } |
|
51920
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2385 else if (err == 0) { |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2386 STACKADJ(-1); |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2387 Py_DECREF(w); |
|
ef8fe9088696
Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51759
diff
changeset
|
2388 } |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2389 else |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2390 break; |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2391 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2392 |
|
31649
243642bbd03f
LIST_APPEND is predicably followed by JUMP_ABSOLUTE.
Raymond Hettinger <python@rcn.com>
parents:
31647
diff
changeset
|
2393 PREDICTED_WITH_ARG(JUMP_ABSOLUTE); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2394 case JUMP_ABSOLUTE: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2395 JUMPTO(oparg); |
|
43784
8fcc3f46c69d
Add build option for faster loop execution.
Raymond Hettinger <python@rcn.com>
parents:
43416
diff
changeset
|
2396 #if FAST_LOOPS |
|
8fcc3f46c69d
Add build option for faster loop execution.
Raymond Hettinger <python@rcn.com>
parents:
43416
diff
changeset
|
2397 /* Enabling this path speeds-up all while and for-loops by bypassing |
|
8fcc3f46c69d
Add build option for faster loop execution.
Raymond Hettinger <python@rcn.com>
parents:
43416
diff
changeset
|
2398 the per-loop checks for signals. By default, this should be turned-off |
|
8fcc3f46c69d
Add build option for faster loop execution.
Raymond Hettinger <python@rcn.com>
parents:
43416
diff
changeset
|
2399 because it prevents detection of a control-break in tight loops like |
|
8fcc3f46c69d
Add build option for faster loop execution.
Raymond Hettinger <python@rcn.com>
parents:
43416
diff
changeset
|
2400 "while 1: pass". Compile with this option turned-on when you need |
|
8fcc3f46c69d
Add build option for faster loop execution.
Raymond Hettinger <python@rcn.com>
parents:
43416
diff
changeset
|
2401 the speed-up and do not need break checking inside tight loops (ones |
|
48077
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
2402 that contain only instructions ending with goto fast_next_opcode). |
|
43784
8fcc3f46c69d
Add build option for faster loop execution.
Raymond Hettinger <python@rcn.com>
parents:
43416
diff
changeset
|
2403 */ |
|
8fcc3f46c69d
Add build option for faster loop execution.
Raymond Hettinger <python@rcn.com>
parents:
43416
diff
changeset
|
2404 goto fast_next_opcode; |
|
8fcc3f46c69d
Add build option for faster loop execution.
Raymond Hettinger <python@rcn.com>
parents:
43416
diff
changeset
|
2405 #else |
|
29337
f9495815c18f
Don't use fast_next_opcode for JUMP_* opcodes. This fixes the problem
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
28886
diff
changeset
|
2406 continue; |
|
43784
8fcc3f46c69d
Add build option for faster loop execution.
Raymond Hettinger <python@rcn.com>
parents:
43416
diff
changeset
|
2407 #endif |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2408 |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2409 case GET_ITER: |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2410 /* before: [obj]; after [getiter(obj)] */ |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2411 v = TOP(); |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2412 x = PyObject_GetIter(v); |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2413 Py_DECREF(v); |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2414 if (x != NULL) { |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2415 SET_TOP(x); |
|
28304
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
2416 PREDICT(FOR_ITER); |
|
17617
aac65f50df6f
Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents:
17600
diff
changeset
|
2417 continue; |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2418 } |
|
27243
3afbd55fb18f
Replaced POP() with STACKADJ(-1) on lines where the result wasn't used.
Raymond Hettinger <python@rcn.com>
parents:
27201
diff
changeset
|
2419 STACKADJ(-1); |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2420 break; |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2421 |
|
28304
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
2422 PREDICTED_WITH_ARG(FOR_ITER); |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2423 case FOR_ITER: |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2424 /* before: [iter]; after: [iter, iter()] *or* [] */ |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2425 v = TOP(); |
|
31646
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2426 x = (*v->ob_type->tp_iternext)(v); |
|
17617
aac65f50df6f
Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents:
17600
diff
changeset
|
2427 if (x != NULL) { |
|
aac65f50df6f
Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents:
17600
diff
changeset
|
2428 PUSH(x); |
|
28304
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
2429 PREDICT(STORE_FAST); |
|
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
2430 PREDICT(UNPACK_SEQUENCE); |
|
17617
aac65f50df6f
Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents:
17600
diff
changeset
|
2431 continue; |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2432 } |
|
31646
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2433 if (PyErr_Occurred()) { |
|
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
|
2434 if (!PyErr_ExceptionMatches( |
|
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
|
2435 PyExc_StopIteration)) |
|
31646
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2436 break; |
|
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2437 PyErr_Clear(); |
|
17617
aac65f50df6f
Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents:
17600
diff
changeset
|
2438 } |
|
31646
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2439 /* iterator ended normally */ |
|
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2440 x = v = POP(); |
|
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2441 Py_DECREF(v); |
|
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2442 JUMPBY(oparg); |
|
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2443 continue; |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2444 |
|
31647
d10c778af167
Move the code for BREAK and CONTINUE_LOOP to be near FOR_ITER.
Raymond Hettinger <python@rcn.com>
parents:
31646
diff
changeset
|
2445 case BREAK_LOOP: |
|
d10c778af167
Move the code for BREAK and CONTINUE_LOOP to be near FOR_ITER.
Raymond Hettinger <python@rcn.com>
parents:
31646
diff
changeset
|
2446 why = WHY_BREAK; |
|
d10c778af167
Move the code for BREAK and CONTINUE_LOOP to be near FOR_ITER.
Raymond Hettinger <python@rcn.com>
parents:
31646
diff
changeset
|
2447 goto fast_block_end; |
|
d10c778af167
Move the code for BREAK and CONTINUE_LOOP to be near FOR_ITER.
Raymond Hettinger <python@rcn.com>
parents:
31646
diff
changeset
|
2448 |
|
d10c778af167
Move the code for BREAK and CONTINUE_LOOP to be near FOR_ITER.
Raymond Hettinger <python@rcn.com>
parents:
31646
diff
changeset
|
2449 case CONTINUE_LOOP: |
|
d10c778af167
Move the code for BREAK and CONTINUE_LOOP to be near FOR_ITER.
Raymond Hettinger <python@rcn.com>
parents:
31646
diff
changeset
|
2450 retval = PyInt_FromLong(oparg); |
|
38217
2195972f7391
Fix #132 from Coverity, retval could have been derefed
Neal Norwitz <nnorwitz@gmail.com>
parents:
38134
diff
changeset
|
2451 if (!retval) { |
|
2195972f7391
Fix #132 from Coverity, retval could have been derefed
Neal Norwitz <nnorwitz@gmail.com>
parents:
38134
diff
changeset
|
2452 x = NULL; |
|
2195972f7391
Fix #132 from Coverity, retval could have been derefed
Neal Norwitz <nnorwitz@gmail.com>
parents:
38134
diff
changeset
|
2453 break; |
|
2195972f7391
Fix #132 from Coverity, retval could have been derefed
Neal Norwitz <nnorwitz@gmail.com>
parents:
38134
diff
changeset
|
2454 } |
|
31647
d10c778af167
Move the code for BREAK and CONTINUE_LOOP to be near FOR_ITER.
Raymond Hettinger <python@rcn.com>
parents:
31646
diff
changeset
|
2455 why = WHY_CONTINUE; |
|
d10c778af167
Move the code for BREAK and CONTINUE_LOOP to be near FOR_ITER.
Raymond Hettinger <python@rcn.com>
parents:
31646
diff
changeset
|
2456 goto fast_block_end; |
|
d10c778af167
Move the code for BREAK and CONTINUE_LOOP to be near FOR_ITER.
Raymond Hettinger <python@rcn.com>
parents:
31646
diff
changeset
|
2457 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2458 case SETUP_LOOP: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2459 case SETUP_EXCEPT: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2460 case SETUP_FINALLY: |
|
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
|
2461 /* NOTE: If you add any new block-setup opcodes that |
|
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
|
2462 are not try/except/finally handlers, you may need |
|
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
|
2463 to update the PyGen_NeedsFinalizing() function. |
|
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
|
2464 */ |
|
37564
c782cf6b516e
SF Patch #1463867: Improved generator finalization to allow generators
Phillip J. Eby <pje@telecommunity.com>
parents:
37286
diff
changeset
|
2465 |
| 5368 | 2466 PyFrame_BlockSetup(f, opcode, INSTR_OFFSET() + oparg, |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2467 STACK_LEVEL()); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2468 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2469 |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2470 case WITH_CLEANUP: |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2471 { |
|
45703
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2472 /* At the top of the stack are 1-3 values indicating |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2473 how/why we entered the finally clause: |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2474 - TOP = None |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2475 - (TOP, SECOND) = (WHY_{RETURN,CONTINUE}), retval |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2476 - TOP = WHY_*; no retval below it |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2477 - (TOP, SECOND, THIRD) = exc_info() |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2478 Below them is EXIT, the context.__exit__ bound method. |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2479 In the last case, we must call |
|
45703
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2480 EXIT(TOP, SECOND, THIRD) |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2481 otherwise we must call |
|
45703
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2482 EXIT(None, None, None) |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2483 |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2484 In all cases, we remove EXIT from the stack, leaving |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2485 the rest in the same order. |
|
36737
fa92fe15251a
Updates to the with-statement:
Guido van Rossum <guido@python.org>
parents:
36712
diff
changeset
|
2486 |
|
fa92fe15251a
Updates to the with-statement:
Guido van Rossum <guido@python.org>
parents:
36712
diff
changeset
|
2487 In addition, if the stack represents an exception, |
|
36926
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
2488 *and* the function call returns a 'true' value, we |
|
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
2489 "zap" this information, to prevent END_FINALLY from |
|
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
2490 re-raising the exception. (But non-local gotos |
|
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
2491 should still be resumed.) |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2492 */ |
| 38418 | 2493 |
|
45703
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2494 PyObject *exit_func; |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2495 |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2496 u = POP(); |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2497 if (u == Py_None) { |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2498 exit_func = TOP(); |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2499 SET_TOP(u); |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2500 v = w = Py_None; |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2501 } |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2502 else if (PyInt_Check(u)) { |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2503 switch(PyInt_AS_LONG(u)) { |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2504 case WHY_RETURN: |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2505 case WHY_CONTINUE: |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2506 /* Retval in TOP. */ |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2507 exit_func = SECOND(); |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2508 SET_SECOND(TOP()); |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2509 SET_TOP(u); |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2510 break; |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2511 default: |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2512 exit_func = TOP(); |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2513 SET_TOP(u); |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2514 break; |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2515 } |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2516 u = v = w = Py_None; |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2517 } |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2518 else { |
|
45703
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2519 v = TOP(); |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2520 w = SECOND(); |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2521 exit_func = THIRD(); |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2522 SET_TOP(u); |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2523 SET_SECOND(v); |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2524 SET_THIRD(w); |
|
36926
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
2525 } |
|
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
2526 /* XXX Not the fastest way to call it... */ |
|
45703
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2527 x = PyObject_CallFunctionObjArgs(exit_func, u, v, w, |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2528 NULL); |
|
50103
9a10d4404bd0
#4559: When a context manager's __exit__() method returns an object whose
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50092
diff
changeset
|
2529 Py_DECREF(exit_func); |
|
9a10d4404bd0
#4559: When a context manager's __exit__() method returns an object whose
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50092
diff
changeset
|
2530 if (x == NULL) |
|
36926
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
2531 break; /* Go to error exit */ |
|
50103
9a10d4404bd0
#4559: When a context manager's __exit__() method returns an object whose
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50092
diff
changeset
|
2532 |
|
9a10d4404bd0
#4559: When a context manager's __exit__() method returns an object whose
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50092
diff
changeset
|
2533 if (u != Py_None) |
|
9a10d4404bd0
#4559: When a context manager's __exit__() method returns an object whose
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50092
diff
changeset
|
2534 err = PyObject_IsTrue(x); |
|
9a10d4404bd0
#4559: When a context manager's __exit__() method returns an object whose
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50092
diff
changeset
|
2535 else |
|
9a10d4404bd0
#4559: When a context manager's __exit__() method returns an object whose
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50092
diff
changeset
|
2536 err = 0; |
|
9a10d4404bd0
#4559: When a context manager's __exit__() method returns an object whose
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50092
diff
changeset
|
2537 Py_DECREF(x); |
|
9a10d4404bd0
#4559: When a context manager's __exit__() method returns an object whose
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50092
diff
changeset
|
2538 |
|
9a10d4404bd0
#4559: When a context manager's __exit__() method returns an object whose
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50092
diff
changeset
|
2539 if (err < 0) |
|
9a10d4404bd0
#4559: When a context manager's __exit__() method returns an object whose
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50092
diff
changeset
|
2540 break; /* Go to error exit */ |
|
9a10d4404bd0
#4559: When a context manager's __exit__() method returns an object whose
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50092
diff
changeset
|
2541 else if (err > 0) { |
|
9a10d4404bd0
#4559: When a context manager's __exit__() method returns an object whose
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50092
diff
changeset
|
2542 err = 0; |
|
36926
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
2543 /* There was an exception and a true return */ |
|
45703
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2544 STACKADJ(-2); |
|
36737
fa92fe15251a
Updates to the with-statement:
Guido van Rossum <guido@python.org>
parents:
36712
diff
changeset
|
2545 Py_INCREF(Py_None); |
|
36926
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
2546 SET_TOP(Py_None); |
|
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
2547 Py_DECREF(u); |
|
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
2548 Py_DECREF(v); |
|
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
2549 Py_DECREF(w); |
|
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
2550 } else { |
|
45703
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2551 /* The stack was rearranged to remove EXIT |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45624
diff
changeset
|
2552 above. Let END_FINALLY do its thing */ |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2553 } |
|
45624
6068b75ec27a
compile.c always emits END_FINALLY after WITH_CLEANUP, so predict that in
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
45011
diff
changeset
|
2554 PREDICT(END_FINALLY); |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2555 break; |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2556 } |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2557 |
|
2813
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
2558 case CALL_FUNCTION: |
|
32359
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
2559 { |
|
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
2560 PyObject **sp; |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
2561 PCALL(PCALL_ALL); |
|
32359
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
2562 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
|
2563 #ifdef WITH_TSC |
|
32359
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
2564 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
|
2565 #else |
|
32359
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
2566 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
|
2567 #endif |
|
32359
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
2568 stack_pointer = sp; |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
2569 PUSH(x); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
2570 if (x != NULL) |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
2571 continue; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
2572 break; |
|
32359
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
2573 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2574 |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2575 case CALL_FUNCTION_VAR: |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2576 case CALL_FUNCTION_KW: |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2577 case CALL_FUNCTION_VAR_KW: |
|
2813
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
2578 { |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2579 int na = oparg & 0xff; |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2580 int nk = (oparg>>8) & 0xff; |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2581 int flags = (opcode - CALL_FUNCTION) & 3; |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2582 int n = na + 2 * nk; |
|
32359
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
2583 PyObject **pfunc, *func, **sp; |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
2584 PCALL(PCALL_ALL); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2585 if (flags & CALL_FLAG_VAR) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2586 n++; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2587 if (flags & CALL_FLAG_KW) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2588 n++; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2589 pfunc = stack_pointer - n - 1; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2590 func = *pfunc; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2591 |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2592 if (PyMethod_Check(func) |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2593 && PyMethod_GET_SELF(func) != NULL) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2594 PyObject *self = PyMethod_GET_SELF(func); |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2595 Py_INCREF(self); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2596 func = PyMethod_GET_FUNCTION(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2597 Py_INCREF(func); |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2598 Py_DECREF(*pfunc); |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2599 *pfunc = self; |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2600 na++; |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2601 n++; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2602 } else |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2603 Py_INCREF(func); |
|
32359
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
2604 sp = stack_pointer; |
|
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
|
2605 READ_TIMESTAMP(intr0); |
|
32359
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
2606 x = ext_do_call(func, &sp, flags, na, nk); |
|
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
|
2607 READ_TIMESTAMP(intr1); |
|
32359
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
2608 stack_pointer = sp; |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2609 Py_DECREF(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2610 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2611 while (stack_pointer > pfunc) { |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2612 w = POP(); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2613 Py_DECREF(w); |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2614 } |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2615 PUSH(x); |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2616 if (x != NULL) |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2617 continue; |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2618 break; |
|
2813
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
2619 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2620 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2621 case MAKE_FUNCTION: |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2622 v = POP(); /* code object */ |
| 5368 | 2623 x = PyFunction_New(v, f->f_globals); |
| 2624 Py_DECREF(v); | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2625 /* XXX Maybe this should be a separate opcode? */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2626 if (x != NULL && oparg > 0) { |
| 5368 | 2627 v = PyTuple_New(oparg); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2628 if (v == NULL) { |
| 5368 | 2629 Py_DECREF(x); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2630 x = NULL; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2631 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2632 } |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
2633 while (--oparg >= 0) { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2634 w = POP(); |
| 5368 | 2635 PyTuple_SET_ITEM(v, oparg, w); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2636 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2637 err = PyFunction_SetDefaults(x, v); |
| 5368 | 2638 Py_DECREF(v); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2639 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2640 PUSH(x); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2641 break; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2642 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2643 case MAKE_CLOSURE: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2644 { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2645 v = POP(); /* code object */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2646 x = PyFunction_New(v, f->f_globals); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2647 Py_DECREF(v); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
2648 if (x != NULL) { |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
2649 v = POP(); |
|
50092
dc696deb2cf2
Issue 4597: Fix several cases in EvalFrameEx where an exception could be
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49940
diff
changeset
|
2650 if (PyFunction_SetClosure(x, v) != 0) { |
|
dc696deb2cf2
Issue 4597: Fix several cases in EvalFrameEx where an exception could be
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49940
diff
changeset
|
2651 /* Can't happen unless bytecode is corrupt. */ |
|
dc696deb2cf2
Issue 4597: Fix several cases in EvalFrameEx where an exception could be
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49940
diff
changeset
|
2652 why = WHY_EXCEPTION; |
|
dc696deb2cf2
Issue 4597: Fix several cases in EvalFrameEx where an exception could be
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49940
diff
changeset
|
2653 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2654 Py_DECREF(v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2655 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2656 if (x != NULL && oparg > 0) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2657 v = PyTuple_New(oparg); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2658 if (v == NULL) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2659 Py_DECREF(x); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2660 x = NULL; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2661 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2662 } |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
2663 while (--oparg >= 0) { |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2664 w = POP(); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2665 PyTuple_SET_ITEM(v, oparg, w); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2666 } |
|
50092
dc696deb2cf2
Issue 4597: Fix several cases in EvalFrameEx where an exception could be
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49940
diff
changeset
|
2667 if (PyFunction_SetDefaults(x, v) != 0) { |
|
dc696deb2cf2
Issue 4597: Fix several cases in EvalFrameEx where an exception could be
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49940
diff
changeset
|
2668 /* Can't happen unless |
|
dc696deb2cf2
Issue 4597: Fix several cases in EvalFrameEx where an exception could be
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49940
diff
changeset
|
2669 PyFunction_SetDefaults changes. */ |
|
dc696deb2cf2
Issue 4597: Fix several cases in EvalFrameEx where an exception could be
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49940
diff
changeset
|
2670 why = WHY_EXCEPTION; |
|
dc696deb2cf2
Issue 4597: Fix several cases in EvalFrameEx where an exception could be
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49940
diff
changeset
|
2671 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2672 Py_DECREF(v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2673 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2674 PUSH(x); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2675 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2676 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2677 |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2678 case BUILD_SLICE: |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2679 if (oparg == 3) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2680 w = POP(); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2681 else |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2682 w = NULL; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2683 v = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2684 u = TOP(); |
| 5018 | 2685 x = PySlice_New(u, v, w); |
| 5368 | 2686 Py_DECREF(u); |
| 2687 Py_DECREF(v); | |
| 2688 Py_XDECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2689 SET_TOP(x); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2690 if (x != NULL) continue; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2691 break; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2692 |
|
14147
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
2693 case EXTENDED_ARG: |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
2694 opcode = NEXTOP(); |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
2695 oparg = oparg<<16 | NEXTARG(); |
|
14147
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
2696 goto dispatch_opcode; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2697 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2698 default: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2699 fprintf(stderr, |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2700 "XXX lineno: %d, opcode: %d\n", |
|
53931
9ef683d41c9b
Issue 5954, PyFrame_GetLineNumber:
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51920
diff
changeset
|
2701 PyFrame_GetLineNumber(f), |
| 24844 | 2702 opcode); |
| 5368 | 2703 PyErr_SetString(PyExc_SystemError, "unknown opcode"); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2704 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2705 break; |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2706 |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2707 #ifdef CASE_TOO_BIG |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2708 } |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2709 #endif |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2710 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2711 } /* switch */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2712 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2713 on_error: |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2714 |
|
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
|
2715 READ_TIMESTAMP(inst1); |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
2716 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2717 /* Quickly continue if no error occurred */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2718 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2719 if (why == WHY_NOT) { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2720 if (err == 0 && x != NULL) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2721 #ifdef CHECKEXC |
|
10363
4daab7a9f566
Always test for an error return (usually NULL or -1) without setting
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
2722 /* This check is expensive! */ |
| 5368 | 2723 if (PyErr_Occurred()) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2724 fprintf(stderr, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2725 "XXX undetected error\n"); |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
2726 else { |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
2727 #endif |
|
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
|
2728 READ_TIMESTAMP(loop1); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2729 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
|
2730 #ifdef CHECKEXC |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
2731 } |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
2732 #endif |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2733 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2734 why = WHY_EXCEPTION; |
| 5368 | 2735 x = Py_None; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2736 err = 0; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2737 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2738 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2739 /* Double-check exception status */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2740 |
|
31900
0265bf9912ea
Some (but not all) of the why code bitfield tests ran faster as
Raymond Hettinger <python@rcn.com>
parents:
31894
diff
changeset
|
2741 if (why == WHY_EXCEPTION || why == WHY_RERAISE) { |
| 5368 | 2742 if (!PyErr_Occurred()) { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2743 PyErr_SetString(PyExc_SystemError, |
|
10363
4daab7a9f566
Always test for an error return (usually NULL or -1) without setting
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
2744 "error return without exception set"); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2745 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2746 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2747 } |
|
10363
4daab7a9f566
Always test for an error return (usually NULL or -1) without setting
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
2748 #ifdef CHECKEXC |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2749 else { |
|
10363
4daab7a9f566
Always test for an error return (usually NULL or -1) without setting
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
2750 /* This check is expensive! */ |
| 5368 | 2751 if (PyErr_Occurred()) { |
|
45011
a3d5700b1d5a
Reduce buffer size since we do not need 1k
Neal Norwitz <nnorwitz@gmail.com>
parents:
44894
diff
changeset
|
2752 char buf[128]; |
|
30861
c89fd7eaf875
Make undetected error on stack unwind a fatal error.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
30801
diff
changeset
|
2753 sprintf(buf, "Stack unwind with exception " |
|
c89fd7eaf875
Make undetected error on stack unwind a fatal error.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
30801
diff
changeset
|
2754 "set and why=%d", why); |
|
c89fd7eaf875
Make undetected error on stack unwind a fatal error.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
30801
diff
changeset
|
2755 Py_FatalError(buf); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2756 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2757 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2758 #endif |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2759 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2760 /* Log traceback info if this is a real exception */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2761 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2762 if (why == WHY_EXCEPTION) { |
| 5368 | 2763 PyTraceBack_Here(f); |
| 567 | 2764 |
|
20247
a4d328d50897
Rationalize the events passed to the profiler (no changes for the tracer).
Fred Drake <fdrake@acm.org>
parents:
20183
diff
changeset
|
2765 if (tstate->c_tracefunc != NULL) |
|
a4d328d50897
Rationalize the events passed to the profiler (no changes for the tracer).
Fred Drake <fdrake@acm.org>
parents:
20183
diff
changeset
|
2766 call_exc_trace(tstate->c_tracefunc, |
|
a4d328d50897
Rationalize the events passed to the profiler (no changes for the tracer).
Fred Drake <fdrake@acm.org>
parents:
20183
diff
changeset
|
2767 tstate->c_traceobj, f); |
|
9513
350f24180dcb
Whoops! One the "redundant" initializations removed by Vladimir in
Guido van Rossum <guido@python.org>
parents:
9490
diff
changeset
|
2768 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2769 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2770 /* For the rest, treat WHY_RERAISE as WHY_EXCEPTION */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2771 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2772 if (why == WHY_RERAISE) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2773 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2774 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2775 /* Unwind stacks if a (pseudo) exception occurred */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2776 |
|
31462
d5c047807c69
SF patch #864059: optimize eval_frame
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2777 fast_block_end: |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
2778 while (why != WHY_NOT && f->f_iblock > 0) { |
| 5368 | 2779 PyTryBlock *b = PyFrame_BlockPop(f); |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2780 |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
2781 assert(why != WHY_YIELD); |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2782 if (b->b_type == SETUP_LOOP && why == WHY_CONTINUE) { |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2783 /* For a continue inside a try block, |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2784 don't pop the block for the loop. */ |
|
20064
ef3034a60a3e
Don't swap the arguments to PyFrame_BlockSetup when recreating the recently
Thomas Wouters <thomas@python.org>
parents:
20012
diff
changeset
|
2785 PyFrame_BlockSetup(f, b->b_type, b->b_handler, |
|
ef3034a60a3e
Don't swap the arguments to PyFrame_BlockSetup when recreating the recently
Thomas Wouters <thomas@python.org>
parents:
20012
diff
changeset
|
2786 b->b_level); |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2787 why = WHY_NOT; |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2788 JUMPTO(PyInt_AS_LONG(retval)); |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2789 Py_DECREF(retval); |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2790 break; |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2791 } |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2792 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2793 while (STACK_LEVEL() > b->b_level) { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2794 v = POP(); |
| 5368 | 2795 Py_XDECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2796 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2797 if (b->b_type == SETUP_LOOP && why == WHY_BREAK) { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2798 why = WHY_NOT; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2799 JUMPTO(b->b_handler); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2800 break; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2801 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2802 if (b->b_type == SETUP_FINALLY || |
|
4594
41857075d45b
Change the Don Beaudry hack into the Don B + Jim F hack; now, if *any*
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
2803 (b->b_type == SETUP_EXCEPT && |
|
41857075d45b
Change the Don Beaudry hack into the Don B + Jim F hack; now, if *any*
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
2804 why == WHY_EXCEPTION)) { |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2805 if (why == WHY_EXCEPTION) { |
| 5368 | 2806 PyObject *exc, *val, *tb; |
| 2807 PyErr_Fetch(&exc, &val, &tb); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2808 if (val == NULL) { |
| 5368 | 2809 val = Py_None; |
| 2810 Py_INCREF(val); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2811 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2812 /* Make the raw exception data |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2813 available to the handler, |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2814 so a program can emulate the |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2815 Python main loop. Don't do |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2816 this for 'finally'. */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2817 if (b->b_type == SETUP_EXCEPT) { |
|
6185
32aacd753f34
eval_code2(), set_exc_info(): Call PyErr_NormalizeException() the
Barry Warsaw <barry@python.org>
parents:
6160
diff
changeset
|
2818 PyErr_NormalizeException( |
|
32aacd753f34
eval_code2(), set_exc_info(): Call PyErr_NormalizeException() the
Barry Warsaw <barry@python.org>
parents:
6160
diff
changeset
|
2819 &exc, &val, &tb); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2820 set_exc_info(tstate, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2821 exc, val, tb); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2822 } |
|
20114
233f9606ba8e
Prevent a NULL pointer from being pushed onto the stack.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20064
diff
changeset
|
2823 if (tb == NULL) { |
|
233f9606ba8e
Prevent a NULL pointer from being pushed onto the stack.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20064
diff
changeset
|
2824 Py_INCREF(Py_None); |
|
233f9606ba8e
Prevent a NULL pointer from being pushed onto the stack.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20064
diff
changeset
|
2825 PUSH(Py_None); |
|
233f9606ba8e
Prevent a NULL pointer from being pushed onto the stack.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20064
diff
changeset
|
2826 } else |
|
233f9606ba8e
Prevent a NULL pointer from being pushed onto the stack.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20064
diff
changeset
|
2827 PUSH(tb); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2828 PUSH(val); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2829 PUSH(exc); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2830 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2831 else { |
|
31874
c88d4610f283
Coded WHY flags as bitfields (taking inspiration from tp_flags).
Raymond Hettinger <python@rcn.com>
parents:
31872
diff
changeset
|
2832 if (why & (WHY_RETURN | WHY_CONTINUE)) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2833 PUSH(retval); |
| 5368 | 2834 v = PyInt_FromLong((long)why); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2835 PUSH(v); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2836 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2837 why = WHY_NOT; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2838 JUMPTO(b->b_handler); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2839 break; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2840 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2841 } /* unwind stack */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2842 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2843 /* End the loop if we still have an error (or return) */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2844 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2845 if (why != WHY_NOT) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2846 break; |
|
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
|
2847 READ_TIMESTAMP(loop1); |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2848 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2849 } /* main loop */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2850 |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
2851 assert(why != WHY_YIELD); |
|
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
2852 /* Pop remaining stack entries. */ |
|
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
2853 while (!EMPTY()) { |
|
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
2854 v = POP(); |
|
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
2855 Py_XDECREF(v); |
|
21270
97709fd8fda0
Fix for SF bug #489671 (Neil Norwitz): memory leak in test_richcmp.
Guido van Rossum <guido@python.org>
parents:
21252
diff
changeset
|
2856 } |
|
97709fd8fda0
Fix for SF bug #489671 (Neil Norwitz): memory leak in test_richcmp.
Guido van Rossum <guido@python.org>
parents:
21252
diff
changeset
|
2857 |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
2858 if (why != WHY_RETURN) |
| 567 | 2859 retval = NULL; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2860 |
|
31462
d5c047807c69
SF patch #864059: optimize eval_frame
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2861 fast_yield: |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2862 if (tstate->use_tracing) { |
|
35345
700f08369092
Port from the Python 2.4 branch, patches for SF bug # 900092,
Barry Warsaw <barry@python.org>
parents:
35298
diff
changeset
|
2863 if (tstate->c_tracefunc) { |
|
700f08369092
Port from the Python 2.4 branch, patches for SF bug # 900092,
Barry Warsaw <barry@python.org>
parents:
35298
diff
changeset
|
2864 if (why == WHY_RETURN || why == WHY_YIELD) { |
|
700f08369092
Port from the Python 2.4 branch, patches for SF bug # 900092,
Barry Warsaw <barry@python.org>
parents:
35298
diff
changeset
|
2865 if (call_trace(tstate->c_tracefunc, |
|
700f08369092
Port from the Python 2.4 branch, patches for SF bug # 900092,
Barry Warsaw <barry@python.org>
parents:
35298
diff
changeset
|
2866 tstate->c_traceobj, f, |
|
700f08369092
Port from the Python 2.4 branch, patches for SF bug # 900092,
Barry Warsaw <barry@python.org>
parents:
35298
diff
changeset
|
2867 PyTrace_RETURN, retval)) { |
|
700f08369092
Port from the Python 2.4 branch, patches for SF bug # 900092,
Barry Warsaw <barry@python.org>
parents:
35298
diff
changeset
|
2868 Py_XDECREF(retval); |
|
700f08369092
Port from the Python 2.4 branch, patches for SF bug # 900092,
Barry Warsaw <barry@python.org>
parents:
35298
diff
changeset
|
2869 retval = NULL; |
|
700f08369092
Port from the Python 2.4 branch, patches for SF bug # 900092,
Barry Warsaw <barry@python.org>
parents:
35298
diff
changeset
|
2870 why = WHY_EXCEPTION; |
|
700f08369092
Port from the Python 2.4 branch, patches for SF bug # 900092,
Barry Warsaw <barry@python.org>
parents:
35298
diff
changeset
|
2871 } |
|
700f08369092
Port from the Python 2.4 branch, patches for SF bug # 900092,
Barry Warsaw <barry@python.org>
parents:
35298
diff
changeset
|
2872 } |
|
700f08369092
Port from the Python 2.4 branch, patches for SF bug # 900092,
Barry Warsaw <barry@python.org>
parents:
35298
diff
changeset
|
2873 else if (why == WHY_EXCEPTION) { |
|
700f08369092
Port from the Python 2.4 branch, patches for SF bug # 900092,
Barry Warsaw <barry@python.org>
parents:
35298
diff
changeset
|
2874 call_trace_protected(tstate->c_tracefunc, |
|
700f08369092
Port from the Python 2.4 branch, patches for SF bug # 900092,
Barry Warsaw <barry@python.org>
parents:
35298
diff
changeset
|
2875 tstate->c_traceobj, f, |
|
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
|
2876 PyTrace_RETURN, NULL); |
| 567 | 2877 } |
| 2878 } | |
|
20247
a4d328d50897
Rationalize the events passed to the profiler (no changes for the tracer).
Fred Drake <fdrake@acm.org>
parents:
20183
diff
changeset
|
2879 if (tstate->c_profilefunc) { |
|
20257
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2880 if (why == WHY_EXCEPTION) |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2881 call_trace_protected(tstate->c_profilefunc, |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2882 tstate->c_profileobj, f, |
|
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
|
2883 PyTrace_RETURN, NULL); |
|
20257
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2884 else if (call_trace(tstate->c_profilefunc, |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2885 tstate->c_profileobj, f, |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2886 PyTrace_RETURN, retval)) { |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2887 Py_XDECREF(retval); |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2888 retval = NULL; |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2889 why = WHY_EXCEPTION; |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2890 } |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
2891 } |
| 567 | 2892 } |
|
5023
75c1ee882a4a
Kill all local variables on function return. This closes a gigantic
Guido van Rossum <guido@python.org>
parents:
5021
diff
changeset
|
2893 |
| 38418 | 2894 if (tstate->frame->f_exc_type != NULL) |
| 2895 reset_exc_info(tstate); | |
| 2896 else { | |
| 2897 assert(tstate->frame->f_exc_value == NULL); | |
| 2898 assert(tstate->frame->f_exc_traceback == NULL); | |
| 2899 } | |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2900 |
|
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
|
2901 /* pop frame */ |
| 43408 | 2902 exit_eval_frame: |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
2903 Py_LeaveRecursiveCall(); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2904 tstate->frame = f->f_back; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2905 |
| 567 | 2906 return retval; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2907 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2908 |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2909 /* 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
|
2910 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
|
2911 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
|
2912 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
2913 PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
2914 PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals, |
|
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
|
2915 PyObject **args, int argcount, PyObject **kws, int kwcount, |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2916 PyObject **defs, int defcount, PyObject *closure) |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2917 { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2918 register PyFrameObject *f; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2919 register PyObject *retval = NULL; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2920 register PyObject **fastlocals, **freevars; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2921 PyThreadState *tstate = PyThreadState_GET(); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2922 PyObject *x, *u; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2923 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2924 if (globals == NULL) { |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
2925 PyErr_SetString(PyExc_SystemError, |
|
19198
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19158
diff
changeset
|
2926 "PyEval_EvalCodeEx: NULL globals"); |
|
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
|
2927 return NULL; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2928 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2929 |
|
39466
c7ff02c1559f
Move/copy assert for tstate != NULL before first use.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39463
diff
changeset
|
2930 assert(tstate != NULL); |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
2931 assert(globals != NULL); |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
2932 f = PyFrame_New(tstate, co, globals, locals); |
|
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
|
2933 if (f == NULL) |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2934 return NULL; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2935 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2936 fastlocals = f->f_localsplus; |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38217
diff
changeset
|
2937 freevars = f->f_localsplus + co->co_nlocals; |
|
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
|
2938 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2939 if (co->co_argcount > 0 || |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2940 co->co_flags & (CO_VARARGS | CO_VARKEYWORDS)) { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2941 int i; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2942 int n = argcount; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2943 PyObject *kwdict = NULL; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2944 if (co->co_flags & CO_VARKEYWORDS) { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2945 kwdict = PyDict_New(); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2946 if (kwdict == NULL) |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2947 goto fail; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2948 i = co->co_argcount; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2949 if (co->co_flags & CO_VARARGS) |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2950 i++; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2951 SETLOCAL(i, kwdict); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2952 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2953 if (argcount > co->co_argcount) { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2954 if (!(co->co_flags & CO_VARARGS)) { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2955 PyErr_Format(PyExc_TypeError, |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2956 "%.200s() takes %s %d " |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2957 "%sargument%s (%d given)", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2958 PyString_AsString(co->co_name), |
|
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
|
2959 defcount ? "at most" : "exactly", |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2960 co->co_argcount, |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2961 kwcount ? "non-keyword " : "", |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2962 co->co_argcount == 1 ? "" : "s", |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2963 argcount); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2964 goto fail; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2965 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2966 n = co->co_argcount; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2967 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2968 for (i = 0; i < n; i++) { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2969 x = args[i]; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2970 Py_INCREF(x); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2971 SETLOCAL(i, x); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2972 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2973 if (co->co_flags & CO_VARARGS) { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2974 u = PyTuple_New(argcount - n); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2975 if (u == NULL) |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2976 goto fail; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2977 SETLOCAL(co->co_argcount, u); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2978 for (i = n; i < argcount; i++) { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2979 x = args[i]; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2980 Py_INCREF(x); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2981 PyTuple_SET_ITEM(u, i-n, x); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2982 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2983 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2984 for (i = 0; i < kwcount; i++) { |
|
48077
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
2985 PyObject **co_varnames; |
|
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
|
2986 PyObject *keyword = kws[2*i]; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2987 PyObject *value = kws[2*i + 1]; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2988 int j; |
|
51032
551257c8058a
fix building the core with --disable-unicode
Benjamin Peterson <benjamin@python.org>
parents:
50936
diff
changeset
|
2989 if (keyword == NULL || !(PyString_Check(keyword) |
|
551257c8058a
fix building the core with --disable-unicode
Benjamin Peterson <benjamin@python.org>
parents:
50936
diff
changeset
|
2990 #ifdef Py_USING_UNICODE |
|
551257c8058a
fix building the core with --disable-unicode
Benjamin Peterson <benjamin@python.org>
parents:
50936
diff
changeset
|
2991 || PyUnicode_Check(keyword) |
|
551257c8058a
fix building the core with --disable-unicode
Benjamin Peterson <benjamin@python.org>
parents:
50936
diff
changeset
|
2992 #endif |
|
551257c8058a
fix building the core with --disable-unicode
Benjamin Peterson <benjamin@python.org>
parents:
50936
diff
changeset
|
2993 )) { |
|
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
|
2994 PyErr_Format(PyExc_TypeError, |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2995 "%.200s() keywords must be strings", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2996 PyString_AsString(co->co_name)); |
|
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
|
2997 goto fail; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2998 } |
|
48077
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
2999 /* Speed hack: do raw pointer compares. As names are |
|
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
3000 normally interned this should almost always hit. */ |
|
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
3001 co_varnames = PySequence_Fast_ITEMS(co->co_varnames); |
|
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
|
3002 for (j = 0; j < co->co_argcount; j++) { |
|
48077
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
3003 PyObject *nm = co_varnames[j]; |
|
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
3004 if (nm == keyword) |
|
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
3005 goto kw_found; |
|
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
3006 } |
|
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
3007 /* Slow fallback, just in case */ |
|
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
3008 for (j = 0; j < co->co_argcount; j++) { |
|
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
3009 PyObject *nm = co_varnames[j]; |
|
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
|
3010 int cmp = PyObject_RichCompareBool( |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3011 keyword, nm, Py_EQ); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3012 if (cmp > 0) |
|
48077
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
3013 goto kw_found; |
|
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
|
3014 else if (cmp < 0) |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3015 goto fail; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3016 } |
|
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 /* Check errors from Compare */ |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3018 if (PyErr_Occurred()) |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3019 goto fail; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3020 if (j >= co->co_argcount) { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3021 if (kwdict == NULL) { |
|
50936
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3022 PyObject *kwd_str = kwd_as_string(keyword); |
|
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3023 if (kwd_str) { |
|
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3024 PyErr_Format(PyExc_TypeError, |
|
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3025 "%.200s() got an unexpected " |
|
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3026 "keyword argument '%.400s'", |
|
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3027 PyString_AsString(co->co_name), |
|
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3028 PyString_AsString(kwd_str)); |
|
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3029 Py_DECREF(kwd_str); |
|
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3030 } |
|
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
|
3031 goto fail; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3032 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3033 PyDict_SetItem(kwdict, keyword, value); |
|
48077
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
3034 continue; |
|
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
|
3035 } |
|
48077
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
3036 kw_found: |
|
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
3037 if (GETLOCAL(j) != NULL) { |
|
50936
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3038 PyObject *kwd_str = kwd_as_string(keyword); |
|
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3039 if (kwd_str) { |
|
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3040 PyErr_Format(PyExc_TypeError, |
|
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3041 "%.200s() got multiple " |
|
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3042 "values for keyword " |
|
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3043 "argument '%.400s'", |
|
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3044 PyString_AsString(co->co_name), |
|
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3045 PyString_AsString(kwd_str)); |
|
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3046 Py_DECREF(kwd_str); |
|
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3047 } |
|
48077
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
3048 goto fail; |
|
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
|
3049 } |
|
48077
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
3050 Py_INCREF(value); |
|
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
3051 SETLOCAL(j, value); |
|
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
|
3052 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3053 if (argcount < co->co_argcount) { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3054 int m = co->co_argcount - defcount; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3055 for (i = argcount; i < m; i++) { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3056 if (GETLOCAL(i) == NULL) { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3057 PyErr_Format(PyExc_TypeError, |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3058 "%.200s() takes %s %d " |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3059 "%sargument%s (%d given)", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
3060 PyString_AsString(co->co_name), |
|
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
|
3061 ((co->co_flags & CO_VARARGS) || |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3062 defcount) ? "at least" |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3063 : "exactly", |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3064 m, kwcount ? "non-keyword " : "", |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3065 m == 1 ? "" : "s", i); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3066 goto fail; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3067 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3068 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3069 if (n > m) |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3070 i = n - m; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3071 else |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3072 i = 0; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3073 for (; i < defcount; i++) { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3074 if (GETLOCAL(m+i) == NULL) { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3075 PyObject *def = defs[i]; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3076 Py_INCREF(def); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3077 SETLOCAL(m+i, def); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3078 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3079 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3080 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3081 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3082 else { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3083 if (argcount > 0 || kwcount > 0) { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3084 PyErr_Format(PyExc_TypeError, |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3085 "%.200s() takes no arguments (%d given)", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
3086 PyString_AsString(co->co_name), |
|
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
|
3087 argcount + kwcount); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3088 goto fail; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3089 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3090 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3091 /* Allocate and initialize storage for cell vars, and copy free |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3092 vars into frame. This isn't too efficient right now. */ |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38217
diff
changeset
|
3093 if (PyTuple_GET_SIZE(co->co_cellvars)) { |
|
38768
a91e739ce333
i and j are initialized below when used. No need to do it twice
Neal Norwitz <nnorwitz@gmail.com>
parents:
38766
diff
changeset
|
3094 int i, j, nargs, found; |
|
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
|
3095 char *cellname, *argname; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3096 PyObject *c; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3097 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3098 nargs = co->co_argcount; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3099 if (co->co_flags & CO_VARARGS) |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3100 nargs++; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3101 if (co->co_flags & CO_VARKEYWORDS) |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3102 nargs++; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3103 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
3104 /* Initialize each cell var, taking into account |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
3105 cell vars that are initialized from arguments. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
3106 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
3107 Should arrange for the compiler to put cellvars |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
3108 that are arguments at the beginning of the cellvars |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
3109 list so that we can march over it more efficiently? |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
3110 */ |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38217
diff
changeset
|
3111 for (i = 0; i < PyTuple_GET_SIZE(co->co_cellvars); ++i) { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
3112 cellname = PyString_AS_STRING( |
|
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
|
3113 PyTuple_GET_ITEM(co->co_cellvars, i)); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3114 found = 0; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
3115 for (j = 0; j < nargs; j++) { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
3116 argname = PyString_AS_STRING( |
|
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
|
3117 PyTuple_GET_ITEM(co->co_varnames, j)); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3118 if (strcmp(cellname, argname) == 0) { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3119 c = PyCell_New(GETLOCAL(j)); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3120 if (c == NULL) |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3121 goto fail; |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38217
diff
changeset
|
3122 GETLOCAL(co->co_nlocals + i) = c; |
|
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
|
3123 found = 1; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3124 break; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3125 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3126 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3127 if (found == 0) { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3128 c = PyCell_New(NULL); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3129 if (c == NULL) |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3130 goto fail; |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38217
diff
changeset
|
3131 SETLOCAL(co->co_nlocals + i, c); |
|
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
|
3132 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3133 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3134 } |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38217
diff
changeset
|
3135 if (PyTuple_GET_SIZE(co->co_freevars)) { |
|
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
|
3136 int i; |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38217
diff
changeset
|
3137 for (i = 0; i < PyTuple_GET_SIZE(co->co_freevars); ++i) { |
|
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
|
3138 PyObject *o = PyTuple_GET_ITEM(closure, i); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3139 Py_INCREF(o); |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38217
diff
changeset
|
3140 freevars[PyTuple_GET_SIZE(co->co_cellvars) + i] = o; |
|
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
|
3141 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3142 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3143 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3144 if (co->co_flags & CO_GENERATOR) { |
|
18194
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
3145 /* Don't need to keep the reference to f_back, it will be set |
|
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
3146 * when the generator is resumed. */ |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3147 Py_XDECREF(f->f_back); |
|
18194
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
3148 f->f_back = NULL; |
|
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
3149 |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3150 PCALL(PCALL_GENERATOR); |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3151 |
|
18194
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
3152 /* Create a new generator that owns the ready to run frame |
|
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
3153 * and return that as the value. */ |
|
32175
8ee5a56b8031
Patch #957398: Add public API for Generator Object/Type.
Martin v. Löwis <martin@v.loewis.de>
parents:
31900
diff
changeset
|
3154 return PyGen_New(f); |
|
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
|
3155 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3156 |
| 43408 | 3157 retval = PyEval_EvalFrameEx(f,0); |
| 3158 | |
| 3159 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
|
3160 |
|
21058
9df82c13c675
SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents:
21027
diff
changeset
|
3161 /* decref'ing the frame can cause __del__ methods to get invoked, |
|
9df82c13c675
SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents:
21027
diff
changeset
|
3162 which can call back into Python. While we're done with the |
|
9df82c13c675
SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents:
21027
diff
changeset
|
3163 current Python frame (f), the associated C stack is still in use, |
|
9df82c13c675
SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents:
21027
diff
changeset
|
3164 so recursion_depth must be boosted for the duration. |
|
9df82c13c675
SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents:
21027
diff
changeset
|
3165 */ |
|
9df82c13c675
SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents:
21027
diff
changeset
|
3166 assert(tstate != NULL); |
|
9df82c13c675
SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents:
21027
diff
changeset
|
3167 ++tstate->recursion_depth; |
| 43408 | 3168 Py_DECREF(f); |
|
21058
9df82c13c675
SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents:
21027
diff
changeset
|
3169 --tstate->recursion_depth; |
|
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
|
3170 return retval; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3171 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3172 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3173 |
|
51032
551257c8058a
fix building the core with --disable-unicode
Benjamin Peterson <benjamin@python.org>
parents:
50936
diff
changeset
|
3174 |
|
50936
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3175 static PyObject * |
|
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3176 kwd_as_string(PyObject *kwd) { |
|
51032
551257c8058a
fix building the core with --disable-unicode
Benjamin Peterson <benjamin@python.org>
parents:
50936
diff
changeset
|
3177 #ifdef Py_USING_UNICODE |
|
50936
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3178 if (PyString_Check(kwd)) { |
|
51032
551257c8058a
fix building the core with --disable-unicode
Benjamin Peterson <benjamin@python.org>
parents:
50936
diff
changeset
|
3179 #else |
|
551257c8058a
fix building the core with --disable-unicode
Benjamin Peterson <benjamin@python.org>
parents:
50936
diff
changeset
|
3180 assert(PyString_Check(kwd)); |
|
551257c8058a
fix building the core with --disable-unicode
Benjamin Peterson <benjamin@python.org>
parents:
50936
diff
changeset
|
3181 #endif |
|
50936
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3182 Py_INCREF(kwd); |
|
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3183 return kwd; |
|
51032
551257c8058a
fix building the core with --disable-unicode
Benjamin Peterson <benjamin@python.org>
parents:
50936
diff
changeset
|
3184 #ifdef Py_USING_UNICODE |
|
50936
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3185 } |
|
51032
551257c8058a
fix building the core with --disable-unicode
Benjamin Peterson <benjamin@python.org>
parents:
50936
diff
changeset
|
3186 return _PyUnicode_AsDefaultEncodedString(kwd, "replace"); |
|
551257c8058a
fix building the core with --disable-unicode
Benjamin Peterson <benjamin@python.org>
parents:
50936
diff
changeset
|
3187 #endif |
|
50936
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3188 } |
|
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3189 |
|
dbc14acdde37
allow unicode keyword arguments for the ** syntax #4978
Benjamin Peterson <benjamin@python.org>
parents:
50674
diff
changeset
|
3190 |
|
28121
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3191 /* 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
|
3192 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3193 - 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
|
3194 '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
|
3195 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3196 - 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
|
3197 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
|
3198 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3199 - 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
|
3200 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
|
3201 can pick it up. This is the primary task of set_exc_info(). |
| 38418 | 3202 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
|
3203 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3204 - 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
|
3205 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3206 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
|
3207 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
|
3208 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
|
3209 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
|
3210 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
|
3211 this: |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3212 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3213 try: |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3214 "something that may fail" |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3215 except "some exception": |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3216 "do something else first" |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3217 "print the exception from sys.exc_ZZZ." |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3218 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3219 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
|
3220 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
|
3221 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
|
3222 follows: |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3223 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3224 - 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
|
3225 *in that frame*. |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3226 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3227 - 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
|
3228 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
|
3229 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
|
3230 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3231 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
|
3232 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
|
3233 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
|
3234 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
|
3235 (Example: traceback.print_exc()). |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3236 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3237 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
|
3238 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
|
3239 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
|
3240 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3241 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
|
3242 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
|
3243 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
|
3244 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
|
3245 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
|
3246 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
|
3247 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
|
3248 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
|
3249 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
|
3250 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3251 */ |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3252 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
3253 static void |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3254 set_exc_info(PyThreadState *tstate, |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3255 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
|
3256 { |
| 38418 | 3257 PyFrameObject *frame = tstate->frame; |
|
5557
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
3258 PyObject *tmp_type, *tmp_value, *tmp_tb; |
|
6147
b76a44163e0f
cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents:
6139
diff
changeset
|
3259 |
| 38418 | 3260 assert(type != NULL); |
| 3261 assert(frame != NULL); | |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3262 if (frame->f_exc_type == NULL) { |
| 38418 | 3263 assert(frame->f_exc_value == NULL); |
| 3264 assert(frame->f_exc_traceback == NULL); | |
| 3265 /* This frame didn't catch an exception before. */ | |
| 3266 /* Save previous exception of this thread in this frame. */ | |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3267 if (tstate->exc_type == NULL) { |
| 38418 | 3268 /* XXX Why is this set to Py_None? */ |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3269 Py_INCREF(Py_None); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3270 tstate->exc_type = Py_None; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3271 } |
| 38418 | 3272 Py_INCREF(tstate->exc_type); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3273 Py_XINCREF(tstate->exc_value); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3274 Py_XINCREF(tstate->exc_traceback); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3275 frame->f_exc_type = tstate->exc_type; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3276 frame->f_exc_value = tstate->exc_value; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3277 frame->f_exc_traceback = tstate->exc_traceback; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3278 } |
| 38418 | 3279 /* Set new exception for this thread. */ |
|
5557
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
3280 tmp_type = tstate->exc_type; |
|
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
3281 tmp_value = tstate->exc_value; |
|
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
3282 tmp_tb = tstate->exc_traceback; |
| 38418 | 3283 Py_INCREF(type); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3284 Py_XINCREF(value); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3285 Py_XINCREF(tb); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3286 tstate->exc_type = type; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3287 tstate->exc_value = value; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3288 tstate->exc_traceback = tb; |
|
5557
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
3289 Py_XDECREF(tmp_type); |
|
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
3290 Py_XDECREF(tmp_value); |
|
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
3291 Py_XDECREF(tmp_tb); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3292 /* For b/w compatibility */ |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3293 PySys_SetObject("exc_type", type); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3294 PySys_SetObject("exc_value", value); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3295 PySys_SetObject("exc_traceback", tb); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3296 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3297 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
3298 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3299 reset_exc_info(PyThreadState *tstate) |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3300 { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3301 PyFrameObject *frame; |
|
5557
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
3302 PyObject *tmp_type, *tmp_value, *tmp_tb; |
| 38418 | 3303 |
| 3304 /* It's a precondition that the thread state's frame caught an | |
| 3305 * exception -- verify in a debug build. | |
| 3306 */ | |
| 3307 assert(tstate != NULL); | |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3308 frame = tstate->frame; |
| 38418 | 3309 assert(frame != NULL); |
| 3310 assert(frame->f_exc_type != NULL); | |
| 3311 | |
| 3312 /* Copy the frame's exception info back to the thread state. */ | |
| 3313 tmp_type = tstate->exc_type; | |
| 3314 tmp_value = tstate->exc_value; | |
| 3315 tmp_tb = tstate->exc_traceback; | |
| 3316 Py_INCREF(frame->f_exc_type); | |
| 3317 Py_XINCREF(frame->f_exc_value); | |
| 3318 Py_XINCREF(frame->f_exc_traceback); | |
| 3319 tstate->exc_type = frame->f_exc_type; | |
| 3320 tstate->exc_value = frame->f_exc_value; | |
| 3321 tstate->exc_traceback = frame->f_exc_traceback; | |
| 3322 Py_XDECREF(tmp_type); | |
| 3323 Py_XDECREF(tmp_value); | |
| 3324 Py_XDECREF(tmp_tb); | |
| 3325 | |
| 3326 /* For b/w compatibility */ | |
| 3327 PySys_SetObject("exc_type", frame->f_exc_type); | |
| 3328 PySys_SetObject("exc_value", frame->f_exc_value); | |
| 3329 PySys_SetObject("exc_traceback", frame->f_exc_traceback); | |
| 3330 | |
| 3331 /* Clear the frame's exception info. */ | |
|
5557
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
3332 tmp_type = frame->f_exc_type; |
|
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
3333 tmp_value = frame->f_exc_value; |
|
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
3334 tmp_tb = frame->f_exc_traceback; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3335 frame->f_exc_type = NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3336 frame->f_exc_value = NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3337 frame->f_exc_traceback = NULL; |
| 38418 | 3338 Py_DECREF(tmp_type); |
|
5557
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
3339 Py_XDECREF(tmp_value); |
|
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
3340 Py_XDECREF(tmp_tb); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3341 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3342 |
|
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
|
3343 /* 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
|
3344 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
|
3345 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
|
3346 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
|
3347 { |
|
7946
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
3348 if (type == NULL) { |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
3349 /* Reraise */ |
|
31797
846b3ee7e106
Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31796
diff
changeset
|
3350 PyThreadState *tstate = PyThreadState_GET(); |
|
7946
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
3351 type = tstate->exc_type == NULL ? Py_None : tstate->exc_type; |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
3352 value = tstate->exc_value; |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
3353 tb = tstate->exc_traceback; |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
3354 Py_XINCREF(type); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
3355 Py_XINCREF(value); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
3356 Py_XINCREF(tb); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
3357 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3358 |
|
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
|
3359 /* We support the following forms of raise: |
|
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
|
3360 raise <class>, <classinstance> |
|
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
|
3361 raise <class>, <argument tuple> |
|
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
|
3362 raise <class>, None |
|
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
|
3363 raise <class>, <argument> |
|
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
|
3364 raise <classinstance>, None |
|
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
|
3365 raise <string>, <object> |
|
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
|
3366 raise <string>, None |
|
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
|
3367 |
|
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
|
3368 An omitted second argument is the same as None. |
|
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
|
3369 |
|
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
|
3370 In addition, raise <tuple>, <anything> is the same as |
|
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
|
3371 raising the tuple's first item (and it better have one!); |
|
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
|
3372 this rule is applied recursively. |
|
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
|
3373 |
|
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
|
3374 Finally, an optional third argument can be supplied, which |
|
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
|
3375 gives the traceback to be substituted (useful when |
|
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
|
3376 re-raising an exception after examining it). */ |
|
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
|
3377 |
|
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
|
3378 /* First, check the traceback argument, replacing None with |
|
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
|
3379 NULL. */ |
| 5368 | 3380 if (tb == Py_None) { |
| 3381 Py_DECREF(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
|
3382 tb = NULL; |
|
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
|
3383 } |
|
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
|
3384 else if (tb != NULL && !PyTraceBack_Check(tb)) { |
| 5368 | 3385 PyErr_SetString(PyExc_TypeError, |
| 15318 | 3386 "raise: arg 3 must be a traceback or None"); |
|
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
|
3387 goto raise_error; |
|
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
|
3388 } |
|
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
|
3389 |
|
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
|
3390 /* Next, replace a missing value with None */ |
|
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
|
3391 if (value == NULL) { |
| 5368 | 3392 value = Py_None; |
| 3393 Py_INCREF(value); | |
|
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
|
3394 } |
|
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
|
3395 |
|
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
|
3396 /* Next, repeatedly, replace a tuple exception with its first item */ |
| 5368 | 3397 while (PyTuple_Check(type) && PyTuple_Size(type) > 0) { |
| 3398 PyObject *tmp = type; | |
| 3399 type = PyTuple_GET_ITEM(type, 0); | |
| 3400 Py_INCREF(type); | |
| 3401 Py_DECREF(tmp); | |
|
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
|
3402 } |
|
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
|
3403 |
|
40735
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
3404 if (PyExceptionClass_Check(type)) |
|
6147
b76a44163e0f
cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents:
6139
diff
changeset
|
3405 PyErr_NormalizeException(&type, &value, &tb); |
|
b76a44163e0f
cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents:
6139
diff
changeset
|
3406 |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36737
diff
changeset
|
3407 else if (PyExceptionInstance_Check(type)) { |
|
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
|
3408 /* Raising an instance. The value should be a dummy. */ |
| 5368 | 3409 if (value != Py_None) { |
| 3410 PyErr_SetString(PyExc_TypeError, | |
|
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
|
3411 "instance exception may not have a separate value"); |
|
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
|
3412 goto raise_error; |
|
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
|
3413 } |
|
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
|
3414 else { |
|
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
|
3415 /* Normalize to raise <class>, <instance> */ |
| 5368 | 3416 Py_DECREF(value); |
|
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
|
3417 value = type; |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36737
diff
changeset
|
3418 type = PyExceptionInstance_Class(type); |
| 5368 | 3419 Py_INCREF(type); |
|
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
|
3420 } |
|
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
|
3421 } |
|
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
|
3422 else { |
|
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
|
3423 /* Not something you can raise. You get an exception |
|
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
|
3424 anyway, just not what you specified :-) */ |
|
17636
9921a9d27f72
improved error message-- names the type of the unexpected object
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17617
diff
changeset
|
3425 PyErr_Format(PyExc_TypeError, |
|
46578
7670005da8c5
A little reformating of Py3k warnings
Benjamin Peterson <benjamin@python.org>
parents:
46573
diff
changeset
|
3426 "exceptions must be classes or instances, not %s", |
|
7670005da8c5
A little reformating of Py3k warnings
Benjamin Peterson <benjamin@python.org>
parents:
46573
diff
changeset
|
3427 type->ob_type->tp_name); |
|
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
|
3428 goto raise_error; |
|
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
|
3429 } |
|
45827
27e7dc2e6290
Issue #2341: Add a Py3k warning when raising an exception that doesn't
Guido van Rossum <guido@python.org>
parents:
45820
diff
changeset
|
3430 |
|
27e7dc2e6290
Issue #2341: Add a Py3k warning when raising an exception that doesn't
Guido van Rossum <guido@python.org>
parents:
45820
diff
changeset
|
3431 assert(PyExceptionClass_Check(type)); |
|
27e7dc2e6290
Issue #2341: Add a Py3k warning when raising an exception that doesn't
Guido van Rossum <guido@python.org>
parents:
45820
diff
changeset
|
3432 if (Py_Py3kWarningFlag && PyClass_Check(type)) { |
|
46573
aef3501d8e77
Use PyErr_WarnPy3k throughout
Benjamin Peterson <benjamin@python.org>
parents:
46075
diff
changeset
|
3433 if (PyErr_WarnEx(PyExc_DeprecationWarning, |
|
46578
7670005da8c5
A little reformating of Py3k warnings
Benjamin Peterson <benjamin@python.org>
parents:
46573
diff
changeset
|
3434 "exceptions must derive from BaseException " |
|
7670005da8c5
A little reformating of Py3k warnings
Benjamin Peterson <benjamin@python.org>
parents:
46573
diff
changeset
|
3435 "in 3.x", 1) < 0) |
|
45827
27e7dc2e6290
Issue #2341: Add a Py3k warning when raising an exception that doesn't
Guido van Rossum <guido@python.org>
parents:
45820
diff
changeset
|
3436 goto raise_error; |
|
27e7dc2e6290
Issue #2341: Add a Py3k warning when raising an exception that doesn't
Guido van Rossum <guido@python.org>
parents:
45820
diff
changeset
|
3437 } |
|
27e7dc2e6290
Issue #2341: Add a Py3k warning when raising an exception that doesn't
Guido van Rossum <guido@python.org>
parents:
45820
diff
changeset
|
3438 |
| 5368 | 3439 PyErr_Restore(type, value, 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
|
3440 if (tb == NULL) |
|
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
|
3441 return WHY_EXCEPTION; |
|
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
|
3442 else |
|
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
|
3443 return WHY_RERAISE; |
|
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
|
3444 raise_error: |
| 5368 | 3445 Py_XDECREF(value); |
| 3446 Py_XDECREF(type); | |
| 3447 Py_XDECREF(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
|
3448 return WHY_EXCEPTION; |
|
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
|
3449 } |
|
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
|
3450 |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3451 /* 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
|
3452 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
|
3453 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
3454 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
|
3455 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
|
3456 { |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3457 int i = 0; |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3458 PyObject *it; /* iter(v) */ |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3459 PyObject *w; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3460 |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3461 assert(v != NULL); |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3462 |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3463 it = PyObject_GetIter(v); |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3464 if (it == NULL) |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3465 goto Error; |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3466 |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3467 for (; i < argcnt; i++) { |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3468 w = PyIter_Next(it); |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3469 if (w == NULL) { |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3470 /* Iterator done, via error or exhaustion. */ |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3471 if (!PyErr_Occurred()) { |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3472 PyErr_Format(PyExc_ValueError, |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3473 "need more than %d value%s to unpack", |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3474 i, i == 1 ? "" : "s"); |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3475 } |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3476 goto Error; |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3477 } |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3478 *--sp = w; |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3479 } |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3480 |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3481 /* We better have exhausted the iterator now. */ |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3482 w = PyIter_Next(it); |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3483 if (w == NULL) { |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3484 if (PyErr_Occurred()) |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3485 goto Error; |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3486 Py_DECREF(it); |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3487 return 1; |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3488 } |
|
21170
2dfc600f99ce
unpack_iterable(): Add a missing DECREF in an error case. Reported by
Guido van Rossum <guido@python.org>
parents:
21058
diff
changeset
|
3489 Py_DECREF(w); |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3490 PyErr_SetString(PyExc_ValueError, "too many values to unpack"); |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3491 /* 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
|
3492 Error: |
|
6160
79592761b331
unpack_sequence(): In finally clause, watch out for Py_DECREF
Barry Warsaw <barry@python.org>
parents:
6157
diff
changeset
|
3493 for (; i > 0; i--, sp++) |
|
79592761b331
unpack_sequence(): In finally clause, watch out for Py_DECREF
Barry Warsaw <barry@python.org>
parents:
6157
diff
changeset
|
3494 Py_DECREF(*sp); |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3495 Py_XDECREF(it); |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3496 return 0; |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3497 } |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3498 |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3499 |
| 567 | 3500 #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
|
3501 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3502 prtrace(PyObject *v, char *str) |
| 69 | 3503 { |
| 86 | 3504 printf("%s ", str); |
| 5368 | 3505 if (PyObject_Print(v, stdout, 0) != 0) |
| 3506 PyErr_Clear(); /* Don't know what else to do */ | |
| 86 | 3507 printf("\n"); |
|
12579
978253542076
Add useless 'return 1' to prtrace() to shut up VC++.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
3508 return 1; |
| 69 | 3509 } |
| 86 | 3510 #endif |
| 69 | 3511 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
3512 static void |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3513 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
|
3514 { |
| 5368 | 3515 PyObject *type, *value, *traceback, *arg; |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3516 int err; |
| 5368 | 3517 PyErr_Fetch(&type, &value, &traceback); |
|
815
6508c93f9472
Test for NULL coming out of err_get() in call_exc_trace()
Guido van Rossum <guido@python.org>
parents:
814
diff
changeset
|
3518 if (value == NULL) { |
| 5368 | 3519 value = Py_None; |
| 3520 Py_INCREF(value); | |
|
815
6508c93f9472
Test for NULL coming out of err_get() in call_exc_trace()
Guido van Rossum <guido@python.org>
parents:
814
diff
changeset
|
3521 } |
|
30683
3b59fa5d25b1
Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents:
29669
diff
changeset
|
3522 arg = PyTuple_Pack(3, type, value, traceback); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
3523 if (arg == NULL) { |
| 5368 | 3524 PyErr_Restore(type, value, traceback); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
3525 return; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
3526 } |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3527 err = call_trace(func, self, f, PyTrace_EXCEPTION, arg); |
| 5368 | 3528 Py_DECREF(arg); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
3529 if (err == 0) |
| 5368 | 3530 PyErr_Restore(type, value, traceback); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
3531 else { |
| 5368 | 3532 Py_XDECREF(type); |
| 3533 Py_XDECREF(value); | |
| 3534 Py_XDECREF(traceback); | |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3535 } |
|
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3536 } |
|
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3537 |
|
43845
76844a0a579f
Merge from py3k branch:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43784
diff
changeset
|
3538 static int |
|
20257
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3539 call_trace_protected(Py_tracefunc func, PyObject *obj, PyFrameObject *frame, |
|
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
|
3540 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
|
3541 { |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3542 PyObject *type, *value, *traceback; |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3543 int err; |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3544 PyErr_Fetch(&type, &value, &traceback); |
|
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
|
3545 err = call_trace(func, obj, frame, what, arg); |
|
20257
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3546 if (err == 0) |
|
43845
76844a0a579f
Merge from py3k branch:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43784
diff
changeset
|
3547 { |
|
20257
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3548 PyErr_Restore(type, value, traceback); |
|
43845
76844a0a579f
Merge from py3k branch:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43784
diff
changeset
|
3549 return 0; |
|
76844a0a579f
Merge from py3k branch:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43784
diff
changeset
|
3550 } |
|
20257
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3551 else { |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3552 Py_XDECREF(type); |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3553 Py_XDECREF(value); |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3554 Py_XDECREF(traceback); |
|
43845
76844a0a579f
Merge from py3k branch:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43784
diff
changeset
|
3555 return -1; |
|
20257
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3556 } |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3557 } |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3558 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
3559 static int |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3560 call_trace(Py_tracefunc func, PyObject *obj, PyFrameObject *frame, |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3561 int what, PyObject *arg) |
| 567 | 3562 { |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3563 register PyThreadState *tstate = frame->f_tstate; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3564 int result; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3565 if (tstate->tracing) |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3566 return 0; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3567 tstate->tracing++; |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
3568 tstate->use_tracing = 0; |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3569 result = func(obj, frame, what, arg); |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
3570 tstate->use_tracing = ((tstate->c_tracefunc != NULL) |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
3571 || (tstate->c_profilefunc != NULL)); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3572 tstate->tracing--; |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3573 return result; |
| 567 | 3574 } |
| 3575 | |
|
28556
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3576 PyObject * |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3577 _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
|
3578 { |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3579 PyFrameObject *frame = PyEval_GetFrame(); |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3580 PyThreadState *tstate = frame->f_tstate; |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3581 int save_tracing = tstate->tracing; |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3582 int save_use_tracing = tstate->use_tracing; |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3583 PyObject *result; |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3584 |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3585 tstate->tracing = 0; |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3586 tstate->use_tracing = ((tstate->c_tracefunc != NULL) |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3587 || (tstate->c_profilefunc != NULL)); |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3588 result = PyObject_Call(func, args, NULL); |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3589 tstate->tracing = save_tracing; |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3590 tstate->use_tracing = save_use_tracing; |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3591 return result; |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3592 } |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3593 |
| 54297 | 3594 /* 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
|
3595 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
|
3596 maybe_call_line_trace(Py_tracefunc func, PyObject *obj, |
| 31768 | 3597 PyFrameObject *frame, int *instr_lb, int *instr_ub, |
| 3598 int *instr_prev) | |
| 24844 | 3599 { |
|
26110
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
3600 int result = 0; |
| 54297 | 3601 int line = frame->f_lineno; |
|
26110
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
3602 |
|
37838
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37597
diff
changeset
|
3603 /* If the last instruction executed isn't in the current |
| 54297 | 3604 instruction window, reset the window. |
|
37838
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37597
diff
changeset
|
3605 */ |
| 54297 | 3606 if (frame->f_lasti < *instr_lb || frame->f_lasti >= *instr_ub) { |
| 43408 | 3607 PyAddrPair bounds; |
| 54297 | 3608 line = _PyCode_CheckLineNumber(frame->f_code, frame->f_lasti, |
| 3609 &bounds); | |
| 43408 | 3610 *instr_lb = bounds.ap_lower; |
| 3611 *instr_ub = bounds.ap_upper; | |
| 24844 | 3612 } |
| 54297 | 3613 /* If the last instruction falls at the start of a line or if |
| 3614 it represents a jump backwards, update the frame's line | |
| 3615 number and call the trace function. */ | |
| 3616 if (frame->f_lasti == *instr_lb || frame->f_lasti < *instr_prev) { | |
| 3617 frame->f_lineno = line; | |
|
37838
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37597
diff
changeset
|
3618 result = call_trace(func, obj, frame, PyTrace_LINE, Py_None); |
| 31768 | 3619 } |
| 3620 *instr_prev = frame->f_lasti; | |
|
26110
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
3621 return result; |
| 24844 | 3622 } |
| 3623 | |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3624 void |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3625 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
|
3626 { |
|
31797
846b3ee7e106
Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31796
diff
changeset
|
3627 PyThreadState *tstate = PyThreadState_GET(); |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3628 PyObject *temp = tstate->c_profileobj; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3629 Py_XINCREF(arg); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3630 tstate->c_profilefunc = NULL; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3631 tstate->c_profileobj = NULL; |
|
35125
cdec978b916c
Add comments about PyThreadState and the usage of its fields.
Brett Cannon <bcannon@gmail.com>
parents:
34863
diff
changeset
|
3632 /* Must make sure that tracing is not ignored if 'temp' is freed */ |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
3633 tstate->use_tracing = 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
|
3634 Py_XDECREF(temp); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3635 tstate->c_profilefunc = func; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3636 tstate->c_profileobj = arg; |
|
35125
cdec978b916c
Add comments about PyThreadState and the usage of its fields.
Brett Cannon <bcannon@gmail.com>
parents:
34863
diff
changeset
|
3637 /* Flag that tracing or profiling is turned on */ |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
3638 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
|
3639 } |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3640 |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3641 void |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3642 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
|
3643 { |
|
31797
846b3ee7e106
Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31796
diff
changeset
|
3644 PyThreadState *tstate = PyThreadState_GET(); |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3645 PyObject *temp = tstate->c_traceobj; |
|
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
|
3646 _Py_TracingPossible += (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
|
3647 Py_XINCREF(arg); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3648 tstate->c_tracefunc = NULL; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3649 tstate->c_traceobj = NULL; |
|
35125
cdec978b916c
Add comments about PyThreadState and the usage of its fields.
Brett Cannon <bcannon@gmail.com>
parents:
34863
diff
changeset
|
3650 /* Must make sure that profiling is not ignored if 'temp' is freed */ |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
3651 tstate->use_tracing = tstate->c_profilefunc != NULL; |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3652 Py_XDECREF(temp); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3653 tstate->c_tracefunc = func; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3654 tstate->c_traceobj = arg; |
|
35125
cdec978b916c
Add comments about PyThreadState and the usage of its fields.
Brett Cannon <bcannon@gmail.com>
parents:
34863
diff
changeset
|
3655 /* Flag that tracing or profiling is turned on */ |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
3656 tstate->use_tracing = ((func != NULL) |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
3657 || (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
|
3658 } |
|
4cb34314bd97
Instead of initializing & interning the strings passed to the profile
Fred Drake <fdrake@acm.org>
parents:
18128
diff
changeset
|
3659 |
| 5368 | 3660 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3661 PyEval_GetBuiltins(void) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3662 { |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
3663 PyFrameObject *current_frame = PyEval_GetFrame(); |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3664 if (current_frame == NULL) |
|
31797
846b3ee7e106
Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31796
diff
changeset
|
3665 return PyThreadState_GET()->interp->builtins; |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3666 else |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3667 return current_frame->f_builtins; |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3668 } |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3669 |
| 5368 | 3670 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3671 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
|
3672 { |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
3673 PyFrameObject *current_frame = PyEval_GetFrame(); |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3674 if (current_frame == NULL) |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3675 return NULL; |
| 5368 | 3676 PyFrame_FastToLocals(current_frame); |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3677 return current_frame->f_locals; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3678 } |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3679 |
| 5368 | 3680 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3681 PyEval_GetGlobals(void) |
| 69 | 3682 { |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
3683 PyFrameObject *current_frame = PyEval_GetFrame(); |
| 86 | 3684 if (current_frame == NULL) |
| 3685 return NULL; | |
| 3686 else | |
| 3687 return current_frame->f_globals; | |
| 69 | 3688 } |
| 3689 | |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
3690 PyFrameObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3691 PyEval_GetFrame(void) |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
3692 { |
|
31797
846b3ee7e106
Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31796
diff
changeset
|
3693 PyThreadState *tstate = PyThreadState_GET(); |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
3694 return _PyThreadState_GetFrame(tstate); |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
3695 } |
|
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
3696 |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3697 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3698 PyEval_GetRestricted(void) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3699 { |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
3700 PyFrameObject *current_frame = PyEval_GetFrame(); |
|
38766
79983cf634c0
Get rid of f_restricted too. Doc the other 4 ints that were already removed
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
3701 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
|
3702 } |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3703 |
|
5606
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
3704 int |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3705 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
|
3706 { |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
3707 PyFrameObject *current_frame = PyEval_GetFrame(); |
|
27781
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
3708 int result = cf->cf_flags != 0; |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3709 |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3710 if (current_frame != NULL) { |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3711 const int codeflags = current_frame->f_code->co_flags; |
|
19350
5b6a6d7d44ae
ceval, PyEval_MergeCompilerFlags: wasn't merging in the
Tim Peters <tim.peters@gmail.com>
parents:
19301
diff
changeset
|
3712 const int compilerflags = codeflags & PyCF_MASK; |
|
5b6a6d7d44ae
ceval, PyEval_MergeCompilerFlags: wasn't merging in the
Tim Peters <tim.peters@gmail.com>
parents:
19301
diff
changeset
|
3713 if (compilerflags) { |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3714 result = 1; |
|
19350
5b6a6d7d44ae
ceval, PyEval_MergeCompilerFlags: wasn't merging in the
Tim Peters <tim.peters@gmail.com>
parents:
19301
diff
changeset
|
3715 cf->cf_flags |= compilerflags; |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3716 } |
|
22468
eebae4f60d05
Disable the parser hacks that enabled the "yield" keyword using a future
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22398
diff
changeset
|
3717 #if 0 /* future keyword */ |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
3718 if (codeflags & CO_GENERATOR_ALLOWED) { |
|
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
3719 result = 1; |
|
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
3720 cf->cf_flags |= CO_GENERATOR_ALLOWED; |
|
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
3721 } |
|
22468
eebae4f60d05
Disable the parser hacks that enabled the "yield" keyword using a future
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22398
diff
changeset
|
3722 #endif |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3723 } |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3724 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
|
3725 } |
|
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
|
3726 |
|
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
|
3727 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3728 Py_FlushLine(void) |
| 69 | 3729 { |
| 5368 | 3730 PyObject *f = PySys_GetObject("stdout"); |
|
5606
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
3731 if (f == NULL) |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
3732 return 0; |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
3733 if (!PyFile_SoftSpace(f, 0)) |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
3734 return 0; |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
3735 return PyFile_WriteString("\n", f); |
| 69 | 3736 } |
| 3737 | |
| 86 | 3738 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3739 /* External interface to call any callable object. |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3740 The arg must be a tuple or NULL. */ |
|
314
e83852d1a5e2
Add interface to call a Python function (or other callable) object
Guido van Rossum <guido@python.org>
parents:
312
diff
changeset
|
3741 |
|
6206
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
3742 #undef PyEval_CallObject |
|
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
3743 /* for backward compatibility: export this interface */ |
|
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
3744 |
| 5368 | 3745 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3746 PyEval_CallObject(PyObject *func, PyObject *arg) |
|
314
e83852d1a5e2
Add interface to call a Python function (or other callable) object
Guido van Rossum <guido@python.org>
parents:
312
diff
changeset
|
3747 { |
| 5368 | 3748 return PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3749 } |
|
6206
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
3750 #define PyEval_CallObject(func,arg) \ |
|
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
3751 PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3752 |
| 5368 | 3753 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3754 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
|
3755 { |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3756 PyObject *result; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3757 |
|
36877
e9a7a2784e17
SF #1444030: Fix several potential defects found by Coverity.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
36803
diff
changeset
|
3758 if (arg == NULL) { |
| 5368 | 3759 arg = PyTuple_New(0); |
|
36877
e9a7a2784e17
SF #1444030: Fix several potential defects found by Coverity.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
36803
diff
changeset
|
3760 if (arg == NULL) |
|
e9a7a2784e17
SF #1444030: Fix several potential defects found by Coverity.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
36803
diff
changeset
|
3761 return NULL; |
|
e9a7a2784e17
SF #1444030: Fix several potential defects found by Coverity.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
36803
diff
changeset
|
3762 } |
| 5368 | 3763 else if (!PyTuple_Check(arg)) { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3764 PyErr_SetString(PyExc_TypeError, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3765 "argument list must be a tuple"); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3766 return NULL; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3767 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3768 else |
| 5368 | 3769 Py_INCREF(arg); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3770 |
| 5368 | 3771 if (kw != NULL && !PyDict_Check(kw)) { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3772 PyErr_SetString(PyExc_TypeError, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3773 "keyword list must be a dictionary"); |
|
12440
d47460b1a679
Charles Waldman writes:
Guido van Rossum <guido@python.org>
parents:
12320
diff
changeset
|
3774 Py_DECREF(arg); |
|
2894
4095782c940e
empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents:
2872
diff
changeset
|
3775 return NULL; |
|
4095782c940e
empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents:
2872
diff
changeset
|
3776 } |
|
4095782c940e
empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents:
2872
diff
changeset
|
3777 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3778 result = PyObject_Call(func, arg, kw); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3779 Py_DECREF(arg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3780 return result; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3781 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3782 |
|
35999
9541369b0dca
Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35745
diff
changeset
|
3783 const char * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3784 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
|
3785 { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3786 if (PyMethod_Check(func)) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3787 return PyEval_GetFuncName(PyMethod_GET_FUNCTION(func)); |
|
17406
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3788 else if (PyFunction_Check(func)) |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
3789 return PyString_AsString(((PyFunctionObject*)func)->func_name); |
|
17406
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3790 else if (PyCFunction_Check(func)) |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3791 return ((PyCFunctionObject*)func)->m_ml->ml_name; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3792 else if (PyClass_Check(func)) |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
3793 return PyString_AsString(((PyClassObject*)func)->cl_name); |
|
17406
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3794 else if (PyInstance_Check(func)) { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
3795 return PyString_AsString( |
|
17406
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3796 ((PyInstanceObject*)func)->in_class->cl_name); |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3797 } else { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3798 return func->ob_type->tp_name; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3799 } |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3800 } |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3801 |
|
35999
9541369b0dca
Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35745
diff
changeset
|
3802 const char * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3803 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
|
3804 { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3805 if (PyMethod_Check(func)) |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3806 return "()"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3807 else if (PyFunction_Check(func)) |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3808 return "()"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3809 else if (PyCFunction_Check(func)) |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3810 return "()"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3811 else if (PyClass_Check(func)) |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3812 return " constructor"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3813 else if (PyInstance_Check(func)) { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3814 return " instance"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3815 } else { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3816 return " object"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3817 } |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3818 } |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3819 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
3820 static void |
|
24870
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3821 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
|
3822 { |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3823 if (flags & METH_NOARGS) |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
3824 PyErr_Format(PyExc_TypeError, |
|
24978
b1ab4e8d7d9c
The error messages in err_args() -- which is only called when the
Guido van Rossum <guido@python.org>
parents:
24916
diff
changeset
|
3825 "%.200s() takes no arguments (%d given)", |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
3826 ((PyCFunctionObject *)func)->m_ml->ml_name, |
|
24870
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3827 nargs); |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3828 else |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
3829 PyErr_Format(PyExc_TypeError, |
|
24978
b1ab4e8d7d9c
The error messages in err_args() -- which is only called when the
Guido van Rossum <guido@python.org>
parents:
24916
diff
changeset
|
3830 "%.200s() takes exactly one argument (%d given)", |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
3831 ((PyCFunctionObject *)func)->m_ml->ml_name, |
|
24870
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3832 nargs); |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3833 } |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3834 |
|
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
|
3835 #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
|
3836 if (tstate->use_tracing && tstate->c_profilefunc) { \ |
|
77913be294b9
Massive performance improvement for C extension and builtin tracing code
Nicholas Bastin <nick.bastin@gmail.com>
parents:
32398
diff
changeset
|
3837 if (call_trace(tstate->c_profilefunc, \ |
|
77913be294b9
Massive performance improvement for C extension and builtin tracing code
Nicholas Bastin <nick.bastin@gmail.com>
parents:
32398
diff
changeset
|
3838 tstate->c_profileobj, \ |
|
77913be294b9
Massive performance improvement for C extension and builtin tracing code
Nicholas Bastin <nick.bastin@gmail.com>
parents:
32398
diff
changeset
|
3839 tstate->frame, PyTrace_C_CALL, \ |
|
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
|
3840 func)) { \ |
|
23dda92de993
clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents:
35345
diff
changeset
|
3841 x = NULL; \ |
|
23dda92de993
clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents:
35345
diff
changeset
|
3842 } \ |
|
23dda92de993
clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents:
35345
diff
changeset
|
3843 else { \ |
|
23dda92de993
clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents:
35345
diff
changeset
|
3844 x = call; \ |
|
23dda92de993
clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents:
35345
diff
changeset
|
3845 if (tstate->c_profilefunc != NULL) { \ |
|
23dda92de993
clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents:
35345
diff
changeset
|
3846 if (x == NULL) { \ |
|
23dda92de993
clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents:
35345
diff
changeset
|
3847 call_trace_protected(tstate->c_profilefunc, \ |
|
23dda92de993
clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents:
35345
diff
changeset
|
3848 tstate->c_profileobj, \ |
|
23dda92de993
clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents:
35345
diff
changeset
|
3849 tstate->frame, PyTrace_C_EXCEPTION, \ |
|
23dda92de993
clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents:
35345
diff
changeset
|
3850 func); \ |
|
23dda92de993
clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents:
35345
diff
changeset
|
3851 /* XXX should pass (type, value, tb) */ \ |
|
23dda92de993
clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents:
35345
diff
changeset
|
3852 } else { \ |
|
23dda92de993
clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents:
35345
diff
changeset
|
3853 if (call_trace(tstate->c_profilefunc, \ |
|
23dda92de993
clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents:
35345
diff
changeset
|
3854 tstate->c_profileobj, \ |
|
23dda92de993
clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents:
35345
diff
changeset
|
3855 tstate->frame, PyTrace_C_RETURN, \ |
|
23dda92de993
clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents:
35345
diff
changeset
|
3856 func)) { \ |
|
23dda92de993
clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents:
35345
diff
changeset
|
3857 Py_DECREF(x); \ |
|
23dda92de993
clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents:
35345
diff
changeset
|
3858 x = NULL; \ |
|
23dda92de993
clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents:
35345
diff
changeset
|
3859 } \ |
|
23dda92de993
clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents:
35345
diff
changeset
|
3860 } \ |
|
31796
1c117dbb2def
Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31768
diff
changeset
|
3861 } \ |
|
32409
77913be294b9
Massive performance improvement for C extension and builtin tracing code
Nicholas Bastin <nick.bastin@gmail.com>
parents:
32398
diff
changeset
|
3862 } \ |
|
77913be294b9
Massive performance improvement for C extension and builtin tracing code
Nicholas Bastin <nick.bastin@gmail.com>
parents:
32398
diff
changeset
|
3863 } else { \ |
|
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
|
3864 x = call; \ |
|
31796
1c117dbb2def
Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31768
diff
changeset
|
3865 } |
|
1c117dbb2def
Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31768
diff
changeset
|
3866 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
3867 static PyObject * |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
3868 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
|
3869 #ifdef WITH_TSC |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
3870 , uint64* pintr0, uint64* pintr1 |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
3871 #endif |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
3872 ) |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3873 { |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3874 int na = oparg & 0xff; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3875 int nk = (oparg>>8) & 0xff; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3876 int n = na + 2 * nk; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3877 PyObject **pfunc = (*pp_stack) - n - 1; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3878 PyObject *func = *pfunc; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3879 PyObject *x, *w; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3880 |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3881 /* Always dispatch PyCFunction first, because these are |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3882 presumed to be the most frequent callable object. |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3883 */ |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3884 if (PyCFunction_Check(func) && nk == 0) { |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3885 int flags = PyCFunction_GET_FLAGS(func); |
|
32412
393c15c0c5a4
Get ceval.c to compile again by moving declarations before other statments.
Raymond Hettinger <python@rcn.com>
parents:
32409
diff
changeset
|
3886 PyThreadState *tstate = PyThreadState_GET(); |
|
393c15c0c5a4
Get ceval.c to compile again by moving declarations before other statments.
Raymond Hettinger <python@rcn.com>
parents:
32409
diff
changeset
|
3887 |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3888 PCALL(PCALL_CFUNCTION); |
|
24870
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3889 if (flags & (METH_NOARGS | METH_O)) { |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3890 PyCFunction meth = PyCFunction_GET_FUNCTION(func); |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3891 PyObject *self = PyCFunction_GET_SELF(func); |
|
31796
1c117dbb2def
Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31768
diff
changeset
|
3892 if (flags & METH_NOARGS && na == 0) { |
|
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
|
3893 C_TRACE(x, (*meth)(self,NULL)); |
|
31796
1c117dbb2def
Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31768
diff
changeset
|
3894 } |
|
24870
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3895 else if (flags & METH_O && na == 1) { |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3896 PyObject *arg = EXT_POP(*pp_stack); |
|
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
|
3897 C_TRACE(x, (*meth)(self,arg)); |
|
24870
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3898 Py_DECREF(arg); |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3899 } |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3900 else { |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3901 err_args(func, flags, na); |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3902 x = NULL; |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3903 } |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3904 } |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3905 else { |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3906 PyObject *callargs; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3907 callargs = load_args(pp_stack, na); |
|
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
|
3908 READ_TIMESTAMP(*pintr0); |
|
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
|
3909 C_TRACE(x, PyCFunction_Call(func,callargs,NULL)); |
|
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
|
3910 READ_TIMESTAMP(*pintr1); |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
3911 Py_XDECREF(callargs); |
|
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
3912 } |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3913 } else { |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3914 if (PyMethod_Check(func) && PyMethod_GET_SELF(func) != NULL) { |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3915 /* optimize access to bound methods */ |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3916 PyObject *self = PyMethod_GET_SELF(func); |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3917 PCALL(PCALL_METHOD); |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3918 PCALL(PCALL_BOUND_METHOD); |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3919 Py_INCREF(self); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3920 func = PyMethod_GET_FUNCTION(func); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3921 Py_INCREF(func); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3922 Py_DECREF(*pfunc); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3923 *pfunc = self; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3924 na++; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3925 n++; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3926 } else |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3927 Py_INCREF(func); |
|
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
|
3928 READ_TIMESTAMP(*pintr0); |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3929 if (PyFunction_Check(func)) |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3930 x = fast_function(func, pp_stack, n, na, nk); |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
3931 else |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3932 x = do_call(func, pp_stack, na, nk); |
|
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
|
3933 READ_TIMESTAMP(*pintr1); |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3934 Py_DECREF(func); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3935 } |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
3936 |
|
37286
ab3efbca5c92
answer a question from a comment
Armin Rigo <arigo@tunes.org>
parents:
37164
diff
changeset
|
3937 /* Clear the stack of the function object. Also removes |
|
ab3efbca5c92
answer a question from a comment
Armin Rigo <arigo@tunes.org>
parents:
37164
diff
changeset
|
3938 the arguments in case they weren't consumed already |
|
ab3efbca5c92
answer a question from a comment
Armin Rigo <arigo@tunes.org>
parents:
37164
diff
changeset
|
3939 (fast_function() and err_args() leave them on the stack). |
|
36756
d0ca6302dd3c
Put back the essence of Jeremy's original XXX comment.
Thomas Wouters <thomas@python.org>
parents:
36751
diff
changeset
|
3940 */ |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3941 while ((*pp_stack) > pfunc) { |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3942 w = EXT_POP(*pp_stack); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3943 Py_DECREF(w); |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3944 PCALL(PCALL_POP); |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3945 } |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3946 return x; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3947 } |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3948 |
|
24870
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3949 /* 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
|
3950 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
|
3951 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
|
3952 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
|
3953 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
|
3954 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
|
3955 done before evaluating the frame. |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3956 */ |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3957 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
3958 static PyObject * |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3959 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
|
3960 { |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3961 PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3962 PyObject *globals = PyFunction_GET_GLOBALS(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3963 PyObject *argdefs = PyFunction_GET_DEFAULTS(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3964 PyObject **d = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3965 int nd = 0; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3966 |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3967 PCALL(PCALL_FUNCTION); |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3968 PCALL(PCALL_FAST_FUNCTION); |
|
29339
fc286e28556f
SF bug #733667: kwargs handled incorrectly
Raymond Hettinger <python@rcn.com>
parents:
29337
diff
changeset
|
3969 if (argdefs == NULL && co->co_argcount == n && nk==0 && |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3970 co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) { |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3971 PyFrameObject *f; |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3972 PyObject *retval = NULL; |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3973 PyThreadState *tstate = PyThreadState_GET(); |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3974 PyObject **fastlocals, **stack; |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3975 int i; |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3976 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3977 PCALL(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
|
3978 assert(globals != NULL); |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3979 /* XXX Perhaps we should create a specialized |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3980 PyFrame_New() that doesn't take locals, but does |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3981 take builtins without sanity checking them. |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3982 */ |
|
39466
c7ff02c1559f
Move/copy assert for tstate != NULL before first use.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39463
diff
changeset
|
3983 assert(tstate != NULL); |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3984 f = PyFrame_New(tstate, co, globals, NULL); |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3985 if (f == NULL) |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3986 return NULL; |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3987 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3988 fastlocals = f->f_localsplus; |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3989 stack = (*pp_stack) - n; |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3990 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3991 for (i = 0; i < n; i++) { |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3992 Py_INCREF(*stack); |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3993 fastlocals[i] = *stack++; |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3994 } |
|
35298
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
3995 retval = PyEval_EvalFrameEx(f,0); |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3996 ++tstate->recursion_depth; |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3997 Py_DECREF(f); |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3998 --tstate->recursion_depth; |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3999 return retval; |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4000 } |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4001 if (argdefs != NULL) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4002 d = &PyTuple_GET_ITEM(argdefs, 0); |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
44339
diff
changeset
|
4003 nd = Py_SIZE(argdefs); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4004 } |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4005 return PyEval_EvalCodeEx(co, globals, |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4006 (PyObject *)NULL, (*pp_stack)-n, na, |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4007 (*pp_stack)-2*nk, nk, d, nd, |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4008 PyFunction_GET_CLOSURE(func)); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4009 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4010 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
4011 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
|
4012 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
|
4013 PyObject *func) |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4014 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4015 PyObject *kwdict = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4016 if (orig_kwdict == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4017 kwdict = PyDict_New(); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4018 else { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4019 kwdict = PyDict_Copy(orig_kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4020 Py_DECREF(orig_kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4021 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4022 if (kwdict == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4023 return NULL; |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
4024 while (--nk >= 0) { |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4025 int err; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4026 PyObject *value = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4027 PyObject *key = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4028 if (PyDict_GetItem(kwdict, key) != NULL) { |
| 43408 | 4029 PyErr_Format(PyExc_TypeError, |
| 4030 "%.200s%s got multiple values " | |
| 4031 "for keyword argument '%.200s'", | |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
4032 PyEval_GetFuncName(func), |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
4033 PyEval_GetFuncDesc(func), |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4034 PyString_AsString(key)); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4035 Py_DECREF(key); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4036 Py_DECREF(value); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4037 Py_DECREF(kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4038 return NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4039 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4040 err = PyDict_SetItem(kwdict, key, value); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4041 Py_DECREF(key); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4042 Py_DECREF(value); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4043 if (err) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4044 Py_DECREF(kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4045 return NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4046 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4047 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4048 return kwdict; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4049 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4050 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
4051 static PyObject * |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4052 update_star_args(int nstack, int nstar, PyObject *stararg, |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4053 PyObject ***pp_stack) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4054 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4055 PyObject *callargs, *w; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4056 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4057 callargs = PyTuple_New(nstack + nstar); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4058 if (callargs == NULL) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4059 return NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4060 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4061 if (nstar) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4062 int i; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4063 for (i = 0; i < nstar; i++) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4064 PyObject *a = PyTuple_GET_ITEM(stararg, i); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4065 Py_INCREF(a); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4066 PyTuple_SET_ITEM(callargs, nstack + i, a); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4067 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4068 } |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
4069 while (--nstack >= 0) { |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4070 w = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4071 PyTuple_SET_ITEM(callargs, nstack, w); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4072 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4073 return callargs; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4074 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4075 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
4076 static PyObject * |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4077 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
|
4078 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4079 PyObject *args = PyTuple_New(na); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4080 PyObject *w; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4081 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4082 if (args == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4083 return NULL; |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
4084 while (--na >= 0) { |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4085 w = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4086 PyTuple_SET_ITEM(args, na, w); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4087 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4088 return args; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4089 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4090 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
4091 static PyObject * |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4092 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
|
4093 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4094 PyObject *callargs = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4095 PyObject *kwdict = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4096 PyObject *result = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4097 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4098 if (nk > 0) { |
|
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
|
4099 kwdict = update_keyword_args(NULL, nk, pp_stack, func); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4100 if (kwdict == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4101 goto call_fail; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4102 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4103 callargs = load_args(pp_stack, na); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4104 if (callargs == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4105 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
|
4106 #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
|
4107 /* At this point, we have to look at the type of func to |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4108 update the call stats properly. Do it here so as to avoid |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4109 exposing the call stats machinery outside ceval.c |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4110 */ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4111 if (PyFunction_Check(func)) |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4112 PCALL(PCALL_FUNCTION); |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4113 else if (PyMethod_Check(func)) |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4114 PCALL(PCALL_METHOD); |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4115 else if (PyType_Check(func)) |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4116 PCALL(PCALL_TYPE); |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4117 else |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4118 PCALL(PCALL_OTHER); |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4119 #endif |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
4120 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
|
4121 call_fail: |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4122 Py_XDECREF(callargs); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4123 Py_XDECREF(kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4124 return result; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4125 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4126 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
4127 static PyObject * |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4128 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
|
4129 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4130 int nstar = 0; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4131 PyObject *callargs = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4132 PyObject *stararg = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4133 PyObject *kwdict = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4134 PyObject *result = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4135 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4136 if (flags & CALL_FLAG_KW) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4137 kwdict = EXT_POP(*pp_stack); |
|
41807
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4138 if (!PyDict_Check(kwdict)) { |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4139 PyObject *d; |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4140 d = PyDict_New(); |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4141 if (d == NULL) |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4142 goto ext_call_fail; |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4143 if (PyDict_Update(d, kwdict) != 0) { |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4144 Py_DECREF(d); |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4145 /* PyDict_Update raises attribute |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4146 * error (percolated from an attempt |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4147 * to get 'keys' attribute) instead of |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4148 * a type error if its second argument |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4149 * is not a mapping. |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4150 */ |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4151 if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4152 PyErr_Format(PyExc_TypeError, |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4153 "%.200s%.200s argument after ** " |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4154 "must be a mapping, not %.200s", |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4155 PyEval_GetFuncName(func), |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4156 PyEval_GetFuncDesc(func), |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4157 kwdict->ob_type->tp_name); |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4158 } |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4159 goto ext_call_fail; |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4160 } |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4161 Py_DECREF(kwdict); |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4162 kwdict = d; |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4163 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4164 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4165 if (flags & CALL_FLAG_VAR) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4166 stararg = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4167 if (!PyTuple_Check(stararg)) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4168 PyObject *t = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4169 t = PySequence_Tuple(stararg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4170 if (t == NULL) { |
|
17406
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
4171 if (PyErr_ExceptionMatches(PyExc_TypeError)) { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
4172 PyErr_Format(PyExc_TypeError, |
|
41807
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4173 "%.200s%.200s argument after * " |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4174 "must be a sequence, not %200s", |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
4175 PyEval_GetFuncName(func), |
|
41807
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4176 PyEval_GetFuncDesc(func), |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
4177 stararg->ob_type->tp_name); |
|
17406
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
4178 } |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4179 goto ext_call_fail; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4180 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4181 Py_DECREF(stararg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4182 stararg = t; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4183 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4184 nstar = PyTuple_GET_SIZE(stararg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4185 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4186 if (nk > 0) { |
|
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
|
4187 kwdict = update_keyword_args(kwdict, nk, pp_stack, func); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4188 if (kwdict == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4189 goto ext_call_fail; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4190 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4191 callargs = update_star_args(na, nstar, stararg, pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4192 if (callargs == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4193 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
|
4194 #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
|
4195 /* At this point, we have to look at the type of func to |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4196 update the call stats properly. Do it here so as to avoid |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4197 exposing the call stats machinery outside ceval.c |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4198 */ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4199 if (PyFunction_Check(func)) |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4200 PCALL(PCALL_FUNCTION); |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4201 else if (PyMethod_Check(func)) |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4202 PCALL(PCALL_METHOD); |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4203 else if (PyType_Check(func)) |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4204 PCALL(PCALL_TYPE); |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4205 else |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4206 PCALL(PCALL_OTHER); |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4207 #endif |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
4208 result = PyObject_Call(func, callargs, kwdict); |
| 43408 | 4209 ext_call_fail: |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4210 Py_XDECREF(callargs); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4211 Py_XDECREF(kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4212 Py_XDECREF(stararg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4213 return result; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4214 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4215 |
|
36882
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4216 /* 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
|
4217 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
|
4218 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
|
4219 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
|
4220 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
|
4221 */ |
|
21441
05ad7a69d933
_PyEval_SliceIndex(): explain why a NULL argument is allowed (thanks
Tim Peters <tim.peters@gmail.com>
parents:
21440
diff
changeset
|
4222 /* 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
|
4223 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
|
4224 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
|
4225 */ |
| 12614 | 4226 int |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36475
diff
changeset
|
4227 _PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi) |
| 69 | 4228 { |
|
21441
05ad7a69d933
_PyEval_SliceIndex(): explain why a NULL argument is allowed (thanks
Tim Peters <tim.peters@gmail.com>
parents:
21440
diff
changeset
|
4229 if (v != NULL) { |
|
36558
d3685f9b7b71
Remove size constraints in SLICE opcodes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
4230 Py_ssize_t x; |
|
11839
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
4231 if (PyInt_Check(v)) { |
|
39463
6cafdc81cfde
Patch #1538606, Patch to fix __index__() clipping.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39455
diff
changeset
|
4232 /* XXX(nnorwitz): I think PyInt_AS_LONG is correct, |
|
6cafdc81cfde
Patch #1538606, Patch to fix __index__() clipping.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39455
diff
changeset
|
4233 however, it looks like it should be AsSsize_t. |
|
6cafdc81cfde
Patch #1538606, Patch to fix __index__() clipping.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39455
diff
changeset
|
4234 There should be a comment here explaining why. |
|
6cafdc81cfde
Patch #1538606, Patch to fix __index__() clipping.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39455
diff
changeset
|
4235 */ |
|
6cafdc81cfde
Patch #1538606, Patch to fix __index__() clipping.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39455
diff
changeset
|
4236 x = PyInt_AS_LONG(v); |
| 38418 | 4237 } |
|
39463
6cafdc81cfde
Patch #1538606, Patch to fix __index__() clipping.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39455
diff
changeset
|
4238 else if (PyIndex_Check(v)) { |
|
6cafdc81cfde
Patch #1538606, Patch to fix __index__() clipping.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39455
diff
changeset
|
4239 x = PyNumber_AsSsize_t(v, NULL); |
|
36882
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4240 if (x == -1 && PyErr_Occurred()) |
|
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4241 return 0; |
|
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4242 } |
|
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4243 else { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
4244 PyErr_SetString(PyExc_TypeError, |
|
36882
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4245 "slice indices must be integers or " |
|
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4246 "None or have an __index__ method"); |
| 12614 | 4247 return 0; |
| 69 | 4248 } |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
4249 *pi = x; |
| 69 | 4250 } |
| 12614 | 4251 return 1; |
| 69 | 4252 } |
| 4253 | |
|
36882
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4254 #undef ISINDEX |
|
39463
6cafdc81cfde
Patch #1538606, Patch to fix __index__() clipping.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39455
diff
changeset
|
4255 #define ISINDEX(x) ((x) == NULL || \ |
|
6cafdc81cfde
Patch #1538606, Patch to fix __index__() clipping.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39455
diff
changeset
|
4256 PyInt_Check(x) || PyLong_Check(x) || PyIndex_Check(x)) |
| 19369 | 4257 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
4258 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4259 apply_slice(PyObject *u, PyObject *v, PyObject *w) /* return u[v:w] */ |
| 69 | 4260 { |
| 19369 | 4261 PyTypeObject *tp = u->ob_type; |
| 4262 PySequenceMethods *sq = tp->tp_as_sequence; | |
| 4263 | |
|
36882
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4264 if (sq && sq->sq_slice && ISINDEX(v) && ISINDEX(w)) { |
|
36558
d3685f9b7b71
Remove size constraints in SLICE opcodes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
4265 Py_ssize_t ilow = 0, ihigh = PY_SSIZE_T_MAX; |
| 19369 | 4266 if (!_PyEval_SliceIndex(v, &ilow)) |
| 4267 return NULL; | |
| 4268 if (!_PyEval_SliceIndex(w, &ihigh)) | |
| 4269 return NULL; | |
| 4270 return PySequence_GetSlice(u, ilow, ihigh); | |
| 4271 } | |
| 4272 else { | |
| 4273 PyObject *slice = PySlice_New(v, w, NULL); | |
|
21171
2458cbcc1dd3
Fix the final two issues in Armin Rigo's SF bug #488477: apply_slice()
Guido van Rossum <guido@python.org>
parents:
21170
diff
changeset
|
4274 if (slice != NULL) { |
|
2458cbcc1dd3
Fix the final two issues in Armin Rigo's SF bug #488477: apply_slice()
Guido van Rossum <guido@python.org>
parents:
21170
diff
changeset
|
4275 PyObject *res = PyObject_GetItem(u, slice); |
|
2458cbcc1dd3
Fix the final two issues in Armin Rigo's SF bug #488477: apply_slice()
Guido van Rossum <guido@python.org>
parents:
21170
diff
changeset
|
4276 Py_DECREF(slice); |
|
2458cbcc1dd3
Fix the final two issues in Armin Rigo's SF bug #488477: apply_slice()
Guido van Rossum <guido@python.org>
parents:
21170
diff
changeset
|
4277 return res; |
|
2458cbcc1dd3
Fix the final two issues in Armin Rigo's SF bug #488477: apply_slice()
Guido van Rossum <guido@python.org>
parents:
21170
diff
changeset
|
4278 } |
| 19369 | 4279 else |
| 4280 return NULL; | |
| 4281 } | |
| 69 | 4282 } |
| 86 | 4283 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
4284 static int |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
4285 assign_slice(PyObject *u, PyObject *v, PyObject *w, PyObject *x) |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
4286 /* u[v:w] = x */ |
| 69 | 4287 { |
| 19369 | 4288 PyTypeObject *tp = u->ob_type; |
| 4289 PySequenceMethods *sq = tp->tp_as_sequence; | |
| 4290 | |
|
41007
6d3454c371dd
Patch #1674228: when assigning a slice (old-style), check for the
Georg Brandl <georg@python.org>
parents:
40931
diff
changeset
|
4291 if (sq && sq->sq_ass_slice && ISINDEX(v) && ISINDEX(w)) { |
|
36558
d3685f9b7b71
Remove size constraints in SLICE opcodes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
4292 Py_ssize_t ilow = 0, ihigh = PY_SSIZE_T_MAX; |
| 19369 | 4293 if (!_PyEval_SliceIndex(v, &ilow)) |
| 4294 return -1; | |
| 4295 if (!_PyEval_SliceIndex(w, &ihigh)) | |
| 4296 return -1; | |
| 4297 if (x == NULL) | |
| 4298 return PySequence_DelSlice(u, ilow, ihigh); | |
| 4299 else | |
| 4300 return PySequence_SetSlice(u, ilow, ihigh, x); | |
| 4301 } | |
| 4302 else { | |
| 4303 PyObject *slice = PySlice_New(v, w, NULL); | |
| 4304 if (slice != NULL) { | |
|
21171
2458cbcc1dd3
Fix the final two issues in Armin Rigo's SF bug #488477: apply_slice()
Guido van Rossum <guido@python.org>
parents:
21170
diff
changeset
|
4305 int res; |
| 19369 | 4306 if (x != NULL) |
|
21171
2458cbcc1dd3
Fix the final two issues in Armin Rigo's SF bug #488477: apply_slice()
Guido van Rossum <guido@python.org>
parents:
21170
diff
changeset
|
4307 res = PyObject_SetItem(u, slice, x); |
| 19369 | 4308 else |
|
21171
2458cbcc1dd3
Fix the final two issues in Armin Rigo's SF bug #488477: apply_slice()
Guido van Rossum <guido@python.org>
parents:
21170
diff
changeset
|
4309 res = PyObject_DelItem(u, slice); |
|
2458cbcc1dd3
Fix the final two issues in Armin Rigo's SF bug #488477: apply_slice()
Guido van Rossum <guido@python.org>
parents:
21170
diff
changeset
|
4310 Py_DECREF(slice); |
|
2458cbcc1dd3
Fix the final two issues in Armin Rigo's SF bug #488477: apply_slice()
Guido van Rossum <guido@python.org>
parents:
21170
diff
changeset
|
4311 return res; |
| 19369 | 4312 } |
| 4313 else | |
| 4314 return -1; | |
| 4315 } | |
| 69 | 4316 } |
| 4317 | |
|
45818
ff0ab7b28f49
- Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents:
45703
diff
changeset
|
4318 #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
|
4319 (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
|
4320 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
|
4321 |
|
ff0ab7b28f49
- Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents:
45703
diff
changeset
|
4322 #define CANNOT_CATCH_MSG "catching classes that don't inherit from " \ |
|
46075
84bb7701efba
Make Py3k warnings consistent w.r.t. punctuation; also respect the
Georg Brandl <georg@python.org>
parents:
45827
diff
changeset
|
4323 "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
|
4324 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
4325 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4326 cmp_outcome(int op, register PyObject *v, register PyObject *w) |
| 69 | 4327 { |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
4328 int res = 0; |
| 69 | 4329 switch (op) { |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
4330 case PyCmp_IS: |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
4331 res = (v == w); |
|
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
4332 break; |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
4333 case PyCmp_IS_NOT: |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
4334 res = (v != w); |
| 86 | 4335 break; |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
4336 case PyCmp_IN: |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
4337 res = PySequence_Contains(w, v); |
|
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
4338 if (res < 0) |
|
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
4339 return NULL; |
|
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
4340 break; |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
4341 case PyCmp_NOT_IN: |
|
8403
c4df8b6637b6
Moved cmp_member() to abstract.c, as PySequence_Contains() [with
Guido van Rossum <guido@python.org>
parents:
8328
diff
changeset
|
4342 res = PySequence_Contains(w, v); |
| 86 | 4343 if (res < 0) |
| 4344 return NULL; | |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
4345 res = !res; |
| 69 | 4346 break; |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
4347 case PyCmp_EXC_MATCH: |
|
40735
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4348 if (PyTuple_Check(w)) { |
|
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4349 Py_ssize_t i, length; |
|
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4350 length = PyTuple_Size(w); |
|
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4351 for (i = 0; i < length; i += 1) { |
|
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4352 PyObject *exc = PyTuple_GET_ITEM(w, i); |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4353 if (PyString_Check(exc)) { |
|
40735
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4354 int ret_val; |
|
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4355 ret_val = PyErr_WarnEx( |
|
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
|
4356 PyExc_DeprecationWarning, |
|
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
|
4357 "catching of string " |
|
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
|
4358 "exceptions is deprecated", 1); |
|
46578
7670005da8c5
A little reformating of Py3k warnings
Benjamin Peterson <benjamin@python.org>
parents:
46573
diff
changeset
|
4359 if (ret_val < 0) |
|
40735
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4360 return NULL; |
|
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4361 } |
|
45820
79fdc88ff9ec
Clean up the Py3k warnings for non-BaseException-subclasses a bit. We
Guido van Rossum <guido@python.org>
parents:
45818
diff
changeset
|
4362 else if (Py_Py3kWarningFlag && |
|
79fdc88ff9ec
Clean up the Py3k warnings for non-BaseException-subclasses a bit. We
Guido van Rossum <guido@python.org>
parents:
45818
diff
changeset
|
4363 !PyTuple_Check(exc) && |
|
79fdc88ff9ec
Clean up the Py3k warnings for non-BaseException-subclasses a bit. We
Guido van Rossum <guido@python.org>
parents:
45818
diff
changeset
|
4364 !Py3kExceptionClass_Check(exc)) |
|
45818
ff0ab7b28f49
- Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents:
45703
diff
changeset
|
4365 { |
|
ff0ab7b28f49
- Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents:
45703
diff
changeset
|
4366 int ret_val; |
|
ff0ab7b28f49
- Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents:
45703
diff
changeset
|
4367 ret_val = PyErr_WarnEx( |
|
ff0ab7b28f49
- Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents:
45703
diff
changeset
|
4368 PyExc_DeprecationWarning, |
|
ff0ab7b28f49
- Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents:
45703
diff
changeset
|
4369 CANNOT_CATCH_MSG, 1); |
|
46578
7670005da8c5
A little reformating of Py3k warnings
Benjamin Peterson <benjamin@python.org>
parents:
46573
diff
changeset
|
4370 if (ret_val < 0) |
|
45818
ff0ab7b28f49
- Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents:
45703
diff
changeset
|
4371 return NULL; |
|
ff0ab7b28f49
- Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents:
45703
diff
changeset
|
4372 } |
|
40735
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4373 } |
|
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4374 } |
|
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4375 else { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4376 if (PyString_Check(w)) { |
|
40735
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4377 int ret_val; |
|
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4378 ret_val = PyErr_WarnEx( |
|
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4379 PyExc_DeprecationWarning, |
|
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4380 "catching of string " |
|
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
|
4381 "exceptions is deprecated", 1); |
|
46578
7670005da8c5
A little reformating of Py3k warnings
Benjamin Peterson <benjamin@python.org>
parents:
46573
diff
changeset
|
4382 if (ret_val < 0) |
|
40735
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4383 return NULL; |
|
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4384 } |
|
45820
79fdc88ff9ec
Clean up the Py3k warnings for non-BaseException-subclasses a bit. We
Guido van Rossum <guido@python.org>
parents:
45818
diff
changeset
|
4385 else if (Py_Py3kWarningFlag && |
|
79fdc88ff9ec
Clean up the Py3k warnings for non-BaseException-subclasses a bit. We
Guido van Rossum <guido@python.org>
parents:
45818
diff
changeset
|
4386 !PyTuple_Check(w) && |
|
79fdc88ff9ec
Clean up the Py3k warnings for non-BaseException-subclasses a bit. We
Guido van Rossum <guido@python.org>
parents:
45818
diff
changeset
|
4387 !Py3kExceptionClass_Check(w)) |
|
45818
ff0ab7b28f49
- Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents:
45703
diff
changeset
|
4388 { |
|
ff0ab7b28f49
- Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents:
45703
diff
changeset
|
4389 int ret_val; |
|
ff0ab7b28f49
- Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents:
45703
diff
changeset
|
4390 ret_val = PyErr_WarnEx( |
|
ff0ab7b28f49
- Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents:
45703
diff
changeset
|
4391 PyExc_DeprecationWarning, |
|
ff0ab7b28f49
- Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents:
45703
diff
changeset
|
4392 CANNOT_CATCH_MSG, 1); |
|
46578
7670005da8c5
A little reformating of Py3k warnings
Benjamin Peterson <benjamin@python.org>
parents:
46573
diff
changeset
|
4393 if (ret_val < 0) |
|
45818
ff0ab7b28f49
- Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents:
45703
diff
changeset
|
4394 return NULL; |
|
ff0ab7b28f49
- Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents:
45703
diff
changeset
|
4395 } |
|
40735
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4396 } |
|
6147
b76a44163e0f
cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents:
6139
diff
changeset
|
4397 res = PyErr_GivenExceptionMatches(v, w); |
| 69 | 4398 break; |
| 4399 default: | |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
4400 return PyObject_RichCompare(v, w, op); |
| 69 | 4401 } |
| 5368 | 4402 v = res ? Py_True : Py_False; |
| 4403 Py_INCREF(v); | |
| 69 | 4404 return v; |
| 4405 } | |
| 4406 | |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
4407 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
|
4408 import_from(PyObject *v, PyObject *name) |
|
72
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
4409 { |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4410 PyObject *x; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4411 |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4412 x = PyObject_GetAttr(v, name); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4413 if (x == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) { |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
4414 PyErr_Format(PyExc_ImportError, |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
4415 "cannot import name %.230s", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4416 PyString_AsString(name)); |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4417 } |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
4418 return x; |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
4419 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
4420 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
4421 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
|
4422 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
|
4423 { |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4424 PyObject *all = PyObject_GetAttrString(v, "__all__"); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4425 PyObject *dict, *name, *value; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4426 int skip_leading_underscores = 0; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4427 int pos, err; |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
4428 |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4429 if (all == NULL) { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4430 if (!PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4431 return -1; /* Unexpected error */ |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4432 PyErr_Clear(); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4433 dict = PyObject_GetAttrString(v, "__dict__"); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4434 if (dict == NULL) { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4435 if (!PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4436 return -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4437 PyErr_SetString(PyExc_ImportError, |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4438 "from-import-* object has no __dict__ and no __all__"); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4439 return -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4440 } |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4441 all = PyMapping_Keys(dict); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4442 Py_DECREF(dict); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4443 if (all == NULL) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4444 return -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4445 skip_leading_underscores = 1; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
4446 } |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
4447 |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4448 for (pos = 0, err = 0; ; pos++) { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4449 name = PySequence_GetItem(all, pos); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4450 if (name == NULL) { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4451 if (!PyErr_ExceptionMatches(PyExc_IndexError)) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4452 err = -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4453 else |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4454 PyErr_Clear(); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4455 break; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4456 } |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4457 if (skip_leading_underscores && |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4458 PyString_Check(name) && |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4459 PyString_AS_STRING(name)[0] == '_') |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4460 { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4461 Py_DECREF(name); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4462 continue; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4463 } |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4464 value = PyObject_GetAttr(v, name); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4465 if (value == NULL) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4466 err = -1; |
|
40405
4e368e82c70d
Forgot a case where the locals can now be a general mapping
Armin Rigo <arigo@tunes.org>
parents:
40193
diff
changeset
|
4467 else if (PyDict_CheckExact(locals)) |
|
4e368e82c70d
Forgot a case where the locals can now be a general mapping
Armin Rigo <arigo@tunes.org>
parents:
40193
diff
changeset
|
4468 err = PyDict_SetItem(locals, name, value); |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4469 else |
|
40405
4e368e82c70d
Forgot a case where the locals can now be a general mapping
Armin Rigo <arigo@tunes.org>
parents:
40193
diff
changeset
|
4470 err = PyObject_SetItem(locals, name, value); |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4471 Py_DECREF(name); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4472 Py_XDECREF(value); |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
4473 if (err != 0) |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4474 break; |
|
72
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
4475 } |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4476 Py_DECREF(all); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4477 return err; |
|
72
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
4478 } |
|
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
4479 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
4480 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4481 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
|
4482 { |
|
19890
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
4483 PyObject *metaclass = NULL, *result, *base; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
4484 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
4485 if (PyDict_Check(methods)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
4486 metaclass = PyDict_GetItemString(methods, "__metaclass__"); |
|
19890
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
4487 if (metaclass != NULL) |
|
21252
e386f6e26a42
Fix a typo (probably caused by autocompletion <blush>) that caused a
Guido van Rossum <guido@python.org>
parents:
21251
diff
changeset
|
4488 Py_INCREF(metaclass); |
|
19890
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
4489 else if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0) { |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
4490 base = PyTuple_GET_ITEM(bases, 0); |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
4491 metaclass = PyObject_GetAttrString(base, "__class__"); |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
4492 if (metaclass == NULL) { |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
4493 PyErr_Clear(); |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
4494 metaclass = (PyObject *)base->ob_type; |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
4495 Py_INCREF(metaclass); |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
4496 } |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
4497 } |
|
19890
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
4498 else { |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
4499 PyObject *g = PyEval_GetGlobals(); |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
4500 if (g != NULL && PyDict_Check(g)) |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
4501 metaclass = PyDict_GetItemString(g, "__metaclass__"); |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
4502 if (metaclass == NULL) |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
4503 metaclass = (PyObject *) &PyClass_Type; |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
4504 Py_INCREF(metaclass); |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
4505 } |
| 40931 | 4506 result = PyObject_CallFunctionObjArgs(metaclass, name, bases, methods, |
| 43408 | 4507 NULL); |
|
19890
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
4508 Py_DECREF(metaclass); |
|
32247
a98f50e50bef
SF bug #963956: Bad error mesage when subclassing a module
Raymond Hettinger <python@rcn.com>
parents:
32175
diff
changeset
|
4509 if (result == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) { |
| 38418 | 4510 /* A type error here likely means that the user passed |
|
32247
a98f50e50bef
SF bug #963956: Bad error mesage when subclassing a module
Raymond Hettinger <python@rcn.com>
parents:
32175
diff
changeset
|
4511 in a base that was not a class (such the random module |
|
a98f50e50bef
SF bug #963956: Bad error mesage when subclassing a module
Raymond Hettinger <python@rcn.com>
parents:
32175
diff
changeset
|
4512 instead of the random.random type). Help them out with |
|
33501
af9bedd5a8e7
SF bug #1014215: Unspecific errors with metaclass
Raymond Hettinger <python@rcn.com>
parents:
33318
diff
changeset
|
4513 by augmenting the error message with more information.*/ |
|
af9bedd5a8e7
SF bug #1014215: Unspecific errors with metaclass
Raymond Hettinger <python@rcn.com>
parents:
33318
diff
changeset
|
4514 |
|
af9bedd5a8e7
SF bug #1014215: Unspecific errors with metaclass
Raymond Hettinger <python@rcn.com>
parents:
33318
diff
changeset
|
4515 PyObject *ptype, *pvalue, *ptraceback; |
|
af9bedd5a8e7
SF bug #1014215: Unspecific errors with metaclass
Raymond Hettinger <python@rcn.com>
parents:
33318
diff
changeset
|
4516 |
|
af9bedd5a8e7
SF bug #1014215: Unspecific errors with metaclass
Raymond Hettinger <python@rcn.com>
parents:
33318
diff
changeset
|
4517 PyErr_Fetch(&ptype, &pvalue, &ptraceback); |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4518 if (PyString_Check(pvalue)) { |
|
33501
af9bedd5a8e7
SF bug #1014215: Unspecific errors with metaclass
Raymond Hettinger <python@rcn.com>
parents:
33318
diff
changeset
|
4519 PyObject *newmsg; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4520 newmsg = PyString_FromFormat( |
| 40931 | 4521 "Error when calling the metaclass bases\n" |
| 43408 | 4522 " %s", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4523 PyString_AS_STRING(pvalue)); |
|
33501
af9bedd5a8e7
SF bug #1014215: Unspecific errors with metaclass
Raymond Hettinger <python@rcn.com>
parents:
33318
diff
changeset
|
4524 if (newmsg != NULL) { |
|
af9bedd5a8e7
SF bug #1014215: Unspecific errors with metaclass
Raymond Hettinger <python@rcn.com>
parents:
33318
diff
changeset
|
4525 Py_DECREF(pvalue); |
|
af9bedd5a8e7
SF bug #1014215: Unspecific errors with metaclass
Raymond Hettinger <python@rcn.com>
parents:
33318
diff
changeset
|
4526 pvalue = newmsg; |
|
af9bedd5a8e7
SF bug #1014215: Unspecific errors with metaclass
Raymond Hettinger <python@rcn.com>
parents:
33318
diff
changeset
|
4527 } |
|
af9bedd5a8e7
SF bug #1014215: Unspecific errors with metaclass
Raymond Hettinger <python@rcn.com>
parents:
33318
diff
changeset
|
4528 } |
|
af9bedd5a8e7
SF bug #1014215: Unspecific errors with metaclass
Raymond Hettinger <python@rcn.com>
parents:
33318
diff
changeset
|
4529 PyErr_Restore(ptype, pvalue, ptraceback); |
|
32247
a98f50e50bef
SF bug #963956: Bad error mesage when subclassing a module
Raymond Hettinger <python@rcn.com>
parents:
32175
diff
changeset
|
4530 } |
|
19890
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
4531 return result; |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
4532 } |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
4533 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
4534 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4535 exec_statement(PyFrameObject *f, PyObject *prog, PyObject *globals, |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4536 PyObject *locals) |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4537 { |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4538 int n; |
| 5368 | 4539 PyObject *v; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4540 int plain = 0; |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4541 |
| 5368 | 4542 if (PyTuple_Check(prog) && globals == Py_None && locals == Py_None && |
| 4543 ((n = PyTuple_Size(prog)) == 2 || n == 3)) { | |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4544 /* Backward compatibility hack */ |
| 5368 | 4545 globals = PyTuple_GetItem(prog, 1); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4546 if (n == 3) |
| 5368 | 4547 locals = PyTuple_GetItem(prog, 2); |
| 4548 prog = PyTuple_GetItem(prog, 0); | |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4549 } |
| 5368 | 4550 if (globals == Py_None) { |
| 4551 globals = PyEval_GetGlobals(); | |
| 4552 if (locals == Py_None) { | |
| 4553 locals = PyEval_GetLocals(); | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4554 plain = 1; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4555 } |
|
39466
c7ff02c1559f
Move/copy assert for tstate != NULL before first use.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39463
diff
changeset
|
4556 if (!globals || !locals) { |
|
c7ff02c1559f
Move/copy assert for tstate != NULL before first use.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39463
diff
changeset
|
4557 PyErr_SetString(PyExc_SystemError, |
|
c7ff02c1559f
Move/copy assert for tstate != NULL before first use.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39463
diff
changeset
|
4558 "globals and locals cannot be NULL"); |
|
c7ff02c1559f
Move/copy assert for tstate != NULL before first use.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39463
diff
changeset
|
4559 return -1; |
|
c7ff02c1559f
Move/copy assert for tstate != NULL before first use.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39463
diff
changeset
|
4560 } |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4561 } |
| 5368 | 4562 else if (locals == Py_None) |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4563 locals = globals; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4564 if (!PyString_Check(prog) && |
|
51032
551257c8058a
fix building the core with --disable-unicode
Benjamin Peterson <benjamin@python.org>
parents:
50936
diff
changeset
|
4565 #ifdef Py_USING_UNICODE |
|
14696
85038a024b19
This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents:
14375
diff
changeset
|
4566 !PyUnicode_Check(prog) && |
|
51032
551257c8058a
fix building the core with --disable-unicode
Benjamin Peterson <benjamin@python.org>
parents:
50936
diff
changeset
|
4567 #endif |
| 5368 | 4568 !PyCode_Check(prog) && |
| 4569 !PyFile_Check(prog)) { | |
| 4570 PyErr_SetString(PyExc_TypeError, | |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
4571 "exec: arg 1 must be a string, file, or code object"); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4572 return -1; |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4573 } |
| 15318 | 4574 if (!PyDict_Check(globals)) { |
| 5368 | 4575 PyErr_SetString(PyExc_TypeError, |
| 15318 | 4576 "exec: arg 2 must be a dictionary or None"); |
| 4577 return -1; | |
| 4578 } | |
|
32890
b8c2aa2be19a
Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents:
32531
diff
changeset
|
4579 if (!PyMapping_Check(locals)) { |
| 15318 | 4580 PyErr_SetString(PyExc_TypeError, |
|
32890
b8c2aa2be19a
Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents:
32531
diff
changeset
|
4581 "exec: arg 3 must be a mapping or None"); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4582 return -1; |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4583 } |
| 5368 | 4584 if (PyDict_GetItemString(globals, "__builtins__") == NULL) |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
4585 PyDict_SetItemString(globals, "__builtins__", f->f_builtins); |
| 5368 | 4586 if (PyCode_Check(prog)) { |
|
21398
de125792bfaa
Fix for SF bug [ #492403 ] exec() segfaults on closure's func_code
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21270
diff
changeset
|
4587 if (PyCode_GetNumFree((PyCodeObject *)prog) > 0) { |
|
de125792bfaa
Fix for SF bug [ #492403 ] exec() segfaults on closure's func_code
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21270
diff
changeset
|
4588 PyErr_SetString(PyExc_TypeError, |
|
de125792bfaa
Fix for SF bug [ #492403 ] exec() segfaults on closure's func_code
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21270
diff
changeset
|
4589 "code object passed to exec may not contain free variables"); |
|
de125792bfaa
Fix for SF bug [ #492403 ] exec() segfaults on closure's func_code
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21270
diff
changeset
|
4590 return -1; |
|
de125792bfaa
Fix for SF bug [ #492403 ] exec() segfaults on closure's func_code
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21270
diff
changeset
|
4591 } |
|
11651
d88996e46cb2
Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents:
11468
diff
changeset
|
4592 v = PyEval_EvalCode((PyCodeObject *) prog, globals, locals); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4593 } |
|
11651
d88996e46cb2
Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents:
11468
diff
changeset
|
4594 else if (PyFile_Check(prog)) { |
| 5368 | 4595 FILE *fp = PyFile_AsFile(prog); |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4596 char *name = PyString_AsString(PyFile_Name(prog)); |
|
40904
191c48ca8bf9
Put declarations before code.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40903
diff
changeset
|
4597 PyCompilerFlags cf; |
| 43408 | 4598 if (name == NULL) |
| 4599 return -1; | |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
4600 cf.cf_flags = 0; |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
4601 if (PyEval_MergeCompilerFlags(&cf)) |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4602 v = PyRun_FileFlags(fp, name, Py_file_input, globals, |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
4603 locals, &cf); |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
4604 else |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4605 v = PyRun_File(fp, name, Py_file_input, globals, |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
4606 locals); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4607 } |
|
11651
d88996e46cb2
Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents:
11468
diff
changeset
|
4608 else { |
|
27781
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4609 PyObject *tmp = NULL; |
|
14696
85038a024b19
This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents:
14375
diff
changeset
|
4610 char *str; |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
4611 PyCompilerFlags cf; |
|
27781
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4612 cf.cf_flags = 0; |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4613 #ifdef Py_USING_UNICODE |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4614 if (PyUnicode_Check(prog)) { |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4615 tmp = PyUnicode_AsUTF8String(prog); |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4616 if (tmp == NULL) |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4617 return -1; |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4618 prog = tmp; |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4619 cf.cf_flags |= PyCF_SOURCE_IS_UTF8; |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4620 } |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4621 #endif |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4622 if (PyString_AsStringAndSize(prog, &str, NULL)) |
|
11651
d88996e46cb2
Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents:
11468
diff
changeset
|
4623 return -1; |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
4624 if (PyEval_MergeCompilerFlags(&cf)) |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
4625 v = PyRun_StringFlags(str, Py_file_input, globals, |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4626 locals, &cf); |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
4627 else |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4628 v = PyRun_String(str, Py_file_input, globals, locals); |
|
27781
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4629 Py_XDECREF(tmp); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4630 } |
|
11651
d88996e46cb2
Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents:
11468
diff
changeset
|
4631 if (plain) |
|
d88996e46cb2
Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents:
11468
diff
changeset
|
4632 PyFrame_LocalsToFast(f, 0); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4633 if (v == NULL) |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4634 return -1; |
| 5368 | 4635 Py_DECREF(v); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4636 return 0; |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4637 } |
|
2338
4c2f1452125d
call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents:
2310
diff
changeset
|
4638 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
4639 static void |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4640 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
|
4641 { |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4642 char *obj_str; |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4643 |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4644 if (!obj) |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4645 return; |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4646 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4647 obj_str = PyString_AsString(obj); |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4648 if (!obj_str) |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4649 return; |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4650 |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4651 PyErr_Format(exc, format_str, obj_str); |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4652 } |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4653 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
4654 static PyObject * |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4655 string_concatenate(PyObject *v, PyObject *w, |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4656 PyFrameObject *f, unsigned char *next_instr) |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4657 { |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4658 /* This function implements 'variable += expr' when both arguments |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4659 are strings. */ |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4660 Py_ssize_t v_len = PyString_GET_SIZE(v); |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4661 Py_ssize_t w_len = PyString_GET_SIZE(w); |
|
39417
74d23cd04421
Concatenation on a long string breaks (SF #1526585).
Armin Rigo <arigo@tunes.org>
parents:
38768
diff
changeset
|
4662 Py_ssize_t new_len = v_len + w_len; |
|
74d23cd04421
Concatenation on a long string breaks (SF #1526585).
Armin Rigo <arigo@tunes.org>
parents:
38768
diff
changeset
|
4663 if (new_len < 0) { |
|
74d23cd04421
Concatenation on a long string breaks (SF #1526585).
Armin Rigo <arigo@tunes.org>
parents:
38768
diff
changeset
|
4664 PyErr_SetString(PyExc_OverflowError, |
|
74d23cd04421
Concatenation on a long string breaks (SF #1526585).
Armin Rigo <arigo@tunes.org>
parents:
38768
diff
changeset
|
4665 "strings are too large to concat"); |
|
74d23cd04421
Concatenation on a long string breaks (SF #1526585).
Armin Rigo <arigo@tunes.org>
parents:
38768
diff
changeset
|
4666 return NULL; |
|
74d23cd04421
Concatenation on a long string breaks (SF #1526585).
Armin Rigo <arigo@tunes.org>
parents:
38768
diff
changeset
|
4667 } |
| 38418 | 4668 |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4669 if (v->ob_refcnt == 2) { |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4670 /* In the common case, there are 2 references to the value |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4671 * stored in 'variable' when the += is performed: one on the |
|
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
|
4672 * value stack (in 'v') and one still stored in the |
|
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
|
4673 * 'variable'. We try to delete the variable now to reduce |
|
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
|
4674 * the refcnt to 1. |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4675 */ |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4676 switch (*next_instr) { |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4677 case STORE_FAST: |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4678 { |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4679 int oparg = PEEKARG(); |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4680 PyObject **fastlocals = f->f_localsplus; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4681 if (GETLOCAL(oparg) == v) |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4682 SETLOCAL(oparg, NULL); |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4683 break; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4684 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4685 case STORE_DEREF: |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4686 { |
|
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
|
4687 PyObject **freevars = (f->f_localsplus + |
|
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
|
4688 f->f_code->co_nlocals); |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4689 PyObject *c = freevars[PEEKARG()]; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4690 if (PyCell_GET(c) == v) |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4691 PyCell_Set(c, NULL); |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4692 break; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4693 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4694 case STORE_NAME: |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4695 { |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4696 PyObject *names = f->f_code->co_names; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4697 PyObject *name = GETITEM(names, PEEKARG()); |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4698 PyObject *locals = f->f_locals; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4699 if (PyDict_CheckExact(locals) && |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4700 PyDict_GetItem(locals, name) == v) { |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4701 if (PyDict_DelItem(locals, name) != 0) { |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4702 PyErr_Clear(); |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4703 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4704 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4705 break; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4706 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4707 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4708 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4709 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4710 if (v->ob_refcnt == 1 && !PyString_CHECK_INTERNED(v)) { |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4711 /* Now we own the last reference to 'v', so we can resize it |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4712 * in-place. |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4713 */ |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4714 if (_PyString_Resize(&v, new_len) != 0) { |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4715 /* XXX if _PyString_Resize() fails, 'v' has been |
|
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
|
4716 * deallocated so it cannot be put back into |
|
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
|
4717 * 'variable'. The MemoryError is raised when there |
|
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
|
4718 * is no value in 'variable', which might (very |
|
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
|
4719 * remotely) be a cause of incompatibilities. |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4720 */ |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4721 return NULL; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4722 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4723 /* copy 'w' into the newly allocated area of 'v' */ |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4724 memcpy(PyString_AS_STRING(v) + v_len, |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4725 PyString_AS_STRING(w), w_len); |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4726 return v; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4727 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4728 else { |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4729 /* When in-place resizing is not an option. */ |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4730 PyString_Concat(&v, w); |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4731 return v; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4732 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4733 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4734 |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4735 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4736 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
4737 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4738 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
|
4739 { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4740 int i; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4741 PyObject *l = PyList_New(256); |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4742 if (l == NULL) return NULL; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4743 for (i = 0; i < 256; i++) { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4744 PyObject *x = PyInt_FromLong(a[i]); |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4745 if (x == NULL) { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4746 Py_DECREF(l); |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4747 return NULL; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4748 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4749 PyList_SetItem(l, i, x); |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4750 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4751 for (i = 0; i < 256; i++) |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4752 a[i] = 0; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4753 return l; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4754 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4755 |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4756 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4757 _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
|
4758 { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4759 #ifndef DXPAIRS |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4760 return getarray(dxp); |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4761 #else |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4762 int i; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4763 PyObject *l = PyList_New(257); |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4764 if (l == NULL) return NULL; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4765 for (i = 0; i < 257; i++) { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4766 PyObject *x = getarray(dxpairs[i]); |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4767 if (x == NULL) { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4768 Py_DECREF(l); |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4769 return NULL; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4770 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4771 PyList_SetItem(l, i, x); |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4772 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4773 return l; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4774 #endif |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4775 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4776 |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4777 #endif |
