annotate Python/ceval.c @ 43411:a5d37cdcd316

Whitespace cleanup.
author Thomas Wouters <thomas@python.org>
date Wed, 19 Sep 2007 21:56:32 +0000
parents b06b191b7cfa
children 0c8fec76111c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
1
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2 /* Execute compiled code */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
4 /* XXX TO DO:
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
5 XXX speed up searching for keywords by using a dictionary
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
6 XXX document it!
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
7 */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
8
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
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
12 #include "Python.h"
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
13
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35609
diff changeset
14 #include "code.h"
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
15 #include "frameobject.h"
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
16 #include "eval.h"
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 #include "opcode.h"
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 18611
diff changeset
18 #include "structmember.h"
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
19
1400
aac8231a715c * mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents: 1391
diff changeset
20 #include <ctype.h>
aac8231a715c * mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents: 1391
diff changeset
21
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
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
30 #if defined(__ppc__) /* <- Don't know if this is the correct symbol; this
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
31 section should work for GCC on any PowerPC platform,
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
32 irrespective of OS. POWER? Who knows :-) */
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
33
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
34 #define READ_TIMESTAMP(var) ppc_getcounter(&var)
33104
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
35
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
36 static void
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
37 ppc_getcounter(uint64 *v)
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
38 {
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
39 register unsigned long tbu, tb, tbu2;
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
40
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
41 loop:
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
42 asm volatile ("mftbu %0" : "=r" (tbu) );
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
43 asm volatile ("mftb %0" : "=r" (tb) );
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
44 asm volatile ("mftbu %0" : "=r" (tbu2));
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
45 if (__builtin_expect(tbu != tbu2, 0)) goto loop;
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
46
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
47 /* The slightly peculiar way of writing the next lines is
33104
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
48 compiled better by GCC than any other way I tried. */
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
49 ((long*)(v))[0] = tbu;
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
50 ((long*)(v))[1] = tb;
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
51 }
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
52
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
53 #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
54
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 #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
56 __asm__ __volatile__("rdtsc" : "=A" (val))
33104
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
57
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
58 #endif
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
59
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
60 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
61 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
62 {
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
63 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
64 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
65 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
66 return;
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
67 intr = intr1 - intr0;
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
68 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
69 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
70 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
71 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
72 }
33104
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
73
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
74 #endif
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
75
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
76 /* 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
77 /* #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
78
4839
4567e158d20c Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents: 4667
diff changeset
79 #ifdef Py_DEBUG
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
80 /* For debugging the interpreter: */
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
81 #define LLTRACE 1 /* Low-level trace feature */
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
82 #define CHECKEXC 1 /* Double-check exception checking */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 #endif
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
84
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
85 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
86
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
87 /* Forward declarations */
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
88 #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
89 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
90 #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
91 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
92 #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
93 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
94 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
95 static PyObject * ext_do_call(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
96 static PyObject * update_keyword_args(PyObject *, 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
97 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
98 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
99 #define CALL_FLAG_VAR 1
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
100 #define CALL_FLAG_KW 2
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
101
746
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
102 #ifdef LLTRACE
36695
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
103 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
104 static int prtrace(PyObject *, char *);
746
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
105 #endif
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18293
diff changeset
106 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
107 int, PyObject *);
20257
e3f63a95455f Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
108 static void 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
109 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
110 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
111 static int maybe_call_line_trace(Py_tracefunc, PyObject *,
31768
9817dee5d9df Fix SF bug #765624.
Armin Rigo <arigo@tunes.org>
parents: 31714
diff changeset
112 PyFrameObject *, int *, int *, int *);
24844
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24718
diff changeset
113
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
114 static PyObject * 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
115 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
116 static int import_all_from(PyObject *, PyObject *);
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
117 static void set_exc_info(PyThreadState *, PyObject *, PyObject *, PyObject *);
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
118 static void reset_exc_info(PyThreadState *);
42860
bf1a53cc6e65 Use unicode
Neal Norwitz <nnorwitz@gmail.com>
parents: 42334
diff changeset
119 static void format_exc_check_arg(PyObject *, const char *, 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
120 static PyObject * string_concatenate(PyObject *, PyObject *,
32974
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
121 PyFrameObject *, unsigned char *);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
122
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
123 #define NAME_ERROR_MSG \
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 15166
diff changeset
124 "name '%.200s' is not defined"
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
125 #define GLOBAL_NAME_ERROR_MSG \
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
126 "global name '%.200s' is not defined"
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
127 #define UNBOUNDLOCAL_ERROR_MSG \
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 15166
diff changeset
128 "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
129 #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
130 "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
131 " in enclosing scope"
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
132
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
133 /* Dynamic execution profile */
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
134 #ifdef 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 DXPAIRS
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
136 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
137 #define dxp dxpairs[256]
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
138 #else
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
139 static long dxp[256];
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
140 #endif
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
27712
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
143 /* 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
144 #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
145 #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
146 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
147
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
148 #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
149 #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
150 #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
151 #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
152 #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
153 #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
154 #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
155 #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
156 #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
157 #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
158 #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
159
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
160 /* 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
161
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
162 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
163
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
164 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
165 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
166
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
167 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
168 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
169 twice.
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
170
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
171 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
172 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
173 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
174 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
175 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
176 */
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 #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
179
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
180 PyObject *
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
181 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
182 {
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 40381
diff changeset
183 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
184 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
185 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
186 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
187 }
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
188 #else
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
189 #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
190
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
191 PyObject *
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
192 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
193 {
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
194 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
195 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
196 }
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
197 #endif
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
198
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
199
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
200 #ifdef WITH_THREAD
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
201
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 39222
diff changeset
202 #ifdef HAVE_ERRNO_H
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
203 #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
204 #endif
9203
07dae6fdae79 Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents: 9048
diff changeset
205 #include "pythread.h"
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
206
29643
fa97293533a9 Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents: 29349
diff changeset
207 static PyThread_type_lock interpreter_lock = 0; /* This is the GIL */
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
208 static long main_thread = 0;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
209
33715
a46b76eb9053 SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents: 33501
diff changeset
210 int
a46b76eb9053 SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents: 33501
diff changeset
211 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
212 {
a46b76eb9053 SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents: 33501
diff changeset
213 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
214 }
a46b76eb9053 SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Tim Peters <tim.peters@gmail.com>
parents: 33501
diff changeset
215
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
216 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
217 PyEval_InitThreads(void)
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
218 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
219 if (interpreter_lock)
1179
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1132
diff changeset
220 return;
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9671
diff changeset
221 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
222 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
223 main_thread = PyThread_get_thread_ident();
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
224 }
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
225
5865
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
226 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
227 PyEval_AcquireLock(void)
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5911
diff changeset
228 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9671
diff changeset
229 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
230 }
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5911
diff changeset
231
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5911
diff changeset
232 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
233 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
234 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9671
diff changeset
235 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
236 }
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5911
diff changeset
237
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5911
diff changeset
238 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
239 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
240 {
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
241 if (tstate == NULL)
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
242 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
243 /* 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
244 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
245 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
246 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
247 Py_FatalError(
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
248 "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
249 }
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
250
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
251 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
252 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
253 {
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
254 if (tstate == NULL)
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
255 Py_FatalError("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
256 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
257 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
258 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
259 }
14225
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
260
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
261 /* 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
262 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
263 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
264 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
265
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
266 void
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
267 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
268 {
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
269 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
270 return;
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
271 /*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
272 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
273 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
274 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
275 interpreter_lock = PyThread_allocate_lock();
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
276 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
277 main_thread = PyThread_get_thread_ident();
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
278 }
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
279 #endif
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
280
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
281 /* Functions save_thread and restore_thread are always defined so
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
282 dynamically loaded modules needn't be compiled separately for use
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
283 with and without threads: */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
284
5846
852a1fa62a7c PyEval_SaveThread() and PyEval_RestoreThread() now return/take a
Guido van Rossum <guido@python.org>
parents: 5829
diff changeset
285 PyThreadState *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
286 PyEval_SaveThread(void)
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
287 {
6365
21b93d98926b Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents: 6243
diff changeset
288 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
289 if (tstate == NULL)
21b93d98926b Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents: 6243
diff changeset
290 Py_FatalError("PyEval_SaveThread: NULL tstate");
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
291 #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
292 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
293 PyThread_release_lock(interpreter_lock);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
294 #endif
6365
21b93d98926b Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents: 6243
diff changeset
295 return tstate;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
296 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
297
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
298 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
299 PyEval_RestoreThread(PyThreadState *tstate)
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
300 {
6365
21b93d98926b Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents: 6243
diff changeset
301 if (tstate == NULL)
21b93d98926b Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents: 6243
diff changeset
302 Py_FatalError("PyEval_RestoreThread: NULL tstate");
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
303 #ifdef WITH_THREAD
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
304 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
305 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
306 PyThread_acquire_lock(interpreter_lock, 1);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
307 errno = err;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
308 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
309 #endif
6365
21b93d98926b Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents: 6243
diff changeset
310 PyThreadState_Swap(tstate);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
311 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
312
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
313
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
314 /* 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
315 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
316 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
317 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
318 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
319 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
320
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
321 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
322 (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
323 an exception condition).
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
324
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
325 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
326 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
327
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
328 #ifdef WITH_THREAD
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
329 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
330 will execute them.
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
331 #endif
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
332
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
333 XXX WARNING! ASYNCHRONOUSLY EXECUTING CODE!
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
334 There are two possible race conditions:
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
335 (1) nested asynchronous registry calls;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
336 (2) registry calls made while pending calls are being processed.
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
337 While (1) is very unlikely, (2) is a real possibility.
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
338 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
339 The safety against (2) is derived from the fact that only one
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
340 thread (the main thread) ever takes things out of the queue.
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
341
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
342 XXX Darn! With the advent of thread state, we should have an array
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
343 of pending calls per thread in the thread state! Later...
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
344 */
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
345
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
346 #define NPENDINGCALLS 32
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
347 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
348 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
349 void *arg;
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
350 } pendingcalls[NPENDINGCALLS];
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
351 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
352 static volatile int pendinglast = 0;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
353 static volatile int things_to_do = 0;
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
354
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
355 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
356 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
357 {
32526
78bd25b42d46 This closes patch:
Michael W. Hudson <mwh@python.net>
parents: 32463
diff changeset
358 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
359 int i, j;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
360 /* XXX Begin critical section */
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
361 /* XXX If you want this to be safe against nested
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
362 XXX asynchronous calls, you'll have to work harder! */
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
363 if (busy)
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
364 return -1;
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
365 busy = 1;
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
366 i = pendinglast;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
367 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
368 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
369 busy = 0;
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
370 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
371 }
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
372 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
373 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
374 pendinglast = j;
25108
3a26e352f0a6 replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents: 25078
diff changeset
375
3a26e352f0a6 replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents: 25078
diff changeset
376 _Py_Ticker = 0;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
377 things_to_do = 1; /* Signal main loop */
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
378 busy = 0;
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
379 /* 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
380 return 0;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
381 }
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
382
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
383 int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
384 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
385 {
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
386 static int busy = 0;
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
387 #ifdef WITH_THREAD
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9671
diff changeset
388 if (main_thread && PyThread_get_thread_ident() != main_thread)
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
389 return 0;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
390 #endif
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
391 if (busy)
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
392 return 0;
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
393 busy = 1;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
394 things_to_do = 0;
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
395 for (;;) {
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
396 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
397 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
398 void *arg;
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
399 i = pendingfirst;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
400 if (i == pendinglast)
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
401 break; /* Queue empty */
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
402 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
403 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
404 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
405 if (func(arg) < 0) {
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
406 busy = 0;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
407 things_to_do = 1; /* We're not done yet */
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
408 return -1;
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
409 }
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
410 }
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
411 busy = 0;
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
412 return 0;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
413 }
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
414
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
415
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
416 /* The interpreter's recursion limit */
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
417
34863
71fd7ee4b7f5 Make a handy macro, Py_DEFAULT_RECURSION_LIMIT to allow to define
Hye-Shik Chang <hyeshik@gmail.com>
parents: 34442
diff changeset
418 #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
419 #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
420 #endif
71fd7ee4b7f5 Make a handy macro, Py_DEFAULT_RECURSION_LIMIT to allow to define
Hye-Shik Chang <hyeshik@gmail.com>
parents: 34442
diff changeset
421 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
422 int _Py_CheckRecursionLimit = Py_DEFAULT_RECURSION_LIMIT;
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
423
14348
6d0f64f7dedd Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 14333
diff changeset
424 int
6d0f64f7dedd Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 14333
diff changeset
425 Py_GetRecursionLimit(void)
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
426 {
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
427 return recursion_limit;
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
428 }
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
429
14348
6d0f64f7dedd Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 14333
diff changeset
430 void
6d0f64f7dedd Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 14333
diff changeset
431 Py_SetRecursionLimit(int new_limit)
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
432 {
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
433 recursion_limit = new_limit;
43410
b06b191b7cfa Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
434 _Py_CheckRecursionLimit = recursion_limit;
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
435 }
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
436
30801
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
437 /* the macro Py_EnterRecursiveCall() only calls _Py_CheckRecursiveCall()
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
438 if the recursion_depth reaches _Py_CheckRecursionLimit.
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
439 If USE_STACKCHECK, the macro decrements _Py_CheckRecursionLimit
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
440 to guarantee that _Py_CheckRecursiveCall() is regularly called.
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
441 Without USE_STACKCHECK, there is no need for this. */
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
442 int
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
443 _Py_CheckRecursiveCall(char *where)
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
444 {
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
445 PyThreadState *tstate = PyThreadState_GET();
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
446
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
447 #ifdef USE_STACKCHECK
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
448 if (PyOS_CheckStack()) {
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
449 --tstate->recursion_depth;
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
450 PyErr_SetString(PyExc_MemoryError, "Stack overflow");
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
451 return -1;
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
452 }
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
453 #endif
42013
cd125fe83051 Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents: 41969
diff changeset
454 if (tstate->recursion_critical)
cd125fe83051 Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents: 41969
diff changeset
455 /* 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
456 return 0;
cd125fe83051 Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents: 41969
diff changeset
457 if (tstate->overflowed) {
cd125fe83051 Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents: 41969
diff changeset
458 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
459 /* 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
460 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
461 }
cd125fe83051 Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents: 41969
diff changeset
462 return 0;
cd125fe83051 Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents: 41969
diff changeset
463 }
30801
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
464 if (tstate->recursion_depth > recursion_limit) {
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
465 --tstate->recursion_depth;
42013
cd125fe83051 Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents: 41969
diff changeset
466 tstate->overflowed = 1;
30801
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
467 PyErr_Format(PyExc_RuntimeError,
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
468 "maximum recursion depth exceeded%s",
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
469 where);
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
470 return -1;
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
471 }
43410
b06b191b7cfa Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
472 _Py_CheckRecursionLimit = recursion_limit;
30801
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
473 return 0;
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
474 }
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
475
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
476 /* 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
477 enum why_code {
1fb2313ac3ce Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents: 31874
diff changeset
478 WHY_NOT = 0x0001, /* No error */
1fb2313ac3ce Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents: 31874
diff changeset
479 WHY_EXCEPTION = 0x0002, /* Exception occurred */
1fb2313ac3ce Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents: 31874
diff changeset
480 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
481 WHY_RETURN = 0x0008, /* 'return' statement */
1fb2313ac3ce Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents: 31874
diff changeset
482 WHY_BREAK = 0x0010, /* 'break' statement */
1fb2313ac3ce Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents: 31874
diff changeset
483 WHY_CONTINUE = 0x0020, /* 'continue' statement */
1fb2313ac3ce Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents: 31874
diff changeset
484 WHY_YIELD = 0x0040 /* 'yield' operator */
1fb2313ac3ce Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents: 31874
diff changeset
485 };
1fb2313ac3ce Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents: 31874
diff changeset
486
43102
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 43100
diff changeset
487 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
488 static int unpack_iterable(PyObject *, int, int, PyObject **);
5018
001a5042b181 Cleanup:
Guido van Rossum <guido@python.org>
parents: 5014
diff changeset
489
25108
3a26e352f0a6 replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents: 25078
diff changeset
490 /* 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
491 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
492 int _Py_CheckInterval = 100;
00b6dd414b80 Bump default check interval to 100 instructions. Computers are much faster
Skip Montanaro <skip@pobox.com>
parents: 25108
diff changeset
493 volatile int _Py_Ticker = 100;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
494
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
495 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
496 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
497 {
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 18611
diff changeset
498 return PyEval_EvalCodeEx(co,
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
499 globals, locals,
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
500 (PyObject **)NULL, 0,
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
501 (PyObject **)NULL, 0,
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
502 (PyObject **)NULL, 0,
40215
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
503 NULL, NULL);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
504 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
505
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
506
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
507 /* Interpreter main loop */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
508
32421
485d2ef43419 Patch #966493: Cleanup generator/eval_frame exposure.
Martin v. Löwis <martin@v.loewis.de>
parents: 32412
diff changeset
509 PyObject *
35298
b2fe5f8fcfdd PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents: 35126
diff changeset
510 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
511 /* This is for backward compatibility with extension modules that
b2fe5f8fcfdd PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents: 35126
diff changeset
512 used this API; core interpreter code should call PyEval_EvalFrameEx() */
b2fe5f8fcfdd PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents: 35126
diff changeset
513 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
514 }
b2fe5f8fcfdd PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents: 35126
diff changeset
515
b2fe5f8fcfdd PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents: 35126
diff changeset
516 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
517 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
518 {
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
519 #ifdef DXPAIRS
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
520 int lastopcode = 0;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
521 #endif
32359
e5bc947c44ca Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents: 32301
diff changeset
522 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
523 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
524 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
525 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
526 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
527 register int err; /* Error status -- nonzero if error */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
528 register PyObject *x; /* Result object -- NULL if error */
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
529 register PyObject *v; /* Temporary objects popped off stack */
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
530 register PyObject *w;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
531 register PyObject *u;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
532 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
533 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
534 PyObject *retval = NULL; /* Return value */
9671
1d40bc25703a Use PyThreadState_GET() macro.
Guido van Rossum <guido@python.org>
parents: 9591
diff changeset
535 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
536 PyCodeObject *co;
24844
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24718
diff changeset
537
31872
9f5fe6b23e59 Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents: 31797
diff changeset
538 /* when tracing we set things up so that
24844
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24718
diff changeset
539
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24718
diff changeset
540 not (instr_lb <= current_bytecode_offset < instr_ub)
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24718
diff changeset
541
31872
9f5fe6b23e59 Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents: 31797
diff changeset
542 is true when the line being executed has changed. The
24844
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24718
diff changeset
543 initial values are such as to make this false the first
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24718
diff changeset
544 time it is tested. */
31768
9817dee5d9df Fix SF bug #765624.
Armin Rigo <arigo@tunes.org>
parents: 31714
diff changeset
545 int instr_ub = -1, instr_lb = 0, instr_prev = -1;
24844
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24718
diff changeset
546
9293
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 9203
diff changeset
547 unsigned char *first_instr;
24545
d2f41c8a81f0 small speedup for constant and name access
Skip Montanaro <skip@pobox.com>
parents: 24284
diff changeset
548 PyObject *names;
d2f41c8a81f0 small speedup for constant and name access
Skip Montanaro <skip@pobox.com>
parents: 24284
diff changeset
549 PyObject *consts;
35745
407c3dacbd7c Fix some mods that got dropped from the AST merge
Neal Norwitz <nnorwitz@gmail.com>
parents: 35742
diff changeset
550 #if defined(Py_DEBUG) || defined(LLTRACE)
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
551 /* 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
552 char *filename;
1016
a41e3ba5b47d Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents: 974
diff changeset
553 #endif
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
554
24232
e06b1ab0bdb8 SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents: 24190
diff changeset
555 /* 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
556
e06b1ab0bdb8 SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents: 24190
diff changeset
557 #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
558 #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
559 #else
e06b1ab0bdb8 SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents: 24190
diff changeset
560 #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
561 #endif
e06b1ab0bdb8 SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents: 24190
diff changeset
562
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
563 #ifdef WITH_TSC
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
564 /* 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
565 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
566 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
567 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
568 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
569 (may be skipped)
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
570 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
571 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
572
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
573 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
574 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
575 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
576 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
577 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
578
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
579 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
580 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
581 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
582
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
583 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
584 cases:
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
585
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
586 IMPORT_STAR
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
587 IMPORT_FROM
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
588 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
589
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
590 */
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
591 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
592 int ticked = 0;
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
593
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
594 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
595 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
596 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
597 READ_TIMESTAMP(loop1);
33104
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
598
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
599 /* shut up the compiler */
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 33030
diff changeset
600 opcode = 0;
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
601 #endif
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
602
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
603 /* Code access macros */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
604
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36475
diff changeset
605 #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
606 #define NEXTOP() (*next_instr++)
31894
310dd98ea064 Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents: 31880
diff changeset
607 #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
608 #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
609 #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
610 #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
611
28302
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
612 /* OpCode prediction macros
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
613 Some opcodes tend to come in pairs thus making it possible to predict
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
614 the second code when the first is run. For example, COMPARE_OP is often
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
615 followed by JUMP_IF_FALSE or JUMP_IF_TRUE. And, those opcodes are often
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
616 followed by a POP_TOP.
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
617
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
618 Verifying the prediction costs a single high-speed test of register
28303
470504ef578b Fix comment and whitespace.
Raymond Hettinger <python@rcn.com>
parents: 28302
diff changeset
619 variable against a constant. If the pairing was good, then the
28302
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
620 processor has a high likelihood of making its own successful branch
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
621 prediction which results in a nearly zero overhead transition to the
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
622 next opcode.
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
623
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
624 A successful prediction saves a trip through the eval-loop including
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
625 its two unpredictable branches, the HASARG test and the switch-case.
31487
f57f5ce22c8d SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents: 31462
diff changeset
626
31872
9f5fe6b23e59 Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents: 31797
diff changeset
627 If collecting opcode statistics, turn off prediction so that
9f5fe6b23e59 Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents: 31797
diff changeset
628 statistics are accurately maintained (the predictions bypass
31487
f57f5ce22c8d SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents: 31462
diff changeset
629 the opcode frequency counter updates).
28302
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
630 */
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
631
31487
f57f5ce22c8d SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents: 31462
diff changeset
632 #ifdef DYNAMIC_EXECUTION_PROFILE
f57f5ce22c8d SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents: 31462
diff changeset
633 #define PREDICT(op) if (0) goto PRED_##op
f57f5ce22c8d SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents: 31462
diff changeset
634 #else
28303
470504ef578b Fix comment and whitespace.
Raymond Hettinger <python@rcn.com>
parents: 28302
diff changeset
635 #define PREDICT(op) if (*next_instr == op) goto PRED_##op
31487
f57f5ce22c8d SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents: 31462
diff changeset
636 #endif
f57f5ce22c8d SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents: 31462
diff changeset
637
28302
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
638 #define PREDICTED(op) PRED_##op: next_instr++
32974
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
639 #define PREDICTED_WITH_ARG(op) PRED_##op: oparg = PEEKARG(); next_instr += 3
28302
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
640
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
641 /* Stack manipulation macros */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
642
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36475
diff changeset
643 /* 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
644 co_stacksize are ints. */
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36475
diff changeset
645 #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
646 #define EMPTY() (STACK_LEVEL() == 0)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
647 #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
648 #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
649 #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
650 #define FOURTH() (stack_pointer[-4])
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
651 #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
652 #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
653 #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
654 #define SET_FOURTH(v) (stack_pointer[-4] = (v))
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
655 #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
656 #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
657 #define BASIC_POP() (*--stack_pointer)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
658
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
659 #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
660 #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
661 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
662 assert(STACK_LEVEL() <= co->co_stacksize); }
20409
b98185c882e4 Suppress a bunch of "value computed is not used" warnings when building in
Fred Drake <fdrake@acm.org>
parents: 20275
diff changeset
663 #define POP() ((void)(lltrace && prtrace(TOP(), "pop")), BASIC_POP())
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
664 #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
665 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
666 assert(STACK_LEVEL() <= co->co_stacksize); }
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41464
diff changeset
667 #define EXT_POP(STACK_POINTER) (lltrace && prtrace((STACK_POINTER)[-1], "ext_pop"), *--(STACK_POINTER))
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
668 #else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
669 #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
670 #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
671 #define STACKADJ(n) BASIC_STACKADJ(n)
36695
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
672 #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
673 #endif
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
674
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
675 /* Local variable macros */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
676
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
677 #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
678
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
679 /* 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
680 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
681 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
682 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
683 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
684 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
685 #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
686 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
687 Py_XDECREF(tmp); } while (0)
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
688
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
689 /* Start of code */
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
690
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
691 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
692 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
693
30801
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
694 /* push frame */
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
695 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
696 return NULL;
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
697
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
698 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
699
19692
04218e85b156 Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19611
diff changeset
700 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
701 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
702 /* 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
703 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
704 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
705 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
706 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
707 (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
708 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
709 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
710 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
711 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
712 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
713 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
714 whenever an exception is detected. */
04218e85b156 Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19611
diff changeset
715 if (call_trace(tstate->c_tracefunc, tstate->c_traceobj,
04218e85b156 Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19611
diff changeset
716 f, PyTrace_CALL, Py_None)) {
04218e85b156 Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19611
diff changeset
717 /* Trace function raised an error */
30801
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
718 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
719 }
04218e85b156 Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19611
diff changeset
720 }
04218e85b156 Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19611
diff changeset
721 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
722 /* 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
723 return itself and isn't called for "line" events */
04218e85b156 Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19611
diff changeset
724 if (call_trace(tstate->c_profilefunc,
04218e85b156 Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19611
diff changeset
725 tstate->c_profileobj,
04218e85b156 Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19611
diff changeset
726 f, PyTrace_CALL, Py_None)) {
04218e85b156 Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19611
diff changeset
727 /* Profile function raised an error */
30801
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
728 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
729 }
04218e85b156 Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19611
diff changeset
730 }
04218e85b156 Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19611
diff changeset
731 }
04218e85b156 Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19611
diff changeset
732
26109
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 26079
diff changeset
733 co = f->f_code;
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 26079
diff changeset
734 names = co->co_names;
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 26079
diff changeset
735 consts = co->co_consts;
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 26079
diff changeset
736 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
737 freevars = f->f_localsplus + co->co_nlocals;
35126
70681267a74a Fix signedness of various char variables to stop causing a warning under gcc 4.
Brett Cannon <bcannon@gmail.com>
parents: 35125
diff changeset
738 first_instr = (unsigned char*) PyString_AS_STRING(co->co_code);
26109
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 26079
diff changeset
739 /* 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
740
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 26079
diff changeset
741 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
742 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
743 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
744 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
745 and YIELD_VALUE doesn't fiddle with f_lasti any more. So this
40582
67287ca4e1e8 Merged revisions 53005-53303 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40529
diff changeset
746 does work. Promise.
67287ca4e1e8 Merged revisions 53005-53303 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40529
diff changeset
747
67287ca4e1e8 Merged revisions 53005-53303 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40529
diff changeset
748 When the PREDICT() macros are enabled, some opcode pairs follow in
67287ca4e1e8 Merged revisions 53005-53303 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40529
diff changeset
749 direct succession without updating f->f_lasti. A successful
67287ca4e1e8 Merged revisions 53005-53303 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40529
diff changeset
750 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
751 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
752 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
753 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
754 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
755 */
26109
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 26079
diff changeset
756 next_instr = first_instr + f->f_lasti + 1;
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 26079
diff changeset
757 stack_pointer = f->f_stacktop;
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 26079
diff changeset
758 assert(stack_pointer != NULL);
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 26079
diff changeset
759 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
760
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
761 #ifdef LLTRACE
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35609
diff changeset
762 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
763 #endif
35745
407c3dacbd7c Fix some mods that got dropped from the AST merge
Neal Norwitz <nnorwitz@gmail.com>
parents: 35742
diff changeset
764 #if defined(Py_DEBUG) || defined(LLTRACE)
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
765 filename = PyString_AsString(co->co_filename);
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
766 #endif
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
767
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
768 why = WHY_NOT;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
769 err = 0;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
770 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
771 w = NULL;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
772
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
773 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
774 why = WHY_EXCEPTION;
b2fe5f8fcfdd PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents: 35126
diff changeset
775 goto on_error;
b2fe5f8fcfdd PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents: 35126
diff changeset
776 }
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
777
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
778 for (;;) {
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
779 #ifdef WITH_TSC
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
780 if (inst1 == 0) {
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
781 /* 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
782 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
783 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
784 */
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
785 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
786 loop1 = inst1;
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
787 }
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
788 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
789 intr0, intr1);
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
790 ticked = 0;
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
791 inst1 = 0;
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
792 intr0 = 0;
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
793 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
794 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
795 #endif
24844
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24718
diff changeset
796 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
797 assert(STACK_LEVEL() <= co->co_stacksize); /* else overflow */
24844
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24718
diff changeset
798
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
799 /* 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
800 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
801 only every Nth instruction. We also do it if
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
802 ``things_to_do'' is set, i.e. when an asynchronous
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
803 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
804 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
805 Py_MakePendingCalls() above. */
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
806
25108
3a26e352f0a6 replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents: 25078
diff changeset
807 if (--_Py_Ticker < 0) {
43410
b06b191b7cfa Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
808 if (*next_instr == SETUP_FINALLY) {
b06b191b7cfa Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
809 /* Make the last opcode before
b06b191b7cfa Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
810 a try: finally: block uninterruptable. */
b06b191b7cfa Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
811 goto fast_next_opcode;
b06b191b7cfa Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
812 }
25108
3a26e352f0a6 replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents: 25078
diff changeset
813 _Py_Ticker = _Py_CheckInterval;
26109
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 26079
diff changeset
814 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
815 #ifdef WITH_TSC
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
816 ticked = 1;
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
817 #endif
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
818 if (things_to_do) {
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
819 if (Py_MakePendingCalls() < 0) {
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
820 why = WHY_EXCEPTION;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
821 goto on_error;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
822 }
34020
be370abb020f Hye-Shik Chang's fix for Bug 875692.
Kurt B. Kaiser <kbk@shore.net>
parents: 33715
diff changeset
823 if (things_to_do)
be370abb020f Hye-Shik Chang's fix for Bug 875692.
Kurt B. Kaiser <kbk@shore.net>
parents: 33715
diff changeset
824 /* MakePendingCalls() didn't succeed.
be370abb020f Hye-Shik Chang's fix for Bug 875692.
Kurt B. Kaiser <kbk@shore.net>
parents: 33715
diff changeset
825 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
826 "periodic" code, possibly after
be370abb020f Hye-Shik Chang's fix for Bug 875692.
Kurt B. Kaiser <kbk@shore.net>
parents: 33715
diff changeset
827 a thread switch */
be370abb020f Hye-Shik Chang's fix for Bug 875692.
Kurt B. Kaiser <kbk@shore.net>
parents: 33715
diff changeset
828 _Py_Ticker = 0;
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
829 }
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
830 #ifdef WITH_THREAD
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
831 if (interpreter_lock) {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
832 /* Give another thread a chance */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
833
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5911
diff changeset
834 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
835 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
836 PyThread_release_lock(interpreter_lock);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
837
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
838 /* Other threads may run now */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
839
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9671
diff changeset
840 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
841 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
842 Py_FatalError("ceval: orphan tstate");
29643
fa97293533a9 Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents: 29349
diff changeset
843
fa97293533a9 Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents: 29349
diff changeset
844 /* Check for thread interrupts */
fa97293533a9 Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents: 29349
diff changeset
845
fa97293533a9 Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents: 29349
diff changeset
846 if (tstate->async_exc != NULL) {
fa97293533a9 Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents: 29349
diff changeset
847 x = tstate->async_exc;
fa97293533a9 Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents: 29349
diff changeset
848 tstate->async_exc = NULL;
fa97293533a9 Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents: 29349
diff changeset
849 PyErr_SetNone(x);
fa97293533a9 Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents: 29349
diff changeset
850 Py_DECREF(x);
fa97293533a9 Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents: 29349
diff changeset
851 why = WHY_EXCEPTION;
fa97293533a9 Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents: 29349
diff changeset
852 goto on_error;
fa97293533a9 Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents: 29349
diff changeset
853 }
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
854 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
855 #endif
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
856 }
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
857
21974
052efc06520a Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 21935
diff changeset
858 fast_next_opcode:
26109
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 26079
diff changeset
859 f->f_lasti = INSTR_OFFSET();
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 26079
diff changeset
860
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 26079
diff changeset
861 /* line-by-line tracing support */
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 26079
diff changeset
862
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 26079
diff changeset
863 if (tstate->c_tracefunc != NULL && !tstate->tracing) {
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 26079
diff changeset
864 /* see maybe_call_line_trace
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 26079
diff changeset
865 for expository comments */
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 26079
diff changeset
866 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
867
28886
af53729d3cdd Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents: 28759
diff changeset
868 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
869 tstate->c_traceobj,
31768
9817dee5d9df Fix SF bug #765624.
Armin Rigo <arigo@tunes.org>
parents: 31714
diff changeset
870 f, &instr_lb, &instr_ub,
9817dee5d9df Fix SF bug #765624.
Armin Rigo <arigo@tunes.org>
parents: 31714
diff changeset
871 &instr_prev);
28886
af53729d3cdd Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents: 28759
diff changeset
872 /* Reload possibly changed frame fields */
af53729d3cdd Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents: 28759
diff changeset
873 JUMPTO(f->f_lasti);
af53729d3cdd Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents: 28759
diff changeset
874 if (f->f_stacktop != NULL) {
af53729d3cdd Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents: 28759
diff changeset
875 stack_pointer = f->f_stacktop;
af53729d3cdd Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents: 28759
diff changeset
876 f->f_stacktop = NULL;
af53729d3cdd Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents: 28759
diff changeset
877 }
af53729d3cdd Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents: 28759
diff changeset
878 if (err) {
26110
964d6b79c22e This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents: 26109
diff changeset
879 /* trace function raised an exception */
964d6b79c22e This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents: 26109
diff changeset
880 goto on_error;
964d6b79c22e This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents: 26109
diff changeset
881 }
26109
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 26079
diff changeset
882 }
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 26079
diff changeset
883
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
884 /* Extract opcode and argument */
1016
a41e3ba5b47d Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents: 974
diff changeset
885
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
886 opcode = NEXTOP();
32359
e5bc947c44ca Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents: 32301
diff changeset
887 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
888 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
889 if (HAS_ARG(opcode))
310dd98ea064 Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents: 31880
diff changeset
890 oparg = NEXTARG();
14147
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14100
diff changeset
891 dispatch_opcode:
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
892 #ifdef DYNAMIC_EXECUTION_PROFILE
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
893 #ifdef DXPAIRS
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
894 dxpairs[lastopcode][opcode]++;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
895 lastopcode = opcode;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
896 #endif
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
897 dxp[opcode]++;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
898 #endif
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
899
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
900 #ifdef LLTRACE
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
901 /* Instruction tracing */
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
902
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
903 if (lltrace) {
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
904 if (HAS_ARG(opcode)) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
905 printf("%d: %d, %d\n",
24844
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24718
diff changeset
906 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
907 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
908 else {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
909 printf("%d: %d\n",
24844
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24718
diff changeset
910 f->f_lasti, opcode);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
911 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
912 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
913 #endif
24844
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24718
diff changeset
914
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
915 /* 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
916 READ_TIMESTAMP(inst0);
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
917
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
918 switch (opcode) {
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
919
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
920 /* BEWARE!
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
921 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
922 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
923 and that no operation that succeeds does this! */
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
924
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
925 /* case STOP_CODE: this is an error! */
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
926
32395
6bc6abba8659 Install two code generation optimizations that depend on NOP.
Raymond Hettinger <python@rcn.com>
parents: 32359
diff changeset
927 case NOP:
6bc6abba8659 Install two code generation optimizations that depend on NOP.
Raymond Hettinger <python@rcn.com>
parents: 32359
diff changeset
928 goto fast_next_opcode;
6bc6abba8659 Install two code generation optimizations that depend on NOP.
Raymond Hettinger <python@rcn.com>
parents: 32359
diff changeset
929
21974
052efc06520a Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 21935
diff changeset
930 case LOAD_FAST:
052efc06520a Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 21935
diff changeset
931 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
932 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
933 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
934 PUSH(x);
052efc06520a Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 21935
diff changeset
935 goto fast_next_opcode;
052efc06520a Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 21935
diff changeset
936 }
052efc06520a Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 21935
diff changeset
937 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
938 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
939 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
940 break;
052efc06520a Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 21935
diff changeset
941
052efc06520a Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 21935
diff changeset
942 case LOAD_CONST:
24545
d2f41c8a81f0 small speedup for constant and name access
Skip Montanaro <skip@pobox.com>
parents: 24284
diff changeset
943 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
944 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
945 PUSH(x);
052efc06520a Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 21935
diff changeset
946 goto fast_next_opcode;
052efc06520a Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 21935
diff changeset
947
28304
b14d6741f496 Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents: 28303
diff changeset
948 PREDICTED_WITH_ARG(STORE_FAST);
21974
052efc06520a Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 21935
diff changeset
949 case STORE_FAST:
052efc06520a Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 21935
diff changeset
950 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
951 SETLOCAL(oparg, v);
052efc06520a Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 21935
diff changeset
952 goto fast_next_opcode;
052efc06520a Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 21935
diff changeset
953
28302
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
954 PREDICTED(POP_TOP);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
955 case POP_TOP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
956 v = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
957 Py_DECREF(v);
21974
052efc06520a Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 21935
diff changeset
958 goto fast_next_opcode;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
959
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
960 case ROT_TWO:
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
961 v = TOP();
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
962 w = SECOND();
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
963 SET_TOP(w);
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
964 SET_SECOND(v);
28296
7654c24decc4 SF patch #701907: More use of fast_next_opcode
Raymond Hettinger <python@rcn.com>
parents: 28121
diff changeset
965 goto fast_next_opcode;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
966
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
967 case ROT_THREE:
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
968 v = TOP();
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
969 w = SECOND();
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
970 x = THIRD();
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
971 SET_TOP(w);
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
972 SET_SECOND(x);
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
973 SET_THIRD(v);
28296
7654c24decc4 SF patch #701907: More use of fast_next_opcode
Raymond Hettinger <python@rcn.com>
parents: 28121
diff changeset
974 goto fast_next_opcode;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
975
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
976 case ROT_FOUR:
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
977 u = TOP();
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
978 v = SECOND();
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
979 w = THIRD();
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
980 x = FOURTH();
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
981 SET_TOP(v);
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
982 SET_SECOND(w);
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
983 SET_THIRD(x);
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
984 SET_FOURTH(u);
28296
7654c24decc4 SF patch #701907: More use of fast_next_opcode
Raymond Hettinger <python@rcn.com>
parents: 28121
diff changeset
985 goto fast_next_opcode;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
986
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
987 case DUP_TOP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
988 v = TOP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
989 Py_INCREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
990 PUSH(v);
28296
7654c24decc4 SF patch #701907: More use of fast_next_opcode
Raymond Hettinger <python@rcn.com>
parents: 28121
diff changeset
991 goto fast_next_opcode;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
992
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
993 case DUP_TOPX:
27295
b8387730dd8f SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents: 27243
diff changeset
994 if (oparg == 2) {
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
995 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
996 Py_INCREF(x);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
997 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
998 Py_INCREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
999 STACKADJ(2);
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1000 SET_TOP(x);
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1001 SET_SECOND(w);
28302
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
1002 goto fast_next_opcode;
27295
b8387730dd8f SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents: 27243
diff changeset
1003 } 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
1004 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
1005 Py_INCREF(x);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1006 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
1007 Py_INCREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1008 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
1009 Py_INCREF(v);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1010 STACKADJ(3);
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1011 SET_TOP(x);
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1012 SET_SECOND(w);
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1013 SET_THIRD(v);
28302
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
1014 goto fast_next_opcode;
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1015 }
27295
b8387730dd8f SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents: 27243
diff changeset
1016 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
1017 " (bytecode corruption?)");
15151
ca9f6a8e9885 Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents: 14869
diff changeset
1018 break;
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1019
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1020 case UNARY_POSITIVE:
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1021 v = TOP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1022 x = PyNumber_Positive(v);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1023 Py_DECREF(v);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1024 SET_TOP(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1025 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1026 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1027
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1028 case UNARY_NEGATIVE:
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1029 v = TOP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1030 x = PyNumber_Negative(v);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1031 Py_DECREF(v);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1032 SET_TOP(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1033 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1034 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1035
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1036 case UNARY_NOT:
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1037 v = TOP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1038 err = PyObject_IsTrue(v);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1039 Py_DECREF(v);
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1040 if (err == 0) {
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1041 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
1042 SET_TOP(Py_True);
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1043 continue;
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1044 }
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1045 else if (err > 0) {
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1046 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
1047 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
1048 err = 0;
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1049 continue;
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1050 }
27243
3afbd55fb18f Replaced POP() with STACKADJ(-1) on lines where the result wasn't used.
Raymond Hettinger <python@rcn.com>
parents: 27201
diff changeset
1051 STACKADJ(-1);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1052 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1053
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1054 case UNARY_INVERT:
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1055 v = TOP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1056 x = PyNumber_Invert(v);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1057 Py_DECREF(v);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1058 SET_TOP(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1059 if (x != NULL) continue;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1060 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1061
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
1062 case BINARY_POWER:
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
1063 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1064 v = TOP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1065 x = PyNumber_Power(v, w, Py_None);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1066 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1067 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1068 SET_TOP(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1069 if (x != NULL) continue;
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
1070 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1071
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1072 case BINARY_MULTIPLY:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1073 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1074 v = TOP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1075 x = PyNumber_Multiply(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1076 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1077 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1078 SET_TOP(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1079 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1080 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1081
21251
45e1177424e1 SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents: 21171
diff changeset
1082 case BINARY_TRUE_DIVIDE:
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1083 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1084 v = TOP();
21251
45e1177424e1 SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents: 21171
diff changeset
1085 x = PyNumber_TrueDivide(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1086 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1087 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1088 SET_TOP(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1089 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1090 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1091
19051
f20727cc3d0f Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents: 18933
diff changeset
1092 case BINARY_FLOOR_DIVIDE:
f20727cc3d0f Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents: 18933
diff changeset
1093 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1094 v = TOP();
19051
f20727cc3d0f Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents: 18933
diff changeset
1095 x = PyNumber_FloorDivide(v, w);
f20727cc3d0f Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents: 18933
diff changeset
1096 Py_DECREF(v);
f20727cc3d0f Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents: 18933
diff changeset
1097 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1098 SET_TOP(x);
19051
f20727cc3d0f Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents: 18933
diff changeset
1099 if (x != NULL) continue;
f20727cc3d0f Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents: 18933
diff changeset
1100 break;
f20727cc3d0f Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents: 18933
diff changeset
1101
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1102 case BINARY_MODULO:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1103 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1104 v = TOP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1105 x = PyNumber_Remainder(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1106 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1107 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1108 SET_TOP(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1109 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1110 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1111
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1112 case BINARY_ADD:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1113 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1114 v = TOP();
20273
2269cb371e05 Get rid of unique local ISSTRICTINT macro in favor of std PyInt_CheckExact.
Tim Peters <tim.peters@gmail.com>
parents: 20257
diff changeset
1115 if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {
5829
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1116 /* INLINE: int + int */
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1117 register long a, b, i;
9591
7f90736701a3 Use PyInt_AS_LONG macro instead of explicit inlining.
Guido van Rossum <guido@python.org>
parents: 9513
diff changeset
1118 a = PyInt_AS_LONG(v);
7f90736701a3 Use PyInt_AS_LONG macro instead of explicit inlining.
Guido van Rossum <guido@python.org>
parents: 9513
diff changeset
1119 b = PyInt_AS_LONG(w);
5829
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1120 i = a + b;
19434
c140bd7d3bdc When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents: 19369
diff changeset
1121 if ((i^a) < 0 && (i^b) < 0)
c140bd7d3bdc When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents: 19369
diff changeset
1122 goto slow_add;
c140bd7d3bdc When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents: 19369
diff changeset
1123 x = PyInt_FromLong(i);
5829
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1124 }
32974
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
1125 else if (PyString_CheckExact(v) &&
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
1126 PyString_CheckExact(w)) {
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
1127 x = string_concatenate(v, w, f, next_instr);
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
1128 /* string_concatenate consumed the ref to v */
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
1129 goto skip_decref_vx;
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
1130 }
19434
c140bd7d3bdc When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents: 19369
diff changeset
1131 else {
c140bd7d3bdc When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents: 19369
diff changeset
1132 slow_add:
5829
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1133 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
1134 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1135 Py_DECREF(v);
32974
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
1136 skip_decref_vx:
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1137 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1138 SET_TOP(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1139 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1140 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1141
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1142 case BINARY_SUBTRACT:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1143 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1144 v = TOP();
20273
2269cb371e05 Get rid of unique local ISSTRICTINT macro in favor of std PyInt_CheckExact.
Tim Peters <tim.peters@gmail.com>
parents: 20257
diff changeset
1145 if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {
5829
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1146 /* INLINE: int - int */
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1147 register long a, b, i;
9591
7f90736701a3 Use PyInt_AS_LONG macro instead of explicit inlining.
Guido van Rossum <guido@python.org>
parents: 9513
diff changeset
1148 a = PyInt_AS_LONG(v);
7f90736701a3 Use PyInt_AS_LONG macro instead of explicit inlining.
Guido van Rossum <guido@python.org>
parents: 9513
diff changeset
1149 b = PyInt_AS_LONG(w);
5829
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1150 i = a - b;
19434
c140bd7d3bdc When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents: 19369
diff changeset
1151 if ((i^a) < 0 && (i^~b) < 0)
c140bd7d3bdc When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents: 19369
diff changeset
1152 goto slow_sub;
c140bd7d3bdc When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents: 19369
diff changeset
1153 x = PyInt_FromLong(i);
5829
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1154 }
19434
c140bd7d3bdc When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents: 19369
diff changeset
1155 else {
c140bd7d3bdc When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents: 19369
diff changeset
1156 slow_sub:
5829
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1157 x = PyNumber_Subtract(v, w);
19434
c140bd7d3bdc When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents: 19369
diff changeset
1158 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1159 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1160 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1161 SET_TOP(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1162 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1163 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1164
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1165 case BINARY_SUBSCR:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1166 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1167 v = TOP();
20275
167e7f98b51f Introduced the oddly-missing PyList_CheckExact(), and used it to replace
Tim Peters <tim.peters@gmail.com>
parents: 20273
diff changeset
1168 if (PyList_CheckExact(v) && PyInt_CheckExact(w)) {
5829
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1169 /* INLINE: list[int] */
36803
8eaf9531a2de Use Py_ssize_t since we are working with list size below
Neal Norwitz <nnorwitz@gmail.com>
parents: 36756
diff changeset
1170 Py_ssize_t i = PyInt_AsSsize_t(w);
5829
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1171 if (i < 0)
8652
97a1108b0eb2 # In case BINARY_SUBSCR, use proper PyList_GET* macros instead of inlining.
Guido van Rossum <guido@python.org>
parents: 8651
diff changeset
1172 i += PyList_GET_SIZE(v);
31878
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1173 if (i >= 0 && i < PyList_GET_SIZE(v)) {
8652
97a1108b0eb2 # In case BINARY_SUBSCR, use proper PyList_GET* macros instead of inlining.
Guido van Rossum <guido@python.org>
parents: 8651
diff changeset
1174 x = PyList_GET_ITEM(v, i);
5829
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1175 Py_INCREF(x);
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1176 }
31878
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1177 else
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1178 goto slow_get;
5829
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1179 }
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1180 else
31878
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1181 slow_get:
5829
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1182 x = PyObject_GetItem(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1183 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1184 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1185 SET_TOP(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1186 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1187 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1188
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1189 case BINARY_LSHIFT:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1190 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1191 v = TOP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1192 x = PyNumber_Lshift(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1193 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1194 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1195 SET_TOP(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1196 if (x != NULL) continue;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1197 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1198
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1199 case BINARY_RSHIFT:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1200 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1201 v = TOP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1202 x = PyNumber_Rshift(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1203 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1204 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1205 SET_TOP(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1206 if (x != NULL) continue;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1207 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1208
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1209 case BINARY_AND:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1210 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1211 v = TOP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1212 x = PyNumber_And(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1213 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1214 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1215 SET_TOP(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1216 if (x != NULL) continue;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1217 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1218
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1219 case BINARY_XOR:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1220 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1221 v = TOP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1222 x = PyNumber_Xor(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1223 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1224 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1225 SET_TOP(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1226 if (x != NULL) continue;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1227 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1228
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1229 case BINARY_OR:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1230 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1231 v = TOP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1232 x = PyNumber_Or(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1233 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1234 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1235 SET_TOP(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1236 if (x != NULL) continue;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1237 break;
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1238
31618
bc006682acb2 SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents: 31606
diff changeset
1239 case LIST_APPEND:
bc006682acb2 SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents: 31606
diff changeset
1240 w = POP();
bc006682acb2 SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents: 31606
diff changeset
1241 v = POP();
bc006682acb2 SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents: 31606
diff changeset
1242 err = PyList_Append(v, w);
bc006682acb2 SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents: 31606
diff changeset
1243 Py_DECREF(v);
bc006682acb2 SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents: 31606
diff changeset
1244 Py_DECREF(w);
31649
243642bbd03f LIST_APPEND is predicably followed by JUMP_ABSOLUTE.
Raymond Hettinger <python@rcn.com>
parents: 31647
diff changeset
1245 if (err == 0) {
243642bbd03f LIST_APPEND is predicably followed by JUMP_ABSOLUTE.
Raymond Hettinger <python@rcn.com>
parents: 31647
diff changeset
1246 PREDICT(JUMP_ABSOLUTE);
243642bbd03f LIST_APPEND is predicably followed by JUMP_ABSOLUTE.
Raymond Hettinger <python@rcn.com>
parents: 31647
diff changeset
1247 continue;
243642bbd03f LIST_APPEND is predicably followed by JUMP_ABSOLUTE.
Raymond Hettinger <python@rcn.com>
parents: 31647
diff changeset
1248 }
31618
bc006682acb2 SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents: 31606
diff changeset
1249 break;
bc006682acb2 SF patch #910929: Optimize list comprehensions
Raymond Hettinger <python@rcn.com>
parents: 31606
diff changeset
1250
41464
060c79f6d919 Hide list comp variables and support set comprehensions
Nick Coghlan <ncoghlan@gmail.com>
parents: 41226
diff changeset
1251 case SET_ADD:
060c79f6d919 Hide list comp variables and support set comprehensions
Nick Coghlan <ncoghlan@gmail.com>
parents: 41226
diff changeset
1252 w = POP();
060c79f6d919 Hide list comp variables and support set comprehensions
Nick Coghlan <ncoghlan@gmail.com>
parents: 41226
diff changeset
1253 v = POP();
060c79f6d919 Hide list comp variables and support set comprehensions
Nick Coghlan <ncoghlan@gmail.com>
parents: 41226
diff changeset
1254 err = PySet_Add(v, w);
060c79f6d919 Hide list comp variables and support set comprehensions
Nick Coghlan <ncoghlan@gmail.com>
parents: 41226
diff changeset
1255 Py_DECREF(v);
060c79f6d919 Hide list comp variables and support set comprehensions
Nick Coghlan <ncoghlan@gmail.com>
parents: 41226
diff changeset
1256 Py_DECREF(w);
060c79f6d919 Hide list comp variables and support set comprehensions
Nick Coghlan <ncoghlan@gmail.com>
parents: 41226
diff changeset
1257 if (err == 0) {
060c79f6d919 Hide list comp variables and support set comprehensions
Nick Coghlan <ncoghlan@gmail.com>
parents: 41226
diff changeset
1258 PREDICT(JUMP_ABSOLUTE);
060c79f6d919 Hide list comp variables and support set comprehensions
Nick Coghlan <ncoghlan@gmail.com>
parents: 41226
diff changeset
1259 continue;
060c79f6d919 Hide list comp variables and support set comprehensions
Nick Coghlan <ncoghlan@gmail.com>
parents: 41226
diff changeset
1260 }
060c79f6d919 Hide list comp variables and support set comprehensions
Nick Coghlan <ncoghlan@gmail.com>
parents: 41226
diff changeset
1261 break;
060c79f6d919 Hide list comp variables and support set comprehensions
Nick Coghlan <ncoghlan@gmail.com>
parents: 41226
diff changeset
1262
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1263 case INPLACE_POWER:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1264 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1265 v = TOP();
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1266 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
1267 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1268 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1269 SET_TOP(x);
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1270 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1271 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1272
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1273 case INPLACE_MULTIPLY:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1274 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1275 v = TOP();
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1276 x = PyNumber_InPlaceMultiply(v, w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1277 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1278 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1279 SET_TOP(x);
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1280 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1281 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1282
21537
ca27d82ac89b SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents: 21477
diff changeset
1283 case INPLACE_TRUE_DIVIDE:
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1284 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1285 v = TOP();
21537
ca27d82ac89b SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents: 21477
diff changeset
1286 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
1287 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1288 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1289 SET_TOP(x);
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1290 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1291 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1292
19051
f20727cc3d0f Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents: 18933
diff changeset
1293 case INPLACE_FLOOR_DIVIDE:
f20727cc3d0f Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents: 18933
diff changeset
1294 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1295 v = TOP();
19051
f20727cc3d0f Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents: 18933
diff changeset
1296 x = PyNumber_InPlaceFloorDivide(v, w);
f20727cc3d0f Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents: 18933
diff changeset
1297 Py_DECREF(v);
f20727cc3d0f Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents: 18933
diff changeset
1298 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1299 SET_TOP(x);
19051
f20727cc3d0f Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents: 18933
diff changeset
1300 if (x != NULL) continue;
f20727cc3d0f Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents: 18933
diff changeset
1301 break;
f20727cc3d0f Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents: 18933
diff changeset
1302
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1303 case INPLACE_MODULO:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1304 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1305 v = TOP();
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1306 x = PyNumber_InPlaceRemainder(v, w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1307 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1308 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1309 SET_TOP(x);
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1310 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1311 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1312
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1313 case INPLACE_ADD:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1314 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1315 v = TOP();
20273
2269cb371e05 Get rid of unique local ISSTRICTINT macro in favor of std PyInt_CheckExact.
Tim Peters <tim.peters@gmail.com>
parents: 20257
diff changeset
1316 if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1317 /* INLINE: int + int */
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1318 register long a, b, i;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1319 a = PyInt_AS_LONG(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1320 b = PyInt_AS_LONG(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1321 i = a + b;
19434
c140bd7d3bdc When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents: 19369
diff changeset
1322 if ((i^a) < 0 && (i^b) < 0)
c140bd7d3bdc When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents: 19369
diff changeset
1323 goto slow_iadd;
c140bd7d3bdc When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents: 19369
diff changeset
1324 x = PyInt_FromLong(i);
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1325 }
32974
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
1326 else if (PyString_CheckExact(v) &&
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
1327 PyString_CheckExact(w)) {
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
1328 x = string_concatenate(v, w, f, next_instr);
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
1329 /* string_concatenate consumed the ref to v */
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
1330 goto skip_decref_v;
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
1331 }
19434
c140bd7d3bdc When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents: 19369
diff changeset
1332 else {
c140bd7d3bdc When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents: 19369
diff changeset
1333 slow_iadd:
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1334 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
1335 }
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1336 Py_DECREF(v);
32974
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
1337 skip_decref_v:
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1338 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1339 SET_TOP(x);
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1340 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1341 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1342
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1343 case INPLACE_SUBTRACT:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1344 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1345 v = TOP();
20273
2269cb371e05 Get rid of unique local ISSTRICTINT macro in favor of std PyInt_CheckExact.
Tim Peters <tim.peters@gmail.com>
parents: 20257
diff changeset
1346 if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1347 /* INLINE: int - int */
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1348 register long a, b, i;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1349 a = PyInt_AS_LONG(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1350 b = PyInt_AS_LONG(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1351 i = a - b;
19434
c140bd7d3bdc When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents: 19369
diff changeset
1352 if ((i^a) < 0 && (i^~b) < 0)
c140bd7d3bdc When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents: 19369
diff changeset
1353 goto slow_isub;
c140bd7d3bdc When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents: 19369
diff changeset
1354 x = PyInt_FromLong(i);
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1355 }
19434
c140bd7d3bdc When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents: 19369
diff changeset
1356 else {
c140bd7d3bdc When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents: 19369
diff changeset
1357 slow_isub:
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1358 x = PyNumber_InPlaceSubtract(v, w);
19434
c140bd7d3bdc When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents: 19369
diff changeset
1359 }
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1360 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1361 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1362 SET_TOP(x);
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1363 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1364 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1365
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1366 case INPLACE_LSHIFT:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1367 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1368 v = TOP();
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1369 x = PyNumber_InPlaceLshift(v, w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1370 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1371 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1372 SET_TOP(x);
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1373 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1374 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1375
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1376 case INPLACE_RSHIFT:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1377 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1378 v = TOP();
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1379 x = PyNumber_InPlaceRshift(v, w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1380 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1381 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1382 SET_TOP(x);
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1383 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1384 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1385
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1386 case INPLACE_AND:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1387 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1388 v = TOP();
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1389 x = PyNumber_InPlaceAnd(v, w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1390 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1391 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1392 SET_TOP(x);
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1393 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1394 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1395
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1396 case INPLACE_XOR:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1397 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1398 v = TOP();
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1399 x = PyNumber_InPlaceXor(v, w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1400 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1401 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1402 SET_TOP(x);
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1403 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1404 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1405
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1406 case INPLACE_OR:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1407 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1408 v = TOP();
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1409 x = PyNumber_InPlaceOr(v, w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1410 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1411 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1412 SET_TOP(x);
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1413 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1414 break;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1415
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1416 case STORE_SUBSCR:
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1417 w = TOP();
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1418 v = SECOND();
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1419 u = THIRD();
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1420 STACKADJ(-3);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1421 /* v[w] = u */
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1422 err = PyObject_SetItem(v, w, u);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1423 Py_DECREF(u);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1424 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1425 Py_DECREF(w);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1426 if (err == 0) continue;
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
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1429 case DELETE_SUBSCR:
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1430 w = TOP();
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1431 v = SECOND();
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1432 STACKADJ(-2);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1433 /* del v[w] */
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1434 err = PyObject_DelItem(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1435 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1436 Py_DECREF(w);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1437 if (err == 0) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1438 break;
14100
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1439
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1440 case PRINT_EXPR:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1441 v = POP();
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1442 w = PySys_GetObject("displayhook");
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1443 if (w == NULL) {
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1444 PyErr_SetString(PyExc_RuntimeError,
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1445 "lost sys.displayhook");
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1446 err = -1;
15814
faaf9f10d849 Fixed bugs noted by Greg Stein
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15811
diff changeset
1447 x = NULL;
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1448 }
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1449 if (err == 0) {
30683
3b59fa5d25b1 Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents: 29669
diff changeset
1450 x = PyTuple_Pack(1, v);
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1451 if (x == NULL)
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1452 err = -1;
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1453 }
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1454 if (err == 0) {
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1455 w = PyEval_CallObject(w, x);
15814
faaf9f10d849 Fixed bugs noted by Greg Stein
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15811
diff changeset
1456 Py_XDECREF(w);
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1457 if (w == NULL)
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1458 err = -1;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1459 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1460 Py_DECREF(v);
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1461 Py_XDECREF(x);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1462 break;
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1463
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1464 #ifdef CASE_TOO_BIG
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1465 default: switch (opcode) {
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1466 #endif
2813
999b5bdc18ce 3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents: 2612
diff changeset
1467 case RAISE_VARARGS:
43102
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 43100
diff changeset
1468 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
1469 switch (oparg) {
43411
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
1470 case 2:
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
1471 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
1472 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
1473 w = POP(); /* exc */
7946
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
1474 case 0: /* Fallthrough */
43102
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 43100
diff changeset
1475 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
1476 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
1477 default:
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1478 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
1479 "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
1480 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
1481 break;
464
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1482 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1483 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1484
41226
19f7ff443718 Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents: 40946
diff changeset
1485 case STORE_LOCALS:
19f7ff443718 Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents: 40946
diff changeset
1486 x = POP();
19f7ff443718 Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents: 40946
diff changeset
1487 v = f->f_locals;
19f7ff443718 Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents: 40946
diff changeset
1488 Py_XDECREF(v);
19f7ff443718 Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents: 40946
diff changeset
1489 f->f_locals = x;
19f7ff443718 Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents: 40946
diff changeset
1490 continue;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1491
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1492 case RETURN_VALUE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1493 retval = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1494 why = WHY_RETURN;
31462
d5c047807c69 SF patch #864059: optimize eval_frame
Raymond Hettinger <python@rcn.com>
parents: 30979
diff changeset
1495 goto fast_block_end;
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
1496
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
1497 case YIELD_VALUE:
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
1498 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
1499 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
1500 why = WHY_YIELD;
31462
d5c047807c69 SF patch #864059: optimize eval_frame
Raymond Hettinger <python@rcn.com>
parents: 30979
diff changeset
1501 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
1502
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1503 case POP_BLOCK:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1504 {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1505 PyTryBlock *b = PyFrame_BlockPop(f);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1506 while (STACK_LEVEL() > b->b_level) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1507 v = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1508 Py_DECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1509 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1510 }
31880
4c6fdeb8e2e0 Use continue instead of break whereever possible.
Raymond Hettinger <python@rcn.com>
parents: 31879
diff changeset
1511 continue;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1512
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1513 case END_FINALLY:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1514 v = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1515 if (PyInt_Check(v)) {
31875
1fb2313ac3ce Simplify previous checkin (bitfields for WHY codes).
Raymond Hettinger <python@rcn.com>
parents: 31874
diff changeset
1516 why = (enum why_code) PyInt_AS_LONG(v);
31872
9f5fe6b23e59 Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents: 31797
diff changeset
1517 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
1518 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
1519 why == WHY_CONTINUE)
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1520 retval = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1521 }
40942
4b9d0dac79cc You can no longer catch non-BaseException objects; TypeError is raised if such
Brett Cannon <bcannon@gmail.com>
parents: 40937
diff changeset
1522 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
1523 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
1524 u = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1525 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
1526 why = WHY_RERAISE;
2872
d3b07ba3e12d fix bogus DECREF in finally clause
Guido van Rossum <guido@python.org>
parents: 2866
diff changeset
1527 break;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1528 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1529 else if (v != Py_None) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1530 PyErr_SetString(PyExc_SystemError,
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1531 "'finally' pops bad exception");
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1532 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1533 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1534 Py_DECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1535 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1536
41226
19f7ff443718 Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents: 40946
diff changeset
1537 case LOAD_BUILD_CLASS:
19f7ff443718 Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents: 40946
diff changeset
1538 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
1539 "__build_class__");
19f7ff443718 Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents: 40946
diff changeset
1540 if (x == NULL) {
19f7ff443718 Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents: 40946
diff changeset
1541 PyErr_SetString(PyExc_ImportError,
19f7ff443718 Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents: 40946
diff changeset
1542 "__build_class__ not found");
19f7ff443718 Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents: 40946
diff changeset
1543 break;
19f7ff443718 Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents: 40946
diff changeset
1544 }
19f7ff443718 Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents: 40946
diff changeset
1545 Py_INCREF(x);
19f7ff443718 Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents: 40946
diff changeset
1546 PUSH(x);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1547 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1548
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1549 case STORE_NAME:
24607
3e4d432872ea get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents: 24545
diff changeset
1550 w = GETITEM(names, oparg);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1551 v = POP();
31878
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1552 if ((x = f->f_locals) != NULL) {
32890
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32531
diff changeset
1553 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
1554 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
1555 else
d4a59230e93a SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents: 32421
diff changeset
1556 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
1557 Py_DECREF(v);
31880
4c6fdeb8e2e0 Use continue instead of break whereever possible.
Raymond Hettinger <python@rcn.com>
parents: 31879
diff changeset
1558 if (err == 0) continue;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1559 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1560 }
31878
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1561 PyErr_Format(PyExc_SystemError,
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1562 "no locals found when storing %s",
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1563 PyObject_REPR(w));
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1564 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1565
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1566 case DELETE_NAME:
24607
3e4d432872ea get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents: 24545
diff changeset
1567 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
1568 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
1569 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
1570 format_exc_check_arg(PyExc_NameError,
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1571 NAME_ERROR_MSG ,w);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1572 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1573 }
31878
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1574 PyErr_Format(PyExc_SystemError,
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1575 "no locals when deleting %s",
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1576 PyObject_REPR(w));
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1577 break;
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1578
28304
b14d6741f496 Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents: 28303
diff changeset
1579 PREDICTED_WITH_ARG(UNPACK_SEQUENCE);
13930
4eaa463c031a Merge UNPACK_LIST and UNPACK_TUPLE into a single UNPACK_SEQUENCE, since they
Thomas Wouters <thomas@python.org>
parents: 13881
diff changeset
1580 case UNPACK_SEQUENCE:
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1581 v = POP();
31630
b4e4dbd24fe7 Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents: 31618
diff changeset
1582 if (PyTuple_CheckExact(v) && PyTuple_GET_SIZE(v) == oparg) {
b4e4dbd24fe7 Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents: 31618
diff changeset
1583 PyObject **items = ((PyTupleObject *)v)->ob_item;
b4e4dbd24fe7 Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents: 31618
diff changeset
1584 while (oparg--) {
b4e4dbd24fe7 Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents: 31618
diff changeset
1585 w = items[oparg];
b4e4dbd24fe7 Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents: 31618
diff changeset
1586 Py_INCREF(w);
b4e4dbd24fe7 Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents: 31618
diff changeset
1587 PUSH(w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1588 }
31880
4c6fdeb8e2e0 Use continue instead of break whereever possible.
Raymond Hettinger <python@rcn.com>
parents: 31879
diff changeset
1589 Py_DECREF(v);
4c6fdeb8e2e0 Use continue instead of break whereever possible.
Raymond Hettinger <python@rcn.com>
parents: 31879
diff changeset
1590 continue;
31630
b4e4dbd24fe7 Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents: 31618
diff changeset
1591 } else if (PyList_CheckExact(v) && PyList_GET_SIZE(v) == oparg) {
b4e4dbd24fe7 Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents: 31618
diff changeset
1592 PyObject **items = ((PyListObject *)v)->ob_item;
b4e4dbd24fe7 Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents: 31618
diff changeset
1593 while (oparg--) {
b4e4dbd24fe7 Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents: 31618
diff changeset
1594 w = items[oparg];
b4e4dbd24fe7 Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents: 31618
diff changeset
1595 Py_INCREF(w);
b4e4dbd24fe7 Refactor and optimize code for UNPACK_SEQUENCE.
Raymond Hettinger <python@rcn.com>
parents: 31618
diff changeset
1596 PUSH(w);
6157
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1597 }
41699
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
1598 } else if (unpack_iterable(v, oparg, -1,
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41464
diff changeset
1599 stack_pointer + oparg)) {
18195
36e825660a24 Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents: 18194
diff changeset
1600 stack_pointer += oparg;
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41464
diff changeset
1601 } else {
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41464
diff changeset
1602 /* 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
1603 why = WHY_EXCEPTION;
20183
c6b6189a8397 SF bug [#466173] unpack TypeError unclear
Tim Peters <tim.peters@gmail.com>
parents: 20114
diff changeset
1604 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1605 Py_DECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1606 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1607
41699
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
1608 case UNPACK_EX:
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
1609 {
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
1610 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
1611 v = POP();
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
1612
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
1613 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
1614 stack_pointer + totalargs)) {
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
1615 stack_pointer += totalargs;
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
1616 } else {
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
1617 why = WHY_EXCEPTION;
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
1618 }
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
1619 Py_DECREF(v);
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
1620 break;
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
1621 }
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
1622
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1623 case STORE_ATTR:
24607
3e4d432872ea get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents: 24545
diff changeset
1624 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
1625 v = TOP();
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1626 u = SECOND();
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1627 STACKADJ(-2);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1628 err = PyObject_SetAttr(v, w, u); /* v.w = u */
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1629 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1630 Py_DECREF(u);
31880
4c6fdeb8e2e0 Use continue instead of break whereever possible.
Raymond Hettinger <python@rcn.com>
parents: 31879
diff changeset
1631 if (err == 0) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1632 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1633
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1634 case DELETE_ATTR:
24607
3e4d432872ea get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents: 24545
diff changeset
1635 w = GETITEM(names, oparg);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1636 v = POP();
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
1637 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
1638 /* del v.w */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1639 Py_DECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1640 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1641
464
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1642 case STORE_GLOBAL:
24607
3e4d432872ea get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents: 24545
diff changeset
1643 w = GETITEM(names, oparg);
464
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1644 v = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1645 err = PyDict_SetItem(f->f_globals, w, v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1646 Py_DECREF(v);
31880
4c6fdeb8e2e0 Use continue instead of break whereever possible.
Raymond Hettinger <python@rcn.com>
parents: 31879
diff changeset
1647 if (err == 0) continue;
464
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1648 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1649
464
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1650 case DELETE_GLOBAL:
24607
3e4d432872ea get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents: 24545
diff changeset
1651 w = GETITEM(names, oparg);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1652 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
1653 format_exc_check_arg(
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1654 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
1655 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1656
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1657 case LOAD_NAME:
24607
3e4d432872ea get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents: 24545
diff changeset
1658 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
1659 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
1660 PyErr_Format(PyExc_SystemError,
7234d7c3c29f clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15948
diff changeset
1661 "no locals when loading %s",
16394
f700e6b8de1f Undo recent change that banned using import to bind a global, as per
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16365
diff changeset
1662 PyObject_REPR(w));
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1663 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1664 }
32900
ac73f6662e11 Fix for the unfortunate fact that PyDict_GetItem and PyObject_GetItem
Michael W. Hudson <mwh@python.net>
parents: 32890
diff changeset
1665 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
1666 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
1667 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
1668 }
32463
d4a59230e93a SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents: 32421
diff changeset
1669 else {
d4a59230e93a SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents: 32421
diff changeset
1670 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
1671 if (x == NULL && PyErr_Occurred()) {
d4a59230e93a SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents: 32421
diff changeset
1672 if (!PyErr_ExceptionMatches(PyExc_KeyError))
d4a59230e93a SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents: 32421
diff changeset
1673 break;
d4a59230e93a SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents: 32421
diff changeset
1674 PyErr_Clear();
d4a59230e93a SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents: 32421
diff changeset
1675 }
d4a59230e93a SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents: 32421
diff changeset
1676 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1677 if (x == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1678 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
1679 if (x == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1680 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
1681 if (x == NULL) {
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1682 format_exc_check_arg(
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1683 PyExc_NameError,
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1684 NAME_ERROR_MSG ,w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1685 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1686 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1687 }
32900
ac73f6662e11 Fix for the unfortunate fact that PyDict_GetItem and PyObject_GetItem
Michael W. Hudson <mwh@python.net>
parents: 32890
diff changeset
1688 Py_INCREF(x);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1689 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1690 PUSH(x);
31878
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1691 continue;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1692
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1693 case LOAD_GLOBAL:
24607
3e4d432872ea get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents: 24545
diff changeset
1694 w = GETITEM(names, oparg);
42860
bf1a53cc6e65 Use unicode
Neal Norwitz <nnorwitz@gmail.com>
parents: 42334
diff changeset
1695 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
1696 /* 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
1697 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
1698 Do not try this at home. */
42860
bf1a53cc6e65 Use unicode
Neal Norwitz <nnorwitz@gmail.com>
parents: 42334
diff changeset
1699 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
1700 if (hash != -1) {
8f8fe990e82c Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents: 24870
diff changeset
1701 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
1702 PyDictEntry *e;
24899
8f8fe990e82c Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents: 24870
diff changeset
1703 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
1704 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
1705 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
1706 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
1707 break;
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1708 }
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1709 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
1710 if (x != NULL) {
8f8fe990e82c Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents: 24870
diff changeset
1711 Py_INCREF(x);
8f8fe990e82c Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents: 24870
diff changeset
1712 PUSH(x);
8f8fe990e82c Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents: 24870
diff changeset
1713 continue;
8f8fe990e82c Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents: 24870
diff changeset
1714 }
8f8fe990e82c Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents: 24870
diff changeset
1715 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
1716 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
1717 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
1718 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
1719 break;
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1720 }
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1721 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
1722 if (x != NULL) {
8f8fe990e82c Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents: 24870
diff changeset
1723 Py_INCREF(x);
8f8fe990e82c Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents: 24870
diff changeset
1724 PUSH(x);
8f8fe990e82c Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents: 24870
diff changeset
1725 continue;
8f8fe990e82c Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents: 24870
diff changeset
1726 }
8f8fe990e82c Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents: 24870
diff changeset
1727 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
1728 }
8f8fe990e82c Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents: 24870
diff changeset
1729 }
8f8fe990e82c Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents: 24870
diff changeset
1730 /* This is the un-inlined version of the code above */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1731 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
1732 if (x == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1733 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
1734 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
1735 load_global_error:
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1736 format_exc_check_arg(
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1737 PyExc_NameError,
24899
8f8fe990e82c Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents: 24870
diff changeset
1738 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
1739 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1740 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1741 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1742 Py_INCREF(x);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1743 PUSH(x);
31880
4c6fdeb8e2e0 Use continue instead of break whereever possible.
Raymond Hettinger <python@rcn.com>
parents: 31879
diff changeset
1744 continue;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1745
1262
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1746 case DELETE_FAST:
8318
ec87b62466d3 DELETE_FAST should issue an exception when the local variable is undefined.
Guido van Rossum <guido@python.org>
parents: 7982
diff changeset
1747 x = GETLOCAL(oparg);
31878
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1748 if (x != NULL) {
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1749 SETLOCAL(oparg, NULL);
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1750 continue;
8318
ec87b62466d3 DELETE_FAST should issue an exception when the local variable is undefined.
Guido van Rossum <guido@python.org>
parents: 7982
diff changeset
1751 }
31878
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1752 format_exc_check_arg(
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1753 PyExc_UnboundLocalError,
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1754 UNBOUNDLOCAL_ERROR_MSG,
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1755 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
1756 );
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1757 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1758
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1759 case LOAD_CLOSURE:
16355
e4420c2468f9 Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16257
diff changeset
1760 x = freevars[oparg];
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1761 Py_INCREF(x);
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1762 PUSH(x);
31880
4c6fdeb8e2e0 Use continue instead of break whereever possible.
Raymond Hettinger <python@rcn.com>
parents: 31879
diff changeset
1763 if (x != NULL) continue;
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1764 break;
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1765
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1766 case LOAD_DEREF:
16355
e4420c2468f9 Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16257
diff changeset
1767 x = freevars[oparg];
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1768 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
1769 if (w != NULL) {
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1770 PUSH(w);
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1771 continue;
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1772 }
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1773 err = -1;
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1774 /* 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
1775 if (PyErr_Occurred())
16453
2e3dd62ceac5 SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16398
diff changeset
1776 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
1777 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
1778 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
1779 oparg);
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1780 format_exc_check_arg(
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1781 PyExc_UnboundLocalError,
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1782 UNBOUNDLOCAL_ERROR_MSG,
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1783 v);
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1784 } 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
1785 v = PyTuple_GET_ITEM(
31878
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1786 co->co_freevars,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1787 oparg - PyTuple_GET_SIZE(co->co_cellvars));
31878
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1788 format_exc_check_arg(
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1789 PyExc_NameError,
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1790 UNBOUNDFREE_ERROR_MSG,
26ee1b3eb345 Small code improvements for readability, code size, and/or speed.
Raymond Hettinger <python@rcn.com>
parents: 31875
diff changeset
1791 v);
16453
2e3dd62ceac5 SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16398
diff changeset
1792 }
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1793 break;
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1794
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1795 case STORE_DEREF:
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1796 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
1797 x = freevars[oparg];
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1798 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
1799 Py_DECREF(w);
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1800 continue;
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1801
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1802 case BUILD_TUPLE:
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1803 x = PyTuple_New(oparg);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1804 if (x != NULL) {
31894
310dd98ea064 Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents: 31880
diff changeset
1805 for (; --oparg >= 0;) {
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1806 w = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1807 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
1808 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1809 PUSH(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1810 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1811 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1812 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1813
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1814 case BUILD_LIST:
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1815 x = PyList_New(oparg);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1816 if (x != NULL) {
31894
310dd98ea064 Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents: 31880
diff changeset
1817 for (; --oparg >= 0;) {
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1818 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
1819 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
1820 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1821 PUSH(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1822 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1823 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1824 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1825
39693
d0b83c4630c0 SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents: 39678
diff changeset
1826 case BUILD_SET:
d0b83c4630c0 SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents: 39678
diff changeset
1827 x = PySet_New(NULL);
d0b83c4630c0 SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents: 39678
diff changeset
1828 if (x != NULL) {
d0b83c4630c0 SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents: 39678
diff changeset
1829 for (; --oparg >= 0;) {
d0b83c4630c0 SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents: 39678
diff changeset
1830 w = POP();
d0b83c4630c0 SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents: 39678
diff changeset
1831 if (err == 0)
d0b83c4630c0 SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents: 39678
diff changeset
1832 err = PySet_Add(x, w);
d0b83c4630c0 SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents: 39678
diff changeset
1833 Py_DECREF(w);
d0b83c4630c0 SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents: 39678
diff changeset
1834 }
d0b83c4630c0 SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents: 39678
diff changeset
1835 if (err != 0) {
d0b83c4630c0 SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents: 39678
diff changeset
1836 Py_DECREF(x);
d0b83c4630c0 SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents: 39678
diff changeset
1837 break;
d0b83c4630c0 SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents: 39678
diff changeset
1838 }
d0b83c4630c0 SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents: 39678
diff changeset
1839 PUSH(x);
d0b83c4630c0 SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents: 39678
diff changeset
1840 continue;
d0b83c4630c0 SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents: 39678
diff changeset
1841 }
d0b83c4630c0 SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents: 39678
diff changeset
1842 break;
d0b83c4630c0 SF patch 1547796 by Georg Brandl -- set literals.
Guido van Rossum <guido@python.org>
parents: 39678
diff changeset
1843
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1844 case BUILD_MAP:
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1845 x = PyDict_New();
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1846 PUSH(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1847 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1848 break;
40894
0ea24f4f2467 Bytes literal.
Thomas Wouters <thomas@python.org>
parents: 40799
diff changeset
1849
0ea24f4f2467 Bytes literal.
Thomas Wouters <thomas@python.org>
parents: 40799
diff changeset
1850 case MAKE_BYTES:
0ea24f4f2467 Bytes literal.
Thomas Wouters <thomas@python.org>
parents: 40799
diff changeset
1851 w = POP();
0ea24f4f2467 Bytes literal.
Thomas Wouters <thomas@python.org>
parents: 40799
diff changeset
1852 if (PyString_Check(w))
0ea24f4f2467 Bytes literal.
Thomas Wouters <thomas@python.org>
parents: 40799
diff changeset
1853 x = PyBytes_FromStringAndSize(
0ea24f4f2467 Bytes literal.
Thomas Wouters <thomas@python.org>
parents: 40799
diff changeset
1854 PyString_AS_STRING(w),
0ea24f4f2467 Bytes literal.
Thomas Wouters <thomas@python.org>
parents: 40799
diff changeset
1855 PyString_GET_SIZE(w));
0ea24f4f2467 Bytes literal.
Thomas Wouters <thomas@python.org>
parents: 40799
diff changeset
1856 else
0ea24f4f2467 Bytes literal.
Thomas Wouters <thomas@python.org>
parents: 40799
diff changeset
1857 x = NULL;
0ea24f4f2467 Bytes literal.
Thomas Wouters <thomas@python.org>
parents: 40799
diff changeset
1858 Py_DECREF(w);
0ea24f4f2467 Bytes literal.
Thomas Wouters <thomas@python.org>
parents: 40799
diff changeset
1859 PUSH(x);
0ea24f4f2467 Bytes literal.
Thomas Wouters <thomas@python.org>
parents: 40799
diff changeset
1860 if (x != NULL) continue;
0ea24f4f2467 Bytes literal.
Thomas Wouters <thomas@python.org>
parents: 40799
diff changeset
1861 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1862
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1863 case LOAD_ATTR:
24607
3e4d432872ea get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents: 24545
diff changeset
1864 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
1865 v = TOP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1866 x = PyObject_GetAttr(v, w);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1867 Py_DECREF(v);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1868 SET_TOP(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1869 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1870 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1871
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1872 case COMPARE_OP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1873 w = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1874 v = TOP();
27295
b8387730dd8f SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents: 27243
diff changeset
1875 if (PyInt_CheckExact(w) && PyInt_CheckExact(v)) {
5829
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1876 /* INLINE: cmp(int, int) */
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1877 register long a, b;
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1878 register int res;
9591
7f90736701a3 Use PyInt_AS_LONG macro instead of explicit inlining.
Guido van Rossum <guido@python.org>
parents: 9513
diff changeset
1879 a = PyInt_AS_LONG(v);
7f90736701a3 Use PyInt_AS_LONG macro instead of explicit inlining.
Guido van Rossum <guido@python.org>
parents: 9513
diff changeset
1880 b = PyInt_AS_LONG(w);
5829
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1881 switch (oparg) {
21609
3ba0f1b20320 Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents: 21537
diff changeset
1882 case PyCmp_LT: res = a < b; break;
3ba0f1b20320 Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents: 21537
diff changeset
1883 case PyCmp_LE: res = a <= b; break;
3ba0f1b20320 Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents: 21537
diff changeset
1884 case PyCmp_EQ: res = a == b; break;
3ba0f1b20320 Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents: 21537
diff changeset
1885 case PyCmp_NE: res = a != b; break;
3ba0f1b20320 Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents: 21537
diff changeset
1886 case PyCmp_GT: res = a > b; break;
3ba0f1b20320 Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents: 21537
diff changeset
1887 case PyCmp_GE: res = a >= b; break;
3ba0f1b20320 Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents: 21537
diff changeset
1888 case PyCmp_IS: res = v == w; break;
3ba0f1b20320 Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents: 21537
diff changeset
1889 case PyCmp_IS_NOT: res = v != w; break;
5829
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1890 default: goto slow_compare;
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1891 }
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1892 x = res ? Py_True : Py_False;
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1893 Py_INCREF(x);
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1894 }
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1895 else {
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1896 slow_compare:
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1897 x = cmp_outcome(oparg, v, w);
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1898 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1899 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1900 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1901 SET_TOP(x);
28302
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
1902 if (x == NULL) break;
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
1903 PREDICT(JUMP_IF_FALSE);
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
1904 PREDICT(JUMP_IF_TRUE);
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
1905 continue;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1906
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1907 case IMPORT_NAME:
24607
3e4d432872ea get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents: 24545
diff changeset
1908 w = GETITEM(names, oparg);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1909 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
1910 if (x == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1911 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
1912 "__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
1913 break;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1914 }
36712
5c36c222e7ca SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents: 36702
diff changeset
1915 v = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1916 u = TOP();
36712
5c36c222e7ca SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents: 36702
diff changeset
1917 if (PyInt_AsLong(u) != -1 || PyErr_Occurred())
5c36c222e7ca SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents: 36702
diff changeset
1918 w = PyTuple_Pack(5,
5c36c222e7ca SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents: 36702
diff changeset
1919 w,
5c36c222e7ca SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents: 36702
diff changeset
1920 f->f_globals,
5c36c222e7ca SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents: 36702
diff changeset
1921 f->f_locals == NULL ?
5c36c222e7ca SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents: 36702
diff changeset
1922 Py_None : f->f_locals,
5c36c222e7ca SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents: 36702
diff changeset
1923 v,
5c36c222e7ca SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents: 36702
diff changeset
1924 u);
5c36c222e7ca SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents: 36702
diff changeset
1925 else
5c36c222e7ca SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents: 36702
diff changeset
1926 w = PyTuple_Pack(4,
5c36c222e7ca SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents: 36702
diff changeset
1927 w,
5c36c222e7ca SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents: 36702
diff changeset
1928 f->f_globals,
5c36c222e7ca SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents: 36702
diff changeset
1929 f->f_locals == NULL ?
5c36c222e7ca SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents: 36702
diff changeset
1930 Py_None : f->f_locals,
5c36c222e7ca SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents: 36702
diff changeset
1931 v);
5c36c222e7ca SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents: 36702
diff changeset
1932 Py_DECREF(v);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1933 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
1934 if (w == NULL) {
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1935 u = POP();
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1936 x = NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1937 break;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1938 }
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
1939 READ_TIMESTAMP(intr0);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1940 x = PyEval_CallObject(x, 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
1941 READ_TIMESTAMP(intr1);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1942 Py_DECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
1943 SET_TOP(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1944 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1945 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1946
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
1947 case IMPORT_STAR:
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
1948 v = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1949 PyFrame_FastToLocals(f);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1950 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
1951 PyErr_SetString(PyExc_SystemError,
16017
7234d7c3c29f clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15948
diff changeset
1952 "no locals found during 'import *'");
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1953 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1954 }
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
1955 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
1956 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
1957 READ_TIMESTAMP(intr1);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1958 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
1959 Py_DECREF(v);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1960 if (err == 0) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1961 break;
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
1962
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
1963 case IMPORT_FROM:
24607
3e4d432872ea get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents: 24545
diff changeset
1964 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
1965 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
1966 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
1967 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
1968 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
1969 PUSH(x);
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
1970 if (x != NULL) continue;
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
1971 break;
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
1972
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1973 case JUMP_FORWARD:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1974 JUMPBY(oparg);
29349
2f731c57cdc6 Use fast_next_opcode shortcut for forward jump opcodes (it's safe and
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 29339
diff changeset
1975 goto fast_next_opcode;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1976
28302
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
1977 PREDICTED_WITH_ARG(JUMP_IF_FALSE);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1978 case JUMP_IF_FALSE:
28077
fcb39b0a6e30 Micro-optimizations.
Raymond Hettinger <python@rcn.com>
parents: 27978
diff changeset
1979 w = TOP();
28302
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
1980 if (w == Py_True) {
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
1981 PREDICT(POP_TOP);
29349
2f731c57cdc6 Use fast_next_opcode shortcut for forward jump opcodes (it's safe and
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 29339
diff changeset
1982 goto fast_next_opcode;
28302
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
1983 }
28077
fcb39b0a6e30 Micro-optimizations.
Raymond Hettinger <python@rcn.com>
parents: 27978
diff changeset
1984 if (w == Py_False) {
fcb39b0a6e30 Micro-optimizations.
Raymond Hettinger <python@rcn.com>
parents: 27978
diff changeset
1985 JUMPBY(oparg);
29349
2f731c57cdc6 Use fast_next_opcode shortcut for forward jump opcodes (it's safe and
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 29339
diff changeset
1986 goto fast_next_opcode;
28077
fcb39b0a6e30 Micro-optimizations.
Raymond Hettinger <python@rcn.com>
parents: 27978
diff changeset
1987 }
fcb39b0a6e30 Micro-optimizations.
Raymond Hettinger <python@rcn.com>
parents: 27978
diff changeset
1988 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
1989 if (err > 0)
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1990 err = 0;
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1991 else if (err == 0)
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1992 JUMPBY(oparg);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1993 else
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1994 break;
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1995 continue;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1996
28302
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
1997 PREDICTED_WITH_ARG(JUMP_IF_TRUE);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1998 case JUMP_IF_TRUE:
28077
fcb39b0a6e30 Micro-optimizations.
Raymond Hettinger <python@rcn.com>
parents: 27978
diff changeset
1999 w = TOP();
28302
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
2000 if (w == Py_False) {
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
2001 PREDICT(POP_TOP);
29349
2f731c57cdc6 Use fast_next_opcode shortcut for forward jump opcodes (it's safe and
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 29339
diff changeset
2002 goto fast_next_opcode;
28302
8c082936daaf Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents: 28296
diff changeset
2003 }
28077
fcb39b0a6e30 Micro-optimizations.
Raymond Hettinger <python@rcn.com>
parents: 27978
diff changeset
2004 if (w == Py_True) {
fcb39b0a6e30 Micro-optimizations.
Raymond Hettinger <python@rcn.com>
parents: 27978
diff changeset
2005 JUMPBY(oparg);
29349
2f731c57cdc6 Use fast_next_opcode shortcut for forward jump opcodes (it's safe and
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 29339
diff changeset
2006 goto fast_next_opcode;
28077
fcb39b0a6e30 Micro-optimizations.
Raymond Hettinger <python@rcn.com>
parents: 27978
diff changeset
2007 }
fcb39b0a6e30 Micro-optimizations.
Raymond Hettinger <python@rcn.com>
parents: 27978
diff changeset
2008 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
2009 if (err > 0) {
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2010 err = 0;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2011 JUMPBY(oparg);
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2012 }
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
2013 else if (err == 0)
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
2014 ;
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
2015 else
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
2016 break;
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
2017 continue;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2018
31649
243642bbd03f LIST_APPEND is predicably followed by JUMP_ABSOLUTE.
Raymond Hettinger <python@rcn.com>
parents: 31647
diff changeset
2019 PREDICTED_WITH_ARG(JUMP_ABSOLUTE);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2020 case JUMP_ABSOLUTE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2021 JUMPTO(oparg);
29337
f9495815c18f Don't use fast_next_opcode for JUMP_* opcodes. This fixes the problem
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 28886
diff changeset
2022 continue;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2023
17597
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
2024 case GET_ITER:
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
2025 /* 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
2026 v = TOP();
17597
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
2027 x = PyObject_GetIter(v);
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
2028 Py_DECREF(v);
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
2029 if (x != NULL) {
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
2030 SET_TOP(x);
28304
b14d6741f496 Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents: 28303
diff changeset
2031 PREDICT(FOR_ITER);
17617
aac65f50df6f Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents: 17600
diff changeset
2032 continue;
17597
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
2033 }
27243
3afbd55fb18f Replaced POP() with STACKADJ(-1) on lines where the result wasn't used.
Raymond Hettinger <python@rcn.com>
parents: 27201
diff changeset
2034 STACKADJ(-1);
17597
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
2035 break;
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
2036
28304
b14d6741f496 Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents: 28303
diff changeset
2037 PREDICTED_WITH_ARG(FOR_ITER);
17597
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
2038 case FOR_ITER:
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
2039 /* before: [iter]; after: [iter, iter()] *or* [] */
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
2040 v = TOP();
31646
83b0382e0d36 Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents: 31630
diff changeset
2041 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
2042 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
2043 PUSH(x);
28304
b14d6741f496 Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents: 28303
diff changeset
2044 PREDICT(STORE_FAST);
b14d6741f496 Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents: 28303
diff changeset
2045 PREDICT(UNPACK_SEQUENCE);
17617
aac65f50df6f Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents: 17600
diff changeset
2046 continue;
17597
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
2047 }
31646
83b0382e0d36 Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents: 31630
diff changeset
2048 if (PyErr_Occurred()) {
83b0382e0d36 Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents: 31630
diff changeset
2049 if (!PyErr_ExceptionMatches(PyExc_StopIteration))
83b0382e0d36 Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents: 31630
diff changeset
2050 break;
83b0382e0d36 Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents: 31630
diff changeset
2051 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
2052 }
31646
83b0382e0d36 Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents: 31630
diff changeset
2053 /* iterator ended normally */
83b0382e0d36 Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents: 31630
diff changeset
2054 x = v = POP();
83b0382e0d36 Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents: 31630
diff changeset
2055 Py_DECREF(v);
83b0382e0d36 Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents: 31630
diff changeset
2056 JUMPBY(oparg);
83b0382e0d36 Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
Raymond Hettinger <python@rcn.com>
parents: 31630
diff changeset
2057 continue;
17597
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
2058
31647
d10c778af167 Move the code for BREAK and CONTINUE_LOOP to be near FOR_ITER.
Raymond Hettinger <python@rcn.com>
parents: 31646
diff changeset
2059 case BREAK_LOOP:
d10c778af167 Move the code for BREAK and CONTINUE_LOOP to be near FOR_ITER.
Raymond Hettinger <python@rcn.com>
parents: 31646
diff changeset
2060 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
2061 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
2062
d10c778af167 Move the code for BREAK and CONTINUE_LOOP to be near FOR_ITER.
Raymond Hettinger <python@rcn.com>
parents: 31646
diff changeset
2063 case CONTINUE_LOOP:
d10c778af167 Move the code for BREAK and CONTINUE_LOOP to be near FOR_ITER.
Raymond Hettinger <python@rcn.com>
parents: 31646
diff changeset
2064 retval = PyInt_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
2065 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
2066 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
2067 break;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2068 }
31647
d10c778af167 Move the code for BREAK and CONTINUE_LOOP to be near FOR_ITER.
Raymond Hettinger <python@rcn.com>
parents: 31646
diff changeset
2069 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
2070 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
2071
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2072 case SETUP_LOOP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2073 case SETUP_EXCEPT:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2074 case SETUP_FINALLY:
40742
f1701ba2452b Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40729
diff changeset
2075 /* NOTE: If you add any new block-setup opcodes that are
f1701ba2452b Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40729
diff changeset
2076 not try/except/finally handlers, you may need to
f1701ba2452b Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40729
diff changeset
2077 update the PyGen_NeedsFinalizing() function. */
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
2078
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2079 PyFrame_BlockSetup(f, opcode, INSTR_OFFSET() + oparg,
16398
80c0b280a4f9 Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16394
diff changeset
2080 STACK_LEVEL());
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
2081 continue;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2082
36695
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2083 case WITH_CLEANUP:
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2084 {
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2085 /* TOP is the context.__exit__ bound method.
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2086 Below that are 1-3 values indicating how/why
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2087 we entered the finally clause:
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2088 - SECOND = None
36926
fc10ff322df1 Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents: 36882
diff changeset
2089 - (SECOND, THIRD) = (WHY_{RETURN,CONTINUE}), retval
36695
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2090 - SECOND = WHY_*; no retval below it
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2091 - (SECOND, THIRD, FOURTH) = exc_info()
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2092 In the last case, we must call
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2093 TOP(SECOND, THIRD, FOURTH)
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2094 otherwise we must call
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2095 TOP(None, None, None)
36737
fa92fe15251a Updates to the with-statement:
Guido van Rossum <guido@python.org>
parents: 36712
diff changeset
2096
fa92fe15251a Updates to the with-statement:
Guido van Rossum <guido@python.org>
parents: 36712
diff changeset
2097 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
2098 *and* the function call returns a 'true' value, we
fc10ff322df1 Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents: 36882
diff changeset
2099 "zap" this information, to prevent END_FINALLY from
fc10ff322df1 Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents: 36882
diff changeset
2100 re-raising the exception. (But non-local gotos
fc10ff322df1 Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents: 36882
diff changeset
2101 should still be resumed.)
36695
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2102 */
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2103
36695
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2104 x = TOP();
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2105 u = SECOND();
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2106 if (PyInt_Check(u) || u == Py_None) {
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2107 u = v = w = Py_None;
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2108 }
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2109 else {
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2110 v = THIRD();
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2111 w = FOURTH();
36926
fc10ff322df1 Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents: 36882
diff changeset
2112 }
fc10ff322df1 Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents: 36882
diff changeset
2113 /* XXX Not the fastest way to call it... */
fc10ff322df1 Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents: 36882
diff changeset
2114 x = PyObject_CallFunctionObjArgs(x, u, v, w, NULL);
fc10ff322df1 Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents: 36882
diff changeset
2115 if (x == NULL)
fc10ff322df1 Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents: 36882
diff changeset
2116 break; /* Go to error exit */
fc10ff322df1 Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents: 36882
diff changeset
2117 if (u != Py_None && PyObject_IsTrue(x)) {
fc10ff322df1 Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents: 36882
diff changeset
2118 /* There was an exception and a true return */
fc10ff322df1 Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents: 36882
diff changeset
2119 Py_DECREF(x);
fc10ff322df1 Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents: 36882
diff changeset
2120 x = TOP(); /* Again */
fc10ff322df1 Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents: 36882
diff changeset
2121 STACKADJ(-3);
36737
fa92fe15251a Updates to the with-statement:
Guido van Rossum <guido@python.org>
parents: 36712
diff changeset
2122 Py_INCREF(Py_None);
36926
fc10ff322df1 Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents: 36882
diff changeset
2123 SET_TOP(Py_None);
fc10ff322df1 Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents: 36882
diff changeset
2124 Py_DECREF(x);
fc10ff322df1 Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents: 36882
diff changeset
2125 Py_DECREF(u);
fc10ff322df1 Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents: 36882
diff changeset
2126 Py_DECREF(v);
fc10ff322df1 Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents: 36882
diff changeset
2127 Py_DECREF(w);
fc10ff322df1 Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents: 36882
diff changeset
2128 } else {
fc10ff322df1 Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents: 36882
diff changeset
2129 /* Let END_FINALLY do its thing */
fc10ff322df1 Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents: 36882
diff changeset
2130 Py_DECREF(x);
fc10ff322df1 Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents: 36882
diff changeset
2131 x = POP();
fc10ff322df1 Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents: 36882
diff changeset
2132 Py_DECREF(x);
36695
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2133 }
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2134 break;
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2135 }
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2136
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
2137 case CALL_FUNCTION:
32359
e5bc947c44ca Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents: 32301
diff changeset
2138 {
e5bc947c44ca Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents: 32301
diff changeset
2139 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
2140 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
2141 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
2142 #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
2143 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
2144 #else
32359
e5bc947c44ca Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents: 32301
diff changeset
2145 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
2146 #endif
32359
e5bc947c44ca Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents: 32301
diff changeset
2147 stack_pointer = sp;
24868
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
2148 PUSH(x);
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
2149 if (x != NULL)
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
2150 continue;
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
2151 break;
32359
e5bc947c44ca Performance tweak: allow stack_pointer and oparg to be register variables.
Armin Rigo <arigo@tunes.org>
parents: 32301
diff changeset
2152 }
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2153
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
2154 case CALL_FUNCTION_VAR:
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
2155 case CALL_FUNCTION_KW:
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
2156 case CALL_FUNCTION_VAR_KW:
2813
999b5bdc18ce 3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents: 2612
diff changeset
2157 {
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
2158 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
2159 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
2160 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
2161 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
2162 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
2163 PCALL(PCALL_ALL);
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2164 if (flags & CALL_FLAG_VAR)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2165 n++;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2166 if (flags & CALL_FLAG_KW)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2167 n++;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2168 pfunc = stack_pointer - n - 1;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2169 func = *pfunc;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2170
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2171 if (PyMethod_Check(func)
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2172 && PyMethod_GET_SELF(func) != NULL) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2173 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
2174 Py_INCREF(self);
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2175 func = PyMethod_GET_FUNCTION(func);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2176 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
2177 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
2178 *pfunc = self;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
2179 na++;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
2180 n++;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2181 } else
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2182 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
2183 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
2184 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
2185 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
2186 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
2187 stack_pointer = sp;
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2188 Py_DECREF(func);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2189
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2190 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
2191 w = POP();
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2192 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
2193 }
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
2194 PUSH(x);
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2195 if (x != NULL)
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2196 continue;
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
2197 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
2198 }
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2199
40943
c79e6234fb19 Two more patches by Tony Lownds (SF# 1607548).
Guido van Rossum <guido@python.org>
parents: 40942
diff changeset
2200 case MAKE_CLOSURE:
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2201 case MAKE_FUNCTION:
40215
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2202 {
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2203 int posdefaults = oparg & 0xff;
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2204 int kwdefaults = (oparg>>8) & 0xff;
40529
54cd47788811 PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents: 40450
diff changeset
2205 int num_annotations = (oparg >> 16) & 0x7fff;
40215
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2206
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2207 v = POP(); /* code object */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2208 x = PyFunction_New(v, f->f_globals);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2209 Py_DECREF(v);
40943
c79e6234fb19 Two more patches by Tony Lownds (SF# 1607548).
Guido van Rossum <guido@python.org>
parents: 40942
diff changeset
2210
c79e6234fb19 Two more patches by Tony Lownds (SF# 1607548).
Guido van Rossum <guido@python.org>
parents: 40942
diff changeset
2211 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
2212 v = POP();
c79e6234fb19 Two more patches by Tony Lownds (SF# 1607548).
Guido van Rossum <guido@python.org>
parents: 40942
diff changeset
2213 err = PyFunction_SetClosure(x, v);
c79e6234fb19 Two more patches by Tony Lownds (SF# 1607548).
Guido van Rossum <guido@python.org>
parents: 40942
diff changeset
2214 Py_DECREF(v);
c79e6234fb19 Two more patches by Tony Lownds (SF# 1607548).
Guido van Rossum <guido@python.org>
parents: 40942
diff changeset
2215 }
40529
54cd47788811 PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents: 40450
diff changeset
2216
54cd47788811 PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents: 40450
diff changeset
2217 if (x != NULL && num_annotations > 0) {
54cd47788811 PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents: 40450
diff changeset
2218 Py_ssize_t name_ix;
54cd47788811 PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents: 40450
diff changeset
2219 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
2220 v = PyDict_New();
54cd47788811 PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents: 40450
diff changeset
2221 if (v == NULL) {
54cd47788811 PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents: 40450
diff changeset
2222 Py_DECREF(x);
54cd47788811 PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents: 40450
diff changeset
2223 x = NULL;
54cd47788811 PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents: 40450
diff changeset
2224 break;
54cd47788811 PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents: 40450
diff changeset
2225 }
54cd47788811 PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents: 40450
diff changeset
2226 name_ix = PyTuple_Size(u);
54cd47788811 PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents: 40450
diff changeset
2227 assert(num_annotations == name_ix+1);
54cd47788811 PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents: 40450
diff changeset
2228 while (name_ix > 0) {
54cd47788811 PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents: 40450
diff changeset
2229 --name_ix;
54cd47788811 PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents: 40450
diff changeset
2230 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
2231 w = POP();
54cd47788811 PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents: 40450
diff changeset
2232 /* XXX(nnorwitz): check for errors */
54cd47788811 PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents: 40450
diff changeset
2233 PyDict_SetItem(v, t, w);
54cd47788811 PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents: 40450
diff changeset
2234 Py_DECREF(w);
54cd47788811 PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents: 40450
diff changeset
2235 }
54cd47788811 PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents: 40450
diff changeset
2236
54cd47788811 PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents: 40450
diff changeset
2237 err = PyFunction_SetAnnotations(x, v);
54cd47788811 PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents: 40450
diff changeset
2238 Py_DECREF(v);
54cd47788811 PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents: 40450
diff changeset
2239 Py_DECREF(u);
54cd47788811 PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents: 40450
diff changeset
2240 }
54cd47788811 PEP 3107 - Function Annotations thanks to Tony Lownds
Neal Norwitz <nnorwitz@gmail.com>
parents: 40450
diff changeset
2241
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2242 /* 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
2243 if (x != NULL && posdefaults > 0) {
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2244 v = PyTuple_New(posdefaults);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2245 if (v == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2246 Py_DECREF(x);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2247 x = NULL;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2248 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2249 }
40215
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2250 while (--posdefaults >= 0) {
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2251 w = POP();
40215
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2252 PyTuple_SET_ITEM(v, posdefaults, w);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2253 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2254 err = PyFunction_SetDefaults(x, v);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2255 Py_DECREF(v);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2256 }
40215
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2257 if (x != NULL && kwdefaults > 0) {
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2258 v = PyDict_New();
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2259 if (v == NULL) {
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2260 Py_DECREF(x);
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2261 x = NULL;
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2262 break;
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2263 }
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2264 while (--kwdefaults >= 0) {
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2265 w = POP(); /* default value */
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2266 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
2267 /* XXX(nnorwitz): check for errors */
40215
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2268 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
2269 Py_DECREF(w);
93f582803733 Fix a refleak in the MAKE_FUNCTION opcode in ceval.c.
Georg Brandl <georg@python.org>
parents: 40894
diff changeset
2270 Py_DECREF(u);
40215
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2271 }
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2272 err = PyFunction_SetKwDefaults(x, v);
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2273 Py_DECREF(v);
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2274 }
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2275 PUSH(x);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2276 break;
40215
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2277 }
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2278
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2279 case BUILD_SLICE:
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2280 if (oparg == 3)
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2281 w = POP();
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2282 else
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2283 w = NULL;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2284 v = POP();
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
2285 u = TOP();
5018
001a5042b181 Cleanup:
Guido van Rossum <guido@python.org>
parents: 5014
diff changeset
2286 x = PySlice_New(u, v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2287 Py_DECREF(u);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2288 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2289 Py_XDECREF(w);
27186
04aa86d49d93 SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents: 26141
diff changeset
2290 SET_TOP(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
2291 if (x != NULL) continue;
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2292 break;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2293
14147
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14100
diff changeset
2294 case EXTENDED_ARG:
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14100
diff changeset
2295 opcode = NEXTOP();
31894
310dd98ea064 Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents: 31880
diff changeset
2296 oparg = oparg<<16 | NEXTARG();
14147
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14100
diff changeset
2297 goto dispatch_opcode;
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2298
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2299 default:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2300 fprintf(stderr,
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2301 "XXX lineno: %d, opcode: %d\n",
24844
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24718
diff changeset
2302 PyCode_Addr2Line(f->f_code, f->f_lasti),
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24718
diff changeset
2303 opcode);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2304 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
2305 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2306 break;
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2307
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2308 #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
2309 }
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2310 #endif
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2311
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2312 } /* switch */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2313
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2314 on_error:
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2315
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
2316 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
2317
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2318 /* Quickly continue if no error occurred */
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2319
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2320 if (why == WHY_NOT) {
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2321 if (err == 0 && x != NULL) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2322 #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
2323 /* This check is expensive! */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2324 if (PyErr_Occurred())
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2325 fprintf(stderr,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2326 "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
2327 else {
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
2328 #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
2329 READ_TIMESTAMP(loop1);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2330 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
2331 #ifdef CHECKEXC
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
2332 }
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
2333 #endif
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2334 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2335 why = WHY_EXCEPTION;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2336 x = Py_None;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2337 err = 0;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2338 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2339
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2340 /* Double-check exception status */
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2341
31900
0265bf9912ea Some (but not all) of the why code bitfield tests ran faster as
Raymond Hettinger <python@rcn.com>
parents: 31894
diff changeset
2342 if (why == WHY_EXCEPTION || why == WHY_RERAISE) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2343 if (!PyErr_Occurred()) {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2344 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
2345 "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
2346 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2347 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2348 }
10363
4daab7a9f566 Always test for an error return (usually NULL or -1) without setting
Guido van Rossum <guido@python.org>
parents: 9679
diff changeset
2349 #ifdef CHECKEXC
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2350 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
2351 /* This check is expensive! */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2352 if (PyErr_Occurred()) {
30861
c89fd7eaf875 Make undetected error on stack unwind a fatal error.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 30801
diff changeset
2353 char buf[1024];
c89fd7eaf875 Make undetected error on stack unwind a fatal error.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 30801
diff changeset
2354 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
2355 "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
2356 Py_FatalError(buf);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2357 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2358 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2359 #endif
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2360
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2361 /* 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
2362
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2363 if (why == WHY_EXCEPTION) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2364 PyTraceBack_Here(f);
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2365
20247
a4d328d50897 Rationalize the events passed to the profiler (no changes for the tracer).
Fred Drake <fdrake@acm.org>
parents: 20183
diff changeset
2366 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
2367 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
2368 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
2369 }
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2370
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2371 /* 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
2372
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2373 if (why == WHY_RERAISE)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2374 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2375
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2376 /* Unwind stacks if a (pseudo) exception occurred */
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2377
31462
d5c047807c69 SF patch #864059: optimize eval_frame
Raymond Hettinger <python@rcn.com>
parents: 30979
diff changeset
2378 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
2379 while (why != WHY_NOT && f->f_iblock > 0) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2380 PyTryBlock *b = PyFrame_BlockPop(f);
16398
80c0b280a4f9 Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16394
diff changeset
2381
31872
9f5fe6b23e59 Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents: 31797
diff changeset
2382 assert(why != WHY_YIELD);
16398
80c0b280a4f9 Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16394
diff changeset
2383 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
2384 /* For a continue inside a try block,
80c0b280a4f9 Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16394
diff changeset
2385 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
2386 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
2387 b->b_level);
16398
80c0b280a4f9 Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16394
diff changeset
2388 why = WHY_NOT;
80c0b280a4f9 Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16394
diff changeset
2389 JUMPTO(PyInt_AS_LONG(retval));
80c0b280a4f9 Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16394
diff changeset
2390 Py_DECREF(retval);
80c0b280a4f9 Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16394
diff changeset
2391 break;
80c0b280a4f9 Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16394
diff changeset
2392 }
80c0b280a4f9 Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16394
diff changeset
2393
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2394 while (STACK_LEVEL() > b->b_level) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2395 v = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2396 Py_XDECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2397 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2398 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
2399 why = WHY_NOT;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2400 JUMPTO(b->b_handler);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2401 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2402 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2403 if (b->b_type == SETUP_FINALLY ||
4594
41857075d45b Change the Don Beaudry hack into the Don B + Jim F hack; now, if *any*
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
2404 (b->b_type == SETUP_EXCEPT &&
41857075d45b Change the Don Beaudry hack into the Don B + Jim F hack; now, if *any*
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
2405 why == WHY_EXCEPTION)) {
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2406 if (why == WHY_EXCEPTION) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2407 PyObject *exc, *val, *tb;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2408 PyErr_Fetch(&exc, &val, &tb);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2409 if (val == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2410 val = Py_None;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2411 Py_INCREF(val);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2412 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2413 /* Make the raw exception data
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2414 available to the handler,
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2415 so a program can emulate the
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2416 Python main loop. Don't do
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2417 this for 'finally'. */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2418 if (b->b_type == SETUP_EXCEPT) {
6185
32aacd753f34 eval_code2(), set_exc_info(): Call PyErr_NormalizeException() the
Barry Warsaw <barry@python.org>
parents: 6160
diff changeset
2419 PyErr_NormalizeException(
32aacd753f34 eval_code2(), set_exc_info(): Call PyErr_NormalizeException() the
Barry Warsaw <barry@python.org>
parents: 6160
diff changeset
2420 &exc, &val, &tb);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2421 set_exc_info(tstate,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2422 exc, val, tb);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2423 }
20114
233f9606ba8e Prevent a NULL pointer from being pushed onto the stack.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20064
diff changeset
2424 if (tb == NULL) {
233f9606ba8e Prevent a NULL pointer from being pushed onto the stack.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20064
diff changeset
2425 Py_INCREF(Py_None);
233f9606ba8e Prevent a NULL pointer from being pushed onto the stack.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20064
diff changeset
2426 PUSH(Py_None);
233f9606ba8e Prevent a NULL pointer from being pushed onto the stack.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20064
diff changeset
2427 } else
233f9606ba8e Prevent a NULL pointer from being pushed onto the stack.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20064
diff changeset
2428 PUSH(tb);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2429 PUSH(val);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2430 PUSH(exc);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2431 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2432 else {
31874
c88d4610f283 Coded WHY flags as bitfields (taking inspiration from tp_flags).
Raymond Hettinger <python@rcn.com>
parents: 31872
diff changeset
2433 if (why & (WHY_RETURN | WHY_CONTINUE))
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2434 PUSH(retval);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2435 v = PyInt_FromLong((long)why);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2436 PUSH(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2437 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2438 why = WHY_NOT;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2439 JUMPTO(b->b_handler);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2440 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2441 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2442 } /* unwind stack */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2443
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2444 /* 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
2445
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2446 if (why != WHY_NOT)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2447 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
2448 READ_TIMESTAMP(loop1);
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2449
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2450 } /* main loop */
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2451
31872
9f5fe6b23e59 Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents: 31797
diff changeset
2452 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
2453 /* 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
2454 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
2455 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
2456 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
2457 }
97709fd8fda0 Fix for SF bug #489671 (Neil Norwitz): memory leak in test_richcmp.
Guido van Rossum <guido@python.org>
parents: 21252
diff changeset
2458
31872
9f5fe6b23e59 Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents: 31797
diff changeset
2459 if (why != WHY_RETURN)
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2460 retval = NULL;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2461
31462
d5c047807c69 SF patch #864059: optimize eval_frame
Raymond Hettinger <python@rcn.com>
parents: 30979
diff changeset
2462 fast_yield:
18374
3b295ce2705f This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents: 18326
diff changeset
2463 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
2464 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
2465 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
2466 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
2467 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
2468 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
2469 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
2470 retval = NULL;
700f08369092 Port from the Python 2.4 branch, patches for SF bug # 900092,
Barry Warsaw <barry@python.org>
parents: 35298
diff changeset
2471 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
2472 }
700f08369092 Port from the Python 2.4 branch, patches for SF bug # 900092,
Barry Warsaw <barry@python.org>
parents: 35298
diff changeset
2473 }
700f08369092 Port from the Python 2.4 branch, patches for SF bug # 900092,
Barry Warsaw <barry@python.org>
parents: 35298
diff changeset
2474 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
2475 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
2476 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
2477 PyTrace_RETURN, NULL);
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2478 }
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2479 }
20247
a4d328d50897 Rationalize the events passed to the profiler (no changes for the tracer).
Fred Drake <fdrake@acm.org>
parents: 20183
diff changeset
2480 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
2481 if (why == WHY_EXCEPTION)
e3f63a95455f Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
2482 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
2483 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
2484 PyTrace_RETURN, NULL);
20257
e3f63a95455f Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
2485 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
2486 tstate->c_profileobj, f,
e3f63a95455f Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
2487 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
2488 Py_XDECREF(retval);
3b295ce2705f This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents: 18326
diff changeset
2489 retval = NULL;
3b295ce2705f This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents: 18326
diff changeset
2490 why = WHY_EXCEPTION;
3b295ce2705f This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents: 18326
diff changeset
2491 }
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2492 }
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2493 }
5023
75c1ee882a4a Kill all local variables on function return. This closes a gigantic
Guido van Rossum <guido@python.org>
parents: 5021
diff changeset
2494
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2495 if (tstate->frame->f_exc_type != NULL)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2496 reset_exc_info(tstate);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2497 else {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2498 assert(tstate->frame->f_exc_value == NULL);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2499 assert(tstate->frame->f_exc_traceback == NULL);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2500 }
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2501
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
2502 /* pop frame */
43410
b06b191b7cfa Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
2503 exit_eval_frame:
30801
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 30782
diff changeset
2504 Py_LeaveRecursiveCall();
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2505 tstate->frame = f->f_back;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2506
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2507 return retval;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2508 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2509
36695
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36580
diff changeset
2510 /* 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
2511 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
2512 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
2513
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 18611
diff changeset
2514 PyObject *
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 18611
diff changeset
2515 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
2516 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
2517 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
2518 {
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2519 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
2520 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
2521 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
2522 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
2523 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
2524
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2525 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
2526 PyErr_SetString(PyExc_SystemError,
19198
3c1c9948ff65 Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19158
diff changeset
2527 "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
2528 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
2529 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2530
39610
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
2531 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
2532 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
2533 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
2534 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
2535 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
2536
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2537 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
2538 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
2539
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2540 if (co->co_argcount > 0 ||
40215
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2541 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
2542 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
2543 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
2544 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
2545 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
2546 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
2547 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
2548 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
2549 goto fail;
40215
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2550 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
2551 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
2552 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
2553 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
2554 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2555 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
2556 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
2557 PyErr_Format(PyExc_TypeError,
41878
089f449a20cd Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents: 41824
diff changeset
2558 "%S() takes %s %d "
40215
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2559 "%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
2560 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
2561 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
2562 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
2563 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
2564 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
2565 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
2566 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
2567 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2568 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
2569 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2570 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
2571 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
2572 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
2573 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
2574 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2575 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
2576 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
2577 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
2578 goto fail;
40215
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2579 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
2580 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
2581 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
2582 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
2583 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
2584 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2585 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2586 for (i = 0; i < kwcount; 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
2587 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
2588 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
2589 int j;
42860
bf1a53cc6e65 Use unicode
Neal Norwitz <nnorwitz@gmail.com>
parents: 42334
diff changeset
2590 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
2591 PyErr_Format(PyExc_TypeError,
41878
089f449a20cd Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents: 41824
diff changeset
2592 "%S() keywords must be strings",
089f449a20cd Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents: 41824
diff changeset
2593 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
2594 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
2595 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2596 /* XXX slow -- speed up using dictionary? */
40215
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2597 for (j = 0;
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2598 j < co->co_argcount + co->co_kwonlyargcount;
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2599 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
2600 PyObject *nm = PyTuple_GET_ITEM(
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2601 co->co_varnames, j);
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2602 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
2603 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
2604 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
2605 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
2606 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
2607 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
2608 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2609 /* 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
2610 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
2611 goto fail;
40215
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2612 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
2613 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
2614 PyErr_Format(PyExc_TypeError,
41878
089f449a20cd Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents: 41824
diff changeset
2615 "%S() got an unexpected "
089f449a20cd Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents: 41824
diff changeset
2616 "keyword argument '%S'",
089f449a20cd Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents: 41824
diff changeset
2617 co->co_name,
089f449a20cd Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents: 41824
diff changeset
2618 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
2619 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
2620 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2621 PyDict_SetItem(kwdict, keyword, value);
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2622 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2623 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
2624 if (GETLOCAL(j) != 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
2625 PyErr_Format(PyExc_TypeError,
41878
089f449a20cd Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents: 41824
diff changeset
2626 "%S() got multiple "
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
2627 "values for keyword "
41878
089f449a20cd Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents: 41824
diff changeset
2628 "argument '%S'",
089f449a20cd Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents: 41824
diff changeset
2629 co->co_name,
089f449a20cd Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents: 41824
diff changeset
2630 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
2631 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
2632 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2633 Py_INCREF(value);
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2634 SETLOCAL(j, value);
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2635 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2636 }
40215
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2637 if (co->co_kwonlyargcount > 0) {
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2638 for (i = co->co_argcount;
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2639 i < co->co_argcount + co->co_kwonlyargcount;
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2640 i++) {
40381
259d26900861 Make it compile with older compilers.
Guido van Rossum <guido@python.org>
parents: 40215
diff changeset
2641 PyObject *name, *def;
40215
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2642 if (GETLOCAL(i) != NULL)
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2643 continue;
40381
259d26900861 Make it compile with older compilers.
Guido van Rossum <guido@python.org>
parents: 40215
diff changeset
2644 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
2645 def = NULL;
40215
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2646 if (kwdefs != NULL)
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2647 def = PyDict_GetItem(kwdefs, name);
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2648 if (def != NULL) {
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2649 Py_INCREF(def);
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2650 SETLOCAL(i, def);
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2651 continue;
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2652 }
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2653 PyErr_Format(PyExc_TypeError,
41878
089f449a20cd Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents: 41824
diff changeset
2654 "%S() needs keyword-only argument %S",
089f449a20cd Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents: 41824
diff changeset
2655 co->co_name, name);
40215
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2656 goto fail;
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2657 }
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2658 }
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
2659 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
2660 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
2661 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
2662 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
2663 PyErr_Format(PyExc_TypeError,
41878
089f449a20cd Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents: 41824
diff changeset
2664 "%S() takes %s %d "
40215
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2665 "%spositional argument%s "
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
2666 "(%d given)",
41878
089f449a20cd Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents: 41824
diff changeset
2667 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
2668 ((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
2669 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
2670 : "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
2671 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
2672 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
2673 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
2674 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2675 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2676 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
2677 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
2678 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
2679 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
2680 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
2681 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
2682 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
2683 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
2684 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
2685 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2686 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2687 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2688 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2689 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
2690 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
2691 PyErr_Format(PyExc_TypeError,
41878
089f449a20cd Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents: 41824
diff changeset
2692 "%S() takes no arguments (%d given)",
089f449a20cd Change PyErr_Format() to generate a unicode string (by using
Walter Dörwald <walter@livinglogic.de>
parents: 41824
diff changeset
2693 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
2694 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
2695 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
2696 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2697 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2698 /* 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
2699 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
2700 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
2701 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
2702 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
2703 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
2704
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2705 nargs = co->co_argcount;
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2706 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
2707 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
2708 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
2709 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
2710
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35609
diff changeset
2711 /* Initialize each cell var, taking into account
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35609
diff changeset
2712 cell vars that are initialized from arguments.
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35609
diff changeset
2713
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35609
diff changeset
2714 Should arrange for the compiler to put cellvars
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35609
diff changeset
2715 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
2716 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
2717 */
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2718 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
2719 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
2720 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
2721 found = 0;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35609
diff changeset
2722 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
2723 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
2724 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
2725 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
2726 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
2727 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
2728 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
2729 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
2730 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
2731 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
2732 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2733 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2734 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
2735 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
2736 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
2737 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
2738 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
2739 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2740 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2741 }
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2742 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
2743 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
2744 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
2745 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
2746 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
2747 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
2748 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2749 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2750
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2751 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
2752 /* 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
2753 * 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
2754 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
2755 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
2756
27712
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
2757 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
2758
18194
990b73fa074c Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18172
diff changeset
2759 /* 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
2760 * 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
2761 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
2762 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2763
43410
b06b191b7cfa Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
2764 retval = PyEval_EvalFrameEx(f,0);
b06b191b7cfa Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
2765
b06b191b7cfa Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
2766 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
2767
21058
9df82c13c675 SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents: 21027
diff changeset
2768 /* 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
2769 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
2770 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
2771 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
2772 */
9df82c13c675 SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents: 21027
diff changeset
2773 assert(tstate != NULL);
9df82c13c675 SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents: 21027
diff changeset
2774 ++tstate->recursion_depth;
43410
b06b191b7cfa Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
2775 Py_DECREF(f);
21058
9df82c13c675 SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents: 21027
diff changeset
2776 --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
2777 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
2778 }
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2779
7bc473b2c654 Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents: 18136
diff changeset
2780
28121
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2781 /* Implementation notes for set_exc_info() and reset_exc_info():
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2782
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2783 - Below, 'exc_ZZZ' stands for 'exc_type', 'exc_value' and
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2784 'exc_traceback'. These always travel together.
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2785
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2786 - tstate->curexc_ZZZ is the "hot" exception that is set by
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2787 PyErr_SetString(), cleared by PyErr_Clear(), and so on.
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2788
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2789 - Once an exception is caught by an except clause, it is transferred
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2790 from tstate->curexc_ZZZ to tstate->exc_ZZZ, from which sys.exc_info()
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2791 can pick it up. This is the primary task of set_exc_info().
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2792 XXX That can't be right: set_exc_info() doesn't look at tstate->curexc_ZZZ.
28121
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2793
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2794 - Now let me explain the complicated dance with frame->f_exc_ZZZ.
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2795
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2796 Long ago, when none of this existed, there were just a few globals:
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2797 one set corresponding to the "hot" exception, and one set
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2798 corresponding to sys.exc_ZZZ. (Actually, the latter weren't C
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2799 globals; they were simply stored as sys.exc_ZZZ. For backwards
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2800 compatibility, they still are!) The problem was that in code like
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2801 this:
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2802
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2803 try:
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2804 "something that may fail"
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2805 except "some exception":
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2806 "do something else first"
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2807 "print the exception from sys.exc_ZZZ."
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2808
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2809 if "do something else first" invoked something that raised and caught
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2810 an exception, sys.exc_ZZZ were overwritten. That was a frequent
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2811 cause of subtle bugs. I fixed this by changing the semantics as
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2812 follows:
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2813
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2814 - Within one frame, sys.exc_ZZZ will hold the last exception caught
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2815 *in that frame*.
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2816
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2817 - But initially, and as long as no exception is caught in a given
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2818 frame, sys.exc_ZZZ will hold the last exception caught in the
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2819 previous frame (or the frame before that, etc.).
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2820
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2821 The first bullet fixed the bug in the above example. The second
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2822 bullet was for backwards compatibility: it was (and is) common to
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2823 have a function that is called when an exception is caught, and to
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2824 have that function access the caught exception via sys.exc_ZZZ.
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2825 (Example: traceback.print_exc()).
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2826
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2827 At the same time I fixed the problem that sys.exc_ZZZ weren't
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2828 thread-safe, by introducing sys.exc_info() which gets it from tstate;
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2829 but that's really a separate improvement.
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2830
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2831 The reset_exc_info() function in ceval.c restores the tstate->exc_ZZZ
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2832 variables to what they were before the current frame was called. The
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2833 set_exc_info() function saves them on the frame so that
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2834 reset_exc_info() can restore them. The invariant is that
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2835 frame->f_exc_ZZZ is NULL iff the current frame never caught an
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2836 exception (where "catching" an exception applies only to successful
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2837 except clauses); and if the current frame ever caught an exception,
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2838 frame->f_exc_ZZZ is the exception that was stored in tstate->exc_ZZZ
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2839 at the start of the current frame.
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2840
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2841 */
c24a23b1f198 Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents: 28086
diff changeset
2842
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2843 static void
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2844 set_exc_info(PyThreadState *tstate,
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2845 PyObject *type, PyObject *value, PyObject *tb)
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2846 {
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2847 PyFrameObject *frame = tstate->frame;
5557
4329e4077cf3 Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents: 5551
diff changeset
2848 PyObject *tmp_type, *tmp_value, *tmp_tb;
6147
b76a44163e0f cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents: 6139
diff changeset
2849
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2850 assert(type != NULL);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2851 assert(frame != NULL);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2852 if (frame->f_exc_type == NULL) {
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2853 assert(frame->f_exc_value == NULL);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2854 assert(frame->f_exc_traceback == NULL);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2855 /* This frame didn't catch an exception before. */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2856 /* Save previous exception of this thread in this frame. */
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2857 if (tstate->exc_type == NULL) {
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2858 /* XXX Why is this set to Py_None? */
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2859 Py_INCREF(Py_None);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2860 tstate->exc_type = Py_None;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2861 }
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2862 Py_INCREF(tstate->exc_type);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2863 Py_XINCREF(tstate->exc_value);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2864 Py_XINCREF(tstate->exc_traceback);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2865 frame->f_exc_type = tstate->exc_type;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2866 frame->f_exc_value = tstate->exc_value;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2867 frame->f_exc_traceback = tstate->exc_traceback;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2868 }
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2869 /* Set new exception for this thread. */
5557
4329e4077cf3 Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents: 5551
diff changeset
2870 tmp_type = tstate->exc_type;
4329e4077cf3 Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents: 5551
diff changeset
2871 tmp_value = tstate->exc_value;
4329e4077cf3 Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents: 5551
diff changeset
2872 tmp_tb = tstate->exc_traceback;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2873 Py_INCREF(type);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2874 Py_XINCREF(value);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2875 Py_XINCREF(tb);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2876 tstate->exc_type = type;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2877 tstate->exc_value = value;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2878 tstate->exc_traceback = tb;
43411
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2879 PyException_SetTraceback(value, tb);
5557
4329e4077cf3 Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents: 5551
diff changeset
2880 Py_XDECREF(tmp_type);
4329e4077cf3 Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents: 5551
diff changeset
2881 Py_XDECREF(tmp_value);
4329e4077cf3 Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents: 5551
diff changeset
2882 Py_XDECREF(tmp_tb);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2883 }
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2884
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2885 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2886 reset_exc_info(PyThreadState *tstate)
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2887 {
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2888 PyFrameObject *frame;
5557
4329e4077cf3 Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents: 5551
diff changeset
2889 PyObject *tmp_type, *tmp_value, *tmp_tb;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2890
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2891 /* It's a precondition that the thread state's frame caught an
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2892 * exception -- verify in a debug build.
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2893 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2894 assert(tstate != NULL);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2895 frame = tstate->frame;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2896 assert(frame != NULL);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2897 assert(frame->f_exc_type != NULL);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2898
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2899 /* Copy the frame's exception info back to the thread state. */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2900 tmp_type = tstate->exc_type;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2901 tmp_value = tstate->exc_value;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2902 tmp_tb = tstate->exc_traceback;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2903 Py_INCREF(frame->f_exc_type);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2904 Py_XINCREF(frame->f_exc_value);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2905 Py_XINCREF(frame->f_exc_traceback);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2906 tstate->exc_type = frame->f_exc_type;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2907 tstate->exc_value = frame->f_exc_value;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2908 tstate->exc_traceback = frame->f_exc_traceback;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2909 Py_XDECREF(tmp_type);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2910 Py_XDECREF(tmp_value);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2911 Py_XDECREF(tmp_tb);
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2912
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2913 /* Clear the frame's exception info. */
5557
4329e4077cf3 Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents: 5551
diff changeset
2914 tmp_type = frame->f_exc_type;
4329e4077cf3 Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents: 5551
diff changeset
2915 tmp_value = frame->f_exc_value;
4329e4077cf3 Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents: 5551
diff changeset
2916 tmp_tb = frame->f_exc_traceback;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2917 frame->f_exc_type = NULL;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2918 frame->f_exc_value = NULL;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2919 frame->f_exc_traceback = NULL;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2920 Py_DECREF(tmp_type);
5557
4329e4077cf3 Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents: 5551
diff changeset
2921 Py_XDECREF(tmp_value);
4329e4077cf3 Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents: 5551
diff changeset
2922 Py_XDECREF(tmp_tb);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2923 }
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2924
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
2925 /* 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
2926 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
2927 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
2928 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
2929 {
43411
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2930 PyObject *type = NULL, *value = NULL, *tb = NULL;
43102
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 43100
diff changeset
2931
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 43100
diff changeset
2932 if (exc == NULL) {
7946
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
2933 /* Reraise */
31797
846b3ee7e106 Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31796
diff changeset
2934 PyThreadState *tstate = PyThreadState_GET();
43102
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 43100
diff changeset
2935 type = tstate->exc_type;
7946
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
2936 value = tstate->exc_value;
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
2937 tb = tstate->exc_traceback;
43411
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2938 if (type == Py_None) {
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2939 PyErr_SetString(PyExc_RuntimeError,
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2940 "No active exception to reraise");
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2941 return WHY_EXCEPTION;
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2942 }
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2943 Py_XINCREF(type);
7946
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
2944 Py_XINCREF(value);
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
2945 Py_XINCREF(tb);
43411
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2946 PyErr_Restore(type, value, tb);
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2947 return WHY_RERAISE;
7946
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
2948 }
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2949
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
2950 /* 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
2951 raise
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 43100
diff changeset
2952 raise <instance>
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 43100
diff changeset
2953 raise <type> */
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 43100
diff changeset
2954
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 43100
diff changeset
2955 if (PyExceptionClass_Check(exc)) {
43411
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2956 type = exc;
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2957 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
2958 if (value == NULL)
43411
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2959 goto raise_error;
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2960 }
43102
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 43100
diff changeset
2961 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
2962 value = exc;
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 43100
diff changeset
2963 type = PyExceptionInstance_Class(exc);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2964 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
2965 }
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
2966 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
2967 /* 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
2968 anyway, just not what you specified :-) */
43411
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2969 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
2970 PyErr_SetString(PyExc_TypeError,
43411
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2971 "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
2972 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
2973 }
43102
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 43100
diff changeset
2974
43411
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2975 tb = PyException_GetTraceback(value);
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2976 if (cause) {
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2977 PyObject *fixed_cause;
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2978 if (PyExceptionClass_Check(cause)) {
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2979 fixed_cause = PyObject_CallObject(cause, NULL);
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2980 if (fixed_cause == NULL)
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2981 goto raise_error;
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2982 Py_DECREF(cause);
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2983 }
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2984 else if (PyExceptionInstance_Check(cause)) {
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2985 fixed_cause = cause;
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2986 }
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2987 else {
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2988 PyErr_SetString(PyExc_TypeError,
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2989 "exception causes must derive from "
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2990 "BaseException");
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2991 goto raise_error;
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2992 }
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2993 PyException_SetCause(value, fixed_cause);
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
2994 }
43102
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 43100
diff changeset
2995
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2996 PyErr_Restore(type, value, tb);
43102
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 43100
diff changeset
2997 return WHY_EXCEPTION;
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 43100
diff changeset
2998
981ecc526703 Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents: 43100
diff changeset
2999 raise_error:
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3000 Py_XDECREF(value);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3001 Py_XDECREF(type);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3002 Py_XDECREF(tb);
43188
386c22d93ab6 Fix refleaks exposed by test_raise.
Collin Winter <collinw@gmail.com>
parents: 43102
diff changeset
3003 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
3004 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
3005 }
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
3006
18195
36e825660a24 Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents: 18194
diff changeset
3007 /* 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
3008 sp). Return 1 for success, 0 if error.
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3009
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3010 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
3011 with a variable target.
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3012 */
18195
36e825660a24 Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents: 18194
diff changeset
3013
6157
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
3014 static int
41699
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3015 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
3016 {
41699
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3017 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
3018 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
3019 PyObject *it; /* iter(v) */
6157
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
3020 PyObject *w;
41699
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3021 PyObject *l = NULL; /* variable list */
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3022
18195
36e825660a24 Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents: 18194
diff changeset
3023 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
3024
36e825660a24 Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents: 18194
diff changeset
3025 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
3026 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
3027 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
3028
36e825660a24 Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents: 18194
diff changeset
3029 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
3030 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
3031 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
3032 /* 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
3033 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
3034 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
3035 "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
3036 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
3037 }
36e825660a24 Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents: 18194
diff changeset
3038 goto Error;
6157
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
3039 }
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
3040 *--sp = w;
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
3041 }
18195
36e825660a24 Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents: 18194
diff changeset
3042
41699
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3043 if (argcntafter == -1) {
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3044 /* 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
3045 w = PyIter_Next(it);
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3046 if (w == NULL) {
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3047 if (PyErr_Occurred())
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3048 goto Error;
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3049 Py_DECREF(it);
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3050 return 1;
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3051 }
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3052 Py_DECREF(w);
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3053 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
3054 goto Error;
6157
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
3055 }
41699
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3056
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3057 l = PySequence_List(it);
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3058 if (l == NULL)
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3059 goto Error;
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3060 *--sp = l;
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3061 i++;
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3062
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3063 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
3064 if (ll < argcntafter) {
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3065 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
3066 argcnt + ll);
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3067 goto Error;
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3068 }
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3069
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3070 /* 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
3071 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
3072 *--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
3073 }
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3074 /* Resize the list. */
42334
e70cdce0e8b2 Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 42132
diff changeset
3075 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
3076 Py_DECREF(it);
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3077 return 1;
e16c8e5c5ca4 Merged revisions 55225-55227,55229-55269 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
3078
18195
36e825660a24 Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents: 18194
diff changeset
3079 Error:
6160
79592761b331 unpack_sequence(): In finally clause, watch out for Py_DECREF
Barry Warsaw <barry@python.org>
parents: 6157
diff changeset
3080 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
3081 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
3082 Py_XDECREF(it);
6157
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
3083 return 0;
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
3084 }
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
3085
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
3086
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
3087 #ifdef LLTRACE
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3088 static int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3089 prtrace(PyObject *v, char *str)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3090 {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3091 printf("%s ", str);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3092 if (PyObject_Print(v, stdout, 0) != 0)
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3093 PyErr_Clear(); /* Don't know what else to do */
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3094 printf("\n");
12579
978253542076 Add useless 'return 1' to prtrace() to shut up VC++.
Guido van Rossum <guido@python.org>
parents: 12576
diff changeset
3095 return 1;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3096 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3097 #endif
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3098
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
3099 static void
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18293
diff changeset
3100 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
3101 {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3102 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
3103 int err;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3104 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
3105 if (value == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3106 value = Py_None;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3107 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
3108 }
30683
3b59fa5d25b1 Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents: 29669
diff changeset
3109 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
3110 if (arg == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3111 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
3112 return;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
3113 }
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18293
diff changeset
3114 err = call_trace(func, self, f, PyTrace_EXCEPTION, arg);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3115 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
3116 if (err == 0)
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3117 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
3118 else {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3119 Py_XDECREF(type);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3120 Py_XDECREF(value);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3121 Py_XDECREF(traceback);
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
3122 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
3123 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
3124
20257
e3f63a95455f Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
3125 static void
e3f63a95455f Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
3126 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
3127 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
3128 {
e3f63a95455f Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
3129 PyObject *type, *value, *traceback;
e3f63a95455f Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
3130 int err;
e3f63a95455f Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
3131 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
3132 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
3133 if (err == 0)
e3f63a95455f Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
3134 PyErr_Restore(type, value, traceback);
e3f63a95455f Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
3135 else {
e3f63a95455f Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
3136 Py_XDECREF(type);
e3f63a95455f Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
3137 Py_XDECREF(value);
e3f63a95455f Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
3138 Py_XDECREF(traceback);
e3f63a95455f Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
3139 }
e3f63a95455f Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
3140 }
e3f63a95455f Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
3141
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
3142 static int
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18293
diff changeset
3143 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
3144 int what, PyObject *arg)
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
3145 {
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18293
diff changeset
3146 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
3147 int result;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18293
diff changeset
3148 if (tstate->tracing)
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
3149 return 0;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3150 tstate->tracing++;
18374
3b295ce2705f This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents: 18326
diff changeset
3151 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
3152 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
3153 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
3154 || (tstate->c_profilefunc != NULL));
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3155 tstate->tracing--;
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18293
diff changeset
3156 return result;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
3157 }
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
3158
28556
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28304
diff changeset
3159 PyObject *
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28304
diff changeset
3160 _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
3161 {
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28304
diff changeset
3162 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
3163 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
3164 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
3165 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
3166 PyObject *result;
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28304
diff changeset
3167
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28304
diff changeset
3168 tstate->tracing = 0;
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28304
diff changeset
3169 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
3170 || (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
3171 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
3172 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
3173 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
3174 return result;
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28304
diff changeset
3175 }
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28304
diff changeset
3176
26110
964d6b79c22e This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents: 26109
diff changeset
3177 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
3178 maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
31768
9817dee5d9df Fix SF bug #765624.
Armin Rigo <arigo@tunes.org>
parents: 31714
diff changeset
3179 PyFrameObject *frame, int *instr_lb, int *instr_ub,
9817dee5d9df Fix SF bug #765624.
Armin Rigo <arigo@tunes.org>
parents: 31714
diff changeset
3180 int *instr_prev)
24844
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24718
diff changeset
3181 {
26110
964d6b79c22e This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents: 26109
diff changeset
3182 int result = 0;
964d6b79c22e This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents: 26109
diff changeset
3183
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
3184 /* 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
3185 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
3186 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
3187 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
3188 */
25078
be2868a63ed5 Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents: 24978
diff changeset
3189 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
3190 int line;
b06b191b7cfa Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
3191 PyAddrPair bounds;
b06b191b7cfa Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
3192
b06b191b7cfa Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
3193 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
3194 &bounds);
b06b191b7cfa Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
3195 if (line >= 0) {
25207
1e46da1e6522 A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents: 25109
diff changeset
3196 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
3197 result = call_trace(func, obj, frame,
26110
964d6b79c22e This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents: 26109
diff changeset
3198 PyTrace_LINE, Py_None);
43410
b06b191b7cfa Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
3199 }
b06b191b7cfa Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
3200 *instr_lb = bounds.ap_lower;
b06b191b7cfa Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
3201 *instr_ub = bounds.ap_upper;
24844
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24718
diff changeset
3202 }
31768
9817dee5d9df Fix SF bug #765624.
Armin Rigo <arigo@tunes.org>
parents: 31714
diff changeset
3203 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
3204 result = call_trace(func, obj, frame, PyTrace_LINE, Py_None);
31768
9817dee5d9df Fix SF bug #765624.
Armin Rigo <arigo@tunes.org>
parents: 31714
diff changeset
3205 }
9817dee5d9df Fix SF bug #765624.
Armin Rigo <arigo@tunes.org>
parents: 31714
diff changeset
3206 *instr_prev = frame->f_lasti;
26110
964d6b79c22e This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents: 26109
diff changeset
3207 return result;
24844
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24718
diff changeset
3208 }
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24718
diff changeset
3209
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18293
diff changeset
3210 void
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18293
diff changeset
3211 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
3212 {
31797
846b3ee7e106 Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31796
diff changeset
3213 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
3214 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
3215 Py_XINCREF(arg);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18293
diff changeset
3216 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
3217 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
3218 /* 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
3219 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
3220 Py_XDECREF(temp);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18293
diff changeset
3221 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
3222 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
3223 /* 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
3224 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
3225 }
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18293
diff changeset
3226
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18293
diff changeset
3227 void
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18293
diff changeset
3228 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
3229 {
31797
846b3ee7e106 Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31796
diff changeset
3230 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
3231 PyObject *temp = tstate->c_traceobj;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18293
diff changeset
3232 Py_XINCREF(arg);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18293
diff changeset
3233 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
3234 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
3235 /* 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
3236 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
3237 Py_XDECREF(temp);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18293
diff changeset
3238 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
3239 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
3240 /* 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
3241 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
3242 || (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
3243 }
4cb34314bd97 Instead of initializing & interning the strings passed to the profile
Fred Drake <fdrake@acm.org>
parents: 18128
diff changeset
3244
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3245 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3246 PyEval_GetBuiltins(void)
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
3247 {
27978
4b99a701defe - PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents: 27781
diff changeset
3248 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
3249 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
3250 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
3251 else
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
3252 return current_frame->f_builtins;
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
3253 }
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
3254
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3255 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3256 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
3257 {
27978
4b99a701defe - PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents: 27781
diff changeset
3258 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
3259 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
3260 return NULL;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3261 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
3262 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
3263 }
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
3264
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3265 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3266 PyEval_GetGlobals(void)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3267 {
27978
4b99a701defe - PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents: 27781
diff changeset
3268 PyFrameObject *current_frame = PyEval_GetFrame();
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3269 if (current_frame == NULL)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3270 return NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3271 else
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3272 return current_frame->f_globals;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3273 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3274
27978
4b99a701defe - PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents: 27781
diff changeset
3275 PyFrameObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3276 PyEval_GetFrame(void)
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
3277 {
31797
846b3ee7e106 Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31796
diff changeset
3278 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
3279 return _PyThreadState_GetFrame(tstate);
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
3280 }
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
3281
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
3282 int
18611
fdb36a0c7e6e Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents: 18513
diff changeset
3283 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
3284 {
27978
4b99a701defe - PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents: 27781
diff changeset
3285 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
3286 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
3287
fdb36a0c7e6e Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents: 18513
diff changeset
3288 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
3289 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
3290 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
3291 if (compilerflags) {
18611
fdb36a0c7e6e Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents: 18513
diff changeset
3292 result = 1;
19350
5b6a6d7d44ae ceval, PyEval_MergeCompilerFlags: wasn't merging in the
Tim Peters <tim.peters@gmail.com>
parents: 19301
diff changeset
3293 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
3294 }
22468
eebae4f60d05 Disable the parser hacks that enabled the "yield" keyword using a future
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22398
diff changeset
3295 #if 0 /* future keyword */
21609
3ba0f1b20320 Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents: 21537
diff changeset
3296 if (codeflags & CO_GENERATOR_ALLOWED) {
3ba0f1b20320 Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents: 21537
diff changeset
3297 result = 1;
3ba0f1b20320 Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents: 21537
diff changeset
3298 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
3299 }
22468
eebae4f60d05 Disable the parser hacks that enabled the "yield" keyword using a future
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22398
diff changeset
3300 #endif
18611
fdb36a0c7e6e Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents: 18513
diff changeset
3301 }
fdb36a0c7e6e Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents: 18513
diff changeset
3302 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
3303 }
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
3304
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3305
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3306 /* External interface to call any callable object.
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3307 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
3308
6206
77f5b6cbea66 Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents: 6185
diff changeset
3309 #undef PyEval_CallObject
77f5b6cbea66 Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents: 6185
diff changeset
3310 /* for backward compatibility: export this interface */
77f5b6cbea66 Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents: 6185
diff changeset
3311
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3312 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3313 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
3314 {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3315 return PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3316 }
6206
77f5b6cbea66 Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents: 6185
diff changeset
3317 #define PyEval_CallObject(func,arg) \
77f5b6cbea66 Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents: 6185
diff changeset
3318 PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL)
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3319
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3320 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3321 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
3322 {
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3323 PyObject *result;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3324
36877
e9a7a2784e17 SF #1444030: Fix several potential defects found by Coverity.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 36803
diff changeset
3325 if (arg == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3326 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
3327 if (arg == NULL)
e9a7a2784e17 SF #1444030: Fix several potential defects found by Coverity.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 36803
diff changeset
3328 return NULL;
e9a7a2784e17 SF #1444030: Fix several potential defects found by Coverity.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 36803
diff changeset
3329 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3330 else if (!PyTuple_Check(arg)) {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3331 PyErr_SetString(PyExc_TypeError,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3332 "argument list must be a tuple");
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3333 return NULL;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3334 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3335 else
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3336 Py_INCREF(arg);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3337
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3338 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
3339 PyErr_SetString(PyExc_TypeError,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3340 "keyword list must be a dictionary");
12440
d47460b1a679 Charles Waldman writes:
Guido van Rossum <guido@python.org>
parents: 12320
diff changeset
3341 Py_DECREF(arg);
2894
4095782c940e empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents: 2872
diff changeset
3342 return NULL;
4095782c940e empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents: 2872
diff changeset
3343 }
4095782c940e empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents: 2872
diff changeset
3344
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 18611
diff changeset
3345 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
3346 Py_DECREF(arg);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3347 return result;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3348 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3349
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35745
diff changeset
3350 const char *
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 18611
diff changeset
3351 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
3352 {
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
3353 if (PyMethod_Check(func))
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 18611
diff changeset
3354 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
3355 else if (PyFunction_Check(func))
42013
cd125fe83051 Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents: 41969
diff changeset
3356 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
3357 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
3358 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
3359 else
17406
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
3360 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
3361 }
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
3362
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35745
diff changeset
3363 const char *
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 18611
diff changeset
3364 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
3365 {
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
3366 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
3367 return "()";
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
3368 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
3369 return "()";
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
3370 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
3371 return "()";
39536
8f5b9982beba Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents: 39442
diff changeset
3372 else
17406
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
3373 return " object";
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
3374 }
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
3375
26141
6ce9228a3da2 Make private functions static so we don't pollute the namespace
Neal Norwitz <nnorwitz@gmail.com>
parents: 26110
diff changeset
3376 static void
24870
df2326a4894d Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24868
diff changeset
3377 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
3378 {
df2326a4894d Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24868
diff changeset
3379 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
3380 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
3381 "%.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
3382 ((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
3383 nargs);
df2326a4894d Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24868
diff changeset
3384 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
3385 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
3386 "%.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
3387 ((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
3388 nargs);
df2326a4894d Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24868
diff changeset
3389 }
df2326a4894d Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24868
diff changeset
3390
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
3391 #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
3392 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
3393 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
3394 tstate->c_profileobj, \
77913be294b9 Massive performance improvement for C extension and builtin tracing code
Nicholas Bastin <nick.bastin@gmail.com>
parents: 32398
diff changeset
3395 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
3396 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
3397 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
3398 } \
23dda92de993 clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents: 35345
diff changeset
3399 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
3400 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
3401 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
3402 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
3403 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
3404 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
3405 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
3406 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
3407 /* 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
3408 } 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
3409 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
3410 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
3411 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
3412 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
3413 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
3414 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
3415 } \
23dda92de993 clean-up tracing of C functions. In particular, don't call the trace func
Armin Rigo <arigo@tunes.org>
parents: 35345
diff changeset
3416 } \
31796
1c117dbb2def Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31768
diff changeset
3417 } \
32409
77913be294b9 Massive performance improvement for C extension and builtin tracing code
Nicholas Bastin <nick.bastin@gmail.com>
parents: 32398
diff changeset
3418 } \
77913be294b9 Massive performance improvement for C extension and builtin tracing code
Nicholas Bastin <nick.bastin@gmail.com>
parents: 32398
diff changeset
3419 } 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
3420 x = call; \
31796
1c117dbb2def Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31768
diff changeset
3421 }
1c117dbb2def Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31768
diff changeset
3422
24868
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3423 static PyObject *
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
3424 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
3425 #ifdef WITH_TSC
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
3426 , 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
3427 #endif
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 32247
diff changeset
3428 )
24868
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3429 {
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3430 int na = oparg & 0xff;
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3431 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
3432 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
3433 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
3434 PyObject *func = *pfunc;
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3435 PyObject *x, *w;
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3436
27712
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
3437 /* 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
3438 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
3439 */
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3440 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
3441 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
3442 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
3443
27712
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
3444 PCALL(PCALL_CFUNCTION);
24870
df2326a4894d Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24868
diff changeset
3445 if (flags & (METH_NOARGS | METH_O)) {
df2326a4894d Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24868
diff changeset
3446 PyCFunction meth = PyCFunction_GET_FUNCTION(func);
df2326a4894d Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24868
diff changeset
3447 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
3448 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
3449 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
3450 }
24870
df2326a4894d Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24868
diff changeset
3451 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
3452 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
3453 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
3454 Py_DECREF(arg);
df2326a4894d Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24868
diff changeset
3455 }
df2326a4894d Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24868
diff changeset
3456 else {
df2326a4894d Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24868
diff changeset
3457 err_args(func, flags, na);
df2326a4894d Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24868
diff changeset
3458 x = NULL;
df2326a4894d Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24868
diff changeset
3459 }
df2326a4894d Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24868
diff changeset
3460 }
df2326a4894d Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24868
diff changeset
3461 else {
24868
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3462 PyObject *callargs;
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3463 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
3464 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
3465 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
3466 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
3467 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
3468 }
24868
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3469 } else {
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3470 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
3471 /* 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
3472 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
3473 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
3474 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
3475 Py_INCREF(self);
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3476 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
3477 Py_INCREF(func);
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3478 Py_DECREF(*pfunc);
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3479 *pfunc = self;
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3480 na++;
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3481 n++;
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3482 } else
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3483 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
3484 READ_TIMESTAMP(*pintr0);
24868
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3485 if (PyFunction_Check(func))
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3486 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
3487 else
24868
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3488 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
3489 READ_TIMESTAMP(*pintr1);
24868
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3490 Py_DECREF(func);
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3491 }
31872
9f5fe6b23e59 Since the fast_yield branch target was introduced, it appears that most
Tim Peters <tim.peters@gmail.com>
parents: 31797
diff changeset
3492
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
3493 /* 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
3494 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
3495 (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
3496 */
24868
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3497 while ((*pp_stack) > pfunc) {
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3498 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
3499 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
3500 PCALL(PCALL_POP);
24868
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3501 }
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3502 return x;
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3503 }
2306001f6eaa Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24866
diff changeset
3504
24870
df2326a4894d Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24868
diff changeset
3505 /* 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
3506 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
3507 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
3508 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
3509 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
3510 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
3511 done before evaluating the frame.
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3512 */
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3513
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3514 static PyObject *
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3515 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
3516 {
27712
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
3517 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
3518 PyObject *globals = PyFunction_GET_GLOBALS(func);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3519 PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
40215
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
3520 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
3521 PyObject **d = NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3522 int nd = 0;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3523
27712
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
3524 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
3525 PCALL(PCALL_FAST_FUNCTION);
40215
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
3526 if (argdefs == NULL && co->co_argcount == n &&
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
3527 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
3528 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
3529 PyFrameObject *f;
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
3530 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
3531 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
3532 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
3533 int i;
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
3534
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
3535 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
3536 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
3537 /* 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
3538 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
3539 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
3540 */
39610
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
3541 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
3542 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
3543 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
3544 return NULL;
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
3545
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
3546 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
3547 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
3548
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
3549 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
3550 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
3551 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
3552 }
35298
b2fe5f8fcfdd PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents: 35126
diff changeset
3553 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
3554 ++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
3555 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
3556 --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
3557 return retval;
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
3558 }
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3559 if (argdefs != NULL) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3560 d = &PyTuple_GET_ITEM(argdefs, 0);
42334
e70cdce0e8b2 Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 42132
diff changeset
3561 nd = Py_Size(argdefs);
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3562 }
27712
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
3563 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
3564 (PyObject *)NULL, (*pp_stack)-n, na,
40215
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39782
diff changeset
3565 (*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
3566 PyFunction_GET_CLOSURE(func));
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3567 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3568
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3569 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
3570 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
3571 PyObject *func)
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3572 {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3573 PyObject *kwdict = NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3574 if (orig_kwdict == NULL)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3575 kwdict = PyDict_New();
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3576 else {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3577 kwdict = PyDict_Copy(orig_kwdict);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3578 Py_DECREF(orig_kwdict);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3579 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3580 if (kwdict == NULL)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3581 return NULL;
31894
310dd98ea064 Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents: 31880
diff changeset
3582 while (--nk >= 0) {
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3583 int err;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3584 PyObject *value = EXT_POP(*pp_stack);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3585 PyObject *key = EXT_POP(*pp_stack);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3586 if (PyDict_GetItem(kwdict, key) != NULL) {
43410
b06b191b7cfa Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
3587 PyErr_Format(PyExc_TypeError,
b06b191b7cfa Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
3588 "%.200s%s got multiple values "
b06b191b7cfa Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
3589 "for keyword argument '%.200s'",
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 18611
diff changeset
3590 PyEval_GetFuncName(func),
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 18611
diff changeset
3591 PyEval_GetFuncDesc(func),
42860
bf1a53cc6e65 Use unicode
Neal Norwitz <nnorwitz@gmail.com>
parents: 42334
diff changeset
3592 PyUnicode_AsString(key));
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3593 Py_DECREF(key);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3594 Py_DECREF(value);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3595 Py_DECREF(kwdict);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3596 return NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3597 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3598 err = PyDict_SetItem(kwdict, key, value);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3599 Py_DECREF(key);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3600 Py_DECREF(value);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3601 if (err) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3602 Py_DECREF(kwdict);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3603 return NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3604 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3605 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3606 return kwdict;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3607 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3608
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3609 static PyObject *
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3610 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
3611 PyObject ***pp_stack)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3612 {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3613 PyObject *callargs, *w;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3614
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3615 callargs = PyTuple_New(nstack + nstar);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3616 if (callargs == NULL) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3617 return NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3618 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3619 if (nstar) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3620 int i;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3621 for (i = 0; i < nstar; i++) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3622 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
3623 Py_INCREF(a);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3624 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
3625 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3626 }
31894
310dd98ea064 Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents: 31880
diff changeset
3627 while (--nstack >= 0) {
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3628 w = EXT_POP(*pp_stack);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3629 PyTuple_SET_ITEM(callargs, nstack, w);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3630 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3631 return callargs;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3632 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3633
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3634 static PyObject *
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3635 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
3636 {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3637 PyObject *args = PyTuple_New(na);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3638 PyObject *w;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3639
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3640 if (args == NULL)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3641 return NULL;
31894
310dd98ea064 Revert 2.393, elimination of pre-decrementing, which
Raymond Hettinger <python@rcn.com>
parents: 31880
diff changeset
3642 while (--na >= 0) {
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3643 w = EXT_POP(*pp_stack);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3644 PyTuple_SET_ITEM(args, na, w);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3645 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3646 return args;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3647 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3648
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3649 static PyObject *
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3650 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
3651 {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3652 PyObject *callargs = NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3653 PyObject *kwdict = NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3654 PyObject *result = NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3655
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3656 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
3657 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
3658 if (kwdict == NULL)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3659 goto call_fail;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3660 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3661 callargs = load_args(pp_stack, na);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3662 if (callargs == NULL)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3663 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
3664 #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
3665 /* 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
3666 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
3667 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
3668 */
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
3669 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
3670 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
3671 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
3672 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
3673 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
3674 PCALL(PCALL_TYPE);
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
3675 else
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
3676 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
3677 #endif
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 18611
diff changeset
3678 result = PyObject_Call(func, callargs, kwdict);
43411
a5d37cdcd316 Whitespace cleanup.
Thomas Wouters <thomas@python.org>
parents: 43410
diff changeset
3679 call_fail:
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3680 Py_XDECREF(callargs);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3681 Py_XDECREF(kwdict);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3682 return result;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3683 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3684
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3685 static PyObject *
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3686 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
3687 {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3688 int nstar = 0;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3689 PyObject *callargs = NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3690 PyObject *stararg = NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3691 PyObject *kwdict = NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3692 PyObject *result = NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3693
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3694 if (flags & CALL_FLAG_KW) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3695 kwdict = EXT_POP(*pp_stack);
41824
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3696 if (!PyDict_Check(kwdict)) {
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3697 PyObject *d;
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3698 d = PyDict_New();
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3699 if (d == NULL)
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3700 goto ext_call_fail;
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3701 if (PyDict_Update(d, kwdict) != 0) {
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3702 Py_DECREF(d);
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3703 /* PyDict_Update raises attribute
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3704 * error (percolated from an attempt
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3705 * to get 'keys' attribute) instead of
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3706 * 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
3707 * is not a mapping.
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3708 */
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3709 if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3710 PyErr_Format(PyExc_TypeError,
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3711 "%.200s%.200s argument after ** "
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3712 "must be a mapping, not %.200s",
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3713 PyEval_GetFuncName(func),
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3714 PyEval_GetFuncDesc(func),
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3715 kwdict->ob_type->tp_name);
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3716 }
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3717 goto ext_call_fail;
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3718 }
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3719 Py_DECREF(kwdict);
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3720 kwdict = d;
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3721 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3722 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3723 if (flags & CALL_FLAG_VAR) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3724 stararg = EXT_POP(*pp_stack);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3725 if (!PyTuple_Check(stararg)) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3726 PyObject *t = NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3727 t = PySequence_Tuple(stararg);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3728 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
3729 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
3730 PyErr_Format(PyExc_TypeError,
41824
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3731 "%.200s%.200s argument after * "
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3732 "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
3733 PyEval_GetFuncName(func),
41824
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3734 PyEval_GetFuncDesc(func),
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
3735 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
3736 }
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3737 goto ext_call_fail;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3738 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3739 Py_DECREF(stararg);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3740 stararg = t;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3741 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3742 nstar = PyTuple_GET_SIZE(stararg);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3743 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3744 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
3745 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
3746 if (kwdict == NULL)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3747 goto ext_call_fail;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3748 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3749 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
3750 if (callargs == NULL)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3751 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
3752 #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
3753 /* 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
3754 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
3755 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
3756 */
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
3757 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
3758 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
3759 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
3760 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
3761 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
3762 PCALL(PCALL_TYPE);
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
3763 else
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27295
diff changeset
3764 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
3765 #endif
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 18611
diff changeset
3766 result = PyObject_Call(func, callargs, kwdict);
43410
b06b191b7cfa Merged revisions 58203-58210 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 43188
diff changeset
3767 ext_call_fail:
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3768 Py_XDECREF(callargs);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3769 Py_XDECREF(kwdict);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3770 Py_XDECREF(stararg);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3771 return result;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3772 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3773
36882
6a9c7165b17b Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents: 36877
diff changeset
3774 /* 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
3775 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
3776 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
3777 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
3778 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
3779 */
21441
05ad7a69d933 _PyEval_SliceIndex(): explain why a NULL argument is allowed (thanks
Tim Peters <tim.peters@gmail.com>
parents: 21440
diff changeset
3780 /* 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
3781 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
3782 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
3783 */
12614
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
3784 int
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36475
diff changeset
3785 _PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3786 {
21441
05ad7a69d933 _PyEval_SliceIndex(): explain why a NULL argument is allowed (thanks
Tim Peters <tim.peters@gmail.com>
parents: 21440
diff changeset
3787 if (v != NULL) {
36558
d3685f9b7b71 Remove size constraints in SLICE opcodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
3788 Py_ssize_t x;
40626
4aee3f672f77 Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents: 40582
diff changeset
3789 if (PyInt_CheckExact(v)) {
39610
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
3790 /* XXX(nnorwitz): I think PyInt_AS_LONG is correct,
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
3791 however, it looks like it should be AsSsize_t.
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
3792 There should be a comment here explaining why.
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
3793 */
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
3794 x = PyInt_AS_LONG(v);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
3795 }
39610
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
3796 else if (PyIndex_Check(v)) {
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
3797 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
3798 if (x == -1 && PyErr_Occurred())
6a9c7165b17b Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents: 36877
diff changeset
3799 return 0;
6a9c7165b17b Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents: 36877
diff changeset
3800 }
6a9c7165b17b Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents: 36877
diff changeset
3801 else {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3802 PyErr_SetString(PyExc_TypeError,
36882
6a9c7165b17b Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents: 36877
diff changeset
3803 "slice indices must be integers or "
6a9c7165b17b Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents: 36877
diff changeset
3804 "None or have an __index__ method");
12614
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
3805 return 0;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3806 }
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3807 *pi = x;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3808 }
12614
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
3809 return 1;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3810 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3811
42132
863ed7cd45dc Merged revisions 56020-56124 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42013
diff changeset
3812 #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
3813 "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
3814
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3815 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3816 cmp_outcome(int op, register PyObject *v, register PyObject *w)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3817 {
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3818 int res = 0;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3819 switch (op) {
21609
3ba0f1b20320 Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents: 21537
diff changeset
3820 case PyCmp_IS:
27295
b8387730dd8f SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents: 27243
diff changeset
3821 res = (v == w);
b8387730dd8f SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents: 27243
diff changeset
3822 break;
21609
3ba0f1b20320 Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents: 21537
diff changeset
3823 case PyCmp_IS_NOT:
27295
b8387730dd8f SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents: 27243
diff changeset
3824 res = (v != w);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3825 break;
21609
3ba0f1b20320 Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents: 21537
diff changeset
3826 case PyCmp_IN:
27295
b8387730dd8f SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents: 27243
diff changeset
3827 res = PySequence_Contains(w, v);
b8387730dd8f SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents: 27243
diff changeset
3828 if (res < 0)
b8387730dd8f SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents: 27243
diff changeset
3829 return NULL;
b8387730dd8f SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents: 27243
diff changeset
3830 break;
21609
3ba0f1b20320 Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents: 21537
diff changeset
3831 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
3832 res = PySequence_Contains(w, v);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3833 if (res < 0)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3834 return NULL;
27295
b8387730dd8f SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents: 27243
diff changeset
3835 res = !res;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3836 break;
21609
3ba0f1b20320 Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents: 21537
diff changeset
3837 case PyCmp_EXC_MATCH:
40742
f1701ba2452b Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40729
diff changeset
3838 if (PyTuple_Check(w)) {
f1701ba2452b Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40729
diff changeset
3839 Py_ssize_t i, length;
f1701ba2452b Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40729
diff changeset
3840 length = PyTuple_Size(w);
f1701ba2452b Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40729
diff changeset
3841 for (i = 0; i < length; i += 1) {
f1701ba2452b Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40729
diff changeset
3842 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
3843 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
3844 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
3845 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
3846 return NULL;
40742
f1701ba2452b Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40729
diff changeset
3847 }
f1701ba2452b Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40729
diff changeset
3848 }
f1701ba2452b Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40729
diff changeset
3849 }
f1701ba2452b Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40729
diff changeset
3850 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
3851 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
3852 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
3853 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
3854 return NULL;
40742
f1701ba2452b Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40729
diff changeset
3855 }
f1701ba2452b Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40729
diff changeset
3856 }
6147
b76a44163e0f cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents: 6139
diff changeset
3857 res = PyErr_GivenExceptionMatches(v, w);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3858 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3859 default:
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3860 return PyObject_RichCompare(v, w, op);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3861 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3862 v = res ? Py_True : Py_False;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3863 Py_INCREF(v);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3864 return v;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3865 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3866
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
3867 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
3868 import_from(PyObject *v, PyObject *name)
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
3869 {
15830
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3870 PyObject *x;
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3871
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3872 x = PyObject_GetAttr(v, name);
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3873 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
3874 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
3875 }
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
3876 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
3877 }
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3878
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
3879 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
3880 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
3881 {
15830
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3882 PyObject *all = PyObject_GetAttrString(v, "__all__");
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3883 PyObject *dict, *name, *value;
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3884 int skip_leading_underscores = 0;
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3885 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
3886
15830
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3887 if (all == NULL) {
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3888 if (!PyErr_ExceptionMatches(PyExc_AttributeError))
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3889 return -1; /* Unexpected error */
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3890 PyErr_Clear();
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3891 dict = PyObject_GetAttrString(v, "__dict__");
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3892 if (dict == NULL) {
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3893 if (!PyErr_ExceptionMatches(PyExc_AttributeError))
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3894 return -1;
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3895 PyErr_SetString(PyExc_ImportError,
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3896 "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
3897 return -1;
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3898 }
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3899 all = PyMapping_Keys(dict);
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3900 Py_DECREF(dict);
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3901 if (all == NULL)
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3902 return -1;
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3903 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
3904 }
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
3905
15830
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3906 for (pos = 0, err = 0; ; pos++) {
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3907 name = PySequence_GetItem(all, pos);
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3908 if (name == NULL) {
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3909 if (!PyErr_ExceptionMatches(PyExc_IndexError))
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3910 err = -1;
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3911 else
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3912 PyErr_Clear();
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3913 break;
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3914 }
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3915 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
3916 PyUnicode_Check(name) &&
cd125fe83051 Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents: 41969
diff changeset
3917 PyUnicode_AS_UNICODE(name)[0] == '_')
15830
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3918 {
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3919 Py_DECREF(name);
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3920 continue;
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3921 }
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3922 value = PyObject_GetAttr(v, name);
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3923 if (value == NULL)
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3924 err = -1;
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 40381
diff changeset
3925 else if (PyDict_CheckExact(locals))
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 40381
diff changeset
3926 err = PyDict_SetItem(locals, name, value);
15830
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3927 else
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 40381
diff changeset
3928 err = PyObject_SetItem(locals, name, value);
15830
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3929 Py_DECREF(name);
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3930 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
3931 if (err != 0)
15830
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3932 break;
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
3933 }
15830
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3934 Py_DECREF(all);
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3935 return err;
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
3936 }
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
3937
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3938 static void
42860
bf1a53cc6e65 Use unicode
Neal Norwitz <nnorwitz@gmail.com>
parents: 42334
diff changeset
3939 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
3940 {
42860
bf1a53cc6e65 Use unicode
Neal Norwitz <nnorwitz@gmail.com>
parents: 42334
diff changeset
3941 const char *obj_str;
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3942
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3943 if (!obj)
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3944 return;
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3945
42860
bf1a53cc6e65 Use unicode
Neal Norwitz <nnorwitz@gmail.com>
parents: 42334
diff changeset
3946 obj_str = PyUnicode_AsString(obj);
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3947 if (!obj_str)
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3948 return;
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3949
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3950 PyErr_Format(exc, format_str, obj_str);
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3951 }
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3952
32974
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3953 static PyObject *
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3954 string_concatenate(PyObject *v, PyObject *w,
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3955 PyFrameObject *f, unsigned char *next_instr)
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3956 {
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3957 /* This function implements 'variable += expr' when both arguments
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3958 are strings. */
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 39222
diff changeset
3959 Py_ssize_t v_len = PyString_GET_SIZE(v);
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 39222
diff changeset
3960 Py_ssize_t w_len = PyString_GET_SIZE(w);
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 39222
diff changeset
3961 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
3962 if (new_len < 0) {
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 39222
diff changeset
3963 PyErr_SetString(PyExc_OverflowError,
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 39222
diff changeset
3964 "strings are too large to concat");
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 39222
diff changeset
3965 return NULL;
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 39222
diff changeset
3966 }
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
3967
32974
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3968 if (v->ob_refcnt == 2) {
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3969 /* 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
3970 * stored in 'variable' when the += is performed: one on the
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3971 * value stack (in 'v') and one still stored in the 'variable'.
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3972 * We try to delete the variable now to reduce the refcnt to 1.
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3973 */
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3974 switch (*next_instr) {
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3975 case STORE_FAST:
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3976 {
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3977 int oparg = PEEKARG();
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3978 PyObject **fastlocals = f->f_localsplus;
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3979 if (GETLOCAL(oparg) == v)
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3980 SETLOCAL(oparg, NULL);
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3981 break;
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3982 }
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3983 case STORE_DEREF:
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3984 {
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
3985 PyObject **freevars = f->f_localsplus + f->f_code->co_nlocals;
32974
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3986 PyObject *c = freevars[PEEKARG()];
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3987 if (PyCell_GET(c) == v)
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3988 PyCell_Set(c, NULL);
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3989 break;
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3990 }
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3991 case STORE_NAME:
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3992 {
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3993 PyObject *names = f->f_code->co_names;
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3994 PyObject *name = GETITEM(names, PEEKARG());
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3995 PyObject *locals = f->f_locals;
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3996 if (PyDict_CheckExact(locals) &&
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3997 PyDict_GetItem(locals, name) == v) {
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3998 if (PyDict_DelItem(locals, name) != 0) {
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
3999 PyErr_Clear();
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4000 }
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4001 }
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4002 break;
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4003 }
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4004 }
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4005 }
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4006
33030
8607ac2f81c8 This was quite a dark bug in my recent in-place string concatenation
Armin Rigo <arigo@tunes.org>
parents: 32974
diff changeset
4007 if (v->ob_refcnt == 1 && !PyString_CHECK_INTERNED(v)) {
32974
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4008 /* 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
4009 * in-place.
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4010 */
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 39222
diff changeset
4011 if (_PyString_Resize(&v, new_len) != 0) {
32974
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4012 /* XXX if _PyString_Resize() fails, 'v' has been
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4013 * deallocated so it cannot be put back into 'variable'.
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4014 * The MemoryError is raised when there is no value in
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4015 * 'variable', which might (very remotely) be a cause
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4016 * of incompatibilities.
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4017 */
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4018 return NULL;
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4019 }
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4020 /* copy 'w' into the newly allocated area of 'v' */
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4021 memcpy(PyString_AS_STRING(v) + v_len,
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4022 PyString_AS_STRING(w), w_len);
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4023 return v;
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4024 }
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4025 else {
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4026 /* When in-place resizing is not an option. */
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4027 PyString_Concat(&v, w);
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4028 return v;
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4029 }
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4030 }
fb6ffd290cfb SF patch #980695: efficient string concatenation
Raymond Hettinger <python@rcn.com>
parents: 32900
diff changeset
4031
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4032 #ifdef DYNAMIC_EXECUTION_PROFILE
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4033
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
4034 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
4035 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
4036 {
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4037 int i;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4038 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
4039 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
4040 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
4041 PyObject *x = PyInt_FromLong(a[i]);
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4042 if (x == NULL) {
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4043 Py_DECREF(l);
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4044 return NULL;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4045 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4046 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
4047 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4048 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
4049 a[i] = 0;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4050 return l;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4051 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4052
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4053 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
4054 _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
4055 {
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4056 #ifndef DXPAIRS
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4057 return getarray(dxp);
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4058 #else
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4059 int i;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4060 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
4061 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
4062 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
4063 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
4064 if (x == NULL) {
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4065 Py_DECREF(l);
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4066 return NULL;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4067 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4068 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
4069 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4070 return l;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4071 #endif
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4072 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4073
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
4074 #endif