Mercurial > cpython-lru_cache-weakref
annotate Python/ceval.c @ 54908:aa950f7962fd
Merged revisions 73614-73615 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r73614 | benjamin.peterson | 2009-06-28 11:08:02 -0500 (Sun, 28 Jun 2009) | 1 line
add two generic macros for peeking and setting in the stack
........
r73615 | benjamin.peterson | 2009-06-28 11:14:07 -0500 (Sun, 28 Jun 2009) | 1 line
use stack macros
........
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sun, 28 Jun 2009 16:17:34 +0000 |
| parents | b55a78b39bd5 |
| children | 0c319e03d9a1 |
| rev | line source |
|---|---|
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
119
diff
changeset
|
1 |
| 86 | 2 /* Execute compiled code */ |
| 69 | 3 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4 /* XXX TO DO: |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
5 XXX speed up searching for keywords by using a dictionary |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
6 XXX document it! |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
7 */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
8 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
9 /* enable more aggressive intra-module optimizations, where available */ |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
10 #define PY_LOCAL_AGGRESSIVE |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
11 |
| 5368 | 12 #include "Python.h" |
| 86 | 13 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
14 #include "code.h" |
| 86 | 15 #include "frameobject.h" |
| 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 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
22 #ifndef WITH_TSC |
|
34442
683719e04218
Change the name of the macro used by --with-tsc builds to the less
Michael W. Hudson <mwh@python.net>
parents:
34371
diff
changeset
|
23 |
|
683719e04218
Change the name of the macro used by --with-tsc builds to the less
Michael W. Hudson <mwh@python.net>
parents:
34371
diff
changeset
|
24 #define READ_TIMESTAMP(var) |
|
683719e04218
Change the name of the macro used by --with-tsc builds to the less
Michael W. Hudson <mwh@python.net>
parents:
34371
diff
changeset
|
25 |
|
683719e04218
Change the name of the macro used by --with-tsc builds to the less
Michael W. Hudson <mwh@python.net>
parents:
34371
diff
changeset
|
26 #else |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
27 |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
28 typedef unsigned long long uint64; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
29 |
| 33104 | 30 #if defined(__ppc__) /* <- Don't know if this is the correct symbol; this |
|
43418
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
31 section should work for GCC on any PowerPC |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
32 platform, irrespective of OS. |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
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 |
| 37 static void | |
| 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 | |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
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 | |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
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 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
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 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
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 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
94 static PyObject * fast_function(PyObject *, PyObject ***, int, int, int); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
95 static PyObject * do_call(PyObject *, PyObject ***, int, int); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
96 static PyObject * ext_do_call(PyObject *, PyObject ***, int, int, int); |
|
43418
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
97 static PyObject * update_keyword_args(PyObject *, int, PyObject ***, |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
98 PyObject *); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
99 static PyObject * update_star_args(int, int, PyObject *, PyObject ***); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
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 |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
105 static int lltrace; |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
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 |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
108 static int call_trace(Py_tracefunc, PyObject *, PyFrameObject *, |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
109 int, PyObject *); |
|
43840
73c8e27eb9ce
Correction for issue1265 (pdb bug with "with" statement).
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43815
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 *); |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
112 static void call_exc_trace(Py_tracefunc, PyObject *, PyFrameObject *); |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
113 static int maybe_call_line_trace(Py_tracefunc, PyObject *, |
| 31768 | 114 PyFrameObject *, int *, int *, int *); |
| 24844 | 115 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
116 static PyObject * cmp_outcome(int, PyObject *, PyObject *); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
117 static PyObject * import_from(PyObject *, PyObject *); |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
118 static int import_all_from(PyObject *, PyObject *); |
| 42860 | 119 static void format_exc_check_arg(PyObject *, const char *, PyObject *); |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
120 static PyObject * unicode_concatenate(PyObject *, PyObject *, |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
121 PyFrameObject *, unsigned char *); |
|
54889
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
122 static PyObject * special_lookup(PyObject *, char *, PyObject **); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
123 |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
124 #define NAME_ERROR_MSG \ |
| 15318 | 125 "name '%.200s' is not defined" |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
126 #define GLOBAL_NAME_ERROR_MSG \ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
127 "global name '%.200s' is not defined" |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
128 #define UNBOUNDLOCAL_ERROR_MSG \ |
| 15318 | 129 "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
|
130 #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
|
131 "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
|
132 " in enclosing scope" |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
133 |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
134 /* Dynamic execution profile */ |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
135 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
136 #ifdef DXPAIRS |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
137 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
|
138 #define dxp dxpairs[256] |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
139 #else |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
140 static long dxp[256]; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
141 #endif |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
142 #endif |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
143 |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
144 /* 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
|
145 #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
|
146 #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
|
147 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
|
148 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
149 #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
|
150 #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
|
151 #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
|
152 #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
|
153 #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
|
154 #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
|
155 #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
|
156 #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
|
157 #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
|
158 #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
|
159 #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
|
160 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
161 /* 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
|
162 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
163 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
|
164 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
165 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
|
166 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
|
167 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
168 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
|
169 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
|
170 twice. |
|
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 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 */ |
|
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 #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
|
180 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
181 PyObject * |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
182 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
|
183 { |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40381
diff
changeset
|
184 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
|
185 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
|
186 pcall[4], pcall[5], pcall[6], pcall[7], |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40381
diff
changeset
|
187 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
|
188 } |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
189 #else |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
190 #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
|
191 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
192 PyObject * |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
193 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
|
194 { |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
195 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
|
196 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
|
197 } |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
198 #endif |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
199 |
|
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
|
200 |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
201 #ifdef WITH_THREAD |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
202 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
203 #ifdef HAVE_ERRNO_H |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
204 #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
|
205 #endif |
|
9203
07dae6fdae79
Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents:
9048
diff
changeset
|
206 #include "pythread.h" |
| 926 | 207 |
|
29643
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
208 static PyThread_type_lock interpreter_lock = 0; /* This is the GIL */ |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
209 static PyThread_type_lock pending_lock = 0; /* for pending calls */ |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
210 static long main_thread = 0; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
211 |
|
33715
a46b76eb9053
SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents:
33501
diff
changeset
|
212 int |
|
a46b76eb9053
SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents:
33501
diff
changeset
|
213 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
|
214 { |
|
a46b76eb9053
SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents:
33501
diff
changeset
|
215 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
|
216 } |
|
a46b76eb9053
SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents:
33501
diff
changeset
|
217 |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
218 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
219 PyEval_InitThreads(void) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
220 { |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
221 if (interpreter_lock) |
| 1179 | 222 return; |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
223 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
|
224 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
|
225 main_thread = PyThread_get_thread_ident(); |
| 926 | 226 } |
| 227 | |
|
5865
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
228 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
229 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
|
230 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
231 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
|
232 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
233 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
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_ReleaseLock(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_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
|
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_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
|
242 { |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
243 if (tstate == NULL) |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
244 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
|
245 /* 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
|
246 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
|
247 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
|
248 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
|
249 Py_FatalError( |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
250 "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
|
251 } |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
252 |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
253 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
254 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
|
255 { |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
256 if (tstate == NULL) |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
257 Py_FatalError("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
|
258 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
|
259 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
|
260 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
|
261 } |
|
14225
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
262 |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
263 /* 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
|
264 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
|
265 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
|
266 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
|
267 |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
268 void |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
269 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
|
270 { |
| 48516 | 271 PyObject *threading, *result; |
| 272 PyThreadState *tstate; | |
| 273 | |
|
14225
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
274 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
|
275 return; |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
276 /*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
|
277 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
|
278 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
|
279 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
|
280 interpreter_lock = PyThread_allocate_lock(); |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
281 pending_lock = PyThread_allocate_lock(); |
|
14225
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
282 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
|
283 main_thread = PyThread_get_thread_ident(); |
| 48516 | 284 |
| 285 /* Update the threading module with the new state. | |
| 286 */ | |
| 287 tstate = PyThreadState_GET(); | |
| 288 threading = PyMapping_GetItemString(tstate->interp->modules, | |
| 289 "threading"); | |
| 290 if (threading == NULL) { | |
| 291 /* threading not imported */ | |
| 292 PyErr_Clear(); | |
| 293 return; | |
| 294 } | |
| 295 result = PyObject_CallMethod(threading, "_after_fork", NULL); | |
| 296 if (result == NULL) | |
| 297 PyErr_WriteUnraisable(threading); | |
| 298 else | |
| 299 Py_DECREF(result); | |
| 300 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
|
301 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
302 #endif |
| 926 | 303 |
| 304 /* Functions save_thread and restore_thread are always defined so | |
| 305 dynamically loaded modules needn't be compiled separately for use | |
| 306 with and without threads: */ | |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
307 |
|
5846
852a1fa62a7c
PyEval_SaveThread() and PyEval_RestoreThread() now return/take a
Guido van Rossum <guido@python.org>
parents:
5829
diff
changeset
|
308 PyThreadState * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
309 PyEval_SaveThread(void) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
310 { |
|
6365
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
311 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
|
312 if (tstate == NULL) |
|
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
313 Py_FatalError("PyEval_SaveThread: NULL tstate"); |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
314 #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
|
315 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
|
316 PyThread_release_lock(interpreter_lock); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
317 #endif |
|
6365
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
318 return tstate; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
319 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
320 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
321 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
322 PyEval_RestoreThread(PyThreadState *tstate) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
323 { |
|
6365
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
324 if (tstate == NULL) |
|
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
325 Py_FatalError("PyEval_RestoreThread: NULL tstate"); |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
326 #ifdef WITH_THREAD |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
327 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
|
328 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
|
329 PyThread_acquire_lock(interpreter_lock, 1); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
330 errno = err; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
331 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
332 #endif |
|
6365
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
333 PyThreadState_Swap(tstate); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
334 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
335 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
336 |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
337 /* 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
|
338 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
|
339 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
|
340 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
|
341 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
|
342 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
|
343 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
344 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
|
345 (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
|
346 an exception condition). |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
347 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
348 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
|
349 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
|
350 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
351 #ifdef WITH_THREAD |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
352 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
|
353 will execute them. |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
354 There is no facility to schedule calls to a particular thread, but |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
355 that should be easy to change, should that ever be required. In |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
356 that case, the static variables here should go into the python |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
357 threadstate. |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
358 #endif |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
359 */ |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
360 |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
361 #ifdef WITH_THREAD |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
362 |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
363 /* The WITH_THREAD implementation is thread-safe. It allows |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
364 scheduling to be made from any thread, and even from an executing |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
365 callback. |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
366 */ |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
367 |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
368 #define NPENDINGCALLS 32 |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
369 static struct { |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
370 int (*func)(void *); |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
371 void *arg; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
372 } pendingcalls[NPENDINGCALLS]; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
373 static int pendingfirst = 0; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
374 static int pendinglast = 0; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
375 static volatile int pendingcalls_to_do = 1; /* trigger initialization of lock */ |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
376 static char pendingbusy = 0; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
377 |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
378 int |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
379 Py_AddPendingCall(int (*func)(void *), void *arg) |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
380 { |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
381 int i, j, result=0; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
382 PyThread_type_lock lock = pending_lock; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
383 |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
384 /* try a few times for the lock. Since this mechanism is used |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
385 * for signal handling (on the main thread), there is a (slim) |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
386 * chance that a signal is delivered on the same thread while we |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
387 * hold the lock during the Py_MakePendingCalls() function. |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
388 * This avoids a deadlock in that case. |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
389 * Note that signals can be delivered on any thread. In particular, |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
390 * on Windows, a SIGINT is delivered on a system-created worker |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
391 * thread. |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
392 * We also check for lock being NULL, in the unlikely case that |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
393 * this function is called before any bytecode evaluation takes place. |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
394 */ |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
395 if (lock != NULL) { |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
396 for (i = 0; i<100; i++) { |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
397 if (PyThread_acquire_lock(lock, NOWAIT_LOCK)) |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
398 break; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
399 } |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
400 if (i == 100) |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
401 return -1; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
402 } |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
403 |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
404 i = pendinglast; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
405 j = (i + 1) % NPENDINGCALLS; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
406 if (j == pendingfirst) { |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
407 result = -1; /* Queue full */ |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
408 } else { |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
409 pendingcalls[i].func = func; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
410 pendingcalls[i].arg = arg; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
411 pendinglast = j; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
412 } |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
413 /* signal main loop */ |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
414 _Py_Ticker = 0; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
415 pendingcalls_to_do = 1; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
416 if (lock != NULL) |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
417 PyThread_release_lock(lock); |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
418 return result; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
419 } |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
420 |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
421 int |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
422 Py_MakePendingCalls(void) |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
423 { |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
424 int i; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
425 int r = 0; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
426 |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
427 if (!pending_lock) { |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
428 /* initial allocation of the lock */ |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
429 pending_lock = PyThread_allocate_lock(); |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
430 if (pending_lock == NULL) |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
431 return -1; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
432 } |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
433 |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
434 /* only service pending calls on main thread */ |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
435 if (main_thread && PyThread_get_thread_ident() != main_thread) |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
436 return 0; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
437 /* don't perform recursive pending calls */ |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
438 if (pendingbusy) |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
439 return 0; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
440 pendingbusy = 1; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
441 /* perform a bounded number of calls, in case of recursion */ |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
442 for (i=0; i<NPENDINGCALLS; i++) { |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
443 int j; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
444 int (*func)(void *); |
|
50840
29edf26b9c23
fix compiler warning
Benjamin Peterson <benjamin@python.org>
parents:
50839
diff
changeset
|
445 void *arg = NULL; |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
446 |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
447 /* pop one item off the queue while holding the lock */ |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
448 PyThread_acquire_lock(pending_lock, WAIT_LOCK); |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
449 j = pendingfirst; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
450 if (j == pendinglast) { |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
451 func = NULL; /* Queue empty */ |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
452 } else { |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
453 func = pendingcalls[j].func; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
454 arg = pendingcalls[j].arg; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
455 pendingfirst = (j + 1) % NPENDINGCALLS; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
456 } |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
457 pendingcalls_to_do = pendingfirst != pendinglast; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
458 PyThread_release_lock(pending_lock); |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
459 /* having released the lock, perform the callback */ |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
460 if (func == NULL) |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
461 break; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
462 r = func(arg); |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
463 if (r) |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
464 break; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
465 } |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
466 pendingbusy = 0; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
467 return r; |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
468 } |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
469 |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
470 #else /* if ! defined WITH_THREAD */ |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
471 |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
472 /* |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
473 WARNING! ASYNCHRONOUSLY EXECUTING CODE! |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
474 This code is used for signal handling in python that isn't built |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
475 with WITH_THREAD. |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
476 Don't use this implementation when Py_AddPendingCalls() can happen |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
477 on a different thread! |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
478 |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
479 There are two possible race conditions: |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
480 (1) nested asynchronous calls to Py_AddPendingCall() |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
481 (2) AddPendingCall() calls made while pending calls are being processed. |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
482 |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
483 (1) is very unlikely because typically signal delivery |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
484 is blocked during signal handling. So it should be impossible. |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
485 (2) is a real possibility. |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
486 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
|
487 The safety against (2) is derived from the fact that only one |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
488 thread is present, interrupted by signals, and that the critical |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
489 section is protected with the "busy" variable. On Windows, which |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
490 delivers SIGINT on a system thread, this does not hold and therefore |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
491 Windows really shouldn't use this version. |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
492 The two threads could theoretically wiggle around the "busy" variable. |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
493 */ |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
494 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
495 #define NPENDINGCALLS 32 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
496 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
|
497 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
|
498 void *arg; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
499 } pendingcalls[NPENDINGCALLS]; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
500 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
|
501 static volatile int pendinglast = 0; |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
502 static volatile int pendingcalls_to_do = 0; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
503 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
504 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
|
505 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
|
506 { |
| 32526 | 507 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
|
508 int i, j; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
509 /* XXX Begin critical section */ |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
510 if (busy) |
|
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
511 return -1; |
|
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
512 busy = 1; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
513 i = pendinglast; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
514 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
|
515 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
|
516 busy = 0; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
517 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
|
518 } |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
519 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
|
520 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
|
521 pendinglast = j; |
|
25108
3a26e352f0a6
replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents:
25078
diff
changeset
|
522 |
|
3a26e352f0a6
replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents:
25078
diff
changeset
|
523 _Py_Ticker = 0; |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
524 pendingcalls_to_do = 1; /* Signal main loop */ |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
525 busy = 0; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
526 /* 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
|
527 return 0; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
528 } |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
529 |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
530 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
531 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
|
532 { |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
533 static int busy = 0; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
534 if (busy) |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
535 return 0; |
|
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
536 busy = 1; |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
537 pendingcalls_to_do = 0; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
538 for (;;) { |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
539 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
|
540 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
|
541 void *arg; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
542 i = pendingfirst; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
543 if (i == pendinglast) |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
544 break; /* Queue empty */ |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
545 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
|
546 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
|
547 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
|
548 if (func(arg) < 0) { |
|
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
549 busy = 0; |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
550 pendingcalls_to_do = 1; /* We're not done yet */ |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
551 return -1; |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
552 } |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
553 } |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
554 busy = 0; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
555 return 0; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
556 } |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
557 |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
558 #endif /* WITH_THREAD */ |
|
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
559 |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
560 |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
561 /* The interpreter's recursion limit */ |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
562 |
|
34863
71fd7ee4b7f5
Make a handy macro, Py_DEFAULT_RECURSION_LIMIT to allow to define
Hye-Shik Chang <hyeshik@gmail.com>
parents:
34442
diff
changeset
|
563 #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
|
564 #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
|
565 #endif |
|
71fd7ee4b7f5
Make a handy macro, Py_DEFAULT_RECURSION_LIMIT to allow to define
Hye-Shik Chang <hyeshik@gmail.com>
parents:
34442
diff
changeset
|
566 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
|
567 int _Py_CheckRecursionLimit = Py_DEFAULT_RECURSION_LIMIT; |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
568 |
|
14348
6d0f64f7dedd
Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14333
diff
changeset
|
569 int |
|
6d0f64f7dedd
Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14333
diff
changeset
|
570 Py_GetRecursionLimit(void) |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
571 { |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
572 return recursion_limit; |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
573 } |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
574 |
|
14348
6d0f64f7dedd
Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14333
diff
changeset
|
575 void |
|
6d0f64f7dedd
Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14333
diff
changeset
|
576 Py_SetRecursionLimit(int new_limit) |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
577 { |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
578 recursion_limit = new_limit; |
|
43410
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
579 _Py_CheckRecursionLimit = recursion_limit; |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
580 } |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
581 |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
582 /* the macro Py_EnterRecursiveCall() only calls _Py_CheckRecursiveCall() |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
583 if the recursion_depth reaches _Py_CheckRecursionLimit. |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
584 If USE_STACKCHECK, the macro decrements _Py_CheckRecursionLimit |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
585 to guarantee that _Py_CheckRecursiveCall() is regularly called. |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
586 Without USE_STACKCHECK, there is no need for this. */ |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
587 int |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
588 _Py_CheckRecursiveCall(char *where) |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
589 { |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
590 PyThreadState *tstate = PyThreadState_GET(); |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
591 |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
592 #ifdef USE_STACKCHECK |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
593 if (PyOS_CheckStack()) { |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
594 --tstate->recursion_depth; |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
595 PyErr_SetString(PyExc_MemoryError, "Stack overflow"); |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
596 return -1; |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
597 } |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
598 #endif |
|
48986
22ab106e3186
Issue #3697: "Fatal Python error: Cannot recover from stack overflow"
Antoine Pitrou <solipsis@pitrou.net>
parents:
48887
diff
changeset
|
599 _Py_CheckRecursionLimit = recursion_limit; |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41969
diff
changeset
|
600 if (tstate->recursion_critical) |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41969
diff
changeset
|
601 /* Somebody asked that we don't check for recursion. */ |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41969
diff
changeset
|
602 return 0; |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41969
diff
changeset
|
603 if (tstate->overflowed) { |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41969
diff
changeset
|
604 if (tstate->recursion_depth > recursion_limit + 50) { |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41969
diff
changeset
|
605 /* Overflowing while handling an overflow. Give up. */ |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41969
diff
changeset
|
606 Py_FatalError("Cannot recover from stack overflow."); |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41969
diff
changeset
|
607 } |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41969
diff
changeset
|
608 return 0; |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41969
diff
changeset
|
609 } |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
610 if (tstate->recursion_depth > recursion_limit) { |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
611 --tstate->recursion_depth; |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41969
diff
changeset
|
612 tstate->overflowed = 1; |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
613 PyErr_Format(PyExc_RuntimeError, |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
614 "maximum recursion depth exceeded%s", |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
615 where); |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
616 return -1; |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
617 } |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
618 return 0; |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
619 } |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
620 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
621 /* 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
|
622 enum why_code { |
|
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
623 WHY_NOT = 0x0001, /* No error */ |
|
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
624 WHY_EXCEPTION = 0x0002, /* Exception occurred */ |
|
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
625 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
|
626 WHY_RETURN = 0x0008, /* 'return' statement */ |
|
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
627 WHY_BREAK = 0x0010, /* 'break' statement */ |
|
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
628 WHY_CONTINUE = 0x0020, /* 'continue' statement */ |
|
47594
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
629 WHY_YIELD = 0x0040, /* 'yield' operator */ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
630 WHY_SILENCED = 0x0080 /* Exception silenced by 'with' */ |
|
31875
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
631 }; |
|
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
632 |
|
43102
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
633 static enum why_code do_raise(PyObject *, PyObject *); |
|
41699
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
634 static int unpack_iterable(PyObject *, int, int, PyObject **); |
| 5018 | 635 |
|
50045
ba8fe3a40a5b
Merged revisions 67494 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
48986
diff
changeset
|
636 /* Records whether tracing is on for any thread. Counts the number of |
|
ba8fe3a40a5b
Merged revisions 67494 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
48986
diff
changeset
|
637 threads for which tstate->c_tracefunc is non-NULL, so if the value |
|
ba8fe3a40a5b
Merged revisions 67494 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
48986
diff
changeset
|
638 is 0, we know we don't have to check this thread's c_tracefunc. |
|
ba8fe3a40a5b
Merged revisions 67494 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
48986
diff
changeset
|
639 This speeds up the if statement in PyEval_EvalFrameEx() after |
|
ba8fe3a40a5b
Merged revisions 67494 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
48986
diff
changeset
|
640 fast_next_opcode*/ |
|
ba8fe3a40a5b
Merged revisions 67494 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
48986
diff
changeset
|
641 static int _Py_TracingPossible = 0; |
|
ba8fe3a40a5b
Merged revisions 67494 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
48986
diff
changeset
|
642 |
|
25108
3a26e352f0a6
replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents:
25078
diff
changeset
|
643 /* 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
|
644 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
|
645 int _Py_CheckInterval = 100; |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
646 volatile int _Py_Ticker = 0; /* so that we hit a "tick" first thing */ |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
647 |
| 5368 | 648 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
649 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
|
650 { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
651 return PyEval_EvalCodeEx(co, |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
652 globals, locals, |
| 5368 | 653 (PyObject **)NULL, 0, |
| 654 (PyObject **)NULL, 0, | |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
655 (PyObject **)NULL, 0, |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
656 NULL, NULL); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
657 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
658 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
659 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
660 /* Interpreter main loop */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
661 |
|
32421
485d2ef43419
Patch #966493: Cleanup generator/eval_frame exposure.
Martin v. Löwis <martin@v.loewis.de>
parents:
32412
diff
changeset
|
662 PyObject * |
|
35298
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
663 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
|
664 /* This is for backward compatibility with extension modules that |
|
43418
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
665 used this API; core interpreter code should call |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
666 PyEval_EvalFrameEx() */ |
|
35298
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
667 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
|
668 } |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
669 |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
670 PyObject * |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
671 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
|
672 { |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
673 #ifdef DXPAIRS |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
674 int lastopcode = 0; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
675 #endif |
|
43418
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
676 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
|
677 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
|
678 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
|
679 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
|
680 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
|
681 register int err; /* Error status -- nonzero if error */ |
| 5368 | 682 register PyObject *x; /* Result object -- NULL if error */ |
| 683 register PyObject *v; /* Temporary objects popped off stack */ | |
| 684 register PyObject *w; | |
| 685 register PyObject *u; | |
| 686 register PyObject *t; | |
|
16355
e4420c2468f9
Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16257
diff
changeset
|
687 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
|
688 PyObject *retval = NULL; /* Return value */ |
|
9671
1d40bc25703a
Use PyThreadState_GET() macro.
Guido van Rossum <guido@python.org>
parents:
9591
diff
changeset
|
689 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
|
690 PyCodeObject *co; |
| 24844 | 691 |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
692 /* when tracing we set things up so that |
| 24844 | 693 |
| 694 not (instr_lb <= current_bytecode_offset < instr_ub) | |
| 695 | |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
696 is true when the line being executed has changed. The |
| 24844 | 697 initial values are such as to make this false the first |
| 698 time it is tested. */ | |
| 31768 | 699 int instr_ub = -1, instr_lb = 0, instr_prev = -1; |
| 24844 | 700 |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
701 unsigned char *first_instr; |
|
24545
d2f41c8a81f0
small speedup for constant and name access
Skip Montanaro <skip@pobox.com>
parents:
24284
diff
changeset
|
702 PyObject *names; |
|
d2f41c8a81f0
small speedup for constant and name access
Skip Montanaro <skip@pobox.com>
parents:
24284
diff
changeset
|
703 PyObject *consts; |
|
35745
407c3dacbd7c
Fix some mods that got dropped from the AST merge
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
704 #if defined(Py_DEBUG) || defined(LLTRACE) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
705 /* 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
|
706 char *filename; |
|
1016
a41e3ba5b47d
Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents:
974
diff
changeset
|
707 #endif |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
708 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
709 /* Computed GOTOs, or |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
710 the-optimization-commonly-but-improperly-known-as-"threaded code" |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
711 using gcc's labels-as-values extension |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
712 (http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html). |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
713 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
714 The traditional bytecode evaluation loop uses a "switch" statement, which |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
715 decent compilers will optimize as a single indirect branch instruction |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
716 combined with a lookup table of jump addresses. However, since the |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
717 indirect jump instruction is shared by all opcodes, the CPU will have a |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
718 hard time making the right prediction for where to jump next (actually, |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
719 it will be always wrong except in the uncommon case of a sequence of |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
720 several identical opcodes). |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
721 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
722 "Threaded code" in contrast, uses an explicit jump table and an explicit |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
723 indirect jump instruction at the end of each opcode. Since the jump |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
724 instruction is at a different address for each opcode, the CPU will make a |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
725 separate prediction for each of these instructions, which is equivalent to |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
726 predicting the second opcode of each opcode pair. These predictions have |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
727 a much better chance to turn out valid, especially in small bytecode loops. |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
728 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
729 A mispredicted branch on a modern CPU flushes the whole pipeline and |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
730 can cost several CPU cycles (depending on the pipeline depth), |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
731 and potentially many more instructions (depending on the pipeline width). |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
732 A correctly predicted branch, however, is nearly free. |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
733 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
734 At the time of this writing, the "threaded code" version is up to 15-20% |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
735 faster than the normal "switch" version, depending on the compiler and the |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
736 CPU architecture. |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
737 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
738 We disable the optimization if DYNAMIC_EXECUTION_PROFILE is defined, |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
739 because it would render the measurements invalid. |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
740 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
741 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
742 NOTE: care must be taken that the compiler doesn't try to "optimize" the |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
743 indirect jumps by sharing them between all opcodes. Such optimizations |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
744 can be disabled on gcc by using the -fno-gcse flag (or possibly |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
745 -fno-crossjumping). |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
746 */ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
747 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
748 #if defined(USE_COMPUTED_GOTOS) && defined(DYNAMIC_EXECUTION_PROFILE) |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
749 #undef USE_COMPUTED_GOTOS |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
750 #endif |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
751 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
752 #ifdef USE_COMPUTED_GOTOS |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
753 /* Import the static jump table */ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
754 #include "opcode_targets.h" |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
755 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
756 /* This macro is used when several opcodes defer to the same implementation |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
757 (e.g. SETUP_LOOP, SETUP_FINALLY) */ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
758 #define TARGET_WITH_IMPL(op, impl) \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
759 TARGET_##op: \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
760 opcode = op; \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
761 if (HAS_ARG(op)) \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
762 oparg = NEXTARG(); \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
763 case op: \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
764 goto impl; \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
765 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
766 #define TARGET(op) \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
767 TARGET_##op: \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
768 opcode = op; \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
769 if (HAS_ARG(op)) \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
770 oparg = NEXTARG(); \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
771 case op: |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
772 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
773 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
774 #define DISPATCH() \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
775 { \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
776 /* Avoid multiple loads from _Py_Ticker despite `volatile` */ \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
777 int _tick = _Py_Ticker - 1; \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
778 _Py_Ticker = _tick; \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
779 if (_tick >= 0) { \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
780 FAST_DISPATCH(); \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
781 } \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
782 continue; \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
783 } |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
784 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
785 #ifdef LLTRACE |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
786 #define FAST_DISPATCH() \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
787 { \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
788 if (!lltrace && !_Py_TracingPossible) { \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
789 f->f_lasti = INSTR_OFFSET(); \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
790 goto *opcode_targets[*next_instr++]; \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
791 } \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
792 goto fast_next_opcode; \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
793 } |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
794 #else |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
795 #define FAST_DISPATCH() \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
796 { \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
797 if (!_Py_TracingPossible) { \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
798 f->f_lasti = INSTR_OFFSET(); \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
799 goto *opcode_targets[*next_instr++]; \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
800 } \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
801 goto fast_next_opcode; \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
802 } |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
803 #endif |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
804 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
805 #else |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
806 #define TARGET(op) \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
807 case op: |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
808 #define TARGET_WITH_IMPL(op, impl) \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
809 /* silence compiler warnings about `impl` unused */ \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
810 if (0) goto impl; \ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
811 case op: |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
812 #define DISPATCH() continue |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
813 #define FAST_DISPATCH() goto fast_next_opcode |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
814 #endif |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
815 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
816 |
|
24232
e06b1ab0bdb8
SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents:
24190
diff
changeset
|
817 /* 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
|
818 |
|
e06b1ab0bdb8
SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents:
24190
diff
changeset
|
819 #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
|
820 #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
|
821 #else |
|
e06b1ab0bdb8
SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents:
24190
diff
changeset
|
822 #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
|
823 #endif |
|
e06b1ab0bdb8
SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents:
24190
diff
changeset
|
824 |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
825 #ifdef WITH_TSC |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
826 /* 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
|
827 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
|
828 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
|
829 loop0 -- the top of the mainloop |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
830 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
|
831 (may be skipped) |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
832 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
|
833 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
|
834 |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
835 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
|
836 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
|
837 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
|
838 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
|
839 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
|
840 |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
841 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
|
842 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
|
843 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
|
844 |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
845 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
|
846 cases: |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
847 |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
848 IMPORT_STAR |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
849 IMPORT_FROM |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
850 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
|
851 |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
852 */ |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
853 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
|
854 int ticked = 0; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
855 |
|
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
|
856 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
|
857 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
|
858 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
|
859 READ_TIMESTAMP(loop1); |
| 33104 | 860 |
| 861 /* shut up the compiler */ | |
| 862 opcode = 0; | |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
863 #endif |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
864 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
865 /* Code access macros */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
866 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36475
diff
changeset
|
867 #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
|
868 #define NEXTOP() (*next_instr++) |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
869 #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
|
870 #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
|
871 #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
|
872 #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
|
873 |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
874 /* OpCode prediction macros |
|
43418
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
875 Some opcodes tend to come in pairs thus making it possible to |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
876 predict the second code when the first is run. For example, |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
877 COMPARE_OP is often followed by JUMP_IF_FALSE or JUMP_IF_TRUE. And, |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
878 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
|
879 |
|
48494
aca5b2e6a66f
Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47729
diff
changeset
|
880 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
|
881 variable against a constant. If the pairing was good, then the |
|
48494
aca5b2e6a66f
Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47729
diff
changeset
|
882 processor's own internal branch predication has a high likelihood of |
|
aca5b2e6a66f
Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47729
diff
changeset
|
883 success, resulting in a nearly zero-overhead transition to the |
|
aca5b2e6a66f
Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47729
diff
changeset
|
884 next opcode. A successful prediction saves a trip through the eval-loop |
|
48574
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
885 including its two unpredictable branches, the HAS_ARG test and the |
|
48494
aca5b2e6a66f
Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47729
diff
changeset
|
886 switch-case. Combined with the processor's internal branch prediction, |
|
48574
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
887 a successful PREDICT has the effect of making the two opcodes run as if |
|
48494
aca5b2e6a66f
Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47729
diff
changeset
|
888 they were a single new opcode with the bodies combined. |
|
aca5b2e6a66f
Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47729
diff
changeset
|
889 |
|
aca5b2e6a66f
Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47729
diff
changeset
|
890 If collecting opcode statistics, your choices are to either keep the |
|
aca5b2e6a66f
Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47729
diff
changeset
|
891 predictions turned-on and interpret the results as if some opcodes |
|
aca5b2e6a66f
Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47729
diff
changeset
|
892 had been combined or turn-off predictions so that the opcode frequency |
|
aca5b2e6a66f
Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47729
diff
changeset
|
893 counter updates for both opcodes. |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
894 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
895 Opcode prediction is disabled with threaded code, since the latter allows |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
896 the CPU to record separate branch prediction information for each |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
897 opcode. |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
898 |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
899 */ |
|
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
900 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
901 #if defined(DYNAMIC_EXECUTION_PROFILE) || defined(USE_COMPUTED_GOTOS) |
|
31487
f57f5ce22c8d
SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents:
31462
diff
changeset
|
902 #define PREDICT(op) if (0) goto PRED_##op |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
903 #define PREDICTED(op) PRED_##op: |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
904 #define PREDICTED_WITH_ARG(op) PRED_##op: |
|
31487
f57f5ce22c8d
SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents:
31462
diff
changeset
|
905 #else |
|
28303
470504ef578b
Fix comment and whitespace.
Raymond Hettinger <python@rcn.com>
parents:
28302
diff
changeset
|
906 #define PREDICT(op) if (*next_instr == op) goto PRED_##op |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
907 #define PREDICTED(op) PRED_##op: next_instr++ |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
908 #define PREDICTED_WITH_ARG(op) PRED_##op: oparg = PEEKARG(); next_instr += 3 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
909 #endif |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
910 |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
911 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
912 /* Stack manipulation macros */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
913 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36475
diff
changeset
|
914 /* 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
|
915 co_stacksize are ints. */ |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36475
diff
changeset
|
916 #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
|
917 #define EMPTY() (STACK_LEVEL() == 0) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
918 #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
|
919 #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
|
920 #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
|
921 #define FOURTH() (stack_pointer[-4]) |
|
54908
aa950f7962fd
Merged revisions 73614-73615 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54905
diff
changeset
|
922 #define PEEK(n) (stack_pointer[-(n)]) |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
923 #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
|
924 #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
|
925 #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
|
926 #define SET_FOURTH(v) (stack_pointer[-4] = (v)) |
|
54908
aa950f7962fd
Merged revisions 73614-73615 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54905
diff
changeset
|
927 #define SET_VALUE(n, v) (stack_pointer[-(n)] = (v)) |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
928 #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
|
929 #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
|
930 #define BASIC_POP() (*--stack_pointer) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
931 |
| 567 | 932 #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
|
933 #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
|
934 lltrace && prtrace(TOP(), "push")); \ |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
935 assert(STACK_LEVEL() <= co->co_stacksize); } |
|
43418
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
936 #define POP() ((void)(lltrace && prtrace(TOP(), "pop")), \ |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
937 BASIC_POP()) |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
938 #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
|
939 lltrace && prtrace(TOP(), "stackadj")); \ |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
940 assert(STACK_LEVEL() <= co->co_stacksize); } |
|
44310
e70acbf26cda
Merged revisions 59488-59511 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44187
diff
changeset
|
941 #define EXT_POP(STACK_POINTER) ((void)(lltrace && \ |
|
e70acbf26cda
Merged revisions 59488-59511 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44187
diff
changeset
|
942 prtrace((STACK_POINTER)[-1], "ext_pop")), \ |
|
e70acbf26cda
Merged revisions 59488-59511 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44187
diff
changeset
|
943 *--(STACK_POINTER)) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
944 #else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
945 #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
|
946 #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
|
947 #define STACKADJ(n) BASIC_STACKADJ(n) |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
948 #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
|
949 #endif |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
950 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
951 /* Local variable macros */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
952 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
953 #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
|
954 |
|
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
|
955 /* 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
|
956 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
|
957 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
|
958 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
|
959 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
|
960 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
|
961 #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
|
962 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
|
963 Py_XDECREF(tmp); } while (0) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
964 |
|
47594
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
965 |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
966 #define UNWIND_BLOCK(b) \ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
967 while (STACK_LEVEL() > (b)->b_level) { \ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
968 PyObject *v = POP(); \ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
969 Py_XDECREF(v); \ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
970 } |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
971 |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
972 #define UNWIND_EXCEPT_HANDLER(b) \ |
|
47729
ee2823e1f23b
improvements to the fix for #3114
Benjamin Peterson <benjamin@python.org>
parents:
47724
diff
changeset
|
973 { \ |
|
ee2823e1f23b
improvements to the fix for #3114
Benjamin Peterson <benjamin@python.org>
parents:
47724
diff
changeset
|
974 PyObject *type, *value, *traceback; \ |
|
ee2823e1f23b
improvements to the fix for #3114
Benjamin Peterson <benjamin@python.org>
parents:
47724
diff
changeset
|
975 assert(STACK_LEVEL() >= (b)->b_level + 3); \ |
|
ee2823e1f23b
improvements to the fix for #3114
Benjamin Peterson <benjamin@python.org>
parents:
47724
diff
changeset
|
976 while (STACK_LEVEL() > (b)->b_level + 3) { \ |
|
ee2823e1f23b
improvements to the fix for #3114
Benjamin Peterson <benjamin@python.org>
parents:
47724
diff
changeset
|
977 value = POP(); \ |
|
ee2823e1f23b
improvements to the fix for #3114
Benjamin Peterson <benjamin@python.org>
parents:
47724
diff
changeset
|
978 Py_XDECREF(value); \ |
|
ee2823e1f23b
improvements to the fix for #3114
Benjamin Peterson <benjamin@python.org>
parents:
47724
diff
changeset
|
979 } \ |
|
ee2823e1f23b
improvements to the fix for #3114
Benjamin Peterson <benjamin@python.org>
parents:
47724
diff
changeset
|
980 type = tstate->exc_type; \ |
|
ee2823e1f23b
improvements to the fix for #3114
Benjamin Peterson <benjamin@python.org>
parents:
47724
diff
changeset
|
981 value = tstate->exc_value; \ |
|
ee2823e1f23b
improvements to the fix for #3114
Benjamin Peterson <benjamin@python.org>
parents:
47724
diff
changeset
|
982 traceback = tstate->exc_traceback; \ |
|
ee2823e1f23b
improvements to the fix for #3114
Benjamin Peterson <benjamin@python.org>
parents:
47724
diff
changeset
|
983 tstate->exc_type = POP(); \ |
|
ee2823e1f23b
improvements to the fix for #3114
Benjamin Peterson <benjamin@python.org>
parents:
47724
diff
changeset
|
984 tstate->exc_value = POP(); \ |
|
ee2823e1f23b
improvements to the fix for #3114
Benjamin Peterson <benjamin@python.org>
parents:
47724
diff
changeset
|
985 tstate->exc_traceback = POP(); \ |
|
ee2823e1f23b
improvements to the fix for #3114
Benjamin Peterson <benjamin@python.org>
parents:
47724
diff
changeset
|
986 Py_XDECREF(type); \ |
|
ee2823e1f23b
improvements to the fix for #3114
Benjamin Peterson <benjamin@python.org>
parents:
47724
diff
changeset
|
987 Py_XDECREF(value); \ |
|
ee2823e1f23b
improvements to the fix for #3114
Benjamin Peterson <benjamin@python.org>
parents:
47724
diff
changeset
|
988 Py_XDECREF(traceback); \ |
|
ee2823e1f23b
improvements to the fix for #3114
Benjamin Peterson <benjamin@python.org>
parents:
47724
diff
changeset
|
989 } |
|
47594
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
990 |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
991 #define SAVE_EXC_STATE() \ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
992 { \ |
|
47729
ee2823e1f23b
improvements to the fix for #3114
Benjamin Peterson <benjamin@python.org>
parents:
47724
diff
changeset
|
993 PyObject *type, *value, *traceback; \ |
|
47594
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
994 Py_XINCREF(tstate->exc_type); \ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
995 Py_XINCREF(tstate->exc_value); \ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
996 Py_XINCREF(tstate->exc_traceback); \ |
|
47729
ee2823e1f23b
improvements to the fix for #3114
Benjamin Peterson <benjamin@python.org>
parents:
47724
diff
changeset
|
997 type = f->f_exc_type; \ |
|
ee2823e1f23b
improvements to the fix for #3114
Benjamin Peterson <benjamin@python.org>
parents:
47724
diff
changeset
|
998 value = f->f_exc_value; \ |
|
ee2823e1f23b
improvements to the fix for #3114
Benjamin Peterson <benjamin@python.org>
parents:
47724
diff
changeset
|
999 traceback = f->f_exc_traceback; \ |
|
47594
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1000 f->f_exc_type = tstate->exc_type; \ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1001 f->f_exc_value = tstate->exc_value; \ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1002 f->f_exc_traceback = tstate->exc_traceback; \ |
|
47729
ee2823e1f23b
improvements to the fix for #3114
Benjamin Peterson <benjamin@python.org>
parents:
47724
diff
changeset
|
1003 Py_XDECREF(type); \ |
|
ee2823e1f23b
improvements to the fix for #3114
Benjamin Peterson <benjamin@python.org>
parents:
47724
diff
changeset
|
1004 Py_XDECREF(value); \ |
|
ee2823e1f23b
improvements to the fix for #3114
Benjamin Peterson <benjamin@python.org>
parents:
47724
diff
changeset
|
1005 Py_XDECREF(traceback); \ |
|
47594
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1006 } |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1007 |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1008 #define SWAP_EXC_STATE() \ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1009 { \ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1010 PyObject *tmp; \ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1011 tmp = tstate->exc_type; \ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1012 tstate->exc_type = f->f_exc_type; \ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1013 f->f_exc_type = tmp; \ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1014 tmp = tstate->exc_value; \ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1015 tstate->exc_value = f->f_exc_value; \ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1016 f->f_exc_value = tmp; \ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1017 tmp = tstate->exc_traceback; \ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1018 tstate->exc_traceback = f->f_exc_traceback; \ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1019 f->f_exc_traceback = tmp; \ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1020 } |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1021 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1022 /* Start of code */ |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1023 |
|
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
|
1024 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
|
1025 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
|
1026 |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
1027 /* push frame */ |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
1028 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
|
1029 return NULL; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
1030 |
|
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
|
1031 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
|
1032 |
|
19692
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
1033 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
|
1034 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
|
1035 /* 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
|
1036 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
|
1037 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
|
1038 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
|
1039 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
|
1040 (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
|
1041 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
|
1042 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
|
1043 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
|
1044 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
|
1045 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
|
1046 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
|
1047 whenever an exception is detected. */ |
|
48574
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
1048 if (call_trace_protected(tstate->c_tracefunc, |
|
43840
73c8e27eb9ce
Correction for issue1265 (pdb bug with "with" statement).
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43815
diff
changeset
|
1049 tstate->c_traceobj, |
|
73c8e27eb9ce
Correction for issue1265 (pdb bug with "with" statement).
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43815
diff
changeset
|
1050 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
|
1051 /* Trace function raised an error */ |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
1052 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
|
1053 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
1054 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
1055 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
|
1056 /* 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
|
1057 return itself and isn't called for "line" events */ |
|
43840
73c8e27eb9ce
Correction for issue1265 (pdb bug with "with" statement).
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43815
diff
changeset
|
1058 if (call_trace_protected(tstate->c_profilefunc, |
|
73c8e27eb9ce
Correction for issue1265 (pdb bug with "with" statement).
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43815
diff
changeset
|
1059 tstate->c_profileobj, |
|
73c8e27eb9ce
Correction for issue1265 (pdb bug with "with" statement).
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43815
diff
changeset
|
1060 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
|
1061 /* Profile function raised an error */ |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
1062 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
|
1063 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
1064 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
1065 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
1066 |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1067 co = f->f_code; |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1068 names = co->co_names; |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1069 consts = co->co_consts; |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1070 fastlocals = f->f_localsplus; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1071 freevars = f->f_localsplus + co->co_nlocals; |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46725
diff
changeset
|
1072 first_instr = (unsigned char*) PyBytes_AS_STRING(co->co_code); |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1073 /* 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
|
1074 |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1075 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
|
1076 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
|
1077 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
|
1078 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
|
1079 and YIELD_VALUE doesn't fiddle with f_lasti any more. So this |
|
48574
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
1080 does work. Promise. |
|
40582
67287ca4e1e8
Merged revisions 53005-53303 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40529
diff
changeset
|
1081 |
|
67287ca4e1e8
Merged revisions 53005-53303 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40529
diff
changeset
|
1082 When the PREDICT() macros are enabled, some opcode pairs follow in |
|
48574
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
1083 direct succession without updating f->f_lasti. A successful |
|
40582
67287ca4e1e8
Merged revisions 53005-53303 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40529
diff
changeset
|
1084 prediction effectively links the two codes together as if they |
|
67287ca4e1e8
Merged revisions 53005-53303 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40529
diff
changeset
|
1085 were a single new opcode; accordingly,f->f_lasti will point to |
|
67287ca4e1e8
Merged revisions 53005-53303 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40529
diff
changeset
|
1086 the first code in the pair (for instance, GET_ITER followed by |
|
67287ca4e1e8
Merged revisions 53005-53303 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40529
diff
changeset
|
1087 FOR_ITER is effectively a single opcode and f->f_lasti will point |
|
67287ca4e1e8
Merged revisions 53005-53303 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40529
diff
changeset
|
1088 at to the beginning of the combined pair.) |
|
67287ca4e1e8
Merged revisions 53005-53303 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40529
diff
changeset
|
1089 */ |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1090 next_instr = first_instr + f->f_lasti + 1; |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1091 stack_pointer = f->f_stacktop; |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1092 assert(stack_pointer != NULL); |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1093 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
|
1094 |
|
47594
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1095 if (f->f_code->co_flags & CO_GENERATOR) { |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1096 if (f->f_exc_type != NULL && f->f_exc_type != Py_None) { |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1097 /* We were in an except handler when we left, |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1098 restore the exception state which was put aside |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1099 (see YIELD_VALUE). */ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1100 SWAP_EXC_STATE(); |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1101 } |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1102 else { |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1103 SAVE_EXC_STATE(); |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1104 } |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1105 } |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1106 |
|
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
|
1107 #ifdef LLTRACE |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
1108 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
|
1109 #endif |
|
35745
407c3dacbd7c
Fix some mods that got dropped from the AST merge
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
1110 #if defined(Py_DEBUG) || defined(LLTRACE) |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
48574
diff
changeset
|
1111 filename = _PyUnicode_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
|
1112 #endif |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1113 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1114 why = WHY_NOT; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1115 err = 0; |
| 5368 | 1116 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
|
1117 w = NULL; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1118 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
1119 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
|
1120 why = WHY_EXCEPTION; |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
1121 goto on_error; |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
1122 } |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1123 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1124 for (;;) { |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
1125 #ifdef WITH_TSC |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
1126 if (inst1 == 0) { |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
1127 /* 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
|
1128 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
|
1129 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
|
1130 */ |
|
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
|
1131 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
|
1132 loop1 = inst1; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
1133 } |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
1134 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
|
1135 intr0, intr1); |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
1136 ticked = 0; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
1137 inst1 = 0; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
1138 intr0 = 0; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
1139 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
|
1140 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
|
1141 #endif |
| 24844 | 1142 assert(stack_pointer >= f->f_valuestack); /* else underflow */ |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1143 assert(STACK_LEVEL() <= co->co_stacksize); /* else overflow */ |
| 24844 | 1144 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1145 /* 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
|
1146 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
|
1147 only every Nth instruction. We also do it if |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
1148 ``pendingcalls_to_do'' is set, i.e. when an asynchronous |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1149 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
|
1150 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
|
1151 Py_MakePendingCalls() above. */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1152 |
|
25108
3a26e352f0a6
replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents:
25078
diff
changeset
|
1153 if (--_Py_Ticker < 0) { |
|
43410
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
1154 if (*next_instr == SETUP_FINALLY) { |
|
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
1155 /* Make the last opcode before |
|
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
1156 a try: finally: block uninterruptable. */ |
|
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
1157 goto fast_next_opcode; |
|
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
1158 } |
|
25108
3a26e352f0a6
replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents:
25078
diff
changeset
|
1159 _Py_Ticker = _Py_CheckInterval; |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1160 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
|
1161 #ifdef WITH_TSC |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
1162 ticked = 1; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
1163 #endif |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
1164 if (pendingcalls_to_do) { |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
1165 if (Py_MakePendingCalls() < 0) { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
1166 why = WHY_EXCEPTION; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
1167 goto on_error; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
1168 } |
|
50839
75009d4863c9
Merged revisions 68460 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50211
diff
changeset
|
1169 if (pendingcalls_to_do) |
|
34020
be370abb020f
Hye-Shik Chang's fix for Bug 875692.
Kurt B. Kaiser <kbk@shore.net>
parents:
33715
diff
changeset
|
1170 /* MakePendingCalls() didn't succeed. |
|
be370abb020f
Hye-Shik Chang's fix for Bug 875692.
Kurt B. Kaiser <kbk@shore.net>
parents:
33715
diff
changeset
|
1171 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
|
1172 "periodic" code, possibly after |
|
be370abb020f
Hye-Shik Chang's fix for Bug 875692.
Kurt B. Kaiser <kbk@shore.net>
parents:
33715
diff
changeset
|
1173 a thread switch */ |
|
be370abb020f
Hye-Shik Chang's fix for Bug 875692.
Kurt B. Kaiser <kbk@shore.net>
parents:
33715
diff
changeset
|
1174 _Py_Ticker = 0; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
1175 } |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
1176 #ifdef WITH_THREAD |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
1177 if (interpreter_lock) { |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
1178 /* Give another thread a chance */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
1179 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
1180 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
|
1181 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
|
1182 PyThread_release_lock(interpreter_lock); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
1183 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
1184 /* Other threads may run now */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
1185 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
1186 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
|
1187 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
|
1188 Py_FatalError("ceval: orphan tstate"); |
|
29643
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
1189 |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
1190 /* Check for thread interrupts */ |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
1191 |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
1192 if (tstate->async_exc != NULL) { |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
1193 x = tstate->async_exc; |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
1194 tstate->async_exc = NULL; |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
1195 PyErr_SetNone(x); |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
1196 Py_DECREF(x); |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
1197 why = WHY_EXCEPTION; |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
1198 goto on_error; |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
1199 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
1200 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
1201 #endif |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1202 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
1203 |
|
21974
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1204 fast_next_opcode: |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1205 f->f_lasti = INSTR_OFFSET(); |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1206 |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1207 /* line-by-line tracing support */ |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1208 |
|
50045
ba8fe3a40a5b
Merged revisions 67494 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
48986
diff
changeset
|
1209 if (_Py_TracingPossible && |
|
ba8fe3a40a5b
Merged revisions 67494 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
48986
diff
changeset
|
1210 tstate->c_tracefunc != NULL && !tstate->tracing) { |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1211 /* see maybe_call_line_trace |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1212 for expository comments */ |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1213 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
|
1214 |
|
28886
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
1215 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
|
1216 tstate->c_traceobj, |
| 31768 | 1217 f, &instr_lb, &instr_ub, |
| 1218 &instr_prev); | |
|
28886
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
1219 /* Reload possibly changed frame fields */ |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
1220 JUMPTO(f->f_lasti); |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
1221 if (f->f_stacktop != NULL) { |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
1222 stack_pointer = f->f_stacktop; |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
1223 f->f_stacktop = NULL; |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
1224 } |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
1225 if (err) { |
|
26110
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
1226 /* trace function raised an exception */ |
|
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
1227 goto on_error; |
|
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
1228 } |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1229 } |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
1230 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1231 /* Extract opcode and argument */ |
|
1016
a41e3ba5b47d
Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents:
974
diff
changeset
|
1232 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1233 opcode = NEXTOP(); |
|
32359
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
1234 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
|
1235 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
|
1236 if (HAS_ARG(opcode)) |
|
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
1237 oparg = NEXTARG(); |
|
14147
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
1238 dispatch_opcode: |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
1239 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
1240 #ifdef DXPAIRS |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
1241 dxpairs[lastopcode][opcode]++; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
1242 lastopcode = opcode; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
1243 #endif |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
1244 dxp[opcode]++; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
1245 #endif |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1246 |
| 567 | 1247 #ifdef LLTRACE |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1248 /* Instruction tracing */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1249 |
| 567 | 1250 if (lltrace) { |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1251 if (HAS_ARG(opcode)) { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1252 printf("%d: %d, %d\n", |
| 24844 | 1253 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
|
1254 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1255 else { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1256 printf("%d: %d\n", |
| 24844 | 1257 f->f_lasti, opcode); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1258 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1259 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1260 #endif |
| 24844 | 1261 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1262 /* 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
|
1263 READ_TIMESTAMP(inst0); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1264 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1265 switch (opcode) { |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1266 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1267 /* BEWARE! |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1268 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
|
1269 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
|
1270 and that no operation that succeeds does this! */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1271 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1272 /* case STOP_CODE: this is an error! */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1273 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1274 TARGET(NOP) |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1275 FAST_DISPATCH(); |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1276 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1277 TARGET(LOAD_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
|
1278 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
|
1279 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
|
1280 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
|
1281 PUSH(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1282 FAST_DISPATCH(); |
|
21974
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1283 } |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1284 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
|
1285 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
|
1286 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
|
1287 break; |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1288 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1289 TARGET(LOAD_CONST) |
|
24545
d2f41c8a81f0
small speedup for constant and name access
Skip Montanaro <skip@pobox.com>
parents:
24284
diff
changeset
|
1290 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
|
1291 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
|
1292 PUSH(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1293 FAST_DISPATCH(); |
|
21974
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1294 |
|
28304
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
1295 PREDICTED_WITH_ARG(STORE_FAST); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1296 TARGET(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
|
1297 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
|
1298 SETLOCAL(oparg, v); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1299 FAST_DISPATCH(); |
|
21974
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
1300 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1301 TARGET(POP_TOP) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1302 v = POP(); |
| 5368 | 1303 Py_DECREF(v); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1304 FAST_DISPATCH(); |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1305 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1306 TARGET(ROT_TWO) |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1307 v = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1308 w = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1309 SET_TOP(w); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1310 SET_SECOND(v); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1311 FAST_DISPATCH(); |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1312 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1313 TARGET(ROT_THREE) |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1314 v = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1315 w = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1316 x = THIRD(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1317 SET_TOP(w); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1318 SET_SECOND(x); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1319 SET_THIRD(v); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1320 FAST_DISPATCH(); |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1321 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1322 TARGET(ROT_FOUR) |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1323 u = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1324 v = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1325 w = THIRD(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1326 x = FOURTH(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1327 SET_TOP(v); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1328 SET_SECOND(w); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1329 SET_THIRD(x); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1330 SET_FOURTH(u); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1331 FAST_DISPATCH(); |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1332 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1333 TARGET(DUP_TOP) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1334 v = TOP(); |
| 5368 | 1335 Py_INCREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1336 PUSH(v); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1337 FAST_DISPATCH(); |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1338 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1339 TARGET(DUP_TOPX) |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
1340 if (oparg == 2) { |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1341 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
|
1342 Py_INCREF(x); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1343 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
|
1344 Py_INCREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1345 STACKADJ(2); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1346 SET_TOP(x); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1347 SET_SECOND(w); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1348 FAST_DISPATCH(); |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
1349 } 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
|
1350 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
|
1351 Py_INCREF(x); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1352 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
|
1353 Py_INCREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1354 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
|
1355 Py_INCREF(v); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1356 STACKADJ(3); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1357 SET_TOP(x); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1358 SET_SECOND(w); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1359 SET_THIRD(v); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1360 FAST_DISPATCH(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1361 } |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
1362 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
|
1363 " (bytecode corruption?)"); |
|
50112
abf815b80b5d
Merged revisions 67666,67685 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
50104
diff
changeset
|
1364 /* 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
|
1365 break; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1366 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1367 TARGET(UNARY_POSITIVE) |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1368 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1369 x = PyNumber_Positive(v); |
| 5368 | 1370 Py_DECREF(v); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1371 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1372 if (x != NULL) DISPATCH(); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1373 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1374 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1375 TARGET(UNARY_NEGATIVE) |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1376 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1377 x = PyNumber_Negative(v); |
| 5368 | 1378 Py_DECREF(v); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1379 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1380 if (x != NULL) DISPATCH(); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1381 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1382 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1383 TARGET(UNARY_NOT) |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1384 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1385 err = PyObject_IsTrue(v); |
| 5368 | 1386 Py_DECREF(v); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1387 if (err == 0) { |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1388 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
|
1389 SET_TOP(Py_True); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1390 DISPATCH(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1391 } |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1392 else if (err > 0) { |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1393 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
|
1394 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
|
1395 err = 0; |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1396 DISPATCH(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1397 } |
|
27243
3afbd55fb18f
Replaced POP() with STACKADJ(-1) on lines where the result wasn't used.
Raymond Hettinger <python@rcn.com>
parents:
27201
diff
changeset
|
1398 STACKADJ(-1); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1399 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1400 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1401 TARGET(UNARY_INVERT) |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1402 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1403 x = PyNumber_Invert(v); |
| 5368 | 1404 Py_DECREF(v); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1405 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1406 if (x != NULL) DISPATCH(); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1407 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1408 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1409 TARGET(BINARY_POWER) |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3294
diff
changeset
|
1410 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1411 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1412 x = PyNumber_Power(v, w, Py_None); |
| 5368 | 1413 Py_DECREF(v); |
| 1414 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1415 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1416 if (x != NULL) DISPATCH(); |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3294
diff
changeset
|
1417 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1418 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1419 TARGET(BINARY_MULTIPLY) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1420 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1421 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1422 x = PyNumber_Multiply(v, w); |
| 5368 | 1423 Py_DECREF(v); |
| 1424 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1425 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1426 if (x != NULL) DISPATCH(); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1427 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1428 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1429 TARGET(BINARY_TRUE_DIVIDE) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1430 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1431 v = TOP(); |
|
21251
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1432 x = PyNumber_TrueDivide(v, w); |
| 5368 | 1433 Py_DECREF(v); |
| 1434 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1435 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1436 if (x != NULL) DISPATCH(); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1437 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1438 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1439 TARGET(BINARY_FLOOR_DIVIDE) |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1440 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1441 v = TOP(); |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1442 x = PyNumber_FloorDivide(v, w); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1443 Py_DECREF(v); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1444 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1445 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1446 if (x != NULL) DISPATCH(); |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1447 break; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1448 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1449 TARGET(BINARY_MODULO) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1450 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1451 v = TOP(); |
|
51872
3722ce458318
Merged revisions 69811,69947 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51853
diff
changeset
|
1452 if (PyUnicode_CheckExact(v)) |
|
3722ce458318
Merged revisions 69811,69947 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51853
diff
changeset
|
1453 x = PyUnicode_Format(v, w); |
|
3722ce458318
Merged revisions 69811,69947 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51853
diff
changeset
|
1454 else |
|
3722ce458318
Merged revisions 69811,69947 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51853
diff
changeset
|
1455 x = PyNumber_Remainder(v, w); |
| 5368 | 1456 Py_DECREF(v); |
| 1457 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1458 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1459 if (x != NULL) DISPATCH(); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1460 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1461 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1462 TARGET(BINARY_ADD) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1463 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1464 v = TOP(); |
|
44156
fb84bd9500a4
Remove special-casing of integer operations, to stop
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1465 if (PyUnicode_CheckExact(v) && |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
1466 PyUnicode_CheckExact(w)) { |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
1467 x = unicode_concatenate(v, w, f, next_instr); |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
1468 /* unicode_concatenate consumed the ref to v */ |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1469 goto skip_decref_vx; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1470 } |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1471 else { |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1472 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
|
1473 } |
| 5368 | 1474 Py_DECREF(v); |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1475 skip_decref_vx: |
| 5368 | 1476 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1477 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1478 if (x != NULL) DISPATCH(); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1479 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1480 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1481 TARGET(BINARY_SUBTRACT) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1482 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1483 v = TOP(); |
|
44156
fb84bd9500a4
Remove special-casing of integer operations, to stop
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1484 x = PyNumber_Subtract(v, w); |
| 5368 | 1485 Py_DECREF(v); |
| 1486 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1487 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1488 if (x != NULL) DISPATCH(); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1489 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1490 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1491 TARGET(BINARY_SUBSCR) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1492 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1493 v = TOP(); |
|
44156
fb84bd9500a4
Remove special-casing of integer operations, to stop
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1494 x = PyObject_GetItem(v, w); |
| 5368 | 1495 Py_DECREF(v); |
| 1496 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1497 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1498 if (x != NULL) DISPATCH(); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1499 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1500 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1501 TARGET(BINARY_LSHIFT) |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1502 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1503 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1504 x = PyNumber_Lshift(v, w); |
| 5368 | 1505 Py_DECREF(v); |
| 1506 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1507 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1508 if (x != NULL) DISPATCH(); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1509 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1510 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1511 TARGET(BINARY_RSHIFT) |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1512 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1513 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1514 x = PyNumber_Rshift(v, w); |
| 5368 | 1515 Py_DECREF(v); |
| 1516 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1517 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1518 if (x != NULL) DISPATCH(); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1519 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1520 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1521 TARGET(BINARY_AND) |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1522 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1523 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1524 x = PyNumber_And(v, w); |
| 5368 | 1525 Py_DECREF(v); |
| 1526 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1527 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1528 if (x != NULL) DISPATCH(); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1529 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1530 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1531 TARGET(BINARY_XOR) |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1532 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1533 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1534 x = PyNumber_Xor(v, w); |
| 5368 | 1535 Py_DECREF(v); |
| 1536 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1537 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1538 if (x != NULL) DISPATCH(); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1539 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1540 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1541 TARGET(BINARY_OR) |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1542 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1543 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1544 x = PyNumber_Or(v, w); |
| 5368 | 1545 Py_DECREF(v); |
| 1546 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1547 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1548 if (x != NULL) DISPATCH(); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1549 break; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1550 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1551 TARGET(LIST_APPEND) |
|
31618
bc006682acb2
SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents:
31606
diff
changeset
|
1552 w = POP(); |
|
54908
aa950f7962fd
Merged revisions 73614-73615 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54905
diff
changeset
|
1553 v = PEEK(oparg); |
|
31618
bc006682acb2
SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents:
31606
diff
changeset
|
1554 err = PyList_Append(v, w); |
|
bc006682acb2
SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents:
31606
diff
changeset
|
1555 Py_DECREF(w); |
|
31649
243642bbd03f
LIST_APPEND is predicably followed by JUMP_ABSOLUTE.
Raymond Hettinger <python@rcn.com>
parents:
31647
diff
changeset
|
1556 if (err == 0) { |
|
243642bbd03f
LIST_APPEND is predicably followed by JUMP_ABSOLUTE.
Raymond Hettinger <python@rcn.com>
parents:
31647
diff
changeset
|
1557 PREDICT(JUMP_ABSOLUTE); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1558 DISPATCH(); |
|
31649
243642bbd03f
LIST_APPEND is predicably followed by JUMP_ABSOLUTE.
Raymond Hettinger <python@rcn.com>
parents:
31647
diff
changeset
|
1559 } |
|
31618
bc006682acb2
SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents:
31606
diff
changeset
|
1560 break; |
|
bc006682acb2
SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents:
31606
diff
changeset
|
1561 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1562 TARGET(SET_ADD) |
|
41464
060c79f6d919
Hide list comp variables and support set comprehensions
Nick Coghlan <ncoghlan@gmail.com>
parents:
41226
diff
changeset
|
1563 w = POP(); |
|
50211
2ee4653927f7
Merged revisions 67818 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50112
diff
changeset
|
1564 v = stack_pointer[-oparg]; |
|
41464
060c79f6d919
Hide list comp variables and support set comprehensions
Nick Coghlan <ncoghlan@gmail.com>
parents:
41226
diff
changeset
|
1565 err = PySet_Add(v, w); |
|
060c79f6d919
Hide list comp variables and support set comprehensions
Nick Coghlan <ncoghlan@gmail.com>
parents:
41226
diff
changeset
|
1566 Py_DECREF(w); |
|
060c79f6d919
Hide list comp variables and support set comprehensions
Nick Coghlan <ncoghlan@gmail.com>
parents:
41226
diff
changeset
|
1567 if (err == 0) { |
|
060c79f6d919
Hide list comp variables and support set comprehensions
Nick Coghlan <ncoghlan@gmail.com>
parents:
41226
diff
changeset
|
1568 PREDICT(JUMP_ABSOLUTE); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1569 DISPATCH(); |
|
41464
060c79f6d919
Hide list comp variables and support set comprehensions
Nick Coghlan <ncoghlan@gmail.com>
parents:
41226
diff
changeset
|
1570 } |
|
060c79f6d919
Hide list comp variables and support set comprehensions
Nick Coghlan <ncoghlan@gmail.com>
parents:
41226
diff
changeset
|
1571 break; |
|
060c79f6d919
Hide list comp variables and support set comprehensions
Nick Coghlan <ncoghlan@gmail.com>
parents:
41226
diff
changeset
|
1572 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1573 TARGET(INPLACE_POWER) |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1574 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1575 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1576 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
|
1577 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1578 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1579 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1580 if (x != NULL) DISPATCH(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1581 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1582 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1583 TARGET(INPLACE_MULTIPLY) |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1584 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1585 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1586 x = PyNumber_InPlaceMultiply(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1587 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1588 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1589 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1590 if (x != NULL) DISPATCH(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1591 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1592 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1593 TARGET(INPLACE_TRUE_DIVIDE) |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1594 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1595 v = TOP(); |
|
21537
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1596 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
|
1597 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1598 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1599 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1600 if (x != NULL) DISPATCH(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1601 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1602 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1603 TARGET(INPLACE_FLOOR_DIVIDE) |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1604 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1605 v = TOP(); |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1606 x = PyNumber_InPlaceFloorDivide(v, w); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1607 Py_DECREF(v); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1608 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1609 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1610 if (x != NULL) DISPATCH(); |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1611 break; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1612 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1613 TARGET(INPLACE_MODULO) |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1614 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1615 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1616 x = PyNumber_InPlaceRemainder(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1617 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1618 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1619 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1620 if (x != NULL) DISPATCH(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1621 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1622 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1623 TARGET(INPLACE_ADD) |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1624 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1625 v = TOP(); |
|
44156
fb84bd9500a4
Remove special-casing of integer operations, to stop
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1626 if (PyUnicode_CheckExact(v) && |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
1627 PyUnicode_CheckExact(w)) { |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
1628 x = unicode_concatenate(v, w, f, next_instr); |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
1629 /* unicode_concatenate consumed the ref to v */ |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1630 goto skip_decref_v; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1631 } |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1632 else { |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1633 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
|
1634 } |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1635 Py_DECREF(v); |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
1636 skip_decref_v: |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1637 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1638 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1639 if (x != NULL) DISPATCH(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1640 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1641 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1642 TARGET(INPLACE_SUBTRACT) |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1643 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1644 v = TOP(); |
|
44156
fb84bd9500a4
Remove special-casing of integer operations, to stop
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1645 x = PyNumber_InPlaceSubtract(v, w); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1646 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1647 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1648 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1649 if (x != NULL) DISPATCH(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1650 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1651 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1652 TARGET(INPLACE_LSHIFT) |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1653 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1654 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1655 x = PyNumber_InPlaceLshift(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1656 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1657 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1658 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1659 if (x != NULL) DISPATCH(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1660 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1661 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1662 TARGET(INPLACE_RSHIFT) |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1663 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1664 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1665 x = PyNumber_InPlaceRshift(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1666 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1667 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1668 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1669 if (x != NULL) DISPATCH(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1670 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1671 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1672 TARGET(INPLACE_AND) |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1673 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1674 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1675 x = PyNumber_InPlaceAnd(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1676 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1677 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1678 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1679 if (x != NULL) DISPATCH(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1680 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1681 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1682 TARGET(INPLACE_XOR) |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1683 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1684 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1685 x = PyNumber_InPlaceXor(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1686 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1687 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1688 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1689 if (x != NULL) DISPATCH(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1690 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1691 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1692 TARGET(INPLACE_OR) |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1693 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1694 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1695 x = PyNumber_InPlaceOr(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1696 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1697 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1698 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1699 if (x != NULL) DISPATCH(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1700 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1701 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1702 TARGET(STORE_SUBSCR) |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1703 w = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1704 v = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1705 u = THIRD(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1706 STACKADJ(-3); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1707 /* v[w] = u */ |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1708 err = PyObject_SetItem(v, w, u); |
| 5368 | 1709 Py_DECREF(u); |
| 1710 Py_DECREF(v); | |
| 1711 Py_DECREF(w); | |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1712 if (err == 0) DISPATCH(); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1713 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1714 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1715 TARGET(DELETE_SUBSCR) |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1716 w = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1717 v = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1718 STACKADJ(-2); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1719 /* del v[w] */ |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1720 err = PyObject_DelItem(v, w); |
| 5368 | 1721 Py_DECREF(v); |
| 1722 Py_DECREF(w); | |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1723 if (err == 0) DISPATCH(); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1724 break; |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1725 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1726 TARGET(PRINT_EXPR) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1727 v = POP(); |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1728 w = PySys_GetObject("displayhook"); |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1729 if (w == NULL) { |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1730 PyErr_SetString(PyExc_RuntimeError, |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1731 "lost sys.displayhook"); |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1732 err = -1; |
|
15814
faaf9f10d849
Fixed bugs noted by Greg Stein
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15811
diff
changeset
|
1733 x = NULL; |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1734 } |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1735 if (err == 0) { |
|
30683
3b59fa5d25b1
Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents:
29669
diff
changeset
|
1736 x = PyTuple_Pack(1, v); |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1737 if (x == NULL) |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1738 err = -1; |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1739 } |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1740 if (err == 0) { |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1741 w = PyEval_CallObject(w, x); |
|
15814
faaf9f10d849
Fixed bugs noted by Greg Stein
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15811
diff
changeset
|
1742 Py_XDECREF(w); |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1743 if (w == NULL) |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1744 err = -1; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1745 } |
| 5368 | 1746 Py_DECREF(v); |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1747 Py_XDECREF(x); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1748 break; |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1749 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1750 #ifdef CASE_TOO_BIG |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1751 default: switch (opcode) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1752 #endif |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1753 TARGET(RAISE_VARARGS) |
|
43102
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
1754 v = w = NULL; |
|
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
|
1755 switch (oparg) { |
| 43411 | 1756 case 2: |
| 1757 v = POP(); /* cause */ | |
|
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
|
1758 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
|
1759 w = POP(); /* exc */ |
|
7946
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
1760 case 0: /* Fallthrough */ |
|
43102
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
1761 why = do_raise(w, v); |
|
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
|
1762 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
|
1763 default: |
| 5368 | 1764 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
|
1765 "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
|
1766 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
|
1767 break; |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1768 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1769 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1770 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1771 TARGET(STORE_LOCALS) |
|
41226
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
40946
diff
changeset
|
1772 x = POP(); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
40946
diff
changeset
|
1773 v = f->f_locals; |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
40946
diff
changeset
|
1774 Py_XDECREF(v); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
40946
diff
changeset
|
1775 f->f_locals = x; |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1776 DISPATCH(); |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1777 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1778 TARGET(RETURN_VALUE) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1779 retval = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1780 why = WHY_RETURN; |
|
31462
d5c047807c69
SF patch #864059: optimize eval_frame
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1781 goto fast_block_end; |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1782 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1783 TARGET(YIELD_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
|
1784 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
|
1785 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
|
1786 why = WHY_YIELD; |
|
47594
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1787 /* Put aside the current exception state and restore |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1788 that of the calling frame. This only serves when |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1789 "yield" is used inside an except handler. */ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1790 SWAP_EXC_STATE(); |
|
31462
d5c047807c69
SF patch #864059: optimize eval_frame
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1791 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
|
1792 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1793 TARGET(POP_EXCEPT) |
|
47594
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1794 { |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1795 PyTryBlock *b = PyFrame_BlockPop(f); |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1796 if (b->b_type != EXCEPT_HANDLER) { |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1797 PyErr_SetString(PyExc_SystemError, |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1798 "popped block is not an except handler"); |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1799 why = WHY_EXCEPTION; |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1800 break; |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1801 } |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1802 UNWIND_EXCEPT_HANDLER(b); |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1803 } |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1804 DISPATCH(); |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1805 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1806 TARGET(POP_BLOCK) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1807 { |
| 5368 | 1808 PyTryBlock *b = PyFrame_BlockPop(f); |
|
47594
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1809 UNWIND_BLOCK(b); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1810 } |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1811 DISPATCH(); |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1812 |
|
45635
882eba145119
Merged revisions 61189-61190,61192,61194-61195,61198-61199 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45017
diff
changeset
|
1813 PREDICTED(END_FINALLY); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1814 TARGET(END_FINALLY) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1815 v = POP(); |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43996
diff
changeset
|
1816 if (PyLong_Check(v)) { |
|
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43996
diff
changeset
|
1817 why = (enum why_code) PyLong_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
|
1818 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
|
1819 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
|
1820 why == WHY_CONTINUE) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1821 retval = POP(); |
|
47594
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1822 if (why == WHY_SILENCED) { |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1823 /* An exception was silenced by 'with', we must |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1824 manually unwind the EXCEPT_HANDLER block which was |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1825 created when the exception was caught, otherwise |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1826 the stack will be in an inconsistent state. */ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1827 PyTryBlock *b = PyFrame_BlockPop(f); |
|
54905
b55a78b39bd5
this is better written as an assertion
Benjamin Peterson <benjamin@python.org>
parents:
54904
diff
changeset
|
1828 assert(b->b_type == EXCEPT_HANDLER); |
|
b55a78b39bd5
this is better written as an assertion
Benjamin Peterson <benjamin@python.org>
parents:
54904
diff
changeset
|
1829 UNWIND_EXCEPT_HANDLER(b); |
|
b55a78b39bd5
this is better written as an assertion
Benjamin Peterson <benjamin@python.org>
parents:
54904
diff
changeset
|
1830 why = WHY_NOT; |
|
47594
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
1831 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1832 } |
|
40942
4b9d0dac79cc
You can no longer catch non-BaseException objects; TypeError is raised if such
Brett Cannon <bcannon@gmail.com>
parents:
40937
diff
changeset
|
1833 else if (PyExceptionClass_Check(v)) { |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1834 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
|
1835 u = POP(); |
| 5368 | 1836 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
|
1837 why = WHY_RERAISE; |
|
2872
d3b07ba3e12d
fix bogus DECREF in finally clause
Guido van Rossum <guido@python.org>
parents:
2866
diff
changeset
|
1838 break; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1839 } |
| 5368 | 1840 else if (v != Py_None) { |
| 1841 PyErr_SetString(PyExc_SystemError, | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1842 "'finally' pops bad exception"); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1843 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1844 } |
| 5368 | 1845 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1846 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1847 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1848 TARGET(LOAD_BUILD_CLASS) |
|
41226
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
40946
diff
changeset
|
1849 x = PyDict_GetItemString(f->f_builtins, |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
40946
diff
changeset
|
1850 "__build_class__"); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
40946
diff
changeset
|
1851 if (x == NULL) { |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
40946
diff
changeset
|
1852 PyErr_SetString(PyExc_ImportError, |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
40946
diff
changeset
|
1853 "__build_class__ not found"); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
40946
diff
changeset
|
1854 break; |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
40946
diff
changeset
|
1855 } |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
40946
diff
changeset
|
1856 Py_INCREF(x); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
40946
diff
changeset
|
1857 PUSH(x); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1858 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1859 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1860 TARGET(STORE_NAME) |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1861 w = GETITEM(names, oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1862 v = POP(); |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1863 if ((x = f->f_locals) != NULL) { |
|
32890
b8c2aa2be19a
Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents:
32531
diff
changeset
|
1864 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
|
1865 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
|
1866 else |
|
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
1867 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
|
1868 Py_DECREF(v); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1869 if (err == 0) DISPATCH(); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1870 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1871 } |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1872 PyErr_Format(PyExc_SystemError, |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
1873 "no locals found when storing %R", w); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1874 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1875 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1876 TARGET(DELETE_NAME) |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1877 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
|
1878 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
|
1879 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
|
1880 format_exc_check_arg(PyExc_NameError, |
|
43418
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
1881 NAME_ERROR_MSG, |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
1882 w); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1883 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1884 } |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
1885 PyErr_Format(PyExc_SystemError, |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
1886 "no locals when deleting %R", w); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1887 break; |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
1888 |
|
28304
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
1889 PREDICTED_WITH_ARG(UNPACK_SEQUENCE); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1890 TARGET(UNPACK_SEQUENCE) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1891 v = POP(); |
|
43418
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
1892 if (PyTuple_CheckExact(v) && |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
1893 PyTuple_GET_SIZE(v) == oparg) { |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
1894 PyObject **items = \ |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
1895 ((PyTupleObject *)v)->ob_item; |
|
31630
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1896 while (oparg--) { |
|
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1897 w = items[oparg]; |
|
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1898 Py_INCREF(w); |
|
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1899 PUSH(w); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1900 } |
|
31880
4c6fdeb8e2e0
Use continue instead of break whereever possible.
Raymond Hettinger <python@rcn.com>
parents:
31879
diff
changeset
|
1901 Py_DECREF(v); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1902 DISPATCH(); |
|
43418
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
1903 } else if (PyList_CheckExact(v) && |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
1904 PyList_GET_SIZE(v) == oparg) { |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
1905 PyObject **items = \ |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
1906 ((PyListObject *)v)->ob_item; |
|
31630
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1907 while (oparg--) { |
|
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1908 w = items[oparg]; |
|
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1909 Py_INCREF(w); |
|
b4e4dbd24fe7
Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents:
31618
diff
changeset
|
1910 PUSH(w); |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1911 } |
|
41699
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
1912 } else if (unpack_iterable(v, oparg, -1, |
|
43418
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
1913 stack_pointer + oparg)) { |
|
54908
aa950f7962fd
Merged revisions 73614-73615 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54905
diff
changeset
|
1914 STACKADJ(oparg); |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41464
diff
changeset
|
1915 } else { |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41464
diff
changeset
|
1916 /* 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
|
1917 why = WHY_EXCEPTION; |
|
20183
c6b6189a8397
SF bug [#466173] unpack TypeError unclear
Tim Peters <tim.peters@gmail.com>
parents:
20114
diff
changeset
|
1918 } |
| 5368 | 1919 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1920 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1921 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1922 TARGET(UNPACK_EX) |
|
41699
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
1923 { |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
1924 int totalargs = 1 + (oparg & 0xFF) + (oparg >> 8); |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
1925 v = POP(); |
|
48574
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
1926 |
|
41699
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
1927 if (unpack_iterable(v, oparg & 0xFF, oparg >> 8, |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
1928 stack_pointer + totalargs)) { |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
1929 stack_pointer += totalargs; |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
1930 } else { |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
1931 why = WHY_EXCEPTION; |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
1932 } |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
1933 Py_DECREF(v); |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
1934 break; |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
1935 } |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
1936 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1937 TARGET(STORE_ATTR) |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1938 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
|
1939 v = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1940 u = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1941 STACKADJ(-2); |
| 5368 | 1942 err = PyObject_SetAttr(v, w, u); /* v.w = u */ |
| 1943 Py_DECREF(v); | |
| 1944 Py_DECREF(u); | |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1945 if (err == 0) DISPATCH(); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1946 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1947 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1948 TARGET(DELETE_ATTR) |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1949 w = GETITEM(names, oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1950 v = POP(); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1951 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
|
1952 /* del v.w */ |
| 5368 | 1953 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1954 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1955 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1956 TARGET(STORE_GLOBAL) |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1957 w = GETITEM(names, oparg); |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1958 v = POP(); |
| 5368 | 1959 err = PyDict_SetItem(f->f_globals, w, v); |
| 1960 Py_DECREF(v); | |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1961 if (err == 0) DISPATCH(); |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1962 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1963 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1964 TARGET(DELETE_GLOBAL) |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1965 w = GETITEM(names, oparg); |
| 5368 | 1966 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
|
1967 format_exc_check_arg( |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1968 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
|
1969 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1970 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
1971 TARGET(LOAD_NAME) |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1972 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
|
1973 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
|
1974 PyErr_Format(PyExc_SystemError, |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
1975 "no locals when loading %R", w); |
|
50112
abf815b80b5d
Merged revisions 67666,67685 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
50104
diff
changeset
|
1976 why = WHY_EXCEPTION; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1977 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1978 } |
|
32900
ac73f6662e11
Fix for the unfortunate fact that PyDict_GetItem and PyObject_GetItem
Michael W. Hudson <mwh@python.net>
parents:
32890
diff
changeset
|
1979 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
|
1980 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
|
1981 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
|
1982 } |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
1983 else { |
|
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
1984 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
|
1985 if (x == NULL && PyErr_Occurred()) { |
|
43418
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
1986 if (!PyErr_ExceptionMatches( |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
1987 PyExc_KeyError)) |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
1988 break; |
|
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
1989 PyErr_Clear(); |
|
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
1990 } |
|
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
32421
diff
changeset
|
1991 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1992 if (x == NULL) { |
| 5368 | 1993 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
|
1994 if (x == NULL) { |
| 5368 | 1995 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
|
1996 if (x == NULL) { |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1997 format_exc_check_arg( |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1998 PyExc_NameError, |
|
43418
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
1999 NAME_ERROR_MSG, w); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2000 break; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2001 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2002 } |
|
32900
ac73f6662e11
Fix for the unfortunate fact that PyDict_GetItem and PyObject_GetItem
Michael W. Hudson <mwh@python.net>
parents:
32890
diff
changeset
|
2003 Py_INCREF(x); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2004 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2005 PUSH(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2006 DISPATCH(); |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2007 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2008 TARGET(LOAD_GLOBAL) |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
2009 w = GETITEM(names, oparg); |
| 42860 | 2010 if (PyUnicode_CheckExact(w)) { |
|
24900
2cdf3d0dfabd
Add a warning comment to the LOAD_GLOBAL inline code.
Guido van Rossum <guido@python.org>
parents:
24899
diff
changeset
|
2011 /* 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
|
2012 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
|
2013 Do not try this at home. */ |
| 42860 | 2014 long hash = ((PyUnicodeObject *)w)->hash; |
|
24899
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2015 if (hash != -1) { |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2016 PyDictObject *d; |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
2017 PyDictEntry *e; |
|
24899
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2018 d = (PyDictObject *)(f->f_globals); |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
2019 e = d->ma_lookup(d, w, hash); |
|
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
2020 if (e == NULL) { |
|
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
2021 x = NULL; |
|
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
2022 break; |
|
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
2023 } |
|
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
2024 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
|
2025 if (x != NULL) { |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2026 Py_INCREF(x); |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2027 PUSH(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2028 DISPATCH(); |
|
24899
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2029 } |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2030 d = (PyDictObject *)(f->f_builtins); |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
2031 e = d->ma_lookup(d, w, hash); |
|
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
2032 if (e == NULL) { |
|
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
2033 x = NULL; |
|
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
2034 break; |
|
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
2035 } |
|
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
2036 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
|
2037 if (x != NULL) { |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2038 Py_INCREF(x); |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2039 PUSH(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2040 DISPATCH(); |
|
24899
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2041 } |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2042 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
|
2043 } |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2044 } |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2045 /* This is the un-inlined version of the code above */ |
| 5368 | 2046 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
|
2047 if (x == NULL) { |
| 5368 | 2048 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
|
2049 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
|
2050 load_global_error: |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
2051 format_exc_check_arg( |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2052 PyExc_NameError, |
|
24899
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
2053 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
|
2054 break; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2055 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2056 } |
| 5368 | 2057 Py_INCREF(x); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2058 PUSH(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2059 DISPATCH(); |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2060 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2061 TARGET(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
|
2062 x = GETLOCAL(oparg); |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2063 if (x != NULL) { |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2064 SETLOCAL(oparg, NULL); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2065 DISPATCH(); |
|
8318
ec87b62466d3
DELETE_FAST should issue an exception when the local variable is undefined.
Guido van Rossum <guido@python.org>
parents:
7982
diff
changeset
|
2066 } |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2067 format_exc_check_arg( |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2068 PyExc_UnboundLocalError, |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2069 UNBOUNDLOCAL_ERROR_MSG, |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2070 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
|
2071 ); |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2072 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2073 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2074 TARGET(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
|
2075 x = freevars[oparg]; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2076 Py_INCREF(x); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2077 PUSH(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2078 if (x != NULL) DISPATCH(); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2079 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2080 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2081 TARGET(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
|
2082 x = freevars[oparg]; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2083 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
|
2084 if (w != NULL) { |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2085 PUSH(w); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2086 DISPATCH(); |
|
31878
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2087 } |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2088 err = -1; |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2089 /* 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
|
2090 if (PyErr_Occurred()) |
|
16453
2e3dd62ceac5
SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16398
diff
changeset
|
2091 break; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2092 if (oparg < PyTuple_GET_SIZE(co->co_cellvars)) { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2093 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
|
2094 oparg); |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2095 format_exc_check_arg( |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2096 PyExc_UnboundLocalError, |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2097 UNBOUNDLOCAL_ERROR_MSG, |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2098 v); |
|
26ee1b3eb345
Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents:
31875
diff
changeset
|
2099 } else { |
|
43418
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
2100 v = PyTuple_GET_ITEM(co->co_freevars, oparg - |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
2101 PyTuple_GET_SIZE(co->co_cellvars)); |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
2102 format_exc_check_arg(PyExc_NameError, |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
2103 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
|
2104 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2105 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2106 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2107 TARGET(STORE_DEREF) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2108 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
|
2109 x = freevars[oparg]; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2110 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
|
2111 Py_DECREF(w); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2112 DISPATCH(); |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2113 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2114 TARGET(BUILD_TUPLE) |
| 5368 | 2115 x = PyTuple_New(oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2116 if (x != NULL) { |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
2117 for (; --oparg >= 0;) { |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2118 w = POP(); |
| 5368 | 2119 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
|
2120 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2121 PUSH(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2122 DISPATCH(); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2123 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2124 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2125 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2126 TARGET(BUILD_LIST) |
| 5368 | 2127 x = PyList_New(oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2128 if (x != NULL) { |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
2129 for (; --oparg >= 0;) { |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2130 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
|
2131 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
|
2132 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2133 PUSH(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2134 DISPATCH(); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2135 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2136 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2137 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2138 TARGET(BUILD_SET) |
|
39693
d0b83c4630c0
SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents:
39678
diff
changeset
|
2139 x = PySet_New(NULL); |
|
d0b83c4630c0
SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents:
39678
diff
changeset
|
2140 if (x != NULL) { |
|
d0b83c4630c0
SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents:
39678
diff
changeset
|
2141 for (; --oparg >= 0;) { |
|
d0b83c4630c0
SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents:
39678
diff
changeset
|
2142 w = POP(); |
|
d0b83c4630c0
SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents:
39678
diff
changeset
|
2143 if (err == 0) |
|
d0b83c4630c0
SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents:
39678
diff
changeset
|
2144 err = PySet_Add(x, w); |
|
d0b83c4630c0
SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents:
39678
diff
changeset
|
2145 Py_DECREF(w); |
|
d0b83c4630c0
SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents:
39678
diff
changeset
|
2146 } |
|
d0b83c4630c0
SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents:
39678
diff
changeset
|
2147 if (err != 0) { |
|
d0b83c4630c0
SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents:
39678
diff
changeset
|
2148 Py_DECREF(x); |
|
d0b83c4630c0
SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents:
39678
diff
changeset
|
2149 break; |
|
d0b83c4630c0
SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents:
39678
diff
changeset
|
2150 } |
|
d0b83c4630c0
SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents:
39678
diff
changeset
|
2151 PUSH(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2152 DISPATCH(); |
|
39693
d0b83c4630c0
SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents:
39678
diff
changeset
|
2153 } |
|
d0b83c4630c0
SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents:
39678
diff
changeset
|
2154 break; |
|
d0b83c4630c0
SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents:
39678
diff
changeset
|
2155 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2156 TARGET(BUILD_MAP) |
|
44349
4dc01402d78a
Merged revisions 59541-59561 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44310
diff
changeset
|
2157 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
|
2158 PUSH(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2159 if (x != NULL) DISPATCH(); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2160 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2161 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2162 TARGET(STORE_MAP) |
|
44349
4dc01402d78a
Merged revisions 59541-59561 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44310
diff
changeset
|
2163 w = TOP(); /* key */ |
|
4dc01402d78a
Merged revisions 59541-59561 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44310
diff
changeset
|
2164 u = SECOND(); /* value */ |
|
4dc01402d78a
Merged revisions 59541-59561 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44310
diff
changeset
|
2165 v = THIRD(); /* dict */ |
|
4dc01402d78a
Merged revisions 59541-59561 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44310
diff
changeset
|
2166 STACKADJ(-2); |
|
4dc01402d78a
Merged revisions 59541-59561 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44310
diff
changeset
|
2167 assert (PyDict_CheckExact(v)); |
|
4dc01402d78a
Merged revisions 59541-59561 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44310
diff
changeset
|
2168 err = PyDict_SetItem(v, w, u); /* v[w] = u */ |
|
4dc01402d78a
Merged revisions 59541-59561 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44310
diff
changeset
|
2169 Py_DECREF(u); |
|
4dc01402d78a
Merged revisions 59541-59561 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44310
diff
changeset
|
2170 Py_DECREF(w); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2171 if (err == 0) DISPATCH(); |
|
44349
4dc01402d78a
Merged revisions 59541-59561 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44310
diff
changeset
|
2172 break; |
|
4dc01402d78a
Merged revisions 59541-59561 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44310
diff
changeset
|
2173 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2174 TARGET(MAP_ADD) |
|
50211
2ee4653927f7
Merged revisions 67818 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50112
diff
changeset
|
2175 w = TOP(); /* key */ |
|
2ee4653927f7
Merged revisions 67818 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50112
diff
changeset
|
2176 u = SECOND(); /* value */ |
|
2ee4653927f7
Merged revisions 67818 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50112
diff
changeset
|
2177 STACKADJ(-2); |
|
2ee4653927f7
Merged revisions 67818 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50112
diff
changeset
|
2178 v = stack_pointer[-oparg]; /* dict */ |
|
2ee4653927f7
Merged revisions 67818 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50112
diff
changeset
|
2179 assert (PyDict_CheckExact(v)); |
|
2ee4653927f7
Merged revisions 67818 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50112
diff
changeset
|
2180 err = PyDict_SetItem(v, w, u); /* v[w] = u */ |
|
2ee4653927f7
Merged revisions 67818 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50112
diff
changeset
|
2181 Py_DECREF(u); |
|
2ee4653927f7
Merged revisions 67818 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50112
diff
changeset
|
2182 Py_DECREF(w); |
|
2ee4653927f7
Merged revisions 67818 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50112
diff
changeset
|
2183 if (err == 0) { |
|
2ee4653927f7
Merged revisions 67818 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50112
diff
changeset
|
2184 PREDICT(JUMP_ABSOLUTE); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2185 DISPATCH(); |
|
50211
2ee4653927f7
Merged revisions 67818 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50112
diff
changeset
|
2186 } |
|
2ee4653927f7
Merged revisions 67818 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50112
diff
changeset
|
2187 break; |
|
2ee4653927f7
Merged revisions 67818 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50112
diff
changeset
|
2188 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2189 TARGET(LOAD_ATTR) |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
2190 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
|
2191 v = TOP(); |
| 5368 | 2192 x = PyObject_GetAttr(v, w); |
| 2193 Py_DECREF(v); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2194 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2195 if (x != NULL) DISPATCH(); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2196 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2197 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2198 TARGET(COMPARE_OP) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2199 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2200 v = TOP(); |
|
44156
fb84bd9500a4
Remove special-casing of integer operations, to stop
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
2201 x = cmp_outcome(oparg, v, w); |
| 5368 | 2202 Py_DECREF(v); |
| 2203 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2204 SET_TOP(x); |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2205 if (x == NULL) break; |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2206 PREDICT(POP_JUMP_IF_FALSE); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2207 PREDICT(POP_JUMP_IF_TRUE); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2208 DISPATCH(); |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2209 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2210 TARGET(IMPORT_NAME) |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
2211 w = GETITEM(names, oparg); |
| 5368 | 2212 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
|
2213 if (x == NULL) { |
| 5368 | 2214 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
|
2215 "__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
|
2216 break; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
2217 } |
|
44905
c0f048356c36
Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2218 Py_INCREF(x); |
|
36712
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2219 v = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2220 u = TOP(); |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43996
diff
changeset
|
2221 if (PyLong_AsLong(u) != -1 || PyErr_Occurred()) |
|
36712
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2222 w = PyTuple_Pack(5, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2223 w, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2224 f->f_globals, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2225 f->f_locals == NULL ? |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2226 Py_None : f->f_locals, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2227 v, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2228 u); |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2229 else |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2230 w = PyTuple_Pack(4, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2231 w, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2232 f->f_globals, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2233 f->f_locals == NULL ? |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2234 Py_None : f->f_locals, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2235 v); |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36702
diff
changeset
|
2236 Py_DECREF(v); |
| 5368 | 2237 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
|
2238 if (w == NULL) { |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2239 u = POP(); |
|
44905
c0f048356c36
Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2240 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
|
2241 x = NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
2242 break; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
2243 } |
|
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
|
2244 READ_TIMESTAMP(intr0); |
|
44905
c0f048356c36
Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2245 v = x; |
|
c0f048356c36
Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2246 x = PyEval_CallObject(v, w); |
|
c0f048356c36
Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2247 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
|
2248 READ_TIMESTAMP(intr1); |
| 5368 | 2249 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2250 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2251 if (x != NULL) DISPATCH(); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2252 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2253 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2254 TARGET(IMPORT_STAR) |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
2255 v = POP(); |
| 5368 | 2256 PyFrame_FastToLocals(f); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2257 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
|
2258 PyErr_SetString(PyExc_SystemError, |
|
16017
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15948
diff
changeset
|
2259 "no locals found during 'import *'"); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2260 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2261 } |
|
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
|
2262 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
|
2263 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
|
2264 READ_TIMESTAMP(intr1); |
| 5368 | 2265 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
|
2266 Py_DECREF(v); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2267 if (err == 0) DISPATCH(); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2268 break; |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
2269 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2270 TARGET(IMPORT_FROM) |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
2271 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
|
2272 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
|
2273 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
|
2274 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
|
2275 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
|
2276 PUSH(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2277 if (x != NULL) DISPATCH(); |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
2278 break; |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
2279 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2280 TARGET(JUMP_FORWARD) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2281 JUMPBY(oparg); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2282 FAST_DISPATCH(); |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2283 |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2284 PREDICTED_WITH_ARG(POP_JUMP_IF_FALSE); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2285 TARGET(POP_JUMP_IF_FALSE) |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2286 w = POP(); |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2287 if (w == Py_True) { |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2288 Py_DECREF(w); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2289 FAST_DISPATCH(); |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2290 } |
| 28077 | 2291 if (w == Py_False) { |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2292 Py_DECREF(w); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2293 JUMPTO(oparg); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2294 FAST_DISPATCH(); |
| 28077 | 2295 } |
| 2296 err = PyObject_IsTrue(w); | |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2297 Py_DECREF(w); |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2298 if (err > 0) |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2299 err = 0; |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2300 else if (err == 0) |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2301 JUMPTO(oparg); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2302 else |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2303 break; |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2304 DISPATCH(); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2305 |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2306 PREDICTED_WITH_ARG(POP_JUMP_IF_TRUE); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2307 TARGET(POP_JUMP_IF_TRUE) |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2308 w = POP(); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2309 if (w == Py_False) { |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2310 Py_DECREF(w); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2311 FAST_DISPATCH(); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2312 } |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2313 if (w == Py_True) { |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2314 Py_DECREF(w); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2315 JUMPTO(oparg); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2316 FAST_DISPATCH(); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2317 } |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2318 err = PyObject_IsTrue(w); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2319 Py_DECREF(w); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2320 if (err > 0) { |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2321 err = 0; |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2322 JUMPTO(oparg); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2323 } |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2324 else if (err == 0) |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2325 ; |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2326 else |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2327 break; |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2328 DISPATCH(); |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2329 |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2330 TARGET(JUMP_IF_FALSE_OR_POP) |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2331 w = TOP(); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2332 if (w == Py_True) { |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2333 STACKADJ(-1); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2334 Py_DECREF(w); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2335 FAST_DISPATCH(); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2336 } |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2337 if (w == Py_False) { |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2338 JUMPTO(oparg); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2339 FAST_DISPATCH(); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2340 } |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2341 err = PyObject_IsTrue(w); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2342 if (err > 0) { |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2343 STACKADJ(-1); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2344 Py_DECREF(w); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2345 err = 0; |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2346 } |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2347 else if (err == 0) |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2348 JUMPTO(oparg); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2349 else |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2350 break; |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2351 DISPATCH(); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2352 |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2353 TARGET(JUMP_IF_TRUE_OR_POP) |
| 28077 | 2354 w = TOP(); |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2355 if (w == Py_False) { |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2356 STACKADJ(-1); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2357 Py_DECREF(w); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2358 FAST_DISPATCH(); |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2359 } |
| 28077 | 2360 if (w == Py_True) { |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2361 JUMPTO(oparg); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2362 FAST_DISPATCH(); |
| 28077 | 2363 } |
| 2364 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
|
2365 if (err > 0) { |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2366 err = 0; |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2367 JUMPTO(oparg); |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2368 } |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2369 else if (err == 0) { |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2370 STACKADJ(-1); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2371 Py_DECREF(w); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51031
diff
changeset
|
2372 } |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2373 else |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2374 break; |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2375 DISPATCH(); |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2376 |
|
31649
243642bbd03f
LIST_APPEND is predicably followed by JUMP_ABSOLUTE.
Raymond Hettinger <python@rcn.com>
parents:
31647
diff
changeset
|
2377 PREDICTED_WITH_ARG(JUMP_ABSOLUTE); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2378 TARGET(JUMP_ABSOLUTE) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2379 JUMPTO(oparg); |
|
43815
85cf334b32c3
Merged revisions 58886-58929 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
2380 #if FAST_LOOPS |
|
85cf334b32c3
Merged revisions 58886-58929 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
2381 /* Enabling this path speeds-up all while and for-loops by bypassing |
|
85cf334b32c3
Merged revisions 58886-58929 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
2382 the per-loop checks for signals. By default, this should be turned-off |
|
85cf334b32c3
Merged revisions 58886-58929 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
2383 because it prevents detection of a control-break in tight loops like |
|
85cf334b32c3
Merged revisions 58886-58929 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
2384 "while 1: pass". Compile with this option turned-on when you need |
|
85cf334b32c3
Merged revisions 58886-58929 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
2385 the speed-up and do not need break checking inside tight loops (ones |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2386 that contain only instructions ending with FAST_DISPATCH). |
|
43815
85cf334b32c3
Merged revisions 58886-58929 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
2387 */ |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2388 FAST_DISPATCH(); |
|
43815
85cf334b32c3
Merged revisions 58886-58929 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
2389 #else |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2390 DISPATCH(); |
|
43815
85cf334b32c3
Merged revisions 58886-58929 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
2391 #endif |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2392 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2393 TARGET(GET_ITER) |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2394 /* 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
|
2395 v = TOP(); |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2396 x = PyObject_GetIter(v); |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2397 Py_DECREF(v); |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2398 if (x != NULL) { |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2399 SET_TOP(x); |
|
28304
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
2400 PREDICT(FOR_ITER); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2401 DISPATCH(); |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2402 } |
|
27243
3afbd55fb18f
Replaced POP() with STACKADJ(-1) on lines where the result wasn't used.
Raymond Hettinger <python@rcn.com>
parents:
27201
diff
changeset
|
2403 STACKADJ(-1); |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2404 break; |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2405 |
|
28304
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
2406 PREDICTED_WITH_ARG(FOR_ITER); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2407 TARGET(FOR_ITER) |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2408 /* before: [iter]; after: [iter, iter()] *or* [] */ |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2409 v = TOP(); |
|
31646
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2410 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
|
2411 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
|
2412 PUSH(x); |
|
28304
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
2413 PREDICT(STORE_FAST); |
|
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
2414 PREDICT(UNPACK_SEQUENCE); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2415 DISPATCH(); |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2416 } |
|
31646
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2417 if (PyErr_Occurred()) { |
|
43418
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
2418 if (!PyErr_ExceptionMatches( |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
2419 PyExc_StopIteration)) |
|
31646
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2420 break; |
|
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2421 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
|
2422 } |
|
31646
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2423 /* iterator ended normally */ |
|
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2424 x = v = POP(); |
|
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2425 Py_DECREF(v); |
|
83b0382e0d36
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents:
31630
diff
changeset
|
2426 JUMPBY(oparg); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2427 DISPATCH(); |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2428 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2429 TARGET(BREAK_LOOP) |
|
31647
d10c778af167
Move the code for BREAK and CONTINUE_LOOP to be near FOR_ITER.
Raymond Hettinger <python@rcn.com>
parents:
31646
diff
changeset
|
2430 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
|
2431 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
|
2432 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2433 TARGET(CONTINUE_LOOP) |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43996
diff
changeset
|
2434 retval = PyLong_FromLong(oparg); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2435 if (!retval) { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2436 x = NULL; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2437 break; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2438 } |
|
31647
d10c778af167
Move the code for BREAK and CONTINUE_LOOP to be near FOR_ITER.
Raymond Hettinger <python@rcn.com>
parents:
31646
diff
changeset
|
2439 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
|
2440 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
|
2441 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2442 TARGET_WITH_IMPL(SETUP_LOOP, _setup_finally) |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2443 TARGET_WITH_IMPL(SETUP_EXCEPT, _setup_finally) |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2444 TARGET(SETUP_FINALLY) |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2445 _setup_finally: |
|
43418
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
2446 /* NOTE: If you add any new block-setup opcodes that |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
2447 are not try/except/finally handlers, you may need |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
2448 to update the PyGen_NeedsFinalizing() function. |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
2449 */ |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2450 |
| 5368 | 2451 PyFrame_BlockSetup(f, opcode, INSTR_OFFSET() + oparg, |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2452 STACK_LEVEL()); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2453 DISPATCH(); |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2454 |
|
54889
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2455 TARGET(SETUP_WITH) |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2456 { |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2457 static PyObject *exit, *enter; |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2458 w = TOP(); |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2459 x = special_lookup(w, "__exit__", &exit); |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2460 if (!x) |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2461 break; |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2462 SET_TOP(x); |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2463 u = special_lookup(w, "__enter__", &enter); |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2464 Py_DECREF(w); |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2465 if (!u) { |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2466 x = NULL; |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2467 break; |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2468 } |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2469 x = PyObject_CallFunctionObjArgs(u, NULL); |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2470 Py_DECREF(u); |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2471 if (!x) |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2472 break; |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2473 /* Setup the finally block before pushing the result |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2474 of __enter__ on the stack. */ |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2475 PyFrame_BlockSetup(f, SETUP_FINALLY, INSTR_OFFSET() + oparg, |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2476 STACK_LEVEL()); |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2477 |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2478 PUSH(x); |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2479 DISPATCH(); |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2480 } |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2481 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2482 TARGET(WITH_CLEANUP) |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2483 { |
|
45773
832c820e9d14
Merged revisions 61239-61249,61252-61257,61260-61264,61269-61275,61278-61279,61285-61286,61288-61290,61298,61303-61305,61312-61314,61317,61329,61332,61344,61350-61351,61363-61376,61378-61379,61382-61383,61387-61388,61392,61395-61396,61402-61403 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45635
diff
changeset
|
2484 /* At the top of the stack are 1-3 values indicating |
|
832c820e9d14
Merged revisions 61239-61249,61252-61257,61260-61264,61269-61275,61278-61279,61285-61286,61288-61290,61298,61303-61305,61312-61314,61317,61329,61332,61344,61350-61351,61363-61376,61378-61379,61382-61383,61387-61388,61392,61395-61396,61402-61403 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45635
diff
changeset
|
2485 how/why we entered the finally clause: |
|
832c820e9d14
Merged revisions 61239-61249,61252-61257,61260-61264,61269-61275,61278-61279,61285-61286,61288-61290,61298,61303-61305,61312-61314,61317,61329,61332,61344,61350-61351,61363-61376,61378-61379,61382-61383,61387-61388,61392,61395-61396,61402-61403 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45635
diff
changeset
|
2486 - TOP = None |
|
832c820e9d14
Merged revisions 61239-61249,61252-61257,61260-61264,61269-61275,61278-61279,61285-61286,61288-61290,61298,61303-61305,61312-61314,61317,61329,61332,61344,61350-61351,61363-61376,61378-61379,61382-61383,61387-61388,61392,61395-61396,61402-61403 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45635
diff
changeset
|
2487 - (TOP, SECOND) = (WHY_{RETURN,CONTINUE}), retval |
|
832c820e9d14
Merged revisions 61239-61249,61252-61257,61260-61264,61269-61275,61278-61279,61285-61286,61288-61290,61298,61303-61305,61312-61314,61317,61329,61332,61344,61350-61351,61363-61376,61378-61379,61382-61383,61387-61388,61392,61395-61396,61402-61403 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45635
diff
changeset
|
2488 - TOP = WHY_*; no retval below it |
|
832c820e9d14
Merged revisions 61239-61249,61252-61257,61260-61264,61269-61275,61278-61279,61285-61286,61288-61290,61298,61303-61305,61312-61314,61317,61329,61332,61344,61350-61351,61363-61376,61378-61379,61382-61383,61387-61388,61392,61395-61396,61402-61403 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45635
diff
changeset
|
2489 - (TOP, SECOND, THIRD) = exc_info() |
| 54904 | 2490 (FOURTH, FITH, SIXTH) = previous exception for EXCEPT_HANDLER |
|
45773
832c820e9d14
Merged revisions 61239-61249,61252-61257,61260-61264,61269-61275,61278-61279,61285-61286,61288-61290,61298,61303-61305,61312-61314,61317,61329,61332,61344,61350-61351,61363-61376,61378-61379,61382-61383,61387-61388,61392,61395-61396,61402-61403 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45635
diff
changeset
|
2491 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
|
2492 In the last case, we must call |
|
45773
832c820e9d14
Merged revisions 61239-61249,61252-61257,61260-61264,61269-61275,61278-61279,61285-61286,61288-61290,61298,61303-61305,61312-61314,61317,61329,61332,61344,61350-61351,61363-61376,61378-61379,61382-61383,61387-61388,61392,61395-61396,61402-61403 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45635
diff
changeset
|
2493 EXIT(TOP, SECOND, THIRD) |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2494 otherwise we must call |
|
45773
832c820e9d14
Merged revisions 61239-61249,61252-61257,61260-61264,61269-61275,61278-61279,61285-61286,61288-61290,61298,61303-61305,61312-61314,61317,61329,61332,61344,61350-61351,61363-61376,61378-61379,61382-61383,61387-61388,61392,61395-61396,61402-61403 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45635
diff
changeset
|
2495 EXIT(None, None, None) |
|
832c820e9d14
Merged revisions 61239-61249,61252-61257,61260-61264,61269-61275,61278-61279,61285-61286,61288-61290,61298,61303-61305,61312-61314,61317,61329,61332,61344,61350-61351,61363-61376,61378-61379,61382-61383,61387-61388,61392,61395-61396,61402-61403 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45635
diff
changeset
|
2496 |
| 54904 | 2497 In the first two cases, we remove EXIT from the |
| 2498 stack, leaving the rest in the same order. In the | |
| 2499 third case, we shift the bottom 3 values of the | |
| 2500 stack down, and replace the empty spot with NULL. | |
|
36737
fa92fe15251a
Updates to the with-statement:
Guido van Rossum <guido@python.org>
parents:
36712
diff
changeset
|
2501 |
|
fa92fe15251a
Updates to the with-statement:
Guido van Rossum <guido@python.org>
parents:
36712
diff
changeset
|
2502 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
|
2503 *and* the function call returns a 'true' value, we |
| 54904 | 2504 push WHY_SILENCED onto the stack. END_FINALLY will |
| 2505 then not re-raise the exception. (But non-local | |
| 2506 gotos should still be resumed.) | |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2507 */ |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2508 |
|
54889
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2509 PyObject *exit_func; |
|
47594
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2510 u = TOP(); |
|
45773
832c820e9d14
Merged revisions 61239-61249,61252-61257,61260-61264,61269-61275,61278-61279,61285-61286,61288-61290,61298,61303-61305,61312-61314,61317,61329,61332,61344,61350-61351,61363-61376,61378-61379,61382-61383,61387-61388,61392,61395-61396,61402-61403 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45635
diff
changeset
|
2511 if (u == Py_None) { |
|
54889
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2512 POP(); |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2513 exit_func = TOP(); |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2514 SET_TOP(u); |
|
45773
832c820e9d14
Merged revisions 61239-61249,61252-61257,61260-61264,61269-61275,61278-61279,61285-61286,61288-61290,61298,61303-61305,61312-61314,61317,61329,61332,61344,61350-61351,61363-61376,61378-61379,61382-61383,61387-61388,61392,61395-61396,61402-61403 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45635
diff
changeset
|
2515 v = w = Py_None; |
|
832c820e9d14
Merged revisions 61239-61249,61252-61257,61260-61264,61269-61275,61278-61279,61285-61286,61288-61290,61298,61303-61305,61312-61314,61317,61329,61332,61344,61350-61351,61363-61376,61378-61379,61382-61383,61387-61388,61392,61395-61396,61402-61403 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45635
diff
changeset
|
2516 } |
|
832c820e9d14
Merged revisions 61239-61249,61252-61257,61260-61264,61269-61275,61278-61279,61285-61286,61288-61290,61298,61303-61305,61312-61314,61317,61329,61332,61344,61350-61351,61363-61376,61378-61379,61382-61383,61387-61388,61392,61395-61396,61402-61403 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45635
diff
changeset
|
2517 else if (PyLong_Check(u)) { |
|
54889
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2518 POP(); |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2519 switch(PyLong_AsLong(u)) { |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2520 case WHY_RETURN: |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2521 case WHY_CONTINUE: |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2522 /* Retval in TOP. */ |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2523 exit_func = SECOND(); |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2524 SET_SECOND(TOP()); |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2525 SET_TOP(u); |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2526 break; |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2527 default: |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2528 exit_func = TOP(); |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2529 SET_TOP(u); |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2530 break; |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2531 } |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2532 u = v = w = Py_None; |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2533 } |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2534 else { |
|
54903
544c5bad1607
correctly rearrange the stack in the exception case of WITH_CLEANUP
Benjamin Peterson <benjamin@python.org>
parents:
54889
diff
changeset
|
2535 PyObject *tp, *exc, *tb; |
|
544c5bad1607
correctly rearrange the stack in the exception case of WITH_CLEANUP
Benjamin Peterson <benjamin@python.org>
parents:
54889
diff
changeset
|
2536 PyTryBlock *block; |
|
54889
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2537 v = SECOND(); |
|
47594
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2538 w = THIRD(); |
|
54903
544c5bad1607
correctly rearrange the stack in the exception case of WITH_CLEANUP
Benjamin Peterson <benjamin@python.org>
parents:
54889
diff
changeset
|
2539 tp = FOURTH(); |
|
544c5bad1607
correctly rearrange the stack in the exception case of WITH_CLEANUP
Benjamin Peterson <benjamin@python.org>
parents:
54889
diff
changeset
|
2540 exc = stack_pointer[-5]; |
|
544c5bad1607
correctly rearrange the stack in the exception case of WITH_CLEANUP
Benjamin Peterson <benjamin@python.org>
parents:
54889
diff
changeset
|
2541 tb = stack_pointer[-6]; |
|
54889
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2542 exit_func = stack_pointer[-7]; |
|
54903
544c5bad1607
correctly rearrange the stack in the exception case of WITH_CLEANUP
Benjamin Peterson <benjamin@python.org>
parents:
54889
diff
changeset
|
2543 stack_pointer[-7] = tb; |
|
544c5bad1607
correctly rearrange the stack in the exception case of WITH_CLEANUP
Benjamin Peterson <benjamin@python.org>
parents:
54889
diff
changeset
|
2544 stack_pointer[-6] = exc; |
|
544c5bad1607
correctly rearrange the stack in the exception case of WITH_CLEANUP
Benjamin Peterson <benjamin@python.org>
parents:
54889
diff
changeset
|
2545 stack_pointer[-5] = tp; |
| 54904 | 2546 /* UNWIND_EXCEPT_BLOCK will pop this off. */ |
|
54903
544c5bad1607
correctly rearrange the stack in the exception case of WITH_CLEANUP
Benjamin Peterson <benjamin@python.org>
parents:
54889
diff
changeset
|
2547 FOURTH() = NULL; |
| 54904 | 2548 /* We just shifted the stack down, so we have |
| 2549 to tell the except handler block that the | |
| 2550 values are lower than it expects. */ | |
|
54903
544c5bad1607
correctly rearrange the stack in the exception case of WITH_CLEANUP
Benjamin Peterson <benjamin@python.org>
parents:
54889
diff
changeset
|
2551 block = &f->f_blockstack[f->f_iblock - 1]; |
|
544c5bad1607
correctly rearrange the stack in the exception case of WITH_CLEANUP
Benjamin Peterson <benjamin@python.org>
parents:
54889
diff
changeset
|
2552 assert(block->b_type == EXCEPT_HANDLER); |
|
544c5bad1607
correctly rearrange the stack in the exception case of WITH_CLEANUP
Benjamin Peterson <benjamin@python.org>
parents:
54889
diff
changeset
|
2553 block->b_level--; |
|
36926
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
2554 } |
|
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
2555 /* XXX Not the fastest way to call it... */ |
|
45773
832c820e9d14
Merged revisions 61239-61249,61252-61257,61260-61264,61269-61275,61278-61279,61285-61286,61288-61290,61298,61303-61305,61312-61314,61317,61329,61332,61344,61350-61351,61363-61376,61378-61379,61382-61383,61387-61388,61392,61395-61396,61402-61403 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45635
diff
changeset
|
2556 x = PyObject_CallFunctionObjArgs(exit_func, u, v, w, |
|
832c820e9d14
Merged revisions 61239-61249,61252-61257,61260-61264,61269-61275,61278-61279,61285-61286,61288-61290,61298,61303-61305,61312-61314,61317,61329,61332,61344,61350-61351,61363-61376,61378-61379,61382-61383,61387-61388,61392,61395-61396,61402-61403 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45635
diff
changeset
|
2557 NULL); |
|
47594
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2558 Py_DECREF(exit_func); |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2559 if (x == NULL) |
|
36926
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
2560 break; /* Go to error exit */ |
|
50104
48239f6209b0
Merged revisions 67688 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50045
diff
changeset
|
2561 |
|
48239f6209b0
Merged revisions 67688 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50045
diff
changeset
|
2562 if (u != Py_None) |
|
48239f6209b0
Merged revisions 67688 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50045
diff
changeset
|
2563 err = PyObject_IsTrue(x); |
|
48239f6209b0
Merged revisions 67688 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50045
diff
changeset
|
2564 else |
|
48239f6209b0
Merged revisions 67688 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50045
diff
changeset
|
2565 err = 0; |
|
48239f6209b0
Merged revisions 67688 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50045
diff
changeset
|
2566 Py_DECREF(x); |
|
48239f6209b0
Merged revisions 67688 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50045
diff
changeset
|
2567 |
|
48239f6209b0
Merged revisions 67688 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50045
diff
changeset
|
2568 if (err < 0) |
|
48239f6209b0
Merged revisions 67688 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50045
diff
changeset
|
2569 break; /* Go to error exit */ |
|
48239f6209b0
Merged revisions 67688 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50045
diff
changeset
|
2570 else if (err > 0) { |
|
48239f6209b0
Merged revisions 67688 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50045
diff
changeset
|
2571 err = 0; |
|
47594
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2572 /* There was an exception and a True return */ |
|
54889
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
2573 PUSH(PyLong_FromLong((long) WHY_SILENCED)); |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2574 } |
|
45635
882eba145119
Merged revisions 61189-61190,61192,61194-61195,61198-61199 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45017
diff
changeset
|
2575 PREDICT(END_FINALLY); |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2576 break; |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2577 } |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2578 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2579 TARGET(CALL_FUNCTION) |
|
32359
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
2580 { |
|
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
2581 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
|
2582 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
|
2583 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
|
2584 #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
|
2585 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
|
2586 #else |
|
32359
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
2587 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
|
2588 #endif |
|
32359
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
2589 stack_pointer = sp; |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
2590 PUSH(x); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
2591 if (x != NULL) |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2592 DISPATCH(); |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
2593 break; |
|
32359
e5bc947c44ca
Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents:
32301
diff
changeset
|
2594 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2595 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2596 TARGET_WITH_IMPL(CALL_FUNCTION_VAR, _call_function_var_kw) |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2597 TARGET_WITH_IMPL(CALL_FUNCTION_KW, _call_function_var_kw) |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2598 TARGET(CALL_FUNCTION_VAR_KW) |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2599 _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
|
2600 { |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2601 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
|
2602 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
|
2603 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
|
2604 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
|
2605 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
|
2606 PCALL(PCALL_ALL); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2607 if (flags & CALL_FLAG_VAR) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2608 n++; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2609 if (flags & CALL_FLAG_KW) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2610 n++; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2611 pfunc = stack_pointer - n - 1; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2612 func = *pfunc; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2613 |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2614 if (PyMethod_Check(func) |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2615 && PyMethod_GET_SELF(func) != NULL) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2616 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
|
2617 Py_INCREF(self); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2618 func = PyMethod_GET_FUNCTION(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2619 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
|
2620 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
|
2621 *pfunc = self; |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2622 na++; |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2623 n++; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2624 } else |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2625 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
|
2626 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
|
2627 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
|
2628 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
|
2629 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
|
2630 stack_pointer = sp; |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2631 Py_DECREF(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2632 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2633 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
|
2634 w = POP(); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2635 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
|
2636 } |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2637 PUSH(x); |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2638 if (x != NULL) |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2639 DISPATCH(); |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2640 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
|
2641 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2642 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2643 TARGET_WITH_IMPL(MAKE_CLOSURE, _make_function) |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2644 TARGET(MAKE_FUNCTION) |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2645 _make_function: |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
2646 { |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
2647 int posdefaults = oparg & 0xff; |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
2648 int kwdefaults = (oparg>>8) & 0xff; |
|
40529
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2649 int num_annotations = (oparg >> 16) & 0x7fff; |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
2650 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2651 v = POP(); /* code object */ |
| 5368 | 2652 x = PyFunction_New(v, f->f_globals); |
| 2653 Py_DECREF(v); | |
|
48574
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
2654 |
|
40943
c79e6234fb19
Two more patches by Tony Lownds (SF# 1607548).
Guido van Rossum <guido@python.org>
parents:
40942
diff
changeset
|
2655 if (x != NULL && opcode == MAKE_CLOSURE) { |
|
c79e6234fb19
Two more patches by Tony Lownds (SF# 1607548).
Guido van Rossum <guido@python.org>
parents:
40942
diff
changeset
|
2656 v = POP(); |
|
50112
abf815b80b5d
Merged revisions 67666,67685 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
50104
diff
changeset
|
2657 if (PyFunction_SetClosure(x, v) != 0) { |
|
abf815b80b5d
Merged revisions 67666,67685 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
50104
diff
changeset
|
2658 /* Can't happen unless bytecode is corrupt. */ |
|
abf815b80b5d
Merged revisions 67666,67685 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
50104
diff
changeset
|
2659 why = WHY_EXCEPTION; |
|
abf815b80b5d
Merged revisions 67666,67685 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
50104
diff
changeset
|
2660 } |
|
40943
c79e6234fb19
Two more patches by Tony Lownds (SF# 1607548).
Guido van Rossum <guido@python.org>
parents:
40942
diff
changeset
|
2661 Py_DECREF(v); |
|
c79e6234fb19
Two more patches by Tony Lownds (SF# 1607548).
Guido van Rossum <guido@python.org>
parents:
40942
diff
changeset
|
2662 } |
|
40529
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2663 |
|
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2664 if (x != NULL && num_annotations > 0) { |
|
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2665 Py_ssize_t name_ix; |
|
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2666 u = POP(); /* names of args with annotations */ |
|
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2667 v = PyDict_New(); |
|
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2668 if (v == NULL) { |
|
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2669 Py_DECREF(x); |
|
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2670 x = NULL; |
|
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2671 break; |
|
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2672 } |
|
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2673 name_ix = PyTuple_Size(u); |
|
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2674 assert(num_annotations == name_ix+1); |
|
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2675 while (name_ix > 0) { |
|
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2676 --name_ix; |
|
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2677 t = PyTuple_GET_ITEM(u, name_ix); |
|
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2678 w = POP(); |
|
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2679 /* XXX(nnorwitz): check for errors */ |
|
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2680 PyDict_SetItem(v, t, w); |
|
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2681 Py_DECREF(w); |
|
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2682 } |
|
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2683 |
|
50112
abf815b80b5d
Merged revisions 67666,67685 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
50104
diff
changeset
|
2684 if (PyFunction_SetAnnotations(x, v) != 0) { |
|
abf815b80b5d
Merged revisions 67666,67685 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
50104
diff
changeset
|
2685 /* Can't happen unless |
|
abf815b80b5d
Merged revisions 67666,67685 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
50104
diff
changeset
|
2686 PyFunction_SetAnnotations changes. */ |
|
abf815b80b5d
Merged revisions 67666,67685 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
50104
diff
changeset
|
2687 why = WHY_EXCEPTION; |
|
abf815b80b5d
Merged revisions 67666,67685 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
50104
diff
changeset
|
2688 } |
|
40529
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2689 Py_DECREF(v); |
|
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2690 Py_DECREF(u); |
|
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2691 } |
|
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2692 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2693 /* XXX Maybe this should be a separate opcode? */ |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
2694 if (x != NULL && posdefaults > 0) { |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
2695 v = PyTuple_New(posdefaults); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2696 if (v == NULL) { |
| 5368 | 2697 Py_DECREF(x); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2698 x = NULL; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2699 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2700 } |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
2701 while (--posdefaults >= 0) { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2702 w = POP(); |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
2703 PyTuple_SET_ITEM(v, posdefaults, w); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2704 } |
|
50112
abf815b80b5d
Merged revisions 67666,67685 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
50104
diff
changeset
|
2705 if (PyFunction_SetDefaults(x, v) != 0) { |
|
abf815b80b5d
Merged revisions 67666,67685 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
50104
diff
changeset
|
2706 /* Can't happen unless |
|
abf815b80b5d
Merged revisions 67666,67685 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
50104
diff
changeset
|
2707 PyFunction_SetDefaults changes. */ |
|
abf815b80b5d
Merged revisions 67666,67685 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
50104
diff
changeset
|
2708 why = WHY_EXCEPTION; |
|
abf815b80b5d
Merged revisions 67666,67685 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
50104
diff
changeset
|
2709 } |
| 5368 | 2710 Py_DECREF(v); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2711 } |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
2712 if (x != NULL && kwdefaults > 0) { |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
2713 v = PyDict_New(); |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
2714 if (v == NULL) { |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
2715 Py_DECREF(x); |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
2716 x = NULL; |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
2717 break; |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
2718 } |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
2719 while (--kwdefaults >= 0) { |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
2720 w = POP(); /* default value */ |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
2721 u = POP(); /* kw only arg name */ |
|
40529
54cd47788811
PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents:
40450
diff
changeset
|
2722 /* XXX(nnorwitz): check for errors */ |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
2723 PyDict_SetItem(v, u, w); |
|
40927
93f582803733
Fix a refleak in the MAKE_FUNCTION opcode in ceval.c.
Georg Brandl <georg@python.org>
parents:
40894
diff
changeset
|
2724 Py_DECREF(w); |
|
93f582803733
Fix a refleak in the MAKE_FUNCTION opcode in ceval.c.
Georg Brandl <georg@python.org>
parents:
40894
diff
changeset
|
2725 Py_DECREF(u); |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
2726 } |
|
50112
abf815b80b5d
Merged revisions 67666,67685 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
50104
diff
changeset
|
2727 if (PyFunction_SetKwDefaults(x, v) != 0) { |
|
abf815b80b5d
Merged revisions 67666,67685 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
50104
diff
changeset
|
2728 /* Can't happen unless |
|
abf815b80b5d
Merged revisions 67666,67685 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
50104
diff
changeset
|
2729 PyFunction_SetKwDefaults changes. */ |
|
abf815b80b5d
Merged revisions 67666,67685 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
50104
diff
changeset
|
2730 why = WHY_EXCEPTION; |
|
abf815b80b5d
Merged revisions 67666,67685 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
50104
diff
changeset
|
2731 } |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
2732 Py_DECREF(v); |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
2733 } |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2734 PUSH(x); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2735 break; |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
2736 } |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2737 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2738 TARGET(BUILD_SLICE) |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2739 if (oparg == 3) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2740 w = POP(); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2741 else |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2742 w = NULL; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2743 v = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2744 u = TOP(); |
| 5018 | 2745 x = PySlice_New(u, v, w); |
| 5368 | 2746 Py_DECREF(u); |
| 2747 Py_DECREF(v); | |
| 2748 Py_XDECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2749 SET_TOP(x); |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2750 if (x != NULL) DISPATCH(); |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2751 break; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2752 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2753 TARGET(EXTENDED_ARG) |
|
14147
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
2754 opcode = NEXTOP(); |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
2755 oparg = oparg<<16 | NEXTARG(); |
|
14147
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
2756 goto dispatch_opcode; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2757 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2758 #ifdef USE_COMPUTED_GOTOS |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2759 _unknown_opcode: |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
50840
diff
changeset
|
2760 #endif |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2761 default: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2762 fprintf(stderr, |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2763 "XXX lineno: %d, opcode: %d\n", |
| 24844 | 2764 PyCode_Addr2Line(f->f_code, f->f_lasti), |
| 2765 opcode); | |
| 5368 | 2766 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
|
2767 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2768 break; |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2769 |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2770 #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
|
2771 } |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2772 #endif |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2773 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2774 } /* switch */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2775 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2776 on_error: |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2777 |
|
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
|
2778 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
|
2779 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2780 /* Quickly continue if no error occurred */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2781 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2782 if (why == WHY_NOT) { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2783 if (err == 0 && x != NULL) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2784 #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
|
2785 /* This check is expensive! */ |
| 5368 | 2786 if (PyErr_Occurred()) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2787 fprintf(stderr, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2788 "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
|
2789 else { |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
2790 #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
|
2791 READ_TIMESTAMP(loop1); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2792 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
|
2793 #ifdef CHECKEXC |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
2794 } |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
2795 #endif |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2796 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2797 why = WHY_EXCEPTION; |
| 5368 | 2798 x = Py_None; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2799 err = 0; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2800 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2801 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2802 /* Double-check exception status */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2803 |
|
31900
0265bf9912ea
Some (but not all) of the why code bitfield tests ran faster as
Raymond Hettinger <python@rcn.com>
parents:
31894
diff
changeset
|
2804 if (why == WHY_EXCEPTION || why == WHY_RERAISE) { |
| 5368 | 2805 if (!PyErr_Occurred()) { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2806 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
|
2807 "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
|
2808 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2809 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2810 } |
|
10363
4daab7a9f566
Always test for an error return (usually NULL or -1) without setting
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
2811 #ifdef CHECKEXC |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2812 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
|
2813 /* This check is expensive! */ |
| 5368 | 2814 if (PyErr_Occurred()) { |
|
45017
4725c84b0422
Merged revisions 60350-60363 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44905
diff
changeset
|
2815 char buf[128]; |
|
30861
c89fd7eaf875
Make undetected error on stack unwind a fatal error.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
30801
diff
changeset
|
2816 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
|
2817 "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
|
2818 Py_FatalError(buf); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2819 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2820 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2821 #endif |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2822 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2823 /* 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
|
2824 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2825 if (why == WHY_EXCEPTION) { |
| 5368 | 2826 PyTraceBack_Here(f); |
| 567 | 2827 |
|
20247
a4d328d50897
Rationalize the events passed to the profiler (no changes for the tracer).
Fred Drake <fdrake@acm.org>
parents:
20183
diff
changeset
|
2828 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
|
2829 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
|
2830 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
|
2831 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2832 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2833 /* 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
|
2834 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2835 if (why == WHY_RERAISE) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2836 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2837 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2838 /* Unwind stacks if a (pseudo) exception occurred */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2839 |
|
31462
d5c047807c69
SF patch #864059: optimize eval_frame
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2840 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
|
2841 while (why != WHY_NOT && f->f_iblock > 0) { |
| 5368 | 2842 PyTryBlock *b = PyFrame_BlockPop(f); |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2843 |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
2844 assert(why != WHY_YIELD); |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2845 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
|
2846 /* For a continue inside a try block, |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2847 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
|
2848 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
|
2849 b->b_level); |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2850 why = WHY_NOT; |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43996
diff
changeset
|
2851 JUMPTO(PyLong_AS_LONG(retval)); |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2852 Py_DECREF(retval); |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2853 break; |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2854 } |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2855 |
|
47594
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2856 if (b->b_type == EXCEPT_HANDLER) { |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2857 UNWIND_EXCEPT_HANDLER(b); |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2858 continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2859 } |
|
47594
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2860 UNWIND_BLOCK(b); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2861 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
|
2862 why = WHY_NOT; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2863 JUMPTO(b->b_handler); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2864 break; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2865 } |
|
47594
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2866 if (why == WHY_EXCEPTION && (b->b_type == SETUP_EXCEPT |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2867 || b->b_type == SETUP_FINALLY)) { |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2868 PyObject *exc, *val, *tb; |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2869 int handler = b->b_handler; |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2870 /* Beware, this invalidates all b->b_* fields */ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2871 PyFrame_BlockSetup(f, EXCEPT_HANDLER, -1, STACK_LEVEL()); |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2872 PUSH(tstate->exc_traceback); |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2873 PUSH(tstate->exc_value); |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2874 if (tstate->exc_type != NULL) { |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2875 PUSH(tstate->exc_type); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2876 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2877 else { |
|
47594
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2878 Py_INCREF(Py_None); |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2879 PUSH(Py_None); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2880 } |
|
47594
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2881 PyErr_Fetch(&exc, &val, &tb); |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2882 /* Make the raw exception data |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2883 available to the handler, |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2884 so a program can emulate the |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2885 Python main loop. */ |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2886 PyErr_NormalizeException( |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2887 &exc, &val, &tb); |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2888 PyException_SetTraceback(val, tb); |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2889 Py_INCREF(exc); |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2890 tstate->exc_type = exc; |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2891 Py_INCREF(val); |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2892 tstate->exc_value = val; |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2893 tstate->exc_traceback = tb; |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2894 if (tb == NULL) |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2895 tb = Py_None; |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2896 Py_INCREF(tb); |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2897 PUSH(tb); |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2898 PUSH(val); |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2899 PUSH(exc); |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2900 why = WHY_NOT; |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2901 JUMPTO(handler); |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2902 break; |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2903 } |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2904 if (b->b_type == SETUP_FINALLY) { |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2905 if (why & (WHY_RETURN | WHY_CONTINUE)) |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2906 PUSH(retval); |
|
212a1fee6bf9
#3021: Antoine Pitrou's Lexical exception handlers
Benjamin Peterson <benjamin@python.org>
parents:
47301
diff
changeset
|
2907 PUSH(PyLong_FromLong((long)why)); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2908 why = WHY_NOT; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2909 JUMPTO(b->b_handler); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2910 break; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2911 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2912 } /* unwind stack */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2913 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2914 /* 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
|
2915 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2916 if (why != WHY_NOT) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2917 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
|
2918 READ_TIMESTAMP(loop1); |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2919 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2920 } /* main loop */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2921 |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
2922 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
|
2923 /* 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
|
2924 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
|
2925 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
|
2926 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
|
2927 } |
|
97709fd8fda0
Fix for SF bug #489671 (Neil Norwitz): memory leak in test_richcmp.
Guido van Rossum <guido@python.org>
parents:
21252
diff
changeset
|
2928 |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
2929 if (why != WHY_RETURN) |
| 567 | 2930 retval = NULL; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2931 |
|
31462
d5c047807c69
SF patch #864059: optimize eval_frame
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2932 fast_yield: |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2933 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
|
2934 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
|
2935 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
|
2936 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
|
2937 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
|
2938 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
|
2939 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
|
2940 retval = NULL; |
|
700f08369092
Port from the Python 2.4 branch, patches for SF bug # 900092,
Barry Warsaw <barry@python.org>
parents:
35298
diff
changeset
|
2941 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
|
2942 } |
|
700f08369092
Port from the Python 2.4 branch, patches for SF bug # 900092,
Barry Warsaw <barry@python.org>
parents:
35298
diff
changeset
|
2943 } |
|
700f08369092
Port from the Python 2.4 branch, patches for SF bug # 900092,
Barry Warsaw <barry@python.org>
parents:
35298
diff
changeset
|
2944 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
|
2945 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
|
2946 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
|
2947 PyTrace_RETURN, NULL); |
| 567 | 2948 } |
| 2949 } | |
|
20247
a4d328d50897
Rationalize the events passed to the profiler (no changes for the tracer).
Fred Drake <fdrake@acm.org>
parents:
20183
diff
changeset
|
2950 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
|
2951 if (why == WHY_EXCEPTION) |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2952 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
|
2953 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
|
2954 PyTrace_RETURN, NULL); |
|
20257
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2955 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
|
2956 tstate->c_profileobj, f, |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2957 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
|
2958 Py_XDECREF(retval); |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2959 retval = NULL; |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2960 why = WHY_EXCEPTION; |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2961 } |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
2962 } |
| 567 | 2963 } |
|
5023
75c1ee882a4a
Kill all local variables on function return. This closes a gigantic
Guido van Rossum <guido@python.org>
parents:
5021
diff
changeset
|
2964 |
|
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
|
2965 /* pop frame */ |
|
43410
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
2966 exit_eval_frame: |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
2967 Py_LeaveRecursiveCall(); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2968 tstate->frame = f->f_back; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2969 |
| 567 | 2970 return retval; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2971 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2972 |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36580
diff
changeset
|
2973 /* 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
|
2974 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
|
2975 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
|
2976 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
2977 PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
2978 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
|
2979 PyObject **args, int argcount, PyObject **kws, int kwcount, |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
2980 PyObject **defs, int defcount, PyObject *kwdefs, PyObject *closure) |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2981 { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2982 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
|
2983 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
|
2984 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
|
2985 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
|
2986 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
|
2987 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2988 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
|
2989 PyErr_SetString(PyExc_SystemError, |
|
19198
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19158
diff
changeset
|
2990 "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
|
2991 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
|
2992 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2993 |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39536
diff
changeset
|
2994 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
|
2995 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
|
2996 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
|
2997 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
|
2998 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
|
2999 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3000 fastlocals = f->f_localsplus; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3001 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
|
3002 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3003 if (co->co_argcount > 0 || |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3004 co->co_kwonlyargcount > 0 || |
|
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
|
3005 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
|
3006 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
|
3007 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
|
3008 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
|
3009 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
|
3010 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
|
3011 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
|
3012 goto fail; |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3013 i = co->co_argcount + co->co_kwonlyargcount; |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3014 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
|
3015 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
|
3016 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
|
3017 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3018 if (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
|
3019 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
|
3020 PyErr_Format(PyExc_TypeError, |
|
43569
19319e70fc3e
Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents:
43418
diff
changeset
|
3021 "%U() takes %s %d " |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3022 "%spositional argument%s (%d given)", |
|
41878
089f449a20cd
Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents:
41824
diff
changeset
|
3023 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
|
3024 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
|
3025 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
|
3026 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
|
3027 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
|
3028 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
|
3029 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
|
3030 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3031 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
|
3032 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3033 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
|
3034 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
|
3035 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
|
3036 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
|
3037 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3038 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
|
3039 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
|
3040 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
|
3041 goto fail; |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3042 SETLOCAL(co->co_argcount + co->co_kwonlyargcount, u); |
|
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
|
3043 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
|
3044 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
|
3045 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
|
3046 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
|
3047 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3048 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3049 for (i = 0; i < kwcount; i++) { |
|
48574
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3050 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
|
3051 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
|
3052 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
|
3053 int j; |
| 42860 | 3054 if (keyword == NULL || !PyUnicode_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
|
3055 PyErr_Format(PyExc_TypeError, |
|
43569
19319e70fc3e
Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents:
43418
diff
changeset
|
3056 "%U() keywords must be strings", |
|
41878
089f449a20cd
Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents:
41824
diff
changeset
|
3057 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
|
3058 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
|
3059 } |
|
48574
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3060 /* Speed hack: do raw pointer compares. As names are |
|
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3061 normally interned this should almost always hit. */ |
|
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3062 co_varnames = PySequence_Fast_ITEMS(co->co_varnames); |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3063 for (j = 0; |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3064 j < co->co_argcount + co->co_kwonlyargcount; |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3065 j++) { |
|
48574
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3066 PyObject *nm = co_varnames[j]; |
|
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3067 if (nm == keyword) |
|
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3068 goto kw_found; |
|
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3069 } |
|
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3070 /* Slow fallback, just in case */ |
|
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3071 for (j = 0; |
|
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3072 j < co->co_argcount + co->co_kwonlyargcount; |
|
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3073 j++) { |
|
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3074 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
|
3075 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
|
3076 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
|
3077 if (cmp > 0) |
|
48574
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3078 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
|
3079 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
|
3080 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
|
3081 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3082 /* 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
|
3083 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
|
3084 goto fail; |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3085 if (j >= co->co_argcount + co->co_kwonlyargcount) { |
|
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
|
3086 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
|
3087 PyErr_Format(PyExc_TypeError, |
|
43569
19319e70fc3e
Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents:
43418
diff
changeset
|
3088 "%U() got an unexpected " |
|
41878
089f449a20cd
Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents:
41824
diff
changeset
|
3089 "keyword argument '%S'", |
|
089f449a20cd
Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents:
41824
diff
changeset
|
3090 co->co_name, |
|
089f449a20cd
Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents:
41824
diff
changeset
|
3091 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
|
3092 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
|
3093 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3094 PyDict_SetItem(kwdict, keyword, value); |
|
48574
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3095 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
|
3096 } |
|
48574
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3097 kw_found: |
|
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3098 if (GETLOCAL(j) != NULL) { |
|
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3099 PyErr_Format(PyExc_TypeError, |
|
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3100 "%U() got multiple " |
|
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3101 "values for keyword " |
|
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3102 "argument '%S'", |
|
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3103 co->co_name, |
|
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3104 keyword); |
|
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3105 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
|
3106 } |
|
48574
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3107 Py_INCREF(value); |
|
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3108 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
|
3109 } |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3110 if (co->co_kwonlyargcount > 0) { |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3111 for (i = co->co_argcount; |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3112 i < co->co_argcount + co->co_kwonlyargcount; |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3113 i++) { |
|
40381
259d26900861
Make it compile with older compilers.
Guido van Rossum <guido@python.org>
parents:
40215
diff
changeset
|
3114 PyObject *name, *def; |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3115 if (GETLOCAL(i) != NULL) |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3116 continue; |
|
40381
259d26900861
Make it compile with older compilers.
Guido van Rossum <guido@python.org>
parents:
40215
diff
changeset
|
3117 name = PyTuple_GET_ITEM(co->co_varnames, i); |
|
259d26900861
Make it compile with older compilers.
Guido van Rossum <guido@python.org>
parents:
40215
diff
changeset
|
3118 def = NULL; |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3119 if (kwdefs != NULL) |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3120 def = PyDict_GetItem(kwdefs, name); |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3121 if (def != NULL) { |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3122 Py_INCREF(def); |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3123 SETLOCAL(i, def); |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3124 continue; |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3125 } |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3126 PyErr_Format(PyExc_TypeError, |
|
43569
19319e70fc3e
Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents:
43418
diff
changeset
|
3127 "%U() needs keyword-only argument %S", |
|
41878
089f449a20cd
Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents:
41824
diff
changeset
|
3128 co->co_name, name); |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3129 goto fail; |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3130 } |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3131 } |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3132 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
|
3133 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
|
3134 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
|
3135 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
|
3136 PyErr_Format(PyExc_TypeError, |
|
43569
19319e70fc3e
Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents:
43418
diff
changeset
|
3137 "%U() takes %s %d " |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3138 "%spositional argument%s " |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3139 "(%d given)", |
|
41878
089f449a20cd
Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents:
41824
diff
changeset
|
3140 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
|
3141 ((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
|
3142 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
|
3143 : "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
|
3144 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
|
3145 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
|
3146 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
|
3147 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3148 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3149 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
|
3150 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
|
3151 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
|
3152 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
|
3153 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
|
3154 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
|
3155 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
|
3156 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
|
3157 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
|
3158 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3159 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3160 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3161 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3162 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
|
3163 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
|
3164 PyErr_Format(PyExc_TypeError, |
|
43569
19319e70fc3e
Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents:
43418
diff
changeset
|
3165 "%U() takes no arguments (%d given)", |
|
41878
089f449a20cd
Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents:
41824
diff
changeset
|
3166 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
|
3167 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
|
3168 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
|
3169 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3170 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3171 /* 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
|
3172 vars into frame. This isn't too efficient right now. */ |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3173 if (PyTuple_GET_SIZE(co->co_cellvars)) { |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
3174 int i, j, nargs, found; |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41969
diff
changeset
|
3175 Py_UNICODE *cellname, *argname; |
|
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
|
3176 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
|
3177 |
|
43996
b86e6bf7438f
fix #1409: cell variables were not initialized,
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43840
diff
changeset
|
3178 nargs = co->co_argcount + co->co_kwonlyargcount; |
|
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
|
3179 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
|
3180 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
|
3181 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
|
3182 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
|
3183 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
3184 /* Initialize each cell var, taking into account |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
3185 cell vars that are initialized from arguments. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
3186 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
3187 Should arrange for the compiler to put cellvars |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
3188 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
|
3189 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
|
3190 */ |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3191 for (i = 0; i < PyTuple_GET_SIZE(co->co_cellvars); ++i) { |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41969
diff
changeset
|
3192 cellname = PyUnicode_AS_UNICODE( |
|
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
|
3193 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
|
3194 found = 0; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35609
diff
changeset
|
3195 for (j = 0; j < nargs; j++) { |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41969
diff
changeset
|
3196 argname = PyUnicode_AS_UNICODE( |
|
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
|
3197 PyTuple_GET_ITEM(co->co_varnames, j)); |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41969
diff
changeset
|
3198 if (Py_UNICODE_strcmp(cellname, argname) == 0) { |
|
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
|
3199 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
|
3200 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
|
3201 goto fail; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3202 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
|
3203 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
|
3204 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
|
3205 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3206 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3207 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
|
3208 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
|
3209 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
|
3210 goto fail; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3211 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
|
3212 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3213 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3214 } |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3215 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
|
3216 int i; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3217 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
|
3218 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
|
3219 Py_INCREF(o); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3220 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
|
3221 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3222 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3223 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3224 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
|
3225 /* 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
|
3226 * 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
|
3227 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
|
3228 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
|
3229 |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3230 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
|
3231 |
|
18194
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
3232 /* 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
|
3233 * 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
|
3234 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
|
3235 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3236 |
|
43410
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
3237 retval = PyEval_EvalFrameEx(f,0); |
|
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
3238 |
|
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
3239 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
|
3240 |
|
21058
9df82c13c675
SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents:
21027
diff
changeset
|
3241 /* 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
|
3242 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
|
3243 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
|
3244 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
|
3245 */ |
|
9df82c13c675
SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents:
21027
diff
changeset
|
3246 assert(tstate != NULL); |
|
9df82c13c675
SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents:
21027
diff
changeset
|
3247 ++tstate->recursion_depth; |
|
43410
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
3248 Py_DECREF(f); |
|
21058
9df82c13c675
SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents:
21027
diff
changeset
|
3249 --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
|
3250 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
|
3251 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3252 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
3253 |
|
54889
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
3254 static PyObject * |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
3255 special_lookup(PyObject *o, char *meth, PyObject **cache) |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
3256 { |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
3257 PyObject *res; |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
3258 res = _PyObject_LookupSpecial(o, meth, cache); |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
3259 if (res == NULL && !PyErr_Occurred()) { |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
3260 PyErr_SetObject(PyExc_AttributeError, *cache); |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
3261 return NULL; |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
3262 } |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
3263 return res; |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
3264 } |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
3265 |
|
3aaf2e065db0
Merged revisions 72912,72920,72940 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54459
diff
changeset
|
3266 |
|
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
|
3267 /* 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
|
3268 This *consumes* a reference count to each of its arguments. */ |
|
31875
1fb2313ac3ce
Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents:
31874
diff
changeset
|
3269 static enum why_code |
|
43102
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
3270 do_raise(PyObject *exc, PyObject *cause) |
|
4667
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
3271 { |
|
47722
7ba7901dad7f
Implicit exception chaining via __context__ (PEP 3134).
Guido van Rossum <guido@python.org>
parents:
47594
diff
changeset
|
3272 PyObject *type = NULL, *value = NULL; |
|
43102
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
3273 |
|
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
3274 if (exc == NULL) { |
|
7946
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
3275 /* Reraise */ |
|
31797
846b3ee7e106
Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31796
diff
changeset
|
3276 PyThreadState *tstate = PyThreadState_GET(); |
|
47722
7ba7901dad7f
Implicit exception chaining via __context__ (PEP 3134).
Guido van Rossum <guido@python.org>
parents:
47594
diff
changeset
|
3277 PyObject *tb; |
|
43102
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
3278 type = tstate->exc_type; |
|
7946
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
3279 value = tstate->exc_value; |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
3280 tb = tstate->exc_traceback; |
| 43411 | 3281 if (type == Py_None) { |
| 3282 PyErr_SetString(PyExc_RuntimeError, | |
| 3283 "No active exception to reraise"); | |
| 3284 return WHY_EXCEPTION; | |
| 3285 } | |
| 3286 Py_XINCREF(type); | |
|
7946
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
3287 Py_XINCREF(value); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
3288 Py_XINCREF(tb); |
| 43411 | 3289 PyErr_Restore(type, value, tb); |
| 3290 return WHY_RERAISE; | |
|
7946
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
3291 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3292 |
|
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
|
3293 /* We support the following forms of raise: |
|
43102
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
3294 raise |
|
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
3295 raise <instance> |
|
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
3296 raise <type> */ |
|
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
3297 |
|
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
3298 if (PyExceptionClass_Check(exc)) { |
| 43411 | 3299 type = exc; |
| 3300 value = PyObject_CallObject(exc, NULL); | |
|
43102
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
3301 if (value == NULL) |
| 43411 | 3302 goto raise_error; |
| 3303 } | |
|
43102
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
3304 else if (PyExceptionInstance_Check(exc)) { |
|
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
3305 value = exc; |
|
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
3306 type = PyExceptionInstance_Class(exc); |
| 5368 | 3307 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
|
3308 } |
|
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
|
3309 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
|
3310 /* 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
|
3311 anyway, just not what you specified :-) */ |
| 43411 | 3312 Py_DECREF(exc); |
|
36988
49c6eb688906
Checkpoint. 218 tests are okay; 53 are failing. Done so far:
Guido van Rossum <guido@python.org>
parents:
36926
diff
changeset
|
3313 PyErr_SetString(PyExc_TypeError, |
| 43411 | 3314 "exceptions must derive from BaseException"); |
|
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
|
3315 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
|
3316 } |
|
43102
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
3317 |
| 43411 | 3318 if (cause) { |
| 3319 PyObject *fixed_cause; | |
| 3320 if (PyExceptionClass_Check(cause)) { | |
| 3321 fixed_cause = PyObject_CallObject(cause, NULL); | |
| 3322 if (fixed_cause == NULL) | |
| 3323 goto raise_error; | |
| 3324 Py_DECREF(cause); | |
| 3325 } | |
| 3326 else if (PyExceptionInstance_Check(cause)) { | |
| 3327 fixed_cause = cause; | |
| 3328 } | |
| 3329 else { | |
| 3330 PyErr_SetString(PyExc_TypeError, | |
| 3331 "exception causes must derive from " | |
| 3332 "BaseException"); | |
| 3333 goto raise_error; | |
| 3334 } | |
| 3335 PyException_SetCause(value, fixed_cause); | |
| 3336 } | |
|
43102
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
3337 |
|
47722
7ba7901dad7f
Implicit exception chaining via __context__ (PEP 3134).
Guido van Rossum <guido@python.org>
parents:
47594
diff
changeset
|
3338 PyErr_SetObject(type, value); |
|
7ba7901dad7f
Implicit exception chaining via __context__ (PEP 3134).
Guido van Rossum <guido@python.org>
parents:
47594
diff
changeset
|
3339 /* PyErr_SetObject incref's its arguments */ |
|
7ba7901dad7f
Implicit exception chaining via __context__ (PEP 3134).
Guido van Rossum <guido@python.org>
parents:
47594
diff
changeset
|
3340 Py_XDECREF(value); |
|
7ba7901dad7f
Implicit exception chaining via __context__ (PEP 3134).
Guido van Rossum <guido@python.org>
parents:
47594
diff
changeset
|
3341 Py_XDECREF(type); |
|
43102
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
3342 return WHY_EXCEPTION; |
|
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
3343 |
|
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
43100
diff
changeset
|
3344 raise_error: |
| 5368 | 3345 Py_XDECREF(value); |
| 3346 Py_XDECREF(type); | |
|
43188
386c22d93ab6
Fix refleaks exposed by test_raise.
Collin Winter <collinw@gmail.com>
parents:
43102
diff
changeset
|
3347 Py_XDECREF(cause); |
|
4667
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
3348 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
|
3349 } |
|
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
|
3350 |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3351 /* Iterate v argcnt times and store the results on the stack (via decreasing |
|
41699
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3352 sp). Return 1 for success, 0 if error. |
|
48574
d3d586019aff
Merged revisions 65240-65242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48516
diff
changeset
|
3353 |
|
41699
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3354 If argcntafter == -1, do a simple unpack. If it is >= 0, do an unpack |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3355 with a variable target. |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3356 */ |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3357 |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3358 static int |
|
41699
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3359 unpack_iterable(PyObject *v, int argcnt, int argcntafter, PyObject **sp) |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3360 { |
|
41699
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3361 int i = 0, j = 0; |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3362 Py_ssize_t ll = 0; |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3363 PyObject *it; /* iter(v) */ |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3364 PyObject *w; |
|
41699
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3365 PyObject *l = NULL; /* variable list */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3366 |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3367 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
|
3368 |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3369 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
|
3370 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
|
3371 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
|
3372 |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3373 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
|
3374 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
|
3375 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
|
3376 /* 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
|
3377 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
|
3378 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
|
3379 "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
|
3380 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
|
3381 } |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3382 goto Error; |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3383 } |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3384 *--sp = w; |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3385 } |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3386 |
|
41699
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3387 if (argcntafter == -1) { |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3388 /* We better have exhausted the iterator now. */ |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3389 w = PyIter_Next(it); |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3390 if (w == NULL) { |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3391 if (PyErr_Occurred()) |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3392 goto Error; |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3393 Py_DECREF(it); |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3394 return 1; |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3395 } |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3396 Py_DECREF(w); |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3397 PyErr_SetString(PyExc_ValueError, "too many values to unpack"); |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3398 goto Error; |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3399 } |
|
41699
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3400 |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3401 l = PySequence_List(it); |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3402 if (l == NULL) |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3403 goto Error; |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3404 *--sp = l; |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3405 i++; |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3406 |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3407 ll = PyList_GET_SIZE(l); |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3408 if (ll < argcntafter) { |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3409 PyErr_Format(PyExc_ValueError, "need more than %zd values to unpack", |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3410 argcnt + ll); |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3411 goto Error; |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3412 } |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3413 |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3414 /* Pop the "after-variable" args off the list. */ |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3415 for (j = argcntafter; j > 0; j--, i++) { |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3416 *--sp = PyList_GET_ITEM(l, ll - j); |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3417 } |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3418 /* Resize the list. */ |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44349
diff
changeset
|
3419 Py_SIZE(l) = ll - argcntafter; |
|
41699
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3420 Py_DECREF(it); |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3421 return 1; |
|
e16c8e5c5ca4
Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
3422 |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
3423 Error: |
|
6160
79592761b331
unpack_sequence(): In finally clause, watch out for Py_DECREF
Barry Warsaw <barry@python.org>
parents:
6157
diff
changeset
|
3424 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
|
3425 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
|
3426 Py_XDECREF(it); |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3427 return 0; |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3428 } |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3429 |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
3430 |
| 567 | 3431 #ifdef LLTRACE |
| 86 | 3432 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3433 prtrace(PyObject *v, char *str) |
| 69 | 3434 { |
| 86 | 3435 printf("%s ", str); |
| 5368 | 3436 if (PyObject_Print(v, stdout, 0) != 0) |
| 3437 PyErr_Clear(); /* Don't know what else to do */ | |
| 86 | 3438 printf("\n"); |
|
12579
978253542076
Add useless 'return 1' to prtrace() to shut up VC++.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
3439 return 1; |
| 69 | 3440 } |
| 86 | 3441 #endif |
| 69 | 3442 |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3443 static void |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3444 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
|
3445 { |
| 5368 | 3446 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
|
3447 int err; |
| 5368 | 3448 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
|
3449 if (value == NULL) { |
| 5368 | 3450 value = Py_None; |
| 3451 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
|
3452 } |
|
30683
3b59fa5d25b1
Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents:
29669
diff
changeset
|
3453 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
|
3454 if (arg == NULL) { |
| 5368 | 3455 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
|
3456 return; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
3457 } |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3458 err = call_trace(func, self, f, PyTrace_EXCEPTION, arg); |
| 5368 | 3459 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
|
3460 if (err == 0) |
| 5368 | 3461 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
|
3462 else { |
| 5368 | 3463 Py_XDECREF(type); |
| 3464 Py_XDECREF(value); | |
| 3465 Py_XDECREF(traceback); | |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3466 } |
|
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3467 } |
|
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3468 |
|
43840
73c8e27eb9ce
Correction for issue1265 (pdb bug with "with" statement).
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43815
diff
changeset
|
3469 static int |
|
20257
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3470 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
|
3471 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
|
3472 { |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3473 PyObject *type, *value, *traceback; |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3474 int err; |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3475 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
|
3476 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
|
3477 if (err == 0) |
|
43840
73c8e27eb9ce
Correction for issue1265 (pdb bug with "with" statement).
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43815
diff
changeset
|
3478 { |
|
20257
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3479 PyErr_Restore(type, value, traceback); |
|
43840
73c8e27eb9ce
Correction for issue1265 (pdb bug with "with" statement).
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43815
diff
changeset
|
3480 return 0; |
|
73c8e27eb9ce
Correction for issue1265 (pdb bug with "with" statement).
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43815
diff
changeset
|
3481 } |
|
20257
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3482 else { |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3483 Py_XDECREF(type); |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3484 Py_XDECREF(value); |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3485 Py_XDECREF(traceback); |
|
43840
73c8e27eb9ce
Correction for issue1265 (pdb bug with "with" statement).
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
43815
diff
changeset
|
3486 return -1; |
|
20257
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3487 } |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3488 } |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3489 |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3490 static int |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3491 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
|
3492 int what, PyObject *arg) |
| 567 | 3493 { |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3494 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
|
3495 int result; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3496 if (tstate->tracing) |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3497 return 0; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3498 tstate->tracing++; |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
3499 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
|
3500 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
|
3501 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
|
3502 || (tstate->c_profilefunc != NULL)); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3503 tstate->tracing--; |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3504 return result; |
| 567 | 3505 } |
| 3506 | |
|
28556
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3507 PyObject * |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3508 _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
|
3509 { |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3510 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
|
3511 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
|
3512 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
|
3513 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
|
3514 PyObject *result; |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3515 |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3516 tstate->tracing = 0; |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3517 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
|
3518 || (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
|
3519 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
|
3520 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
|
3521 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
|
3522 return result; |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3523 } |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3524 |
|
26110
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
3525 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
|
3526 maybe_call_line_trace(Py_tracefunc func, PyObject *obj, |
| 31768 | 3527 PyFrameObject *frame, int *instr_lb, int *instr_ub, |
| 3528 int *instr_prev) | |
| 24844 | 3529 { |
|
26110
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
3530 int result = 0; |
|
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
3531 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
3532 /* If the last instruction executed isn't in the current |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
3533 instruction window, reset the window. If the last |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
3534 instruction happens to fall at the start of a line or if it |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
3535 represents a jump backwards, call the trace function. |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
3536 */ |
|
25078
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24978
diff
changeset
|
3537 if ((frame->f_lasti < *instr_lb || frame->f_lasti >= *instr_ub)) { |
|
43410
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
3538 int line; |
|
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
3539 PyAddrPair bounds; |
|
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
3540 |
|
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
3541 line = PyCode_CheckLineNumber(frame->f_code, frame->f_lasti, |
|
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
3542 &bounds); |
|
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
3543 if (line >= 0) { |
|
25207
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25109
diff
changeset
|
3544 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
|
3545 result = call_trace(func, obj, frame, |
|
26110
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
3546 PyTrace_LINE, Py_None); |
|
43410
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
3547 } |
|
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
3548 *instr_lb = bounds.ap_lower; |
|
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
3549 *instr_ub = bounds.ap_upper; |
| 24844 | 3550 } |
| 31768 | 3551 else if (frame->f_lasti <= *instr_prev) { |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
3552 result = call_trace(func, obj, frame, PyTrace_LINE, Py_None); |
| 31768 | 3553 } |
| 3554 *instr_prev = frame->f_lasti; | |
|
26110
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
3555 return result; |
| 24844 | 3556 } |
| 3557 | |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3558 void |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3559 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
|
3560 { |
|
31797
846b3ee7e106
Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31796
diff
changeset
|
3561 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
|
3562 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
|
3563 Py_XINCREF(arg); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3564 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
|
3565 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
|
3566 /* 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
|
3567 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
|
3568 Py_XDECREF(temp); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3569 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
|
3570 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
|
3571 /* 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
|
3572 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
|
3573 } |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3574 |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3575 void |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3576 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
|
3577 { |
|
31797
846b3ee7e106
Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31796
diff
changeset
|
3578 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
|
3579 PyObject *temp = tstate->c_traceobj; |
|
50045
ba8fe3a40a5b
Merged revisions 67494 via svnmerge from
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
48986
diff
changeset
|
3580 _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
|
3581 Py_XINCREF(arg); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3582 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
|
3583 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
|
3584 /* 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
|
3585 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
|
3586 Py_XDECREF(temp); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3587 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
|
3588 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
|
3589 /* 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
|
3590 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
|
3591 || (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
|
3592 } |
|
4cb34314bd97
Instead of initializing & interning the strings passed to the profile
Fred Drake <fdrake@acm.org>
parents:
18128
diff
changeset
|
3593 |
| 5368 | 3594 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3595 PyEval_GetBuiltins(void) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3596 { |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
3597 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
|
3598 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
|
3599 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
|
3600 else |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3601 return current_frame->f_builtins; |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3602 } |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3603 |
| 5368 | 3604 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3605 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
|
3606 { |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
3607 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
|
3608 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
|
3609 return NULL; |
| 5368 | 3610 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
|
3611 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
|
3612 } |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3613 |
| 5368 | 3614 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3615 PyEval_GetGlobals(void) |
| 69 | 3616 { |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
3617 PyFrameObject *current_frame = PyEval_GetFrame(); |
| 86 | 3618 if (current_frame == NULL) |
| 3619 return NULL; | |
| 3620 else | |
| 3621 return current_frame->f_globals; | |
| 69 | 3622 } |
| 3623 | |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
3624 PyFrameObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3625 PyEval_GetFrame(void) |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
3626 { |
|
31797
846b3ee7e106
Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31796
diff
changeset
|
3627 PyThreadState *tstate = PyThreadState_GET(); |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
3628 return _PyThreadState_GetFrame(tstate); |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
3629 } |
|
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
3630 |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3631 int |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3632 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
|
3633 { |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
3634 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
|
3635 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
|
3636 |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3637 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
|
3638 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
|
3639 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
|
3640 if (compilerflags) { |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3641 result = 1; |
|
19350
5b6a6d7d44ae
ceval, PyEval_MergeCompilerFlags: wasn't merging in the
Tim Peters <tim.peters@gmail.com>
parents:
19301
diff
changeset
|
3642 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
|
3643 } |
|
22468
eebae4f60d05
Disable the parser hacks that enabled the "yield" keyword using a future
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22398
diff
changeset
|
3644 #if 0 /* future keyword */ |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
3645 if (codeflags & CO_GENERATOR_ALLOWED) { |
|
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
3646 result = 1; |
|
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
3647 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
|
3648 } |
|
22468
eebae4f60d05
Disable the parser hacks that enabled the "yield" keyword using a future
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22398
diff
changeset
|
3649 #endif |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3650 } |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3651 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
|
3652 } |
|
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
|
3653 |
| 86 | 3654 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3655 /* External interface to call any callable object. |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3656 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
|
3657 |
|
6206
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
3658 #undef PyEval_CallObject |
|
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
3659 /* for backward compatibility: export this interface */ |
|
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
3660 |
| 5368 | 3661 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3662 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
|
3663 { |
| 5368 | 3664 return PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3665 } |
|
6206
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
3666 #define PyEval_CallObject(func,arg) \ |
|
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
3667 PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3668 |
| 5368 | 3669 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3670 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
|
3671 { |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3672 PyObject *result; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3673 |
|
36877
e9a7a2784e17
SF #1444030: Fix several potential defects found by Coverity.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
36803
diff
changeset
|
3674 if (arg == NULL) { |
| 5368 | 3675 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
|
3676 if (arg == NULL) |
|
e9a7a2784e17
SF #1444030: Fix several potential defects found by Coverity.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
36803
diff
changeset
|
3677 return NULL; |
|
e9a7a2784e17
SF #1444030: Fix several potential defects found by Coverity.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
36803
diff
changeset
|
3678 } |
| 5368 | 3679 else if (!PyTuple_Check(arg)) { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3680 PyErr_SetString(PyExc_TypeError, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3681 "argument list must be a tuple"); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3682 return NULL; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3683 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3684 else |
| 5368 | 3685 Py_INCREF(arg); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3686 |
| 5368 | 3687 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
|
3688 PyErr_SetString(PyExc_TypeError, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3689 "keyword list must be a dictionary"); |
|
12440
d47460b1a679
Charles Waldman writes:
Guido van Rossum <guido@python.org>
parents:
12320
diff
changeset
|
3690 Py_DECREF(arg); |
|
2894
4095782c940e
empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents:
2872
diff
changeset
|
3691 return NULL; |
|
4095782c940e
empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents:
2872
diff
changeset
|
3692 } |
|
4095782c940e
empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents:
2872
diff
changeset
|
3693 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3694 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
|
3695 Py_DECREF(arg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3696 return result; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3697 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3698 |
|
35999
9541369b0dca
Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35745
diff
changeset
|
3699 const char * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3700 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
|
3701 { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3702 if (PyMethod_Check(func)) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3703 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
|
3704 else if (PyFunction_Check(func)) |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
48574
diff
changeset
|
3705 return _PyUnicode_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
|
3706 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
|
3707 return ((PyCFunctionObject*)func)->m_ml->ml_name; |
|
39536
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
3708 else |
|
17406
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3709 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
|
3710 } |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3711 |
|
35999
9541369b0dca
Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35745
diff
changeset
|
3712 const char * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3713 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
|
3714 { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3715 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
|
3716 return "()"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3717 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
|
3718 return "()"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3719 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
|
3720 return "()"; |
|
39536
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
3721 else |
|
17406
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3722 return " object"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3723 } |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3724 |
|
26141
6ce9228a3da2
Make private functions static so we don't pollute the namespace
Neal Norwitz <nnorwitz@gmail.com>
parents:
26110
diff
changeset
|
3725 static void |
|
24870
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3726 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
|
3727 { |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3728 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
|
3729 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
|
3730 "%.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
|
3731 ((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
|
3732 nargs); |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3733 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
|
3734 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
|
3735 "%.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
|
3736 ((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
|
3737 nargs); |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3738 } |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3739 |
|
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
|
3740 #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
|
3741 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
|
3742 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
|
3743 tstate->c_profileobj, \ |
|
77913be294b9
Massive performance improvement for C extension and builtin tracing code
Nicholas Bastin <nick.bastin@gmail.com>
parents:
32398
diff
changeset
|
3744 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
|
3745 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
|
3746 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
|
3747 } \ |
|
23dda92de993
clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents:
35345
diff
changeset
|
3748 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
|
3749 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
|
3750 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
|
3751 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
|
3752 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
|
3753 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
|
3754 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
|
3755 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
|
3756 /* 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
|
3757 } 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
|
3758 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
|
3759 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
|
3760 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
|
3761 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
|
3762 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
|
3763 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
|
3764 } \ |
|
23dda92de993
clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents:
35345
diff
changeset
|
3765 } \ |
|
31796
1c117dbb2def
Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31768
diff
changeset
|
3766 } \ |
|
32409
77913be294b9
Massive performance improvement for C extension and builtin tracing code
Nicholas Bastin <nick.bastin@gmail.com>
parents:
32398
diff
changeset
|
3767 } \ |
|
77913be294b9
Massive performance improvement for C extension and builtin tracing code
Nicholas Bastin <nick.bastin@gmail.com>
parents:
32398
diff
changeset
|
3768 } 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
|
3769 x = call; \ |
|
31796
1c117dbb2def
Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31768
diff
changeset
|
3770 } |
|
1c117dbb2def
Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31768
diff
changeset
|
3771 |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3772 static PyObject * |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
3773 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
|
3774 #ifdef WITH_TSC |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
3775 , 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
|
3776 #endif |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
32247
diff
changeset
|
3777 ) |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3778 { |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3779 int na = oparg & 0xff; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3780 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
|
3781 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
|
3782 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
|
3783 PyObject *func = *pfunc; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3784 PyObject *x, *w; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3785 |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3786 /* 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
|
3787 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
|
3788 */ |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3789 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
|
3790 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
|
3791 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
|
3792 |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3793 PCALL(PCALL_CFUNCTION); |
|
24870
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3794 if (flags & (METH_NOARGS | METH_O)) { |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3795 PyCFunction meth = PyCFunction_GET_FUNCTION(func); |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3796 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
|
3797 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
|
3798 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
|
3799 } |
|
24870
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3800 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
|
3801 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
|
3802 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
|
3803 Py_DECREF(arg); |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3804 } |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3805 else { |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3806 err_args(func, flags, na); |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3807 x = NULL; |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3808 } |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3809 } |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3810 else { |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3811 PyObject *callargs; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3812 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
|
3813 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
|
3814 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
|
3815 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
|
3816 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
|
3817 } |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3818 } else { |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3819 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
|
3820 /* 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
|
3821 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
|
3822 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
|
3823 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
|
3824 Py_INCREF(self); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3825 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
|
3826 Py_INCREF(func); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3827 Py_DECREF(*pfunc); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3828 *pfunc = self; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3829 na++; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3830 n++; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3831 } else |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3832 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
|
3833 READ_TIMESTAMP(*pintr0); |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3834 if (PyFunction_Check(func)) |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3835 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
|
3836 else |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3837 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
|
3838 READ_TIMESTAMP(*pintr1); |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3839 Py_DECREF(func); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3840 } |
|
31872
9f5fe6b23e59
Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents:
31797
diff
changeset
|
3841 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
3842 /* Clear the stack of the function object. Also removes |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
3843 the arguments in case they weren't consumed already |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
3844 (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
|
3845 */ |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3846 while ((*pp_stack) > pfunc) { |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3847 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
|
3848 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
|
3849 PCALL(PCALL_POP); |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3850 } |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3851 return x; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3852 } |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3853 |
|
24870
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3854 /* 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
|
3855 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
|
3856 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
|
3857 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
|
3858 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
|
3859 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
|
3860 done before evaluating the frame. |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3861 */ |
|
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 static PyObject * |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3864 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
|
3865 { |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3866 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
|
3867 PyObject *globals = PyFunction_GET_GLOBALS(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3868 PyObject *argdefs = PyFunction_GET_DEFAULTS(func); |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3869 PyObject *kwdefs = PyFunction_GET_KW_DEFAULTS(func); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3870 PyObject **d = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3871 int nd = 0; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3872 |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3873 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
|
3874 PCALL(PCALL_FAST_FUNCTION); |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3875 if (argdefs == NULL && co->co_argcount == n && |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3876 co->co_kwonlyargcount == 0 && 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
|
3877 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
|
3878 PyFrameObject *f; |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3879 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
|
3880 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
|
3881 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
|
3882 int i; |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3883 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3884 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
|
3885 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
|
3886 /* 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
|
3887 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
|
3888 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
|
3889 */ |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39536
diff
changeset
|
3890 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
|
3891 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
|
3892 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
|
3893 return NULL; |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3894 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3895 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
|
3896 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
|
3897 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3898 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
|
3899 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
|
3900 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
|
3901 } |
|
35298
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
35126
diff
changeset
|
3902 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
|
3903 ++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
|
3904 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
|
3905 --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
|
3906 return retval; |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3907 } |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3908 if (argdefs != NULL) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3909 d = &PyTuple_GET_ITEM(argdefs, 0); |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44349
diff
changeset
|
3910 nd = Py_SIZE(argdefs); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3911 } |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3912 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
|
3913 (PyObject *)NULL, (*pp_stack)-n, na, |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
3914 (*pp_stack)-2*nk, nk, d, nd, kwdefs, |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3915 PyFunction_GET_CLOSURE(func)); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3916 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3917 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3918 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
|
3919 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
|
3920 PyObject *func) |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3921 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3922 PyObject *kwdict = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3923 if (orig_kwdict == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3924 kwdict = PyDict_New(); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3925 else { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3926 kwdict = PyDict_Copy(orig_kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3927 Py_DECREF(orig_kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3928 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3929 if (kwdict == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3930 return NULL; |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
3931 while (--nk >= 0) { |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3932 int err; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3933 PyObject *value = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3934 PyObject *key = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3935 if (PyDict_GetItem(kwdict, key) != NULL) { |
|
43410
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
3936 PyErr_Format(PyExc_TypeError, |
|
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
3937 "%.200s%s got multiple values " |
|
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
3938 "for keyword argument '%.200s'", |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3939 PyEval_GetFuncName(func), |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3940 PyEval_GetFuncDesc(func), |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
48574
diff
changeset
|
3941 _PyUnicode_AsString(key)); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3942 Py_DECREF(key); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3943 Py_DECREF(value); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3944 Py_DECREF(kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3945 return NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3946 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3947 err = PyDict_SetItem(kwdict, key, value); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3948 Py_DECREF(key); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3949 Py_DECREF(value); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3950 if (err) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3951 Py_DECREF(kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3952 return NULL; |
|
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 return kwdict; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3956 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3957 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3958 static PyObject * |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3959 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
|
3960 PyObject ***pp_stack) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3961 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3962 PyObject *callargs, *w; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3963 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3964 callargs = PyTuple_New(nstack + nstar); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3965 if (callargs == NULL) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3966 return NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3967 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3968 if (nstar) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3969 int i; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3970 for (i = 0; i < nstar; i++) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3971 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
|
3972 Py_INCREF(a); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3973 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
|
3974 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3975 } |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
3976 while (--nstack >= 0) { |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3977 w = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3978 PyTuple_SET_ITEM(callargs, nstack, w); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3979 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3980 return callargs; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3981 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3982 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3983 static PyObject * |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3984 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
|
3985 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3986 PyObject *args = PyTuple_New(na); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3987 PyObject *w; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3988 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3989 if (args == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3990 return NULL; |
|
31894
310dd98ea064
Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents:
31880
diff
changeset
|
3991 while (--na >= 0) { |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3992 w = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3993 PyTuple_SET_ITEM(args, na, w); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3994 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3995 return args; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3996 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3997 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3998 static PyObject * |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3999 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
|
4000 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4001 PyObject *callargs = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4002 PyObject *kwdict = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4003 PyObject *result = NULL; |
|
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 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
|
4006 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
|
4007 if (kwdict == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4008 goto call_fail; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4009 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4010 callargs = load_args(pp_stack, na); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4011 if (callargs == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4012 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
|
4013 #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
|
4014 /* 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
|
4015 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
|
4016 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
|
4017 */ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4018 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
|
4019 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
|
4020 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
|
4021 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
|
4022 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
|
4023 PCALL(PCALL_TYPE); |
|
54459
4e96d7daf79f
Merged revisions 73064 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51872
diff
changeset
|
4024 else if (PyCFunction_Check(func)) |
|
4e96d7daf79f
Merged revisions 73064 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51872
diff
changeset
|
4025 PCALL(PCALL_CFUNCTION); |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4026 else |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4027 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
|
4028 #endif |
|
54459
4e96d7daf79f
Merged revisions 73064 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51872
diff
changeset
|
4029 if (PyCFunction_Check(func)) { |
|
4e96d7daf79f
Merged revisions 73064 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51872
diff
changeset
|
4030 PyThreadState *tstate = PyThreadState_GET(); |
|
4e96d7daf79f
Merged revisions 73064 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51872
diff
changeset
|
4031 C_TRACE(result, PyCFunction_Call(func, callargs, kwdict)); |
|
4e96d7daf79f
Merged revisions 73064 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51872
diff
changeset
|
4032 } |
|
4e96d7daf79f
Merged revisions 73064 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51872
diff
changeset
|
4033 else |
|
4e96d7daf79f
Merged revisions 73064 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51872
diff
changeset
|
4034 result = PyObject_Call(func, callargs, kwdict); |
| 43411 | 4035 call_fail: |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4036 Py_XDECREF(callargs); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4037 Py_XDECREF(kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4038 return result; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4039 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4040 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4041 static PyObject * |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4042 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
|
4043 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4044 int nstar = 0; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4045 PyObject *callargs = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4046 PyObject *stararg = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4047 PyObject *kwdict = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4048 PyObject *result = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4049 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4050 if (flags & CALL_FLAG_KW) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4051 kwdict = EXT_POP(*pp_stack); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4052 if (!PyDict_Check(kwdict)) { |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4053 PyObject *d; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4054 d = PyDict_New(); |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4055 if (d == NULL) |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4056 goto ext_call_fail; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4057 if (PyDict_Update(d, kwdict) != 0) { |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4058 Py_DECREF(d); |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4059 /* PyDict_Update raises attribute |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4060 * error (percolated from an attempt |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4061 * to get 'keys' attribute) instead of |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4062 * a type error if its second argument |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4063 * is not a mapping. |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4064 */ |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4065 if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4066 PyErr_Format(PyExc_TypeError, |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4067 "%.200s%.200s argument after ** " |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4068 "must be a mapping, not %.200s", |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4069 PyEval_GetFuncName(func), |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4070 PyEval_GetFuncDesc(func), |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4071 kwdict->ob_type->tp_name); |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4072 } |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4073 goto ext_call_fail; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4074 } |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4075 Py_DECREF(kwdict); |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4076 kwdict = d; |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4077 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4078 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4079 if (flags & CALL_FLAG_VAR) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4080 stararg = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4081 if (!PyTuple_Check(stararg)) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4082 PyObject *t = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4083 t = PySequence_Tuple(stararg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4084 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
|
4085 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
|
4086 PyErr_Format(PyExc_TypeError, |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4087 "%.200s%.200s argument after * " |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4088 "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
|
4089 PyEval_GetFuncName(func), |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4090 PyEval_GetFuncDesc(func), |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
4091 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
|
4092 } |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4093 goto ext_call_fail; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4094 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4095 Py_DECREF(stararg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4096 stararg = t; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4097 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4098 nstar = PyTuple_GET_SIZE(stararg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4099 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4100 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
|
4101 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
|
4102 if (kwdict == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4103 goto ext_call_fail; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4104 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4105 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
|
4106 if (callargs == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4107 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
|
4108 #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
|
4109 /* 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
|
4110 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
|
4111 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
|
4112 */ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4113 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
|
4114 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
|
4115 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
|
4116 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
|
4117 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
|
4118 PCALL(PCALL_TYPE); |
|
54459
4e96d7daf79f
Merged revisions 73064 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51872
diff
changeset
|
4119 else if (PyCFunction_Check(func)) |
|
4e96d7daf79f
Merged revisions 73064 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51872
diff
changeset
|
4120 PCALL(PCALL_CFUNCTION); |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4121 else |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
4122 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
|
4123 #endif |
|
54459
4e96d7daf79f
Merged revisions 73064 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51872
diff
changeset
|
4124 if (PyCFunction_Check(func)) { |
|
4e96d7daf79f
Merged revisions 73064 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51872
diff
changeset
|
4125 PyThreadState *tstate = PyThreadState_GET(); |
|
4e96d7daf79f
Merged revisions 73064 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51872
diff
changeset
|
4126 C_TRACE(result, PyCFunction_Call(func, callargs, kwdict)); |
|
4e96d7daf79f
Merged revisions 73064 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51872
diff
changeset
|
4127 } |
|
4e96d7daf79f
Merged revisions 73064 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51872
diff
changeset
|
4128 else |
|
4e96d7daf79f
Merged revisions 73064 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51872
diff
changeset
|
4129 result = PyObject_Call(func, callargs, kwdict); |
|
43410
b06b191b7cfa
Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43188
diff
changeset
|
4130 ext_call_fail: |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4131 Py_XDECREF(callargs); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4132 Py_XDECREF(kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4133 Py_XDECREF(stararg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4134 return result; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4135 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
4136 |
|
36882
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4137 /* 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
|
4138 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
|
4139 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
|
4140 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
|
4141 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
|
4142 */ |
|
21441
05ad7a69d933
_PyEval_SliceIndex(): explain why a NULL argument is allowed (thanks
Tim Peters <tim.peters@gmail.com>
parents:
21440
diff
changeset
|
4143 /* 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
|
4144 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
|
4145 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
|
4146 */ |
| 12614 | 4147 int |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36475
diff
changeset
|
4148 _PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi) |
| 69 | 4149 { |
|
21441
05ad7a69d933
_PyEval_SliceIndex(): explain why a NULL argument is allowed (thanks
Tim Peters <tim.peters@gmail.com>
parents:
21440
diff
changeset
|
4150 if (v != NULL) { |
|
36558
d3685f9b7b71
Remove size constraints in SLICE opcodes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
4151 Py_ssize_t x; |
|
44158
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44156
diff
changeset
|
4152 if (PyIndex_Check(v)) { |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39536
diff
changeset
|
4153 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
|
4154 if (x == -1 && PyErr_Occurred()) |
|
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4155 return 0; |
|
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4156 } |
|
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4157 else { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
4158 PyErr_SetString(PyExc_TypeError, |
|
36882
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4159 "slice indices must be integers or " |
|
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
4160 "None or have an __index__ method"); |
| 12614 | 4161 return 0; |
| 69 | 4162 } |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
4163 *pi = x; |
| 69 | 4164 } |
| 12614 | 4165 return 1; |
| 69 | 4166 } |
| 4167 | |
|
42132
863ed7cd45dc
Merged revisions 56020-56124 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42013
diff
changeset
|
4168 #define CANNOT_CATCH_MSG "catching classes that do not inherit from "\ |
|
40946
d976c9a63111
Make it so TypeError is raised if an instance of an object is put in an
Brett Cannon <bcannon@gmail.com>
parents:
40943
diff
changeset
|
4169 "BaseException is not allowed" |
|
40942
4b9d0dac79cc
You can no longer catch non-BaseException objects; TypeError is raised if such
Brett Cannon <bcannon@gmail.com>
parents:
40937
diff
changeset
|
4170 |
| 5368 | 4171 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4172 cmp_outcome(int op, register PyObject *v, register PyObject *w) |
| 69 | 4173 { |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
4174 int res = 0; |
| 69 | 4175 switch (op) { |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
4176 case PyCmp_IS: |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
4177 res = (v == w); |
|
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
4178 break; |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
4179 case PyCmp_IS_NOT: |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
4180 res = (v != w); |
| 86 | 4181 break; |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
4182 case PyCmp_IN: |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
4183 res = PySequence_Contains(w, v); |
|
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
4184 if (res < 0) |
|
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
4185 return NULL; |
|
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
4186 break; |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
4187 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
|
4188 res = PySequence_Contains(w, v); |
| 86 | 4189 if (res < 0) |
| 4190 return NULL; | |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
4191 res = !res; |
| 69 | 4192 break; |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
4193 case PyCmp_EXC_MATCH: |
|
40742
f1701ba2452b
Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40729
diff
changeset
|
4194 if (PyTuple_Check(w)) { |
|
f1701ba2452b
Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40729
diff
changeset
|
4195 Py_ssize_t i, length; |
|
f1701ba2452b
Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40729
diff
changeset
|
4196 length = PyTuple_Size(w); |
|
f1701ba2452b
Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40729
diff
changeset
|
4197 for (i = 0; i < length; i += 1) { |
|
f1701ba2452b
Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40729
diff
changeset
|
4198 PyObject *exc = PyTuple_GET_ITEM(w, i); |
|
40946
d976c9a63111
Make it so TypeError is raised if an instance of an object is put in an
Brett Cannon <bcannon@gmail.com>
parents:
40943
diff
changeset
|
4199 if (!PyExceptionClass_Check(exc)) { |
|
d976c9a63111
Make it so TypeError is raised if an instance of an object is put in an
Brett Cannon <bcannon@gmail.com>
parents:
40943
diff
changeset
|
4200 PyErr_SetString(PyExc_TypeError, |
|
d976c9a63111
Make it so TypeError is raised if an instance of an object is put in an
Brett Cannon <bcannon@gmail.com>
parents:
40943
diff
changeset
|
4201 CANNOT_CATCH_MSG); |
|
40942
4b9d0dac79cc
You can no longer catch non-BaseException objects; TypeError is raised if such
Brett Cannon <bcannon@gmail.com>
parents:
40937
diff
changeset
|
4202 return NULL; |
|
40742
f1701ba2452b
Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40729
diff
changeset
|
4203 } |
|
f1701ba2452b
Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40729
diff
changeset
|
4204 } |
|
f1701ba2452b
Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40729
diff
changeset
|
4205 } |
|
f1701ba2452b
Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40729
diff
changeset
|
4206 else { |
|
40946
d976c9a63111
Make it so TypeError is raised if an instance of an object is put in an
Brett Cannon <bcannon@gmail.com>
parents:
40943
diff
changeset
|
4207 if (!PyExceptionClass_Check(w)) { |
|
d976c9a63111
Make it so TypeError is raised if an instance of an object is put in an
Brett Cannon <bcannon@gmail.com>
parents:
40943
diff
changeset
|
4208 PyErr_SetString(PyExc_TypeError, |
|
d976c9a63111
Make it so TypeError is raised if an instance of an object is put in an
Brett Cannon <bcannon@gmail.com>
parents:
40943
diff
changeset
|
4209 CANNOT_CATCH_MSG); |
|
40942
4b9d0dac79cc
You can no longer catch non-BaseException objects; TypeError is raised if such
Brett Cannon <bcannon@gmail.com>
parents:
40937
diff
changeset
|
4210 return NULL; |
|
40742
f1701ba2452b
Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40729
diff
changeset
|
4211 } |
|
f1701ba2452b
Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40729
diff
changeset
|
4212 } |
|
6147
b76a44163e0f
cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents:
6139
diff
changeset
|
4213 res = PyErr_GivenExceptionMatches(v, w); |
| 69 | 4214 break; |
| 4215 default: | |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
4216 return PyObject_RichCompare(v, w, op); |
| 69 | 4217 } |
| 5368 | 4218 v = res ? Py_True : Py_False; |
| 4219 Py_INCREF(v); | |
| 69 | 4220 return v; |
| 4221 } | |
| 4222 | |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
4223 static PyObject * |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
4224 import_from(PyObject *v, PyObject *name) |
|
72
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
4225 { |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4226 PyObject *x; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4227 |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4228 x = PyObject_GetAttr(v, name); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4229 if (x == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) { |
|
41878
089f449a20cd
Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents:
41824
diff
changeset
|
4230 PyErr_Format(PyExc_ImportError, "cannot import name %S", name); |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4231 } |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
4232 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
|
4233 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
4234 |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
4235 static int |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
4236 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
|
4237 { |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4238 PyObject *all = PyObject_GetAttrString(v, "__all__"); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4239 PyObject *dict, *name, *value; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4240 int skip_leading_underscores = 0; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4241 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
|
4242 |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4243 if (all == NULL) { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4244 if (!PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4245 return -1; /* Unexpected error */ |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4246 PyErr_Clear(); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4247 dict = PyObject_GetAttrString(v, "__dict__"); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4248 if (dict == NULL) { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4249 if (!PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4250 return -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4251 PyErr_SetString(PyExc_ImportError, |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4252 "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
|
4253 return -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4254 } |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4255 all = PyMapping_Keys(dict); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4256 Py_DECREF(dict); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4257 if (all == NULL) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4258 return -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4259 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
|
4260 } |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
4261 |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4262 for (pos = 0, err = 0; ; pos++) { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4263 name = PySequence_GetItem(all, pos); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4264 if (name == NULL) { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4265 if (!PyErr_ExceptionMatches(PyExc_IndexError)) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4266 err = -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4267 else |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4268 PyErr_Clear(); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4269 break; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4270 } |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4271 if (skip_leading_underscores && |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41969
diff
changeset
|
4272 PyUnicode_Check(name) && |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41969
diff
changeset
|
4273 PyUnicode_AS_UNICODE(name)[0] == '_') |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4274 { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4275 Py_DECREF(name); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4276 continue; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4277 } |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4278 value = PyObject_GetAttr(v, name); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4279 if (value == NULL) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4280 err = -1; |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40381
diff
changeset
|
4281 else if (PyDict_CheckExact(locals)) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40381
diff
changeset
|
4282 err = PyDict_SetItem(locals, name, value); |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4283 else |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40381
diff
changeset
|
4284 err = PyObject_SetItem(locals, name, value); |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4285 Py_DECREF(name); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4286 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
|
4287 if (err != 0) |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4288 break; |
|
72
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
4289 } |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4290 Py_DECREF(all); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
4291 return err; |
|
72
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
4292 } |
|
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
4293 |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
4294 static void |
| 42860 | 4295 format_exc_check_arg(PyObject *exc, const char *format_str, PyObject *obj) |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4296 { |
| 42860 | 4297 const char *obj_str; |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4298 |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4299 if (!obj) |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4300 return; |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4301 |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
48574
diff
changeset
|
4302 obj_str = _PyUnicode_AsString(obj); |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4303 if (!obj_str) |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4304 return; |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4305 |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4306 PyErr_Format(exc, format_str, obj_str); |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4307 } |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4308 |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4309 static PyObject * |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
4310 unicode_concatenate(PyObject *v, PyObject *w, |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4311 PyFrameObject *f, unsigned char *next_instr) |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4312 { |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4313 /* This function implements 'variable += expr' when both arguments |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
4314 are (Unicode) strings. */ |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
4315 Py_ssize_t v_len = PyUnicode_GET_SIZE(v); |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
4316 Py_ssize_t w_len = PyUnicode_GET_SIZE(w); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
4317 Py_ssize_t new_len = v_len + w_len; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
4318 if (new_len < 0) { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
4319 PyErr_SetString(PyExc_OverflowError, |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
4320 "strings are too large to concat"); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
4321 return NULL; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
4322 } |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
4323 |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4324 if (v->ob_refcnt == 2) { |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4325 /* 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
|
4326 * stored in 'variable' when the += is performed: one on the |
|
43418
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
4327 * value stack (in 'v') and one still stored in the |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
4328 * 'variable'. We try to delete the variable now to reduce |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
4329 * the refcnt to 1. |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4330 */ |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4331 switch (*next_instr) { |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4332 case STORE_FAST: |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4333 { |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4334 int oparg = PEEKARG(); |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4335 PyObject **fastlocals = f->f_localsplus; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4336 if (GETLOCAL(oparg) == v) |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4337 SETLOCAL(oparg, NULL); |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4338 break; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4339 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4340 case STORE_DEREF: |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4341 { |
|
43418
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
4342 PyObject **freevars = (f->f_localsplus + |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
4343 f->f_code->co_nlocals); |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4344 PyObject *c = freevars[PEEKARG()]; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4345 if (PyCell_GET(c) == v) |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4346 PyCell_Set(c, NULL); |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4347 break; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4348 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4349 case STORE_NAME: |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4350 { |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4351 PyObject *names = f->f_code->co_names; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4352 PyObject *name = GETITEM(names, PEEKARG()); |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4353 PyObject *locals = f->f_locals; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4354 if (PyDict_CheckExact(locals) && |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4355 PyDict_GetItem(locals, name) == v) { |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4356 if (PyDict_DelItem(locals, name) != 0) { |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4357 PyErr_Clear(); |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4358 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4359 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4360 break; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4361 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4362 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4363 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4364 |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
4365 if (v->ob_refcnt == 1 && !PyUnicode_CHECK_INTERNED(v)) { |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4366 /* 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
|
4367 * in-place. |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4368 */ |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
4369 if (PyUnicode_Resize(&v, new_len) != 0) { |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
4370 /* XXX if PyUnicode_Resize() fails, 'v' has been |
|
43418
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
4371 * deallocated so it cannot be put back into |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
4372 * 'variable'. The MemoryError is raised when there |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
4373 * is no value in 'variable', which might (very |
|
0c8fec76111c
Merged revisions 58211-58220 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43411
diff
changeset
|
4374 * remotely) be a cause of incompatibilities. |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4375 */ |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4376 return NULL; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4377 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4378 /* copy 'w' into the newly allocated area of 'v' */ |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
4379 memcpy(PyUnicode_AS_UNICODE(v) + v_len, |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
4380 PyUnicode_AS_UNICODE(w), w_len*sizeof(Py_UNICODE)); |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4381 return v; |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4382 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4383 else { |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4384 /* When in-place resizing is not an option. */ |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
4385 w = PyUnicode_Concat(v, w); |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
4386 Py_DECREF(v); |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
4387 return w; |
|
32974
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4388 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4389 } |
|
fb6ffd290cfb
SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents:
32900
diff
changeset
|
4390 |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4391 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4392 |
|
20438
08d7a6756bfe
make getarray static - it's only called from ceval.c and is not an
Skip Montanaro <skip@pobox.com>
parents:
20409
diff
changeset
|
4393 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4394 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
|
4395 { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4396 int i; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4397 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
|
4398 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
|
4399 for (i = 0; i < 256; i++) { |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43996
diff
changeset
|
4400 PyObject *x = PyLong_FromLong(a[i]); |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4401 if (x == NULL) { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4402 Py_DECREF(l); |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4403 return NULL; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4404 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4405 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
|
4406 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4407 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
|
4408 a[i] = 0; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4409 return l; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4410 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4411 |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4412 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4413 _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
|
4414 { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4415 #ifndef DXPAIRS |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4416 return getarray(dxp); |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4417 #else |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4418 int i; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4419 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
|
4420 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
|
4421 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
|
4422 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
|
4423 if (x == NULL) { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4424 Py_DECREF(l); |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4425 return NULL; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4426 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4427 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
|
4428 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4429 return l; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4430 #endif |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4431 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4432 |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4433 #endif |
