Mercurial > cpython-lru_cache-weakref
annotate Python/ceval.c @ 31514:545229dfd909 legacy-trunk
This is my patch #876198 plus a NEWS entry and a header frob.
Remove the ability to use (from C) arbitrary objects supporting the
read buffer interface as the co_code member of code objects.
| author | Michael W. Hudson <mwh@python.net> |
|---|---|
| date | Thu, 12 Feb 2004 15:28:27 +0000 |
| parents | 2abc52c3d4c2 |
| children | fd2103ae6f29 |
| rev | line source |
|---|---|
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
119
diff
changeset
|
1 |
| 86 | 2 /* Execute compiled code */ |
| 69 | 3 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4 /* XXX TO DO: |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
5 XXX speed up searching for keywords by using a dictionary |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
6 XXX document it! |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
7 */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
8 |
| 5368 | 9 #include "Python.h" |
| 86 | 10 |
| 69 | 11 #include "compile.h" |
| 86 | 12 #include "frameobject.h" |
| 926 | 13 #include "eval.h" |
| 69 | 14 #include "opcode.h" |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
15 #include "structmember.h" |
| 69 | 16 |
|
1400
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
17 #include <ctype.h> |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
18 |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
19 /* 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
|
20 /* #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
|
21 |
|
4839
4567e158d20c
Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents:
4667
diff
changeset
|
22 #ifdef Py_DEBUG |
| 567 | 23 /* For debugging the interpreter: */ |
| 24 #define LLTRACE 1 /* Low-level trace feature */ | |
| 25 #define CHECKEXC 1 /* Double-check exception checking */ | |
| 69 | 26 #endif |
| 27 | |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
28 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
|
29 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
30 /* Forward declarations */ |
|
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
|
31 static PyObject *eval_frame(PyFrameObject *); |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
32 static PyObject *call_function(PyObject ***, int); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
33 static PyObject *fast_function(PyObject *, PyObject ***, int, int, int); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
34 static PyObject *do_call(PyObject *, PyObject ***, int, int); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
35 static PyObject *ext_do_call(PyObject *, PyObject ***, int, int, int); |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
36 static PyObject *update_keyword_args(PyObject *, int, PyObject ***,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
|
37 static PyObject *update_star_args(int, int, PyObject *, PyObject ***); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
38 static PyObject *load_args(PyObject ***, int); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
39 #define CALL_FLAG_VAR 1 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
40 #define CALL_FLAG_KW 2 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
41 |
|
746
6c0f16008bd9
lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents:
708
diff
changeset
|
42 #ifdef LLTRACE |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
43 static int prtrace(PyObject *, char *); |
|
746
6c0f16008bd9
lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents:
708
diff
changeset
|
44 #endif |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
45 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
|
46 int, PyObject *); |
|
20257
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
47 static void call_trace_protected(Py_tracefunc, PyObject *, |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
48 PyFrameObject *, int); |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
49 static void call_exc_trace(Py_tracefunc, PyObject *, PyFrameObject *); |
|
26110
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
50 static int maybe_call_line_trace(Py_tracefunc, PyObject *, |
| 24844 | 51 PyFrameObject *, int *, int *); |
| 52 | |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
53 static PyObject *apply_slice(PyObject *, PyObject *, PyObject *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
54 static int assign_slice(PyObject *, PyObject *, |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
55 PyObject *, PyObject *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
56 static PyObject *cmp_outcome(int, 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
|
57 static PyObject *import_from(PyObject *, PyObject *); |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
58 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
|
59 static PyObject *build_class(PyObject *, PyObject *, PyObject *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
60 static int exec_statement(PyFrameObject *, |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
61 PyObject *, PyObject *, PyObject *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
62 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
|
63 static void reset_exc_info(PyThreadState *); |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
64 static void format_exc_check_arg(PyObject *, char *, PyObject *); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
65 |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
66 #define NAME_ERROR_MSG \ |
| 15318 | 67 "name '%.200s' is not defined" |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
68 #define GLOBAL_NAME_ERROR_MSG \ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
69 "global name '%.200s' is not defined" |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
70 #define UNBOUNDLOCAL_ERROR_MSG \ |
| 15318 | 71 "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
|
72 #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
|
73 "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
|
74 " in enclosing scope" |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
75 |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
76 /* Dynamic execution profile */ |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
77 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
78 #ifdef DXPAIRS |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
79 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
|
80 #define dxp dxpairs[256] |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
81 #else |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
82 static long dxp[256]; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
83 #endif |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
84 #endif |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
85 |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
86 /* 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
|
87 #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
|
88 #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
|
89 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
|
90 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
91 #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
|
92 #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
|
93 #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
|
94 #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
|
95 #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
|
96 #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
|
97 #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
|
98 #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
|
99 #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
|
100 #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
|
101 #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
|
102 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
103 /* 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
|
104 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
105 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
|
106 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
107 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
|
108 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
|
109 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
110 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
|
111 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
|
112 twice. |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
113 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 */ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
120 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
121 #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
|
122 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
123 PyObject * |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
124 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
|
125 { |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
126 return Py_BuildValue("iiiiiiiiii", |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
127 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
|
128 pcall[4], pcall[5], pcall[6], pcall[7], |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
129 pcall[8], pcall[9]); |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
130 } |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
131 #else |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
132 #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
|
133 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
134 PyObject * |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
135 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
|
136 { |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
137 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
|
138 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
|
139 } |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
140 #endif |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
141 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24266
diff
changeset
|
142 static PyTypeObject gentype; |
|
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
|
143 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
144 typedef struct { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
145 PyObject_HEAD |
|
18288
6800bcce0455
Add "gi_" (generator-iterator) prefix to names of genobject members.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
146 /* The gi_ prefix is intended to remind of generator-iterator. */ |
|
6800bcce0455
Add "gi_" (generator-iterator) prefix to names of genobject members.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
147 |
|
6800bcce0455
Add "gi_" (generator-iterator) prefix to names of genobject members.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
148 PyFrameObject *gi_frame; |
|
6800bcce0455
Add "gi_" (generator-iterator) prefix to names of genobject members.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
149 |
|
18293
0344e4ac70b0
gen_getattr: make the gi_running and gi_frame members discoverable (but
Tim Peters <tim.peters@gmail.com>
parents:
18288
diff
changeset
|
150 /* True if generator is being executed. */ |
|
0344e4ac70b0
gen_getattr: make the gi_running and gi_frame members discoverable (but
Tim Peters <tim.peters@gmail.com>
parents:
18288
diff
changeset
|
151 int gi_running; |
|
24718
129d8d2e1904
Add weakref support generator-iterators.
Fred Drake <fdrake@acm.org>
parents:
24607
diff
changeset
|
152 |
|
129d8d2e1904
Add weakref support generator-iterators.
Fred Drake <fdrake@acm.org>
parents:
24607
diff
changeset
|
153 /* List of weak reference. */ |
|
129d8d2e1904
Add weakref support generator-iterators.
Fred Drake <fdrake@acm.org>
parents:
24607
diff
changeset
|
154 PyObject *gi_weakreflist; |
|
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
|
155 } genobject; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
156 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
157 static PyObject * |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
158 gen_new(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
|
159 { |
|
22398
963e814e69cc
Re-enable GC of generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21974
diff
changeset
|
160 genobject *gen = PyObject_GC_New(genobject, &gentype); |
|
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
|
161 if (gen == 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
|
162 Py_DECREF(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
|
163 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
|
164 } |
|
18288
6800bcce0455
Add "gi_" (generator-iterator) prefix to names of genobject members.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
165 gen->gi_frame = f; |
|
6800bcce0455
Add "gi_" (generator-iterator) prefix to names of genobject members.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
166 gen->gi_running = 0; |
|
24718
129d8d2e1904
Add weakref support generator-iterators.
Fred Drake <fdrake@acm.org>
parents:
24607
diff
changeset
|
167 gen->gi_weakreflist = NULL; |
|
22398
963e814e69cc
Re-enable GC of generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21974
diff
changeset
|
168 _PyObject_GC_TRACK(gen); |
|
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
|
169 return (PyObject *)gen; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
170 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
171 |
|
18513
65afac84d4f7
GC for generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18374
diff
changeset
|
172 static int |
|
65afac84d4f7
GC for generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18374
diff
changeset
|
173 gen_traverse(genobject *gen, visitproc visit, void *arg) |
|
65afac84d4f7
GC for generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18374
diff
changeset
|
174 { |
|
65afac84d4f7
GC for generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18374
diff
changeset
|
175 return visit((PyObject *)gen->gi_frame, arg); |
|
65afac84d4f7
GC for generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18374
diff
changeset
|
176 } |
|
65afac84d4f7
GC for generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18374
diff
changeset
|
177 |
|
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
|
178 static void |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
179 gen_dealloc(genobject *gen) |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
180 { |
|
22398
963e814e69cc
Re-enable GC of generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21974
diff
changeset
|
181 _PyObject_GC_UNTRACK(gen); |
|
24718
129d8d2e1904
Add weakref support generator-iterators.
Fred Drake <fdrake@acm.org>
parents:
24607
diff
changeset
|
182 if (gen->gi_weakreflist != NULL) |
|
129d8d2e1904
Add weakref support generator-iterators.
Fred Drake <fdrake@acm.org>
parents:
24607
diff
changeset
|
183 PyObject_ClearWeakRefs((PyObject *) gen); |
|
18288
6800bcce0455
Add "gi_" (generator-iterator) prefix to names of genobject members.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
184 Py_DECREF(gen->gi_frame); |
|
22398
963e814e69cc
Re-enable GC of generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21974
diff
changeset
|
185 PyObject_GC_Del(gen); |
|
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
|
186 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
187 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
188 static PyObject * |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
189 gen_iternext(genobject *gen) |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
190 { |
|
18194
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
191 PyThreadState *tstate = PyThreadState_GET(); |
|
18288
6800bcce0455
Add "gi_" (generator-iterator) prefix to names of genobject members.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
192 PyFrameObject *f = gen->gi_frame; |
|
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
|
193 PyObject *result; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
194 |
|
18288
6800bcce0455
Add "gi_" (generator-iterator) prefix to names of genobject members.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
195 if (gen->gi_running) { |
|
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
|
196 PyErr_SetString(PyExc_ValueError, |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
197 "generator already executing"); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
198 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
|
199 } |
|
18237
f02605b8fdc1
PyFrameObject: rename f_stackbottom to f_stacktop, since it points to
Tim Peters <tim.peters@gmail.com>
parents:
18195
diff
changeset
|
200 if (f->f_stacktop == 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
|
201 return NULL; |
|
18194
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
202 |
|
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
203 /* Generators always return to their most recent caller, not |
|
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
204 * necessarily their creator. */ |
|
18239
a1ef43a6d6e1
gen_iternext(): Don't assume that the current thread state's frame is
Tim Peters <tim.peters@gmail.com>
parents:
18237
diff
changeset
|
205 Py_XINCREF(tstate->frame); |
|
18194
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
206 assert(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
|
207 f->f_back = tstate->frame; |
|
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
208 |
|
18288
6800bcce0455
Add "gi_" (generator-iterator) prefix to names of genobject members.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
209 gen->gi_running = 1; |
|
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
|
210 result = eval_frame(f); |
|
18288
6800bcce0455
Add "gi_" (generator-iterator) prefix to names of genobject members.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
211 gen->gi_running = 0; |
|
18194
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
212 |
|
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
213 /* Don't keep the reference to f_back any longer than necessary. It |
|
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
214 * may keep a chain of frames alive or it could create a reference |
|
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
215 * cycle. */ |
|
18239
a1ef43a6d6e1
gen_iternext(): Don't assume that the current thread state's frame is
Tim Peters <tim.peters@gmail.com>
parents:
18237
diff
changeset
|
216 Py_XDECREF(f->f_back); |
|
18172
12d7d4db69f2
gen_iternext(): repair subtle refcount problem.
Tim Peters <tim.peters@gmail.com>
parents:
18171
diff
changeset
|
217 f->f_back = NULL; |
|
18194
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
218 |
|
18243
47717e5667eb
Change the semantics of "return" in generators, as discussed on the
Tim Peters <tim.peters@gmail.com>
parents:
18239
diff
changeset
|
219 /* If the generator just returned (as opposed to yielding), signal |
|
47717e5667eb
Change the semantics of "return" in generators, as discussed on the
Tim Peters <tim.peters@gmail.com>
parents:
18239
diff
changeset
|
220 * that the generator is exhausted. */ |
|
47717e5667eb
Change the semantics of "return" in generators, as discussed on the
Tim Peters <tim.peters@gmail.com>
parents:
18239
diff
changeset
|
221 if (result == Py_None && f->f_stacktop == NULL) { |
|
47717e5667eb
Change the semantics of "return" in generators, as discussed on the
Tim Peters <tim.peters@gmail.com>
parents:
18239
diff
changeset
|
222 Py_DECREF(result); |
|
47717e5667eb
Change the semantics of "return" in generators, as discussed on the
Tim Peters <tim.peters@gmail.com>
parents:
18239
diff
changeset
|
223 result = NULL; |
|
47717e5667eb
Change the semantics of "return" in generators, as discussed on the
Tim Peters <tim.peters@gmail.com>
parents:
18239
diff
changeset
|
224 } |
|
47717e5667eb
Change the semantics of "return" in generators, as discussed on the
Tim Peters <tim.peters@gmail.com>
parents:
18239
diff
changeset
|
225 |
|
18194
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
226 return result; |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
227 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
228 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
229 static PyObject * |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
230 gen_getiter(PyObject *gen) |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
231 { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
232 Py_INCREF(gen); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
233 return gen; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
234 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
235 |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19896
diff
changeset
|
236 static PyMemberDef gen_memberlist[] = { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
237 {"gi_frame", T_OBJECT, offsetof(genobject, gi_frame), RO}, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
238 {"gi_running", T_INT, offsetof(genobject, gi_running), RO}, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
239 {NULL} /* Sentinel */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
240 }; |
|
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
|
241 |
|
24283
c0a67a1cab09
Removed more stray instances of statichere, but left _sre.c alone.
Tim Peters <tim.peters@gmail.com>
parents:
24280
diff
changeset
|
242 static PyTypeObject gentype = { |
|
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
|
243 PyObject_HEAD_INIT(&PyType_Type) |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
244 0, /* ob_size */ |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
245 "generator", /* tp_name */ |
|
22398
963e814e69cc
Re-enable GC of generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21974
diff
changeset
|
246 sizeof(genobject), /* tp_basicsize */ |
|
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
|
247 0, /* tp_itemsize */ |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
248 /* methods */ |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
249 (destructor)gen_dealloc, /* tp_dealloc */ |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
250 0, /* tp_print */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
251 0, /* tp_getattr */ |
|
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
|
252 0, /* tp_setattr */ |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
253 0, /* tp_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
|
254 0, /* tp_repr */ |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
255 0, /* tp_as_number */ |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
256 0, /* tp_as_sequence */ |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
257 0, /* tp_as_mapping */ |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
258 0, /* tp_hash */ |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
259 0, /* tp_call */ |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
260 0, /* tp_str */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
261 PyObject_GenericGetAttr, /* tp_getattro */ |
|
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
|
262 0, /* tp_setattro */ |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
263 0, /* tp_as_buffer */ |
|
22398
963e814e69cc
Re-enable GC of generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21974
diff
changeset
|
264 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ |
|
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
|
265 0, /* tp_doc */ |
|
18513
65afac84d4f7
GC for generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18374
diff
changeset
|
266 (traverseproc)gen_traverse, /* tp_traverse */ |
|
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
|
267 0, /* tp_clear */ |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
268 0, /* tp_richcompare */ |
|
24718
129d8d2e1904
Add weakref support generator-iterators.
Fred Drake <fdrake@acm.org>
parents:
24607
diff
changeset
|
269 offsetof(genobject, gi_weakreflist), /* tp_weaklistoffset */ |
|
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
|
270 (getiterfunc)gen_getiter, /* tp_iter */ |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
271 (iternextfunc)gen_iternext, /* tp_iternext */ |
|
24266
d98b0cdf7e51
There's no need for generators to define an explicit next() method.
Tim Peters <tim.peters@gmail.com>
parents:
24232
diff
changeset
|
272 0, /* tp_methods */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
273 gen_memberlist, /* tp_members */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
274 0, /* tp_getset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
275 0, /* tp_base */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
276 0, /* tp_dict */ |
|
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
|
277 }; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
278 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
279 |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
280 #ifdef WITH_THREAD |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
281 |
|
10530
d834ecdf8c26
Changes by Mark Hammond for Windows CE. Mostly of the form
Guido van Rossum <guido@python.org>
parents:
10363
diff
changeset
|
282 #ifndef DONT_HAVE_ERRNO_H |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
283 #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
|
284 #endif |
|
9203
07dae6fdae79
Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents:
9048
diff
changeset
|
285 #include "pythread.h" |
| 926 | 286 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
287 extern int _PyThread_Started; /* Flag for Py_Exit */ |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
288 |
|
29643
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
289 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
|
290 static long main_thread = 0; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
291 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
292 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
293 PyEval_InitThreads(void) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
294 { |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
295 if (interpreter_lock) |
| 1179 | 296 return; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
297 _PyThread_Started = 1; |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
298 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
|
299 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
|
300 main_thread = PyThread_get_thread_ident(); |
| 926 | 301 } |
| 302 | |
|
5865
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
303 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
304 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
|
305 { |
|
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); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
307 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
308 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
309 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
310 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
|
311 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
312 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
|
313 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
314 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
315 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
316 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
|
317 { |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
318 if (tstate == NULL) |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
319 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
|
320 /* 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
|
321 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
|
322 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
|
323 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
|
324 Py_FatalError( |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
325 "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
|
326 } |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
327 |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
328 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
329 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
|
330 { |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
331 if (tstate == NULL) |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
332 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
|
333 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
|
334 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
|
335 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
|
336 } |
|
14225
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
337 |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
338 /* 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
|
339 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
|
340 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
|
341 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
|
342 |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
343 void |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
344 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
|
345 { |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
346 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
|
347 return; |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
348 /*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
|
349 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
|
350 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
|
351 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
|
352 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
|
353 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
|
354 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
|
355 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
356 #endif |
| 926 | 357 |
| 358 /* Functions save_thread and restore_thread are always defined so | |
| 359 dynamically loaded modules needn't be compiled separately for use | |
| 360 with and without threads: */ | |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
361 |
|
5846
852a1fa62a7c
PyEval_SaveThread() and PyEval_RestoreThread() now return/take a
Guido van Rossum <guido@python.org>
parents:
5829
diff
changeset
|
362 PyThreadState * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
363 PyEval_SaveThread(void) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
364 { |
|
6365
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
365 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
|
366 if (tstate == NULL) |
|
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
367 Py_FatalError("PyEval_SaveThread: NULL tstate"); |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
368 #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
|
369 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
|
370 PyThread_release_lock(interpreter_lock); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
371 #endif |
|
6365
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
372 return tstate; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
373 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
374 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
375 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
376 PyEval_RestoreThread(PyThreadState *tstate) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
377 { |
|
6365
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
378 if (tstate == NULL) |
|
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
379 Py_FatalError("PyEval_RestoreThread: NULL tstate"); |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
380 #ifdef WITH_THREAD |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
381 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
|
382 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
|
383 PyThread_acquire_lock(interpreter_lock, 1); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
384 errno = err; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
385 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
386 #endif |
|
6365
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
387 PyThreadState_Swap(tstate); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
388 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
389 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
390 |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
391 /* 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
|
392 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
|
393 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
|
394 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
|
395 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
|
396 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
|
397 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
398 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
|
399 (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
|
400 an exception condition). |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
401 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
402 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
|
403 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
|
404 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
405 #ifdef WITH_THREAD |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
406 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
|
407 will execute them. |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
408 #endif |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
409 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
410 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
|
411 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
|
412 (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
|
413 (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
|
414 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
|
415 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
|
416 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
|
417 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
|
418 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
419 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
|
420 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
|
421 */ |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
422 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
423 #define NPENDINGCALLS 32 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
424 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
|
425 int (*func)(void *); |
|
4e2aaf1e722a
Use 'void' directly instead of the ANY #define, now that all code is ANSI C.
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
426 void *arg; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
427 } pendingcalls[NPENDINGCALLS]; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
428 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
|
429 static volatile int pendinglast = 0; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
430 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
|
431 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
432 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
|
433 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
|
434 { |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
435 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
|
436 int i, j; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
437 /* 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
|
438 /* 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
|
439 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
|
440 if (busy) |
|
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
441 return -1; |
|
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
442 busy = 1; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
443 i = pendinglast; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
444 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
|
445 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
|
446 busy = 0; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
447 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
|
448 } |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
449 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
|
450 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
|
451 pendinglast = j; |
|
25108
3a26e352f0a6
replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents:
25078
diff
changeset
|
452 |
|
3a26e352f0a6
replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents:
25078
diff
changeset
|
453 _Py_Ticker = 0; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
454 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
|
455 busy = 0; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
456 /* 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
|
457 return 0; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
458 } |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
459 |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
460 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
461 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
|
462 { |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
463 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
|
464 #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
|
465 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
|
466 return 0; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
467 #endif |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
468 if (busy) |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
469 return 0; |
|
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
470 busy = 1; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
471 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
|
472 for (;;) { |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
473 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
|
474 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
|
475 void *arg; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
476 i = pendingfirst; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
477 if (i == pendinglast) |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
478 break; /* Queue empty */ |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
479 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
|
480 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
|
481 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
|
482 if (func(arg) < 0) { |
|
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
483 busy = 0; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
484 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
|
485 return -1; |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
486 } |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
487 } |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
488 busy = 0; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
489 return 0; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
490 } |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
491 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
492 |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
493 /* The interpreter's recursion limit */ |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
494 |
|
14325
22b2ebd78372
Set the recursion limit to 1000 -- 2500 was not enough, let's be
Guido van Rossum <guido@python.org>
parents:
14318
diff
changeset
|
495 static int recursion_limit = 1000; |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
496 int _Py_CheckRecursionLimit = 1000; |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
497 |
|
14348
6d0f64f7dedd
Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14333
diff
changeset
|
498 int |
|
6d0f64f7dedd
Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14333
diff
changeset
|
499 Py_GetRecursionLimit(void) |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
500 { |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
501 return recursion_limit; |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
502 } |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
503 |
|
14348
6d0f64f7dedd
Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14333
diff
changeset
|
504 void |
|
6d0f64f7dedd
Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14333
diff
changeset
|
505 Py_SetRecursionLimit(int new_limit) |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
506 { |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
507 recursion_limit = new_limit; |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
508 _Py_CheckRecursionLimit = recursion_limit; |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
509 } |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
510 |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
511 /* the macro Py_EnterRecursiveCall() only calls _Py_CheckRecursiveCall() |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
512 if the recursion_depth reaches _Py_CheckRecursionLimit. |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
513 If USE_STACKCHECK, the macro decrements _Py_CheckRecursionLimit |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
514 to guarantee that _Py_CheckRecursiveCall() is regularly called. |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
515 Without USE_STACKCHECK, there is no need for this. */ |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
516 int |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
517 _Py_CheckRecursiveCall(char *where) |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
518 { |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
519 PyThreadState *tstate = PyThreadState_GET(); |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
520 |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
521 #ifdef USE_STACKCHECK |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
522 if (PyOS_CheckStack()) { |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
523 --tstate->recursion_depth; |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
524 PyErr_SetString(PyExc_MemoryError, "Stack overflow"); |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
525 return -1; |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
526 } |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
527 #endif |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
528 if (tstate->recursion_depth > recursion_limit) { |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
529 --tstate->recursion_depth; |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
530 PyErr_Format(PyExc_RuntimeError, |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
531 "maximum recursion depth exceeded%s", |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
532 where); |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
533 return -1; |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
534 } |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
535 _Py_CheckRecursionLimit = recursion_limit; |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
536 return 0; |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
537 } |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
538 |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
539 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
540 /* Status code for main loop (reason for stack unwind) */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
541 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
542 enum why_code { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
543 WHY_NOT, /* No error */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
544 WHY_EXCEPTION, /* Exception occurred */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
545 WHY_RERAISE, /* Exception re-raised by 'finally' */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
546 WHY_RETURN, /* 'return' statement */ |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
547 WHY_BREAK, /* 'break' statement */ |
|
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
|
548 WHY_CONTINUE, /* 'continue' statement */ |
|
20541
f567b45737c0
SF Patch (but with no patch) 472555 Remove trailing common in enumeration.
Tim Peters <tim.peters@gmail.com>
parents:
20492
diff
changeset
|
549 WHY_YIELD /* 'yield' operator */ |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
550 }; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
551 |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
552 static enum why_code do_raise(PyObject *, PyObject *, PyObject *); |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
553 static int unpack_iterable(PyObject *, int, PyObject **); |
| 5018 | 554 |
|
25108
3a26e352f0a6
replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents:
25078
diff
changeset
|
555 /* 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
|
556 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
|
557 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
|
558 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
|
559 |
| 5368 | 560 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
561 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
|
562 { |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
563 /* XXX raise SystemError if globals is NULL */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
564 return PyEval_EvalCodeEx(co, |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
565 globals, locals, |
| 5368 | 566 (PyObject **)NULL, 0, |
| 567 (PyObject **)NULL, 0, | |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
568 (PyObject **)NULL, 0, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
569 NULL); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
570 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
571 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
572 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
573 /* Interpreter main loop */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
574 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
575 static PyObject * |
|
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
|
576 eval_frame(PyFrameObject *f) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
577 { |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
578 #ifdef DXPAIRS |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
579 int lastopcode = 0; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
580 #endif |
|
21477
ccb26a118867
SF bug #494668: PUSH() should assert-fail on overflow.
Tim Peters <tim.peters@gmail.com>
parents:
21475
diff
changeset
|
581 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
|
582 register unsigned char *next_instr; |
|
13881
c4e321834250
Initialized opcode and oparg to silence a gcc -Wall warning.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
13709
diff
changeset
|
583 register int opcode=0; /* Current opcode */ |
|
c4e321834250
Initialized opcode and oparg to silence a gcc -Wall warning.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
13709
diff
changeset
|
584 register int oparg=0; /* Current opcode argument, if any */ |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
585 register enum why_code why; /* Reason for block stack unwind */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
586 register int err; /* Error status -- nonzero if error */ |
| 5368 | 587 register PyObject *x; /* Result object -- NULL if error */ |
| 588 register PyObject *v; /* Temporary objects popped off stack */ | |
| 589 register PyObject *w; | |
| 590 register PyObject *u; | |
| 591 register PyObject *t; | |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
592 register PyObject *stream = NULL; /* for PRINT opcodes */ |
|
16355
e4420c2468f9
Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16257
diff
changeset
|
593 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
|
594 PyObject *retval = NULL; /* Return value */ |
|
9671
1d40bc25703a
Use PyThreadState_GET() macro.
Guido van Rossum <guido@python.org>
parents:
9591
diff
changeset
|
595 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
|
596 PyCodeObject *co; |
| 24844 | 597 |
| 598 /* when tracing we set things up so that | |
| 599 | |
| 600 not (instr_lb <= current_bytecode_offset < instr_ub) | |
| 601 | |
| 602 is true when the line being executed has changed. The | |
| 603 initial values are such as to make this false the first | |
| 604 time it is tested. */ | |
| 605 int instr_ub = -1, instr_lb = 0; | |
| 606 | |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
607 unsigned char *first_instr; |
|
24545
d2f41c8a81f0
small speedup for constant and name access
Skip Montanaro <skip@pobox.com>
parents:
24284
diff
changeset
|
608 PyObject *names; |
|
d2f41c8a81f0
small speedup for constant and name access
Skip Montanaro <skip@pobox.com>
parents:
24284
diff
changeset
|
609 PyObject *consts; |
| 567 | 610 #ifdef LLTRACE |
|
1273
69a066b6b1ff
(I suggest a recompile after getting this, the ceval.c bugfix may be crucial!)
Guido van Rossum <guido@python.org>
parents:
1271
diff
changeset
|
611 int lltrace; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
612 #endif |
|
4839
4567e158d20c
Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents:
4667
diff
changeset
|
613 #if defined(Py_DEBUG) || defined(LLTRACE) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
614 /* 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
|
615 char *filename; |
|
1016
a41e3ba5b47d
Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents:
974
diff
changeset
|
616 #endif |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
617 |
|
24232
e06b1ab0bdb8
SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents:
24190
diff
changeset
|
618 /* 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
|
619 |
|
e06b1ab0bdb8
SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents:
24190
diff
changeset
|
620 #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
|
621 #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
|
622 #else |
|
e06b1ab0bdb8
SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents:
24190
diff
changeset
|
623 #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
|
624 #endif |
|
e06b1ab0bdb8
SF patch # 580411, move frame macros from frameobject.h into ceval.c
Neal Norwitz <nnorwitz@gmail.com>
parents:
24190
diff
changeset
|
625 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
626 /* Code access macros */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
627 |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
628 #define INSTR_OFFSET() (next_instr - first_instr) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
629 #define NEXTOP() (*next_instr++) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
630 #define NEXTARG() (next_instr += 2, (next_instr[-1]<<8) + next_instr[-2]) |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
631 #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
|
632 #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
|
633 |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
634 /* OpCode prediction macros |
|
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
635 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
|
636 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
|
637 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
|
638 followed by a POP_TOP. |
|
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
639 |
|
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
640 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
|
641 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
|
642 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
|
643 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
|
644 next opcode. |
|
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
645 |
|
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
646 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
|
647 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
|
648 |
|
f57f5ce22c8d
SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents:
31462
diff
changeset
|
649 If collecting opcode statistics, turn off prediction so that |
|
f57f5ce22c8d
SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents:
31462
diff
changeset
|
650 statistics are accurately maintained (the predictions bypass |
|
f57f5ce22c8d
SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents:
31462
diff
changeset
|
651 the opcode frequency counter updates). |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
652 */ |
|
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
653 |
|
31487
f57f5ce22c8d
SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents:
31462
diff
changeset
|
654 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
f57f5ce22c8d
SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents:
31462
diff
changeset
|
655 #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
|
656 #else |
|
28303
470504ef578b
Fix comment and whitespace.
Raymond Hettinger <python@rcn.com>
parents:
28302
diff
changeset
|
657 #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
|
658 #endif |
|
f57f5ce22c8d
SF patch #884022: dynamic execution profiling vs opcode prediction
Raymond Hettinger <python@rcn.com>
parents:
31462
diff
changeset
|
659 |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
660 #define PREDICTED(op) PRED_##op: next_instr++ |
|
28304
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
661 #define PREDICTED_WITH_ARG(op) PRED_##op: oparg = (next_instr[2]<<8) + \ |
|
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
662 next_instr[1]; next_instr += 3 |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
663 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
664 /* Stack manipulation macros */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
665 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
666 #define STACK_LEVEL() (stack_pointer - f->f_valuestack) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
667 #define EMPTY() (STACK_LEVEL() == 0) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
668 #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
|
669 #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
|
670 #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
|
671 #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
|
672 #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
|
673 #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
|
674 #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
|
675 #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
|
676 #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
|
677 #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
|
678 #define BASIC_POP() (*--stack_pointer) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
679 |
| 567 | 680 #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
|
681 #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
|
682 lltrace && prtrace(TOP(), "push")); \ |
|
bf4ff05eab52
For debug build, check that the stack pointer never exceeds the stack size.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20438
diff
changeset
|
683 assert(STACK_LEVEL() <= f->f_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
|
684 #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
|
685 #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
|
686 lltrace && prtrace(TOP(), "stackadj")); \ |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
687 assert(STACK_LEVEL() <= f->f_stacksize); } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
688 #else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
689 #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
|
690 #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
|
691 #define STACKADJ(n) BASIC_STACKADJ(n) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
692 #endif |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
693 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
694 /* Local variable macros */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
695 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
696 #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
|
697 |
|
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
|
698 /* 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
|
699 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
|
700 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
|
701 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
|
702 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
|
703 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
|
704 #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
|
705 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
|
706 Py_XDECREF(tmp); } while (0) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
707 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
708 /* Start of code */ |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
709 |
|
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
|
710 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
|
711 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
|
712 |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
713 /* push frame */ |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
714 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
|
715 return NULL; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
716 |
|
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
|
717 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
|
718 |
|
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 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
|
720 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
|
721 /* 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
|
722 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
|
723 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
|
724 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
|
725 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
|
726 (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
|
727 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
|
728 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
|
729 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
|
730 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
|
731 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
|
732 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
|
733 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
|
734 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
|
735 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
|
736 /* Trace function raised an error */ |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
737 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
|
738 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
739 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
740 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
|
741 /* 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
|
742 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
|
743 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
|
744 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
|
745 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
|
746 /* Profile function raised an error */ |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
747 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
|
748 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
749 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
750 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
751 |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
752 co = f->f_code; |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
753 names = co->co_names; |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
754 consts = co->co_consts; |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
755 fastlocals = f->f_localsplus; |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
756 freevars = f->f_localsplus + f->f_nlocals; |
|
31514
545229dfd909
This is my patch #876198 plus a NEWS entry and a header frob.
Michael W. Hudson <mwh@python.net>
parents:
31504
diff
changeset
|
757 first_instr = PyString_AS_STRING(co->co_code); |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
758 /* 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
|
759 |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
760 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
|
761 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
|
762 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
|
763 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
|
764 and YIELD_VALUE doesn't fiddle with f_lasti any more. So this |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
765 does work. Promise. */ |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
766 next_instr = first_instr + f->f_lasti + 1; |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
767 stack_pointer = f->f_stacktop; |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
768 assert(stack_pointer != NULL); |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
769 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
|
770 |
|
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
|
771 #ifdef LLTRACE |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
772 lltrace = PyDict_GetItemString(f->f_globals,"__lltrace__") != 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
|
773 #endif |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
774 #if defined(Py_DEBUG) || defined(LLTRACE) |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
775 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
|
776 #endif |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
777 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
778 why = WHY_NOT; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
779 err = 0; |
| 5368 | 780 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
|
781 w = NULL; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
782 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
783 for (;;) { |
| 24844 | 784 assert(stack_pointer >= f->f_valuestack); /* else underflow */ |
| 785 assert(STACK_LEVEL() <= f->f_stacksize); /* else overflow */ | |
| 786 | |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
787 /* 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
|
788 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
|
789 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
|
790 ``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
|
791 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
|
792 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
|
793 Py_MakePendingCalls() above. */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
794 |
|
25108
3a26e352f0a6
replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents:
25078
diff
changeset
|
795 if (--_Py_Ticker < 0) { |
|
29643
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
796 if (*next_instr == SETUP_FINALLY) { |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
797 /* Make the last opcode before |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
798 a try: finally: block uninterruptable. */ |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
799 goto fast_next_opcode; |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
800 } |
|
25108
3a26e352f0a6
replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents:
25078
diff
changeset
|
801 _Py_Ticker = _Py_CheckInterval; |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
802 tstate->tick_counter++; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
803 if (things_to_do) { |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
804 if (Py_MakePendingCalls() < 0) { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
805 why = WHY_EXCEPTION; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
806 goto on_error; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
807 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
808 } |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
809 #ifdef WITH_THREAD |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
810 if (interpreter_lock) { |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
811 /* Give another thread a chance */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
812 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
813 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
|
814 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
|
815 PyThread_release_lock(interpreter_lock); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
816 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
817 /* Other threads may run now */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
818 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
819 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
|
820 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
|
821 Py_FatalError("ceval: orphan tstate"); |
|
29643
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
822 |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
823 /* Check for thread interrupts */ |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
824 |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
825 if (tstate->async_exc != NULL) { |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
826 x = tstate->async_exc; |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
827 tstate->async_exc = NULL; |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
828 PyErr_SetNone(x); |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
829 Py_DECREF(x); |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
830 why = WHY_EXCEPTION; |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
831 goto on_error; |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
29349
diff
changeset
|
832 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
833 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
834 #endif |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
835 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
836 |
|
21974
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
837 fast_next_opcode: |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
838 f->f_lasti = INSTR_OFFSET(); |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
839 |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
840 /* line-by-line tracing support */ |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
841 |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
842 if (tstate->c_tracefunc != NULL && !tstate->tracing) { |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
843 /* see maybe_call_line_trace |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
844 for expository comments */ |
|
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
845 f->f_stacktop = stack_pointer; |
|
26110
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
846 |
|
28886
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
847 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
|
848 tstate->c_traceobj, |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
849 f, &instr_lb, &instr_ub); |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
850 /* Reload possibly changed frame fields */ |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
851 JUMPTO(f->f_lasti); |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
852 if (f->f_stacktop != NULL) { |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
853 stack_pointer = f->f_stacktop; |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
854 f->f_stacktop = NULL; |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
855 } |
|
af53729d3cdd
Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
856 if (err) { |
|
26110
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
857 /* trace function raised an exception */ |
|
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
858 goto on_error; |
|
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
859 } |
|
26109
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 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
862 /* Extract opcode and argument */ |
|
1016
a41e3ba5b47d
Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents:
974
diff
changeset
|
863 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
864 opcode = NEXTOP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
865 if (HAS_ARG(opcode)) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
866 oparg = NEXTARG(); |
|
14147
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
867 dispatch_opcode: |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
868 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
869 #ifdef DXPAIRS |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
870 dxpairs[lastopcode][opcode]++; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
871 lastopcode = opcode; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
872 #endif |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
873 dxp[opcode]++; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
874 #endif |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
875 |
| 567 | 876 #ifdef LLTRACE |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
877 /* Instruction tracing */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
878 |
| 567 | 879 if (lltrace) { |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
880 if (HAS_ARG(opcode)) { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
881 printf("%d: %d, %d\n", |
| 24844 | 882 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
|
883 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
884 else { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
885 printf("%d: %d\n", |
| 24844 | 886 f->f_lasti, opcode); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
887 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
888 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
889 #endif |
| 24844 | 890 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
891 /* Main switch on opcode */ |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
892 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
893 switch (opcode) { |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
894 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
895 /* BEWARE! |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
896 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
|
897 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
|
898 and that no operation that succeeds does this! */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
899 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
900 /* case STOP_CODE: this is an error! */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
901 |
|
21974
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
902 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
|
903 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
|
904 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
|
905 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
|
906 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
|
907 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
|
908 } |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
909 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
|
910 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
|
911 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
|
912 break; |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
913 |
|
052efc06520a
Move some opcodes to top of big eval_frame switch statement. Skip
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
21935
diff
changeset
|
914 case LOAD_CONST: |
|
24545
d2f41c8a81f0
small speedup for constant and name access
Skip Montanaro <skip@pobox.com>
parents:
24284
diff
changeset
|
915 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
|
916 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
|
917 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
|
918 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
|
919 |
|
28304
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
920 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
|
921 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
|
922 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
|
923 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
|
924 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
|
925 |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
926 PREDICTED(POP_TOP); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
927 case POP_TOP: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
928 v = POP(); |
| 5368 | 929 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
|
930 goto fast_next_opcode; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
931 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
932 case ROT_TWO: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
933 v = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
934 w = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
935 SET_TOP(w); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
936 SET_SECOND(v); |
|
28296
7654c24decc4
SF patch #701907: More use of fast_next_opcode
Raymond Hettinger <python@rcn.com>
parents:
28121
diff
changeset
|
937 goto fast_next_opcode; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
938 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
939 case ROT_THREE: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
940 v = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
941 w = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
942 x = THIRD(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
943 SET_TOP(w); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
944 SET_SECOND(x); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
945 SET_THIRD(v); |
|
28296
7654c24decc4
SF patch #701907: More use of fast_next_opcode
Raymond Hettinger <python@rcn.com>
parents:
28121
diff
changeset
|
946 goto fast_next_opcode; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
947 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
948 case ROT_FOUR: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
949 u = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
950 v = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
951 w = THIRD(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
952 x = FOURTH(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
953 SET_TOP(v); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
954 SET_SECOND(w); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
955 SET_THIRD(x); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
956 SET_FOURTH(u); |
|
28296
7654c24decc4
SF patch #701907: More use of fast_next_opcode
Raymond Hettinger <python@rcn.com>
parents:
28121
diff
changeset
|
957 goto fast_next_opcode; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
958 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
959 case DUP_TOP: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
960 v = TOP(); |
| 5368 | 961 Py_INCREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
962 PUSH(v); |
|
28296
7654c24decc4
SF patch #701907: More use of fast_next_opcode
Raymond Hettinger <python@rcn.com>
parents:
28121
diff
changeset
|
963 goto fast_next_opcode; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
964 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
965 case DUP_TOPX: |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
966 if (oparg == 2) { |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
967 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
|
968 Py_INCREF(x); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
969 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
|
970 Py_INCREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
971 STACKADJ(2); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
972 SET_TOP(x); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
973 SET_SECOND(w); |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
974 goto fast_next_opcode; |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
975 } 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
|
976 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
|
977 Py_INCREF(x); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
978 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
|
979 Py_INCREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
980 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
|
981 Py_INCREF(v); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
982 STACKADJ(3); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
983 SET_TOP(x); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
984 SET_SECOND(w); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
985 SET_THIRD(v); |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
986 goto fast_next_opcode; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
987 } |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
988 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
|
989 " (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
|
990 break; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
991 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
992 case UNARY_POSITIVE: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
993 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
994 x = PyNumber_Positive(v); |
| 5368 | 995 Py_DECREF(v); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
996 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
|
997 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
998 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
999 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1000 case UNARY_NEGATIVE: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1001 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1002 x = PyNumber_Negative(v); |
| 5368 | 1003 Py_DECREF(v); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1004 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
|
1005 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1006 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1007 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1008 case UNARY_NOT: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1009 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1010 err = PyObject_IsTrue(v); |
| 5368 | 1011 Py_DECREF(v); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1012 if (err == 0) { |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1013 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
|
1014 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
|
1015 continue; |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1016 } |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1017 else if (err > 0) { |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1018 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
|
1019 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
|
1020 err = 0; |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1021 continue; |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1022 } |
|
27243
3afbd55fb18f
Replaced POP() with STACKADJ(-1) on lines where the result wasn't used.
Raymond Hettinger <python@rcn.com>
parents:
27201
diff
changeset
|
1023 STACKADJ(-1); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1024 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1025 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1026 case UNARY_CONVERT: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1027 v = TOP(); |
| 5368 | 1028 x = PyObject_Repr(v); |
| 1029 Py_DECREF(v); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1030 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
|
1031 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1032 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1033 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1034 case UNARY_INVERT: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1035 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1036 x = PyNumber_Invert(v); |
| 5368 | 1037 Py_DECREF(v); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1038 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
|
1039 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1040 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1041 |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3294
diff
changeset
|
1042 case BINARY_POWER: |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3294
diff
changeset
|
1043 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1044 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1045 x = PyNumber_Power(v, w, Py_None); |
| 5368 | 1046 Py_DECREF(v); |
| 1047 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1048 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
|
1049 if (x != NULL) continue; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3294
diff
changeset
|
1050 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1051 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1052 case BINARY_MULTIPLY: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1053 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1054 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1055 x = PyNumber_Multiply(v, w); |
| 5368 | 1056 Py_DECREF(v); |
| 1057 Py_DECREF(w); | |
|
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; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1060 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1061 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1062 case BINARY_DIVIDE: |
|
21251
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1063 if (!_Py_QnewFlag) { |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1064 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1065 v = TOP(); |
|
21251
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1066 x = PyNumber_Divide(v, w); |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1067 Py_DECREF(v); |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1068 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1069 SET_TOP(x); |
|
21251
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1070 if (x != NULL) continue; |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1071 break; |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1072 } |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1073 /* -Qnew is in effect: fall through to |
|
21251
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1074 BINARY_TRUE_DIVIDE */ |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1075 case BINARY_TRUE_DIVIDE: |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1076 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1077 v = TOP(); |
|
21251
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
1078 x = PyNumber_TrueDivide(v, w); |
| 5368 | 1079 Py_DECREF(v); |
| 1080 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1081 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
|
1082 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1083 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1084 |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1085 case BINARY_FLOOR_DIVIDE: |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1086 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1087 v = TOP(); |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1088 x = PyNumber_FloorDivide(v, w); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1089 Py_DECREF(v); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1090 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1091 SET_TOP(x); |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1092 if (x != NULL) continue; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1093 break; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1094 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1095 case BINARY_MODULO: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1096 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1097 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1098 x = PyNumber_Remainder(v, w); |
| 5368 | 1099 Py_DECREF(v); |
| 1100 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1101 SET_TOP(x); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1102 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1103 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1104 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1105 case BINARY_ADD: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1106 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1107 v = TOP(); |
|
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
|
1108 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
|
1109 /* INLINE: int + int */ |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1110 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
|
1111 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
|
1112 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
|
1113 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
|
1114 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
|
1115 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
|
1116 x = PyInt_FromLong(i); |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1117 } |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1118 else { |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1119 slow_add: |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1120 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
|
1121 } |
| 5368 | 1122 Py_DECREF(v); |
| 1123 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1124 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
|
1125 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1126 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1127 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1128 case BINARY_SUBTRACT: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1129 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1130 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
|
1131 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
|
1132 /* INLINE: int - int */ |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1133 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
|
1134 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
|
1135 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
|
1136 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
|
1137 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
|
1138 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
|
1139 x = PyInt_FromLong(i); |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1140 } |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1141 else { |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1142 slow_sub: |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1143 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
|
1144 } |
| 5368 | 1145 Py_DECREF(v); |
| 1146 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1147 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
|
1148 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1149 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1150 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1151 case BINARY_SUBSCR: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1152 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1153 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
|
1154 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
|
1155 /* INLINE: list[int] */ |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1156 long i = PyInt_AsLong(w); |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1157 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
|
1158 i += PyList_GET_SIZE(v); |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1159 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
|
1160 i >= PyList_GET_SIZE(v)) { |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1161 PyErr_SetString(PyExc_IndexError, |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1162 "list index out of range"); |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1163 x = NULL; |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1164 } |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1165 else { |
|
8652
97a1108b0eb2
# In case BINARY_SUBSCR, use proper PyList_GET* macros instead of inlining.
Guido van Rossum <guido@python.org>
parents:
8651
diff
changeset
|
1166 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
|
1167 Py_INCREF(x); |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1168 } |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1169 } |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1170 else |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1171 x = PyObject_GetItem(v, w); |
| 5368 | 1172 Py_DECREF(v); |
| 1173 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1174 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
|
1175 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1176 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1177 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1178 case BINARY_LSHIFT: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1179 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1180 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1181 x = PyNumber_Lshift(v, w); |
| 5368 | 1182 Py_DECREF(v); |
| 1183 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1184 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
|
1185 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1186 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1187 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1188 case BINARY_RSHIFT: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1189 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1190 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1191 x = PyNumber_Rshift(v, w); |
| 5368 | 1192 Py_DECREF(v); |
| 1193 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1194 SET_TOP(x); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1195 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1196 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1197 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1198 case BINARY_AND: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1199 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1200 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1201 x = PyNumber_And(v, w); |
| 5368 | 1202 Py_DECREF(v); |
| 1203 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1204 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
|
1205 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1206 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1207 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1208 case BINARY_XOR: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1209 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1210 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1211 x = PyNumber_Xor(v, w); |
| 5368 | 1212 Py_DECREF(v); |
| 1213 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1214 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
|
1215 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1216 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1217 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1218 case BINARY_OR: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1219 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1220 v = TOP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1221 x = PyNumber_Or(v, w); |
| 5368 | 1222 Py_DECREF(v); |
| 1223 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1224 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
|
1225 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1226 break; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1227 |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1228 case INPLACE_POWER: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1229 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1230 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1231 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
|
1232 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1233 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1234 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1235 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1236 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1237 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1238 case INPLACE_MULTIPLY: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1239 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1240 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1241 x = PyNumber_InPlaceMultiply(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1242 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1243 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1244 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1245 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1246 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1247 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1248 case INPLACE_DIVIDE: |
|
21537
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1249 if (!_Py_QnewFlag) { |
|
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1250 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1251 v = TOP(); |
|
21537
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1252 x = PyNumber_InPlaceDivide(v, w); |
|
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1253 Py_DECREF(v); |
|
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1254 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1255 SET_TOP(x); |
|
21537
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1256 if (x != NULL) continue; |
|
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1257 break; |
|
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1258 } |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1259 /* -Qnew is in effect: fall through to |
|
21537
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1260 INPLACE_TRUE_DIVIDE */ |
|
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1261 case INPLACE_TRUE_DIVIDE: |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1262 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1263 v = TOP(); |
|
21537
ca27d82ac89b
SF bug #496549 -Qnew and in-place division "/=".
Tim Peters <tim.peters@gmail.com>
parents:
21477
diff
changeset
|
1264 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
|
1265 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1266 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1267 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1268 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1269 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1270 |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1271 case INPLACE_FLOOR_DIVIDE: |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1272 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1273 v = TOP(); |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1274 x = PyNumber_InPlaceFloorDivide(v, w); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1275 Py_DECREF(v); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1276 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1277 SET_TOP(x); |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1278 if (x != NULL) continue; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1279 break; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1280 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1281 case INPLACE_MODULO: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1282 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1283 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1284 x = PyNumber_InPlaceRemainder(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1285 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1286 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1287 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1288 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1289 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1290 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1291 case INPLACE_ADD: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1292 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1293 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
|
1294 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
|
1295 /* INLINE: int + int */ |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1296 register long a, b, i; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1297 a = PyInt_AS_LONG(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1298 b = PyInt_AS_LONG(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1299 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
|
1300 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
|
1301 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
|
1302 x = PyInt_FromLong(i); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1303 } |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1304 else { |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1305 slow_iadd: |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1306 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
|
1307 } |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1308 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1309 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1310 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1311 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1312 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1313 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1314 case INPLACE_SUBTRACT: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1315 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1316 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
|
1317 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
|
1318 /* INLINE: int - int */ |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1319 register long a, b, i; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1320 a = PyInt_AS_LONG(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1321 b = PyInt_AS_LONG(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1322 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
|
1323 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
|
1324 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
|
1325 x = PyInt_FromLong(i); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1326 } |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1327 else { |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1328 slow_isub: |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1329 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
|
1330 } |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1331 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1332 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1333 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1334 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1335 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1336 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1337 case INPLACE_LSHIFT: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1338 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1339 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1340 x = PyNumber_InPlaceLshift(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1341 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1342 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1343 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1344 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1345 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1346 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1347 case INPLACE_RSHIFT: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1348 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1349 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1350 x = PyNumber_InPlaceRshift(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1351 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1352 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1353 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1354 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1355 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1356 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1357 case INPLACE_AND: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1358 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1359 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1360 x = PyNumber_InPlaceAnd(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1361 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1362 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1363 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1364 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1365 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1366 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1367 case INPLACE_XOR: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1368 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1369 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1370 x = PyNumber_InPlaceXor(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1371 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1372 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1373 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1374 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1375 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1376 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1377 case INPLACE_OR: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1378 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1379 v = TOP(); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1380 x = PyNumber_InPlaceOr(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1381 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1382 Py_DECREF(w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1383 SET_TOP(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1384 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1385 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1386 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1387 case SLICE+0: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1388 case SLICE+1: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1389 case SLICE+2: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1390 case SLICE+3: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1391 if ((opcode-SLICE) & 2) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1392 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1393 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1394 w = NULL; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1395 if ((opcode-SLICE) & 1) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1396 v = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1397 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1398 v = NULL; |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1399 u = TOP(); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1400 x = apply_slice(u, v, w); |
| 5368 | 1401 Py_DECREF(u); |
| 1402 Py_XDECREF(v); | |
| 1403 Py_XDECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1404 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
|
1405 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1406 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1407 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1408 case STORE_SLICE+0: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1409 case STORE_SLICE+1: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1410 case STORE_SLICE+2: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1411 case STORE_SLICE+3: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1412 if ((opcode-STORE_SLICE) & 2) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1413 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1414 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1415 w = NULL; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1416 if ((opcode-STORE_SLICE) & 1) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1417 v = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1418 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1419 v = NULL; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1420 u = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1421 t = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1422 err = assign_slice(u, v, w, t); /* u[v:w] = t */ |
| 5368 | 1423 Py_DECREF(t); |
| 1424 Py_DECREF(u); | |
| 1425 Py_XDECREF(v); | |
| 1426 Py_XDECREF(w); | |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1427 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1428 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1429 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1430 case DELETE_SLICE+0: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1431 case DELETE_SLICE+1: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1432 case DELETE_SLICE+2: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1433 case DELETE_SLICE+3: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1434 if ((opcode-DELETE_SLICE) & 2) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1435 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1436 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1437 w = NULL; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1438 if ((opcode-DELETE_SLICE) & 1) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1439 v = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1440 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1441 v = NULL; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1442 u = POP(); |
| 5368 | 1443 err = assign_slice(u, v, w, (PyObject *)NULL); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1444 /* del u[v:w] */ |
| 5368 | 1445 Py_DECREF(u); |
| 1446 Py_XDECREF(v); | |
| 1447 Py_XDECREF(w); | |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1448 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1449 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1450 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1451 case STORE_SUBSCR: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1452 w = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1453 v = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1454 u = THIRD(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1455 STACKADJ(-3); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1456 /* v[w] = u */ |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1457 err = PyObject_SetItem(v, w, u); |
| 5368 | 1458 Py_DECREF(u); |
| 1459 Py_DECREF(v); | |
| 1460 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
|
1461 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1462 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1463 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1464 case DELETE_SUBSCR: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1465 w = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1466 v = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1467 STACKADJ(-2); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1468 /* del v[w] */ |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1469 err = PyObject_DelItem(v, w); |
| 5368 | 1470 Py_DECREF(v); |
| 1471 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
|
1472 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1473 break; |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1474 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1475 case PRINT_EXPR: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1476 v = POP(); |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1477 w = PySys_GetObject("displayhook"); |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1478 if (w == NULL) { |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1479 PyErr_SetString(PyExc_RuntimeError, |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1480 "lost sys.displayhook"); |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1481 err = -1; |
|
15814
faaf9f10d849
Fixed bugs noted by Greg Stein
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15811
diff
changeset
|
1482 x = NULL; |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1483 } |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1484 if (err == 0) { |
|
30683
3b59fa5d25b1
Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents:
29669
diff
changeset
|
1485 x = PyTuple_Pack(1, v); |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1486 if (x == NULL) |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1487 err = -1; |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1488 } |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1489 if (err == 0) { |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1490 w = PyEval_CallObject(w, x); |
|
15814
faaf9f10d849
Fixed bugs noted by Greg Stein
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15811
diff
changeset
|
1491 Py_XDECREF(w); |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1492 if (w == NULL) |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1493 err = -1; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1494 } |
| 5368 | 1495 Py_DECREF(v); |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1496 Py_XDECREF(x); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1497 break; |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1498 |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1499 case PRINT_ITEM_TO: |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1500 w = stream = POP(); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1501 /* fall through to PRINT_ITEM */ |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1502 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1503 case PRINT_ITEM: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1504 v = POP(); |
|
14238
74f7f237f739
eval_code2(): Guido provides this patch for his suggested elaboration
Barry Warsaw <barry@python.org>
parents:
14232
diff
changeset
|
1505 if (stream == NULL || stream == Py_None) { |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1506 w = PySys_GetObject("stdout"); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1507 if (w == NULL) { |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1508 PyErr_SetString(PyExc_RuntimeError, |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1509 "lost sys.stdout"); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1510 err = -1; |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1511 } |
|
7014
c75d899e666f
Last-minute fix for Jim H: don't die after del sys.stdout
Guido van Rossum <guido@python.org>
parents:
6945
diff
changeset
|
1512 } |
|
29669
96ecaab4cba6
Fix SF #762455, segfault when sys.stdout is changed in getattr
Neal Norwitz <nnorwitz@gmail.com>
parents:
29643
diff
changeset
|
1513 /* PyFile_SoftSpace() can exececute arbitrary code |
|
96ecaab4cba6
Fix SF #762455, segfault when sys.stdout is changed in getattr
Neal Norwitz <nnorwitz@gmail.com>
parents:
29643
diff
changeset
|
1514 if sys.stdout is an instance with a __getattr__. |
|
96ecaab4cba6
Fix SF #762455, segfault when sys.stdout is changed in getattr
Neal Norwitz <nnorwitz@gmail.com>
parents:
29643
diff
changeset
|
1515 If __getattr__ raises an exception, w will |
|
96ecaab4cba6
Fix SF #762455, segfault when sys.stdout is changed in getattr
Neal Norwitz <nnorwitz@gmail.com>
parents:
29643
diff
changeset
|
1516 be freed, so we need to prevent that temporarily. */ |
|
96ecaab4cba6
Fix SF #762455, segfault when sys.stdout is changed in getattr
Neal Norwitz <nnorwitz@gmail.com>
parents:
29643
diff
changeset
|
1517 Py_XINCREF(w); |
|
22499
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1518 if (w != NULL && PyFile_SoftSpace(w, 0)) |
|
5606
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
1519 err = PyFile_WriteString(" ", w); |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
1520 if (err == 0) |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
1521 err = PyFile_WriteObject(v, w, Py_PRINT_RAW); |
|
21027
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1522 if (err == 0) { |
|
22499
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1523 /* XXX move into writeobject() ? */ |
|
21027
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1524 if (PyString_Check(v)) { |
|
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1525 char *s = PyString_AS_STRING(v); |
|
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1526 int len = PyString_GET_SIZE(v); |
|
22499
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1527 if (len == 0 || |
|
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1528 !isspace(Py_CHARMASK(s[len-1])) || |
|
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1529 s[len-1] == ' ') |
|
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1530 PyFile_SoftSpace(w, 1); |
|
21027
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1531 } |
|
21475
aac23331a25d
Patch #494384: Disable more Unicode API if Unicode is not used.
Martin v. Löwis <martin@v.loewis.de>
parents:
21441
diff
changeset
|
1532 #ifdef Py_USING_UNICODE |
|
21027
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1533 else if (PyUnicode_Check(v)) { |
|
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1534 Py_UNICODE *s = PyUnicode_AS_UNICODE(v); |
|
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1535 int len = PyUnicode_GET_SIZE(v); |
|
22499
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1536 if (len == 0 || |
|
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1537 !Py_UNICODE_ISSPACE(s[len-1]) || |
|
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1538 s[len-1] == ' ') |
|
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1539 PyFile_SoftSpace(w, 1); |
|
21027
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1540 } |
| 23479 | 1541 #endif |
|
22499
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1542 else |
|
3a3de6567f1a
SF bug 480215: softspace confused in nested print
Tim Peters <tim.peters@gmail.com>
parents:
22468
diff
changeset
|
1543 PyFile_SoftSpace(w, 1); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1544 } |
|
29669
96ecaab4cba6
Fix SF #762455, segfault when sys.stdout is changed in getattr
Neal Norwitz <nnorwitz@gmail.com>
parents:
29643
diff
changeset
|
1545 Py_XDECREF(w); |
| 5368 | 1546 Py_DECREF(v); |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1547 Py_XDECREF(stream); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1548 stream = NULL; |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1549 if (err == 0) |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1550 continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1551 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1552 |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1553 case PRINT_NEWLINE_TO: |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1554 w = stream = POP(); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1555 /* fall through to PRINT_NEWLINE */ |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1556 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1557 case PRINT_NEWLINE: |
|
14238
74f7f237f739
eval_code2(): Guido provides this patch for his suggested elaboration
Barry Warsaw <barry@python.org>
parents:
14232
diff
changeset
|
1558 if (stream == NULL || stream == Py_None) { |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1559 w = PySys_GetObject("stdout"); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1560 if (w == NULL) |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1561 PyErr_SetString(PyExc_RuntimeError, |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1562 "lost sys.stdout"); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1563 } |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1564 if (w != NULL) { |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1565 err = PyFile_WriteString("\n", w); |
|
5606
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
1566 if (err == 0) |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1567 PyFile_SoftSpace(w, 0); |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1016
diff
changeset
|
1568 } |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1569 Py_XDECREF(stream); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1570 stream = NULL; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1571 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1572 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1573 |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1574 #ifdef CASE_TOO_BIG |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1575 default: switch (opcode) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1576 #endif |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1577 case BREAK_LOOP: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1578 why = WHY_BREAK; |
|
31462
d5c047807c69
SF patch #864059: optimize eval_frame
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1579 goto fast_block_end; |
|
17114
6fe13d008e25
Use PyObject_IsInstance() to check whether the first argument to an
Guido van Rossum <guido@python.org>
parents:
17104
diff
changeset
|
1580 |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
1581 case CONTINUE_LOOP: |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
1582 retval = PyInt_FromLong(oparg); |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
1583 why = WHY_CONTINUE; |
|
31462
d5c047807c69
SF patch #864059: optimize eval_frame
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1584 goto fast_block_end; |
|
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
|
1585 |
|
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
|
1586 case RAISE_VARARGS: |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
1587 u = v = w = NULL; |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
1588 switch (oparg) { |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
1589 case 3: |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
1590 u = POP(); /* traceback */ |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
1591 /* Fallthrough */ |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
1592 case 2: |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
1593 v = POP(); /* value */ |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
1594 /* Fallthrough */ |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
1595 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
|
1596 w = POP(); /* exc */ |
|
7946
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
1597 case 0: /* Fallthrough */ |
|
4667
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
1598 why = do_raise(w, v, u); |
|
2813
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
1599 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
|
1600 default: |
| 5368 | 1601 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
|
1602 "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
|
1603 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
|
1604 break; |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1605 } |
|
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 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1608 case LOAD_LOCALS: |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1609 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
|
1610 PyErr_SetString(PyExc_SystemError, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1611 "no locals"); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1612 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1613 } |
| 5368 | 1614 Py_INCREF(x); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1615 PUSH(x); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1616 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1617 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1618 case RETURN_VALUE: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1619 retval = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1620 why = WHY_RETURN; |
|
31462
d5c047807c69
SF patch #864059: optimize eval_frame
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1621 goto fast_block_end; |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1622 |
|
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
|
1623 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
|
1624 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
|
1625 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
|
1626 why = WHY_YIELD; |
|
31462
d5c047807c69
SF patch #864059: optimize eval_frame
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1627 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
|
1628 |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1629 case EXEC_STMT: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1630 w = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1631 v = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1632 u = THIRD(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1633 STACKADJ(-3); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1634 err = exec_statement(f, u, v, w); |
| 5368 | 1635 Py_DECREF(u); |
| 1636 Py_DECREF(v); | |
| 1637 Py_DECREF(w); | |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1638 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1639 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1640 case POP_BLOCK: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1641 { |
| 5368 | 1642 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
|
1643 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
|
1644 v = POP(); |
| 5368 | 1645 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1646 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1647 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1648 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1649 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1650 case END_FINALLY: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1651 v = POP(); |
| 5368 | 1652 if (PyInt_Check(v)) { |
|
28296
7654c24decc4
SF patch #701907: More use of fast_next_opcode
Raymond Hettinger <python@rcn.com>
parents:
28121
diff
changeset
|
1653 why = (enum why_code) PyInt_AS_LONG(v); |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
1654 if (why == WHY_RETURN || |
|
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
|
1655 why == WHY_YIELD || |
|
23785
7a32c2356e56
SF bug 567538: Generator can crash the interpreter (Finn Bock).
Guido van Rossum <guido@python.org>
parents:
23479
diff
changeset
|
1656 why == WHY_CONTINUE) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1657 retval = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1658 } |
| 5368 | 1659 else if (PyString_Check(v) || PyClass_Check(v)) { |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1660 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
|
1661 u = POP(); |
| 5368 | 1662 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
|
1663 why = WHY_RERAISE; |
|
2872
d3b07ba3e12d
fix bogus DECREF in finally clause
Guido van Rossum <guido@python.org>
parents:
2866
diff
changeset
|
1664 break; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1665 } |
| 5368 | 1666 else if (v != Py_None) { |
| 1667 PyErr_SetString(PyExc_SystemError, | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1668 "'finally' pops bad exception"); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1669 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1670 } |
| 5368 | 1671 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1672 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1673 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1674 case BUILD_CLASS: |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1675 u = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1676 v = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1677 w = THIRD(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1678 STACKADJ(-2); |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
1679 x = build_class(u, v, w); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1680 SET_TOP(x); |
| 5368 | 1681 Py_DECREF(u); |
| 1682 Py_DECREF(v); | |
| 1683 Py_DECREF(w); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1684 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1685 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1686 case STORE_NAME: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1687 w = GETITEM(names, oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1688 v = POP(); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1689 if ((x = f->f_locals) == NULL) { |
|
16017
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15948
diff
changeset
|
1690 PyErr_Format(PyExc_SystemError, |
|
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15948
diff
changeset
|
1691 "no locals found when storing %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
|
1692 PyObject_REPR(w)); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1693 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1694 } |
| 5368 | 1695 err = PyDict_SetItem(x, w, v); |
| 1696 Py_DECREF(v); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1697 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1698 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1699 case DELETE_NAME: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1700 w = GETITEM(names, oparg); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1701 if ((x = f->f_locals) == NULL) { |
|
16017
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15948
diff
changeset
|
1702 PyErr_Format(PyExc_SystemError, |
|
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15948
diff
changeset
|
1703 "no locals when deleting %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
|
1704 PyObject_REPR(w)); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1705 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1706 } |
| 5368 | 1707 if ((err = PyDict_DelItem(x, w)) != 0) |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1708 format_exc_check_arg(PyExc_NameError, |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1709 NAME_ERROR_MSG ,w); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1710 break; |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
1711 |
|
28304
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
1712 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
|
1713 case UNPACK_SEQUENCE: |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1714 v = POP(); |
| 28077 | 1715 if (PyTuple_CheckExact(v)) { |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1716 if (PyTuple_Size(v) != oparg) { |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1717 PyErr_SetString(PyExc_ValueError, |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1718 "unpack tuple of wrong size"); |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1719 why = WHY_EXCEPTION; |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1720 } |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1721 else { |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1722 for (; --oparg >= 0; ) { |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1723 w = PyTuple_GET_ITEM(v, oparg); |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1724 Py_INCREF(w); |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1725 PUSH(w); |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1726 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1727 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1728 } |
| 28077 | 1729 else if (PyList_CheckExact(v)) { |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1730 if (PyList_Size(v) != oparg) { |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1731 PyErr_SetString(PyExc_ValueError, |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1732 "unpack list of wrong size"); |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1733 why = WHY_EXCEPTION; |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1734 } |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1735 else { |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1736 for (; --oparg >= 0; ) { |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1737 w = PyList_GET_ITEM(v, oparg); |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1738 Py_INCREF(w); |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1739 PUSH(w); |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1740 } |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1741 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1742 } |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
1743 else if (unpack_iterable(v, oparg, |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
1744 stack_pointer + oparg)) |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
1745 stack_pointer += oparg; |
|
20183
c6b6189a8397
SF bug [#466173] unpack TypeError unclear
Tim Peters <tim.peters@gmail.com>
parents:
20114
diff
changeset
|
1746 else { |
|
c6b6189a8397
SF bug [#466173] unpack TypeError unclear
Tim Peters <tim.peters@gmail.com>
parents:
20114
diff
changeset
|
1747 if (PyErr_ExceptionMatches(PyExc_TypeError)) |
|
c6b6189a8397
SF bug [#466173] unpack TypeError unclear
Tim Peters <tim.peters@gmail.com>
parents:
20114
diff
changeset
|
1748 PyErr_SetString(PyExc_TypeError, |
|
c6b6189a8397
SF bug [#466173] unpack TypeError unclear
Tim Peters <tim.peters@gmail.com>
parents:
20114
diff
changeset
|
1749 "unpack non-sequence"); |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1750 why = WHY_EXCEPTION; |
|
20183
c6b6189a8397
SF bug [#466173] unpack TypeError unclear
Tim Peters <tim.peters@gmail.com>
parents:
20114
diff
changeset
|
1751 } |
| 5368 | 1752 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1753 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1754 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1755 case STORE_ATTR: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1756 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
|
1757 v = TOP(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1758 u = SECOND(); |
|
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1759 STACKADJ(-2); |
| 5368 | 1760 err = PyObject_SetAttr(v, w, u); /* v.w = u */ |
| 1761 Py_DECREF(v); | |
| 1762 Py_DECREF(u); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1763 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1764 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1765 case DELETE_ATTR: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1766 w = GETITEM(names, oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1767 v = POP(); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1768 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
|
1769 /* del v.w */ |
| 5368 | 1770 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1771 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1772 |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1773 case STORE_GLOBAL: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1774 w = GETITEM(names, oparg); |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1775 v = POP(); |
| 5368 | 1776 err = PyDict_SetItem(f->f_globals, w, v); |
| 1777 Py_DECREF(v); | |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1778 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1779 |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1780 case DELETE_GLOBAL: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1781 w = GETITEM(names, oparg); |
| 5368 | 1782 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
|
1783 format_exc_check_arg( |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1784 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
|
1785 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1786 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1787 case LOAD_NAME: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1788 w = GETITEM(names, oparg); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1789 if ((x = f->f_locals) == NULL) { |
|
16017
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15948
diff
changeset
|
1790 PyErr_Format(PyExc_SystemError, |
|
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15948
diff
changeset
|
1791 "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
|
1792 PyObject_REPR(w)); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1793 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1794 } |
| 5368 | 1795 x = PyDict_GetItem(x, w); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1796 if (x == NULL) { |
| 5368 | 1797 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
|
1798 if (x == NULL) { |
| 5368 | 1799 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
|
1800 if (x == NULL) { |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1801 format_exc_check_arg( |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1802 PyExc_NameError, |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1803 NAME_ERROR_MSG ,w); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1804 break; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1805 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1806 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1807 } |
| 5368 | 1808 Py_INCREF(x); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1809 PUSH(x); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1810 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1811 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1812 case LOAD_GLOBAL: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1813 w = GETITEM(names, oparg); |
|
24899
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1814 if (PyString_CheckExact(w)) { |
|
24900
2cdf3d0dfabd
Add a warning comment to the LOAD_GLOBAL inline code.
Guido van Rossum <guido@python.org>
parents:
24899
diff
changeset
|
1815 /* 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
|
1816 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
|
1817 Do not try this at home. */ |
|
24899
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1818 long hash = ((PyStringObject *)w)->ob_shash; |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1819 if (hash != -1) { |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1820 PyDictObject *d; |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1821 d = (PyDictObject *)(f->f_globals); |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1822 x = d->ma_lookup(d, w, hash)->me_value; |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1823 if (x != NULL) { |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1824 Py_INCREF(x); |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1825 PUSH(x); |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1826 continue; |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1827 } |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1828 d = (PyDictObject *)(f->f_builtins); |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1829 x = d->ma_lookup(d, w, hash)->me_value; |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1830 if (x != NULL) { |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1831 Py_INCREF(x); |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1832 PUSH(x); |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1833 continue; |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1834 } |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1835 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
|
1836 } |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1837 } |
|
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1838 /* This is the un-inlined version of the code above */ |
| 5368 | 1839 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
|
1840 if (x == NULL) { |
| 5368 | 1841 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
|
1842 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
|
1843 load_global_error: |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1844 format_exc_check_arg( |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1845 PyExc_NameError, |
|
24899
8f8fe990e82c
Another ugly inlining hack, expanding the two PyDict_GetItem() calls
Guido van Rossum <guido@python.org>
parents:
24870
diff
changeset
|
1846 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
|
1847 break; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1848 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1849 } |
| 5368 | 1850 Py_INCREF(x); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1851 PUSH(x); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1852 break; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1853 |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1854 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
|
1855 x = GETLOCAL(oparg); |
|
ec87b62466d3
DELETE_FAST should issue an exception when the local variable is undefined.
Guido van Rossum <guido@python.org>
parents:
7982
diff
changeset
|
1856 if (x == NULL) { |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1857 format_exc_check_arg( |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1858 PyExc_UnboundLocalError, |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1859 UNBOUNDLOCAL_ERROR_MSG, |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1860 PyTuple_GetItem(co->co_varnames, oparg) |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1861 ); |
|
8318
ec87b62466d3
DELETE_FAST should issue an exception when the local variable is undefined.
Guido van Rossum <guido@python.org>
parents:
7982
diff
changeset
|
1862 break; |
|
ec87b62466d3
DELETE_FAST should issue an exception when the local variable is undefined.
Guido van Rossum <guido@python.org>
parents:
7982
diff
changeset
|
1863 } |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1864 SETLOCAL(oparg, NULL); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1865 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1866 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1867 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
|
1868 x = freevars[oparg]; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1869 Py_INCREF(x); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1870 PUSH(x); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1871 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1872 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1873 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
|
1874 x = freevars[oparg]; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1875 w = PyCell_Get(x); |
|
16453
2e3dd62ceac5
SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16398
diff
changeset
|
1876 if (w == NULL) { |
|
24190
a2bcb00dcbd5
Don't stomp on an exception set by PyCell_Get()
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23863
diff
changeset
|
1877 err = -1; |
|
a2bcb00dcbd5
Don't stomp on an exception set by PyCell_Get()
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23863
diff
changeset
|
1878 /* Don't stomp existing exception */ |
|
a2bcb00dcbd5
Don't stomp on an exception set by PyCell_Get()
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23863
diff
changeset
|
1879 if (PyErr_Occurred()) |
|
a2bcb00dcbd5
Don't stomp on an exception set by PyCell_Get()
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23863
diff
changeset
|
1880 break; |
|
17494
a34293ced63b
Change error message raised when free variable is not yet bound. It
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17490
diff
changeset
|
1881 if (oparg < f->f_ncells) { |
|
16453
2e3dd62ceac5
SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16398
diff
changeset
|
1882 v = PyTuple_GetItem(co->co_cellvars, |
|
2e3dd62ceac5
SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16398
diff
changeset
|
1883 oparg); |
|
17494
a34293ced63b
Change error message raised when free variable is not yet bound. It
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17490
diff
changeset
|
1884 format_exc_check_arg( |
|
a34293ced63b
Change error message raised when free variable is not yet bound. It
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17490
diff
changeset
|
1885 PyExc_UnboundLocalError, |
|
a34293ced63b
Change error message raised when free variable is not yet bound. It
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17490
diff
changeset
|
1886 UNBOUNDLOCAL_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
|
1887 v); |
|
a34293ced63b
Change error message raised when free variable is not yet bound. It
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17490
diff
changeset
|
1888 } else { |
|
16453
2e3dd62ceac5
SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16398
diff
changeset
|
1889 v = PyTuple_GetItem( |
|
2e3dd62ceac5
SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16398
diff
changeset
|
1890 co->co_freevars, |
|
2e3dd62ceac5
SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16398
diff
changeset
|
1891 oparg - f->f_ncells); |
|
17494
a34293ced63b
Change error message raised when free variable is not yet bound. It
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17490
diff
changeset
|
1892 format_exc_check_arg( |
|
a34293ced63b
Change error message raised when free variable is not yet bound. It
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17490
diff
changeset
|
1893 PyExc_NameError, |
|
a34293ced63b
Change error message raised when free variable is not yet bound. It
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17490
diff
changeset
|
1894 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
|
1895 v); |
|
a34293ced63b
Change error message raised when free variable is not yet bound. It
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17490
diff
changeset
|
1896 } |
|
16453
2e3dd62ceac5
SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16398
diff
changeset
|
1897 break; |
|
2e3dd62ceac5
SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16398
diff
changeset
|
1898 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1899 PUSH(w); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1900 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1901 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1902 case STORE_DEREF: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1903 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
|
1904 x = freevars[oparg]; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1905 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
|
1906 Py_DECREF(w); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1907 continue; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1908 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1909 case BUILD_TUPLE: |
| 5368 | 1910 x = PyTuple_New(oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1911 if (x != NULL) { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1912 for (; --oparg >= 0;) { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1913 w = POP(); |
| 5368 | 1914 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
|
1915 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1916 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
|
1917 continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1918 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1919 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1920 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1921 case BUILD_LIST: |
| 5368 | 1922 x = PyList_New(oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1923 if (x != NULL) { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1924 for (; --oparg >= 0;) { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1925 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
|
1926 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
|
1927 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1928 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
|
1929 continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1930 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1931 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1932 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1933 case BUILD_MAP: |
| 5368 | 1934 x = PyDict_New(); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1935 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
|
1936 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1937 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1938 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1939 case LOAD_ATTR: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1940 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
|
1941 v = TOP(); |
| 5368 | 1942 x = PyObject_GetAttr(v, w); |
| 1943 Py_DECREF(v); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1944 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
|
1945 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1946 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1947 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1948 case COMPARE_OP: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1949 w = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1950 v = TOP(); |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
1951 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
|
1952 /* INLINE: cmp(int, int) */ |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1953 register long a, b; |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1954 register int res; |
|
9591
7f90736701a3
Use PyInt_AS_LONG macro instead of explicit inlining.
Guido van Rossum <guido@python.org>
parents:
9513
diff
changeset
|
1955 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
|
1956 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
|
1957 switch (oparg) { |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
1958 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
|
1959 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
|
1960 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
|
1961 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
|
1962 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
|
1963 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
|
1964 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
|
1965 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
|
1966 default: goto slow_compare; |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1967 } |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1968 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
|
1969 Py_INCREF(x); |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1970 } |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1971 else { |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1972 slow_compare: |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1973 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
|
1974 } |
| 5368 | 1975 Py_DECREF(v); |
| 1976 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1977 SET_TOP(x); |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
1978 if (x == NULL) break; |
|
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
1979 PREDICT(JUMP_IF_FALSE); |
|
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
1980 PREDICT(JUMP_IF_TRUE); |
|
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
1981 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1982 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1983 case IMPORT_NAME: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
1984 w = GETITEM(names, oparg); |
| 5368 | 1985 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
|
1986 if (x == NULL) { |
| 5368 | 1987 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
|
1988 "__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
|
1989 break; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
1990 } |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
1991 u = TOP(); |
|
30683
3b59fa5d25b1
Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents:
29669
diff
changeset
|
1992 w = PyTuple_Pack(4, |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1993 w, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1994 f->f_globals, |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1995 f->f_locals == NULL ? |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1996 Py_None : f->f_locals, |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1997 u); |
| 5368 | 1998 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
|
1999 if (w == NULL) { |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2000 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
|
2001 x = NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
2002 break; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
2003 } |
| 5368 | 2004 x = PyEval_CallObject(x, w); |
| 2005 Py_DECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2006 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
|
2007 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2008 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2009 |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
2010 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
|
2011 v = POP(); |
| 5368 | 2012 PyFrame_FastToLocals(f); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2013 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
|
2014 PyErr_SetString(PyExc_SystemError, |
|
16017
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15948
diff
changeset
|
2015 "no locals found during 'import *'"); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2016 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2017 } |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
2018 err = import_all_from(x, v); |
| 5368 | 2019 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
|
2020 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
|
2021 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2022 break; |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
2023 |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
2024 case IMPORT_FROM: |
|
24607
3e4d432872ea
get rid of GETNAMEV macro - use GETITEM directly
Skip Montanaro <skip@pobox.com>
parents:
24545
diff
changeset
|
2025 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
|
2026 v = TOP(); |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
2027 x = import_from(v, w); |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
2028 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
|
2029 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
|
2030 break; |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
2031 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2032 case JUMP_FORWARD: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2033 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
|
2034 goto fast_next_opcode; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2035 |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2036 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
|
2037 case JUMP_IF_FALSE: |
| 28077 | 2038 w = TOP(); |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2039 if (w == Py_True) { |
|
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2040 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
|
2041 goto fast_next_opcode; |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2042 } |
| 28077 | 2043 if (w == Py_False) { |
| 2044 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
|
2045 goto fast_next_opcode; |
| 28077 | 2046 } |
| 2047 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
|
2048 if (err > 0) |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2049 err = 0; |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2050 else if (err == 0) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2051 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
|
2052 else |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2053 break; |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2054 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2055 |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2056 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
|
2057 case JUMP_IF_TRUE: |
| 28077 | 2058 w = TOP(); |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2059 if (w == Py_False) { |
|
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2060 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
|
2061 goto fast_next_opcode; |
|
28302
8c082936daaf
Introduced macros for a simple opcode prediction protocol.
Raymond Hettinger <python@rcn.com>
parents:
28296
diff
changeset
|
2062 } |
| 28077 | 2063 if (w == Py_True) { |
| 2064 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
|
2065 goto fast_next_opcode; |
| 28077 | 2066 } |
| 2067 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
|
2068 if (err > 0) { |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2069 err = 0; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2070 JUMPBY(oparg); |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2071 } |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2072 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
|
2073 ; |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2074 else |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2075 break; |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
2076 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2077 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2078 case JUMP_ABSOLUTE: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2079 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
|
2080 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2081 |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2082 case GET_ITER: |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2083 /* 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
|
2084 v = TOP(); |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2085 x = PyObject_GetIter(v); |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2086 Py_DECREF(v); |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2087 if (x != NULL) { |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2088 SET_TOP(x); |
|
28304
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
2089 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
|
2090 continue; |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2091 } |
|
27243
3afbd55fb18f
Replaced POP() with STACKADJ(-1) on lines where the result wasn't used.
Raymond Hettinger <python@rcn.com>
parents:
27201
diff
changeset
|
2092 STACKADJ(-1); |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2093 break; |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2094 |
|
28304
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
2095 PREDICTED_WITH_ARG(FOR_ITER); |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2096 case FOR_ITER: |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2097 /* before: [iter]; after: [iter, iter()] *or* [] */ |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2098 v = TOP(); |
|
17617
aac65f50df6f
Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents:
17600
diff
changeset
|
2099 x = PyIter_Next(v); |
|
aac65f50df6f
Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents:
17600
diff
changeset
|
2100 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
|
2101 PUSH(x); |
|
28304
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
2102 PREDICT(STORE_FAST); |
|
b14d6741f496
Eliminate data dependency in predict macro.
Raymond Hettinger <python@rcn.com>
parents:
28303
diff
changeset
|
2103 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
|
2104 continue; |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2105 } |
|
17683
e9a4e27e8d4e
Make PyIter_Next() a little smarter (wrt its knowledge of iterator
Tim Peters <tim.peters@gmail.com>
parents:
17636
diff
changeset
|
2106 if (!PyErr_Occurred()) { |
|
e9a4e27e8d4e
Make PyIter_Next() a little smarter (wrt its knowledge of iterator
Tim Peters <tim.peters@gmail.com>
parents:
17636
diff
changeset
|
2107 /* iterator ended normally */ |
|
e9a4e27e8d4e
Make PyIter_Next() a little smarter (wrt its knowledge of iterator
Tim Peters <tim.peters@gmail.com>
parents:
17636
diff
changeset
|
2108 x = v = POP(); |
|
17617
aac65f50df6f
Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents:
17600
diff
changeset
|
2109 Py_DECREF(v); |
|
aac65f50df6f
Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents:
17600
diff
changeset
|
2110 JUMPBY(oparg); |
|
aac65f50df6f
Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents:
17600
diff
changeset
|
2111 continue; |
|
aac65f50df6f
Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents:
17600
diff
changeset
|
2112 } |
|
aac65f50df6f
Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents:
17600
diff
changeset
|
2113 break; |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
2114 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2115 case SETUP_LOOP: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2116 case SETUP_EXCEPT: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2117 case SETUP_FINALLY: |
| 5368 | 2118 PyFrame_BlockSetup(f, opcode, INSTR_OFFSET() + oparg, |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2119 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
|
2120 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2121 |
|
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
|
2122 case CALL_FUNCTION: |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
2123 PCALL(PCALL_ALL); |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
2124 x = call_function(&stack_pointer, oparg); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
2125 PUSH(x); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
2126 if (x != NULL) |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
2127 continue; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
2128 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2129 |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2130 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
|
2131 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
|
2132 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
|
2133 { |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2134 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
|
2135 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
|
2136 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
|
2137 int n = na + 2 * nk; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2138 PyObject **pfunc, *func; |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
2139 PCALL(PCALL_ALL); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2140 if (flags & CALL_FLAG_VAR) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2141 n++; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2142 if (flags & CALL_FLAG_KW) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2143 n++; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2144 pfunc = stack_pointer - n - 1; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2145 func = *pfunc; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2146 |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2147 if (PyMethod_Check(func) |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2148 && PyMethod_GET_SELF(func) != NULL) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2149 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
|
2150 Py_INCREF(self); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2151 func = PyMethod_GET_FUNCTION(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2152 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
|
2153 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
|
2154 *pfunc = self; |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2155 na++; |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2156 n++; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2157 } else |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2158 Py_INCREF(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2159 x = ext_do_call(func, &stack_pointer, flags, na, nk); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2160 Py_DECREF(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2161 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2162 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
|
2163 w = POP(); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2164 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
|
2165 } |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2166 PUSH(x); |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2167 if (x != NULL) |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2168 continue; |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2169 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
|
2170 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2171 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2172 case MAKE_FUNCTION: |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2173 v = POP(); /* code object */ |
| 5368 | 2174 x = PyFunction_New(v, f->f_globals); |
| 2175 Py_DECREF(v); | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2176 /* XXX Maybe this should be a separate opcode? */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2177 if (x != NULL && oparg > 0) { |
| 5368 | 2178 v = PyTuple_New(oparg); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2179 if (v == NULL) { |
| 5368 | 2180 Py_DECREF(x); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2181 x = NULL; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2182 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2183 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2184 while (--oparg >= 0) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2185 w = POP(); |
| 5368 | 2186 PyTuple_SET_ITEM(v, oparg, w); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2187 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2188 err = PyFunction_SetDefaults(x, v); |
| 5368 | 2189 Py_DECREF(v); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2190 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2191 PUSH(x); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2192 break; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2193 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2194 case MAKE_CLOSURE: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2195 { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2196 int nfree; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2197 v = POP(); /* code object */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2198 x = PyFunction_New(v, f->f_globals); |
|
21398
de125792bfaa
Fix for SF bug [ #492403 ] exec() segfaults on closure's func_code
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21270
diff
changeset
|
2199 nfree = PyCode_GetNumFree((PyCodeObject *)v); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2200 Py_DECREF(v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2201 /* XXX Maybe this should be a separate opcode? */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2202 if (x != NULL && nfree > 0) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2203 v = PyTuple_New(nfree); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2204 if (v == NULL) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2205 Py_DECREF(x); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2206 x = NULL; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2207 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2208 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2209 while (--nfree >= 0) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2210 w = POP(); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2211 PyTuple_SET_ITEM(v, nfree, w); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2212 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2213 err = PyFunction_SetClosure(x, v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2214 Py_DECREF(v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2215 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2216 if (x != NULL && oparg > 0) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2217 v = PyTuple_New(oparg); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2218 if (v == NULL) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2219 Py_DECREF(x); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2220 x = NULL; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2221 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2222 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2223 while (--oparg >= 0) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2224 w = POP(); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2225 PyTuple_SET_ITEM(v, oparg, w); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2226 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2227 err = PyFunction_SetDefaults(x, v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2228 Py_DECREF(v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2229 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2230 PUSH(x); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2231 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2232 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2233 |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2234 case BUILD_SLICE: |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2235 if (oparg == 3) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2236 w = POP(); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2237 else |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2238 w = NULL; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2239 v = POP(); |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2240 u = TOP(); |
| 5018 | 2241 x = PySlice_New(u, v, w); |
| 5368 | 2242 Py_DECREF(u); |
| 2243 Py_DECREF(v); | |
| 2244 Py_XDECREF(w); | |
|
27186
04aa86d49d93
SF patch #664320: Replace push/pop clusters in ceval.c
Raymond Hettinger <python@rcn.com>
parents:
26141
diff
changeset
|
2245 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
|
2246 if (x != NULL) continue; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2247 break; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2248 |
|
14147
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
2249 case EXTENDED_ARG: |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
2250 opcode = NEXTOP(); |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
2251 oparg = oparg<<16 | NEXTARG(); |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
2252 goto dispatch_opcode; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2253 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2254 default: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2255 fprintf(stderr, |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2256 "XXX lineno: %d, opcode: %d\n", |
| 24844 | 2257 PyCode_Addr2Line(f->f_code, f->f_lasti), |
| 2258 opcode); | |
| 5368 | 2259 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
|
2260 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2261 break; |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2262 |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2263 #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
|
2264 } |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2265 #endif |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2266 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2267 } /* switch */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2268 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2269 on_error: |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2270 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2271 /* Quickly continue if no error occurred */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2272 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2273 if (why == WHY_NOT) { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2274 if (err == 0 && x != NULL) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2275 #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
|
2276 /* This check is expensive! */ |
| 5368 | 2277 if (PyErr_Occurred()) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2278 fprintf(stderr, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2279 "XXX undetected error\n"); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2280 else |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2281 #endif |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2282 continue; /* Normal, fast path */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2283 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2284 why = WHY_EXCEPTION; |
| 5368 | 2285 x = Py_None; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2286 err = 0; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2287 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2288 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2289 /* Double-check exception status */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2290 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2291 if (why == WHY_EXCEPTION || why == WHY_RERAISE) { |
| 5368 | 2292 if (!PyErr_Occurred()) { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2293 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
|
2294 "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
|
2295 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2296 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2297 } |
|
10363
4daab7a9f566
Always test for an error return (usually NULL or -1) without setting
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
2298 #ifdef CHECKEXC |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2299 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
|
2300 /* This check is expensive! */ |
| 5368 | 2301 if (PyErr_Occurred()) { |
|
30861
c89fd7eaf875
Make undetected error on stack unwind a fatal error.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
30801
diff
changeset
|
2302 char buf[1024]; |
|
c89fd7eaf875
Make undetected error on stack unwind a fatal error.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
30801
diff
changeset
|
2303 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
|
2304 "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
|
2305 Py_FatalError(buf); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2306 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2307 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2308 #endif |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2309 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2310 /* 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
|
2311 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2312 if (why == WHY_EXCEPTION) { |
| 5368 | 2313 PyTraceBack_Here(f); |
| 567 | 2314 |
|
20247
a4d328d50897
Rationalize the events passed to the profiler (no changes for the tracer).
Fred Drake <fdrake@acm.org>
parents:
20183
diff
changeset
|
2315 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
|
2316 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
|
2317 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
|
2318 } |
|
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 /* 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
|
2321 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2322 if (why == WHY_RERAISE) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2323 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2324 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2325 /* Unwind stacks if a (pseudo) exception occurred */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2326 |
|
31462
d5c047807c69
SF patch #864059: optimize eval_frame
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2327 fast_block_end: |
|
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
|
2328 while (why != WHY_NOT && why != WHY_YIELD && f->f_iblock > 0) { |
| 5368 | 2329 PyTryBlock *b = PyFrame_BlockPop(f); |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2330 |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2331 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
|
2332 /* For a continue inside a try block, |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2333 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
|
2334 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
|
2335 b->b_level); |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2336 why = WHY_NOT; |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2337 JUMPTO(PyInt_AS_LONG(retval)); |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2338 Py_DECREF(retval); |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2339 break; |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2340 } |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2341 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2342 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
|
2343 v = POP(); |
| 5368 | 2344 Py_XDECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2345 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2346 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
|
2347 why = WHY_NOT; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2348 JUMPTO(b->b_handler); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2349 break; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2350 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2351 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
|
2352 (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
|
2353 why == WHY_EXCEPTION)) { |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2354 if (why == WHY_EXCEPTION) { |
| 5368 | 2355 PyObject *exc, *val, *tb; |
| 2356 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
|
2357 if (val == NULL) { |
| 5368 | 2358 val = Py_None; |
| 2359 Py_INCREF(val); | |
|
173
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 /* Make the raw exception data |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2362 available to the handler, |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2363 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
|
2364 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
|
2365 this for 'finally'. */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2366 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
|
2367 PyErr_NormalizeException( |
|
32aacd753f34
eval_code2(), set_exc_info(): Call PyErr_NormalizeException() the
Barry Warsaw <barry@python.org>
parents:
6160
diff
changeset
|
2368 &exc, &val, &tb); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2369 set_exc_info(tstate, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2370 exc, val, tb); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2371 } |
|
20114
233f9606ba8e
Prevent a NULL pointer from being pushed onto the stack.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20064
diff
changeset
|
2372 if (tb == NULL) { |
|
233f9606ba8e
Prevent a NULL pointer from being pushed onto the stack.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20064
diff
changeset
|
2373 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
|
2374 PUSH(Py_None); |
|
233f9606ba8e
Prevent a NULL pointer from being pushed onto the stack.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20064
diff
changeset
|
2375 } else |
|
233f9606ba8e
Prevent a NULL pointer from being pushed onto the stack.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20064
diff
changeset
|
2376 PUSH(tb); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2377 PUSH(val); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2378 PUSH(exc); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2379 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2380 else { |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2381 if (why == WHY_RETURN || |
|
23785
7a32c2356e56
SF bug 567538: Generator can crash the interpreter (Finn Bock).
Guido van Rossum <guido@python.org>
parents:
23479
diff
changeset
|
2382 why == WHY_CONTINUE) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2383 PUSH(retval); |
| 5368 | 2384 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
|
2385 PUSH(v); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2386 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2387 why = WHY_NOT; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2388 JUMPTO(b->b_handler); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2389 break; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2390 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2391 } /* unwind stack */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2392 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2393 /* 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
|
2394 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2395 if (why != WHY_NOT) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2396 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2397 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2398 } /* main loop */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2399 |
|
21270
97709fd8fda0
Fix for SF bug #489671 (Neil Norwitz): memory leak in test_richcmp.
Guido van Rossum <guido@python.org>
parents:
21252
diff
changeset
|
2400 if (why != WHY_YIELD) { |
|
97709fd8fda0
Fix for SF bug #489671 (Neil Norwitz): memory leak in test_richcmp.
Guido van Rossum <guido@python.org>
parents:
21252
diff
changeset
|
2401 /* Pop remaining stack entries -- but when yielding */ |
|
97709fd8fda0
Fix for SF bug #489671 (Neil Norwitz): memory leak in test_richcmp.
Guido van Rossum <guido@python.org>
parents:
21252
diff
changeset
|
2402 while (!EMPTY()) { |
|
97709fd8fda0
Fix for SF bug #489671 (Neil Norwitz): memory leak in test_richcmp.
Guido van Rossum <guido@python.org>
parents:
21252
diff
changeset
|
2403 v = POP(); |
|
97709fd8fda0
Fix for SF bug #489671 (Neil Norwitz): memory leak in test_richcmp.
Guido van Rossum <guido@python.org>
parents:
21252
diff
changeset
|
2404 Py_XDECREF(v); |
|
97709fd8fda0
Fix for SF bug #489671 (Neil Norwitz): memory leak in test_richcmp.
Guido van Rossum <guido@python.org>
parents:
21252
diff
changeset
|
2405 } |
|
97709fd8fda0
Fix for SF bug #489671 (Neil Norwitz): memory leak in test_richcmp.
Guido van Rossum <guido@python.org>
parents:
21252
diff
changeset
|
2406 } |
|
97709fd8fda0
Fix for SF bug #489671 (Neil Norwitz): memory leak in test_richcmp.
Guido van Rossum <guido@python.org>
parents:
21252
diff
changeset
|
2407 |
|
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
|
2408 if (why != WHY_RETURN && why != WHY_YIELD) |
| 567 | 2409 retval = NULL; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2410 |
|
31462
d5c047807c69
SF patch #864059: optimize eval_frame
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2411 fast_yield: |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2412 if (tstate->use_tracing) { |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2413 if (tstate->c_tracefunc |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2414 && (why == WHY_RETURN || why == WHY_YIELD)) { |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2415 if (call_trace(tstate->c_tracefunc, |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2416 tstate->c_traceobj, f, |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2417 PyTrace_RETURN, retval)) { |
| 5368 | 2418 Py_XDECREF(retval); |
| 567 | 2419 retval = NULL; |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
2420 why = WHY_EXCEPTION; |
| 567 | 2421 } |
| 2422 } | |
|
20247
a4d328d50897
Rationalize the events passed to the profiler (no changes for the tracer).
Fred Drake <fdrake@acm.org>
parents:
20183
diff
changeset
|
2423 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
|
2424 if (why == WHY_EXCEPTION) |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2425 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
|
2426 tstate->c_profileobj, f, |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2427 PyTrace_RETURN); |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2428 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
|
2429 tstate->c_profileobj, f, |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2430 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
|
2431 Py_XDECREF(retval); |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2432 retval = NULL; |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2433 why = WHY_EXCEPTION; |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2434 } |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
2435 } |
| 567 | 2436 } |
|
5023
75c1ee882a4a
Kill all local variables on function return. This closes a gigantic
Guido van Rossum <guido@python.org>
parents:
5021
diff
changeset
|
2437 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2438 reset_exc_info(tstate); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2439 |
|
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
|
2440 /* pop frame */ |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
2441 exit_eval_frame: |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
30782
diff
changeset
|
2442 Py_LeaveRecursiveCall(); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2443 tstate->frame = f->f_back; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2444 |
| 567 | 2445 return retval; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2446 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2447 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
2448 PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
2449 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
|
2450 PyObject **args, int argcount, PyObject **kws, int kwcount, |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2451 PyObject **defs, int defcount, PyObject *closure) |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2452 { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2453 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
|
2454 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
|
2455 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
|
2456 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
|
2457 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
|
2458 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2459 if (globals == NULL) { |
|
19198
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19158
diff
changeset
|
2460 PyErr_SetString(PyExc_SystemError, |
|
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19158
diff
changeset
|
2461 "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
|
2462 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
|
2463 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2464 |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
2465 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
|
2466 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
|
2467 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
|
2468 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
|
2469 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2470 fastlocals = f->f_localsplus; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2471 freevars = f->f_localsplus + f->f_nlocals; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2472 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2473 if (co->co_argcount > 0 || |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2474 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
|
2475 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
|
2476 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
|
2477 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
|
2478 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
|
2479 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
|
2480 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
|
2481 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
|
2482 i = co->co_argcount; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2483 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
|
2484 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
|
2485 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
|
2486 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2487 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
|
2488 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
|
2489 PyErr_Format(PyExc_TypeError, |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2490 "%.200s() takes %s %d " |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2491 "%sargument%s (%d given)", |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2492 PyString_AsString(co->co_name), |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2493 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
|
2494 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
|
2495 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
|
2496 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
|
2497 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
|
2498 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
|
2499 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2500 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
|
2501 } |
|
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 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
|
2503 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
|
2504 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
|
2505 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
|
2506 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2507 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
|
2508 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
|
2509 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
|
2510 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
|
2511 SETLOCAL(co->co_argcount, u); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2512 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
|
2513 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
|
2514 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
|
2515 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
|
2516 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2517 } |
|
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 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
|
2519 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
|
2520 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
|
2521 int 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
|
2522 if (keyword == NULL || !PyString_Check(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
|
2523 PyErr_Format(PyExc_TypeError, |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2524 "%.200s() keywords must be strings", |
|
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 PyString_AsString(co->co_name)); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2526 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
|
2527 } |
|
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 /* XXX slow -- speed up using dictionary? */ |
|
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 for (j = 0; j < co->co_argcount; 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
|
2530 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
|
2531 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
|
2532 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
|
2533 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
|
2534 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
|
2535 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
|
2536 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
|
2537 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
|
2538 } |
|
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 /* 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
|
2540 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
|
2541 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
|
2542 if (j >= co->co_argcount) { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2543 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
|
2544 PyErr_Format(PyExc_TypeError, |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2545 "%.200s() got an unexpected " |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2546 "keyword argument '%.400s'", |
|
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 PyString_AsString(co->co_name), |
|
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 PyString_AsString(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
|
2549 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
|
2550 } |
|
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 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
|
2552 } |
|
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 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
|
2554 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
|
2555 PyErr_Format(PyExc_TypeError, |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2556 "%.200s() got multiple " |
|
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 "values for 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
|
2558 "argument '%.400s'", |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2559 PyString_AsString(co->co_name), |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2560 PyString_AsString(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
|
2561 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
|
2562 } |
|
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 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
|
2564 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
|
2565 } |
|
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 } |
|
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 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
|
2568 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
|
2569 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
|
2570 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
|
2571 PyErr_Format(PyExc_TypeError, |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2572 "%.200s() takes %s %d " |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2573 "%sargument%s (%d given)", |
|
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 PyString_AsString(co->co_name), |
|
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 ((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 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
|
2577 : "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
|
2578 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
|
2579 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
|
2580 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
|
2581 } |
|
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 } |
|
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 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
|
2584 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
|
2585 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
|
2586 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
|
2587 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
|
2588 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
|
2589 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
|
2590 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
|
2591 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
|
2592 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2593 } |
|
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 } |
|
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 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
|
2597 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
|
2598 PyErr_Format(PyExc_TypeError, |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2599 "%.200s() takes no arguments (%d given)", |
|
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 PyString_AsString(co->co_name), |
|
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 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
|
2602 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
|
2603 } |
|
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 } |
|
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 /* 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
|
2606 vars into frame. This isn't too efficient right now. */ |
|
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 if (f->f_ncells) { |
|
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 int i = 0, j = 0, nargs, found; |
|
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 char *cellname, *argname; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2610 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
|
2611 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2612 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
|
2613 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
|
2614 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
|
2615 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
|
2616 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
|
2617 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2618 /* Check for cells that shadow args */ |
|
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 for (i = 0; i < f->f_ncells && j < nargs; ++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
|
2620 cellname = PyString_AS_STRING( |
|
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 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
|
2622 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
|
2623 while (j < 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
|
2624 argname = PyString_AS_STRING( |
|
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 PyTuple_GET_ITEM(co->co_varnames, j)); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2626 if (strcmp(cellname, argname) == 0) { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2627 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
|
2628 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
|
2629 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
|
2630 GETLOCAL(f->f_nlocals + i) = 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
|
2631 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
|
2632 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
|
2633 } |
|
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 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
|
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 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
|
2637 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
|
2638 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
|
2639 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
|
2640 SETLOCAL(f->f_nlocals + i, 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
|
2641 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2642 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2643 /* Initialize any that are left */ |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2644 while (i < f->f_ncells) { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2645 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
|
2646 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
|
2647 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
|
2648 SETLOCAL(f->f_nlocals + i, 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
|
2649 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
|
2650 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2651 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2652 if (f->f_nfreevars) { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2653 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
|
2654 for (i = 0; i < f->f_nfreevars; ++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
|
2655 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
|
2656 Py_INCREF(o); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2657 freevars[f->f_ncells + i] = o; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2658 } |
|
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 } |
|
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 |
|
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 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
|
2662 /* 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
|
2663 * 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
|
2664 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
|
2665 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
|
2666 |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
2667 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
|
2668 |
|
18194
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
2669 /* 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
|
2670 * and return that as the value. */ |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2671 return gen_new(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
|
2672 } |
|
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 |
|
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 retval = eval_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
|
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 fail: /* Jump here from prelude on failure */ |
|
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 |
|
21058
9df82c13c675
SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents:
21027
diff
changeset
|
2678 /* 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
|
2679 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
|
2680 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
|
2681 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
|
2682 */ |
|
9df82c13c675
SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents:
21027
diff
changeset
|
2683 assert(tstate != NULL); |
|
9df82c13c675
SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents:
21027
diff
changeset
|
2684 ++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
|
2685 Py_DECREF(f); |
|
21058
9df82c13c675
SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents:
21027
diff
changeset
|
2686 --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
|
2687 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
|
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 |
|
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 |
|
28121
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2691 /* 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
|
2692 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2693 - 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
|
2694 '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
|
2695 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2696 - 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
|
2697 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
|
2698 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2699 - 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
|
2700 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
|
2701 can pick it up. This is the primary task of set_exc_info(). |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2702 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2703 - 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
|
2704 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2705 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
|
2706 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
|
2707 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
|
2708 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
|
2709 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
|
2710 this: |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2711 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2712 try: |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2713 "something that may fail" |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2714 except "some exception": |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2715 "do something else first" |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2716 "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
|
2717 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2718 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
|
2719 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
|
2720 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
|
2721 follows: |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2722 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2723 - 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
|
2724 *in that frame*. |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2725 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2726 - 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
|
2727 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
|
2728 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
|
2729 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2730 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
|
2731 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
|
2732 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
|
2733 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
|
2734 (Example: traceback.print_exc()). |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2735 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2736 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
|
2737 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
|
2738 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
|
2739 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2740 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
|
2741 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
|
2742 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
|
2743 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
|
2744 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
|
2745 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
|
2746 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
|
2747 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
|
2748 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
|
2749 |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2750 */ |
|
c24a23b1f198
Added implementation notes for [re]set_exc_info().
Guido van Rossum <guido@python.org>
parents:
28086
diff
changeset
|
2751 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2752 static void |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2753 set_exc_info(PyThreadState *tstate, |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2754 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
|
2755 { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2756 PyFrameObject *frame; |
|
5557
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
2757 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
|
2758 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2759 frame = tstate->frame; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2760 if (frame->f_exc_type == NULL) { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2761 /* This frame didn't catch an exception before */ |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2762 /* Save previous exception of this thread in this frame */ |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2763 if (tstate->exc_type == NULL) { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2764 Py_INCREF(Py_None); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2765 tstate->exc_type = Py_None; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2766 } |
|
5557
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
2767 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
|
2768 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
|
2769 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
|
2770 Py_XINCREF(tstate->exc_type); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2771 Py_XINCREF(tstate->exc_value); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2772 Py_XINCREF(tstate->exc_traceback); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2773 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
|
2774 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
|
2775 frame->f_exc_traceback = tstate->exc_traceback; |
|
5557
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
2776 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
|
2777 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
|
2778 Py_XDECREF(tmp_tb); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2779 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2780 /* 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
|
2781 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
|
2782 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
|
2783 tmp_tb = tstate->exc_traceback; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2784 Py_XINCREF(type); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2785 Py_XINCREF(value); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2786 Py_XINCREF(tb); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2787 tstate->exc_type = type; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2788 tstate->exc_value = value; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2789 tstate->exc_traceback = tb; |
|
5557
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
2790 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
|
2791 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
|
2792 Py_XDECREF(tmp_tb); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2793 /* For b/w compatibility */ |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2794 PySys_SetObject("exc_type", type); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2795 PySys_SetObject("exc_value", value); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2796 PySys_SetObject("exc_traceback", tb); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2797 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2798 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2799 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
2800 reset_exc_info(PyThreadState *tstate) |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2801 { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2802 PyFrameObject *frame; |
|
5557
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
2803 PyObject *tmp_type, *tmp_value, *tmp_tb; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2804 frame = tstate->frame; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2805 if (frame->f_exc_type != NULL) { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2806 /* This frame caught an exception */ |
|
5557
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
2807 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
|
2808 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
|
2809 tmp_tb = tstate->exc_traceback; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2810 Py_XINCREF(frame->f_exc_type); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2811 Py_XINCREF(frame->f_exc_value); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2812 Py_XINCREF(frame->f_exc_traceback); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2813 tstate->exc_type = frame->f_exc_type; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2814 tstate->exc_value = frame->f_exc_value; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2815 tstate->exc_traceback = frame->f_exc_traceback; |
|
5557
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
2816 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
|
2817 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
|
2818 Py_XDECREF(tmp_tb); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2819 /* For b/w compatibility */ |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2820 PySys_SetObject("exc_type", frame->f_exc_type); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2821 PySys_SetObject("exc_value", frame->f_exc_value); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2822 PySys_SetObject("exc_traceback", frame->f_exc_traceback); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2823 } |
|
5557
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
2824 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
|
2825 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
|
2826 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
|
2827 frame->f_exc_type = NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2828 frame->f_exc_value = NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2829 frame->f_exc_traceback = NULL; |
|
5557
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
2830 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
|
2831 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
|
2832 Py_XDECREF(tmp_tb); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2833 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2834 |
|
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
|
2835 /* 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
|
2836 This *consumes* a reference count to each of its arguments. */ |
| 5018 | 2837 static enum why_code |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
2838 do_raise(PyObject *type, PyObject *value, PyObject *tb) |
|
4667
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2839 { |
|
7946
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2840 if (type == NULL) { |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2841 /* Reraise */ |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2842 PyThreadState *tstate = PyThreadState_Get(); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2843 type = tstate->exc_type == NULL ? Py_None : tstate->exc_type; |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2844 value = tstate->exc_value; |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2845 tb = tstate->exc_traceback; |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2846 Py_XINCREF(type); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2847 Py_XINCREF(value); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2848 Py_XINCREF(tb); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2849 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2850 |
|
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
|
2851 /* We support the following forms of raise: |
|
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2852 raise <class>, <classinstance> |
|
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2853 raise <class>, <argument tuple> |
|
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2854 raise <class>, None |
|
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2855 raise <class>, <argument> |
|
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2856 raise <classinstance>, None |
|
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2857 raise <string>, <object> |
|
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2858 raise <string>, None |
|
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2859 |
|
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
|
2860 An omitted second argument is the same as None. |
|
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2861 |
|
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
|
2862 In addition, raise <tuple>, <anything> is the same as |
|
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2863 raising the tuple's first item (and it better have one!); |
|
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2864 this rule is applied recursively. |
|
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2865 |
|
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
|
2866 Finally, an optional third argument can be supplied, which |
|
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2867 gives the traceback to be substituted (useful when |
|
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2868 re-raising an exception after examining it). */ |
|
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2869 |
|
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
|
2870 /* First, check the traceback argument, replacing None with |
|
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2871 NULL. */ |
| 5368 | 2872 if (tb == Py_None) { |
| 2873 Py_DECREF(tb); | |
|
4667
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2874 tb = NULL; |
|
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2875 } |
|
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
|
2876 else if (tb != NULL && !PyTraceBack_Check(tb)) { |
| 5368 | 2877 PyErr_SetString(PyExc_TypeError, |
| 15318 | 2878 "raise: arg 3 must be a traceback or None"); |
|
4667
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2879 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
|
2880 } |
|
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
|
2881 |
|
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
|
2882 /* Next, replace a missing value with None */ |
|
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2883 if (value == NULL) { |
| 5368 | 2884 value = Py_None; |
| 2885 Py_INCREF(value); | |
|
4667
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2886 } |
|
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
|
2887 |
|
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
|
2888 /* Next, repeatedly, replace a tuple exception with its first item */ |
| 5368 | 2889 while (PyTuple_Check(type) && PyTuple_Size(type) > 0) { |
| 2890 PyObject *tmp = type; | |
| 2891 type = PyTuple_GET_ITEM(type, 0); | |
| 2892 Py_INCREF(type); | |
| 2893 Py_DECREF(tmp); | |
|
4667
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2894 } |
|
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
|
2895 |
|
23156
aae814f94bad
ceval.c/do_raise(): Tighten the test to disallow raising an instance of
Tim Peters <tim.peters@gmail.com>
parents:
22621
diff
changeset
|
2896 if (PyString_CheckExact(type)) |
|
aae814f94bad
ceval.c/do_raise(): Tighten the test to disallow raising an instance of
Tim Peters <tim.peters@gmail.com>
parents:
22621
diff
changeset
|
2897 /* Raising builtin string is deprecated but still allowed -- |
|
aae814f94bad
ceval.c/do_raise(): Tighten the test to disallow raising an instance of
Tim Peters <tim.peters@gmail.com>
parents:
22621
diff
changeset
|
2898 * do nothing. Raising an instance of a new-style str |
|
aae814f94bad
ceval.c/do_raise(): Tighten the test to disallow raising an instance of
Tim Peters <tim.peters@gmail.com>
parents:
22621
diff
changeset
|
2899 * subclass is right out. */ |
|
27200
92812f6cd63b
As discussed briefly on python-dev, add Pending Deprecation Warning
Neal Norwitz <nnorwitz@gmail.com>
parents:
27186
diff
changeset
|
2900 PyErr_Warn(PyExc_PendingDeprecationWarning, |
|
92812f6cd63b
As discussed briefly on python-dev, add Pending Deprecation Warning
Neal Norwitz <nnorwitz@gmail.com>
parents:
27186
diff
changeset
|
2901 "raising a string exception is deprecated"); |
|
6147
b76a44163e0f
cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents:
6139
diff
changeset
|
2902 |
|
b76a44163e0f
cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents:
6139
diff
changeset
|
2903 else if (PyClass_Check(type)) |
|
b76a44163e0f
cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents:
6139
diff
changeset
|
2904 PyErr_NormalizeException(&type, &value, &tb); |
|
b76a44163e0f
cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents:
6139
diff
changeset
|
2905 |
| 5368 | 2906 else if (PyInstance_Check(type)) { |
|
4667
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2907 /* Raising an instance. The value should be a dummy. */ |
| 5368 | 2908 if (value != Py_None) { |
| 2909 PyErr_SetString(PyExc_TypeError, | |
|
4667
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2910 "instance exception may not have a separate value"); |
|
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2911 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
|
2912 } |
|
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
|
2913 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
|
2914 /* Normalize to raise <class>, <instance> */ |
| 5368 | 2915 Py_DECREF(value); |
|
4667
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2916 value = type; |
| 5368 | 2917 type = (PyObject*) ((PyInstanceObject*)type)->in_class; |
| 2918 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
|
2919 } |
|
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
|
2920 } |
|
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
|
2921 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
|
2922 /* 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
|
2923 anyway, just not what you specified :-) */ |
|
17636
9921a9d27f72
improved error message-- names the type of the unexpected object
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17617
diff
changeset
|
2924 PyErr_Format(PyExc_TypeError, |
|
27200
92812f6cd63b
As discussed briefly on python-dev, add Pending Deprecation Warning
Neal Norwitz <nnorwitz@gmail.com>
parents:
27186
diff
changeset
|
2925 "exceptions must be classes, instances, or " |
|
92812f6cd63b
As discussed briefly on python-dev, add Pending Deprecation Warning
Neal Norwitz <nnorwitz@gmail.com>
parents:
27186
diff
changeset
|
2926 "strings (deprecated), not %s", |
|
92812f6cd63b
As discussed briefly on python-dev, add Pending Deprecation Warning
Neal Norwitz <nnorwitz@gmail.com>
parents:
27186
diff
changeset
|
2927 type->ob_type->tp_name); |
|
4667
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2928 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
|
2929 } |
| 5368 | 2930 PyErr_Restore(type, value, tb); |
|
4667
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2931 if (tb == NULL) |
|
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2932 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
|
2933 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
|
2934 return WHY_RERAISE; |
|
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2935 raise_error: |
| 5368 | 2936 Py_XDECREF(value); |
| 2937 Py_XDECREF(type); | |
| 2938 Py_XDECREF(tb); | |
|
4667
c42379e4653b
Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents:
4594
diff
changeset
|
2939 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
|
2940 } |
|
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
|
2941 |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2942 /* Iterate v argcnt times and store the results on the stack (via decreasing |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2943 sp). Return 1 for success, 0 if error. */ |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2944 |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2945 static int |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2946 unpack_iterable(PyObject *v, int argcnt, PyObject **sp) |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2947 { |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2948 int i = 0; |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2949 PyObject *it; /* iter(v) */ |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2950 PyObject *w; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2951 |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2952 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
|
2953 |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2954 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
|
2955 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
|
2956 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
|
2957 |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2958 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
|
2959 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
|
2960 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
|
2961 /* 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
|
2962 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
|
2963 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
|
2964 "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
|
2965 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
|
2966 } |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2967 goto Error; |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2968 } |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2969 *--sp = w; |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2970 } |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2971 |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2972 /* We better have exhausted the iterator now. */ |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2973 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
|
2974 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
|
2975 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
|
2976 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
|
2977 Py_DECREF(it); |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2978 return 1; |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2979 } |
|
21170
2dfc600f99ce
unpack_iterable(): Add a missing DECREF in an error case. Reported by
Guido van Rossum <guido@python.org>
parents:
21058
diff
changeset
|
2980 Py_DECREF(w); |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2981 PyErr_SetString(PyExc_ValueError, "too many values to unpack"); |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2982 /* fall through */ |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2983 Error: |
|
6160
79592761b331
unpack_sequence(): In finally clause, watch out for Py_DECREF
Barry Warsaw <barry@python.org>
parents:
6157
diff
changeset
|
2984 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
|
2985 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
|
2986 Py_XDECREF(it); |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2987 return 0; |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2988 } |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2989 |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2990 |
| 567 | 2991 #ifdef LLTRACE |
| 86 | 2992 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
2993 prtrace(PyObject *v, char *str) |
| 69 | 2994 { |
| 86 | 2995 printf("%s ", str); |
| 5368 | 2996 if (PyObject_Print(v, stdout, 0) != 0) |
| 2997 PyErr_Clear(); /* Don't know what else to do */ | |
| 86 | 2998 printf("\n"); |
|
12579
978253542076
Add useless 'return 1' to prtrace() to shut up VC++.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
2999 return 1; |
| 69 | 3000 } |
| 86 | 3001 #endif |
| 69 | 3002 |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3003 static void |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3004 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
|
3005 { |
| 5368 | 3006 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
|
3007 int err; |
| 5368 | 3008 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
|
3009 if (value == NULL) { |
| 5368 | 3010 value = Py_None; |
| 3011 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
|
3012 } |
|
30683
3b59fa5d25b1
Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents:
29669
diff
changeset
|
3013 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
|
3014 if (arg == NULL) { |
| 5368 | 3015 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
|
3016 return; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
3017 } |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3018 err = call_trace(func, self, f, PyTrace_EXCEPTION, arg); |
| 5368 | 3019 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
|
3020 if (err == 0) |
| 5368 | 3021 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
|
3022 else { |
| 5368 | 3023 Py_XDECREF(type); |
| 3024 Py_XDECREF(value); | |
| 3025 Py_XDECREF(traceback); | |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3026 } |
|
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3027 } |
|
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3028 |
|
20257
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3029 static void |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3030 call_trace_protected(Py_tracefunc func, PyObject *obj, PyFrameObject *frame, |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3031 int what) |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3032 { |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3033 PyObject *type, *value, *traceback; |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3034 int err; |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3035 PyErr_Fetch(&type, &value, &traceback); |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3036 err = call_trace(func, obj, frame, what, NULL); |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3037 if (err == 0) |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3038 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
|
3039 else { |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3040 Py_XDECREF(type); |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3041 Py_XDECREF(value); |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3042 Py_XDECREF(traceback); |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3043 } |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3044 } |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
3045 |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3046 static int |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3047 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
|
3048 int what, PyObject *arg) |
| 567 | 3049 { |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3050 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
|
3051 int result; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3052 if (tstate->tracing) |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
3053 return 0; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3054 tstate->tracing++; |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
3055 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
|
3056 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
|
3057 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
|
3058 || (tstate->c_profilefunc != NULL)); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3059 tstate->tracing--; |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3060 return result; |
| 567 | 3061 } |
| 3062 | |
|
28556
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3063 PyObject * |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3064 _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
|
3065 { |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3066 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
|
3067 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
|
3068 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
|
3069 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
|
3070 PyObject *result; |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3071 |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3072 tstate->tracing = 0; |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3073 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
|
3074 || (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
|
3075 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
|
3076 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
|
3077 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
|
3078 return result; |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3079 } |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28304
diff
changeset
|
3080 |
|
26110
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
3081 static int |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
3082 maybe_call_line_trace(Py_tracefunc func, PyObject *obj, |
| 24844 | 3083 PyFrameObject *frame, int *instr_lb, int *instr_ub) |
| 3084 { | |
| 3085 /* The theory of SET_LINENO-less tracing. | |
| 3086 | |
| 3087 In a nutshell, we use the co_lnotab field of the code object | |
| 3088 to tell when execution has moved onto a different line. | |
| 3089 | |
| 3090 As mentioned above, the basic idea is so set things up so | |
| 3091 that | |
| 3092 | |
| 3093 *instr_lb <= frame->f_lasti < *instr_ub | |
| 3094 | |
| 3095 is true so long as execution does not change lines. | |
| 3096 | |
| 3097 This is all fairly simple. Digging the information out of | |
| 3098 co_lnotab takes some work, but is conceptually clear. | |
| 3099 | |
|
25078
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24978
diff
changeset
|
3100 Somewhat harder to explain is why we don't *always* call the |
|
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24978
diff
changeset
|
3101 line trace function when the above test fails. |
| 24844 | 3102 |
| 3103 Consider this code: | |
| 3104 | |
| 3105 1: def f(a): | |
| 3106 2: if a: | |
| 3107 3: print 1 | |
| 3108 4: else: | |
| 3109 5: print 2 | |
| 3110 | |
| 3111 which compiles to this: | |
| 3112 | |
| 3113 2 0 LOAD_FAST 0 (a) | |
| 3114 3 JUMP_IF_FALSE 9 (to 15) | |
| 3115 6 POP_TOP | |
| 3116 | |
| 3117 3 7 LOAD_CONST 1 (1) | |
| 3118 10 PRINT_ITEM | |
| 3119 11 PRINT_NEWLINE | |
| 3120 12 JUMP_FORWARD 6 (to 21) | |
| 3121 >> 15 POP_TOP | |
| 3122 | |
| 3123 5 16 LOAD_CONST 2 (2) | |
| 3124 19 PRINT_ITEM | |
| 3125 20 PRINT_NEWLINE | |
|
25078
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24978
diff
changeset
|
3126 >> 21 LOAD_CONST 0 (None) |
|
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24978
diff
changeset
|
3127 24 RETURN_VALUE |
| 24844 | 3128 |
|
25207
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25109
diff
changeset
|
3129 If 'a' is false, execution will jump to instruction at offset |
| 24844 | 3130 15 and the co_lnotab will claim that execution has moved to |
| 3131 line 3. This is at best misleading. In this case we could | |
| 3132 associate the POP_TOP with line 4, but that doesn't make | |
| 3133 sense in all cases (I think). | |
| 3134 | |
|
25078
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24978
diff
changeset
|
3135 What we do is only call the line trace function if the co_lnotab |
|
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24978
diff
changeset
|
3136 indicates we have jumped to the *start* of a line, i.e. if the |
|
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24978
diff
changeset
|
3137 current instruction offset matches the offset given for the |
|
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24978
diff
changeset
|
3138 start of a line by the co_lnotab. |
|
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24978
diff
changeset
|
3139 |
|
25207
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25109
diff
changeset
|
3140 This also takes care of the situation where 'a' is true. |
|
25078
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24978
diff
changeset
|
3141 Execution will jump from instruction offset 12 to offset 21. |
|
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24978
diff
changeset
|
3142 Then the co_lnotab would imply that execution has moved to line |
|
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24978
diff
changeset
|
3143 5, which is again misleading. |
|
25207
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25109
diff
changeset
|
3144 |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25109
diff
changeset
|
3145 Why do we set f_lineno when tracing? Well, consider the code |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25109
diff
changeset
|
3146 above when 'a' is true. If stepping through this with 'n' in |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25109
diff
changeset
|
3147 pdb, you would stop at line 1 with a "call" type event, then |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25109
diff
changeset
|
3148 line events on lines 2 and 3, then a "return" type event -- but |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25109
diff
changeset
|
3149 you would be shown line 5 during this event. This is a change |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25109
diff
changeset
|
3150 from the behaviour in 2.2 and before, and I've found it |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25109
diff
changeset
|
3151 confusing in practice. By setting and using f_lineno when |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25109
diff
changeset
|
3152 tracing, one can report a line number different from that |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25109
diff
changeset
|
3153 suggested by f_lasti on this one occasion where it's desirable. |
| 24844 | 3154 */ |
| 3155 | |
|
26110
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
3156 int result = 0; |
|
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
3157 |
|
25078
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24978
diff
changeset
|
3158 if ((frame->f_lasti < *instr_lb || frame->f_lasti >= *instr_ub)) { |
| 24844 | 3159 PyCodeObject* co = frame->f_code; |
|
25207
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25109
diff
changeset
|
3160 int size, addr, line; |
| 24844 | 3161 unsigned char* p; |
| 3162 | |
|
25078
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24978
diff
changeset
|
3163 size = PyString_GET_SIZE(co->co_lnotab) / 2; |
|
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24978
diff
changeset
|
3164 p = (unsigned char*)PyString_AS_STRING(co->co_lnotab); |
|
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24978
diff
changeset
|
3165 |
|
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24978
diff
changeset
|
3166 addr = 0; |
|
25207
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25109
diff
changeset
|
3167 line = co->co_firstlineno; |
| 24844 | 3168 |
| 3169 /* possible optimization: if f->f_lasti == instr_ub | |
| 3170 (likely to be a common case) then we already know | |
| 3171 instr_lb -- if we stored the matching value of p | |
| 3172 somwhere we could skip the first while loop. */ | |
| 3173 | |
| 3174 /* see comments in compile.c for the description of | |
| 3175 co_lnotab. A point to remember: increments to p | |
| 3176 should come in pairs -- although we don't care about | |
| 3177 the line increments here, treating them as byte | |
| 3178 increments gets confusing, to say the least. */ | |
| 3179 | |
|
25078
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24978
diff
changeset
|
3180 while (size > 0) { |
| 24844 | 3181 if (addr + *p > frame->f_lasti) |
| 3182 break; | |
| 3183 addr += *p++; | |
|
25539
5fe07cd4b2bf
One last tweak to the tracing machinery: this actually computes what I intended
Michael W. Hudson <mwh@python.net>
parents:
25532
diff
changeset
|
3184 if (*p) *instr_lb = addr; |
|
25207
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25109
diff
changeset
|
3185 line += *p++; |
| 24844 | 3186 --size; |
| 3187 } | |
|
25539
5fe07cd4b2bf
One last tweak to the tracing machinery: this actually computes what I intended
Michael W. Hudson <mwh@python.net>
parents:
25532
diff
changeset
|
3188 |
|
25207
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25109
diff
changeset
|
3189 if (addr == frame->f_lasti) { |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25109
diff
changeset
|
3190 frame->f_lineno = line; |
|
26110
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
3191 result = call_trace(func, obj, frame, |
|
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
3192 PyTrace_LINE, Py_None); |
|
25207
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25109
diff
changeset
|
3193 } |
|
25539
5fe07cd4b2bf
One last tweak to the tracing machinery: this actually computes what I intended
Michael W. Hudson <mwh@python.net>
parents:
25532
diff
changeset
|
3194 |
| 24844 | 3195 if (size > 0) { |
| 3196 while (--size >= 0) { | |
| 3197 addr += *p++; | |
| 3198 if (*p++) | |
| 3199 break; | |
| 3200 } | |
| 3201 *instr_ub = addr; | |
| 3202 } | |
| 3203 else { | |
| 3204 *instr_ub = INT_MAX; | |
| 3205 } | |
| 3206 } | |
|
26110
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
3207 |
|
964d6b79c22e
This is Richie Hindle's patch:
Michael W. Hudson <mwh@python.net>
parents:
26109
diff
changeset
|
3208 return result; |
| 24844 | 3209 } |
| 3210 | |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3211 void |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3212 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
|
3213 { |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3214 PyThreadState *tstate = PyThreadState_Get(); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3215 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
|
3216 Py_XINCREF(arg); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3217 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
|
3218 tstate->c_profileobj = NULL; |
|
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; |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
3223 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
|
3224 } |
|
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 void |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3227 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
|
3228 { |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3229 PyThreadState *tstate = PyThreadState_Get(); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3230 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
|
3231 Py_XINCREF(arg); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3232 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
|
3233 tstate->c_traceobj = NULL; |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
3234 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
|
3235 Py_XDECREF(temp); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
3236 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
|
3237 tstate->c_traceobj = arg; |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
3238 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
|
3239 || (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
|
3240 } |
|
4cb34314bd97
Instead of initializing & interning the strings passed to the profile
Fred Drake <fdrake@acm.org>
parents:
18128
diff
changeset
|
3241 |
| 5368 | 3242 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3243 PyEval_GetBuiltins(void) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3244 { |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
3245 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
|
3246 if (current_frame == NULL) |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
3247 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
|
3248 else |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3249 return current_frame->f_builtins; |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3250 } |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3251 |
| 5368 | 3252 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3253 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
|
3254 { |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
3255 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
|
3256 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
|
3257 return NULL; |
| 5368 | 3258 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
|
3259 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
|
3260 } |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3261 |
| 5368 | 3262 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3263 PyEval_GetGlobals(void) |
| 69 | 3264 { |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
3265 PyFrameObject *current_frame = PyEval_GetFrame(); |
| 86 | 3266 if (current_frame == NULL) |
| 3267 return NULL; | |
| 3268 else | |
| 3269 return current_frame->f_globals; | |
| 69 | 3270 } |
| 3271 | |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
3272 PyFrameObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3273 PyEval_GetFrame(void) |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
3274 { |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
26079
diff
changeset
|
3275 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
|
3276 return _PyThreadState_GetFrame(tstate); |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
3277 } |
|
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
3278 |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3279 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3280 PyEval_GetRestricted(void) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3281 { |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
3282 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
|
3283 return current_frame == NULL ? 0 : current_frame->f_restricted; |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3284 } |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
3285 |
|
5606
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
3286 int |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3287 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
|
3288 { |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
3289 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
|
3290 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
|
3291 |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3292 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
|
3293 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
|
3294 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
|
3295 if (compilerflags) { |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3296 result = 1; |
|
19350
5b6a6d7d44ae
ceval, PyEval_MergeCompilerFlags: wasn't merging in the
Tim Peters <tim.peters@gmail.com>
parents:
19301
diff
changeset
|
3297 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
|
3298 } |
|
22468
eebae4f60d05
Disable the parser hacks that enabled the "yield" keyword using a future
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22398
diff
changeset
|
3299 #if 0 /* future keyword */ |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
3300 if (codeflags & CO_GENERATOR_ALLOWED) { |
|
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
3301 result = 1; |
|
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
3302 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
|
3303 } |
|
22468
eebae4f60d05
Disable the parser hacks that enabled the "yield" keyword using a future
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22398
diff
changeset
|
3304 #endif |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3305 } |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3306 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
|
3307 } |
|
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
|
3308 |
|
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
|
3309 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3310 Py_FlushLine(void) |
| 69 | 3311 { |
| 5368 | 3312 PyObject *f = PySys_GetObject("stdout"); |
|
5606
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
3313 if (f == NULL) |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
3314 return 0; |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
3315 if (!PyFile_SoftSpace(f, 0)) |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
3316 return 0; |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
3317 return PyFile_WriteString("\n", f); |
| 69 | 3318 } |
| 3319 | |
| 86 | 3320 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3321 /* External interface to call any callable object. |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3322 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
|
3323 |
|
6206
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
3324 #undef PyEval_CallObject |
|
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
3325 /* for backward compatibility: export this interface */ |
|
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
3326 |
| 5368 | 3327 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3328 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
|
3329 { |
| 5368 | 3330 return PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3331 } |
|
6206
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
3332 #define PyEval_CallObject(func,arg) \ |
|
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
3333 PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3334 |
| 5368 | 3335 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3336 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
|
3337 { |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3338 PyObject *result; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3339 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3340 if (arg == NULL) |
| 5368 | 3341 arg = PyTuple_New(0); |
| 3342 else if (!PyTuple_Check(arg)) { | |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3343 PyErr_SetString(PyExc_TypeError, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3344 "argument list must be a tuple"); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3345 return NULL; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3346 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3347 else |
| 5368 | 3348 Py_INCREF(arg); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3349 |
| 5368 | 3350 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
|
3351 PyErr_SetString(PyExc_TypeError, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3352 "keyword list must be a dictionary"); |
|
12440
d47460b1a679
Charles Waldman writes:
Guido van Rossum <guido@python.org>
parents:
12320
diff
changeset
|
3353 Py_DECREF(arg); |
|
2894
4095782c940e
empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents:
2872
diff
changeset
|
3354 return NULL; |
|
4095782c940e
empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents:
2872
diff
changeset
|
3355 } |
|
4095782c940e
empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents:
2872
diff
changeset
|
3356 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3357 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
|
3358 Py_DECREF(arg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3359 return result; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3360 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3361 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3362 char * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3363 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
|
3364 { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3365 if (PyMethod_Check(func)) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3366 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
|
3367 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
|
3368 return PyString_AsString(((PyFunctionObject*)func)->func_name); |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3369 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
|
3370 return ((PyCFunctionObject*)func)->m_ml->ml_name; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3371 else if (PyClass_Check(func)) |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3372 return PyString_AsString(((PyClassObject*)func)->cl_name); |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3373 else if (PyInstance_Check(func)) { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3374 return PyString_AsString( |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3375 ((PyInstanceObject*)func)->in_class->cl_name); |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3376 } else { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3377 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
|
3378 } |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3379 } |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3380 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3381 char * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3382 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
|
3383 { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3384 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
|
3385 return "()"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3386 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
|
3387 return "()"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3388 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
|
3389 return "()"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3390 else if (PyClass_Check(func)) |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3391 return " constructor"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3392 else if (PyInstance_Check(func)) { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3393 return " instance"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3394 } else { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3395 return " object"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3396 } |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3397 } |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3398 |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3399 #define EXT_POP(STACK_POINTER) (*--(STACK_POINTER)) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3400 |
|
26141
6ce9228a3da2
Make private functions static so we don't pollute the namespace
Neal Norwitz <nnorwitz@gmail.com>
parents:
26110
diff
changeset
|
3401 static void |
|
24870
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3402 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
|
3403 { |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3404 if (flags & METH_NOARGS) |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3405 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
|
3406 "%.200s() takes no arguments (%d given)", |
|
24870
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3407 ((PyCFunctionObject *)func)->m_ml->ml_name, |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3408 nargs); |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3409 else |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3410 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
|
3411 "%.200s() takes exactly one argument (%d given)", |
|
24870
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3412 ((PyCFunctionObject *)func)->m_ml->ml_name, |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3413 nargs); |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3414 } |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3415 |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3416 static PyObject * |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3417 call_function(PyObject ***pp_stack, int oparg) |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3418 { |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3419 int na = oparg & 0xff; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3420 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
|
3421 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
|
3422 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
|
3423 PyObject *func = *pfunc; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3424 PyObject *x, *w; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3425 |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3426 /* 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
|
3427 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
|
3428 */ |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3429 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
|
3430 int flags = PyCFunction_GET_FLAGS(func); |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3431 PCALL(PCALL_CFUNCTION); |
|
24870
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3432 if (flags & (METH_NOARGS | METH_O)) { |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3433 PyCFunction meth = PyCFunction_GET_FUNCTION(func); |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3434 PyObject *self = PyCFunction_GET_SELF(func); |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3435 if (flags & METH_NOARGS && na == 0) |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3436 x = (*meth)(self, NULL); |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3437 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
|
3438 PyObject *arg = EXT_POP(*pp_stack); |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3439 x = (*meth)(self, arg); |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3440 Py_DECREF(arg); |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3441 } |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3442 else { |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3443 err_args(func, flags, na); |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3444 x = NULL; |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3445 } |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3446 } |
|
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3447 else { |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3448 PyObject *callargs; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3449 callargs = load_args(pp_stack, na); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3450 x = PyCFunction_Call(func, callargs, NULL); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3451 Py_XDECREF(callargs); |
|
24870
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3452 } |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3453 } else { |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3454 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
|
3455 /* 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
|
3456 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
|
3457 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
|
3458 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
|
3459 Py_INCREF(self); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3460 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
|
3461 Py_INCREF(func); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3462 Py_DECREF(*pfunc); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3463 *pfunc = self; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3464 na++; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3465 n++; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3466 } else |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3467 Py_INCREF(func); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3468 if (PyFunction_Check(func)) |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3469 x = fast_function(func, pp_stack, n, na, nk); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3470 else |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3471 x = do_call(func, pp_stack, na, nk); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3472 Py_DECREF(func); |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3473 } |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3474 |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3475 /* What does this do? */ |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3476 while ((*pp_stack) > pfunc) { |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3477 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
|
3478 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
|
3479 PCALL(PCALL_POP); |
|
24868
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3480 } |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3481 return x; |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3482 } |
|
2306001f6eaa
Move body of CALL_FUNCTION opcode into helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24866
diff
changeset
|
3483 |
|
24870
df2326a4894d
Inline fast_cfunction() in new call_function().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24868
diff
changeset
|
3484 /* 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
|
3485 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
|
3486 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
|
3487 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
|
3488 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
|
3489 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
|
3490 done before evaluating the frame. |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3491 */ |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3492 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3493 static PyObject * |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3494 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
|
3495 { |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3496 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
|
3497 PyObject *globals = PyFunction_GET_GLOBALS(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3498 PyObject *argdefs = PyFunction_GET_DEFAULTS(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3499 PyObject **d = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3500 int nd = 0; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3501 |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3502 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
|
3503 PCALL(PCALL_FAST_FUNCTION); |
|
29339
fc286e28556f
SF bug #733667: kwargs handled incorrectly
Raymond Hettinger <python@rcn.com>
parents:
29337
diff
changeset
|
3504 if (argdefs == NULL && co->co_argcount == n && nk==0 && |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3505 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
|
3506 PyFrameObject *f; |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3507 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
|
3508 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
|
3509 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
|
3510 int i; |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3511 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3512 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
|
3513 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
|
3514 /* 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
|
3515 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
|
3516 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
|
3517 */ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3518 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
|
3519 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
|
3520 return NULL; |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3521 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3522 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
|
3523 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
|
3524 |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3525 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
|
3526 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
|
3527 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
|
3528 } |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3529 retval = eval_frame(f); |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3530 assert(tstate != NULL); |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3531 ++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
|
3532 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
|
3533 --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
|
3534 return retval; |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3535 } |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3536 if (argdefs != NULL) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3537 d = &PyTuple_GET_ITEM(argdefs, 0); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3538 nd = ((PyTupleObject *)argdefs)->ob_size; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3539 } |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3540 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
|
3541 (PyObject *)NULL, (*pp_stack)-n, na, |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3542 (*pp_stack)-2*nk, nk, d, nd, |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3543 PyFunction_GET_CLOSURE(func)); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3544 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3545 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3546 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
|
3547 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
|
3548 PyObject *func) |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3549 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3550 PyObject *kwdict = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3551 if (orig_kwdict == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3552 kwdict = PyDict_New(); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3553 else { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3554 kwdict = PyDict_Copy(orig_kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3555 Py_DECREF(orig_kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3556 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3557 if (kwdict == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3558 return NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3559 while (--nk >= 0) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3560 int err; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3561 PyObject *value = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3562 PyObject *key = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3563 if (PyDict_GetItem(kwdict, key) != NULL) { |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3564 PyErr_Format(PyExc_TypeError, |
|
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
|
3565 "%.200s%s got multiple values " |
|
17406
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3566 "for keyword argument '%.200s'", |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3567 PyEval_GetFuncName(func), |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3568 PyEval_GetFuncDesc(func), |
|
17406
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3569 PyString_AsString(key)); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3570 Py_DECREF(key); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3571 Py_DECREF(value); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3572 Py_DECREF(kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3573 return NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3574 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3575 err = PyDict_SetItem(kwdict, key, value); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3576 Py_DECREF(key); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3577 Py_DECREF(value); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3578 if (err) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3579 Py_DECREF(kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3580 return NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3581 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3582 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3583 return kwdict; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3584 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3585 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3586 static PyObject * |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3587 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
|
3588 PyObject ***pp_stack) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3589 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3590 PyObject *callargs, *w; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3591 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3592 callargs = PyTuple_New(nstack + nstar); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3593 if (callargs == NULL) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3594 return NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3595 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3596 if (nstar) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3597 int i; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3598 for (i = 0; i < nstar; i++) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3599 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
|
3600 Py_INCREF(a); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3601 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
|
3602 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3603 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3604 while (--nstack >= 0) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3605 w = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3606 PyTuple_SET_ITEM(callargs, nstack, w); |
|
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 return callargs; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3609 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3610 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3611 static PyObject * |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3612 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
|
3613 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3614 PyObject *args = PyTuple_New(na); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3615 PyObject *w; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3616 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3617 if (args == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3618 return NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3619 while (--na >= 0) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3620 w = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3621 PyTuple_SET_ITEM(args, na, w); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3622 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3623 return args; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3624 } |
|
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 static PyObject * |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3627 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
|
3628 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3629 PyObject *callargs = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3630 PyObject *kwdict = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3631 PyObject *result = NULL; |
|
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 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
|
3634 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
|
3635 if (kwdict == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3636 goto call_fail; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3637 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3638 callargs = load_args(pp_stack, na); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3639 if (callargs == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3640 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
|
3641 #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
|
3642 /* 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
|
3643 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
|
3644 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
|
3645 */ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3646 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
|
3647 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
|
3648 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
|
3649 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
|
3650 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
|
3651 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
|
3652 else |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3653 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
|
3654 #endif |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3655 result = PyObject_Call(func, callargs, kwdict); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3656 call_fail: |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3657 Py_XDECREF(callargs); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3658 Py_XDECREF(kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3659 return result; |
|
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 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3662 static PyObject * |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3663 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
|
3664 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3665 int nstar = 0; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3666 PyObject *callargs = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3667 PyObject *stararg = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3668 PyObject *kwdict = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3669 PyObject *result = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3670 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3671 if (flags & CALL_FLAG_KW) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3672 kwdict = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3673 if (!(kwdict && PyDict_Check(kwdict))) { |
|
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
|
3674 PyErr_Format(PyExc_TypeError, |
|
17406
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3675 "%s%s argument after ** " |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3676 "must be a dictionary", |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3677 PyEval_GetFuncName(func), |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3678 PyEval_GetFuncDesc(func)); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3679 goto ext_call_fail; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3680 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3681 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3682 if (flags & CALL_FLAG_VAR) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3683 stararg = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3684 if (!PyTuple_Check(stararg)) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3685 PyObject *t = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3686 t = PySequence_Tuple(stararg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3687 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
|
3688 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
|
3689 PyErr_Format(PyExc_TypeError, |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3690 "%s%s argument after * " |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3691 "must be a sequence", |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3692 PyEval_GetFuncName(func), |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3693 PyEval_GetFuncDesc(func)); |
|
17406
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3694 } |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3695 goto ext_call_fail; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3696 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3697 Py_DECREF(stararg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3698 stararg = t; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3699 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3700 nstar = PyTuple_GET_SIZE(stararg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3701 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3702 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
|
3703 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
|
3704 if (kwdict == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3705 goto ext_call_fail; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3706 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3707 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
|
3708 if (callargs == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3709 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
|
3710 #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
|
3711 /* 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
|
3712 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
|
3713 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
|
3714 */ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3715 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
|
3716 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
|
3717 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
|
3718 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
|
3719 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
|
3720 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
|
3721 else |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27295
diff
changeset
|
3722 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
|
3723 #endif |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3724 result = PyObject_Call(func, callargs, kwdict); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3725 ext_call_fail: |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3726 Py_XDECREF(callargs); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3727 Py_XDECREF(kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3728 Py_XDECREF(stararg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3729 return result; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3730 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3731 |
|
3863
4566a19c3438
Better error message if stride used on normal sequence object
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
3732 #define SLICE_ERROR_MSG \ |
|
4566a19c3438
Better error message if stride used on normal sequence object
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
3733 "standard sequence type does not support step size other than one" |
|
4566a19c3438
Better error message if stride used on normal sequence object
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
3734 |
|
21440
30efe46f8e3c
_PyEval_SliceIndex(): Repaired the comments, and added XXX comments
Tim Peters <tim.peters@gmail.com>
parents:
21398
diff
changeset
|
3735 /* Extract a slice index from a PyInt or PyLong, and store in *pi. |
|
30efe46f8e3c
_PyEval_SliceIndex(): Repaired the comments, and added XXX comments
Tim Peters <tim.peters@gmail.com>
parents:
21398
diff
changeset
|
3736 Silently reduce values larger than INT_MAX to INT_MAX, and silently |
|
30efe46f8e3c
_PyEval_SliceIndex(): Repaired the comments, and added XXX comments
Tim Peters <tim.peters@gmail.com>
parents:
21398
diff
changeset
|
3737 boost values less than -INT_MAX to 0. Return 0 on error, 1 on success. |
|
30efe46f8e3c
_PyEval_SliceIndex(): Repaired the comments, and added XXX comments
Tim Peters <tim.peters@gmail.com>
parents:
21398
diff
changeset
|
3738 */ |
|
21441
05ad7a69d933
_PyEval_SliceIndex(): explain why a NULL argument is allowed (thanks
Tim Peters <tim.peters@gmail.com>
parents:
21440
diff
changeset
|
3739 /* 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
|
3740 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
|
3741 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
|
3742 */ |
| 12614 | 3743 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3744 _PyEval_SliceIndex(PyObject *v, int *pi) |
| 69 | 3745 { |
|
21441
05ad7a69d933
_PyEval_SliceIndex(): explain why a NULL argument is allowed (thanks
Tim Peters <tim.peters@gmail.com>
parents:
21440
diff
changeset
|
3746 if (v != NULL) { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3747 long x; |
|
11839
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3748 if (PyInt_Check(v)) { |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3749 x = PyInt_AsLong(v); |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3750 } else if (PyLong_Check(v)) { |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3751 x = PyLong_AsLong(v); |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3752 if (x==-1 && PyErr_Occurred()) { |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3753 PyObject *long_zero; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3754 int cmp; |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3755 |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3756 if (!PyErr_ExceptionMatches( |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3757 PyExc_OverflowError)) { |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3758 /* It's not an overflow error, so just |
|
11839
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3759 signal an error */ |
| 12614 | 3760 return 0; |
|
11839
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3761 } |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3762 |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3763 /* Clear the OverflowError */ |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3764 PyErr_Clear(); |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3765 |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3766 /* It's an overflow error, so we need to |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3767 check the sign of the long integer, |
|
28086
2474381527bb
In the process of adding all the extended slice support I attempted to
Michael W. Hudson <mwh@python.net>
parents:
28077
diff
changeset
|
3768 set the value to INT_MAX or -INT_MAX, |
|
2474381527bb
In the process of adding all the extended slice support I attempted to
Michael W. Hudson <mwh@python.net>
parents:
28077
diff
changeset
|
3769 and clear the error. */ |
|
11839
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3770 |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3771 /* Create a long integer with a value of 0 */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3772 long_zero = PyLong_FromLong(0L); |
|
21440
30efe46f8e3c
_PyEval_SliceIndex(): Repaired the comments, and added XXX comments
Tim Peters <tim.peters@gmail.com>
parents:
21398
diff
changeset
|
3773 if (long_zero == NULL) |
|
30efe46f8e3c
_PyEval_SliceIndex(): Repaired the comments, and added XXX comments
Tim Peters <tim.peters@gmail.com>
parents:
21398
diff
changeset
|
3774 return 0; |
|
11839
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3775 |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3776 /* Check sign */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3777 cmp = PyObject_RichCompareBool(v, long_zero, |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3778 Py_GT); |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3779 Py_DECREF(long_zero); |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3780 if (cmp < 0) |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3781 return 0; |
|
28086
2474381527bb
In the process of adding all the extended slice support I attempted to
Michael W. Hudson <mwh@python.net>
parents:
28077
diff
changeset
|
3782 else if (cmp) |
|
11839
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3783 x = INT_MAX; |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3784 else |
|
28086
2474381527bb
In the process of adding all the extended slice support I attempted to
Michael W. Hudson <mwh@python.net>
parents:
28077
diff
changeset
|
3785 x = -INT_MAX; |
|
11839
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3786 } |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3787 } else { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3788 PyErr_SetString(PyExc_TypeError, |
| 15318 | 3789 "slice indices must be integers"); |
| 12614 | 3790 return 0; |
| 69 | 3791 } |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3792 /* Truncate -- very long indices are truncated anyway */ |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3793 if (x > INT_MAX) |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3794 x = INT_MAX; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3795 else if (x < -INT_MAX) |
|
26079
cab167613e43
Handle really big steps in extended slices.
Michael W. Hudson <mwh@python.net>
parents:
25539
diff
changeset
|
3796 x = -INT_MAX; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3797 *pi = x; |
| 69 | 3798 } |
| 12614 | 3799 return 1; |
| 69 | 3800 } |
| 3801 | |
| 19369 | 3802 #undef ISINT |
| 3803 #define ISINT(x) ((x) == NULL || PyInt_Check(x) || PyLong_Check(x)) | |
| 3804 | |
| 5368 | 3805 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3806 apply_slice(PyObject *u, PyObject *v, PyObject *w) /* return u[v:w] */ |
| 69 | 3807 { |
| 19369 | 3808 PyTypeObject *tp = u->ob_type; |
| 3809 PySequenceMethods *sq = tp->tp_as_sequence; | |
| 3810 | |
| 3811 if (sq && sq->sq_slice && ISINT(v) && ISINT(w)) { | |
| 3812 int ilow = 0, ihigh = INT_MAX; | |
| 3813 if (!_PyEval_SliceIndex(v, &ilow)) | |
| 3814 return NULL; | |
| 3815 if (!_PyEval_SliceIndex(w, &ihigh)) | |
| 3816 return NULL; | |
| 3817 return PySequence_GetSlice(u, ilow, ihigh); | |
| 3818 } | |
| 3819 else { | |
| 3820 PyObject *slice = PySlice_New(v, w, NULL); | |
|
21171
2458cbcc1dd3
Fix the final two issues in Armin Rigo's SF bug #488477: apply_slice()
Guido van Rossum <guido@python.org>
parents:
21170
diff
changeset
|
3821 if (slice != NULL) { |
|
2458cbcc1dd3
Fix the final two issues in Armin Rigo's SF bug #488477: apply_slice()
Guido van Rossum <guido@python.org>
parents:
21170
diff
changeset
|
3822 PyObject *res = PyObject_GetItem(u, slice); |
|
2458cbcc1dd3
Fix the final two issues in Armin Rigo's SF bug #488477: apply_slice()
Guido van Rossum <guido@python.org>
parents:
21170
diff
changeset
|
3823 Py_DECREF(slice); |
|
2458cbcc1dd3
Fix the final two issues in Armin Rigo's SF bug #488477: apply_slice()
Guido van Rossum <guido@python.org>
parents:
21170
diff
changeset
|
3824 return res; |
|
2458cbcc1dd3
Fix the final two issues in Armin Rigo's SF bug #488477: apply_slice()
Guido van Rossum <guido@python.org>
parents:
21170
diff
changeset
|
3825 } |
| 19369 | 3826 else |
| 3827 return NULL; | |
| 3828 } | |
| 69 | 3829 } |
| 86 | 3830 |
| 3831 static int | |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3832 assign_slice(PyObject *u, PyObject *v, PyObject *w, PyObject *x) |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3833 /* u[v:w] = x */ |
| 69 | 3834 { |
| 19369 | 3835 PyTypeObject *tp = u->ob_type; |
| 3836 PySequenceMethods *sq = tp->tp_as_sequence; | |
| 3837 | |
| 3838 if (sq && sq->sq_slice && ISINT(v) && ISINT(w)) { | |
| 3839 int ilow = 0, ihigh = INT_MAX; | |
| 3840 if (!_PyEval_SliceIndex(v, &ilow)) | |
| 3841 return -1; | |
| 3842 if (!_PyEval_SliceIndex(w, &ihigh)) | |
| 3843 return -1; | |
| 3844 if (x == NULL) | |
| 3845 return PySequence_DelSlice(u, ilow, ihigh); | |
| 3846 else | |
| 3847 return PySequence_SetSlice(u, ilow, ihigh, x); | |
| 3848 } | |
| 3849 else { | |
| 3850 PyObject *slice = PySlice_New(v, w, NULL); | |
| 3851 if (slice != NULL) { | |
|
21171
2458cbcc1dd3
Fix the final two issues in Armin Rigo's SF bug #488477: apply_slice()
Guido van Rossum <guido@python.org>
parents:
21170
diff
changeset
|
3852 int res; |
| 19369 | 3853 if (x != NULL) |
|
21171
2458cbcc1dd3
Fix the final two issues in Armin Rigo's SF bug #488477: apply_slice()
Guido van Rossum <guido@python.org>
parents:
21170
diff
changeset
|
3854 res = PyObject_SetItem(u, slice, x); |
| 19369 | 3855 else |
|
21171
2458cbcc1dd3
Fix the final two issues in Armin Rigo's SF bug #488477: apply_slice()
Guido van Rossum <guido@python.org>
parents:
21170
diff
changeset
|
3856 res = PyObject_DelItem(u, slice); |
|
2458cbcc1dd3
Fix the final two issues in Armin Rigo's SF bug #488477: apply_slice()
Guido van Rossum <guido@python.org>
parents:
21170
diff
changeset
|
3857 Py_DECREF(slice); |
|
2458cbcc1dd3
Fix the final two issues in Armin Rigo's SF bug #488477: apply_slice()
Guido van Rossum <guido@python.org>
parents:
21170
diff
changeset
|
3858 return res; |
| 19369 | 3859 } |
| 3860 else | |
| 3861 return -1; | |
| 3862 } | |
| 69 | 3863 } |
| 3864 | |
| 5368 | 3865 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3866 cmp_outcome(int op, register PyObject *v, register PyObject *w) |
| 69 | 3867 { |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3868 int res = 0; |
| 69 | 3869 switch (op) { |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
3870 case PyCmp_IS: |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
3871 res = (v == w); |
|
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
3872 break; |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
3873 case PyCmp_IS_NOT: |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
3874 res = (v != w); |
| 86 | 3875 break; |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
3876 case PyCmp_IN: |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
3877 res = PySequence_Contains(w, v); |
|
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
3878 if (res < 0) |
|
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
3879 return NULL; |
|
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
3880 break; |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
3881 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
|
3882 res = PySequence_Contains(w, v); |
| 86 | 3883 if (res < 0) |
| 3884 return NULL; | |
|
27295
b8387730dd8f
SF patch #670367: Micro-optimizations for ceval.c
Raymond Hettinger <python@rcn.com>
parents:
27243
diff
changeset
|
3885 res = !res; |
| 69 | 3886 break; |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21537
diff
changeset
|
3887 case PyCmp_EXC_MATCH: |
|
6147
b76a44163e0f
cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents:
6139
diff
changeset
|
3888 res = PyErr_GivenExceptionMatches(v, w); |
| 69 | 3889 break; |
| 3890 default: | |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3891 return PyObject_RichCompare(v, w, op); |
| 69 | 3892 } |
| 5368 | 3893 v = res ? Py_True : Py_False; |
| 3894 Py_INCREF(v); | |
| 69 | 3895 return v; |
| 3896 } | |
| 3897 | |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
3898 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
|
3899 import_from(PyObject *v, PyObject *name) |
|
72
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3900 { |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3901 PyObject *x; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3902 |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3903 x = PyObject_GetAttr(v, name); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3904 if (x == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) { |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
3905 PyErr_Format(PyExc_ImportError, |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
3906 "cannot import name %.230s", |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
3907 PyString_AsString(name)); |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3908 } |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
3909 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
|
3910 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3911 |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
3912 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
|
3913 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
|
3914 { |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3915 PyObject *all = PyObject_GetAttrString(v, "__all__"); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3916 PyObject *dict, *name, *value; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3917 int skip_leading_underscores = 0; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3918 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
|
3919 |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3920 if (all == NULL) { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3921 if (!PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3922 return -1; /* Unexpected error */ |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3923 PyErr_Clear(); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3924 dict = PyObject_GetAttrString(v, "__dict__"); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3925 if (dict == NULL) { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3926 if (!PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3927 return -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3928 PyErr_SetString(PyExc_ImportError, |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3929 "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
|
3930 return -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3931 } |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3932 all = PyMapping_Keys(dict); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3933 Py_DECREF(dict); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3934 if (all == NULL) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3935 return -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3936 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
|
3937 } |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
3938 |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3939 for (pos = 0, err = 0; ; pos++) { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3940 name = PySequence_GetItem(all, pos); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3941 if (name == NULL) { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3942 if (!PyErr_ExceptionMatches(PyExc_IndexError)) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3943 err = -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3944 else |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3945 PyErr_Clear(); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3946 break; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3947 } |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3948 if (skip_leading_underscores && |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3949 PyString_Check(name) && |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3950 PyString_AS_STRING(name)[0] == '_') |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3951 { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3952 Py_DECREF(name); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3953 continue; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3954 } |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3955 value = PyObject_GetAttr(v, name); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3956 if (value == NULL) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3957 err = -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3958 else |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3959 err = PyDict_SetItem(locals, name, value); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3960 Py_DECREF(name); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3961 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
|
3962 if (err != 0) |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3963 break; |
|
72
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3964 } |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3965 Py_DECREF(all); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3966 return err; |
|
72
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3967 } |
|
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3968 |
| 5368 | 3969 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3970 build_class(PyObject *methods, PyObject *bases, PyObject *name) |
|
72
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3971 { |
|
19890
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3972 PyObject *metaclass = NULL, *result, *base; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3973 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3974 if (PyDict_Check(methods)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3975 metaclass = PyDict_GetItemString(methods, "__metaclass__"); |
|
19890
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3976 if (metaclass != NULL) |
|
21252
e386f6e26a42
Fix a typo (probably caused by autocompletion <blush>) that caused a
Guido van Rossum <guido@python.org>
parents:
21251
diff
changeset
|
3977 Py_INCREF(metaclass); |
|
19890
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3978 else if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0) { |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3979 base = PyTuple_GET_ITEM(bases, 0); |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3980 metaclass = PyObject_GetAttrString(base, "__class__"); |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3981 if (metaclass == NULL) { |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3982 PyErr_Clear(); |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3983 metaclass = (PyObject *)base->ob_type; |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3984 Py_INCREF(metaclass); |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
3985 } |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
3986 } |
|
19890
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3987 else { |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3988 PyObject *g = PyEval_GetGlobals(); |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3989 if (g != NULL && PyDict_Check(g)) |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3990 metaclass = PyDict_GetItemString(g, "__metaclass__"); |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3991 if (metaclass == NULL) |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3992 metaclass = (PyObject *) &PyClass_Type; |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3993 Py_INCREF(metaclass); |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3994 } |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3995 result = PyObject_CallFunction(metaclass, "OOO", name, bases, methods); |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3996 Py_DECREF(metaclass); |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3997 return result; |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
3998 } |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
3999 |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4000 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4001 exec_statement(PyFrameObject *f, PyObject *prog, PyObject *globals, |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4002 PyObject *locals) |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4003 { |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4004 int n; |
| 5368 | 4005 PyObject *v; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4006 int plain = 0; |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4007 |
| 5368 | 4008 if (PyTuple_Check(prog) && globals == Py_None && locals == Py_None && |
| 4009 ((n = PyTuple_Size(prog)) == 2 || n == 3)) { | |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4010 /* Backward compatibility hack */ |
| 5368 | 4011 globals = PyTuple_GetItem(prog, 1); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4012 if (n == 3) |
| 5368 | 4013 locals = PyTuple_GetItem(prog, 2); |
| 4014 prog = PyTuple_GetItem(prog, 0); | |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4015 } |
| 5368 | 4016 if (globals == Py_None) { |
| 4017 globals = PyEval_GetGlobals(); | |
| 4018 if (locals == Py_None) { | |
| 4019 locals = PyEval_GetLocals(); | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4020 plain = 1; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4021 } |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4022 } |
| 5368 | 4023 else if (locals == Py_None) |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4024 locals = globals; |
| 5368 | 4025 if (!PyString_Check(prog) && |
|
14696
85038a024b19
This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents:
14375
diff
changeset
|
4026 !PyUnicode_Check(prog) && |
| 5368 | 4027 !PyCode_Check(prog) && |
| 4028 !PyFile_Check(prog)) { | |
| 4029 PyErr_SetString(PyExc_TypeError, | |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
4030 "exec: arg 1 must be a string, file, or code object"); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4031 return -1; |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4032 } |
| 15318 | 4033 if (!PyDict_Check(globals)) { |
| 5368 | 4034 PyErr_SetString(PyExc_TypeError, |
| 15318 | 4035 "exec: arg 2 must be a dictionary or None"); |
| 4036 return -1; | |
| 4037 } | |
| 4038 if (!PyDict_Check(locals)) { | |
| 4039 PyErr_SetString(PyExc_TypeError, | |
| 4040 "exec: arg 3 must be a dictionary or None"); | |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4041 return -1; |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4042 } |
| 5368 | 4043 if (PyDict_GetItemString(globals, "__builtins__") == NULL) |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
4044 PyDict_SetItemString(globals, "__builtins__", f->f_builtins); |
| 5368 | 4045 if (PyCode_Check(prog)) { |
|
21398
de125792bfaa
Fix for SF bug [ #492403 ] exec() segfaults on closure's func_code
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21270
diff
changeset
|
4046 if (PyCode_GetNumFree((PyCodeObject *)prog) > 0) { |
|
de125792bfaa
Fix for SF bug [ #492403 ] exec() segfaults on closure's func_code
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21270
diff
changeset
|
4047 PyErr_SetString(PyExc_TypeError, |
|
de125792bfaa
Fix for SF bug [ #492403 ] exec() segfaults on closure's func_code
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21270
diff
changeset
|
4048 "code object passed to exec may not contain free variables"); |
|
de125792bfaa
Fix for SF bug [ #492403 ] exec() segfaults on closure's func_code
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21270
diff
changeset
|
4049 return -1; |
|
de125792bfaa
Fix for SF bug [ #492403 ] exec() segfaults on closure's func_code
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21270
diff
changeset
|
4050 } |
|
11651
d88996e46cb2
Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents:
11468
diff
changeset
|
4051 v = PyEval_EvalCode((PyCodeObject *) prog, globals, locals); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4052 } |
|
11651
d88996e46cb2
Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents:
11468
diff
changeset
|
4053 else if (PyFile_Check(prog)) { |
| 5368 | 4054 FILE *fp = PyFile_AsFile(prog); |
| 4055 char *name = PyString_AsString(PyFile_Name(prog)); | |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
4056 PyCompilerFlags cf; |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
4057 cf.cf_flags = 0; |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
4058 if (PyEval_MergeCompilerFlags(&cf)) |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4059 v = PyRun_FileFlags(fp, name, Py_file_input, globals, |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4060 locals, &cf); |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
4061 else |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4062 v = PyRun_File(fp, name, Py_file_input, globals, |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4063 locals); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4064 } |
|
11651
d88996e46cb2
Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents:
11468
diff
changeset
|
4065 else { |
|
27781
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4066 PyObject *tmp = NULL; |
|
14696
85038a024b19
This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents:
14375
diff
changeset
|
4067 char *str; |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
4068 PyCompilerFlags cf; |
|
27781
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4069 cf.cf_flags = 0; |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4070 #ifdef Py_USING_UNICODE |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4071 if (PyUnicode_Check(prog)) { |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4072 tmp = PyUnicode_AsUTF8String(prog); |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4073 if (tmp == NULL) |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4074 return -1; |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4075 prog = tmp; |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4076 cf.cf_flags |= PyCF_SOURCE_IS_UTF8; |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4077 } |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4078 #endif |
|
14696
85038a024b19
This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents:
14375
diff
changeset
|
4079 if (PyString_AsStringAndSize(prog, &str, NULL)) |
|
11651
d88996e46cb2
Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents:
11468
diff
changeset
|
4080 return -1; |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
4081 if (PyEval_MergeCompilerFlags(&cf)) |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4082 v = PyRun_StringFlags(str, Py_file_input, globals, |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4083 locals, &cf); |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
4084 else |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4085 v = PyRun_String(str, Py_file_input, globals, locals); |
|
27781
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4086 Py_XDECREF(tmp); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4087 } |
|
11651
d88996e46cb2
Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents:
11468
diff
changeset
|
4088 if (plain) |
|
d88996e46cb2
Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents:
11468
diff
changeset
|
4089 PyFrame_LocalsToFast(f, 0); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4090 if (v == NULL) |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4091 return -1; |
| 5368 | 4092 Py_DECREF(v); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4093 return 0; |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
4094 } |
|
2338
4c2f1452125d
call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents:
2310
diff
changeset
|
4095 |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
4096 static void |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4097 format_exc_check_arg(PyObject *exc, char *format_str, PyObject *obj) |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4098 { |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4099 char *obj_str; |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4100 |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4101 if (!obj) |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4102 return; |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4103 |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4104 obj_str = PyString_AsString(obj); |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4105 if (!obj_str) |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4106 return; |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4107 |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4108 PyErr_Format(exc, format_str, obj_str); |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
4109 } |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4110 |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4111 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4112 |
|
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
|
4113 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4114 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
|
4115 { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4116 int i; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4117 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
|
4118 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
|
4119 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
|
4120 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
|
4121 if (x == NULL) { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4122 Py_DECREF(l); |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4123 return NULL; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4124 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4125 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
|
4126 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4127 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
|
4128 a[i] = 0; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4129 return l; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4130 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4131 |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4132 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
4133 _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
|
4134 { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4135 #ifndef DXPAIRS |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4136 return getarray(dxp); |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4137 #else |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4138 int i; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4139 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
|
4140 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
|
4141 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
|
4142 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
|
4143 if (x == NULL) { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4144 Py_DECREF(l); |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4145 return NULL; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4146 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4147 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
|
4148 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4149 return l; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4150 #endif |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4151 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4152 |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
4153 #endif |
