Mercurial > cpython-lru_cache-weakref
annotate Python/ceval.c @ 50092:dc696deb2cf2 legacy-trunk
Issue 4597: Fix several cases in EvalFrameEx where an exception could be
"raised" without setting x, err, or why to let the eval loop know.
| author | Jeffrey Yasskin <jyasskin@gmail.com> |
|---|---|
| date | Mon, 08 Dec 2008 18:55:24 +0000 |
| parents | 3344804f327d |
| children | 9a10d4404bd0 |
| 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 *); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
130 |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
131 #define NAME_ERROR_MSG \ |
| 15318 | 132 "name '%.200s' is not defined" |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
133 #define GLOBAL_NAME_ERROR_MSG \ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
134 "global name '%.200s' is not defined" |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
135 #define UNBOUNDLOCAL_ERROR_MSG \ |
| 15318 | 136 "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
|
137 #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
|
138 "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
|
139 " in enclosing scope" |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
140 |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
141 /* Dynamic execution profile */ |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
142 #ifdef 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 DXPAIRS |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
144 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
|
145 #define dxp dxpairs[256] |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
146 #else |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
147 static long dxp[256]; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
148 #endif |
|
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 |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
151 /* 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
|
152 #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
|
153 #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
|
154 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
|
155 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
156 #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
|
157 #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
|
158 #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
|
159 #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
|
160 #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
|
161 #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
|
162 #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
|
163 #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
|
164 #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
|
165 #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
|
166 #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
|
167 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
168 /* 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
|
169 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
170 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
|
171 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
172 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
|
173 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
|
174 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
175 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
|
176 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
|
177 twice. |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
178 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
179 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
|
180 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
|
181 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
|
182 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
|
183 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
|
184 */ |
|
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 #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
|
187 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
188 PyObject * |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
189 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
|
190 { |
|
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
|
191 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
|
192 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
|
193 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
|
194 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
|
195 } |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
196 #else |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
197 #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
|
198 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
199 PyObject * |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
200 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
|
201 { |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
202 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
|
203 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
|
204 } |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
205 #endif |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
206 |
|
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
|
207 |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
208 #ifdef WITH_THREAD |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
209 |
|
38716
42808526511c
Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents:
38536
diff
changeset
|
210 #ifdef HAVE_ERRNO_H |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
211 #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
|
212 #endif |
|
9203
07dae6fdae79
Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents:
9048
diff
changeset
|
213 #include "pythread.h" |
| 926 | 214 |
|
29643
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
215 static PyThread_type_lock interpreter_lock = 0; /* This is the GIL */ |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
216 static long main_thread = 0; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
217 |
|
33715
a46b76eb9053
SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents:
33501
diff
changeset
|
218 int |
|
a46b76eb9053
SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents:
33501
diff
changeset
|
219 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
|
220 { |
|
a46b76eb9053
SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents:
33501
diff
changeset
|
221 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
|
222 } |
|
a46b76eb9053
SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents:
33501
diff
changeset
|
223 |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
224 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
225 PyEval_InitThreads(void) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
226 { |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
227 if (interpreter_lock) |
| 1179 | 228 return; |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
229 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
|
230 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
|
231 main_thread = PyThread_get_thread_ident(); |
| 926 | 232 } |
| 233 | |
|
5865
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
234 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
235 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
|
236 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
237 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
|
238 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
239 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
240 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
241 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
|
242 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
243 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
|
244 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
245 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
246 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
247 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
|
248 { |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
249 if (tstate == NULL) |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
250 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
|
251 /* 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
|
252 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
|
253 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
|
254 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
|
255 Py_FatalError( |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
256 "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
|
257 } |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
258 |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
259 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
260 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
|
261 { |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
262 if (tstate == NULL) |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
263 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
|
264 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
|
265 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
|
266 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
|
267 } |
|
14225
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
268 |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
269 /* 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
|
270 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
|
271 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
|
272 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
|
273 |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
274 void |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
275 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
|
276 { |
|
47985
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
277 PyObject *threading, *result; |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
278 PyThreadState *tstate; |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
279 |
|
14225
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
280 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
|
281 return; |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
282 /*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
|
283 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
|
284 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
|
285 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
|
286 interpreter_lock = PyThread_allocate_lock(); |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
287 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
|
288 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
|
289 |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
290 /* 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
|
291 */ |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
292 tstate = PyThreadState_GET(); |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
293 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
|
294 "threading"); |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
295 if (threading == NULL) { |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
296 /* threading not imported */ |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
297 PyErr_Clear(); |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
298 return; |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
299 } |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
300 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
|
301 if (result == NULL) |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
302 PyErr_WriteUnraisable(threading); |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
303 else |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
304 Py_DECREF(result); |
|
09beb96ba20d
Apply patch for 874900: threading module can deadlock after fork
Jesse Noller <jnoller@gmail.com>
parents:
47886
diff
changeset
|
305 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
|
306 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
307 #endif |
| 926 | 308 |
| 309 /* Functions save_thread and restore_thread are always defined so | |
| 310 dynamically loaded modules needn't be compiled separately for use | |
| 311 with and without threads: */ | |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
312 |
|
5846
852a1fa62a7c
PyEval_SaveThread() and PyEval_RestoreThread() now return/take a
Guido van Rossum <guido@python.org>
parents:
5829
diff
changeset
|
313 PyThreadState * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
314 PyEval_SaveThread(void) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
315 { |
|
6365
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
316 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
|
317 if (tstate == NULL) |
|
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
318 Py_FatalError("PyEval_SaveThread: NULL tstate"); |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
319 #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
|
320 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
|
321 PyThread_release_lock(interpreter_lock); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
322 #endif |
|
6365
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
323 return tstate; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
324 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
325 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
326 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
327 PyEval_RestoreThread(PyThreadState *tstate) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
328 { |
|
6365
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
329 if (tstate == NULL) |
|
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
330 Py_FatalError("PyEval_RestoreThread: NULL tstate"); |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
331 #ifdef WITH_THREAD |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
332 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
|
333 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
|
334 PyThread_acquire_lock(interpreter_lock, 1); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
335 errno = err; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
336 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
337 #endif |
|
6365
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
338 PyThreadState_Swap(tstate); |
|
923
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 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
341 |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
342 /* 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
|
343 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
|
344 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
|
345 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
|
346 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
|
347 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
|
348 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
349 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
|
350 (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
|
351 an exception condition). |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
352 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
353 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
|
354 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
|
355 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
356 #ifdef WITH_THREAD |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
357 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
|
358 will execute them. |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
359 #endif |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
360 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
361 XXX WARNING! ASYNCHRONOUSLY EXECUTING CODE! |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
362 There are two possible race conditions: |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
363 (1) nested asynchronous registry calls; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
364 (2) registry calls made while pending calls are being processed. |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
365 While (1) is very unlikely, (2) is a real possibility. |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
366 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
|
367 The safety against (2) is derived from the fact that only one |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
368 thread (the main thread) ever takes things out of the queue. |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
369 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
370 XXX Darn! With the advent of thread state, we should have an array |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
371 of pending calls per thread in the thread state! Later... |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
372 */ |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
373 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
374 #define NPENDINGCALLS 32 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
375 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
|
376 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
|
377 void *arg; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
378 } pendingcalls[NPENDINGCALLS]; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
379 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
|
380 static volatile int pendinglast = 0; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
381 static volatile int things_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
|
382 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
383 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
|
384 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
|
385 { |
| 32526 | 386 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
|
387 int i, j; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
388 /* XXX Begin critical section */ |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
389 /* XXX If you want this to be safe against nested |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
390 XXX asynchronous calls, you'll have to work harder! */ |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
391 if (busy) |
|
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
392 return -1; |
|
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
393 busy = 1; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
394 i = pendinglast; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
395 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
|
396 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
|
397 busy = 0; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
398 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
|
399 } |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
400 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
|
401 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
|
402 pendinglast = j; |
|
25108
3a26e352f0a6
replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents:
25078
diff
changeset
|
403 |
|
3a26e352f0a6
replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents:
25078
diff
changeset
|
404 _Py_Ticker = 0; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
405 things_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
|
406 busy = 0; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
407 /* 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
|
408 return 0; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
409 } |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
410 |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
411 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
412 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
|
413 { |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
414 static 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
|
415 #ifdef WITH_THREAD |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
416 if (main_thread && PyThread_get_thread_ident() != main_thread) |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
417 return 0; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
418 #endif |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
419 if (busy) |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
420 return 0; |
|
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
421 busy = 1; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
422 things_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
|
423 for (;;) { |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
424 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
|
425 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
|
426 void *arg; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
427 i = pendingfirst; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
428 if (i == pendinglast) |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
429 break; /* Queue empty */ |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
430 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
|
431 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
|
432 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
|
433 if (func(arg) < 0) { |
|
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
434 busy = 0; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
435 things_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
|
436 return -1; |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
437 } |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
438 } |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
439 busy = 0; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
440 return 0; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
441 } |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
442 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
443 |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
444 /* The interpreter's recursion limit */ |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
445 |
|
34863
71fd7ee4b7f5
Make a handy macro, Py_DEFAULT_RECURSION_LIMIT to allow to define
Hye-Shik Chang <hyeshik@gmail.com>
parents:
34442
diff
changeset
|
446 #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
|
447 #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
|
448 #endif |
|
71fd7ee4b7f5
Make a handy macro, Py_DEFAULT_RECURSION_LIMIT to allow to define
Hye-Shik Chang <hyeshik@gmail.com>
parents:
34442
diff
changeset
|
449 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
|
450 int _Py_CheckRecursionLimit = Py_DEFAULT_RECURSION_LIMIT; |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
451 |
|
14348
6d0f64f7dedd
Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14333
diff
changeset
|
452 int |
|
6d0f64f7dedd
Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14333
diff
changeset
|
453 Py_GetRecursionLimit(void) |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
454 { |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
455 return recursion_limit; |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
456 } |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
457 |
|
14348
6d0f64f7dedd
Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14333
diff
changeset
|
458 void |
|
6d0f64f7dedd
Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14333
diff
changeset
|
459 Py_SetRecursionLimit(int new_limit) |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
460 { |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
461 recursion_limit = new_limit; |
| 43408 | 462 _Py_CheckRecursionLimit = recursion_limit; |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
463 } |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
464 |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
465 /* the macro Py_EnterRecursiveCall() only calls _Py_CheckRecursiveCall() |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
466 if the recursion_depth reaches _Py_CheckRecursionLimit. |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
467 If USE_STACKCHECK, the macro decrements _Py_CheckRecursionLimit |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
468 to guarantee that _Py_CheckRecursiveCall() is regularly called. |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
469 Without USE_STACKCHECK, there is no need for this. */ |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
470 int |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
471 _Py_CheckRecursiveCall(char *where) |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
472 { |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
473 PyThreadState *tstate = PyThreadState_GET(); |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
474 |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
475 #ifdef USE_STACKCHECK |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
476 if (PyOS_CheckStack()) { |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
477 --tstate->recursion_depth; |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
478 PyErr_SetString(PyExc_MemoryError, "Stack overflow"); |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
479 return -1; |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
480 } |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
481 #endif |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
482 if (tstate->recursion_depth > recursion_limit) { |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
483 --tstate->recursion_depth; |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
484 PyErr_Format(PyExc_RuntimeError, |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
485 "maximum recursion depth exceeded%s", |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
486 where); |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
487 return -1; |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
488 } |
| 43408 | 489 _Py_CheckRecursionLimit = recursion_limit; |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
490 return 0; |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
491 } |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
492 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
493 /* 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
|
494 enum why_code { |
|
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
495 WHY_NOT = 0x0001, /* No error */ |
|
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
496 WHY_EXCEPTION = 0x0002, /* Exception occurred */ |
|
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
497 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
|
498 WHY_RETURN = 0x0008, /* 'return' statement */ |
|
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
499 WHY_BREAK = 0x0010, /* 'break' statement */ |
|
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
500 WHY_CONTINUE = 0x0020, /* 'continue' statement */ |
|
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
501 WHY_YIELD = 0x0040 /* 'yield' operator */ |
|
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
502 }; |
|
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
503 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
504 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
|
505 static int unpack_iterable(PyObject *, int, PyObject **); |
| 5018 | 506 |
|
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
|
507 /* 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
|
508 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
|
509 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
|
510 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
|
511 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
|
512 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
|
513 |
|
25108
3a26e352f0a6
replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents:
25078
diff
changeset
|
514 /* 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
|
515 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
|
516 int _Py_CheckInterval = 100; |
|
00b6dd414b80
Bump default check interval to 100 instructions. Computers are much faster
Skip Montanaro <skip@pobox.com>
parents:
25108
diff
changeset
|
517 volatile int _Py_Ticker = 100; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
518 |
| 5368 | 519 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
520 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
|
521 { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
522 return PyEval_EvalCodeEx(co, |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
523 globals, locals, |
| 5368 | 524 (PyObject **)NULL, 0, |
| 525 (PyObject **)NULL, 0, | |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
526 (PyObject **)NULL, 0, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
527 NULL); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
528 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
529 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
530 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
531 /* Interpreter main loop */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
532 |
|
32421
485d2ef43419
Patch #966493: Cleanup generator/eval_frame exposure.
Martin v. Löwis <martin@v.loewis.de>
parents:
32412
diff
changeset
|
533 PyObject * |
|
35298
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
534 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
|
535 /* 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
|
536 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
|
537 PyEval_EvalFrameEx() */ |
|
35298
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
538 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
|
539 } |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
540 |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
541 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
|
542 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
|
543 { |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
544 #ifdef DXPAIRS |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
545 int lastopcode = 0; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
546 #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
|
547 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
|
548 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
|
549 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
|
550 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
|
551 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
|
552 register int err; /* Error status -- nonzero if error */ |
| 5368 | 553 register PyObject *x; /* Result object -- NULL if error */ |
| 554 register PyObject *v; /* Temporary objects popped off stack */ | |
| 555 register PyObject *w; | |
| 556 register PyObject *u; | |
| 557 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
|
558 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
|
559 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
|
560 PyObject *retval = NULL; /* Return value */ |
|
9671
1d40bc25703a
Use PyThreadState_GET() macro.
Guido van Rossum <guido@python.org>
parents:
9591
diff
changeset
|
561 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
|
562 PyCodeObject *co; |
| 24844 | 563 |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
564 /* when tracing we set things up so that |
| 24844 | 565 |
| 566 not (instr_lb <= current_bytecode_offset < instr_ub) | |
| 567 | |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
568 is true when the line being executed has changed. The |
| 24844 | 569 initial values are such as to make this false the first |
| 570 time it is tested. */ | |
| 31768 | 571 int instr_ub = -1, instr_lb = 0, instr_prev = -1; |
| 24844 | 572 |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
573 unsigned char *first_instr; |
|
24545
d2f41c8a81f0
small speedup for constant and name access
Skip Montanaro <skip@pobox.com>
parents:
24284
diff
changeset
|
574 PyObject *names; |
|
d2f41c8a81f0
small speedup for constant and name access
Skip Montanaro <skip@pobox.com>
parents:
24284
diff
changeset
|
575 PyObject *consts; |
|
35745
407c3dacbd7c
Fix some mods that got dropped from the AST merge
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
576 #if defined(Py_DEBUG) || defined(LLTRACE) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
577 /* 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
|
578 char *filename; |
|
1016
a41e3ba5b47d
Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents:
974
diff
changeset
|
579 #endif |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
580 |
|
24232
e06b1ab0bdb8
SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents:
24190
diff
changeset
|
581 /* 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
|
582 |
|
e06b1ab0bdb8
SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents:
24190
diff
changeset
|
583 #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
|
584 #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
|
585 #else |
|
e06b1ab0bdb8
SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents:
24190
diff
changeset
|
586 #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
|
587 #endif |
|
e06b1ab0bdb8
SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents:
24190
diff
changeset
|
588 |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
589 #ifdef WITH_TSC |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
590 /* 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
|
591 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
|
592 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
|
593 loop0 -- the top of the mainloop |
| 38418 | 594 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
|
595 (may be skipped) |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
596 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
|
597 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
|
598 |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
599 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
|
600 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
|
601 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
|
602 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
|
603 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
|
604 |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
605 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
|
606 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
|
607 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
|
608 |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
609 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
|
610 cases: |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
611 |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
612 EXEC_STMT |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
613 IMPORT_STAR |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
614 IMPORT_FROM |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
615 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
|
616 |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
617 */ |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
618 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
|
619 int ticked = 0; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
620 |
|
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
|
621 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
|
622 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
|
623 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
|
624 READ_TIMESTAMP(loop1); |
| 33104 | 625 |
| 626 /* shut up the compiler */ | |
| 627 opcode = 0; | |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
628 #endif |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
629 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
630 /* Code access macros */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
631 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36475
diff
changeset
|
632 #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
|
633 #define NEXTOP() (*next_instr++) |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
634 #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
|
635 #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
|
636 #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
|
637 #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
|
638 |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
639 /* 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
|
640 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
|
641 predict the second code when the first is run. For example, |
|
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
|
642 COMPARE_OP is often followed by JUMP_IF_FALSE or JUMP_IF_TRUE. And, |
|
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
|
643 those opcodes are often followed by a POP_TOP. |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
644 |
|
47886
c93596ec1d3d
Update comment on prediction macros.
Raymond Hettinger <python@rcn.com>
parents:
47868
diff
changeset
|
645 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
|
646 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
|
647 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
|
648 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
|
649 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
|
650 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
|
651 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
|
652 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
|
653 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
|
654 |
|
c93596ec1d3d
Update comment on prediction macros.
Raymond Hettinger <python@rcn.com>
parents:
47868
diff
changeset
|
655 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
|
656 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
|
657 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
|
658 counter updates for both opcodes. |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
659 */ |
|
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
660 |
|
31487
f57f5ce22c8d
SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents:
31462
diff
changeset
|
661 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
f57f5ce22c8d
SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents:
31462
diff
changeset
|
662 #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
|
663 #else |
|
28303
470504ef578b
Fix comment and whitespace.
Raymond Hettinger <python@rcn.com>
parents:
28302
diff
changeset
|
664 #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
|
665 #endif |
|
f57f5ce22c8d
SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents:
31462
diff
changeset
|
666 |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
667 #define PREDICTED(op) PRED_##op: next_instr++ |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
668 #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
|
669 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
670 /* Stack manipulation macros */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
671 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36475
diff
changeset
|
672 /* 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
|
673 co_stacksize are ints. */ |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36475
diff
changeset
|
674 #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
|
675 #define EMPTY() (STACK_LEVEL() == 0) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
676 #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
|
677 #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
|
678 #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
|
679 #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
|
680 #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
|
681 #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
|
682 #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
|
683 #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
|
684 #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
|
685 #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
|
686 #define BASIC_POP() (*--stack_pointer) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
687 |
| 567 | 688 #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
|
689 #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
|
690 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
|
691 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
|
692 #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
|
693 BASIC_POP()) |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
694 #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
|
695 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
|
696 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
|
697 #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
|
698 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
|
699 *--(STACK_POINTER)) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
700 #else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
701 #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
|
702 #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
|
703 #define STACKADJ(n) BASIC_STACKADJ(n) |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
704 #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
|
705 #endif |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
706 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
707 /* Local variable macros */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
708 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
709 #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
|
710 |
|
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
|
711 /* 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
|
712 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
|
713 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
|
714 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
|
715 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
|
716 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
|
717 #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
|
718 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
|
719 Py_XDECREF(tmp); } while (0) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
720 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
721 /* Start of code */ |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
722 |
|
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
|
723 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
|
724 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
|
725 |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
726 /* push frame */ |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
727 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
|
728 return NULL; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
729 |
|
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
|
730 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
|
731 |
|
19692
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
732 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
|
733 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
|
734 /* 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
|
735 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
|
736 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
|
737 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
|
738 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
|
739 (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
|
740 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
|
741 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
|
742 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
|
743 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
|
744 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
|
745 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
|
746 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
|
747 if (call_trace_protected(tstate->c_tracefunc, |
|
43845
76844a0a579f
Merge from py3k branch:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43784
diff
changeset
|
748 tstate->c_traceobj, |
|
76844a0a579f
Merge from py3k branch:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43784
diff
changeset
|
749 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
|
750 /* Trace function raised an error */ |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
751 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
|
752 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
753 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
754 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
|
755 /* 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
|
756 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
|
757 if (call_trace_protected(tstate->c_profilefunc, |
|
76844a0a579f
Merge from py3k branch:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43784
diff
changeset
|
758 tstate->c_profileobj, |
|
76844a0a579f
Merge from py3k branch:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43784
diff
changeset
|
759 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
|
760 /* Profile function raised an error */ |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
761 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
|
762 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
763 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
764 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
765 |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
766 co = f->f_code; |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
767 names = co->co_names; |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
768 consts = co->co_consts; |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
769 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
|
770 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
|
771 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
|
772 /* 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
|
773 |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
774 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
|
775 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
|
776 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
|
777 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
|
778 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
|
779 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
|
780 |
|
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
|
781 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
|
782 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
|
783 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
|
784 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
|
785 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
|
786 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
|
787 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
|
788 */ |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
789 next_instr = first_instr + f->f_lasti + 1; |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
790 stack_pointer = f->f_stacktop; |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
791 assert(stack_pointer != NULL); |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
792 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
|
793 |
|
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
|
794 #ifdef LLTRACE |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
795 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
|
796 #endif |
|
35745
407c3dacbd7c
Fix some mods that got dropped from the AST merge
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
797 #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
|
798 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
|
799 #endif |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
800 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
801 why = WHY_NOT; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
802 err = 0; |
| 5368 | 803 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
|
804 w = NULL; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
805 |
|
37597
2b2e9c388fbb
low-hanging fruit in Python/ - g++ still hates all the enum_kind declarations
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37564
diff
changeset
|
806 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
|
807 why = WHY_EXCEPTION; |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
808 goto on_error; |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
809 } |
| 38418 | 810 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
811 for (;;) { |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
812 #ifdef WITH_TSC |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
813 if (inst1 == 0) { |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
814 /* 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
|
815 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
|
816 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
|
817 */ |
|
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
|
818 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
|
819 loop1 = inst1; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
820 } |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
821 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
|
822 intr0, intr1); |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
823 ticked = 0; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
824 inst1 = 0; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
825 intr0 = 0; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
826 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
|
827 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
|
828 #endif |
| 24844 | 829 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
|
830 assert(STACK_LEVEL() <= co->co_stacksize); /* else overflow */ |
| 24844 | 831 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
832 /* 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
|
833 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
|
834 only every Nth instruction. We also do it if |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
835 ``things_to_do'' is set, i.e. when an asynchronous |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
836 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
|
837 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
|
838 Py_MakePendingCalls() above. */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
839 |
|
25108
3a26e352f0a6
replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents:
25078
diff
changeset
|
840 if (--_Py_Ticker < 0) { |
| 43408 | 841 if (*next_instr == SETUP_FINALLY) { |
| 842 /* Make the last opcode before | |
| 843 a try: finally: block uninterruptable. */ | |
| 844 goto fast_next_opcode; | |
| 845 } | |
|
25108
3a26e352f0a6
replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents:
25078
diff
changeset
|
846 _Py_Ticker = _Py_CheckInterval; |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
847 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
|
848 #ifdef WITH_TSC |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
849 ticked = 1; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
850 #endif |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
851 if (things_to_do) { |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
852 if (Py_MakePendingCalls() < 0) { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
853 why = WHY_EXCEPTION; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
854 goto on_error; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
855 } |
|
34020
be370abb020f
Hye-Shik Chang's fix for Bug 875692.
Kurt B. Kaiser <kbk@shore.net>
parents:
33715
diff
changeset
|
856 if (things_to_do) |
|
be370abb020f
Hye-Shik Chang's fix for Bug 875692.
Kurt B. Kaiser <kbk@shore.net>
parents:
33715
diff
changeset
|
857 /* MakePendingCalls() didn't succeed. |
|
be370abb020f
Hye-Shik Chang's fix for Bug 875692.
Kurt B. Kaiser <kbk@shore.net>
parents:
33715
diff
changeset
|
858 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
|
859 "periodic" code, possibly after |
|
be370abb020f
Hye-Shik Chang's fix for Bug 875692.
Kurt B. Kaiser <kbk@shore.net>
parents:
33715
diff
changeset
|
860 a thread switch */ |
|
be370abb020f
Hye-Shik Chang's fix for Bug 875692.
Kurt B. Kaiser <kbk@shore.net>
parents:
33715
diff
changeset
|
861 _Py_Ticker = 0; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
862 } |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
863 #ifdef WITH_THREAD |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
864 if (interpreter_lock) { |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
865 /* Give another thread a chance */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
866 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
867 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
|
868 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
|
869 PyThread_release_lock(interpreter_lock); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
870 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
871 /* Other threads may run now */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
872 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
873 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
|
874 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
|
875 Py_FatalError("ceval: orphan tstate"); |
|
29643
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
876 |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
877 /* Check for thread interrupts */ |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
878 |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
879 if (tstate->async_exc != NULL) { |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
880 x = tstate->async_exc; |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
881 tstate->async_exc = NULL; |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
882 PyErr_SetNone(x); |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
883 Py_DECREF(x); |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
884 why = WHY_EXCEPTION; |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
885 goto on_error; |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
886 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
887 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
888 #endif |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
889 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
890 |
|
21974
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
891 fast_next_opcode: |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
892 f->f_lasti = INSTR_OFFSET(); |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
893 |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
894 /* line-by-line tracing support */ |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
895 |
|
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
|
896 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
|
897 tstate->c_tracefunc != NULL && !tstate->tracing) { |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
898 /* see maybe_call_line_trace |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
899 for expository comments */ |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
900 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
|
901 |
|
28886
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
902 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
|
903 tstate->c_traceobj, |
| 31768 | 904 f, &instr_lb, &instr_ub, |
| 905 &instr_prev); | |
|
28886
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
906 /* Reload possibly changed frame fields */ |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
907 JUMPTO(f->f_lasti); |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
908 if (f->f_stacktop != NULL) { |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
909 stack_pointer = f->f_stacktop; |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
910 f->f_stacktop = NULL; |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
911 } |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
912 if (err) { |
|
26110
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
913 /* trace function raised an exception */ |
|
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
914 goto on_error; |
|
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
915 } |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
916 } |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
917 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
918 /* Extract opcode and argument */ |
|
1016
a41e3ba5b47d
Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents:
974
diff
changeset
|
919 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
920 opcode = NEXTOP(); |
|
32359
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
921 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
|
922 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
|
923 if (HAS_ARG(opcode)) |
|
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
924 oparg = NEXTARG(); |
|
14147
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
925 dispatch_opcode: |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
926 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
927 #ifdef DXPAIRS |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
928 dxpairs[lastopcode][opcode]++; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
929 lastopcode = opcode; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
930 #endif |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
931 dxp[opcode]++; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
932 #endif |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
933 |
| 567 | 934 #ifdef LLTRACE |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
935 /* Instruction tracing */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
936 |
| 567 | 937 if (lltrace) { |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
938 if (HAS_ARG(opcode)) { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
939 printf("%d: %d, %d\n", |
| 24844 | 940 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
|
941 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
942 else { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
943 printf("%d: %d\n", |
| 24844 | 944 f->f_lasti, opcode); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
945 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
946 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
947 #endif |
| 24844 | 948 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
949 /* 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
|
950 READ_TIMESTAMP(inst0); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
951 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
952 switch (opcode) { |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
953 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
954 /* BEWARE! |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
955 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
|
956 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
|
957 and that no operation that succeeds does this! */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
958 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
959 /* case STOP_CODE: this is an error! */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
960 |
|
32395
6bc6abba8659
Install two code generation optimizations that depend on NOP.
Raymond Hettinger <python@rcn.com>
parents:
32359
diff
changeset
|
961 case NOP: |
|
6bc6abba8659
Install two code generation optimizations that depend on NOP.
Raymond Hettinger <python@rcn.com>
parents:
32359
diff
changeset
|
962 goto fast_next_opcode; |
|
6bc6abba8659
Install two code generation optimizations that depend on NOP.
Raymond Hettinger <python@rcn.com>
parents:
32359
diff
changeset
|
963 |
|
21974
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
964 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
|
965 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
|
966 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
|
967 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
|
968 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
|
969 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
|
970 } |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
971 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
|
972 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
|
973 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
|
974 break; |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
975 |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
976 case LOAD_CONST: |
|
24545
d2f41c8a81f0
small speedup for constant and name access
Skip Montanaro <skip@pobox.com>
parents:
24284
diff
changeset
|
977 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
|
978 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
|
979 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
|
980 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
|
981 |
|
28304
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
982 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
|
983 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
|
984 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
|
985 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
|
986 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
|
987 |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
988 PREDICTED(POP_TOP); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
989 case POP_TOP: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
990 v = POP(); |
| 5368 | 991 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
|
992 goto fast_next_opcode; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
993 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
994 case ROT_TWO: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
995 v = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
996 w = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
997 SET_TOP(w); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
998 SET_SECOND(v); |
|
28296
7654c24decc4
SF patch #701907: More use of fast_next_opcode
Raymond Hettinger <python@rcn.com>
parents:
28121
diff
changeset
|
999 goto fast_next_opcode; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1000 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1001 case ROT_THREE: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1002 v = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1003 w = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1004 x = THIRD(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1005 SET_TOP(w); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1006 SET_SECOND(x); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1007 SET_THIRD(v); |
|
28296
7654c24decc4
SF patch #701907: More use of fast_next_opcode
Raymond Hettinger <python@rcn.com>
parents:
28121
diff
changeset
|
1008 goto fast_next_opcode; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1009 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1010 case ROT_FOUR: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1011 u = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1012 v = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1013 w = THIRD(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1014 x = FOURTH(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1015 SET_TOP(v); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1016 SET_SECOND(w); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1017 SET_THIRD(x); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1018 SET_FOURTH(u); |
|
28296
7654c24decc4
SF patch #701907: More use of fast_next_opcode
Raymond Hettinger <python@rcn.com>
parents:
28121
diff
changeset
|
1019 goto fast_next_opcode; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1020 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1021 case DUP_TOP: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1022 v = TOP(); |
| 5368 | 1023 Py_INCREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1024 PUSH(v); |
|
28296
7654c24decc4
SF patch #701907: More use of fast_next_opcode
Raymond Hettinger <python@rcn.com>
parents:
28121
diff
changeset
|
1025 goto fast_next_opcode; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1026 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1027 case DUP_TOPX: |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
1028 if (oparg == 2) { |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1029 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
|
1030 Py_INCREF(x); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1031 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
|
1032 Py_INCREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1033 STACKADJ(2); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1034 SET_TOP(x); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1035 SET_SECOND(w); |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
1036 goto fast_next_opcode; |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
1037 } 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
|
1038 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
|
1039 Py_INCREF(x); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1040 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
|
1041 Py_INCREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1042 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
|
1043 Py_INCREF(v); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1044 STACKADJ(3); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1045 SET_TOP(x); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1046 SET_SECOND(w); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1047 SET_THIRD(v); |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
1048 goto fast_next_opcode; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1049 } |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
1050 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
|
1051 " (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
|
1052 /* 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
|
1053 break; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1054 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1055 case UNARY_POSITIVE: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1056 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1057 x = PyNumber_Positive(v); |
| 5368 | 1058 Py_DECREF(v); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1059 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
|
1060 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1061 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1062 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1063 case UNARY_NEGATIVE: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1064 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1065 x = PyNumber_Negative(v); |
| 5368 | 1066 Py_DECREF(v); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1067 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
|
1068 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1069 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1070 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1071 case UNARY_NOT: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1072 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1073 err = PyObject_IsTrue(v); |
| 5368 | 1074 Py_DECREF(v); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1075 if (err == 0) { |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1076 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
|
1077 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
|
1078 continue; |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1079 } |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1080 else if (err > 0) { |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1081 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
|
1082 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
|
1083 err = 0; |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1084 continue; |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1085 } |
|
27243
3afbd55fb18f
Replaced POP() with STACKADJ(-1) on lines where the result wasn't used.
Raymond Hettinger <python@rcn.com>
parents:
27201
diff
changeset
|
1086 STACKADJ(-1); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1087 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1088 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1089 case UNARY_CONVERT: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1090 v = TOP(); |
| 5368 | 1091 x = PyObject_Repr(v); |
| 1092 Py_DECREF(v); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1093 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
|
1094 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1095 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1096 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1097 case UNARY_INVERT: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1098 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1099 x = PyNumber_Invert(v); |
| 5368 | 1100 Py_DECREF(v); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1101 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
|
1102 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1103 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1104 |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3294
diff
changeset
|
1105 case BINARY_POWER: |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3294
diff
changeset
|
1106 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1107 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1108 x = PyNumber_Power(v, w, Py_None); |
| 5368 | 1109 Py_DECREF(v); |
| 1110 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1111 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
|
1112 if (x != NULL) continue; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3294
diff
changeset
|
1113 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1114 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1115 case BINARY_MULTIPLY: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1116 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1117 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1118 x = PyNumber_Multiply(v, w); |
| 5368 | 1119 Py_DECREF(v); |
| 1120 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1121 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
|
1122 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1123 break; |
|
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 BINARY_DIVIDE: |
|
21251
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1126 if (!_Py_QnewFlag) { |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1127 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1128 v = TOP(); |
|
21251
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1129 x = PyNumber_Divide(v, w); |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1130 Py_DECREF(v); |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1131 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1132 SET_TOP(x); |
|
21251
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1133 if (x != NULL) continue; |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1134 break; |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1135 } |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1136 /* -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
|
1137 BINARY_TRUE_DIVIDE */ |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1138 case BINARY_TRUE_DIVIDE: |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1139 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1140 v = TOP(); |
|
21251
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1141 x = PyNumber_TrueDivide(v, w); |
| 5368 | 1142 Py_DECREF(v); |
| 1143 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1144 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
|
1145 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1146 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1147 |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1148 case BINARY_FLOOR_DIVIDE: |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1149 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1150 v = TOP(); |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1151 x = PyNumber_FloorDivide(v, w); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1152 Py_DECREF(v); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1153 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1154 SET_TOP(x); |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1155 if (x != NULL) continue; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1156 break; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1157 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1158 case BINARY_MODULO: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1159 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1160 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1161 x = PyNumber_Remainder(v, w); |
| 5368 | 1162 Py_DECREF(v); |
| 1163 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1164 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
|
1165 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1166 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1167 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1168 case BINARY_ADD: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1169 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1170 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
|
1171 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
|
1172 /* INLINE: int + int */ |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1173 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
|
1174 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
|
1175 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
|
1176 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
|
1177 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
|
1178 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
|
1179 x = PyInt_FromLong(i); |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1180 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1181 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
|
1182 PyString_CheckExact(w)) { |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1183 x = string_concatenate(v, w, f, next_instr); |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1184 /* string_concatenate consumed the ref to v */ |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1185 goto skip_decref_vx; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1186 } |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1187 else { |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1188 slow_add: |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1189 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
|
1190 } |
| 5368 | 1191 Py_DECREF(v); |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1192 skip_decref_vx: |
| 5368 | 1193 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1194 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
|
1195 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1196 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1197 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1198 case BINARY_SUBTRACT: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1199 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1200 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
|
1201 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
|
1202 /* INLINE: int - int */ |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1203 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
|
1204 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
|
1205 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
|
1206 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
|
1207 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
|
1208 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
|
1209 x = PyInt_FromLong(i); |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1210 } |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1211 else { |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1212 slow_sub: |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1213 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
|
1214 } |
| 5368 | 1215 Py_DECREF(v); |
| 1216 Py_DECREF(w); | |
|
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 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1221 case BINARY_SUBSCR: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1222 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1223 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
|
1224 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
|
1225 /* 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
|
1226 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
|
1227 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
|
1228 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
|
1229 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
|
1230 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
|
1231 Py_INCREF(x); |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1232 } |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1233 else |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1234 goto slow_get; |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1235 } |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1236 else |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1237 slow_get: |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1238 x = PyObject_GetItem(v, w); |
| 5368 | 1239 Py_DECREF(v); |
| 1240 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1241 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
|
1242 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1243 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1244 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1245 case BINARY_LSHIFT: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1246 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1247 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1248 x = PyNumber_Lshift(v, w); |
| 5368 | 1249 Py_DECREF(v); |
| 1250 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1251 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
|
1252 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1253 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1254 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1255 case BINARY_RSHIFT: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1256 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1257 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1258 x = PyNumber_Rshift(v, w); |
| 5368 | 1259 Py_DECREF(v); |
| 1260 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1261 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
|
1262 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1263 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1264 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1265 case BINARY_AND: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1266 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1267 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1268 x = PyNumber_And(v, w); |
| 5368 | 1269 Py_DECREF(v); |
| 1270 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1271 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
|
1272 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1273 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1274 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1275 case BINARY_XOR: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1276 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1277 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1278 x = PyNumber_Xor(v, w); |
| 5368 | 1279 Py_DECREF(v); |
| 1280 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1281 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
|
1282 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1283 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1284 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1285 case BINARY_OR: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1286 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1287 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1288 x = PyNumber_Or(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; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1293 break; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1294 |
|
31618
bc006682acb2
SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents:
31606
diff
changeset
|
1295 case LIST_APPEND: |
|
bc006682acb2
SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents:
31606
diff
changeset
|
1296 w = POP(); |
|
bc006682acb2
SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents:
31606
diff
changeset
|
1297 v = POP(); |
|
bc006682acb2
SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents:
31606
diff
changeset
|
1298 err = PyList_Append(v, w); |
|
bc006682acb2
SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents:
31606
diff
changeset
|
1299 Py_DECREF(v); |
|
bc006682acb2
SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents:
31606
diff
changeset
|
1300 Py_DECREF(w); |
|
31649
243642bbd03f
LIST_APPEND is predicably followed by JUMP_ABSOLUTE.
Raymond Hettinger <python@rcn.com>
parents:
31647
diff
changeset
|
1301 if (err == 0) { |
|
243642bbd03f
LIST_APPEND is predicably followed by JUMP_ABSOLUTE.
Raymond Hettinger <python@rcn.com>
parents:
31647
diff
changeset
|
1302 PREDICT(JUMP_ABSOLUTE); |
|
243642bbd03f
LIST_APPEND is predicably followed by JUMP_ABSOLUTE.
Raymond Hettinger <python@rcn.com>
parents:
31647
diff
changeset
|
1303 continue; |
|
243642bbd03f
LIST_APPEND is predicably followed by JUMP_ABSOLUTE.
Raymond Hettinger <python@rcn.com>
parents:
31647
diff
changeset
|
1304 } |
|
31618
bc006682acb2
SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents:
31606
diff
changeset
|
1305 break; |
|
bc006682acb2
SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents:
31606
diff
changeset
|
1306 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1307 case INPLACE_POWER: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1308 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1309 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1310 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
|
1311 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1312 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1313 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1314 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1315 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1316 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1317 case INPLACE_MULTIPLY: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1318 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1319 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1320 x = PyNumber_InPlaceMultiply(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1321 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1322 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1323 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1324 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1325 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1326 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1327 case INPLACE_DIVIDE: |
|
21537
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1328 if (!_Py_QnewFlag) { |
|
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1329 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1330 v = TOP(); |
|
21537
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1331 x = PyNumber_InPlaceDivide(v, w); |
|
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1332 Py_DECREF(v); |
|
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1333 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1334 SET_TOP(x); |
|
21537
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1335 if (x != NULL) continue; |
|
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1336 break; |
|
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1337 } |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1338 /* -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
|
1339 INPLACE_TRUE_DIVIDE */ |
|
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1340 case INPLACE_TRUE_DIVIDE: |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1341 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1342 v = TOP(); |
|
21537
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1343 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
|
1344 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1345 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1346 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1347 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1348 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1349 |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1350 case INPLACE_FLOOR_DIVIDE: |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1351 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1352 v = TOP(); |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1353 x = PyNumber_InPlaceFloorDivide(v, w); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1354 Py_DECREF(v); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1355 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1356 SET_TOP(x); |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1357 if (x != NULL) continue; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1358 break; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1359 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1360 case INPLACE_MODULO: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1361 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1362 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1363 x = PyNumber_InPlaceRemainder(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1364 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1365 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1366 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1367 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1368 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1369 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1370 case INPLACE_ADD: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1371 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1372 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
|
1373 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
|
1374 /* INLINE: int + int */ |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1375 register long a, b, i; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1376 a = PyInt_AS_LONG(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1377 b = PyInt_AS_LONG(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1378 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
|
1379 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
|
1380 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
|
1381 x = PyInt_FromLong(i); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1382 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1383 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
|
1384 PyString_CheckExact(w)) { |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1385 x = string_concatenate(v, w, f, next_instr); |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1386 /* string_concatenate consumed the ref to v */ |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1387 goto skip_decref_v; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1388 } |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1389 else { |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1390 slow_iadd: |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1391 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
|
1392 } |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1393 Py_DECREF(v); |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1394 skip_decref_v: |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1395 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1396 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1397 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1398 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1399 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1400 case INPLACE_SUBTRACT: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1401 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1402 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
|
1403 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
|
1404 /* INLINE: int - int */ |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1405 register long a, b, i; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1406 a = PyInt_AS_LONG(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1407 b = PyInt_AS_LONG(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1408 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
|
1409 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
|
1410 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
|
1411 x = PyInt_FromLong(i); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1412 } |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1413 else { |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1414 slow_isub: |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1415 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
|
1416 } |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1417 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1418 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1419 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1420 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1421 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1422 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1423 case INPLACE_LSHIFT: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1424 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1425 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1426 x = PyNumber_InPlaceLshift(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1427 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1428 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1429 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1430 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1431 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
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_RSHIFT: |
|
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_InPlaceRshift(v, w); |
|
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_AND: |
|
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_InPlaceAnd(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_XOR: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1454 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1455 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1456 x = PyNumber_InPlaceXor(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1457 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1458 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1459 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1460 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1461 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1462 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1463 case INPLACE_OR: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1464 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1465 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1466 x = PyNumber_InPlaceOr(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1467 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1468 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1469 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1470 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1471 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1472 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1473 case SLICE+0: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1474 case SLICE+1: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1475 case SLICE+2: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1476 case SLICE+3: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1477 if ((opcode-SLICE) & 2) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1478 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1479 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1480 w = NULL; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1481 if ((opcode-SLICE) & 1) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1482 v = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1483 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1484 v = NULL; |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1485 u = TOP(); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1486 x = apply_slice(u, v, w); |
| 5368 | 1487 Py_DECREF(u); |
| 1488 Py_XDECREF(v); | |
| 1489 Py_XDECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1490 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
|
1491 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1492 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1493 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1494 case STORE_SLICE+0: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1495 case STORE_SLICE+1: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1496 case STORE_SLICE+2: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1497 case STORE_SLICE+3: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1498 if ((opcode-STORE_SLICE) & 2) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1499 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1500 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1501 w = NULL; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1502 if ((opcode-STORE_SLICE) & 1) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1503 v = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1504 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1505 v = NULL; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1506 u = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1507 t = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1508 err = assign_slice(u, v, w, t); /* u[v:w] = t */ |
| 5368 | 1509 Py_DECREF(t); |
| 1510 Py_DECREF(u); | |
| 1511 Py_XDECREF(v); | |
| 1512 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
|
1513 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1514 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1515 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1516 case DELETE_SLICE+0: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1517 case DELETE_SLICE+1: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1518 case DELETE_SLICE+2: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1519 case DELETE_SLICE+3: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1520 if ((opcode-DELETE_SLICE) & 2) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1521 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1522 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1523 w = NULL; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1524 if ((opcode-DELETE_SLICE) & 1) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1525 v = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1526 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1527 v = NULL; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1528 u = POP(); |
| 5368 | 1529 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
|
1530 /* del u[v:w] */ |
| 5368 | 1531 Py_DECREF(u); |
| 1532 Py_XDECREF(v); | |
| 1533 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
|
1534 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1535 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1536 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1537 case STORE_SUBSCR: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1538 w = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1539 v = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1540 u = THIRD(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1541 STACKADJ(-3); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1542 /* v[w] = u */ |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1543 err = PyObject_SetItem(v, w, u); |
| 5368 | 1544 Py_DECREF(u); |
| 1545 Py_DECREF(v); | |
| 1546 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
|
1547 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1548 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1549 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1550 case DELETE_SUBSCR: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1551 w = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1552 v = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1553 STACKADJ(-2); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1554 /* del v[w] */ |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1555 err = PyObject_DelItem(v, w); |
| 5368 | 1556 Py_DECREF(v); |
| 1557 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
|
1558 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1559 break; |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1560 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1561 case PRINT_EXPR: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1562 v = POP(); |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1563 w = PySys_GetObject("displayhook"); |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1564 if (w == NULL) { |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1565 PyErr_SetString(PyExc_RuntimeError, |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1566 "lost sys.displayhook"); |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1567 err = -1; |
|
15814
faaf9f10d849
Fixed bugs noted by Greg Stein
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15811
diff
changeset
|
1568 x = NULL; |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1569 } |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1570 if (err == 0) { |
|
30683
3b59fa5d25b1
Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents:
29669
diff
changeset
|
1571 x = PyTuple_Pack(1, v); |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1572 if (x == NULL) |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1573 err = -1; |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1574 } |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1575 if (err == 0) { |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1576 w = PyEval_CallObject(w, x); |
|
15814
faaf9f10d849
Fixed bugs noted by Greg Stein
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15811
diff
changeset
|
1577 Py_XDECREF(w); |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1578 if (w == NULL) |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1579 err = -1; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1580 } |
| 5368 | 1581 Py_DECREF(v); |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1582 Py_XDECREF(x); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1583 break; |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1584 |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1585 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
|
1586 w = stream = POP(); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1587 /* 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
|
1588 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1589 case PRINT_ITEM: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1590 v = POP(); |
|
14238
74f7f237f739
eval_code2(): Guido provides this patch for his suggested elaboration
Barry Warsaw <barry@python.org>
parents:
14232
diff
changeset
|
1591 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
|
1592 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
|
1593 if (w == NULL) { |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1594 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
|
1595 "lost sys.stdout"); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1596 err = -1; |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1597 } |
|
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
|
1598 } |
|
29669
96ecaab4cba6
Fix SF #762455, segfault when sys.stdout is changed in getattr
Neal Norwitz <nnorwitz@gmail.com>
parents:
29643
diff
changeset
|
1599 /* 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
|
1600 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
|
1601 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
|
1602 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
|
1603 Py_XINCREF(w); |
|
22499
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1604 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
|
1605 err = PyFile_WriteString(" ", w); |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
1606 if (err == 0) |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
1607 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
|
1608 if (err == 0) { |
|
22499
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1609 /* 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
|
1610 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
|
1611 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
|
1612 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
|
1613 if (len == 0 || |
|
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1614 !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
|
1615 s[len-1] == ' ') |
|
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1616 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
|
1617 } |
|
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
|
1618 #ifdef Py_USING_UNICODE |
|
21027
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1619 else if (PyUnicode_Check(v)) { |
|
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1620 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
|
1621 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
|
1622 if (len == 0 || |
|
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1623 !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
|
1624 s[len-1] == ' ') |
|
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1625 PyFile_SoftSpace(w, 1); |
|
21027
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1626 } |
| 23479 | 1627 #endif |
|
22499
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1628 else |
|
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1629 PyFile_SoftSpace(w, 1); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1630 } |
|
29669
96ecaab4cba6
Fix SF #762455, segfault when sys.stdout is changed in getattr
Neal Norwitz <nnorwitz@gmail.com>
parents:
29643
diff
changeset
|
1631 Py_XDECREF(w); |
| 5368 | 1632 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
|
1633 Py_XDECREF(stream); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1634 stream = NULL; |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1635 if (err == 0) |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1636 continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1637 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1638 |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1639 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
|
1640 w = stream = POP(); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1641 /* 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
|
1642 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1643 case PRINT_NEWLINE: |
|
14238
74f7f237f739
eval_code2(): Guido provides this patch for his suggested elaboration
Barry Warsaw <barry@python.org>
parents:
14232
diff
changeset
|
1644 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
|
1645 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
|
1646 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
|
1647 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
|
1648 "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
|
1649 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
|
1650 } |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1651 } |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1652 if (w != NULL) { |
|
47868
4a8329535234
Add a comment about incref'ing w.
Georg Brandl <georg@python.org>
parents:
47864
diff
changeset
|
1653 /* 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
|
1654 * 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
|
1655 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
|
1656 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
|
1657 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
|
1658 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
|
1659 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
|
1660 } |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1661 Py_XDECREF(stream); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1662 stream = NULL; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1663 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1664 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1665 |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1666 #ifdef CASE_TOO_BIG |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1667 default: switch (opcode) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1668 #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
|
1669 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
|
1670 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
|
1671 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
|
1672 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
|
1673 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
|
1674 /* 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
|
1675 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
|
1676 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
|
1677 /* 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
|
1678 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
|
1679 w = POP(); /* exc */ |
|
7946
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
1680 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
|
1681 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
|
1682 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
|
1683 default: |
| 5368 | 1684 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
|
1685 "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
|
1686 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
|
1687 break; |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1688 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1689 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1690 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1691 case LOAD_LOCALS: |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1692 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
|
1693 Py_INCREF(x); |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1694 PUSH(x); |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1695 continue; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1696 } |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1697 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
|
1698 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1699 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1700 case RETURN_VALUE: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1701 retval = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1702 why = WHY_RETURN; |
|
31462
d5c047807c69
SF patch #864059: optimize eval_frame
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1703 goto fast_block_end; |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1704 |
|
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
|
1705 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
|
1706 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
|
1707 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
|
1708 why = WHY_YIELD; |
|
31462
d5c047807c69
SF patch #864059: optimize eval_frame
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1709 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
|
1710 |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1711 case EXEC_STMT: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1712 w = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1713 v = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1714 u = THIRD(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1715 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
|
1716 READ_TIMESTAMP(intr0); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1717 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
|
1718 READ_TIMESTAMP(intr1); |
| 5368 | 1719 Py_DECREF(u); |
| 1720 Py_DECREF(v); | |
| 1721 Py_DECREF(w); | |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1722 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1723 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1724 case POP_BLOCK: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1725 { |
| 5368 | 1726 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
|
1727 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
|
1728 v = POP(); |
| 5368 | 1729 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1730 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1731 } |
|
31880
4c6fdeb8e2e0
Use continue instead of break whereever possible.
Raymond Hettinger <python@rcn.com>
parents:
31879
diff
changeset
|
1732 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1733 |
|
45624
6068b75ec27a
compile.c always emits END_FINALLY after WITH_CLEANUP, so predict that in
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
45011
diff
changeset
|
1734 PREDICTED(END_FINALLY); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1735 case END_FINALLY: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1736 v = POP(); |
| 5368 | 1737 if (PyInt_Check(v)) { |
|
31875
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
1738 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
|
1739 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
|
1740 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
|
1741 why == WHY_CONTINUE) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1742 retval = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1743 } |
|
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
|
1744 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
|
1745 PyString_Check(v)) { |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1746 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
|
1747 u = POP(); |
| 5368 | 1748 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
|
1749 why = WHY_RERAISE; |
|
2872
d3b07ba3e12d
fix bogus DECREF in finally clause
Guido van Rossum <guido@python.org>
parents:
2866
diff
changeset
|
1750 break; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1751 } |
| 5368 | 1752 else if (v != Py_None) { |
| 1753 PyErr_SetString(PyExc_SystemError, | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1754 "'finally' pops bad exception"); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1755 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1756 } |
| 5368 | 1757 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1758 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1759 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1760 case BUILD_CLASS: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1761 u = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1762 v = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1763 w = THIRD(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1764 STACKADJ(-2); |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
1765 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
|
1766 SET_TOP(x); |
| 5368 | 1767 Py_DECREF(u); |
| 1768 Py_DECREF(v); | |
| 1769 Py_DECREF(w); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1770 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1771 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1772 case STORE_NAME: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1773 w = GETITEM(names, oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1774 v = POP(); |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1775 if ((x = f->f_locals) != NULL) { |
|
32890
b8c2aa2be19a
Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents:
32531
diff
changeset
|
1776 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
|
1777 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
|
1778 else |
|
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
1779 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
|
1780 Py_DECREF(v); |
|
31880
4c6fdeb8e2e0
Use continue instead of break whereever possible.
Raymond Hettinger <python@rcn.com>
parents:
31879
diff
changeset
|
1781 if (err == 0) continue; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1782 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1783 } |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1784 PyErr_Format(PyExc_SystemError, |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1785 "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
|
1786 PyObject_REPR(w)); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1787 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1788 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1789 case DELETE_NAME: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1790 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
|
1791 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
|
1792 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
|
1793 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
|
1794 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
|
1795 w); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1796 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1797 } |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1798 PyErr_Format(PyExc_SystemError, |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1799 "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
|
1800 PyObject_REPR(w)); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1801 break; |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
1802 |
|
28304
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
1803 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
|
1804 case UNPACK_SEQUENCE: |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1805 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
|
1806 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
|
1807 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
|
1808 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
|
1809 ((PyTupleObject *)v)->ob_item; |
|
31630
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1810 while (oparg--) { |
|
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1811 w = items[oparg]; |
|
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1812 Py_INCREF(w); |
|
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1813 PUSH(w); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1814 } |
|
31880
4c6fdeb8e2e0
Use continue instead of break whereever possible.
Raymond Hettinger <python@rcn.com>
parents:
31879
diff
changeset
|
1815 Py_DECREF(v); |
|
4c6fdeb8e2e0
Use continue instead of break whereever possible.
Raymond Hettinger <python@rcn.com>
parents:
31879
diff
changeset
|
1816 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
|
1817 } 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
|
1818 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
|
1819 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
|
1820 ((PyListObject *)v)->ob_item; |
|
31630
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1821 while (oparg--) { |
|
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1822 w = items[oparg]; |
|
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1823 Py_INCREF(w); |
|
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1824 PUSH(w); |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1825 } |
|
31630
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1826 } 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
|
1827 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
|
1828 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
|
1829 } else { |
|
9cf22c5eee3d
Patch #1682205: a TypeError while unpacking an iterable is no longer
Georg Brandl <georg@python.org>
parents:
41007
diff
changeset
|
1830 /* 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
|
1831 why = WHY_EXCEPTION; |
|
20183
c6b6189a8397
SF bug [#466173] unpack TypeError unclear
Tim Peters <tim.peters@gmail.com>
parents:
20114
diff
changeset
|
1832 } |
| 5368 | 1833 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1834 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1835 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1836 case STORE_ATTR: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1837 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
|
1838 v = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1839 u = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1840 STACKADJ(-2); |
| 5368 | 1841 err = PyObject_SetAttr(v, w, u); /* v.w = u */ |
| 1842 Py_DECREF(v); | |
| 1843 Py_DECREF(u); | |
|
31880
4c6fdeb8e2e0
Use continue instead of break whereever possible.
Raymond Hettinger <python@rcn.com>
parents:
31879
diff
changeset
|
1844 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1845 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1846 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1847 case DELETE_ATTR: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1848 w = GETITEM(names, oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1849 v = POP(); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1850 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
|
1851 /* del v.w */ |
| 5368 | 1852 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1853 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1854 |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1855 case STORE_GLOBAL: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1856 w = GETITEM(names, oparg); |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1857 v = POP(); |
| 5368 | 1858 err = PyDict_SetItem(f->f_globals, w, v); |
| 1859 Py_DECREF(v); | |
|
31880
4c6fdeb8e2e0
Use continue instead of break whereever possible.
Raymond Hettinger <python@rcn.com>
parents:
31879
diff
changeset
|
1860 if (err == 0) continue; |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1861 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1862 |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1863 case DELETE_GLOBAL: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1864 w = GETITEM(names, oparg); |
| 5368 | 1865 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
|
1866 format_exc_check_arg( |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1867 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
|
1868 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1869 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1870 case LOAD_NAME: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1871 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
|
1872 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
|
1873 PyErr_Format(PyExc_SystemError, |
|
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15948
diff
changeset
|
1874 "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
|
1875 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
|
1876 why = WHY_EXCEPTION; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1877 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1878 } |
|
32900
ac73f6662e11
Fix for the unfortunate fact that PyDict_GetItem and PyObject_GetItem
Michael W. Hudson <mwh@python.net>
parents:
32890
diff
changeset
|
1879 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
|
1880 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
|
1881 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
|
1882 } |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
1883 else { |
|
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
1884 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
|
1885 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
|
1886 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
|
1887 PyExc_KeyError)) |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
1888 break; |
|
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
1889 PyErr_Clear(); |
|
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
1890 } |
|
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
1891 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1892 if (x == NULL) { |
| 5368 | 1893 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
|
1894 if (x == NULL) { |
| 5368 | 1895 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
|
1896 if (x == NULL) { |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1897 format_exc_check_arg( |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1898 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
|
1899 NAME_ERROR_MSG, w); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1900 break; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1901 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1902 } |
|
32900
ac73f6662e11
Fix for the unfortunate fact that PyDict_GetItem and PyObject_GetItem
Michael W. Hudson <mwh@python.net>
parents:
32890
diff
changeset
|
1903 Py_INCREF(x); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1904 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1905 PUSH(x); |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1906 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1907 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1908 case LOAD_GLOBAL: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1909 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
|
1910 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
|
1911 /* 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
|
1912 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
|
1913 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
|
1914 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
|
1915 if (hash != -1) { |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1916 PyDictObject *d; |
|
38536
175cbdf9a5fb
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
Armin Rigo <arigo@tunes.org>
parents:
38425
diff
changeset
|
1917 PyDictEntry *e; |
|
24899
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1918 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
|
1919 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
|
1920 if (e == NULL) { |
|
175cbdf9a5fb
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
Armin Rigo <arigo@tunes.org>
parents:
38425
diff
changeset
|
1921 x = NULL; |
|
175cbdf9a5fb
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
Armin Rigo <arigo@tunes.org>
parents:
38425
diff
changeset
|
1922 break; |
|
175cbdf9a5fb
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
Armin Rigo <arigo@tunes.org>
parents:
38425
diff
changeset
|
1923 } |
|
175cbdf9a5fb
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
Armin Rigo <arigo@tunes.org>
parents:
38425
diff
changeset
|
1924 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
|
1925 if (x != NULL) { |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1926 Py_INCREF(x); |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1927 PUSH(x); |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1928 continue; |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1929 } |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1930 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
|
1931 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
|
1932 if (e == NULL) { |
|
175cbdf9a5fb
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
Armin Rigo <arigo@tunes.org>
parents:
38425
diff
changeset
|
1933 x = NULL; |
|
175cbdf9a5fb
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
Armin Rigo <arigo@tunes.org>
parents:
38425
diff
changeset
|
1934 break; |
|
175cbdf9a5fb
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
Armin Rigo <arigo@tunes.org>
parents:
38425
diff
changeset
|
1935 } |
|
175cbdf9a5fb
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
Armin Rigo <arigo@tunes.org>
parents:
38425
diff
changeset
|
1936 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
|
1937 if (x != NULL) { |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1938 Py_INCREF(x); |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1939 PUSH(x); |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1940 continue; |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1941 } |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1942 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
|
1943 } |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1944 } |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1945 /* This is the un-inlined version of the code above */ |
| 5368 | 1946 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
|
1947 if (x == NULL) { |
| 5368 | 1948 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
|
1949 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
|
1950 load_global_error: |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1951 format_exc_check_arg( |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1952 PyExc_NameError, |
|
24899
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1953 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
|
1954 break; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1955 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1956 } |
| 5368 | 1957 Py_INCREF(x); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1958 PUSH(x); |
|
31880
4c6fdeb8e2e0
Use continue instead of break whereever possible.
Raymond Hettinger <python@rcn.com>
parents:
31879
diff
changeset
|
1959 continue; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1960 |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1961 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
|
1962 x = GETLOCAL(oparg); |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1963 if (x != NULL) { |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1964 SETLOCAL(oparg, NULL); |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1965 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
|
1966 } |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1967 format_exc_check_arg( |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1968 PyExc_UnboundLocalError, |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1969 UNBOUNDLOCAL_ERROR_MSG, |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1970 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
|
1971 ); |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1972 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1973 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1974 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
|
1975 x = freevars[oparg]; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1976 Py_INCREF(x); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1977 PUSH(x); |
|
31880
4c6fdeb8e2e0
Use continue instead of break whereever possible.
Raymond Hettinger <python@rcn.com>
parents:
31879
diff
changeset
|
1978 if (x != NULL) continue; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1979 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1980 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1981 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
|
1982 x = freevars[oparg]; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1983 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
|
1984 if (w != NULL) { |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1985 PUSH(w); |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1986 continue; |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1987 } |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1988 err = -1; |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1989 /* 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
|
1990 if (PyErr_Occurred()) |
|
16453
2e3dd62ceac5
SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16398
diff
changeset
|
1991 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
|
1992 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
|
1993 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
|
1994 oparg); |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1995 format_exc_check_arg( |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1996 PyExc_UnboundLocalError, |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1997 UNBOUNDLOCAL_ERROR_MSG, |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1998 v); |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1999 } 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
|
2000 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
|
2001 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
|
2002 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
|
2003 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
|
2004 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2005 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2006 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2007 case STORE_DEREF: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2008 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
|
2009 x = freevars[oparg]; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2010 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
|
2011 Py_DECREF(w); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2012 continue; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2013 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2014 case BUILD_TUPLE: |
| 5368 | 2015 x = PyTuple_New(oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2016 if (x != NULL) { |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
2017 for (; --oparg >= 0;) { |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2018 w = POP(); |
| 5368 | 2019 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
|
2020 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2021 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
|
2022 continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2023 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2024 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2025 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2026 case BUILD_LIST: |
| 5368 | 2027 x = PyList_New(oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2028 if (x != NULL) { |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
2029 for (; --oparg >= 0;) { |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2030 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
|
2031 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
|
2032 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2033 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
|
2034 continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2035 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2036 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2037 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2038 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
|
2039 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
|
2040 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
|
2041 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2042 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2043 |
|
44334
07aa19170a67
Speed-up dictionary constructor by about 10%.
Raymond Hettinger <python@rcn.com>
parents:
44292
diff
changeset
|
2044 case STORE_MAP: |
|
07aa19170a67
Speed-up dictionary constructor by about 10%.
Raymond Hettinger <python@rcn.com>
parents:
44292
diff
changeset
|
2045 w = TOP(); /* key */ |
|
07aa19170a67
Speed-up dictionary constructor by about 10%.
Raymond Hettinger <python@rcn.com>
parents:
44292
diff
changeset
|
2046 u = SECOND(); /* value */ |
|
07aa19170a67
Speed-up dictionary constructor by about 10%.
Raymond Hettinger <python@rcn.com>
parents:
44292
diff
changeset
|
2047 v = THIRD(); /* dict */ |
|
07aa19170a67
Speed-up dictionary constructor by about 10%.
Raymond Hettinger <python@rcn.com>
parents:
44292
diff
changeset
|
2048 STACKADJ(-2); |
|
07aa19170a67
Speed-up dictionary constructor by about 10%.
Raymond Hettinger <python@rcn.com>
parents:
44292
diff
changeset
|
2049 assert (PyDict_CheckExact(v)); |
|
07aa19170a67
Speed-up dictionary constructor by about 10%.
Raymond Hettinger <python@rcn.com>
parents:
44292
diff
changeset
|
2050 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
|
2051 Py_DECREF(u); |
|
07aa19170a67
Speed-up dictionary constructor by about 10%.
Raymond Hettinger <python@rcn.com>
parents:
44292
diff
changeset
|
2052 Py_DECREF(w); |
|
07aa19170a67
Speed-up dictionary constructor by about 10%.
Raymond Hettinger <python@rcn.com>
parents:
44292
diff
changeset
|
2053 if (err == 0) continue; |
|
07aa19170a67
Speed-up dictionary constructor by about 10%.
Raymond Hettinger <python@rcn.com>
parents:
44292
diff
changeset
|
2054 break; |
|
07aa19170a67
Speed-up dictionary constructor by about 10%.
Raymond Hettinger <python@rcn.com>
parents:
44292
diff
changeset
|
2055 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2056 case LOAD_ATTR: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
2057 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
|
2058 v = TOP(); |
| 5368 | 2059 x = PyObject_GetAttr(v, w); |
| 2060 Py_DECREF(v); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2061 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
|
2062 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2063 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2064 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2065 case COMPARE_OP: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2066 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2067 v = TOP(); |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
2068 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
|
2069 /* INLINE: cmp(int, int) */ |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2070 register long a, b; |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2071 register int res; |
|
9591
7f90736701a3
Use PyInt_AS_LONG macro instead of explicit inlining.
Guido van Rossum <guido@python.org>
parents:
9513
diff
changeset
|
2072 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
|
2073 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
|
2074 switch (oparg) { |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
2075 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
|
2076 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
|
2077 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
|
2078 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
|
2079 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
|
2080 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
|
2081 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
|
2082 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
|
2083 default: goto slow_compare; |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2084 } |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2085 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
|
2086 Py_INCREF(x); |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2087 } |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2088 else { |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2089 slow_compare: |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2090 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
|
2091 } |
| 5368 | 2092 Py_DECREF(v); |
| 2093 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2094 SET_TOP(x); |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2095 if (x == NULL) break; |
|
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2096 PREDICT(JUMP_IF_FALSE); |
|
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2097 PREDICT(JUMP_IF_TRUE); |
|
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2098 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2099 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2100 case IMPORT_NAME: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
2101 w = GETITEM(names, oparg); |
| 5368 | 2102 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
|
2103 if (x == NULL) { |
| 5368 | 2104 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
|
2105 "__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
|
2106 break; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
2107 } |
| 44894 | 2108 Py_INCREF(x); |
|
36712
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2109 v = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2110 u = TOP(); |
|
36712
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2111 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
|
2112 w = PyTuple_Pack(5, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2113 w, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2114 f->f_globals, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2115 f->f_locals == NULL ? |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2116 Py_None : f->f_locals, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2117 v, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2118 u); |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2119 else |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2120 w = PyTuple_Pack(4, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2121 w, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2122 f->f_globals, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2123 f->f_locals == NULL ? |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2124 Py_None : f->f_locals, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2125 v); |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2126 Py_DECREF(v); |
| 5368 | 2127 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
|
2128 if (w == NULL) { |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2129 u = POP(); |
| 44894 | 2130 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
|
2131 x = NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
2132 break; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
2133 } |
|
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
|
2134 READ_TIMESTAMP(intr0); |
| 44894 | 2135 v = x; |
| 2136 x = PyEval_CallObject(v, w); | |
| 2137 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
|
2138 READ_TIMESTAMP(intr1); |
| 5368 | 2139 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2140 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
|
2141 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2142 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2143 |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
2144 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
|
2145 v = POP(); |
| 5368 | 2146 PyFrame_FastToLocals(f); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2147 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
|
2148 PyErr_SetString(PyExc_SystemError, |
|
16017
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15948
diff
changeset
|
2149 "no locals found during 'import *'"); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2150 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2151 } |
|
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
|
2152 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
|
2153 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
|
2154 READ_TIMESTAMP(intr1); |
| 5368 | 2155 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
|
2156 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
|
2157 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2158 break; |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
2159 |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
2160 case IMPORT_FROM: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
2161 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
|
2162 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
|
2163 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
|
2164 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
|
2165 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
|
2166 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
|
2167 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
|
2168 break; |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
2169 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2170 case JUMP_FORWARD: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2171 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
|
2172 goto fast_next_opcode; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2173 |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2174 PREDICTED_WITH_ARG(JUMP_IF_FALSE); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2175 case JUMP_IF_FALSE: |
| 28077 | 2176 w = TOP(); |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2177 if (w == Py_True) { |
|
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2178 PREDICT(POP_TOP); |
|
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
|
2179 goto fast_next_opcode; |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2180 } |
| 28077 | 2181 if (w == Py_False) { |
| 2182 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
|
2183 goto fast_next_opcode; |
| 28077 | 2184 } |
| 2185 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
|
2186 if (err > 0) |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2187 err = 0; |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2188 else if (err == 0) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2189 JUMPBY(oparg); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2190 else |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2191 break; |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2192 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2193 |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2194 PREDICTED_WITH_ARG(JUMP_IF_TRUE); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2195 case JUMP_IF_TRUE: |
| 28077 | 2196 w = TOP(); |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2197 if (w == Py_False) { |
|
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2198 PREDICT(POP_TOP); |
|
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
|
2199 goto fast_next_opcode; |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2200 } |
| 28077 | 2201 if (w == Py_True) { |
| 2202 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
|
2203 goto fast_next_opcode; |
| 28077 | 2204 } |
| 2205 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
|
2206 if (err > 0) { |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2207 err = 0; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2208 JUMPBY(oparg); |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2209 } |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2210 else if (err == 0) |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2211 ; |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2212 else |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2213 break; |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2214 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2215 |
|
31649
243642bbd03f
LIST_APPEND is predicably followed by JUMP_ABSOLUTE.
Raymond Hettinger <python@rcn.com>
parents:
31647
diff
changeset
|
2216 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
|
2217 case JUMP_ABSOLUTE: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2218 JUMPTO(oparg); |
|
43784
8fcc3f46c69d
Add build option for faster loop execution.
Raymond Hettinger <python@rcn.com>
parents:
43416
diff
changeset
|
2219 #if FAST_LOOPS |
|
8fcc3f46c69d
Add build option for faster loop execution.
Raymond Hettinger <python@rcn.com>
parents:
43416
diff
changeset
|
2220 /* 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
|
2221 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
|
2222 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
|
2223 "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
|
2224 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
|
2225 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
|
2226 */ |
|
8fcc3f46c69d
Add build option for faster loop execution.
Raymond Hettinger <python@rcn.com>
parents:
43416
diff
changeset
|
2227 goto fast_next_opcode; |
|
8fcc3f46c69d
Add build option for faster loop execution.
Raymond Hettinger <python@rcn.com>
parents:
43416
diff
changeset
|
2228 #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
|
2229 continue; |
|
43784
8fcc3f46c69d
Add build option for faster loop execution.
Raymond Hettinger <python@rcn.com>
parents:
43416
diff
changeset
|
2230 #endif |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2231 |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2232 case GET_ITER: |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2233 /* 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
|
2234 v = TOP(); |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2235 x = PyObject_GetIter(v); |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2236 Py_DECREF(v); |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2237 if (x != NULL) { |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2238 SET_TOP(x); |
|
28304
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
2239 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
|
2240 continue; |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2241 } |
|
27243
3afbd55fb18f
Replaced POP() with STACKADJ(-1) on lines where the result wasn't used.
Raymond Hettinger <python@rcn.com>
parents:
27201
diff
changeset
|
2242 STACKADJ(-1); |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2243 break; |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2244 |
|
28304
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
2245 PREDICTED_WITH_ARG(FOR_ITER); |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2246 case FOR_ITER: |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2247 /* before: [iter]; after: [iter, iter()] *or* [] */ |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2248 v = TOP(); |
|
31646
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2249 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
|
2250 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
|
2251 PUSH(x); |
|
28304
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
2252 PREDICT(STORE_FAST); |
|
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
2253 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
|
2254 continue; |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2255 } |
|
31646
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2256 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
|
2257 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
|
2258 PyExc_StopIteration)) |
|
31646
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2259 break; |
|
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2260 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
|
2261 } |
|
31646
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2262 /* iterator ended normally */ |
|
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2263 x = v = POP(); |
|
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2264 Py_DECREF(v); |
|
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2265 JUMPBY(oparg); |
|
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2266 continue; |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2267 |
|
31647
d10c778af167
Move the code for BREAK and CONTINUE_LOOP to be near FOR_ITER.
Raymond Hettinger <python@rcn.com>
parents:
31646
diff
changeset
|
2268 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
|
2269 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
|
2270 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
|
2271 |
|
d10c778af167
Move the code for BREAK and CONTINUE_LOOP to be near FOR_ITER.
Raymond Hettinger <python@rcn.com>
parents:
31646
diff
changeset
|
2272 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
|
2273 retval = PyInt_FromLong(oparg); |
|
38217
2195972f7391
Fix #132 from Coverity, retval could have been derefed
Neal Norwitz <nnorwitz@gmail.com>
parents:
38134
diff
changeset
|
2274 if (!retval) { |
|
2195972f7391
Fix #132 from Coverity, retval could have been derefed
Neal Norwitz <nnorwitz@gmail.com>
parents:
38134
diff
changeset
|
2275 x = NULL; |
|
2195972f7391
Fix #132 from Coverity, retval could have been derefed
Neal Norwitz <nnorwitz@gmail.com>
parents:
38134
diff
changeset
|
2276 break; |
|
2195972f7391
Fix #132 from Coverity, retval could have been derefed
Neal Norwitz <nnorwitz@gmail.com>
parents:
38134
diff
changeset
|
2277 } |
|
31647
d10c778af167
Move the code for BREAK and CONTINUE_LOOP to be near FOR_ITER.
Raymond Hettinger <python@rcn.com>
parents:
31646
diff
changeset
|
2278 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
|
2279 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
|
2280 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2281 case SETUP_LOOP: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2282 case SETUP_EXCEPT: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2283 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
|
2284 /* 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
|
2285 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
|
2286 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
|
2287 */ |
|
37564
c782cf6b516e
SF Patch #1463867: Improved generator finalization to allow generators
Phillip J. Eby <pje@telecommunity.com>
parents:
37286
diff
changeset
|
2288 |
| 5368 | 2289 PyFrame_BlockSetup(f, opcode, INSTR_OFFSET() + oparg, |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2290 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
|
2291 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2292 |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2293 case WITH_CLEANUP: |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2294 { |
|
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
|
2295 /* 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
|
2296 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
|
2297 - 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
|
2298 - (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
|
2299 - 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
|
2300 - (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
|
2301 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
|
2302 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
|
2303 EXIT(TOP, SECOND, THIRD) |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2304 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
|
2305 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
|
2306 |
|
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
|
2307 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
|
2308 the rest in the same order. |
|
36737
fa92fe15251a
Updates to the with-statement:
Guido van Rossum <guido@python.org>
parents:
36712
diff
changeset
|
2309 |
|
fa92fe15251a
Updates to the with-statement:
Guido van Rossum <guido@python.org>
parents:
36712
diff
changeset
|
2310 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
|
2311 *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
|
2312 "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
|
2313 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
|
2314 should still be resumed.) |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2315 */ |
| 38418 | 2316 |
|
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
|
2317 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
|
2318 |
|
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
|
2319 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
|
2320 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
|
2321 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
|
2322 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
|
2323 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
|
2324 } |
|
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
|
2325 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
|
2326 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
|
2327 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
|
2328 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
|
2329 /* 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
|
2330 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
|
2331 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
|
2332 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
|
2333 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
|
2334 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
|
2335 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
|
2336 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
|
2337 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
|
2338 } |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2339 u = v = w = Py_None; |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2340 } |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2341 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
|
2342 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
|
2343 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
|
2344 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
|
2345 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
|
2346 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
|
2347 SET_THIRD(w); |
|
36926
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
2348 } |
|
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
2349 /* 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
|
2350 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
|
2351 NULL); |
|
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
|
2352 if (x == NULL) { |
|
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
|
2353 Py_DECREF(exit_func); |
|
36926
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
2354 break; /* Go to error exit */ |
|
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
|
2355 } |
|
36926
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
2356 if (u != Py_None && PyObject_IsTrue(x)) { |
|
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
2357 /* 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
|
2358 STACKADJ(-2); |
|
36737
fa92fe15251a
Updates to the with-statement:
Guido van Rossum <guido@python.org>
parents:
36712
diff
changeset
|
2359 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
|
2360 SET_TOP(Py_None); |
|
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
2361 Py_DECREF(u); |
|
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
2362 Py_DECREF(v); |
|
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
2363 Py_DECREF(w); |
|
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
2364 } 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
|
2365 /* 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
|
2366 above. Let END_FINALLY do its thing */ |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2367 } |
|
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
|
2368 Py_DECREF(x); |
|
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
|
2369 Py_DECREF(exit_func); |
|
45624
6068b75ec27a
compile.c always emits END_FINALLY after WITH_CLEANUP, so predict that in
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
45011
diff
changeset
|
2370 PREDICT(END_FINALLY); |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2371 break; |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2372 } |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2373 |
|
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
|
2374 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
|
2375 { |
|
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
2376 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
|
2377 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
|
2378 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
|
2379 #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
|
2380 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
|
2381 #else |
|
32359
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
2382 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
|
2383 #endif |
|
32359
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
2384 stack_pointer = sp; |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
2385 PUSH(x); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
2386 if (x != NULL) |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
2387 continue; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
2388 break; |
|
32359
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
2389 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2390 |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2391 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
|
2392 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
|
2393 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
|
2394 { |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2395 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
|
2396 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
|
2397 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
|
2398 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
|
2399 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
|
2400 PCALL(PCALL_ALL); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2401 if (flags & CALL_FLAG_VAR) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2402 n++; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2403 if (flags & CALL_FLAG_KW) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2404 n++; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2405 pfunc = stack_pointer - n - 1; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2406 func = *pfunc; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2407 |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2408 if (PyMethod_Check(func) |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2409 && PyMethod_GET_SELF(func) != NULL) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2410 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
|
2411 Py_INCREF(self); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2412 func = PyMethod_GET_FUNCTION(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2413 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
|
2414 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
|
2415 *pfunc = self; |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2416 na++; |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2417 n++; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2418 } else |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2419 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
|
2420 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
|
2421 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
|
2422 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
|
2423 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
|
2424 stack_pointer = sp; |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2425 Py_DECREF(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2426 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2427 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
|
2428 w = POP(); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2429 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
|
2430 } |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2431 PUSH(x); |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2432 if (x != NULL) |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2433 continue; |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2434 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
|
2435 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2436 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2437 case MAKE_FUNCTION: |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2438 v = POP(); /* code object */ |
| 5368 | 2439 x = PyFunction_New(v, f->f_globals); |
| 2440 Py_DECREF(v); | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2441 /* XXX Maybe this should be a separate opcode? */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2442 if (x != NULL && oparg > 0) { |
| 5368 | 2443 v = PyTuple_New(oparg); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2444 if (v == NULL) { |
| 5368 | 2445 Py_DECREF(x); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2446 x = NULL; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2447 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2448 } |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
2449 while (--oparg >= 0) { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2450 w = POP(); |
| 5368 | 2451 PyTuple_SET_ITEM(v, oparg, w); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2452 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2453 err = PyFunction_SetDefaults(x, v); |
| 5368 | 2454 Py_DECREF(v); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2455 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2456 PUSH(x); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2457 break; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2458 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2459 case MAKE_CLOSURE: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2460 { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2461 v = POP(); /* code object */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2462 x = PyFunction_New(v, f->f_globals); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2463 Py_DECREF(v); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
2464 if (x != NULL) { |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
2465 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
|
2466 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
|
2467 /* 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
|
2468 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
|
2469 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2470 Py_DECREF(v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2471 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2472 if (x != NULL && oparg > 0) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2473 v = PyTuple_New(oparg); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2474 if (v == NULL) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2475 Py_DECREF(x); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2476 x = NULL; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2477 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2478 } |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
2479 while (--oparg >= 0) { |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2480 w = POP(); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2481 PyTuple_SET_ITEM(v, oparg, w); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2482 } |
|
50092
dc696deb2cf2
Issue 4597: Fix several cases in EvalFrameEx where an exception could be
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49940
diff
changeset
|
2483 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
|
2484 /* 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
|
2485 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
|
2486 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
|
2487 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2488 Py_DECREF(v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2489 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2490 PUSH(x); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2491 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2492 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2493 |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2494 case BUILD_SLICE: |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2495 if (oparg == 3) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2496 w = POP(); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2497 else |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2498 w = NULL; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2499 v = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2500 u = TOP(); |
| 5018 | 2501 x = PySlice_New(u, v, w); |
| 5368 | 2502 Py_DECREF(u); |
| 2503 Py_DECREF(v); | |
| 2504 Py_XDECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2505 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
|
2506 if (x != NULL) continue; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2507 break; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2508 |
|
14147
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
2509 case EXTENDED_ARG: |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
2510 opcode = NEXTOP(); |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
2511 oparg = oparg<<16 | NEXTARG(); |
|
14147
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
2512 goto dispatch_opcode; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2513 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2514 default: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2515 fprintf(stderr, |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2516 "XXX lineno: %d, opcode: %d\n", |
| 24844 | 2517 PyCode_Addr2Line(f->f_code, f->f_lasti), |
| 2518 opcode); | |
| 5368 | 2519 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
|
2520 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2521 break; |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2522 |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2523 #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
|
2524 } |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2525 #endif |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2526 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2527 } /* switch */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2528 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2529 on_error: |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2530 |
|
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
|
2531 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
|
2532 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2533 /* Quickly continue if no error occurred */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2534 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2535 if (why == WHY_NOT) { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2536 if (err == 0 && x != NULL) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2537 #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
|
2538 /* This check is expensive! */ |
| 5368 | 2539 if (PyErr_Occurred()) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2540 fprintf(stderr, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2541 "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
|
2542 else { |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
2543 #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
|
2544 READ_TIMESTAMP(loop1); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2545 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
|
2546 #ifdef CHECKEXC |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
2547 } |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
2548 #endif |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2549 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2550 why = WHY_EXCEPTION; |
| 5368 | 2551 x = Py_None; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2552 err = 0; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2553 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2554 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2555 /* Double-check exception status */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2556 |
|
31900
0265bf9912ea
Some (but not all) of the why code bitfield tests ran faster as
Raymond Hettinger <python@rcn.com>
parents:
31894
diff
changeset
|
2557 if (why == WHY_EXCEPTION || why == WHY_RERAISE) { |
| 5368 | 2558 if (!PyErr_Occurred()) { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2559 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
|
2560 "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
|
2561 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2562 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2563 } |
|
10363
4daab7a9f566
Always test for an error return (usually NULL or -1) without setting
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
2564 #ifdef CHECKEXC |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2565 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
|
2566 /* This check is expensive! */ |
| 5368 | 2567 if (PyErr_Occurred()) { |
|
45011
a3d5700b1d5a
Reduce buffer size since we do not need 1k
Neal Norwitz <nnorwitz@gmail.com>
parents:
44894
diff
changeset
|
2568 char buf[128]; |
|
30861
c89fd7eaf875
Make undetected error on stack unwind a fatal error.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
30801
diff
changeset
|
2569 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
|
2570 "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
|
2571 Py_FatalError(buf); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2572 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2573 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2574 #endif |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2575 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2576 /* 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
|
2577 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2578 if (why == WHY_EXCEPTION) { |
| 5368 | 2579 PyTraceBack_Here(f); |
| 567 | 2580 |
|
20247
a4d328d50897
Rationalize the events passed to the profiler (no changes for the tracer).
Fred Drake <fdrake@acm.org>
parents:
20183
diff
changeset
|
2581 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
|
2582 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
|
2583 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
|
2584 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2585 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2586 /* 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
|
2587 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2588 if (why == WHY_RERAISE) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2589 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2590 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2591 /* Unwind stacks if a (pseudo) exception occurred */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2592 |
|
31462
d5c047807c69
SF patch #864059: optimize eval_frame
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2593 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
|
2594 while (why != WHY_NOT && f->f_iblock > 0) { |
| 5368 | 2595 PyTryBlock *b = PyFrame_BlockPop(f); |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2596 |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
2597 assert(why != WHY_YIELD); |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2598 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
|
2599 /* For a continue inside a try block, |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2600 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
|
2601 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
|
2602 b->b_level); |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2603 why = WHY_NOT; |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2604 JUMPTO(PyInt_AS_LONG(retval)); |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2605 Py_DECREF(retval); |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2606 break; |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2607 } |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2608 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2609 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
|
2610 v = POP(); |
| 5368 | 2611 Py_XDECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2612 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2613 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
|
2614 why = WHY_NOT; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2615 JUMPTO(b->b_handler); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2616 break; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2617 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2618 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
|
2619 (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
|
2620 why == WHY_EXCEPTION)) { |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2621 if (why == WHY_EXCEPTION) { |
| 5368 | 2622 PyObject *exc, *val, *tb; |
| 2623 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
|
2624 if (val == NULL) { |
| 5368 | 2625 val = Py_None; |
| 2626 Py_INCREF(val); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2627 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2628 /* Make the raw exception data |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2629 available to the handler, |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2630 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
|
2631 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
|
2632 this for 'finally'. */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2633 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
|
2634 PyErr_NormalizeException( |
|
32aacd753f34
eval_code2(), set_exc_info(): Call PyErr_NormalizeException() the
Barry Warsaw <barry@python.org>
parents:
6160
diff
changeset
|
2635 &exc, &val, &tb); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2636 set_exc_info(tstate, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2637 exc, val, tb); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2638 } |
|
20114
233f9606ba8e
Prevent a NULL pointer from being pushed onto the stack.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20064
diff
changeset
|
2639 if (tb == NULL) { |
|
233f9606ba8e
Prevent a NULL pointer from being pushed onto the stack.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20064
diff
changeset
|
2640 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
|
2641 PUSH(Py_None); |
|
233f9606ba8e
Prevent a NULL pointer from being pushed onto the stack.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20064
diff
changeset
|
2642 } else |
|
233f9606ba8e
Prevent a NULL pointer from being pushed onto the stack.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20064
diff
changeset
|
2643 PUSH(tb); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2644 PUSH(val); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2645 PUSH(exc); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2646 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2647 else { |
|
31874
c88d4610f283
Coded WHY flags as bitfields (taking inspiration from tp_flags).
Raymond Hettinger <python@rcn.com>
parents:
31872
diff
changeset
|
2648 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
|
2649 PUSH(retval); |
| 5368 | 2650 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
|
2651 PUSH(v); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2652 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2653 why = WHY_NOT; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2654 JUMPTO(b->b_handler); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2655 break; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2656 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2657 } /* unwind stack */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2658 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2659 /* 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
|
2660 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2661 if (why != WHY_NOT) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2662 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
|
2663 READ_TIMESTAMP(loop1); |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2664 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2665 } /* main loop */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2666 |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
2667 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
|
2668 /* 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
|
2669 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
|
2670 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
|
2671 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
|
2672 } |
|
97709fd8fda0
Fix for SF bug #489671 (Neil Norwitz): memory leak in test_richcmp.
Guido van Rossum <guido@python.org>
parents:
21252
diff
changeset
|
2673 |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
2674 if (why != WHY_RETURN) |
| 567 | 2675 retval = NULL; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2676 |
|
31462
d5c047807c69
SF patch #864059: optimize eval_frame
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2677 fast_yield: |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2678 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
|
2679 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
|
2680 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
|
2681 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
|
2682 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
|
2683 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
|
2684 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
|
2685 retval = NULL; |
|
700f08369092
Port from the Python 2.4 branch, patches for SF bug # 900092,
Barry Warsaw <barry@python.org>
parents:
35298
diff
changeset
|
2686 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
|
2687 } |
|
700f08369092
Port from the Python 2.4 branch, patches for SF bug # 900092,
Barry Warsaw <barry@python.org>
parents:
35298
diff
changeset
|
2688 } |
|
700f08369092
Port from the Python 2.4 branch, patches for SF bug # 900092,
Barry Warsaw <barry@python.org>
parents:
35298
diff
changeset
|
2689 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
|
2690 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
|
2691 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
|
2692 PyTrace_RETURN, NULL); |
| 567 | 2693 } |
| 2694 } | |
|
20247
a4d328d50897
Rationalize the events passed to the profiler (no changes for the tracer).
Fred Drake <fdrake@acm.org>
parents:
20183
diff
changeset
|
2695 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
|
2696 if (why == WHY_EXCEPTION) |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2697 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
|
2698 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
|
2699 PyTrace_RETURN, NULL); |
|
20257
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2700 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
|
2701 tstate->c_profileobj, f, |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2702 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
|
2703 Py_XDECREF(retval); |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2704 retval = NULL; |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2705 why = WHY_EXCEPTION; |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2706 } |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
2707 } |
| 567 | 2708 } |
|
5023
75c1ee882a4a
Kill all local variables on function return. This closes a gigantic
Guido van Rossum <guido@python.org>
parents:
5021
diff
changeset
|
2709 |
| 38418 | 2710 if (tstate->frame->f_exc_type != NULL) |
| 2711 reset_exc_info(tstate); | |
| 2712 else { | |
| 2713 assert(tstate->frame->f_exc_value == NULL); | |
| 2714 assert(tstate->frame->f_exc_traceback == NULL); | |
| 2715 } | |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2716 |
|
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
|
2717 /* pop frame */ |
| 43408 | 2718 exit_eval_frame: |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
2719 Py_LeaveRecursiveCall(); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2720 tstate->frame = f->f_back; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2721 |
| 567 | 2722 return retval; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2723 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2724 |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2725 /* 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
|
2726 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
|
2727 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
|
2728 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
2729 PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
2730 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
|
2731 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
|
2732 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
|
2733 { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2734 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
|
2735 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
|
2736 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
|
2737 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
|
2738 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
|
2739 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2740 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
|
2741 PyErr_SetString(PyExc_SystemError, |
|
19198
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19158
diff
changeset
|
2742 "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
|
2743 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
|
2744 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2745 |
|
39466
c7ff02c1559f
Move/copy assert for tstate != NULL before first use.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39463
diff
changeset
|
2746 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
|
2747 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
|
2748 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
|
2749 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
|
2750 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
|
2751 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2752 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
|
2753 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
|
2754 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2755 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
|
2756 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
|
2757 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
|
2758 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
|
2759 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
|
2760 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
|
2761 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
|
2762 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
|
2763 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
|
2764 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
|
2765 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
|
2766 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
|
2767 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
|
2768 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2769 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
|
2770 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
|
2771 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
|
2772 "%.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
|
2773 "%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
|
2774 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
|
2775 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
|
2776 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
|
2777 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
|
2778 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
|
2779 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
|
2780 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
|
2781 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2782 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
|
2783 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2784 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
|
2785 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
|
2786 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
|
2787 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
|
2788 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2789 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
|
2790 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
|
2791 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
|
2792 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
|
2793 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
|
2794 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
|
2795 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
|
2796 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
|
2797 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
|
2798 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2799 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2800 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
|
2801 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
|
2802 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
|
2803 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
|
2804 int j; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2805 if (keyword == NULL || !PyString_Check(keyword)) { |
|
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
|
2806 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
|
2807 "%.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
|
2808 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
|
2809 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
|
2810 } |
|
48077
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
2811 /* 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
|
2812 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
|
2813 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
|
2814 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
|
2815 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
|
2816 if (nm == keyword) |
|
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
2817 goto kw_found; |
|
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
2818 } |
|
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
2819 /* 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
|
2820 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
|
2821 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
|
2822 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
|
2823 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
|
2824 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
|
2825 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
|
2826 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
|
2827 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
|
2828 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2829 /* 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
|
2830 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
|
2831 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
|
2832 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
|
2833 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
|
2834 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
|
2835 "%.200s() got an unexpected " |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2836 "keyword argument '%.400s'", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2837 PyString_AsString(co->co_name), |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2838 PyString_AsString(keyword)); |
|
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
|
2839 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
|
2840 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2841 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
|
2842 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
|
2843 } |
|
48077
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
2844 kw_found: |
|
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
2845 if (GETLOCAL(j) != NULL) { |
|
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
2846 PyErr_Format(PyExc_TypeError, |
|
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
2847 "%.200s() got multiple " |
|
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
2848 "values for keyword " |
|
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
2849 "argument '%.400s'", |
|
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
2850 PyString_AsString(co->co_name), |
|
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
2851 PyString_AsString(keyword)); |
|
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
2852 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
|
2853 } |
|
48077
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
2854 Py_INCREF(value); |
|
30485bc17268
Raymond's patch for #1819: speedup function calls with named parameters
Antoine Pitrou <solipsis@pitrou.net>
parents:
47985
diff
changeset
|
2855 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
|
2856 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2857 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
|
2858 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
|
2859 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
|
2860 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
|
2861 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
|
2862 "%.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
|
2863 "%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
|
2864 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
|
2865 ((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
|
2866 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
|
2867 : "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
|
2868 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
|
2869 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
|
2870 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
|
2871 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2872 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2873 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
|
2874 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
|
2875 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
|
2876 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
|
2877 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
|
2878 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
|
2879 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
|
2880 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
|
2881 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
|
2882 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2883 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2884 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2885 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2886 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
|
2887 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
|
2888 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
|
2889 "%.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
|
2890 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
|
2891 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
|
2892 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
|
2893 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2894 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2895 /* 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
|
2896 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
|
2897 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
|
2898 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
|
2899 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
|
2900 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
|
2901 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2902 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
|
2903 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
|
2904 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
|
2905 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
|
2906 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
|
2907 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
2908 /* Initialize each cell var, taking into account |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
2909 cell vars that are initialized from arguments. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
2910 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
2911 Should arrange for the compiler to put cellvars |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
2912 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
|
2913 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
|
2914 */ |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38217
diff
changeset
|
2915 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
|
2916 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
|
2917 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
|
2918 found = 0; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
2919 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
|
2920 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
|
2921 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
|
2922 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
|
2923 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
|
2924 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
|
2925 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
|
2926 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
|
2927 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
|
2928 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
|
2929 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2930 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2931 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
|
2932 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
|
2933 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
|
2934 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
|
2935 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
|
2936 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2937 } |
|
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 } |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38217
diff
changeset
|
2939 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
|
2940 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
|
2941 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
|
2942 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
|
2943 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
|
2944 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
|
2945 } |
|
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 } |
|
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 |
|
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 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
|
2949 /* 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
|
2950 * 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
|
2951 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
|
2952 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
|
2953 |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
2954 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
|
2955 |
|
18194
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
2956 /* 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
|
2957 * 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
|
2958 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
|
2959 } |
|
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 |
| 43408 | 2961 retval = PyEval_EvalFrameEx(f,0); |
| 2962 | |
| 2963 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
|
2964 |
|
21058
9df82c13c675
SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents:
21027
diff
changeset
|
2965 /* 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
|
2966 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
|
2967 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
|
2968 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
|
2969 */ |
|
9df82c13c675
SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents:
21027
diff
changeset
|
2970 assert(tstate != NULL); |
|
9df82c13c675
SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents:
21027
diff
changeset
|
2971 ++tstate->recursion_depth; |
| 43408 | 2972 Py_DECREF(f); |
|
21058
9df82c13c675
SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents:
21027
diff
changeset
|
2973 --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
|
2974 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
|
2975 } |
|
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 |
|
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 |
|
28121
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2978 /* 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
|
2979 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2980 - 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
|
2981 '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
|
2982 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2983 - 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
|
2984 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
|
2985 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2986 - 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
|
2987 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
|
2988 can pick it up. This is the primary task of set_exc_info(). |
| 38418 | 2989 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
|
2990 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2991 - 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
|
2992 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2993 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
|
2994 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
|
2995 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
|
2996 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
|
2997 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
|
2998 this: |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2999 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3000 try: |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3001 "something that may fail" |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3002 except "some exception": |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3003 "do something else first" |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3004 "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
|
3005 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3006 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
|
3007 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
|
3008 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
|
3009 follows: |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3010 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3011 - 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
|
3012 *in that frame*. |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3013 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3014 - 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
|
3015 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
|
3016 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
|
3017 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3018 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
|
3019 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
|
3020 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
|
3021 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
|
3022 (Example: traceback.print_exc()). |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3023 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3024 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
|
3025 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
|
3026 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
|
3027 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3028 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
|
3029 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
|
3030 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
|
3031 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
|
3032 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
|
3033 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
|
3034 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
|
3035 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
|
3036 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
|
3037 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3038 */ |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
3039 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
3040 static void |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3041 set_exc_info(PyThreadState *tstate, |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3042 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
|
3043 { |
| 38418 | 3044 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
|
3045 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
|
3046 |
| 38418 | 3047 assert(type != NULL); |
| 3048 assert(frame != NULL); | |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3049 if (frame->f_exc_type == NULL) { |
| 38418 | 3050 assert(frame->f_exc_value == NULL); |
| 3051 assert(frame->f_exc_traceback == NULL); | |
| 3052 /* This frame didn't catch an exception before. */ | |
| 3053 /* 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
|
3054 if (tstate->exc_type == NULL) { |
| 38418 | 3055 /* 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
|
3056 Py_INCREF(Py_None); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3057 tstate->exc_type = Py_None; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3058 } |
| 38418 | 3059 Py_INCREF(tstate->exc_type); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3060 Py_XINCREF(tstate->exc_value); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3061 Py_XINCREF(tstate->exc_traceback); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3062 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
|
3063 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
|
3064 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
|
3065 } |
| 38418 | 3066 /* 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
|
3067 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
|
3068 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
|
3069 tmp_tb = tstate->exc_traceback; |
| 38418 | 3070 Py_INCREF(type); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3071 Py_XINCREF(value); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3072 Py_XINCREF(tb); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3073 tstate->exc_type = type; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3074 tstate->exc_value = value; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3075 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
|
3076 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
|
3077 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
|
3078 Py_XDECREF(tmp_tb); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3079 /* For b/w compatibility */ |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3080 PySys_SetObject("exc_type", type); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3081 PySys_SetObject("exc_value", value); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3082 PySys_SetObject("exc_traceback", tb); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3083 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3084 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
3085 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3086 reset_exc_info(PyThreadState *tstate) |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3087 { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3088 PyFrameObject *frame; |
|
5557
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
3089 PyObject *tmp_type, *tmp_value, *tmp_tb; |
| 38418 | 3090 |
| 3091 /* It's a precondition that the thread state's frame caught an | |
| 3092 * exception -- verify in a debug build. | |
| 3093 */ | |
| 3094 assert(tstate != NULL); | |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3095 frame = tstate->frame; |
| 38418 | 3096 assert(frame != NULL); |
| 3097 assert(frame->f_exc_type != NULL); | |
| 3098 | |
| 3099 /* Copy the frame's exception info back to the thread state. */ | |
| 3100 tmp_type = tstate->exc_type; | |
| 3101 tmp_value = tstate->exc_value; | |
| 3102 tmp_tb = tstate->exc_traceback; | |
| 3103 Py_INCREF(frame->f_exc_type); | |
| 3104 Py_XINCREF(frame->f_exc_value); | |
| 3105 Py_XINCREF(frame->f_exc_traceback); | |
| 3106 tstate->exc_type = frame->f_exc_type; | |
| 3107 tstate->exc_value = frame->f_exc_value; | |
| 3108 tstate->exc_traceback = frame->f_exc_traceback; | |
| 3109 Py_XDECREF(tmp_type); | |
| 3110 Py_XDECREF(tmp_value); | |
| 3111 Py_XDECREF(tmp_tb); | |
| 3112 | |
| 3113 /* For b/w compatibility */ | |
| 3114 PySys_SetObject("exc_type", frame->f_exc_type); | |
| 3115 PySys_SetObject("exc_value", frame->f_exc_value); | |
| 3116 PySys_SetObject("exc_traceback", frame->f_exc_traceback); | |
| 3117 | |
| 3118 /* 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
|
3119 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
|
3120 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
|
3121 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
|
3122 frame->f_exc_type = NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3123 frame->f_exc_value = NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3124 frame->f_exc_traceback = NULL; |
| 38418 | 3125 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
|
3126 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
|
3127 Py_XDECREF(tmp_tb); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3128 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3129 |
|
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
|
3130 /* 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
|
3131 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
|
3132 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
|
3133 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
|
3134 { |
|
7946
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
3135 if (type == NULL) { |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
3136 /* Reraise */ |
|
31797
846b3ee7e106
Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31796
diff
changeset
|
3137 PyThreadState *tstate = PyThreadState_GET(); |
|
7946
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
3138 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
|
3139 value = tstate->exc_value; |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
3140 tb = tstate->exc_traceback; |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
3141 Py_XINCREF(type); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
3142 Py_XINCREF(value); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
3143 Py_XINCREF(tb); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
3144 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3145 |
|
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
|
3146 /* 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
|
3147 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
|
3148 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
|
3149 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
|
3150 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
|
3151 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
|
3152 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
|
3153 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
|
3154 |
|
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
|
3155 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
|
3156 |
|
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
|
3157 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
|
3158 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
|
3159 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
|
3160 |
|
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
|
3161 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
|
3162 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
|
3163 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
|
3164 |
|
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
|
3165 /* 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
|
3166 NULL. */ |
| 5368 | 3167 if (tb == Py_None) { |
| 3168 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
|
3169 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
|
3170 } |
|
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
|
3171 else if (tb != NULL && !PyTraceBack_Check(tb)) { |
| 5368 | 3172 PyErr_SetString(PyExc_TypeError, |
| 15318 | 3173 "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
|
3174 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
|
3175 } |
|
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
|
3176 |
|
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
|
3177 /* 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
|
3178 if (value == NULL) { |
| 5368 | 3179 value = Py_None; |
| 3180 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
|
3181 } |
|
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
|
3182 |
|
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
|
3183 /* Next, repeatedly, replace a tuple exception with its first item */ |
| 5368 | 3184 while (PyTuple_Check(type) && PyTuple_Size(type) > 0) { |
| 3185 PyObject *tmp = type; | |
| 3186 type = PyTuple_GET_ITEM(type, 0); | |
| 3187 Py_INCREF(type); | |
| 3188 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
|
3189 } |
|
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
|
3190 |
|
40735
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
3191 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
|
3192 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
|
3193 |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36737
diff
changeset
|
3194 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
|
3195 /* Raising an instance. The value should be a dummy. */ |
| 5368 | 3196 if (value != Py_None) { |
| 3197 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
|
3198 "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
|
3199 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
|
3200 } |
|
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
|
3201 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
|
3202 /* Normalize to raise <class>, <instance> */ |
| 5368 | 3203 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
|
3204 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
|
3205 type = PyExceptionInstance_Class(type); |
| 5368 | 3206 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
|
3207 } |
|
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
|
3208 } |
|
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
|
3209 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
|
3210 /* 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
|
3211 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
|
3212 PyErr_Format(PyExc_TypeError, |
|
46578
7670005da8c5
A little reformating of Py3k warnings
Benjamin Peterson <benjamin@python.org>
parents:
46573
diff
changeset
|
3213 "exceptions must be classes or instances, not %s", |
|
7670005da8c5
A little reformating of Py3k warnings
Benjamin Peterson <benjamin@python.org>
parents:
46573
diff
changeset
|
3214 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
|
3215 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
|
3216 } |
|
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
|
3217 |
|
27e7dc2e6290
Issue #2341: Add a Py3k warning when raising an exception that doesn't
Guido van Rossum <guido@python.org>
parents:
45820
diff
changeset
|
3218 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
|
3219 if (Py_Py3kWarningFlag && PyClass_Check(type)) { |
|
46573
aef3501d8e77
Use PyErr_WarnPy3k throughout
Benjamin Peterson <benjamin@python.org>
parents:
46075
diff
changeset
|
3220 if (PyErr_WarnEx(PyExc_DeprecationWarning, |
|
46578
7670005da8c5
A little reformating of Py3k warnings
Benjamin Peterson <benjamin@python.org>
parents:
46573
diff
changeset
|
3221 "exceptions must derive from BaseException " |
|
7670005da8c5
A little reformating of Py3k warnings
Benjamin Peterson <benjamin@python.org>
parents:
46573
diff
changeset
|
3222 "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
|
3223 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
|
3224 } |
|
27e7dc2e6290
Issue #2341: Add a Py3k warning when raising an exception that doesn't
Guido van Rossum <guido@python.org>
parents:
45820
diff
changeset
|
3225 |
| 5368 | 3226 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
|
3227 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
|
3228 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
|
3229 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
|
3230 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
|
3231 raise_error: |
| 5368 | 3232 Py_XDECREF(value); |
| 3233 Py_XDECREF(type); | |
| 3234 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
|
3235 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
|
3236 } |
|
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
|
3237 |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3238 /* 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
|
3239 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
|
3240 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
3241 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
|
3242 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
|
3243 { |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3244 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
|
3245 PyObject *it; /* iter(v) */ |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3246 PyObject *w; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3247 |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3248 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
|
3249 |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3250 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
|
3251 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
|
3252 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
|
3253 |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3254 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
|
3255 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
|
3256 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
|
3257 /* 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
|
3258 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
|
3259 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
|
3260 "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
|
3261 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
|
3262 } |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3263 goto Error; |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3264 } |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3265 *--sp = w; |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3266 } |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3267 |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3268 /* 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
|
3269 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
|
3270 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
|
3271 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
|
3272 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
|
3273 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
|
3274 return 1; |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3275 } |
|
21170
2dfc600f99ce
unpack_iterable(): Add a missing DECREF in an error case. Reported by
Guido van Rossum <guido@python.org>
parents:
21058
diff
changeset
|
3276 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
|
3277 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
|
3278 /* 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
|
3279 Error: |
|
6160
79592761b331
unpack_sequence(): In finally clause, watch out for Py_DECREF
Barry Warsaw <barry@python.org>
parents:
6157
diff
changeset
|
3280 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
|
3281 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
|
3282 Py_XDECREF(it); |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3283 return 0; |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3284 } |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3285 |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3286 |
| 567 | 3287 #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
|
3288 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3289 prtrace(PyObject *v, char *str) |
| 69 | 3290 { |
| 86 | 3291 printf("%s ", str); |
| 5368 | 3292 if (PyObject_Print(v, stdout, 0) != 0) |
| 3293 PyErr_Clear(); /* Don't know what else to do */ | |
| 86 | 3294 printf("\n"); |
|
12579
978253542076
Add useless 'return 1' to prtrace() to shut up VC++.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
3295 return 1; |
| 69 | 3296 } |
| 86 | 3297 #endif |
| 69 | 3298 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
3299 static void |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3300 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
|
3301 { |
| 5368 | 3302 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
|
3303 int err; |
| 5368 | 3304 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
|
3305 if (value == NULL) { |
| 5368 | 3306 value = Py_None; |
| 3307 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
|
3308 } |
|
30683
3b59fa5d25b1
Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents:
29669
diff
changeset
|
3309 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
|
3310 if (arg == NULL) { |
| 5368 | 3311 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
|
3312 return; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
3313 } |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3314 err = call_trace(func, self, f, PyTrace_EXCEPTION, arg); |
| 5368 | 3315 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
|
3316 if (err == 0) |
| 5368 | 3317 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
|
3318 else { |
| 5368 | 3319 Py_XDECREF(type); |
| 3320 Py_XDECREF(value); | |
| 3321 Py_XDECREF(traceback); | |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3322 } |
|
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3323 } |
|
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3324 |
|
43845
76844a0a579f
Merge from py3k branch:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43784
diff
changeset
|
3325 static int |
|
20257
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3326 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
|
3327 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
|
3328 { |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3329 PyObject *type, *value, *traceback; |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3330 int err; |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3331 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
|
3332 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
|
3333 if (err == 0) |
|
43845
76844a0a579f
Merge from py3k branch:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43784
diff
changeset
|
3334 { |
|
20257
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3335 PyErr_Restore(type, value, traceback); |
|
43845
76844a0a579f
Merge from py3k branch:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43784
diff
changeset
|
3336 return 0; |
|
76844a0a579f
Merge from py3k branch:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43784
diff
changeset
|
3337 } |
|
20257
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3338 else { |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3339 Py_XDECREF(type); |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3340 Py_XDECREF(value); |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3341 Py_XDECREF(traceback); |
|
43845
76844a0a579f
Merge from py3k branch:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43784
diff
changeset
|
3342 return -1; |
|
20257
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3343 } |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3344 } |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3345 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
3346 static int |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3347 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
|
3348 int what, PyObject *arg) |
| 567 | 3349 { |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3350 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
|
3351 int result; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3352 if (tstate->tracing) |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3353 return 0; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3354 tstate->tracing++; |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
3355 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
|
3356 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
|
3357 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
|
3358 || (tstate->c_profilefunc != NULL)); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3359 tstate->tracing--; |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3360 return result; |
| 567 | 3361 } |
| 3362 | |
|
28556
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3363 PyObject * |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3364 _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
|
3365 { |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3366 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
|
3367 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
|
3368 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
|
3369 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
|
3370 PyObject *result; |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3371 |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3372 tstate->tracing = 0; |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3373 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
|
3374 || (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
|
3375 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
|
3376 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
|
3377 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
|
3378 return result; |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3379 } |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3380 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
3381 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
|
3382 maybe_call_line_trace(Py_tracefunc func, PyObject *obj, |
| 31768 | 3383 PyFrameObject *frame, int *instr_lb, int *instr_ub, |
| 3384 int *instr_prev) | |
| 24844 | 3385 { |
|
26110
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
3386 int result = 0; |
|
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
3387 |
|
37838
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37597
diff
changeset
|
3388 /* If the last instruction executed isn't in the current |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37597
diff
changeset
|
3389 instruction window, reset the window. If the last |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37597
diff
changeset
|
3390 instruction happens to fall at the start of a line or if it |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37597
diff
changeset
|
3391 represents a jump backwards, call the trace function. |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37597
diff
changeset
|
3392 */ |
|
25078
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24978
diff
changeset
|
3393 if ((frame->f_lasti < *instr_lb || frame->f_lasti >= *instr_ub)) { |
| 43408 | 3394 int line; |
| 3395 PyAddrPair bounds; | |
| 3396 | |
| 3397 line = PyCode_CheckLineNumber(frame->f_code, frame->f_lasti, | |
| 3398 &bounds); | |
| 3399 if (line >= 0) { | |
|
25207
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25109
diff
changeset
|
3400 frame->f_lineno = line; |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
3401 result = call_trace(func, obj, frame, |
|
26110
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
3402 PyTrace_LINE, Py_None); |
| 43408 | 3403 } |
| 3404 *instr_lb = bounds.ap_lower; | |
| 3405 *instr_ub = bounds.ap_upper; | |
| 24844 | 3406 } |
| 31768 | 3407 else if (frame->f_lasti <= *instr_prev) { |
|
37838
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37597
diff
changeset
|
3408 result = call_trace(func, obj, frame, PyTrace_LINE, Py_None); |
| 31768 | 3409 } |
| 3410 *instr_prev = frame->f_lasti; | |
|
26110
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
3411 return result; |
| 24844 | 3412 } |
| 3413 | |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3414 void |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3415 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
|
3416 { |
|
31797
846b3ee7e106
Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31796
diff
changeset
|
3417 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
|
3418 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
|
3419 Py_XINCREF(arg); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3420 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
|
3421 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
|
3422 /* 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
|
3423 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
|
3424 Py_XDECREF(temp); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3425 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
|
3426 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
|
3427 /* 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
|
3428 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
|
3429 } |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3430 |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3431 void |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3432 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
|
3433 { |
|
31797
846b3ee7e106
Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31796
diff
changeset
|
3434 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
|
3435 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
|
3436 _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
|
3437 Py_XINCREF(arg); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3438 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
|
3439 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
|
3440 /* 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
|
3441 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
|
3442 Py_XDECREF(temp); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3443 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
|
3444 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
|
3445 /* 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
|
3446 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
|
3447 || (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
|
3448 } |
|
4cb34314bd97
Instead of initializing & interning the strings passed to the profile
Fred Drake <fdrake@acm.org>
parents:
18128
diff
changeset
|
3449 |
| 5368 | 3450 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3451 PyEval_GetBuiltins(void) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3452 { |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
3453 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
|
3454 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
|
3455 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
|
3456 else |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3457 return current_frame->f_builtins; |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3458 } |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3459 |
| 5368 | 3460 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3461 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
|
3462 { |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
3463 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
|
3464 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
|
3465 return NULL; |
| 5368 | 3466 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
|
3467 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
|
3468 } |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3469 |
| 5368 | 3470 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3471 PyEval_GetGlobals(void) |
| 69 | 3472 { |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
3473 PyFrameObject *current_frame = PyEval_GetFrame(); |
| 86 | 3474 if (current_frame == NULL) |
| 3475 return NULL; | |
| 3476 else | |
| 3477 return current_frame->f_globals; | |
| 69 | 3478 } |
| 3479 | |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
3480 PyFrameObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3481 PyEval_GetFrame(void) |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
3482 { |
|
31797
846b3ee7e106
Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31796
diff
changeset
|
3483 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
|
3484 return _PyThreadState_GetFrame(tstate); |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
3485 } |
|
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
3486 |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3487 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3488 PyEval_GetRestricted(void) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3489 { |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
3490 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
|
3491 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
|
3492 } |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3493 |
|
5606
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
3494 int |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3495 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
|
3496 { |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
3497 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
|
3498 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
|
3499 |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3500 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
|
3501 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
|
3502 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
|
3503 if (compilerflags) { |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3504 result = 1; |
|
19350
5b6a6d7d44ae
ceval, PyEval_MergeCompilerFlags: wasn't merging in the
Tim Peters <tim.peters@gmail.com>
parents:
19301
diff
changeset
|
3505 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
|
3506 } |
|
22468
eebae4f60d05
Disable the parser hacks that enabled the "yield" keyword using a future
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22398
diff
changeset
|
3507 #if 0 /* future keyword */ |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
3508 if (codeflags & CO_GENERATOR_ALLOWED) { |
|
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
3509 result = 1; |
|
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
3510 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
|
3511 } |
|
22468
eebae4f60d05
Disable the parser hacks that enabled the "yield" keyword using a future
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22398
diff
changeset
|
3512 #endif |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3513 } |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3514 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
|
3515 } |
|
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
|
3516 |
|
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
|
3517 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3518 Py_FlushLine(void) |
| 69 | 3519 { |
| 5368 | 3520 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
|
3521 if (f == NULL) |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
3522 return 0; |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
3523 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
|
3524 return 0; |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
3525 return PyFile_WriteString("\n", f); |
| 69 | 3526 } |
| 3527 | |
| 86 | 3528 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3529 /* External interface to call any callable object. |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3530 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
|
3531 |
|
6206
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
3532 #undef PyEval_CallObject |
|
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
3533 /* for backward compatibility: export this interface */ |
|
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
3534 |
| 5368 | 3535 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3536 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
|
3537 { |
| 5368 | 3538 return PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3539 } |
|
6206
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
3540 #define PyEval_CallObject(func,arg) \ |
|
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
3541 PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3542 |
| 5368 | 3543 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3544 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
|
3545 { |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3546 PyObject *result; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3547 |
|
36877
e9a7a2784e17
SF #1444030: Fix several potential defects found by Coverity.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
36803
diff
changeset
|
3548 if (arg == NULL) { |
| 5368 | 3549 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
|
3550 if (arg == NULL) |
|
e9a7a2784e17
SF #1444030: Fix several potential defects found by Coverity.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
36803
diff
changeset
|
3551 return NULL; |
|
e9a7a2784e17
SF #1444030: Fix several potential defects found by Coverity.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
36803
diff
changeset
|
3552 } |
| 5368 | 3553 else if (!PyTuple_Check(arg)) { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3554 PyErr_SetString(PyExc_TypeError, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3555 "argument list must be a tuple"); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3556 return NULL; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3557 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3558 else |
| 5368 | 3559 Py_INCREF(arg); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3560 |
| 5368 | 3561 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
|
3562 PyErr_SetString(PyExc_TypeError, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3563 "keyword list must be a dictionary"); |
|
12440
d47460b1a679
Charles Waldman writes:
Guido van Rossum <guido@python.org>
parents:
12320
diff
changeset
|
3564 Py_DECREF(arg); |
|
2894
4095782c940e
empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents:
2872
diff
changeset
|
3565 return NULL; |
|
4095782c940e
empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents:
2872
diff
changeset
|
3566 } |
|
4095782c940e
empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents:
2872
diff
changeset
|
3567 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3568 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
|
3569 Py_DECREF(arg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3570 return result; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3571 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3572 |
|
35999
9541369b0dca
Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35745
diff
changeset
|
3573 const char * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3574 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
|
3575 { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3576 if (PyMethod_Check(func)) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3577 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
|
3578 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
|
3579 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
|
3580 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
|
3581 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
|
3582 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
|
3583 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
|
3584 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
|
3585 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
|
3586 ((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
|
3587 } else { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3588 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
|
3589 } |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3590 } |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3591 |
|
35999
9541369b0dca
Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35745
diff
changeset
|
3592 const char * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3593 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
|
3594 { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3595 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
|
3596 return "()"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3597 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
|
3598 return "()"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3599 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
|
3600 return "()"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3601 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
|
3602 return " constructor"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3603 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
|
3604 return " instance"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3605 } else { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3606 return " object"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3607 } |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3608 } |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3609 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
3610 static void |
|
24870
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3611 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
|
3612 { |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3613 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
|
3614 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
|
3615 "%.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
|
3616 ((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
|
3617 nargs); |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3618 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
|
3619 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
|
3620 "%.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
|
3621 ((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
|
3622 nargs); |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3623 } |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3624 |
|
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
|
3625 #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
|
3626 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
|
3627 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
|
3628 tstate->c_profileobj, \ |
|
77913be294b9
Massive performance improvement for C extension and builtin tracing code
Nicholas Bastin <nick.bastin@gmail.com>
parents:
32398
diff
changeset
|
3629 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
|
3630 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
|
3631 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
|
3632 } \ |
|
23dda92de993
clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents:
35345
diff
changeset
|
3633 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
|
3634 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
|
3635 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
|
3636 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
|
3637 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
|
3638 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
|
3639 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
|
3640 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
|
3641 /* 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
|
3642 } 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
|
3643 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
|
3644 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
|
3645 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
|
3646 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
|
3647 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
|
3648 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
|
3649 } \ |
|
23dda92de993
clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents:
35345
diff
changeset
|
3650 } \ |
|
31796
1c117dbb2def
Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31768
diff
changeset
|
3651 } \ |
|
32409
77913be294b9
Massive performance improvement for C extension and builtin tracing code
Nicholas Bastin <nick.bastin@gmail.com>
parents:
32398
diff
changeset
|
3652 } \ |
|
77913be294b9
Massive performance improvement for C extension and builtin tracing code
Nicholas Bastin <nick.bastin@gmail.com>
parents:
32398
diff
changeset
|
3653 } 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
|
3654 x = call; \ |
|
31796
1c117dbb2def
Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31768
diff
changeset
|
3655 } |
|
1c117dbb2def
Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31768
diff
changeset
|
3656 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
3657 static PyObject * |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
3658 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
|
3659 #ifdef WITH_TSC |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
3660 , 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
|
3661 #endif |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
3662 ) |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3663 { |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3664 int na = oparg & 0xff; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3665 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
|
3666 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
|
3667 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
|
3668 PyObject *func = *pfunc; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3669 PyObject *x, *w; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3670 |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3671 /* 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
|
3672 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
|
3673 */ |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3674 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
|
3675 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
|
3676 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
|
3677 |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3678 PCALL(PCALL_CFUNCTION); |
|
24870
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3679 if (flags & (METH_NOARGS | METH_O)) { |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3680 PyCFunction meth = PyCFunction_GET_FUNCTION(func); |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3681 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
|
3682 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
|
3683 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
|
3684 } |
|
24870
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3685 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
|
3686 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
|
3687 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
|
3688 Py_DECREF(arg); |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3689 } |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3690 else { |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3691 err_args(func, flags, na); |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3692 x = NULL; |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3693 } |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3694 } |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3695 else { |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3696 PyObject *callargs; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3697 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
|
3698 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
|
3699 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
|
3700 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
|
3701 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
|
3702 } |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3703 } else { |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3704 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
|
3705 /* 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
|
3706 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
|
3707 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
|
3708 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
|
3709 Py_INCREF(self); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3710 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
|
3711 Py_INCREF(func); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3712 Py_DECREF(*pfunc); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3713 *pfunc = self; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3714 na++; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3715 n++; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3716 } else |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3717 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
|
3718 READ_TIMESTAMP(*pintr0); |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3719 if (PyFunction_Check(func)) |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3720 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
|
3721 else |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3722 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
|
3723 READ_TIMESTAMP(*pintr1); |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3724 Py_DECREF(func); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3725 } |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
3726 |
|
37286
ab3efbca5c92
answer a question from a comment
Armin Rigo <arigo@tunes.org>
parents:
37164
diff
changeset
|
3727 /* 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
|
3728 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
|
3729 (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
|
3730 */ |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3731 while ((*pp_stack) > pfunc) { |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3732 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
|
3733 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
|
3734 PCALL(PCALL_POP); |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3735 } |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3736 return x; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3737 } |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3738 |
|
24870
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3739 /* 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
|
3740 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
|
3741 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
|
3742 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
|
3743 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
|
3744 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
|
3745 done before evaluating the frame. |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3746 */ |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3747 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
3748 static PyObject * |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3749 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
|
3750 { |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3751 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
|
3752 PyObject *globals = PyFunction_GET_GLOBALS(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3753 PyObject *argdefs = PyFunction_GET_DEFAULTS(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3754 PyObject **d = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3755 int nd = 0; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3756 |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3757 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
|
3758 PCALL(PCALL_FAST_FUNCTION); |
|
29339
fc286e28556f
SF bug #733667: kwargs handled incorrectly
Raymond Hettinger <python@rcn.com>
parents:
29337
diff
changeset
|
3759 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
|
3760 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
|
3761 PyFrameObject *f; |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3762 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
|
3763 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
|
3764 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
|
3765 int i; |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3766 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3767 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
|
3768 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
|
3769 /* 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
|
3770 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
|
3771 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
|
3772 */ |
|
39466
c7ff02c1559f
Move/copy assert for tstate != NULL before first use.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39463
diff
changeset
|
3773 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
|
3774 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
|
3775 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
|
3776 return NULL; |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3777 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3778 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
|
3779 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
|
3780 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3781 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
|
3782 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
|
3783 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
|
3784 } |
|
35298
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
3785 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
|
3786 ++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
|
3787 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
|
3788 --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
|
3789 return retval; |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3790 } |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3791 if (argdefs != NULL) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3792 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
|
3793 nd = Py_SIZE(argdefs); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3794 } |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3795 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
|
3796 (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
|
3797 (*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
|
3798 PyFunction_GET_CLOSURE(func)); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3799 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3800 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
3801 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
|
3802 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
|
3803 PyObject *func) |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3804 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3805 PyObject *kwdict = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3806 if (orig_kwdict == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3807 kwdict = PyDict_New(); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3808 else { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3809 kwdict = PyDict_Copy(orig_kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3810 Py_DECREF(orig_kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3811 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3812 if (kwdict == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3813 return NULL; |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
3814 while (--nk >= 0) { |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3815 int err; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3816 PyObject *value = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3817 PyObject *key = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3818 if (PyDict_GetItem(kwdict, key) != NULL) { |
| 43408 | 3819 PyErr_Format(PyExc_TypeError, |
| 3820 "%.200s%s got multiple values " | |
| 3821 "for keyword argument '%.200s'", | |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3822 PyEval_GetFuncName(func), |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3823 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
|
3824 PyString_AsString(key)); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3825 Py_DECREF(key); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3826 Py_DECREF(value); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3827 Py_DECREF(kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3828 return NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3829 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3830 err = PyDict_SetItem(kwdict, key, value); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3831 Py_DECREF(key); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3832 Py_DECREF(value); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3833 if (err) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3834 Py_DECREF(kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3835 return NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3836 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3837 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3838 return kwdict; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3839 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3840 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
3841 static PyObject * |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3842 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
|
3843 PyObject ***pp_stack) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3844 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3845 PyObject *callargs, *w; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3846 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3847 callargs = PyTuple_New(nstack + nstar); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3848 if (callargs == NULL) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3849 return NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3850 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3851 if (nstar) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3852 int i; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3853 for (i = 0; i < nstar; i++) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3854 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
|
3855 Py_INCREF(a); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3856 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
|
3857 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3858 } |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
3859 while (--nstack >= 0) { |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3860 w = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3861 PyTuple_SET_ITEM(callargs, nstack, w); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3862 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3863 return callargs; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3864 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3865 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
3866 static PyObject * |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3867 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
|
3868 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3869 PyObject *args = PyTuple_New(na); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3870 PyObject *w; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3871 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3872 if (args == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3873 return NULL; |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
3874 while (--na >= 0) { |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3875 w = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3876 PyTuple_SET_ITEM(args, na, w); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3877 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3878 return args; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3879 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3880 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
3881 static PyObject * |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3882 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
|
3883 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3884 PyObject *callargs = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3885 PyObject *kwdict = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3886 PyObject *result = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3887 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3888 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
|
3889 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
|
3890 if (kwdict == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3891 goto call_fail; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3892 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3893 callargs = load_args(pp_stack, na); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3894 if (callargs == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3895 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
|
3896 #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
|
3897 /* 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
|
3898 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
|
3899 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
|
3900 */ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3901 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
|
3902 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
|
3903 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
|
3904 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
|
3905 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
|
3906 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
|
3907 else |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3908 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
|
3909 #endif |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3910 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
|
3911 call_fail: |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3912 Py_XDECREF(callargs); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3913 Py_XDECREF(kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3914 return result; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3915 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3916 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
3917 static PyObject * |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3918 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
|
3919 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3920 int nstar = 0; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3921 PyObject *callargs = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3922 PyObject *stararg = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3923 PyObject *kwdict = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3924 PyObject *result = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3925 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3926 if (flags & CALL_FLAG_KW) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3927 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
|
3928 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
|
3929 PyObject *d; |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
3930 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
|
3931 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
|
3932 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
|
3933 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
|
3934 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
|
3935 /* 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
|
3936 * 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
|
3937 * 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
|
3938 * 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
|
3939 * 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
|
3940 */ |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
3941 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
|
3942 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
|
3943 "%.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
|
3944 "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
|
3945 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
|
3946 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
|
3947 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
|
3948 } |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
3949 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
|
3950 } |
|
a405732a262d
Patch #1686487: you can now pass any mapping after '**' in function calls.
Georg Brandl <georg@python.org>
parents:
41692
diff
changeset
|
3951 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
|
3952 kwdict = d; |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3953 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3954 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3955 if (flags & CALL_FLAG_VAR) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3956 stararg = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3957 if (!PyTuple_Check(stararg)) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3958 PyObject *t = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3959 t = PySequence_Tuple(stararg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3960 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
|
3961 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
|
3962 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
|
3963 "%.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
|
3964 "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
|
3965 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
|
3966 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
|
3967 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
|
3968 } |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3969 goto ext_call_fail; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3970 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3971 Py_DECREF(stararg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3972 stararg = t; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3973 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3974 nstar = PyTuple_GET_SIZE(stararg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3975 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3976 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
|
3977 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
|
3978 if (kwdict == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3979 goto ext_call_fail; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3980 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3981 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
|
3982 if (callargs == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3983 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
|
3984 #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
|
3985 /* 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
|
3986 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
|
3987 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
|
3988 */ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3989 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
|
3990 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
|
3991 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
|
3992 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
|
3993 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
|
3994 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
|
3995 else |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3996 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
|
3997 #endif |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3998 result = PyObject_Call(func, callargs, kwdict); |
| 43408 | 3999 ext_call_fail: |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4000 Py_XDECREF(callargs); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4001 Py_XDECREF(kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4002 Py_XDECREF(stararg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4003 return result; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4004 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4005 |
|
36882
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4006 /* 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
|
4007 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
|
4008 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
|
4009 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
|
4010 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
|
4011 */ |
|
21441
05ad7a69d933
_PyEval_SliceIndex(): explain why a NULL argument is allowed (thanks
Tim Peters <tim.peters@gmail.com>
parents:
21440
diff
changeset
|
4012 /* 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
|
4013 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
|
4014 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
|
4015 */ |
| 12614 | 4016 int |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36475
diff
changeset
|
4017 _PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi) |
| 69 | 4018 { |
|
21441
05ad7a69d933
_PyEval_SliceIndex(): explain why a NULL argument is allowed (thanks
Tim Peters <tim.peters@gmail.com>
parents:
21440
diff
changeset
|
4019 if (v != NULL) { |
|
36558
d3685f9b7b71
Remove size constraints in SLICE opcodes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
4020 Py_ssize_t x; |
|
11839
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
4021 if (PyInt_Check(v)) { |
|
39463
6cafdc81cfde
Patch #1538606, Patch to fix __index__() clipping.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39455
diff
changeset
|
4022 /* 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
|
4023 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
|
4024 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
|
4025 */ |
|
6cafdc81cfde
Patch #1538606, Patch to fix __index__() clipping.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39455
diff
changeset
|
4026 x = PyInt_AS_LONG(v); |
| 38418 | 4027 } |
|
39463
6cafdc81cfde
Patch #1538606, Patch to fix __index__() clipping.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39455
diff
changeset
|
4028 else if (PyIndex_Check(v)) { |
|
6cafdc81cfde
Patch #1538606, Patch to fix __index__() clipping.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39455
diff
changeset
|
4029 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
|
4030 if (x == -1 && PyErr_Occurred()) |
|
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4031 return 0; |
|
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4032 } |
|
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4033 else { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
4034 PyErr_SetString(PyExc_TypeError, |
|
36882
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4035 "slice indices must be integers or " |
|
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4036 "None or have an __index__ method"); |
| 12614 | 4037 return 0; |
| 69 | 4038 } |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
4039 *pi = x; |
| 69 | 4040 } |
| 12614 | 4041 return 1; |
| 69 | 4042 } |
| 4043 | |
|
36882
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4044 #undef ISINDEX |
|
39463
6cafdc81cfde
Patch #1538606, Patch to fix __index__() clipping.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39455
diff
changeset
|
4045 #define ISINDEX(x) ((x) == NULL || \ |
|
6cafdc81cfde
Patch #1538606, Patch to fix __index__() clipping.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39455
diff
changeset
|
4046 PyInt_Check(x) || PyLong_Check(x) || PyIndex_Check(x)) |
| 19369 | 4047 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
4048 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4049 apply_slice(PyObject *u, PyObject *v, PyObject *w) /* return u[v:w] */ |
| 69 | 4050 { |
| 19369 | 4051 PyTypeObject *tp = u->ob_type; |
| 4052 PySequenceMethods *sq = tp->tp_as_sequence; | |
| 4053 | |
|
36882
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4054 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
|
4055 Py_ssize_t ilow = 0, ihigh = PY_SSIZE_T_MAX; |
| 19369 | 4056 if (!_PyEval_SliceIndex(v, &ilow)) |
| 4057 return NULL; | |
| 4058 if (!_PyEval_SliceIndex(w, &ihigh)) | |
| 4059 return NULL; | |
| 4060 return PySequence_GetSlice(u, ilow, ihigh); | |
| 4061 } | |
| 4062 else { | |
| 4063 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
|
4064 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
|
4065 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
|
4066 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
|
4067 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
|
4068 } |
| 19369 | 4069 else |
| 4070 return NULL; | |
| 4071 } | |
| 69 | 4072 } |
| 86 | 4073 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
4074 static int |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
4075 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
|
4076 /* u[v:w] = x */ |
| 69 | 4077 { |
| 19369 | 4078 PyTypeObject *tp = u->ob_type; |
| 4079 PySequenceMethods *sq = tp->tp_as_sequence; | |
| 4080 | |
|
41007
6d3454c371dd
Patch #1674228: when assigning a slice (old-style), check for the
Georg Brandl <georg@python.org>
parents:
40931
diff
changeset
|
4081 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
|
4082 Py_ssize_t ilow = 0, ihigh = PY_SSIZE_T_MAX; |
| 19369 | 4083 if (!_PyEval_SliceIndex(v, &ilow)) |
| 4084 return -1; | |
| 4085 if (!_PyEval_SliceIndex(w, &ihigh)) | |
| 4086 return -1; | |
| 4087 if (x == NULL) | |
| 4088 return PySequence_DelSlice(u, ilow, ihigh); | |
| 4089 else | |
| 4090 return PySequence_SetSlice(u, ilow, ihigh, x); | |
| 4091 } | |
| 4092 else { | |
| 4093 PyObject *slice = PySlice_New(v, w, NULL); | |
| 4094 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
|
4095 int res; |
| 19369 | 4096 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
|
4097 res = PyObject_SetItem(u, slice, x); |
| 19369 | 4098 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
|
4099 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
|
4100 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
|
4101 return res; |
| 19369 | 4102 } |
| 4103 else | |
| 4104 return -1; | |
| 4105 } | |
| 69 | 4106 } |
| 4107 | |
|
45818
ff0ab7b28f49
- Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents:
45703
diff
changeset
|
4108 #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
|
4109 (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
|
4110 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
|
4111 |
|
ff0ab7b28f49
- Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents:
45703
diff
changeset
|
4112 #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
|
4113 "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
|
4114 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
4115 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4116 cmp_outcome(int op, register PyObject *v, register PyObject *w) |
| 69 | 4117 { |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
4118 int res = 0; |
| 69 | 4119 switch (op) { |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
4120 case PyCmp_IS: |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
4121 res = (v == w); |
|
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
4122 break; |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
4123 case PyCmp_IS_NOT: |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
4124 res = (v != w); |
| 86 | 4125 break; |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
4126 case PyCmp_IN: |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
4127 res = PySequence_Contains(w, v); |
|
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
4128 if (res < 0) |
|
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
4129 return NULL; |
|
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
4130 break; |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
4131 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
|
4132 res = PySequence_Contains(w, v); |
| 86 | 4133 if (res < 0) |
| 4134 return NULL; | |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
4135 res = !res; |
| 69 | 4136 break; |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
4137 case PyCmp_EXC_MATCH: |
|
40735
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4138 if (PyTuple_Check(w)) { |
|
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4139 Py_ssize_t i, length; |
|
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4140 length = PyTuple_Size(w); |
|
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4141 for (i = 0; i < length; i += 1) { |
|
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4142 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
|
4143 if (PyString_Check(exc)) { |
|
40735
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4144 int ret_val; |
|
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4145 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
|
4146 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
|
4147 "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
|
4148 "exceptions is deprecated", 1); |
|
46578
7670005da8c5
A little reformating of Py3k warnings
Benjamin Peterson <benjamin@python.org>
parents:
46573
diff
changeset
|
4149 if (ret_val < 0) |
|
40735
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4150 return NULL; |
|
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4151 } |
|
45820
79fdc88ff9ec
Clean up the Py3k warnings for non-BaseException-subclasses a bit. We
Guido van Rossum <guido@python.org>
parents:
45818
diff
changeset
|
4152 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
|
4153 !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
|
4154 !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
|
4155 { |
|
ff0ab7b28f49
- Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents:
45703
diff
changeset
|
4156 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
|
4157 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
|
4158 PyExc_DeprecationWarning, |
|
ff0ab7b28f49
- Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents:
45703
diff
changeset
|
4159 CANNOT_CATCH_MSG, 1); |
|
46578
7670005da8c5
A little reformating of Py3k warnings
Benjamin Peterson <benjamin@python.org>
parents:
46573
diff
changeset
|
4160 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
|
4161 return NULL; |
|
ff0ab7b28f49
- Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents:
45703
diff
changeset
|
4162 } |
|
40735
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4163 } |
|
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4164 } |
|
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4165 else { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4166 if (PyString_Check(w)) { |
|
40735
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4167 int ret_val; |
|
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4168 ret_val = PyErr_WarnEx( |
|
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4169 PyExc_DeprecationWarning, |
|
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4170 "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
|
4171 "exceptions is deprecated", 1); |
|
46578
7670005da8c5
A little reformating of Py3k warnings
Benjamin Peterson <benjamin@python.org>
parents:
46573
diff
changeset
|
4172 if (ret_val < 0) |
|
40735
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4173 return NULL; |
|
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4174 } |
|
45820
79fdc88ff9ec
Clean up the Py3k warnings for non-BaseException-subclasses a bit. We
Guido van Rossum <guido@python.org>
parents:
45818
diff
changeset
|
4175 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
|
4176 !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
|
4177 !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
|
4178 { |
|
ff0ab7b28f49
- Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents:
45703
diff
changeset
|
4179 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
|
4180 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
|
4181 PyExc_DeprecationWarning, |
|
ff0ab7b28f49
- Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents:
45703
diff
changeset
|
4182 CANNOT_CATCH_MSG, 1); |
|
46578
7670005da8c5
A little reformating of Py3k warnings
Benjamin Peterson <benjamin@python.org>
parents:
46573
diff
changeset
|
4183 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
|
4184 return NULL; |
|
ff0ab7b28f49
- Issue #2371: Add a Py3k warning when catching an exception that
Guido van Rossum <guido@python.org>
parents:
45703
diff
changeset
|
4185 } |
|
40735
bd3739a87259
No more raising of string exceptions!
Brett Cannon <bcannon@gmail.com>
parents:
40560
diff
changeset
|
4186 } |
|
6147
b76a44163e0f
cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents:
6139
diff
changeset
|
4187 res = PyErr_GivenExceptionMatches(v, w); |
| 69 | 4188 break; |
| 4189 default: | |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
4190 return PyObject_RichCompare(v, w, op); |
| 69 | 4191 } |
| 5368 | 4192 v = res ? Py_True : Py_False; |
| 4193 Py_INCREF(v); | |
| 69 | 4194 return v; |
| 4195 } | |
| 4196 | |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
4197 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
|
4198 import_from(PyObject *v, PyObject *name) |
|
72
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
4199 { |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4200 PyObject *x; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4201 |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4202 x = PyObject_GetAttr(v, name); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4203 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
|
4204 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
|
4205 "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
|
4206 PyString_AsString(name)); |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4207 } |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
4208 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
|
4209 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
4210 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
4211 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
|
4212 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
|
4213 { |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4214 PyObject *all = PyObject_GetAttrString(v, "__all__"); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4215 PyObject *dict, *name, *value; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4216 int skip_leading_underscores = 0; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4217 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
|
4218 |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4219 if (all == NULL) { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4220 if (!PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4221 return -1; /* Unexpected error */ |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4222 PyErr_Clear(); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4223 dict = PyObject_GetAttrString(v, "__dict__"); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4224 if (dict == NULL) { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4225 if (!PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4226 return -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4227 PyErr_SetString(PyExc_ImportError, |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4228 "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
|
4229 return -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4230 } |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4231 all = PyMapping_Keys(dict); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4232 Py_DECREF(dict); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4233 if (all == NULL) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4234 return -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4235 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
|
4236 } |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
4237 |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4238 for (pos = 0, err = 0; ; pos++) { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4239 name = PySequence_GetItem(all, pos); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4240 if (name == NULL) { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4241 if (!PyErr_ExceptionMatches(PyExc_IndexError)) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4242 err = -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4243 else |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4244 PyErr_Clear(); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4245 break; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4246 } |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4247 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
|
4248 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
|
4249 PyString_AS_STRING(name)[0] == '_') |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4250 { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4251 Py_DECREF(name); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4252 continue; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4253 } |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4254 value = PyObject_GetAttr(v, name); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4255 if (value == NULL) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4256 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
|
4257 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
|
4258 err = PyDict_SetItem(locals, name, value); |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4259 else |
|
40405
4e368e82c70d
Forgot a case where the locals can now be a general mapping
Armin Rigo <arigo@tunes.org>
parents:
40193
diff
changeset
|
4260 err = PyObject_SetItem(locals, name, value); |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4261 Py_DECREF(name); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4262 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
|
4263 if (err != 0) |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4264 break; |
|
72
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
4265 } |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4266 Py_DECREF(all); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4267 return err; |
|
72
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
4268 } |
|
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
4269 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
4270 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4271 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
|
4272 { |
|
19890
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
4273 PyObject *metaclass = NULL, *result, *base; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
4274 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
4275 if (PyDict_Check(methods)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
4276 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
|
4277 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
|
4278 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
|
4279 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
|
4280 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
|
4281 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
|
4282 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
|
4283 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
|
4284 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
|
4285 Py_INCREF(metaclass); |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
4286 } |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
4287 } |
|
19890
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
4288 else { |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
4289 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
|
4290 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
|
4291 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
|
4292 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
|
4293 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
|
4294 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
|
4295 } |
| 40931 | 4296 result = PyObject_CallFunctionObjArgs(metaclass, name, bases, methods, |
| 43408 | 4297 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
|
4298 Py_DECREF(metaclass); |
|
32247
a98f50e50bef
SF bug #963956: Bad error mesage when subclassing a module
Raymond Hettinger <python@rcn.com>
parents:
32175
diff
changeset
|
4299 if (result == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) { |
| 38418 | 4300 /* 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
|
4301 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
|
4302 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
|
4303 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
|
4304 |
|
af9bedd5a8e7
SF bug #1014215: Unspecific errors with metaclass
Raymond Hettinger <python@rcn.com>
parents:
33318
diff
changeset
|
4305 PyObject *ptype, *pvalue, *ptraceback; |
|
af9bedd5a8e7
SF bug #1014215: Unspecific errors with metaclass
Raymond Hettinger <python@rcn.com>
parents:
33318
diff
changeset
|
4306 |
|
af9bedd5a8e7
SF bug #1014215: Unspecific errors with metaclass
Raymond Hettinger <python@rcn.com>
parents:
33318
diff
changeset
|
4307 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
|
4308 if (PyString_Check(pvalue)) { |
|
33501
af9bedd5a8e7
SF bug #1014215: Unspecific errors with metaclass
Raymond Hettinger <python@rcn.com>
parents:
33318
diff
changeset
|
4309 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
|
4310 newmsg = PyString_FromFormat( |
| 40931 | 4311 "Error when calling the metaclass bases\n" |
| 43408 | 4312 " %s", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4313 PyString_AS_STRING(pvalue)); |
|
33501
af9bedd5a8e7
SF bug #1014215: Unspecific errors with metaclass
Raymond Hettinger <python@rcn.com>
parents:
33318
diff
changeset
|
4314 if (newmsg != NULL) { |
|
af9bedd5a8e7
SF bug #1014215: Unspecific errors with metaclass
Raymond Hettinger <python@rcn.com>
parents:
33318
diff
changeset
|
4315 Py_DECREF(pvalue); |
|
af9bedd5a8e7
SF bug #1014215: Unspecific errors with metaclass
Raymond Hettinger <python@rcn.com>
parents:
33318
diff
changeset
|
4316 pvalue = newmsg; |
|
af9bedd5a8e7
SF bug #1014215: Unspecific errors with metaclass
Raymond Hettinger <python@rcn.com>
parents:
33318
diff
changeset
|
4317 } |
|
af9bedd5a8e7
SF bug #1014215: Unspecific errors with metaclass
Raymond Hettinger <python@rcn.com>
parents:
33318
diff
changeset
|
4318 } |
|
af9bedd5a8e7
SF bug #1014215: Unspecific errors with metaclass
Raymond Hettinger <python@rcn.com>
parents:
33318
diff
changeset
|
4319 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
|
4320 } |
|
19890
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
4321 return result; |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
4322 } |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
4323 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
4324 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4325 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
|
4326 PyObject *locals) |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4327 { |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4328 int n; |
| 5368 | 4329 PyObject *v; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4330 int plain = 0; |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4331 |
| 5368 | 4332 if (PyTuple_Check(prog) && globals == Py_None && locals == Py_None && |
| 4333 ((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
|
4334 /* Backward compatibility hack */ |
| 5368 | 4335 globals = PyTuple_GetItem(prog, 1); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4336 if (n == 3) |
| 5368 | 4337 locals = PyTuple_GetItem(prog, 2); |
| 4338 prog = PyTuple_GetItem(prog, 0); | |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4339 } |
| 5368 | 4340 if (globals == Py_None) { |
| 4341 globals = PyEval_GetGlobals(); | |
| 4342 if (locals == Py_None) { | |
| 4343 locals = PyEval_GetLocals(); | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4344 plain = 1; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4345 } |
|
39466
c7ff02c1559f
Move/copy assert for tstate != NULL before first use.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39463
diff
changeset
|
4346 if (!globals || !locals) { |
|
c7ff02c1559f
Move/copy assert for tstate != NULL before first use.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39463
diff
changeset
|
4347 PyErr_SetString(PyExc_SystemError, |
|
c7ff02c1559f
Move/copy assert for tstate != NULL before first use.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39463
diff
changeset
|
4348 "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
|
4349 return -1; |
|
c7ff02c1559f
Move/copy assert for tstate != NULL before first use.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39463
diff
changeset
|
4350 } |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4351 } |
| 5368 | 4352 else if (locals == Py_None) |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4353 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
|
4354 if (!PyString_Check(prog) && |
|
14696
85038a024b19
This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents:
14375
diff
changeset
|
4355 !PyUnicode_Check(prog) && |
| 5368 | 4356 !PyCode_Check(prog) && |
| 4357 !PyFile_Check(prog)) { | |
| 4358 PyErr_SetString(PyExc_TypeError, | |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
4359 "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
|
4360 return -1; |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4361 } |
| 15318 | 4362 if (!PyDict_Check(globals)) { |
| 5368 | 4363 PyErr_SetString(PyExc_TypeError, |
| 15318 | 4364 "exec: arg 2 must be a dictionary or None"); |
| 4365 return -1; | |
| 4366 } | |
|
32890
b8c2aa2be19a
Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents:
32531
diff
changeset
|
4367 if (!PyMapping_Check(locals)) { |
| 15318 | 4368 PyErr_SetString(PyExc_TypeError, |
|
32890
b8c2aa2be19a
Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents:
32531
diff
changeset
|
4369 "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
|
4370 return -1; |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4371 } |
| 5368 | 4372 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
|
4373 PyDict_SetItemString(globals, "__builtins__", f->f_builtins); |
| 5368 | 4374 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
|
4375 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
|
4376 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
|
4377 "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
|
4378 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
|
4379 } |
|
11651
d88996e46cb2
Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents:
11468
diff
changeset
|
4380 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
|
4381 } |
|
11651
d88996e46cb2
Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents:
11468
diff
changeset
|
4382 else if (PyFile_Check(prog)) { |
| 5368 | 4383 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
|
4384 char *name = PyString_AsString(PyFile_Name(prog)); |
|
40904
191c48ca8bf9
Put declarations before code.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40903
diff
changeset
|
4385 PyCompilerFlags cf; |
| 43408 | 4386 if (name == NULL) |
| 4387 return -1; | |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
4388 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
|
4389 if (PyEval_MergeCompilerFlags(&cf)) |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4390 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
|
4391 locals, &cf); |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
4392 else |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4393 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
|
4394 locals); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4395 } |
|
11651
d88996e46cb2
Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents:
11468
diff
changeset
|
4396 else { |
|
27781
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4397 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
|
4398 char *str; |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
4399 PyCompilerFlags cf; |
|
27781
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4400 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
|
4401 #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
|
4402 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
|
4403 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
|
4404 if (tmp == NULL) |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4405 return -1; |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4406 prog = tmp; |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4407 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
|
4408 } |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4409 #endif |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4410 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
|
4411 return -1; |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
4412 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
|
4413 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
|
4414 locals, &cf); |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
4415 else |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4416 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
|
4417 Py_XDECREF(tmp); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4418 } |
|
11651
d88996e46cb2
Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents:
11468
diff
changeset
|
4419 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
|
4420 PyFrame_LocalsToFast(f, 0); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4421 if (v == NULL) |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4422 return -1; |
| 5368 | 4423 Py_DECREF(v); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4424 return 0; |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4425 } |
|
2338
4c2f1452125d
call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents:
2310
diff
changeset
|
4426 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
4427 static void |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4428 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
|
4429 { |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4430 char *obj_str; |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4431 |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4432 if (!obj) |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4433 return; |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4434 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4435 obj_str = PyString_AsString(obj); |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4436 if (!obj_str) |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4437 return; |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4438 |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4439 PyErr_Format(exc, format_str, obj_str); |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4440 } |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4441 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
4442 static PyObject * |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4443 string_concatenate(PyObject *v, PyObject *w, |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4444 PyFrameObject *f, unsigned char *next_instr) |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4445 { |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4446 /* This function implements 'variable += expr' when both arguments |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4447 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
|
4448 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
|
4449 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
|
4450 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
|
4451 if (new_len < 0) { |
|
74d23cd04421
Concatenation on a long string breaks (SF #1526585).
Armin Rigo <arigo@tunes.org>
parents:
38768
diff
changeset
|
4452 PyErr_SetString(PyExc_OverflowError, |
|
74d23cd04421
Concatenation on a long string breaks (SF #1526585).
Armin Rigo <arigo@tunes.org>
parents:
38768
diff
changeset
|
4453 "strings are too large to concat"); |
|
74d23cd04421
Concatenation on a long string breaks (SF #1526585).
Armin Rigo <arigo@tunes.org>
parents:
38768
diff
changeset
|
4454 return NULL; |
|
74d23cd04421
Concatenation on a long string breaks (SF #1526585).
Armin Rigo <arigo@tunes.org>
parents:
38768
diff
changeset
|
4455 } |
| 38418 | 4456 |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4457 if (v->ob_refcnt == 2) { |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4458 /* 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
|
4459 * 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
|
4460 * 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
|
4461 * '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
|
4462 * the refcnt to 1. |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4463 */ |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4464 switch (*next_instr) { |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4465 case STORE_FAST: |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4466 { |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4467 int oparg = PEEKARG(); |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4468 PyObject **fastlocals = f->f_localsplus; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4469 if (GETLOCAL(oparg) == v) |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4470 SETLOCAL(oparg, NULL); |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4471 break; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4472 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4473 case STORE_DEREF: |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4474 { |
|
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
|
4475 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
|
4476 f->f_code->co_nlocals); |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4477 PyObject *c = freevars[PEEKARG()]; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4478 if (PyCell_GET(c) == v) |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4479 PyCell_Set(c, NULL); |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4480 break; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4481 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4482 case STORE_NAME: |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4483 { |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4484 PyObject *names = f->f_code->co_names; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4485 PyObject *name = GETITEM(names, PEEKARG()); |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4486 PyObject *locals = f->f_locals; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4487 if (PyDict_CheckExact(locals) && |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4488 PyDict_GetItem(locals, name) == v) { |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4489 if (PyDict_DelItem(locals, name) != 0) { |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4490 PyErr_Clear(); |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4491 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4492 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4493 break; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4494 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4495 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4496 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4497 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4498 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
|
4499 /* 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
|
4500 * in-place. |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4501 */ |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4502 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
|
4503 /* 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
|
4504 * 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
|
4505 * '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
|
4506 * 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
|
4507 * remotely) be a cause of incompatibilities. |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4508 */ |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4509 return NULL; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4510 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4511 /* 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
|
4512 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
|
4513 PyString_AS_STRING(w), w_len); |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4514 return v; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4515 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4516 else { |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4517 /* 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
|
4518 PyString_Concat(&v, w); |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4519 return v; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4520 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4521 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4522 |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4523 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4524 |
|
38425
ca657e0bd09c
needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
Fredrik Lundh <fredrik@pythonware.com>
parents:
38418
diff
changeset
|
4525 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4526 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
|
4527 { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4528 int i; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4529 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
|
4530 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
|
4531 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
|
4532 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
|
4533 if (x == NULL) { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4534 Py_DECREF(l); |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4535 return NULL; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4536 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4537 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
|
4538 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4539 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
|
4540 a[i] = 0; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4541 return l; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4542 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4543 |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4544 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4545 _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
|
4546 { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4547 #ifndef DXPAIRS |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4548 return getarray(dxp); |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4549 #else |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4550 int i; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4551 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
|
4552 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
|
4553 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
|
4554 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
|
4555 if (x == NULL) { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4556 Py_DECREF(l); |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4557 return NULL; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4558 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4559 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
|
4560 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4561 return l; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4562 #endif |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4563 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4564 |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4565 #endif |
