Mercurial > cpython-lru_cache-weakref
annotate Python/ceval.c @ 68235:61b0263d6881 2.2
Close 2.2 branch.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Sat, 05 Mar 2011 14:55:23 +0100 |
| parents | be99f5970688 |
| children |
| 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 |
|
13552
dd2b5218e069
Include macglue.h for some function prototypes, and renamed a few
Jack Jansen <jack.jansen@cwi.nl>
parents:
13447
diff
changeset
|
17 #ifdef macintosh |
|
dd2b5218e069
Include macglue.h for some function prototypes, and renamed a few
Jack Jansen <jack.jansen@cwi.nl>
parents:
13447
diff
changeset
|
18 #include "macglue.h" |
|
dd2b5218e069
Include macglue.h for some function prototypes, and renamed a few
Jack Jansen <jack.jansen@cwi.nl>
parents:
13447
diff
changeset
|
19 #endif |
|
dd2b5218e069
Include macglue.h for some function prototypes, and renamed a few
Jack Jansen <jack.jansen@cwi.nl>
parents:
13447
diff
changeset
|
20 |
|
1400
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
21 #include <ctype.h> |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
22 |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
23 /* 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
|
24 /* #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
|
25 |
|
4839
4567e158d20c
Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents:
4667
diff
changeset
|
26 #ifdef Py_DEBUG |
| 567 | 27 /* For debugging the interpreter: */ |
| 28 #define LLTRACE 1 /* Low-level trace feature */ | |
| 29 #define CHECKEXC 1 /* Double-check exception checking */ | |
| 69 | 30 #endif |
| 31 | |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
32 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
|
33 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
34 /* 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
|
35 static PyObject *eval_frame(PyFrameObject *); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
36 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
|
37 static PyObject *fast_cfunction(PyObject *, PyObject ***, int); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
38 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
|
39 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
|
40 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
|
41 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
|
42 static PyObject *load_args(PyObject ***, int); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
43 #define CALL_FLAG_VAR 1 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
44 #define CALL_FLAG_KW 2 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
45 |
|
746
6c0f16008bd9
lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents:
708
diff
changeset
|
46 #ifdef LLTRACE |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
47 static int prtrace(PyObject *, char *); |
|
746
6c0f16008bd9
lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents:
708
diff
changeset
|
48 #endif |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
49 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
|
50 int, PyObject *); |
|
20257
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
51 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
|
52 PyFrameObject *, int); |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
53 static void call_exc_trace(Py_tracefunc, PyObject *, PyFrameObject *); |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
54 static PyObject *loop_subscript(PyObject *, PyObject *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
55 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
|
56 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
|
57 PyObject *, PyObject *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
58 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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 PyObject *, PyObject *, PyObject *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
64 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
|
65 static void reset_exc_info(PyThreadState *); |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
66 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
|
67 |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
68 #define NAME_ERROR_MSG \ |
| 15318 | 69 "name '%.200s' is not defined" |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
70 #define GLOBAL_NAME_ERROR_MSG \ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
71 "global name '%.200s' is not defined" |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
72 #define UNBOUNDLOCAL_ERROR_MSG \ |
| 15318 | 73 "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
|
74 #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
|
75 "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
|
76 " in enclosing scope" |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
77 |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
78 /* Dynamic execution profile */ |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
79 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
80 #ifdef DXPAIRS |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
81 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
|
82 #define dxp dxpairs[256] |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
83 #else |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
84 static long dxp[256]; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
85 #endif |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
86 #endif |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
87 |
|
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
|
88 staticforward PyTypeObject gentype; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
89 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
90 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
|
91 PyObject_HEAD |
|
18288
6800bcce0455
Add "gi_" (generator-iterator) prefix to names of genobject members.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
92 /* 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
|
93 |
|
6800bcce0455
Add "gi_" (generator-iterator) prefix to names of genobject members.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
94 PyFrameObject *gi_frame; |
|
6800bcce0455
Add "gi_" (generator-iterator) prefix to names of genobject members.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
95 |
|
18293
0344e4ac70b0
gen_getattr: make the gi_running and gi_frame members discoverable (but
Tim Peters <tim.peters@gmail.com>
parents:
18288
diff
changeset
|
96 /* 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
|
97 int 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
|
98 } 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
|
99 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
100 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
|
101 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
|
102 { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
103 genobject *gen = PyObject_New(genobject, &gentype); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
104 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
|
105 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
|
106 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
|
107 } |
|
18288
6800bcce0455
Add "gi_" (generator-iterator) prefix to names of genobject members.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
108 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
|
109 gen->gi_running = 0; |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
110 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
|
111 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
112 |
|
18513
65afac84d4f7
GC for generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18374
diff
changeset
|
113 static int |
|
65afac84d4f7
GC for generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18374
diff
changeset
|
114 gen_traverse(genobject *gen, visitproc visit, void *arg) |
|
65afac84d4f7
GC for generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18374
diff
changeset
|
115 { |
|
65afac84d4f7
GC for generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18374
diff
changeset
|
116 return visit((PyObject *)gen->gi_frame, arg); |
|
65afac84d4f7
GC for generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18374
diff
changeset
|
117 } |
|
65afac84d4f7
GC for generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18374
diff
changeset
|
118 |
|
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
|
119 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
|
120 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
|
121 { |
|
18288
6800bcce0455
Add "gi_" (generator-iterator) prefix to names of genobject members.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
122 Py_DECREF(gen->gi_frame); |
|
18513
65afac84d4f7
GC for generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18374
diff
changeset
|
123 PyObject_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
|
124 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
125 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
126 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
|
127 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
|
128 { |
|
18194
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
129 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
|
130 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
|
131 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
|
132 |
|
18288
6800bcce0455
Add "gi_" (generator-iterator) prefix to names of genobject members.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
133 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
|
134 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
|
135 "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
|
136 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
|
137 } |
|
18237
f02605b8fdc1
PyFrameObject: rename f_stackbottom to f_stacktop, since it points to
Tim Peters <tim.peters@gmail.com>
parents:
18195
diff
changeset
|
138 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
|
139 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
|
140 |
|
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
141 /* 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
|
142 * 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
|
143 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
|
144 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
|
145 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
|
146 |
|
18288
6800bcce0455
Add "gi_" (generator-iterator) prefix to names of genobject members.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
147 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
|
148 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
|
149 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
|
150 |
|
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
151 /* 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
|
152 * 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
|
153 * 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
|
154 Py_XDECREF(f->f_back); |
|
18172
12d7d4db69f2
gen_iternext(): repair subtle refcount problem.
Tim Peters <tim.peters@gmail.com>
parents:
18171
diff
changeset
|
155 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
|
156 |
|
18243
47717e5667eb
Change the semantics of "return" in generators, as discussed on the
Tim Peters <tim.peters@gmail.com>
parents:
18239
diff
changeset
|
157 /* 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
|
158 * 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
|
159 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
|
160 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
|
161 result = NULL; |
|
47717e5667eb
Change the semantics of "return" in generators, as discussed on the
Tim Peters <tim.peters@gmail.com>
parents:
18239
diff
changeset
|
162 } |
|
47717e5667eb
Change the semantics of "return" in generators, as discussed on the
Tim Peters <tim.peters@gmail.com>
parents:
18239
diff
changeset
|
163 |
|
18194
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
164 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
|
165 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
166 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
167 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
168 gen_next(genobject *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 { |
|
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 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
|
171 |
|
18194
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
172 result = gen_iternext(gen); |
|
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
173 |
|
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
174 if (result == NULL && !PyErr_Occurred()) { |
|
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
|
175 PyErr_SetObject(PyExc_StopIteration, Py_None); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
176 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
|
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 |
|
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 return 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
|
180 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
181 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
182 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
|
183 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
|
184 { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
185 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
|
186 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
|
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 |
|
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 static struct PyMethodDef gen_methods[] = { |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
190 {"next", (PyCFunction)gen_next, METH_NOARGS, |
|
18293
0344e4ac70b0
gen_getattr: make the gi_running and gi_frame members discoverable (but
Tim Peters <tim.peters@gmail.com>
parents:
18288
diff
changeset
|
191 "next() -- get the next value, or raise StopIteration"}, |
|
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
|
192 {NULL, NULL} /* Sentinel */ |
|
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 }; |
|
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 |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19896
diff
changeset
|
195 static PyMemberDef gen_memberlist[] = { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
196 {"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
|
197 {"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
|
198 {NULL} /* Sentinel */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
199 }; |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
200 |
|
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 statichere PyTypeObject gentype = { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
202 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
|
203 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
|
204 "generator", /* tp_name */ |
|
24567
7ca46e08200d
Remove calls to 2.1 GC API (they are noops).
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
23786
diff
changeset
|
205 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
|
206 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
|
207 /* 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
|
208 (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
|
209 0, /* tp_print */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
210 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
|
211 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
|
212 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
|
213 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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 0, /* tp_str */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
220 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
|
221 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
|
222 0, /* tp_as_buffer */ |
|
24567
7ca46e08200d
Remove calls to 2.1 GC API (they are noops).
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
23786
diff
changeset
|
223 Py_TPFLAGS_DEFAULT, /* 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
|
224 0, /* tp_doc */ |
|
18513
65afac84d4f7
GC for generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18374
diff
changeset
|
225 (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
|
226 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
|
227 0, /* tp_richcompare */ |
|
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 0, /* tp_weaklistoffset */ |
|
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 (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
|
230 (iternextfunc)gen_iternext, /* tp_iternext */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
231 gen_methods, /* tp_methods */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
232 gen_memberlist, /* tp_members */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
233 0, /* tp_getset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
234 0, /* tp_base */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
235 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
|
236 }; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
237 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
238 |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
239 #ifdef WITH_THREAD |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
240 |
|
10530
d834ecdf8c26
Changes by Mark Hammond for Windows CE. Mostly of the form
Guido van Rossum <guido@python.org>
parents:
10363
diff
changeset
|
241 #ifndef DONT_HAVE_ERRNO_H |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
242 #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
|
243 #endif |
|
9203
07dae6fdae79
Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents:
9048
diff
changeset
|
244 #include "pythread.h" |
| 926 | 245 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
246 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
|
247 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
248 static PyThread_type_lock interpreter_lock = 0; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
249 static long main_thread = 0; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
250 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
251 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
252 PyEval_InitThreads(void) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
253 { |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
254 if (interpreter_lock) |
| 1179 | 255 return; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
256 _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
|
257 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
|
258 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
|
259 main_thread = PyThread_get_thread_ident(); |
| 926 | 260 } |
| 261 | |
|
5865
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
262 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
263 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
|
264 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
265 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
|
266 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
267 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
268 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
269 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
|
270 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
271 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
|
272 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
273 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
274 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
275 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
|
276 { |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
277 if (tstate == NULL) |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
278 Py_FatalError("PyEval_AcquireThread: NULL new 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
|
279 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
|
280 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
|
281 Py_FatalError( |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
282 "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
|
283 } |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
284 |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
285 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
286 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
|
287 { |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
288 if (tstate == NULL) |
|
9841bce37c4d
Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents:
5846
diff
changeset
|
289 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
|
290 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
|
291 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
|
292 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
|
293 } |
|
14225
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
294 |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
295 /* 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
|
296 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
|
297 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
|
298 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
|
299 |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
300 void |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
301 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
|
302 { |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
303 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
|
304 return; |
|
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14163
diff
changeset
|
305 /*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
|
306 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
|
307 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
|
308 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
|
309 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
|
310 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
|
311 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
|
312 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
313 #endif |
| 926 | 314 |
| 315 /* Functions save_thread and restore_thread are always defined so | |
| 316 dynamically loaded modules needn't be compiled separately for use | |
| 317 with and without threads: */ | |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
318 |
|
5846
852a1fa62a7c
PyEval_SaveThread() and PyEval_RestoreThread() now return/take a
Guido van Rossum <guido@python.org>
parents:
5829
diff
changeset
|
319 PyThreadState * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
320 PyEval_SaveThread(void) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
321 { |
|
6365
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
322 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
|
323 if (tstate == NULL) |
|
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
324 Py_FatalError("PyEval_SaveThread: NULL tstate"); |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
325 #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
|
326 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
|
327 PyThread_release_lock(interpreter_lock); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
328 #endif |
|
6365
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
329 return tstate; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
330 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
331 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
332 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
333 PyEval_RestoreThread(PyThreadState *tstate) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
334 { |
|
6365
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
335 if (tstate == NULL) |
|
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
336 Py_FatalError("PyEval_RestoreThread: NULL tstate"); |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
337 #ifdef WITH_THREAD |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
338 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
|
339 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
|
340 PyThread_acquire_lock(interpreter_lock, 1); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
341 errno = err; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
342 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
343 #endif |
|
6365
21b93d98926b
Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
344 PyThreadState_Swap(tstate); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
345 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
346 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
347 |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
348 /* 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
|
349 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
|
350 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
|
351 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
|
352 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
|
353 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
|
354 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
355 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
|
356 (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
|
357 an exception condition). |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
358 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
359 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
|
360 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
|
361 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
362 #ifdef WITH_THREAD |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
363 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
|
364 will execute them. |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
365 #endif |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
366 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
367 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
|
368 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
|
369 (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
|
370 (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
|
371 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
|
372 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
|
373 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
|
374 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
|
375 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
376 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
|
377 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
|
378 */ |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
379 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
380 #define NPENDINGCALLS 32 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
381 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
|
382 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
|
383 void *arg; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
384 } pendingcalls[NPENDINGCALLS]; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
385 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
|
386 static volatile int pendinglast = 0; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
387 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
|
388 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
389 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
|
390 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
|
391 { |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
392 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
|
393 int i, j; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
394 /* 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
|
395 /* 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
|
396 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
|
397 if (busy) |
|
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
398 return -1; |
|
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
399 busy = 1; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
400 i = pendinglast; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
401 j = (i + 1) % NPENDINGCALLS; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
402 if (j == pendingfirst) |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
403 return -1; /* Queue full */ |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
404 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
|
405 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
|
406 pendinglast = j; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
407 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
|
408 busy = 0; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
409 /* 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
|
410 return 0; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
411 } |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
412 |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
413 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
414 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
|
415 { |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
416 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
|
417 #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
|
418 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
|
419 return 0; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
420 #endif |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
421 if (busy) |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
422 return 0; |
|
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
423 busy = 1; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
424 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
|
425 for (;;) { |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
426 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
|
427 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
|
428 void *arg; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
429 i = pendingfirst; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
430 if (i == pendinglast) |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
431 break; /* Queue empty */ |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
432 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
|
433 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
|
434 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
|
435 if (func(arg) < 0) { |
|
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
436 busy = 0; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
437 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
|
438 return -1; |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
439 } |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
440 } |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1887
diff
changeset
|
441 busy = 0; |
|
1887
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
442 return 0; |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
443 } |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
444 |
|
e7c6a18381d9
* Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents:
1846
diff
changeset
|
445 |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
446 /* The interpreter's recursion limit */ |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
447 |
|
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
|
448 static int recursion_limit = 1000; |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
449 |
|
14348
6d0f64f7dedd
Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14333
diff
changeset
|
450 int |
|
6d0f64f7dedd
Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14333
diff
changeset
|
451 Py_GetRecursionLimit(void) |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
452 { |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
453 return recursion_limit; |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
454 } |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
455 |
|
14348
6d0f64f7dedd
Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14333
diff
changeset
|
456 void |
|
6d0f64f7dedd
Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14333
diff
changeset
|
457 Py_SetRecursionLimit(int new_limit) |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
458 { |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
459 recursion_limit = new_limit; |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
460 } |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
461 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
462 /* 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
|
463 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
464 enum why_code { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
465 WHY_NOT, /* No error */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
466 WHY_EXCEPTION, /* Exception occurred */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
467 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
|
468 WHY_RETURN, /* 'return' statement */ |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
469 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
|
470 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
|
471 WHY_YIELD /* 'yield' operator */ |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
472 }; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
473 |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
474 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
|
475 static int unpack_iterable(PyObject *, int, PyObject **); |
| 5018 | 476 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
477 |
| 5368 | 478 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
479 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
|
480 { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
481 return PyEval_EvalCodeEx(co, |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
482 globals, locals, |
| 5368 | 483 (PyObject **)NULL, 0, |
| 484 (PyObject **)NULL, 0, | |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
485 (PyObject **)NULL, 0, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
486 NULL); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
487 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
488 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
489 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
490 /* Interpreter main loop */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
491 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
492 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
|
493 eval_frame(PyFrameObject *f) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
494 { |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
495 #ifdef DXPAIRS |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
496 int lastopcode = 0; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
497 #endif |
|
21477
ccb26a118867
SF bug #494668: PUSH() should assert-fail on overflow.
Tim Peters <tim.peters@gmail.com>
parents:
21475
diff
changeset
|
498 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
|
499 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
|
500 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
|
501 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
|
502 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
|
503 register int err; /* Error status -- nonzero if error */ |
| 5368 | 504 register PyObject *x; /* Result object -- NULL if error */ |
| 505 register PyObject *v; /* Temporary objects popped off stack */ | |
| 506 register PyObject *w; | |
| 507 register PyObject *u; | |
| 508 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
|
509 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
|
510 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
|
511 PyObject *retval = NULL; /* Return value */ |
|
9671
1d40bc25703a
Use PyThreadState_GET() macro.
Guido van Rossum <guido@python.org>
parents:
9591
diff
changeset
|
512 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
|
513 PyCodeObject *co; |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
514 unsigned char *first_instr; |
| 567 | 515 #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
|
516 int lltrace; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
517 #endif |
|
4839
4567e158d20c
Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents:
4667
diff
changeset
|
518 #if defined(Py_DEBUG) || defined(LLTRACE) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
519 /* 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
|
520 char *filename; |
|
1016
a41e3ba5b47d
Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents:
974
diff
changeset
|
521 #endif |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
522 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
523 /* Code access macros */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
524 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
525 #define GETCONST(i) Getconst(f, i) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
526 #define GETNAME(i) Getname(f, i) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
527 #define GETNAMEV(i) Getnamev(f, i) |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
528 #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
|
529 #define NEXTOP() (*next_instr++) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
530 #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
|
531 #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
|
532 #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
|
533 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
534 /* Stack manipulation macros */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
535 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
536 #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
|
537 #define EMPTY() (STACK_LEVEL() == 0) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
538 #define TOP() (stack_pointer[-1]) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
539 #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
|
540 #define BASIC_POP() (*--stack_pointer) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
541 |
| 567 | 542 #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
|
543 #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
|
544 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
|
545 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
|
546 #define POP() ((void)(lltrace && prtrace(TOP(), "pop")), BASIC_POP()) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
547 #else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
548 #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
|
549 #define POP() BASIC_POP() |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
550 #endif |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
551 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
552 /* Local variable macros */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
553 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
554 #define GETLOCAL(i) (fastlocals[i]) |
| 22622 | 555 |
| 556 /* The SETLOCAL() macro must not DECREF the local variable in-place and | |
| 557 then store the new value; it must copy the old value to a temporary | |
| 558 value, then store the new value, and then DECREF the temporary value. | |
| 559 This is because it is possible that during the DECREF the frame is | |
| 560 accessed by other code (e.g. a __del__ method or gc.collect()) and the | |
| 561 variable would be pointing to already-freed memory. */ | |
| 562 #define SETLOCAL(i, value) do { PyObject *tmp = GETLOCAL(i); \ | |
| 563 GETLOCAL(i) = value; \ | |
| 564 Py_XDECREF(tmp); } while (0) | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
565 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
566 /* Start of code */ |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
567 |
|
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
|
568 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
|
569 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
|
570 |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
571 #ifdef USE_STACKCHECK |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
572 if (tstate->recursion_depth%10 == 0 && PyOS_CheckStack()) { |
| 5368 | 573 PyErr_SetString(PyExc_MemoryError, "Stack overflow"); |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
574 return NULL; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
575 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
576 #endif |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
577 |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
578 /* push frame */ |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
579 if (++tstate->recursion_depth > recursion_limit) { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
580 --tstate->recursion_depth; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
581 PyErr_SetString(PyExc_RuntimeError, |
| 15318 | 582 "maximum recursion depth exceeded"); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
583 tstate->frame = f->f_back; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
584 return NULL; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
585 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
586 |
|
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
|
587 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
|
588 |
|
19692
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
589 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
|
590 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
|
591 /* 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
|
592 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
|
593 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
|
594 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
|
595 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
|
596 (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
|
597 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
|
598 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
|
599 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
|
600 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
|
601 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
|
602 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
|
603 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
|
604 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
|
605 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
|
606 /* Trace function raised an error */ |
|
25533
75e5a2a71729
Fix for the recursion_level bug Armin Rigo reported in sf
Michael W. Hudson <mwh@python.net>
parents:
24567
diff
changeset
|
607 --tstate->recursion_depth; |
|
75e5a2a71729
Fix for the recursion_level bug Armin Rigo reported in sf
Michael W. Hudson <mwh@python.net>
parents:
24567
diff
changeset
|
608 tstate->frame = f->f_back; |
|
19692
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
609 return NULL; |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
610 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
611 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
612 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
|
613 /* 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
|
614 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
|
615 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
|
616 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
|
617 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
|
618 /* Profile function raised an error */ |
|
25533
75e5a2a71729
Fix for the recursion_level bug Armin Rigo reported in sf
Michael W. Hudson <mwh@python.net>
parents:
24567
diff
changeset
|
619 --tstate->recursion_depth; |
|
75e5a2a71729
Fix for the recursion_level bug Armin Rigo reported in sf
Michael W. Hudson <mwh@python.net>
parents:
24567
diff
changeset
|
620 tstate->frame = f->f_back; |
|
19692
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
621 return NULL; |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
622 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
623 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
624 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
625 |
|
25631
85062a12c24f
This is Armin Rigo's patch:
Michael W. Hudson <mwh@python.net>
parents:
25533
diff
changeset
|
626 co = f->f_code; |
|
85062a12c24f
This is Armin Rigo's patch:
Michael W. Hudson <mwh@python.net>
parents:
25533
diff
changeset
|
627 fastlocals = f->f_localsplus; |
|
85062a12c24f
This is Armin Rigo's patch:
Michael W. Hudson <mwh@python.net>
parents:
25533
diff
changeset
|
628 freevars = f->f_localsplus + f->f_nlocals; |
|
85062a12c24f
This is Armin Rigo's patch:
Michael W. Hudson <mwh@python.net>
parents:
25533
diff
changeset
|
629 _PyCode_GETCODEPTR(co, &first_instr); |
|
85062a12c24f
This is Armin Rigo's patch:
Michael W. Hudson <mwh@python.net>
parents:
25533
diff
changeset
|
630 next_instr = first_instr + f->f_lasti; |
|
85062a12c24f
This is Armin Rigo's patch:
Michael W. Hudson <mwh@python.net>
parents:
25533
diff
changeset
|
631 stack_pointer = f->f_stacktop; |
|
85062a12c24f
This is Armin Rigo's patch:
Michael W. Hudson <mwh@python.net>
parents:
25533
diff
changeset
|
632 assert(stack_pointer != NULL); |
|
85062a12c24f
This is Armin Rigo's patch:
Michael W. Hudson <mwh@python.net>
parents:
25533
diff
changeset
|
633 f->f_stacktop = NULL; /* remains NULL unless yield suspends frame */ |
|
85062a12c24f
This is Armin Rigo's patch:
Michael W. Hudson <mwh@python.net>
parents:
25533
diff
changeset
|
634 |
|
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
|
635 #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
|
636 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
|
637 #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
|
638 #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
|
639 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
|
640 #endif |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
641 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
642 why = WHY_NOT; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
643 err = 0; |
| 5368 | 644 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
|
645 w = NULL; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
646 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
647 for (;;) { |
|
21477
ccb26a118867
SF bug #494668: PUSH() should assert-fail on overflow.
Tim Peters <tim.peters@gmail.com>
parents:
21475
diff
changeset
|
648 assert(stack_pointer >= f->f_valuestack); /* else underflow */ |
|
ccb26a118867
SF bug #494668: PUSH() should assert-fail on overflow.
Tim Peters <tim.peters@gmail.com>
parents:
21475
diff
changeset
|
649 assert(STACK_LEVEL() <= f->f_stacksize); /* else overflow */ |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
650 /* 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
|
651 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
|
652 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
|
653 ``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
|
654 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
|
655 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
|
656 Py_MakePendingCalls() above. */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
657 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
658 if (things_to_do || --tstate->ticker < 0) { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
659 tstate->ticker = tstate->interp->checkinterval; |
|
25632
4ca32e4f7839
This is Armin Rigo's patch:
Michael W. Hudson <mwh@python.net>
parents:
25631
diff
changeset
|
660 tstate->tick_counter++; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
661 if (things_to_do) { |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
662 if (Py_MakePendingCalls() < 0) { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
663 why = WHY_EXCEPTION; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
664 goto on_error; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
665 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
666 } |
|
5551
34509c05266f
Logic for enabling mac-specific signal handling fixed (Jack)
Guido van Rossum <guido@python.org>
parents:
5492
diff
changeset
|
667 #if !defined(HAVE_SIGNAL_H) || defined(macintosh) |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
668 /* If we have true signals, the signal handler |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
669 will call Py_AddPendingCall() so we don't |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
670 have to call sigcheck(). On the Mac and |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
671 DOS, alas, we have to call it. */ |
| 5368 | 672 if (PyErr_CheckSignals()) { |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
673 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
674 goto on_error; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
675 } |
|
5021
c22add364351
Only call sigcheck() at the ticker code if we don't have true signals.
Guido van Rossum <guido@python.org>
parents:
5018
diff
changeset
|
676 #endif |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
677 |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
678 #ifdef WITH_THREAD |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
679 if (interpreter_lock) { |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
680 /* Give another thread a chance */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
681 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
682 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
|
683 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
|
684 PyThread_release_lock(interpreter_lock); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
685 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
686 /* Other threads may run now */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
687 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
688 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
|
689 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
|
690 Py_FatalError("ceval: orphan tstate"); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
691 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
692 #endif |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
693 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
694 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
695 /* Extract opcode and argument */ |
|
1016
a41e3ba5b47d
Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents:
974
diff
changeset
|
696 |
|
4839
4567e158d20c
Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents:
4667
diff
changeset
|
697 #if defined(Py_DEBUG) || defined(LLTRACE) |
|
1016
a41e3ba5b47d
Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents:
974
diff
changeset
|
698 f->f_lasti = INSTR_OFFSET(); |
|
a41e3ba5b47d
Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents:
974
diff
changeset
|
699 #endif |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
700 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
701 opcode = NEXTOP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
702 if (HAS_ARG(opcode)) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
703 oparg = NEXTARG(); |
|
14147
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
704 dispatch_opcode: |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
705 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
706 #ifdef DXPAIRS |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
707 dxpairs[lastopcode][opcode]++; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
708 lastopcode = opcode; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
709 #endif |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
710 dxp[opcode]++; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
711 #endif |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
712 |
| 567 | 713 #ifdef LLTRACE |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
714 /* Instruction tracing */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
715 |
| 567 | 716 if (lltrace) { |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
717 if (HAS_ARG(opcode)) { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
718 printf("%d: %d, %d\n", |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
719 (int) (INSTR_OFFSET() - 3), |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
720 opcode, oparg); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
721 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
722 else { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
723 printf("%d: %d\n", |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
724 (int) (INSTR_OFFSET() - 1), opcode); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
725 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
726 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
727 #endif |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
728 /* Main switch on opcode */ |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
729 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
730 switch (opcode) { |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
731 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
732 /* BEWARE! |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
733 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
|
734 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
|
735 and that no operation that succeeds does this! */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
736 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
737 /* case STOP_CODE: this is an error! */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
738 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
739 case POP_TOP: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
740 v = POP(); |
| 5368 | 741 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
|
742 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
743 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
744 case ROT_TWO: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
745 v = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
746 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
747 PUSH(v); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
748 PUSH(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
|
749 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
750 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
751 case ROT_THREE: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
752 v = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
753 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
754 x = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
755 PUSH(v); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
756 PUSH(x); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
757 PUSH(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
|
758 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
759 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
760 case ROT_FOUR: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
761 u = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
762 v = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
763 w = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
764 x = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
765 PUSH(u); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
766 PUSH(x); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
767 PUSH(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
768 PUSH(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
769 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
770 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
771 case DUP_TOP: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
772 v = TOP(); |
| 5368 | 773 Py_INCREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
774 PUSH(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
|
775 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
776 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
777 case DUP_TOPX: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
778 switch (oparg) { |
|
15151
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
779 case 1: |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
780 x = TOP(); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
781 Py_INCREF(x); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
782 PUSH(x); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
783 continue; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
784 case 2: |
|
15151
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
785 x = POP(); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
786 Py_INCREF(x); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
787 w = TOP(); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
788 Py_INCREF(w); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
789 PUSH(x); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
790 PUSH(w); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
791 PUSH(x); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
792 continue; |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
793 case 3: |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
794 x = POP(); |
|
15151
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
795 Py_INCREF(x); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
796 w = POP(); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
797 Py_INCREF(w); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
798 v = TOP(); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
799 Py_INCREF(v); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
800 PUSH(w); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
801 PUSH(x); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
802 PUSH(v); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
803 PUSH(w); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
804 PUSH(x); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
805 continue; |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
806 case 4: |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
807 x = POP(); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
808 Py_INCREF(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
809 w = POP(); |
|
15151
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
810 Py_INCREF(w); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
811 v = POP(); |
|
15151
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
812 Py_INCREF(v); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
813 u = TOP(); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
814 Py_INCREF(u); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
815 PUSH(v); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
816 PUSH(w); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
817 PUSH(x); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
818 PUSH(u); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
819 PUSH(v); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
820 PUSH(w); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
821 PUSH(x); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
822 continue; |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
823 case 5: |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
824 x = POP(); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
825 Py_INCREF(x); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
826 w = POP(); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
827 Py_INCREF(w); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
828 v = POP(); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
829 Py_INCREF(v); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
830 u = POP(); |
|
15151
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
831 Py_INCREF(u); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
832 t = TOP(); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
833 Py_INCREF(t); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
834 PUSH(u); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
835 PUSH(v); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
836 PUSH(w); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
837 PUSH(x); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
838 PUSH(t); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
839 PUSH(u); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
840 PUSH(v); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
841 PUSH(w); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
842 PUSH(x); |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
843 continue; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
844 default: |
|
15166
e61e64d1b5ec
Do a better job at staying on-screen :P (Sorry, it's late here.) I'm
Thomas Wouters <thomas@python.org>
parents:
15165
diff
changeset
|
845 Py_FatalError("invalid argument to DUP_TOPX" |
|
e61e64d1b5ec
Do a better job at staying on-screen :P (Sorry, it's late here.) I'm
Thomas Wouters <thomas@python.org>
parents:
15165
diff
changeset
|
846 " (bytecode corruption?)"); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
847 } |
|
15151
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
848 break; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
849 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
850 case UNARY_POSITIVE: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
851 v = POP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
852 x = PyNumber_Positive(v); |
| 5368 | 853 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
854 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
|
855 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
856 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
857 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
858 case UNARY_NEGATIVE: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
859 v = POP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
860 x = PyNumber_Negative(v); |
| 5368 | 861 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
862 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
|
863 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
864 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
865 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
866 case UNARY_NOT: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
867 v = POP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
868 err = PyObject_IsTrue(v); |
| 5368 | 869 Py_DECREF(v); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
870 if (err == 0) { |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
871 Py_INCREF(Py_True); |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
872 PUSH(Py_True); |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
873 continue; |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
874 } |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
875 else if (err > 0) { |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
876 Py_INCREF(Py_False); |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
877 PUSH(Py_False); |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
878 err = 0; |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
879 continue; |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
880 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
881 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
882 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
883 case UNARY_CONVERT: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
884 v = POP(); |
| 5368 | 885 x = PyObject_Repr(v); |
| 886 Py_DECREF(v); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
887 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
|
888 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
889 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
890 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
891 case UNARY_INVERT: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
892 v = POP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
893 x = PyNumber_Invert(v); |
| 5368 | 894 Py_DECREF(v); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
895 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
|
896 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
897 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
898 |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3294
diff
changeset
|
899 case BINARY_POWER: |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3294
diff
changeset
|
900 w = POP(); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3294
diff
changeset
|
901 v = POP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
902 x = PyNumber_Power(v, w, Py_None); |
| 5368 | 903 Py_DECREF(v); |
| 904 Py_DECREF(w); | |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3294
diff
changeset
|
905 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
|
906 if (x != NULL) continue; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3294
diff
changeset
|
907 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
908 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
909 case BINARY_MULTIPLY: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
910 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
911 v = POP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
912 x = PyNumber_Multiply(v, w); |
| 5368 | 913 Py_DECREF(v); |
| 914 Py_DECREF(w); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
915 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
|
916 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
917 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
918 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
919 case BINARY_DIVIDE: |
|
21251
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
920 if (!_Py_QnewFlag) { |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
921 w = POP(); |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
922 v = POP(); |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
923 x = PyNumber_Divide(v, w); |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
924 Py_DECREF(v); |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
925 Py_DECREF(w); |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
926 PUSH(x); |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
927 if (x != NULL) continue; |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
928 break; |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
929 } |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
930 /* -Qnew is in effect: fall through to |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
931 BINARY_TRUE_DIVIDE */ |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
932 case BINARY_TRUE_DIVIDE: |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
933 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
934 v = POP(); |
|
21251
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21171
diff
changeset
|
935 x = PyNumber_TrueDivide(v, w); |
| 5368 | 936 Py_DECREF(v); |
| 937 Py_DECREF(w); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
938 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
|
939 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
940 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
941 |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
942 case BINARY_FLOOR_DIVIDE: |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
943 w = POP(); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
944 v = POP(); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
945 x = PyNumber_FloorDivide(v, w); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
946 Py_DECREF(v); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
947 Py_DECREF(w); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
948 PUSH(x); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
949 if (x != NULL) continue; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
950 break; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
951 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
952 case BINARY_MODULO: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
953 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
954 v = POP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
955 x = PyNumber_Remainder(v, w); |
| 5368 | 956 Py_DECREF(v); |
| 957 Py_DECREF(w); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
958 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
|
959 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
960 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
961 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
962 case BINARY_ADD: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
963 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
964 v = POP(); |
|
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
|
965 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
|
966 /* INLINE: int + int */ |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
967 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
|
968 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
|
969 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
|
970 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
|
971 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
|
972 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
|
973 x = PyInt_FromLong(i); |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
974 } |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
975 else { |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
976 slow_add: |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
977 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
|
978 } |
| 5368 | 979 Py_DECREF(v); |
| 980 Py_DECREF(w); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
981 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
|
982 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
983 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
984 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
985 case BINARY_SUBTRACT: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
986 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
987 v = POP(); |
|
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
|
988 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
|
989 /* INLINE: int - int */ |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
990 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
|
991 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
|
992 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
|
993 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
|
994 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
|
995 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
|
996 x = PyInt_FromLong(i); |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
997 } |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
998 else { |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
999 slow_sub: |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1000 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
|
1001 } |
| 5368 | 1002 Py_DECREF(v); |
| 1003 Py_DECREF(w); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1004 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
|
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 BINARY_SUBSCR: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1009 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1010 v = POP(); |
|
20275
167e7f98b51f
Introduced the oddly-missing PyList_CheckExact(), and used it to replace
Tim Peters <tim.peters@gmail.com>
parents:
20273
diff
changeset
|
1011 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
|
1012 /* INLINE: list[int] */ |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1013 long i = PyInt_AsLong(w); |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1014 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
|
1015 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
|
1016 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
|
1017 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
|
1018 PyErr_SetString(PyExc_IndexError, |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1019 "list index out of range"); |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1020 x = NULL; |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1021 } |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1022 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
|
1023 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
|
1024 Py_INCREF(x); |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1025 } |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1026 } |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1027 else |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1028 x = PyObject_GetItem(v, w); |
| 5368 | 1029 Py_DECREF(v); |
| 1030 Py_DECREF(w); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1031 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
|
1032 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1033 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1034 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1035 case BINARY_LSHIFT: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1036 w = POP(); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1037 v = POP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1038 x = PyNumber_Lshift(v, w); |
| 5368 | 1039 Py_DECREF(v); |
| 1040 Py_DECREF(w); | |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1041 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
|
1042 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1043 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1044 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1045 case BINARY_RSHIFT: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1046 w = POP(); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1047 v = POP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1048 x = PyNumber_Rshift(v, w); |
| 5368 | 1049 Py_DECREF(v); |
| 1050 Py_DECREF(w); | |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1051 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
|
1052 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1053 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1054 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1055 case BINARY_AND: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1056 w = POP(); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1057 v = POP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1058 x = PyNumber_And(v, w); |
| 5368 | 1059 Py_DECREF(v); |
| 1060 Py_DECREF(w); | |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1061 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
|
1062 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1063 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1064 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1065 case BINARY_XOR: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1066 w = POP(); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1067 v = POP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1068 x = PyNumber_Xor(v, w); |
| 5368 | 1069 Py_DECREF(v); |
| 1070 Py_DECREF(w); | |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1071 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
|
1072 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1073 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1074 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1075 case BINARY_OR: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1076 w = POP(); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1077 v = POP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1078 x = PyNumber_Or(v, w); |
| 5368 | 1079 Py_DECREF(v); |
| 1080 Py_DECREF(w); | |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1081 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
|
1082 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1083 break; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1084 |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1085 case INPLACE_POWER: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1086 w = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1087 v = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1088 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
|
1089 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1090 Py_DECREF(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1091 PUSH(x); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1092 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1093 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1094 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1095 case INPLACE_MULTIPLY: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1096 w = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1097 v = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1098 x = PyNumber_InPlaceMultiply(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1099 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1100 Py_DECREF(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1101 PUSH(x); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1102 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1103 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1104 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1105 case INPLACE_DIVIDE: |
|
21578
b9371f3241b8
Backport tim_one's checkin of version 2.302:
Michael W. Hudson <mwh@python.net>
parents:
21477
diff
changeset
|
1106 if (!_Py_QnewFlag) { |
|
b9371f3241b8
Backport tim_one's checkin of version 2.302:
Michael W. Hudson <mwh@python.net>
parents:
21477
diff
changeset
|
1107 w = POP(); |
|
b9371f3241b8
Backport tim_one's checkin of version 2.302:
Michael W. Hudson <mwh@python.net>
parents:
21477
diff
changeset
|
1108 v = POP(); |
|
b9371f3241b8
Backport tim_one's checkin of version 2.302:
Michael W. Hudson <mwh@python.net>
parents:
21477
diff
changeset
|
1109 x = PyNumber_InPlaceDivide(v, w); |
|
b9371f3241b8
Backport tim_one's checkin of version 2.302:
Michael W. Hudson <mwh@python.net>
parents:
21477
diff
changeset
|
1110 Py_DECREF(v); |
|
b9371f3241b8
Backport tim_one's checkin of version 2.302:
Michael W. Hudson <mwh@python.net>
parents:
21477
diff
changeset
|
1111 Py_DECREF(w); |
|
b9371f3241b8
Backport tim_one's checkin of version 2.302:
Michael W. Hudson <mwh@python.net>
parents:
21477
diff
changeset
|
1112 PUSH(x); |
|
b9371f3241b8
Backport tim_one's checkin of version 2.302:
Michael W. Hudson <mwh@python.net>
parents:
21477
diff
changeset
|
1113 if (x != NULL) continue; |
|
b9371f3241b8
Backport tim_one's checkin of version 2.302:
Michael W. Hudson <mwh@python.net>
parents:
21477
diff
changeset
|
1114 break; |
|
b9371f3241b8
Backport tim_one's checkin of version 2.302:
Michael W. Hudson <mwh@python.net>
parents:
21477
diff
changeset
|
1115 } |
|
b9371f3241b8
Backport tim_one's checkin of version 2.302:
Michael W. Hudson <mwh@python.net>
parents:
21477
diff
changeset
|
1116 /* -Qnew is in effect: fall through to |
|
b9371f3241b8
Backport tim_one's checkin of version 2.302:
Michael W. Hudson <mwh@python.net>
parents:
21477
diff
changeset
|
1117 INPLACE_TRUE_DIVIDE */ |
|
b9371f3241b8
Backport tim_one's checkin of version 2.302:
Michael W. Hudson <mwh@python.net>
parents:
21477
diff
changeset
|
1118 case INPLACE_TRUE_DIVIDE: |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1119 w = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1120 v = POP(); |
|
21578
b9371f3241b8
Backport tim_one's checkin of version 2.302:
Michael W. Hudson <mwh@python.net>
parents:
21477
diff
changeset
|
1121 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
|
1122 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1123 Py_DECREF(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1124 PUSH(x); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1125 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1126 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1127 |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1128 case INPLACE_FLOOR_DIVIDE: |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1129 w = POP(); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1130 v = POP(); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1131 x = PyNumber_InPlaceFloorDivide(v, w); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1132 Py_DECREF(v); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1133 Py_DECREF(w); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1134 PUSH(x); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1135 if (x != NULL) continue; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1136 break; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1137 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1138 case INPLACE_MODULO: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1139 w = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1140 v = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1141 x = PyNumber_InPlaceRemainder(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1142 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1143 Py_DECREF(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1144 PUSH(x); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1145 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1146 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1147 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1148 case INPLACE_ADD: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1149 w = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1150 v = POP(); |
|
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
|
1151 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
|
1152 /* INLINE: int + int */ |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1153 register long a, b, i; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1154 a = PyInt_AS_LONG(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1155 b = PyInt_AS_LONG(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1156 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
|
1157 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
|
1158 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
|
1159 x = PyInt_FromLong(i); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1160 } |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1161 else { |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1162 slow_iadd: |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1163 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
|
1164 } |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1165 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1166 Py_DECREF(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1167 PUSH(x); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1168 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1169 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1170 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1171 case INPLACE_SUBTRACT: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1172 w = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1173 v = POP(); |
|
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
|
1174 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
|
1175 /* INLINE: int - int */ |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1176 register long a, b, i; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1177 a = PyInt_AS_LONG(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1178 b = PyInt_AS_LONG(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1179 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
|
1180 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
|
1181 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
|
1182 x = PyInt_FromLong(i); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1183 } |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1184 else { |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1185 slow_isub: |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1186 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
|
1187 } |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1188 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1189 Py_DECREF(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1190 PUSH(x); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1191 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1192 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1193 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1194 case INPLACE_LSHIFT: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1195 w = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1196 v = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1197 x = PyNumber_InPlaceLshift(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1198 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1199 Py_DECREF(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1200 PUSH(x); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1201 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1202 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1203 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1204 case INPLACE_RSHIFT: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1205 w = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1206 v = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1207 x = PyNumber_InPlaceRshift(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1208 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1209 Py_DECREF(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1210 PUSH(x); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1211 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1212 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1213 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1214 case INPLACE_AND: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1215 w = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1216 v = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1217 x = PyNumber_InPlaceAnd(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1218 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1219 Py_DECREF(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1220 PUSH(x); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1221 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1222 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1223 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1224 case INPLACE_XOR: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1225 w = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1226 v = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1227 x = PyNumber_InPlaceXor(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1228 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1229 Py_DECREF(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1230 PUSH(x); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1231 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1232 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1233 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1234 case INPLACE_OR: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1235 w = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1236 v = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1237 x = PyNumber_InPlaceOr(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1238 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1239 Py_DECREF(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1240 PUSH(x); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1241 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1242 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1243 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1244 case SLICE+0: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1245 case SLICE+1: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1246 case SLICE+2: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1247 case SLICE+3: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1248 if ((opcode-SLICE) & 2) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1249 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1250 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1251 w = NULL; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1252 if ((opcode-SLICE) & 1) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1253 v = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1254 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1255 v = NULL; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1256 u = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1257 x = apply_slice(u, v, w); |
| 5368 | 1258 Py_DECREF(u); |
| 1259 Py_XDECREF(v); | |
| 1260 Py_XDECREF(w); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1261 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
|
1262 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1263 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1264 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1265 case STORE_SLICE+0: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1266 case STORE_SLICE+1: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1267 case STORE_SLICE+2: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1268 case STORE_SLICE+3: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1269 if ((opcode-STORE_SLICE) & 2) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1270 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1271 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1272 w = NULL; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1273 if ((opcode-STORE_SLICE) & 1) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1274 v = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1275 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1276 v = NULL; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1277 u = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1278 t = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1279 err = assign_slice(u, v, w, t); /* u[v:w] = t */ |
| 5368 | 1280 Py_DECREF(t); |
| 1281 Py_DECREF(u); | |
| 1282 Py_XDECREF(v); | |
| 1283 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
|
1284 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1285 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1286 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1287 case DELETE_SLICE+0: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1288 case DELETE_SLICE+1: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1289 case DELETE_SLICE+2: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1290 case DELETE_SLICE+3: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1291 if ((opcode-DELETE_SLICE) & 2) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1292 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1293 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1294 w = NULL; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1295 if ((opcode-DELETE_SLICE) & 1) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1296 v = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1297 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1298 v = NULL; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1299 u = POP(); |
| 5368 | 1300 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
|
1301 /* del u[v:w] */ |
| 5368 | 1302 Py_DECREF(u); |
| 1303 Py_XDECREF(v); | |
| 1304 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
|
1305 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1306 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1307 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1308 case STORE_SUBSCR: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1309 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1310 v = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1311 u = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1312 /* v[w] = u */ |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1313 err = PyObject_SetItem(v, w, u); |
| 5368 | 1314 Py_DECREF(u); |
| 1315 Py_DECREF(v); | |
| 1316 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
|
1317 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1318 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1319 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1320 case DELETE_SUBSCR: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1321 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1322 v = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1323 /* del v[w] */ |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1324 err = PyObject_DelItem(v, w); |
| 5368 | 1325 Py_DECREF(v); |
| 1326 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
|
1327 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1328 break; |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1329 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1330 case PRINT_EXPR: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1331 v = POP(); |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1332 w = PySys_GetObject("displayhook"); |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1333 if (w == NULL) { |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1334 PyErr_SetString(PyExc_RuntimeError, |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1335 "lost sys.displayhook"); |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1336 err = -1; |
|
15814
faaf9f10d849
Fixed bugs noted by Greg Stein
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15811
diff
changeset
|
1337 x = NULL; |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1338 } |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1339 if (err == 0) { |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1340 x = Py_BuildValue("(O)", v); |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1341 if (x == NULL) |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1342 err = -1; |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1343 } |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1344 if (err == 0) { |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1345 w = PyEval_CallObject(w, x); |
|
15814
faaf9f10d849
Fixed bugs noted by Greg Stein
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15811
diff
changeset
|
1346 Py_XDECREF(w); |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1347 if (w == NULL) |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1348 err = -1; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1349 } |
| 5368 | 1350 Py_DECREF(v); |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1351 Py_XDECREF(x); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1352 break; |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1353 |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1354 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
|
1355 w = stream = POP(); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1356 /* 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
|
1357 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1358 case PRINT_ITEM: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1359 v = POP(); |
|
14238
74f7f237f739
eval_code2(): Guido provides this patch for his suggested elaboration
Barry Warsaw <barry@python.org>
parents:
14232
diff
changeset
|
1360 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
|
1361 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
|
1362 if (w == NULL) { |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1363 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
|
1364 "lost sys.stdout"); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1365 err = -1; |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1366 } |
|
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
|
1367 } |
| 29670 | 1368 /* PyFile_SoftSpace() can exececute arbitrary code |
| 1369 if sys.stdout is an instance with a __getattr__. | |
| 1370 If __getattr__ raises an exception, w will | |
| 1371 be freed, so we need to prevent that temporarily. */ | |
| 1372 Py_XINCREF(w); | |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1373 if (w != NULL && PyFile_SoftSpace(w, 1)) |
|
5606
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
1374 err = PyFile_WriteString(" ", w); |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
1375 if (err == 0) |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
1376 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
|
1377 if (err == 0) { |
|
1400
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1378 /* XXX move into writeobject() ? */ |
|
21027
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1379 if (PyString_Check(v)) { |
|
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1380 char *s = PyString_AS_STRING(v); |
|
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1381 int len = PyString_GET_SIZE(v); |
| 2310 | 1382 if (len > 0 && |
| 1383 isspace(Py_CHARMASK(s[len-1])) && | |
|
1400
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1384 s[len-1] != ' ') |
| 5368 | 1385 PyFile_SoftSpace(w, 0); |
|
21027
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1386 } |
|
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
|
1387 #ifdef Py_USING_UNICODE |
|
21027
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1388 else if (PyUnicode_Check(v)) { |
|
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1389 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
|
1390 int len = PyUnicode_GET_SIZE(v); |
|
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1391 if (len > 0 && |
|
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1392 Py_UNICODE_ISSPACE(s[len-1]) && |
|
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1393 s[len-1] != ' ') |
|
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1394 PyFile_SoftSpace(w, 0); |
|
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20915
diff
changeset
|
1395 } |
|
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
|
1396 #endif |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1397 } |
| 29670 | 1398 Py_XDECREF(w); |
| 5368 | 1399 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
|
1400 Py_XDECREF(stream); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1401 stream = NULL; |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1402 if (err == 0) |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1403 continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1404 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1405 |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1406 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
|
1407 w = stream = POP(); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1408 /* 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
|
1409 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1410 case PRINT_NEWLINE: |
|
14238
74f7f237f739
eval_code2(): Guido provides this patch for his suggested elaboration
Barry Warsaw <barry@python.org>
parents:
14232
diff
changeset
|
1411 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
|
1412 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
|
1413 if (w == NULL) |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1414 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
|
1415 "lost sys.stdout"); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1416 } |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1417 if (w != NULL) { |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1418 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
|
1419 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
|
1420 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
|
1421 } |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1422 Py_XDECREF(stream); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1423 stream = NULL; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1424 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1425 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1426 |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1427 #ifdef CASE_TOO_BIG |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1428 default: switch (opcode) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1429 #endif |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1430 case BREAK_LOOP: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1431 why = WHY_BREAK; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1432 break; |
|
17114
6fe13d008e25
Use PyObject_IsInstance() to check whether the first argument to an
Guido van Rossum <guido@python.org>
parents:
17104
diff
changeset
|
1433 |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
1434 case CONTINUE_LOOP: |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
1435 retval = PyInt_FromLong(oparg); |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
1436 why = WHY_CONTINUE; |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
1437 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
|
1438 |
|
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
|
1439 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
|
1440 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
|
1441 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
|
1442 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
|
1443 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
|
1444 /* 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
|
1445 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
|
1446 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
|
1447 /* 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
|
1448 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
|
1449 w = POP(); /* exc */ |
|
7946
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
1450 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
|
1451 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
|
1452 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
|
1453 default: |
| 5368 | 1454 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
|
1455 "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
|
1456 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
|
1457 break; |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1458 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1459 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1460 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1461 case LOAD_LOCALS: |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1462 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
|
1463 PyErr_SetString(PyExc_SystemError, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1464 "no locals"); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1465 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1466 } |
| 5368 | 1467 Py_INCREF(x); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1468 PUSH(x); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1469 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1470 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1471 case RETURN_VALUE: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1472 retval = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1473 why = WHY_RETURN; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1474 break; |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1475 |
|
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
|
1476 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
|
1477 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
|
1478 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
|
1479 f->f_lasti = INSTR_OFFSET(); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
1480 why = WHY_YIELD; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
1481 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
|
1482 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
1483 |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1484 case EXEC_STMT: |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1485 w = POP(); |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1486 v = POP(); |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1487 u = POP(); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1488 err = exec_statement(f, u, v, w); |
| 5368 | 1489 Py_DECREF(u); |
| 1490 Py_DECREF(v); | |
| 1491 Py_DECREF(w); | |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1492 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1493 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1494 case POP_BLOCK: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1495 { |
| 5368 | 1496 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
|
1497 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
|
1498 v = POP(); |
| 5368 | 1499 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1500 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1501 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1502 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1503 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1504 case END_FINALLY: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1505 v = POP(); |
| 5368 | 1506 if (PyInt_Check(v)) { |
| 1507 why = (enum why_code) PyInt_AsLong(v); | |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
1508 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
|
1509 why == WHY_YIELD || |
| 23786 | 1510 why == WHY_CONTINUE) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1511 retval = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1512 } |
| 5368 | 1513 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
|
1514 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
|
1515 u = POP(); |
| 5368 | 1516 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
|
1517 why = WHY_RERAISE; |
|
2872
d3b07ba3e12d
fix bogus DECREF in finally clause
Guido van Rossum <guido@python.org>
parents:
2866
diff
changeset
|
1518 break; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1519 } |
| 5368 | 1520 else if (v != Py_None) { |
| 1521 PyErr_SetString(PyExc_SystemError, | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1522 "'finally' pops bad exception"); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1523 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1524 } |
| 5368 | 1525 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1526 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1527 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1528 case BUILD_CLASS: |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
1529 u = POP(); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1530 v = POP(); |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
1531 w = POP(); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
1532 x = build_class(u, v, w); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1533 PUSH(x); |
| 5368 | 1534 Py_DECREF(u); |
| 1535 Py_DECREF(v); | |
| 1536 Py_DECREF(w); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1537 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1538 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1539 case STORE_NAME: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1540 w = GETNAMEV(oparg); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1541 v = POP(); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1542 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
|
1543 PyErr_Format(PyExc_SystemError, |
|
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15948
diff
changeset
|
1544 "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
|
1545 PyObject_REPR(w)); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1546 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1547 } |
| 5368 | 1548 err = PyDict_SetItem(x, w, v); |
| 1549 Py_DECREF(v); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1550 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1551 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1552 case DELETE_NAME: |
|
334
449f5e5d9af6
Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents:
314
diff
changeset
|
1553 w = GETNAMEV(oparg); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1554 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
|
1555 PyErr_Format(PyExc_SystemError, |
|
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15948
diff
changeset
|
1556 "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
|
1557 PyObject_REPR(w)); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1558 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1559 } |
| 5368 | 1560 if ((err = PyDict_DelItem(x, w)) != 0) |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1561 format_exc_check_arg(PyExc_NameError, |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1562 NAME_ERROR_MSG ,w); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1563 break; |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
1564 |
|
13930
4eaa463c031a
Merge UNPACK_LIST and UNPACK_TUPLE into a single UNPACK_SEQUENCE, since they
Thomas Wouters <thomas@python.org>
parents:
13881
diff
changeset
|
1565 case UNPACK_SEQUENCE: |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1566 v = POP(); |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1567 if (PyTuple_Check(v)) { |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1568 if (PyTuple_Size(v) != oparg) { |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1569 PyErr_SetString(PyExc_ValueError, |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1570 "unpack tuple of wrong size"); |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1571 why = WHY_EXCEPTION; |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1572 } |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1573 else { |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1574 for (; --oparg >= 0; ) { |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1575 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
|
1576 Py_INCREF(w); |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1577 PUSH(w); |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1578 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1579 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1580 } |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1581 else if (PyList_Check(v)) { |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1582 if (PyList_Size(v) != oparg) { |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1583 PyErr_SetString(PyExc_ValueError, |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1584 "unpack list of wrong size"); |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1585 why = WHY_EXCEPTION; |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1586 } |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1587 else { |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1588 for (; --oparg >= 0; ) { |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1589 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
|
1590 Py_INCREF(w); |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1591 PUSH(w); |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1592 } |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1593 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1594 } |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
1595 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
|
1596 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
|
1597 stack_pointer += oparg; |
|
20183
c6b6189a8397
SF bug [#466173] unpack TypeError unclear
Tim Peters <tim.peters@gmail.com>
parents:
20114
diff
changeset
|
1598 else { |
|
c6b6189a8397
SF bug [#466173] unpack TypeError unclear
Tim Peters <tim.peters@gmail.com>
parents:
20114
diff
changeset
|
1599 if (PyErr_ExceptionMatches(PyExc_TypeError)) |
|
c6b6189a8397
SF bug [#466173] unpack TypeError unclear
Tim Peters <tim.peters@gmail.com>
parents:
20114
diff
changeset
|
1600 PyErr_SetString(PyExc_TypeError, |
|
c6b6189a8397
SF bug [#466173] unpack TypeError unclear
Tim Peters <tim.peters@gmail.com>
parents:
20114
diff
changeset
|
1601 "unpack non-sequence"); |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1602 why = WHY_EXCEPTION; |
|
20183
c6b6189a8397
SF bug [#466173] unpack TypeError unclear
Tim Peters <tim.peters@gmail.com>
parents:
20114
diff
changeset
|
1603 } |
| 5368 | 1604 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1605 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1606 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1607 case STORE_ATTR: |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1608 w = GETNAMEV(oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1609 v = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1610 u = POP(); |
| 5368 | 1611 err = PyObject_SetAttr(v, w, u); /* v.w = u */ |
| 1612 Py_DECREF(v); | |
| 1613 Py_DECREF(u); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1614 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1615 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1616 case DELETE_ATTR: |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1617 w = GETNAMEV(oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1618 v = POP(); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1619 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
|
1620 /* del v.w */ |
| 5368 | 1621 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1622 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1623 |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1624 case STORE_GLOBAL: |
|
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1625 w = GETNAMEV(oparg); |
|
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1626 v = POP(); |
| 5368 | 1627 err = PyDict_SetItem(f->f_globals, w, v); |
| 1628 Py_DECREF(v); | |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1629 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1630 |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1631 case DELETE_GLOBAL: |
|
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1632 w = GETNAMEV(oparg); |
| 5368 | 1633 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
|
1634 format_exc_check_arg( |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1635 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
|
1636 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1637 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1638 case LOAD_CONST: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1639 x = GETCONST(oparg); |
| 5368 | 1640 Py_INCREF(x); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1641 PUSH(x); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1642 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1643 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1644 case LOAD_NAME: |
|
334
449f5e5d9af6
Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents:
314
diff
changeset
|
1645 w = GETNAMEV(oparg); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1646 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
|
1647 PyErr_Format(PyExc_SystemError, |
|
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15948
diff
changeset
|
1648 "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
|
1649 PyObject_REPR(w)); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1650 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1651 } |
| 5368 | 1652 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
|
1653 if (x == NULL) { |
| 5368 | 1654 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
|
1655 if (x == NULL) { |
| 5368 | 1656 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
|
1657 if (x == NULL) { |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1658 format_exc_check_arg( |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1659 PyExc_NameError, |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1660 NAME_ERROR_MSG ,w); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1661 break; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1662 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1663 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1664 } |
| 5368 | 1665 Py_INCREF(x); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1666 PUSH(x); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1667 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1668 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1669 case LOAD_GLOBAL: |
|
334
449f5e5d9af6
Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents:
314
diff
changeset
|
1670 w = GETNAMEV(oparg); |
| 5368 | 1671 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
|
1672 if (x == NULL) { |
| 5368 | 1673 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
|
1674 if (x == NULL) { |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1675 format_exc_check_arg( |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1676 PyExc_NameError, |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1677 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
|
1678 break; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1679 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1680 } |
| 5368 | 1681 Py_INCREF(x); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1682 PUSH(x); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1683 break; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1684 |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1685 case LOAD_FAST: |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1686 x = GETLOCAL(oparg); |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1687 if (x == NULL) { |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1688 format_exc_check_arg( |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1689 PyExc_UnboundLocalError, |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1690 UNBOUNDLOCAL_ERROR_MSG, |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1691 PyTuple_GetItem(co->co_varnames, oparg) |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1692 ); |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1693 break; |
|
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1694 } |
| 5368 | 1695 Py_INCREF(x); |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1696 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
|
1697 if (x != NULL) continue; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1698 break; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1699 |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1700 case STORE_FAST: |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
1701 v = POP(); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1702 SETLOCAL(oparg, 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
|
1703 continue; |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1704 |
|
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1705 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
|
1706 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
|
1707 if (x == NULL) { |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1708 format_exc_check_arg( |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1709 PyExc_UnboundLocalError, |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1710 UNBOUNDLOCAL_ERROR_MSG, |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1711 PyTuple_GetItem(co->co_varnames, oparg) |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1712 ); |
|
8318
ec87b62466d3
DELETE_FAST should issue an exception when the local variable is undefined.
Guido van Rossum <guido@python.org>
parents:
7982
diff
changeset
|
1713 break; |
|
ec87b62466d3
DELETE_FAST should issue an exception when the local variable is undefined.
Guido van Rossum <guido@python.org>
parents:
7982
diff
changeset
|
1714 } |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1715 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
|
1716 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1717 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1718 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
|
1719 x = freevars[oparg]; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1720 Py_INCREF(x); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1721 PUSH(x); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1722 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1723 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1724 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
|
1725 x = freevars[oparg]; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1726 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
|
1727 if (w == NULL) { |
|
17494
a34293ced63b
Change error message raised when free variable is not yet bound. It
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17490
diff
changeset
|
1728 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
|
1729 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
|
1730 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
|
1731 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
|
1732 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
|
1733 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
|
1734 v); |
|
a34293ced63b
Change error message raised when free variable is not yet bound. It
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17490
diff
changeset
|
1735 } else { |
|
16453
2e3dd62ceac5
SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16398
diff
changeset
|
1736 v = PyTuple_GetItem( |
|
2e3dd62ceac5
SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16398
diff
changeset
|
1737 co->co_freevars, |
|
2e3dd62ceac5
SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16398
diff
changeset
|
1738 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
|
1739 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
|
1740 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
|
1741 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
|
1742 v); |
|
a34293ced63b
Change error message raised when free variable is not yet bound. It
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17490
diff
changeset
|
1743 } |
|
16453
2e3dd62ceac5
SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16398
diff
changeset
|
1744 err = -1; |
|
2e3dd62ceac5
SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16398
diff
changeset
|
1745 break; |
|
2e3dd62ceac5
SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16398
diff
changeset
|
1746 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1747 PUSH(w); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1748 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1749 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1750 case STORE_DEREF: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1751 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
|
1752 x = freevars[oparg]; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1753 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
|
1754 Py_DECREF(w); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1755 continue; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1756 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1757 case BUILD_TUPLE: |
| 5368 | 1758 x = PyTuple_New(oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1759 if (x != NULL) { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1760 for (; --oparg >= 0;) { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1761 w = POP(); |
| 5368 | 1762 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
|
1763 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1764 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
|
1765 continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1766 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1767 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1768 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1769 case BUILD_LIST: |
| 5368 | 1770 x = PyList_New(oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1771 if (x != NULL) { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1772 for (; --oparg >= 0;) { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1773 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
|
1774 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
|
1775 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1776 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
|
1777 continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1778 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1779 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1780 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1781 case BUILD_MAP: |
| 5368 | 1782 x = PyDict_New(); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1783 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
|
1784 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
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_ATTR: |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1788 w = GETNAMEV(oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1789 v = POP(); |
| 5368 | 1790 x = PyObject_GetAttr(v, w); |
| 1791 Py_DECREF(v); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1792 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
|
1793 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1794 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1795 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1796 case COMPARE_OP: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1797 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1798 v = POP(); |
|
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
|
1799 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
|
1800 /* INLINE: cmp(int, int) */ |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1801 register long a, b; |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1802 register int res; |
|
9591
7f90736701a3
Use PyInt_AS_LONG macro instead of explicit inlining.
Guido van Rossum <guido@python.org>
parents:
9513
diff
changeset
|
1803 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
|
1804 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
|
1805 switch (oparg) { |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1806 case LT: res = a < b; break; |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1807 case LE: res = a <= b; break; |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1808 case EQ: res = a == b; break; |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1809 case NE: res = a != b; break; |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1810 case GT: res = a > b; break; |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1811 case GE: res = a >= b; break; |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1812 case IS: res = v == w; break; |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1813 case IS_NOT: res = v != w; break; |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1814 default: goto slow_compare; |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1815 } |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1816 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
|
1817 Py_INCREF(x); |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1818 } |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1819 else { |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1820 slow_compare: |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1821 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
|
1822 } |
| 5368 | 1823 Py_DECREF(v); |
| 1824 Py_DECREF(w); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1825 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
|
1826 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1827 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1828 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1829 case IMPORT_NAME: |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
1830 w = GETNAMEV(oparg); |
| 5368 | 1831 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
|
1832 if (x == NULL) { |
| 5368 | 1833 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
|
1834 "__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
|
1835 break; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
1836 } |
|
14232
1f1a156ed5af
Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents:
14225
diff
changeset
|
1837 u = POP(); |
| 5368 | 1838 w = Py_BuildValue("(OOOO)", |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1839 w, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1840 f->f_globals, |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1841 f->f_locals == NULL ? |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1842 Py_None : f->f_locals, |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1843 u); |
| 5368 | 1844 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
|
1845 if (w == NULL) { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
1846 x = NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
1847 break; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
1848 } |
| 5368 | 1849 x = PyEval_CallObject(x, w); |
| 1850 Py_DECREF(w); | |
|
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
|
1851 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
|
1852 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1853 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1854 |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
1855 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
|
1856 v = POP(); |
| 5368 | 1857 PyFrame_FastToLocals(f); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1858 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
|
1859 PyErr_SetString(PyExc_SystemError, |
|
16017
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15948
diff
changeset
|
1860 "no locals found during 'import *'"); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1861 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1862 } |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
1863 err = import_all_from(x, v); |
| 5368 | 1864 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
|
1865 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
|
1866 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1867 break; |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
1868 |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
1869 case IMPORT_FROM: |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
1870 w = GETNAMEV(oparg); |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
1871 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
|
1872 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
|
1873 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
|
1874 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
|
1875 break; |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
1876 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1877 case JUMP_FORWARD: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1878 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
|
1879 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1880 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1881 case JUMP_IF_FALSE: |
| 5368 | 1882 err = PyObject_IsTrue(TOP()); |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
1883 if (err > 0) |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
1884 err = 0; |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
1885 else if (err == 0) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1886 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
|
1887 else |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1888 break; |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1889 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1890 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1891 case JUMP_IF_TRUE: |
| 5368 | 1892 err = PyObject_IsTrue(TOP()); |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
1893 if (err > 0) { |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
1894 err = 0; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1895 JUMPBY(oparg); |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
1896 } |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1897 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
|
1898 ; |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1899 else |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1900 break; |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1901 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1902 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1903 case JUMP_ABSOLUTE: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1904 JUMPTO(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
|
1905 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1906 |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1907 case GET_ITER: |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1908 /* before: [obj]; after [getiter(obj)] */ |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1909 v = POP(); |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1910 x = PyObject_GetIter(v); |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1911 Py_DECREF(v); |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1912 if (x != NULL) { |
|
17617
aac65f50df6f
Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents:
17600
diff
changeset
|
1913 PUSH(x); |
|
aac65f50df6f
Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents:
17600
diff
changeset
|
1914 continue; |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1915 } |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1916 break; |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1917 |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1918 case FOR_ITER: |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1919 /* before: [iter]; after: [iter, iter()] *or* [] */ |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1920 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
|
1921 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
|
1922 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
|
1923 PUSH(x); |
|
aac65f50df6f
Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents:
17600
diff
changeset
|
1924 continue; |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1925 } |
|
17683
e9a4e27e8d4e
Make PyIter_Next() a little smarter (wrt its knowledge of iterator
Tim Peters <tim.peters@gmail.com>
parents:
17636
diff
changeset
|
1926 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
|
1927 /* 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
|
1928 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
|
1929 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
|
1930 JUMPBY(oparg); |
|
aac65f50df6f
Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents:
17600
diff
changeset
|
1931 continue; |
|
aac65f50df6f
Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents:
17600
diff
changeset
|
1932 } |
|
aac65f50df6f
Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents:
17600
diff
changeset
|
1933 break; |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1934 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1935 case FOR_LOOP: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1936 /* for v in s: ... |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1937 On entry: stack contains s, i. |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1938 On exit: stack contains s, i+1, s[i]; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1939 but if loop exhausted: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1940 s, i are popped, and we jump */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1941 w = POP(); /* Loop index */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1942 v = POP(); /* Sequence object */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1943 u = loop_subscript(v, w); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1944 if (u != NULL) { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1945 PUSH(v); |
| 5368 | 1946 x = PyInt_FromLong(PyInt_AsLong(w)+1); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1947 PUSH(x); |
| 5368 | 1948 Py_DECREF(w); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1949 PUSH(u); |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1950 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1951 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1952 else { |
| 5368 | 1953 Py_DECREF(v); |
| 1954 Py_DECREF(w); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1955 /* A NULL can mean "s exhausted" |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1956 but also an error: */ |
| 5368 | 1957 if (PyErr_Occurred()) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1958 why = WHY_EXCEPTION; |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1959 else { |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1960 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
|
1961 continue; |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1962 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1963 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1964 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1965 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1966 case SETUP_LOOP: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1967 case SETUP_EXCEPT: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1968 case SETUP_FINALLY: |
| 5368 | 1969 PyFrame_BlockSetup(f, opcode, INSTR_OFFSET() + oparg, |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
1970 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
|
1971 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1972 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1973 case SET_LINENO: |
| 567 | 1974 #ifdef LLTRACE |
| 1975 if (lltrace) | |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
1976 printf("--- %s:%d \n", filename, oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1977 #endif |
| 567 | 1978 f->f_lineno = oparg; |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
1979 if (tstate->c_tracefunc == NULL || tstate->tracing) |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1980 continue; |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1981 /* Trace each line of code reached */ |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1982 f->f_lasti = INSTR_OFFSET(); |
|
25631
85062a12c24f
This is Armin Rigo's patch:
Michael W. Hudson <mwh@python.net>
parents:
25533
diff
changeset
|
1983 f->f_stacktop = stack_pointer; |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
1984 /* Inline call_trace() for performance: */ |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
1985 tstate->tracing++; |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
1986 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
|
1987 err = (tstate->c_tracefunc)(tstate->c_traceobj, f, |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
1988 PyTrace_LINE, Py_None); |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
1989 tstate->use_tracing = (tstate->c_tracefunc |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
1990 || tstate->c_profilefunc); |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
1991 tstate->tracing--; |
|
25631
85062a12c24f
This is Armin Rigo's patch:
Michael W. Hudson <mwh@python.net>
parents:
25533
diff
changeset
|
1992 /* Reload possibly changed frame fields */ |
|
85062a12c24f
This is Armin Rigo's patch:
Michael W. Hudson <mwh@python.net>
parents:
25533
diff
changeset
|
1993 JUMPTO(f->f_lasti); |
|
85062a12c24f
This is Armin Rigo's patch:
Michael W. Hudson <mwh@python.net>
parents:
25533
diff
changeset
|
1994 stack_pointer = f->f_stacktop; |
|
85062a12c24f
This is Armin Rigo's patch:
Michael W. Hudson <mwh@python.net>
parents:
25533
diff
changeset
|
1995 assert(stack_pointer != NULL); |
|
85062a12c24f
This is Armin Rigo's patch:
Michael W. Hudson <mwh@python.net>
parents:
25533
diff
changeset
|
1996 f->f_stacktop = NULL; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1997 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
|
1998 |
|
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
|
1999 case CALL_FUNCTION: |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2000 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2001 int na = oparg & 0xff; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2002 int nk = (oparg>>8) & 0xff; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2003 int n = na + 2 * nk; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2004 PyObject **pfunc = stack_pointer - n - 1; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2005 PyObject *func = *pfunc; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2006 f->f_lasti = INSTR_OFFSET() - 3; /* For tracing */ |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2007 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2008 /* Always dispatch PyCFunction first, because |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2009 these are presumed to be the most frequent |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2010 callable object. |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2011 */ |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2012 if (PyCFunction_Check(func)) { |
|
17855
d2d3f88661a3
Add a second special case to the inline function call code in eval_code2().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17683
diff
changeset
|
2013 int flags = PyCFunction_GET_FLAGS(func); |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
2014 if (nk != 0 || (flags & METH_KEYWORDS)) |
|
17991
0769e11d9d5f
Fix bug reported by Tim Peters on python-dev:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17855
diff
changeset
|
2015 x = do_call(func, &stack_pointer, |
|
0769e11d9d5f
Fix bug reported by Tim Peters on python-dev:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17855
diff
changeset
|
2016 na, nk); |
|
0769e11d9d5f
Fix bug reported by Tim Peters on python-dev:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17855
diff
changeset
|
2017 else if (flags == METH_VARARGS) { |
|
17855
d2d3f88661a3
Add a second special case to the inline function call code in eval_code2().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17683
diff
changeset
|
2018 PyObject *callargs; |
|
d2d3f88661a3
Add a second special case to the inline function call code in eval_code2().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17683
diff
changeset
|
2019 callargs = load_args(&stack_pointer, na); |
|
19198
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19158
diff
changeset
|
2020 x = PyCFunction_Call(func, callargs, NULL); |
|
17855
d2d3f88661a3
Add a second special case to the inline function call code in eval_code2().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17683
diff
changeset
|
2021 Py_XDECREF(callargs); |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
2022 } else |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
2023 x = fast_cfunction(func, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
2024 &stack_pointer, na); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2025 } else { |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2026 if (PyMethod_Check(func) |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2027 && PyMethod_GET_SELF(func) != NULL) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2028 /* optimize access to bound methods */ |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2029 PyObject *self = PyMethod_GET_SELF(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2030 Py_INCREF(self); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2031 func = PyMethod_GET_FUNCTION(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2032 Py_INCREF(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2033 Py_DECREF(*pfunc); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2034 *pfunc = self; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2035 na++; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2036 n++; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2037 } else |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2038 Py_INCREF(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2039 if (PyFunction_Check(func)) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2040 x = fast_function(func, &stack_pointer, |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2041 n, na, nk); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2042 } else { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2043 x = do_call(func, &stack_pointer, |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2044 na, nk); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2045 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2046 Py_DECREF(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2047 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2048 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2049 while (stack_pointer > pfunc) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2050 w = POP(); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2051 Py_DECREF(w); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2052 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2053 PUSH(x); |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2054 if (x != NULL) |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2055 continue; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2056 break; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2057 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2058 |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2059 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
|
2060 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
|
2061 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
|
2062 { |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2063 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
|
2064 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
|
2065 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
|
2066 int n = na + 2 * nk; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2067 PyObject **pfunc, *func; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2068 if (flags & CALL_FLAG_VAR) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2069 n++; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2070 if (flags & CALL_FLAG_KW) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2071 n++; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2072 pfunc = stack_pointer - n - 1; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2073 func = *pfunc; |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2074 f->f_lasti = INSTR_OFFSET() - 3; /* For tracing */ |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2075 |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2076 if (PyMethod_Check(func) |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2077 && PyMethod_GET_SELF(func) != NULL) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2078 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
|
2079 Py_INCREF(self); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2080 func = PyMethod_GET_FUNCTION(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2081 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
|
2082 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
|
2083 *pfunc = self; |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2084 na++; |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2085 n++; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2086 } else |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2087 Py_INCREF(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2088 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
|
2089 Py_DECREF(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2090 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2091 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
|
2092 w = POP(); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2093 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
|
2094 } |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2095 PUSH(x); |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2096 if (x != NULL) |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2097 continue; |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2098 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
|
2099 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2100 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2101 case MAKE_FUNCTION: |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2102 v = POP(); /* code object */ |
| 5368 | 2103 x = PyFunction_New(v, f->f_globals); |
| 2104 Py_DECREF(v); | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2105 /* XXX Maybe this should be a separate opcode? */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2106 if (x != NULL && oparg > 0) { |
| 5368 | 2107 v = PyTuple_New(oparg); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2108 if (v == NULL) { |
| 5368 | 2109 Py_DECREF(x); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2110 x = NULL; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2111 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2112 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2113 while (--oparg >= 0) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2114 w = POP(); |
| 5368 | 2115 PyTuple_SET_ITEM(v, oparg, w); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2116 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2117 err = PyFunction_SetDefaults(x, v); |
| 5368 | 2118 Py_DECREF(v); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2119 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2120 PUSH(x); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2121 break; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2122 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2123 case MAKE_CLOSURE: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2124 { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2125 int nfree; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2126 v = POP(); /* code object */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2127 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
|
2128 nfree = PyCode_GetNumFree((PyCodeObject *)v); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2129 Py_DECREF(v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2130 /* XXX Maybe this should be a separate opcode? */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2131 if (x != NULL && nfree > 0) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2132 v = PyTuple_New(nfree); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2133 if (v == NULL) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2134 Py_DECREF(x); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2135 x = NULL; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2136 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2137 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2138 while (--nfree >= 0) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2139 w = POP(); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2140 PyTuple_SET_ITEM(v, nfree, w); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2141 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2142 err = PyFunction_SetClosure(x, v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2143 Py_DECREF(v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2144 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2145 if (x != NULL && oparg > 0) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2146 v = PyTuple_New(oparg); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2147 if (v == NULL) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2148 Py_DECREF(x); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2149 x = NULL; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2150 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2151 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2152 while (--oparg >= 0) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2153 w = POP(); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2154 PyTuple_SET_ITEM(v, oparg, w); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2155 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2156 err = PyFunction_SetDefaults(x, v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2157 Py_DECREF(v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2158 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2159 PUSH(x); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2160 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2161 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2162 |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2163 case BUILD_SLICE: |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2164 if (oparg == 3) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2165 w = POP(); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2166 else |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2167 w = NULL; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2168 v = POP(); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2169 u = POP(); |
| 5018 | 2170 x = PySlice_New(u, v, w); |
| 5368 | 2171 Py_DECREF(u); |
| 2172 Py_DECREF(v); | |
| 2173 Py_XDECREF(w); | |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2174 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
|
2175 if (x != NULL) continue; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2176 break; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2177 |
|
14147
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
2178 case EXTENDED_ARG: |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
2179 opcode = NEXTOP(); |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
2180 oparg = oparg<<16 | NEXTARG(); |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
2181 goto dispatch_opcode; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2182 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2183 default: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2184 fprintf(stderr, |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2185 "XXX lineno: %d, opcode: %d\n", |
| 567 | 2186 f->f_lineno, opcode); |
| 5368 | 2187 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
|
2188 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2189 break; |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2190 |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2191 #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
|
2192 } |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2193 #endif |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2194 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2195 } /* switch */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2196 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2197 on_error: |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2198 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2199 /* Quickly continue if no error occurred */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2200 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2201 if (why == WHY_NOT) { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2202 if (err == 0 && x != NULL) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2203 #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
|
2204 /* This check is expensive! */ |
| 5368 | 2205 if (PyErr_Occurred()) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2206 fprintf(stderr, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2207 "XXX undetected error\n"); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2208 else |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2209 #endif |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2210 continue; /* Normal, fast path */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2211 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2212 why = WHY_EXCEPTION; |
| 5368 | 2213 x = Py_None; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2214 err = 0; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2215 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2216 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2217 /* Double-check exception status */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2218 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2219 if (why == WHY_EXCEPTION || why == WHY_RERAISE) { |
| 5368 | 2220 if (!PyErr_Occurred()) { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2221 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
|
2222 "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
|
2223 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2224 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2225 } |
|
10363
4daab7a9f566
Always test for an error return (usually NULL or -1) without setting
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
2226 #ifdef CHECKEXC |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2227 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
|
2228 /* This check is expensive! */ |
| 5368 | 2229 if (PyErr_Occurred()) { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2230 fprintf(stderr, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2231 "XXX undetected error (why=%d)\n", |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2232 why); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2233 why = WHY_EXCEPTION; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2234 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2235 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2236 #endif |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2237 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2238 /* 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
|
2239 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2240 if (why == WHY_EXCEPTION) { |
| 567 | 2241 f->f_lasti = INSTR_OFFSET() - 1; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2242 if (HAS_ARG(opcode)) |
| 567 | 2243 f->f_lasti -= 2; |
| 5368 | 2244 PyTraceBack_Here(f); |
| 567 | 2245 |
|
20247
a4d328d50897
Rationalize the events passed to the profiler (no changes for the tracer).
Fred Drake <fdrake@acm.org>
parents:
20183
diff
changeset
|
2246 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
|
2247 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
|
2248 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
|
2249 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2250 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2251 /* 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
|
2252 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2253 if (why == WHY_RERAISE) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2254 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2255 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2256 /* Unwind stacks if a (pseudo) exception occurred */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2257 |
|
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
|
2258 while (why != WHY_NOT && why != WHY_YIELD && f->f_iblock > 0) { |
| 5368 | 2259 PyTryBlock *b = PyFrame_BlockPop(f); |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2260 |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2261 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
|
2262 /* For a continue inside a try block, |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2263 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
|
2264 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
|
2265 b->b_level); |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2266 why = WHY_NOT; |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2267 JUMPTO(PyInt_AS_LONG(retval)); |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2268 Py_DECREF(retval); |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2269 break; |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2270 } |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2271 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2272 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
|
2273 v = POP(); |
| 5368 | 2274 Py_XDECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2275 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2276 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
|
2277 why = WHY_NOT; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2278 JUMPTO(b->b_handler); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2279 break; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2280 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2281 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
|
2282 (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
|
2283 why == WHY_EXCEPTION)) { |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2284 if (why == WHY_EXCEPTION) { |
| 5368 | 2285 PyObject *exc, *val, *tb; |
| 2286 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
|
2287 if (val == NULL) { |
| 5368 | 2288 val = Py_None; |
| 2289 Py_INCREF(val); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2290 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2291 /* Make the raw exception data |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2292 available to the handler, |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2293 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
|
2294 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
|
2295 this for 'finally'. */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2296 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
|
2297 PyErr_NormalizeException( |
|
32aacd753f34
eval_code2(), set_exc_info(): Call PyErr_NormalizeException() the
Barry Warsaw <barry@python.org>
parents:
6160
diff
changeset
|
2298 &exc, &val, &tb); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2299 set_exc_info(tstate, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2300 exc, val, tb); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2301 } |
|
20114
233f9606ba8e
Prevent a NULL pointer from being pushed onto the stack.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20064
diff
changeset
|
2302 if (tb == NULL) { |
|
233f9606ba8e
Prevent a NULL pointer from being pushed onto the stack.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20064
diff
changeset
|
2303 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
|
2304 PUSH(Py_None); |
|
233f9606ba8e
Prevent a NULL pointer from being pushed onto the stack.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20064
diff
changeset
|
2305 } else |
|
233f9606ba8e
Prevent a NULL pointer from being pushed onto the stack.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20064
diff
changeset
|
2306 PUSH(tb); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2307 PUSH(val); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2308 PUSH(exc); |
|
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 else { |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2311 if (why == WHY_RETURN || |
| 23786 | 2312 why == WHY_CONTINUE) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2313 PUSH(retval); |
| 5368 | 2314 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
|
2315 PUSH(v); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2316 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2317 why = WHY_NOT; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2318 JUMPTO(b->b_handler); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2319 break; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2320 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2321 } /* unwind stack */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2322 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2323 /* 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
|
2324 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2325 if (why != WHY_NOT) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2326 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2327 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2328 } /* main loop */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2329 |
|
21270
97709fd8fda0
Fix for SF bug #489671 (Neil Norwitz): memory leak in test_richcmp.
Guido van Rossum <guido@python.org>
parents:
21252
diff
changeset
|
2330 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
|
2331 /* 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
|
2332 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
|
2333 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
|
2334 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
|
2335 } |
|
97709fd8fda0
Fix for SF bug #489671 (Neil Norwitz): memory leak in test_richcmp.
Guido van Rossum <guido@python.org>
parents:
21252
diff
changeset
|
2336 } |
|
97709fd8fda0
Fix for SF bug #489671 (Neil Norwitz): memory leak in test_richcmp.
Guido van Rossum <guido@python.org>
parents:
21252
diff
changeset
|
2337 |
|
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
|
2338 if (why != WHY_RETURN && why != WHY_YIELD) |
| 567 | 2339 retval = NULL; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2340 |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2341 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
|
2342 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
|
2343 && (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
|
2344 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
|
2345 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
|
2346 PyTrace_RETURN, retval)) { |
| 5368 | 2347 Py_XDECREF(retval); |
| 567 | 2348 retval = NULL; |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
2349 why = WHY_EXCEPTION; |
| 567 | 2350 } |
| 2351 } | |
|
20247
a4d328d50897
Rationalize the events passed to the profiler (no changes for the tracer).
Fred Drake <fdrake@acm.org>
parents:
20183
diff
changeset
|
2352 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
|
2353 if (why == WHY_EXCEPTION) |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2354 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
|
2355 tstate->c_profileobj, f, |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2356 PyTrace_RETURN); |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2357 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
|
2358 tstate->c_profileobj, f, |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2359 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
|
2360 Py_XDECREF(retval); |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2361 retval = NULL; |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2362 why = WHY_EXCEPTION; |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2363 } |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
2364 } |
| 567 | 2365 } |
|
5023
75c1ee882a4a
Kill all local variables on function return. This closes a gigantic
Guido van Rossum <guido@python.org>
parents:
5021
diff
changeset
|
2366 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2367 reset_exc_info(tstate); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2368 |
|
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
|
2369 /* pop frame */ |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2370 --tstate->recursion_depth; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2371 tstate->frame = f->f_back; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2372 |
| 567 | 2373 return retval; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2374 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2375 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
2376 PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
2377 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
|
2378 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
|
2379 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
|
2380 { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2381 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
|
2382 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
|
2383 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
|
2384 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
|
2385 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
|
2386 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2387 if (globals == NULL) { |
|
19198
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19158
diff
changeset
|
2388 PyErr_SetString(PyExc_SystemError, |
|
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19158
diff
changeset
|
2389 "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
|
2390 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
|
2391 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2392 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2393 f = PyFrame_New(tstate, /*back*/ |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2394 co, /*code*/ |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2395 globals, locals); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2396 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
|
2397 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
|
2398 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2399 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
|
2400 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
|
2401 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2402 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
|
2403 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
|
2404 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
|
2405 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
|
2406 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
|
2407 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
|
2408 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
|
2409 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
|
2410 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
|
2411 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
|
2412 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
|
2413 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
|
2414 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
|
2415 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2416 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
|
2417 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
|
2418 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
|
2419 "%.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
|
2420 "%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
|
2421 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
|
2422 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
|
2423 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
|
2424 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
|
2425 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
|
2426 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
|
2427 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
|
2428 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2429 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
|
2430 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2431 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
|
2432 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
|
2433 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
|
2434 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
|
2435 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2436 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
|
2437 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
|
2438 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
|
2439 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
|
2440 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
|
2441 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
|
2442 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
|
2443 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
|
2444 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
|
2445 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2446 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2447 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
|
2448 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
|
2449 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
|
2450 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
|
2451 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
|
2452 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
|
2453 "%.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
|
2454 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
|
2455 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
|
2456 } |
|
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 /* 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
|
2458 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
|
2459 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
|
2460 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
|
2461 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
|
2462 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
|
2463 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
|
2464 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
|
2465 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
|
2466 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
|
2467 } |
|
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 /* 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
|
2469 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
|
2470 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
|
2471 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
|
2472 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
|
2473 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
|
2474 "%.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
|
2475 "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
|
2476 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
|
2477 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
|
2478 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
|
2479 } |
|
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 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
|
2481 } |
|
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 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
|
2483 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
|
2484 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
|
2485 "%.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
|
2486 "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
|
2487 "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
|
2488 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
|
2489 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
|
2490 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
|
2491 } |
|
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 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
|
2493 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
|
2494 } |
|
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 } |
|
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 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
|
2497 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
|
2498 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
|
2499 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
|
2500 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
|
2501 "%.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
|
2502 "%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
|
2503 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
|
2504 ((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
|
2505 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
|
2506 : "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
|
2507 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
|
2508 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
|
2509 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
|
2510 } |
|
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 } |
|
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 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
|
2513 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
|
2514 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
|
2515 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
|
2516 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
|
2517 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
|
2518 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
|
2519 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
|
2520 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
|
2521 } |
|
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 } |
|
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 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2524 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2525 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
|
2526 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
|
2527 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
|
2528 "%.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
|
2529 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
|
2530 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
|
2531 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
|
2532 } |
|
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 } |
|
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 /* 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
|
2535 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
|
2536 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
|
2537 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
|
2538 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
|
2539 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
|
2540 |
|
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 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
|
2542 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
|
2543 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
|
2544 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
|
2545 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
|
2546 |
|
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 /* 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
|
2548 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
|
2549 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
|
2550 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
|
2551 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
|
2552 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
|
2553 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
|
2554 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
|
2555 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
|
2556 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
|
2557 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
|
2558 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
|
2559 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
|
2560 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
|
2561 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
|
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 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
|
2564 } |
|
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 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
|
2566 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
|
2567 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
|
2568 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
|
2569 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
|
2570 } |
|
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 } |
|
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 /* 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
|
2573 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
|
2574 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
|
2575 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
|
2576 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
|
2577 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
|
2578 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
|
2579 } |
|
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 } |
|
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 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
|
2582 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
|
2583 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
|
2584 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
|
2585 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
|
2586 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
|
2587 } |
|
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 } |
|
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 |
|
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 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
|
2591 /* 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
|
2592 * 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
|
2593 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
|
2594 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
|
2595 |
|
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
2596 /* 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
|
2597 * 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
|
2598 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
|
2599 } |
|
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 |
|
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 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
|
2602 |
|
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 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
|
2604 |
|
21058
9df82c13c675
SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents:
21027
diff
changeset
|
2605 /* 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
|
2606 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
|
2607 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
|
2608 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
|
2609 */ |
|
9df82c13c675
SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents:
21027
diff
changeset
|
2610 assert(tstate != NULL); |
|
9df82c13c675
SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents:
21027
diff
changeset
|
2611 ++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
|
2612 Py_DECREF(f); |
|
21058
9df82c13c675
SF bug #483469: crash on unbounded recursion in __del__.
Tim Peters <tim.peters@gmail.com>
parents:
21027
diff
changeset
|
2613 --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
|
2614 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
|
2615 } |
|
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 |
|
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 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2618 static void |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2619 set_exc_info(PyThreadState *tstate, |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2620 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
|
2621 { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2622 PyFrameObject *frame; |
|
5557
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
2623 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
|
2624 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2625 frame = tstate->frame; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2626 if (frame->f_exc_type == NULL) { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2627 /* 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
|
2628 /* 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
|
2629 if (tstate->exc_type == NULL) { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2630 Py_INCREF(Py_None); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2631 tstate->exc_type = Py_None; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2632 } |
|
5557
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
2633 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
|
2634 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
|
2635 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
|
2636 Py_XINCREF(tstate->exc_type); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2637 Py_XINCREF(tstate->exc_value); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2638 Py_XINCREF(tstate->exc_traceback); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2639 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
|
2640 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
|
2641 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
|
2642 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
|
2643 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
|
2644 Py_XDECREF(tmp_tb); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2645 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2646 /* 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
|
2647 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
|
2648 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
|
2649 tmp_tb = tstate->exc_traceback; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2650 Py_XINCREF(type); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2651 Py_XINCREF(value); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2652 Py_XINCREF(tb); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2653 tstate->exc_type = type; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2654 tstate->exc_value = value; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2655 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
|
2656 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
|
2657 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
|
2658 Py_XDECREF(tmp_tb); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2659 /* For b/w compatibility */ |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2660 PySys_SetObject("exc_type", type); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2661 PySys_SetObject("exc_value", value); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2662 PySys_SetObject("exc_traceback", tb); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2663 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2664 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2665 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
2666 reset_exc_info(PyThreadState *tstate) |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2667 { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2668 PyFrameObject *frame; |
|
5557
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
2669 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
|
2670 frame = tstate->frame; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2671 if (frame->f_exc_type != NULL) { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2672 /* 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
|
2673 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
|
2674 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
|
2675 tmp_tb = tstate->exc_traceback; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2676 Py_XINCREF(frame->f_exc_type); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2677 Py_XINCREF(frame->f_exc_value); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2678 Py_XINCREF(frame->f_exc_traceback); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2679 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
|
2680 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
|
2681 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
|
2682 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
|
2683 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
|
2684 Py_XDECREF(tmp_tb); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2685 /* For b/w compatibility */ |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2686 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
|
2687 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
|
2688 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
|
2689 } |
|
5557
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
2690 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
|
2691 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
|
2692 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
|
2693 frame->f_exc_type = NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2694 frame->f_exc_value = NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2695 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
|
2696 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
|
2697 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
|
2698 Py_XDECREF(tmp_tb); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2699 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2700 |
|
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
|
2701 /* 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
|
2702 This *consumes* a reference count to each of its arguments. */ |
| 5018 | 2703 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
|
2704 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
|
2705 { |
|
7946
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2706 if (type == NULL) { |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2707 /* Reraise */ |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2708 PyThreadState *tstate = PyThreadState_Get(); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2709 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
|
2710 value = tstate->exc_value; |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2711 tb = tstate->exc_traceback; |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2712 Py_XINCREF(type); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2713 Py_XINCREF(value); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2714 Py_XINCREF(tb); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2715 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2716 |
|
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
|
2717 /* 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
|
2718 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
|
2719 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
|
2720 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
|
2721 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
|
2722 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
|
2723 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
|
2724 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
|
2725 |
|
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
|
2726 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
|
2727 |
|
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
|
2728 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
|
2729 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
|
2730 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
|
2731 |
|
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
|
2732 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
|
2733 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
|
2734 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
|
2735 |
|
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
|
2736 /* 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
|
2737 NULL. */ |
| 5368 | 2738 if (tb == Py_None) { |
| 2739 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
|
2740 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
|
2741 } |
|
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
|
2742 else if (tb != NULL && !PyTraceBack_Check(tb)) { |
| 5368 | 2743 PyErr_SetString(PyExc_TypeError, |
| 15318 | 2744 "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
|
2745 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
|
2746 } |
|
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
|
2747 |
|
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
|
2748 /* 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
|
2749 if (value == NULL) { |
| 5368 | 2750 value = Py_None; |
| 2751 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
|
2752 } |
|
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
|
2753 |
|
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
|
2754 /* Next, repeatedly, replace a tuple exception with its first item */ |
| 5368 | 2755 while (PyTuple_Check(type) && PyTuple_Size(type) > 0) { |
| 2756 PyObject *tmp = type; | |
| 2757 type = PyTuple_GET_ITEM(type, 0); | |
| 2758 Py_INCREF(type); | |
| 2759 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
|
2760 } |
|
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
|
2761 |
|
6147
b76a44163e0f
cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents:
6139
diff
changeset
|
2762 if (PyString_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
|
2763 ; |
|
6147
b76a44163e0f
cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents:
6139
diff
changeset
|
2764 |
|
b76a44163e0f
cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents:
6139
diff
changeset
|
2765 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
|
2766 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
|
2767 |
| 5368 | 2768 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
|
2769 /* Raising an instance. The value should be a dummy. */ |
| 5368 | 2770 if (value != Py_None) { |
| 2771 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
|
2772 "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
|
2773 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
|
2774 } |
|
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
|
2775 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
|
2776 /* Normalize to raise <class>, <instance> */ |
| 5368 | 2777 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
|
2778 value = type; |
| 5368 | 2779 type = (PyObject*) ((PyInstanceObject*)type)->in_class; |
| 2780 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
|
2781 } |
|
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
|
2782 } |
|
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
|
2783 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
|
2784 /* 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
|
2785 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
|
2786 PyErr_Format(PyExc_TypeError, |
|
9921a9d27f72
improved error message-- names the type of the unexpected object
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17617
diff
changeset
|
2787 "exceptions must be strings, classes, or " |
|
9921a9d27f72
improved error message-- names the type of the unexpected object
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17617
diff
changeset
|
2788 "instances, not %s", 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
|
2789 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
|
2790 } |
| 5368 | 2791 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
|
2792 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
|
2793 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
|
2794 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
|
2795 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
|
2796 raise_error: |
| 5368 | 2797 Py_XDECREF(value); |
| 2798 Py_XDECREF(type); | |
| 2799 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
|
2800 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
|
2801 } |
|
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
|
2802 |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2803 /* 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
|
2804 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
|
2805 |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2806 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
|
2807 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
|
2808 { |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2809 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
|
2810 PyObject *it; /* iter(v) */ |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2811 PyObject *w; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2812 |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2813 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
|
2814 |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2815 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
|
2816 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
|
2817 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
|
2818 |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2819 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
|
2820 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
|
2821 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
|
2822 /* 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
|
2823 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
|
2824 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
|
2825 "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
|
2826 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
|
2827 } |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2828 goto Error; |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2829 } |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2830 *--sp = w; |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2831 } |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2832 |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2833 /* 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
|
2834 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
|
2835 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
|
2836 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
|
2837 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
|
2838 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
|
2839 return 1; |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2840 } |
|
21170
2dfc600f99ce
unpack_iterable(): Add a missing DECREF in an error case. Reported by
Guido van Rossum <guido@python.org>
parents:
21058
diff
changeset
|
2841 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
|
2842 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
|
2843 /* 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
|
2844 Error: |
|
6160
79592761b331
unpack_sequence(): In finally clause, watch out for Py_DECREF
Barry Warsaw <barry@python.org>
parents:
6157
diff
changeset
|
2845 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
|
2846 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
|
2847 Py_XDECREF(it); |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2848 return 0; |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2849 } |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2850 |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2851 |
| 567 | 2852 #ifdef LLTRACE |
| 86 | 2853 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
2854 prtrace(PyObject *v, char *str) |
| 69 | 2855 { |
| 86 | 2856 printf("%s ", str); |
| 5368 | 2857 if (PyObject_Print(v, stdout, 0) != 0) |
| 2858 PyErr_Clear(); /* Don't know what else to do */ | |
| 86 | 2859 printf("\n"); |
|
12579
978253542076
Add useless 'return 1' to prtrace() to shut up VC++.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
2860 return 1; |
| 69 | 2861 } |
| 86 | 2862 #endif |
| 69 | 2863 |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
2864 static void |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2865 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
|
2866 { |
| 5368 | 2867 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
|
2868 int err; |
| 5368 | 2869 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
|
2870 if (value == NULL) { |
| 5368 | 2871 value = Py_None; |
| 2872 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
|
2873 } |
| 5368 | 2874 arg = Py_BuildValue("(OOO)", 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
|
2875 if (arg == NULL) { |
| 5368 | 2876 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
|
2877 return; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
2878 } |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2879 err = call_trace(func, self, f, PyTrace_EXCEPTION, arg); |
| 5368 | 2880 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
|
2881 if (err == 0) |
| 5368 | 2882 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
|
2883 else { |
| 5368 | 2884 Py_XDECREF(type); |
| 2885 Py_XDECREF(value); | |
| 2886 Py_XDECREF(traceback); | |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
2887 } |
|
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
2888 } |
|
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
2889 |
|
20257
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2890 static void |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2891 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
|
2892 int what) |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2893 { |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2894 PyObject *type, *value, *traceback; |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2895 int err; |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2896 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
|
2897 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
|
2898 if (err == 0) |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2899 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
|
2900 else { |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2901 Py_XDECREF(type); |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2902 Py_XDECREF(value); |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2903 Py_XDECREF(traceback); |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2904 } |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2905 } |
|
e3f63a95455f
Fix bug in profiler modifications detected only in debug builds.
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
2906 |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
2907 static int |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2908 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
|
2909 int what, PyObject *arg) |
| 567 | 2910 { |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2911 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
|
2912 int result; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2913 if (tstate->tracing) |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
2914 return 0; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2915 tstate->tracing++; |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2916 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
|
2917 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
|
2918 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
|
2919 || (tstate->c_profilefunc != NULL)); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2920 tstate->tracing--; |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2921 return result; |
| 567 | 2922 } |
| 2923 | |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2924 void |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2925 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
|
2926 { |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2927 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
|
2928 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
|
2929 Py_XINCREF(arg); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2930 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
|
2931 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
|
2932 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
|
2933 Py_XDECREF(temp); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2934 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
|
2935 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
|
2936 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
|
2937 } |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2938 |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2939 void |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2940 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
|
2941 { |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2942 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
|
2943 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
|
2944 Py_XINCREF(arg); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2945 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
|
2946 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
|
2947 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
|
2948 Py_XDECREF(temp); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2949 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
|
2950 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
|
2951 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
|
2952 || (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
|
2953 } |
|
4cb34314bd97
Instead of initializing & interning the strings passed to the profile
Fred Drake <fdrake@acm.org>
parents:
18128
diff
changeset
|
2954 |
| 5368 | 2955 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
2956 PyEval_GetBuiltins(void) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
2957 { |
|
25633
efa9a86464d3
This is Armin Rigo's patch:
Michael W. Hudson <mwh@python.net>
parents:
25632
diff
changeset
|
2958 PyFrameObject *current_frame = (PyFrameObject *)PyEval_GetFrame(); |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
2959 if (current_frame == NULL) |
|
25633
efa9a86464d3
This is Armin Rigo's patch:
Michael W. Hudson <mwh@python.net>
parents:
25632
diff
changeset
|
2960 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
|
2961 else |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
2962 return current_frame->f_builtins; |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
2963 } |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
2964 |
| 5368 | 2965 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
2966 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
|
2967 { |
|
25633
efa9a86464d3
This is Armin Rigo's patch:
Michael W. Hudson <mwh@python.net>
parents:
25632
diff
changeset
|
2968 PyFrameObject *current_frame = (PyFrameObject *)PyEval_GetFrame(); |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2969 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
|
2970 return NULL; |
| 5368 | 2971 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
|
2972 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
|
2973 } |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2974 |
| 5368 | 2975 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
2976 PyEval_GetGlobals(void) |
| 69 | 2977 { |
|
25633
efa9a86464d3
This is Armin Rigo's patch:
Michael W. Hudson <mwh@python.net>
parents:
25632
diff
changeset
|
2978 PyFrameObject *current_frame = (PyFrameObject *)PyEval_GetFrame(); |
| 86 | 2979 if (current_frame == NULL) |
| 2980 return NULL; | |
| 2981 else | |
| 2982 return current_frame->f_globals; | |
| 69 | 2983 } |
| 2984 | |
| 5368 | 2985 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
2986 PyEval_GetFrame(void) |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
2987 { |
|
25633
efa9a86464d3
This is Armin Rigo's patch:
Michael W. Hudson <mwh@python.net>
parents:
25632
diff
changeset
|
2988 PyThreadState *tstate = PyThreadState_Get(); |
|
efa9a86464d3
This is Armin Rigo's patch:
Michael W. Hudson <mwh@python.net>
parents:
25632
diff
changeset
|
2989 return _PyThreadState_GetFrame((PyObject *)tstate); |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
2990 } |
|
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
2991 |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
2992 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
2993 PyEval_GetRestricted(void) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
2994 { |
|
25633
efa9a86464d3
This is Armin Rigo's patch:
Michael W. Hudson <mwh@python.net>
parents:
25632
diff
changeset
|
2995 PyFrameObject *current_frame = (PyFrameObject *)PyEval_GetFrame(); |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
2996 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
|
2997 } |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
2998 |
|
5606
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
2999 int |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3000 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
|
3001 { |
|
25633
efa9a86464d3
This is Armin Rigo's patch:
Michael W. Hudson <mwh@python.net>
parents:
25632
diff
changeset
|
3002 PyFrameObject *current_frame = (PyFrameObject *)PyEval_GetFrame(); |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3003 int result = 0; |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3004 |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3005 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
|
3006 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
|
3007 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
|
3008 if (compilerflags) { |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3009 result = 1; |
|
19350
5b6a6d7d44ae
ceval, PyEval_MergeCompilerFlags: wasn't merging in the
Tim Peters <tim.peters@gmail.com>
parents:
19301
diff
changeset
|
3010 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
|
3011 } |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3012 } |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3013 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
|
3014 } |
|
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
|
3015 |
|
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
|
3016 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3017 Py_FlushLine(void) |
| 69 | 3018 { |
| 5368 | 3019 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
|
3020 if (f == NULL) |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
3021 return 0; |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
3022 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
|
3023 return 0; |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
3024 return PyFile_WriteString("\n", f); |
| 69 | 3025 } |
| 3026 | |
| 86 | 3027 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3028 /* External interface to call any callable object. |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3029 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
|
3030 |
|
6206
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
3031 #undef PyEval_CallObject |
|
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
3032 /* for backward compatibility: export this interface */ |
|
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
3033 |
| 5368 | 3034 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3035 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
|
3036 { |
| 5368 | 3037 return PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3038 } |
|
6206
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
3039 #define PyEval_CallObject(func,arg) \ |
|
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
3040 PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3041 |
| 5368 | 3042 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3043 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
|
3044 { |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3045 PyObject *result; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3046 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3047 if (arg == NULL) |
| 5368 | 3048 arg = PyTuple_New(0); |
| 3049 else if (!PyTuple_Check(arg)) { | |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3050 PyErr_SetString(PyExc_TypeError, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3051 "argument list must be a tuple"); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3052 return NULL; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3053 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3054 else |
| 5368 | 3055 Py_INCREF(arg); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3056 |
| 5368 | 3057 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
|
3058 PyErr_SetString(PyExc_TypeError, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3059 "keyword list must be a dictionary"); |
|
12440
d47460b1a679
Charles Waldman writes:
Guido van Rossum <guido@python.org>
parents:
12320
diff
changeset
|
3060 Py_DECREF(arg); |
|
2894
4095782c940e
empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents:
2872
diff
changeset
|
3061 return NULL; |
|
4095782c940e
empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents:
2872
diff
changeset
|
3062 } |
|
4095782c940e
empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents:
2872
diff
changeset
|
3063 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3064 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
|
3065 Py_DECREF(arg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3066 return result; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3067 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3068 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3069 char * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3070 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
|
3071 { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3072 if (PyMethod_Check(func)) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3073 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
|
3074 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
|
3075 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
|
3076 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
|
3077 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
|
3078 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
|
3079 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
|
3080 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
|
3081 return PyString_AsString( |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3082 ((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
|
3083 } else { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3084 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
|
3085 } |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3086 } |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3087 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3088 char * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3089 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
|
3090 { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3091 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
|
3092 return "()"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3093 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
|
3094 return "()"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3095 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
|
3096 return "()"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3097 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
|
3098 return " constructor"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3099 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
|
3100 return " instance"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3101 } else { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3102 return " object"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3103 } |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3104 } |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3105 |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3106 #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
|
3107 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3108 /* The two fast_xxx() functions optimize calls for which no argument |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3109 tuple is necessary; the objects are passed directly from the stack. |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3110 fast_cfunction() is called for METH_OLDARGS functions. |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3111 fast_function() is for functions with no special argument handling. |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3112 */ |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3113 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3114 static PyObject * |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3115 fast_cfunction(PyObject *func, PyObject ***pp_stack, int na) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3116 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3117 PyCFunction meth = PyCFunction_GET_FUNCTION(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3118 PyObject *self = PyCFunction_GET_SELF(func); |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3119 int flags = PyCFunction_GET_FLAGS(func); |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3120 |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3121 switch (flags) { |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3122 case METH_OLDARGS: |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3123 if (na == 0) |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3124 return (*meth)(self, NULL); |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3125 else if (na == 1) { |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3126 PyObject *arg = EXT_POP(*pp_stack); |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3127 PyObject *result = (*meth)(self, arg); |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3128 Py_DECREF(arg); |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3129 return result; |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3130 } else { |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3131 PyObject *args = load_args(pp_stack, na); |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3132 PyObject *result = (*meth)(self, args); |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3133 Py_DECREF(args); |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3134 return result; |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3135 } |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3136 case METH_NOARGS: |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3137 if (na == 0) |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3138 return (*meth)(self, NULL); |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3139 PyErr_Format(PyExc_TypeError, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3140 "%.200s() takes no arguments (%d given)", |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3141 ((PyCFunctionObject*)func)->m_ml->ml_name, na); |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3142 return NULL; |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3143 case METH_O: |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3144 if (na == 1) { |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3145 PyObject *arg = EXT_POP(*pp_stack); |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3146 PyObject *result = (*meth)(self, arg); |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3147 Py_DECREF(arg); |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3148 return result; |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3149 } |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3150 PyErr_Format(PyExc_TypeError, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3151 "%.200s() takes exactly one argument (%d given)", |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3152 ((PyCFunctionObject*)func)->m_ml->ml_name, na); |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3153 return NULL; |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3154 default: |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3155 fprintf(stderr, "%.200s() flags = %d\n", |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3156 ((PyCFunctionObject*)func)->m_ml->ml_name, flags); |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3157 PyErr_BadInternalCall(); |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3158 return NULL; |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3159 } |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3160 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3161 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3162 static PyObject * |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3163 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
|
3164 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3165 PyObject *co = PyFunction_GET_CODE(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3166 PyObject *globals = PyFunction_GET_GLOBALS(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3167 PyObject *argdefs = PyFunction_GET_DEFAULTS(func); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
3168 PyObject *closure = PyFunction_GET_CLOSURE(func); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3169 PyObject **d = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3170 int nd = 0; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3171 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3172 if (argdefs != NULL) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3173 d = &PyTuple_GET_ITEM(argdefs, 0); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3174 nd = ((PyTupleObject *)argdefs)->ob_size; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3175 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3176 return PyEval_EvalCodeEx((PyCodeObject *)co, globals, |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3177 (PyObject *)NULL, (*pp_stack)-n, na, |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
3178 (*pp_stack)-2*nk, nk, d, nd, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
3179 closure); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3180 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3181 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3182 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
|
3183 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
|
3184 PyObject *func) |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3185 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3186 PyObject *kwdict = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3187 if (orig_kwdict == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3188 kwdict = PyDict_New(); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3189 else { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3190 kwdict = PyDict_Copy(orig_kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3191 Py_DECREF(orig_kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3192 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3193 if (kwdict == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3194 return NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3195 while (--nk >= 0) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3196 int err; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3197 PyObject *value = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3198 PyObject *key = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3199 if (PyDict_GetItem(kwdict, key) != NULL) { |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3200 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
|
3201 "%.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
|
3202 "for keyword argument '%.200s'", |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3203 PyEval_GetFuncName(func), |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3204 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
|
3205 PyString_AsString(key)); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3206 Py_DECREF(key); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3207 Py_DECREF(value); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3208 Py_DECREF(kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3209 return NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3210 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3211 err = PyDict_SetItem(kwdict, key, value); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3212 Py_DECREF(key); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3213 Py_DECREF(value); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3214 if (err) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3215 Py_DECREF(kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3216 return NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3217 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3218 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3219 return kwdict; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3220 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3221 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3222 static PyObject * |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3223 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
|
3224 PyObject ***pp_stack) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3225 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3226 PyObject *callargs, *w; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3227 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3228 callargs = PyTuple_New(nstack + nstar); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3229 if (callargs == NULL) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3230 return NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3231 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3232 if (nstar) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3233 int i; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3234 for (i = 0; i < nstar; i++) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3235 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
|
3236 Py_INCREF(a); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3237 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
|
3238 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3239 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3240 while (--nstack >= 0) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3241 w = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3242 PyTuple_SET_ITEM(callargs, nstack, w); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3243 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3244 return callargs; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3245 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3246 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3247 static PyObject * |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3248 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
|
3249 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3250 PyObject *args = PyTuple_New(na); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3251 PyObject *w; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3252 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3253 if (args == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3254 return NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3255 while (--na >= 0) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3256 w = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3257 PyTuple_SET_ITEM(args, na, w); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3258 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3259 return args; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3260 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3261 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3262 static PyObject * |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3263 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
|
3264 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3265 PyObject *callargs = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3266 PyObject *kwdict = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3267 PyObject *result = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3268 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3269 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
|
3270 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
|
3271 if (kwdict == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3272 goto call_fail; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3273 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3274 callargs = load_args(pp_stack, na); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3275 if (callargs == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3276 goto call_fail; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3277 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
|
3278 call_fail: |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3279 Py_XDECREF(callargs); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3280 Py_XDECREF(kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3281 return result; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3282 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3283 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3284 static PyObject * |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3285 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
|
3286 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3287 int nstar = 0; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3288 PyObject *callargs = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3289 PyObject *stararg = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3290 PyObject *kwdict = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3291 PyObject *result = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3292 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3293 if (flags & CALL_FLAG_KW) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3294 kwdict = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3295 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
|
3296 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
|
3297 "%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
|
3298 "must be a dictionary", |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3299 PyEval_GetFuncName(func), |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3300 PyEval_GetFuncDesc(func)); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3301 goto ext_call_fail; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3302 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3303 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3304 if (flags & CALL_FLAG_VAR) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3305 stararg = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3306 if (!PyTuple_Check(stararg)) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3307 PyObject *t = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3308 t = PySequence_Tuple(stararg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3309 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
|
3310 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
|
3311 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
|
3312 "%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
|
3313 "must be a sequence", |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3314 PyEval_GetFuncName(func), |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3315 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
|
3316 } |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3317 goto ext_call_fail; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3318 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3319 Py_DECREF(stararg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3320 stararg = t; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3321 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3322 nstar = PyTuple_GET_SIZE(stararg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3323 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3324 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
|
3325 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
|
3326 if (kwdict == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3327 goto ext_call_fail; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3328 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3329 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
|
3330 if (callargs == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3331 goto ext_call_fail; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3332 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
|
3333 ext_call_fail: |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3334 Py_XDECREF(callargs); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3335 Py_XDECREF(kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3336 Py_XDECREF(stararg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3337 return result; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3338 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3339 |
|
3863
4566a19c3438
Better error message if stride used on normal sequence object
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
3340 #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
|
3341 "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
|
3342 |
| 5368 | 3343 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3344 loop_subscript(PyObject *v, PyObject *w) |
| 69 | 3345 { |
| 5368 | 3346 PySequenceMethods *sq = v->ob_type->tp_as_sequence; |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
3347 int i; |
|
8403
c4df8b6637b6
Moved cmp_member() to abstract.c, as PySequence_Contains() [with
Guido van Rossum <guido@python.org>
parents:
8328
diff
changeset
|
3348 if (sq == NULL || sq->sq_item == NULL) { |
| 5368 | 3349 PyErr_SetString(PyExc_TypeError, "loop over non-sequence"); |
| 69 | 3350 return NULL; |
| 3351 } | |
| 5368 | 3352 i = PyInt_AsLong(w); |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
3353 v = (*sq->sq_item)(v, i); |
|
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
3354 if (v) |
|
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
3355 return v; |
|
6147
b76a44163e0f
cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents:
6139
diff
changeset
|
3356 if (PyErr_ExceptionMatches(PyExc_IndexError)) |
| 5368 | 3357 PyErr_Clear(); |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
3358 return NULL; |
| 69 | 3359 } |
| 3360 | |
|
21440
30efe46f8e3c
_PyEval_SliceIndex(): Repaired the comments, and added XXX comments
Tim Peters <tim.peters@gmail.com>
parents:
21398
diff
changeset
|
3361 /* 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
|
3362 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
|
3363 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
|
3364 */ |
|
21441
05ad7a69d933
_PyEval_SliceIndex(): explain why a NULL argument is allowed (thanks
Tim Peters <tim.peters@gmail.com>
parents:
21440
diff
changeset
|
3365 /* 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
|
3366 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
|
3367 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
|
3368 */ |
| 12614 | 3369 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3370 _PyEval_SliceIndex(PyObject *v, int *pi) |
| 69 | 3371 { |
|
21441
05ad7a69d933
_PyEval_SliceIndex(): explain why a NULL argument is allowed (thanks
Tim Peters <tim.peters@gmail.com>
parents:
21440
diff
changeset
|
3372 if (v != NULL) { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3373 long x; |
|
11839
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3374 if (PyInt_Check(v)) { |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3375 x = PyInt_AsLong(v); |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3376 } else if (PyLong_Check(v)) { |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3377 x = PyLong_AsLong(v); |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3378 if (x==-1 && PyErr_Occurred()) { |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3379 PyObject *long_zero; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3380 int cmp; |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3381 |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3382 if (!PyErr_ExceptionMatches( |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3383 PyExc_OverflowError)) { |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3384 /* 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
|
3385 signal an error */ |
| 12614 | 3386 return 0; |
|
11839
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3387 } |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3388 |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3389 /* Clear the OverflowError */ |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3390 PyErr_Clear(); |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3391 |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3392 /* It's an overflow error, so we need to |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3393 check the sign of the long integer, |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3394 set the value to INT_MAX or 0, and clear |
|
11839
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3395 the error. */ |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3396 |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3397 /* 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
|
3398 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
|
3399 if (long_zero == NULL) |
|
30efe46f8e3c
_PyEval_SliceIndex(): Repaired the comments, and added XXX comments
Tim Peters <tim.peters@gmail.com>
parents:
21398
diff
changeset
|
3400 return 0; |
|
11839
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3401 |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3402 /* Check sign */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3403 cmp = PyObject_RichCompareBool(v, long_zero, |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3404 Py_GT); |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3405 Py_DECREF(long_zero); |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3406 if (cmp < 0) |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3407 return 0; |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3408 else if (cmp > 0) |
|
11839
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3409 x = INT_MAX; |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3410 else |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3411 x = 0; |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3412 } |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3413 } else { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3414 PyErr_SetString(PyExc_TypeError, |
| 15318 | 3415 "slice indices must be integers"); |
| 12614 | 3416 return 0; |
| 69 | 3417 } |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3418 /* 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
|
3419 if (x > INT_MAX) |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3420 x = INT_MAX; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3421 else if (x < -INT_MAX) |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3422 x = 0; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3423 *pi = x; |
| 69 | 3424 } |
| 12614 | 3425 return 1; |
| 69 | 3426 } |
| 3427 | |
| 19369 | 3428 #undef ISINT |
| 3429 #define ISINT(x) ((x) == NULL || PyInt_Check(x) || PyLong_Check(x)) | |
| 3430 | |
| 5368 | 3431 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3432 apply_slice(PyObject *u, PyObject *v, PyObject *w) /* return u[v:w] */ |
| 69 | 3433 { |
| 19369 | 3434 PyTypeObject *tp = u->ob_type; |
| 3435 PySequenceMethods *sq = tp->tp_as_sequence; | |
| 3436 | |
| 3437 if (sq && sq->sq_slice && ISINT(v) && ISINT(w)) { | |
| 3438 int ilow = 0, ihigh = INT_MAX; | |
| 3439 if (!_PyEval_SliceIndex(v, &ilow)) | |
| 3440 return NULL; | |
| 3441 if (!_PyEval_SliceIndex(w, &ihigh)) | |
| 3442 return NULL; | |
| 3443 return PySequence_GetSlice(u, ilow, ihigh); | |
| 3444 } | |
| 3445 else { | |
| 3446 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
|
3447 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
|
3448 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
|
3449 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
|
3450 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
|
3451 } |
| 19369 | 3452 else |
| 3453 return NULL; | |
| 3454 } | |
| 69 | 3455 } |
| 86 | 3456 |
| 3457 static int | |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3458 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
|
3459 /* u[v:w] = x */ |
| 69 | 3460 { |
| 19369 | 3461 PyTypeObject *tp = u->ob_type; |
| 3462 PySequenceMethods *sq = tp->tp_as_sequence; | |
| 3463 | |
| 3464 if (sq && sq->sq_slice && ISINT(v) && ISINT(w)) { | |
| 3465 int ilow = 0, ihigh = INT_MAX; | |
| 3466 if (!_PyEval_SliceIndex(v, &ilow)) | |
| 3467 return -1; | |
| 3468 if (!_PyEval_SliceIndex(w, &ihigh)) | |
| 3469 return -1; | |
| 3470 if (x == NULL) | |
| 3471 return PySequence_DelSlice(u, ilow, ihigh); | |
| 3472 else | |
| 3473 return PySequence_SetSlice(u, ilow, ihigh, x); | |
| 3474 } | |
| 3475 else { | |
| 3476 PyObject *slice = PySlice_New(v, w, NULL); | |
| 3477 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
|
3478 int res; |
| 19369 | 3479 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
|
3480 res = PyObject_SetItem(u, slice, x); |
| 19369 | 3481 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
|
3482 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
|
3483 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
|
3484 return res; |
| 19369 | 3485 } |
| 3486 else | |
| 3487 return -1; | |
| 3488 } | |
| 69 | 3489 } |
| 3490 | |
| 5368 | 3491 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3492 cmp_outcome(int op, register PyObject *v, register PyObject *w) |
| 69 | 3493 { |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3494 int res = 0; |
| 69 | 3495 switch (op) { |
| 86 | 3496 case IS: |
| 3497 case IS_NOT: | |
| 3498 res = (v == w); | |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
3499 if (op == (int) IS_NOT) |
| 86 | 3500 res = !res; |
| 3501 break; | |
| 69 | 3502 case IN: |
| 3503 case NOT_IN: | |
|
8403
c4df8b6637b6
Moved cmp_member() to abstract.c, as PySequence_Contains() [with
Guido van Rossum <guido@python.org>
parents:
8328
diff
changeset
|
3504 res = PySequence_Contains(w, v); |
| 86 | 3505 if (res < 0) |
| 3506 return NULL; | |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
3507 if (op == (int) NOT_IN) |
| 86 | 3508 res = !res; |
| 69 | 3509 break; |
| 3510 case EXC_MATCH: | |
|
6147
b76a44163e0f
cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents:
6139
diff
changeset
|
3511 res = PyErr_GivenExceptionMatches(v, w); |
| 69 | 3512 break; |
| 3513 default: | |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3514 return PyObject_RichCompare(v, w, op); |
| 69 | 3515 } |
| 5368 | 3516 v = res ? Py_True : Py_False; |
| 3517 Py_INCREF(v); | |
| 69 | 3518 return v; |
| 3519 } | |
| 3520 | |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
3521 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
|
3522 import_from(PyObject *v, PyObject *name) |
|
72
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3523 { |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3524 PyObject *x; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3525 |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3526 x = PyObject_GetAttr(v, name); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3527 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
|
3528 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
|
3529 "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
|
3530 PyString_AsString(name)); |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3531 } |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
3532 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
|
3533 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3534 |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
3535 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
|
3536 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
|
3537 { |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3538 PyObject *all = PyObject_GetAttrString(v, "__all__"); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3539 PyObject *dict, *name, *value; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3540 int skip_leading_underscores = 0; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3541 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
|
3542 |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3543 if (all == NULL) { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3544 if (!PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3545 return -1; /* Unexpected error */ |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3546 PyErr_Clear(); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3547 dict = PyObject_GetAttrString(v, "__dict__"); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3548 if (dict == NULL) { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3549 if (!PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3550 return -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3551 PyErr_SetString(PyExc_ImportError, |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3552 "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
|
3553 return -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3554 } |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3555 all = PyMapping_Keys(dict); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3556 Py_DECREF(dict); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3557 if (all == NULL) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3558 return -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3559 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
|
3560 } |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
3561 |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3562 for (pos = 0, err = 0; ; pos++) { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3563 name = PySequence_GetItem(all, pos); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3564 if (name == NULL) { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3565 if (!PyErr_ExceptionMatches(PyExc_IndexError)) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3566 err = -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3567 else |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3568 PyErr_Clear(); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3569 break; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3570 } |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3571 if (skip_leading_underscores && |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3572 PyString_Check(name) && |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3573 PyString_AS_STRING(name)[0] == '_') |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3574 { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3575 Py_DECREF(name); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3576 continue; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3577 } |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3578 value = PyObject_GetAttr(v, name); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3579 if (value == NULL) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3580 err = -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3581 else |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3582 err = PyDict_SetItem(locals, name, value); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3583 Py_DECREF(name); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3584 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
|
3585 if (err != 0) |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3586 break; |
|
72
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3587 } |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3588 Py_DECREF(all); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3589 return err; |
|
72
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3590 } |
|
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3591 |
| 5368 | 3592 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3593 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
|
3594 { |
|
19890
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3595 PyObject *metaclass = NULL, *result, *base; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3596 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3597 if (PyDict_Check(methods)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3598 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
|
3599 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
|
3600 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
|
3601 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
|
3602 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
|
3603 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
|
3604 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
|
3605 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
|
3606 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
|
3607 Py_INCREF(metaclass); |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
3608 } |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
3609 } |
|
19890
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3610 else { |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3611 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
|
3612 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
|
3613 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
|
3614 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
|
3615 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
|
3616 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
|
3617 } |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3618 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
|
3619 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
|
3620 return result; |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
3621 } |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
3622 |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3623 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3624 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
|
3625 PyObject *locals) |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3626 { |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3627 int n; |
| 5368 | 3628 PyObject *v; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3629 int plain = 0; |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3630 |
| 5368 | 3631 if (PyTuple_Check(prog) && globals == Py_None && locals == Py_None && |
| 3632 ((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
|
3633 /* Backward compatibility hack */ |
| 5368 | 3634 globals = PyTuple_GetItem(prog, 1); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3635 if (n == 3) |
| 5368 | 3636 locals = PyTuple_GetItem(prog, 2); |
| 3637 prog = PyTuple_GetItem(prog, 0); | |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3638 } |
| 5368 | 3639 if (globals == Py_None) { |
| 3640 globals = PyEval_GetGlobals(); | |
| 3641 if (locals == Py_None) { | |
| 3642 locals = PyEval_GetLocals(); | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3643 plain = 1; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3644 } |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3645 } |
| 5368 | 3646 else if (locals == Py_None) |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3647 locals = globals; |
| 5368 | 3648 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
|
3649 !PyUnicode_Check(prog) && |
| 5368 | 3650 !PyCode_Check(prog) && |
| 3651 !PyFile_Check(prog)) { | |
| 3652 PyErr_SetString(PyExc_TypeError, | |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3653 "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
|
3654 return -1; |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3655 } |
| 15318 | 3656 if (!PyDict_Check(globals)) { |
| 5368 | 3657 PyErr_SetString(PyExc_TypeError, |
| 15318 | 3658 "exec: arg 2 must be a dictionary or None"); |
| 3659 return -1; | |
| 3660 } | |
| 3661 if (!PyDict_Check(locals)) { | |
| 3662 PyErr_SetString(PyExc_TypeError, | |
| 3663 "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
|
3664 return -1; |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3665 } |
| 5368 | 3666 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
|
3667 PyDict_SetItemString(globals, "__builtins__", f->f_builtins); |
| 5368 | 3668 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
|
3669 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
|
3670 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
|
3671 "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
|
3672 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
|
3673 } |
|
11651
d88996e46cb2
Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents:
11468
diff
changeset
|
3674 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
|
3675 } |
|
11651
d88996e46cb2
Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents:
11468
diff
changeset
|
3676 else if (PyFile_Check(prog)) { |
| 5368 | 3677 FILE *fp = PyFile_AsFile(prog); |
| 3678 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
|
3679 PyCompilerFlags cf; |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3680 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
|
3681 if (PyEval_MergeCompilerFlags(&cf)) |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
3682 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
|
3683 locals, &cf); |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3684 else |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
3685 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
|
3686 locals); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3687 } |
|
11651
d88996e46cb2
Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents:
11468
diff
changeset
|
3688 else { |
|
14696
85038a024b19
This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents:
14375
diff
changeset
|
3689 char *str; |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3690 PyCompilerFlags cf; |
|
14696
85038a024b19
This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents:
14375
diff
changeset
|
3691 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
|
3692 return -1; |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3693 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
|
3694 if (PyEval_MergeCompilerFlags(&cf)) |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
3695 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
|
3696 locals, &cf); |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3697 else |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
3698 v = PyRun_String(str, Py_file_input, globals, locals); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3699 } |
|
11651
d88996e46cb2
Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents:
11468
diff
changeset
|
3700 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
|
3701 PyFrame_LocalsToFast(f, 0); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3702 if (v == NULL) |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3703 return -1; |
| 5368 | 3704 Py_DECREF(v); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3705 return 0; |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3706 } |
|
2338
4c2f1452125d
call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents:
2310
diff
changeset
|
3707 |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3708 static void |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
3709 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
|
3710 { |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
3711 char *obj_str; |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
3712 |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
3713 if (!obj) |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
3714 return; |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
3715 |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
3716 obj_str = PyString_AsString(obj); |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
3717 if (!obj_str) |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
3718 return; |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
3719 |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
3720 PyErr_Format(exc, format_str, obj_str); |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
3721 } |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3722 |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3723 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3724 |
|
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
|
3725 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3726 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
|
3727 { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3728 int i; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3729 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
|
3730 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
|
3731 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
|
3732 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
|
3733 if (x == NULL) { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3734 Py_DECREF(l); |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3735 return NULL; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3736 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3737 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
|
3738 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3739 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
|
3740 a[i] = 0; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3741 return l; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3742 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3743 |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3744 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3745 _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
|
3746 { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3747 #ifndef DXPAIRS |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3748 return getarray(dxp); |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3749 #else |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3750 int i; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3751 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
|
3752 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
|
3753 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
|
3754 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
|
3755 if (x == NULL) { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3756 Py_DECREF(l); |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3757 return NULL; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3758 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3759 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
|
3760 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3761 return l; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3762 #endif |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3763 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3764 |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3765 #endif |
