Mercurial > cpython-lru_cache-weakref
annotate Python/ceval.c @ 19896:0491ea611bc4 legacy-trunk
Admit that we'll never add the args for a "call" event to the profile
and trace functions; this now declares that None will be passed for the
"call" event.
This closes SF bug/suggestion #460315.
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Thu, 13 Sep 2001 16:56:43 +0000 |
| parents | 31fe8b3e276b |
| children | 3faabf54b8b8 |
| 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 *); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
51 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
|
52 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
|
53 static PyObject *apply_slice(PyObject *, PyObject *, PyObject *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
54 static int assign_slice(PyObject *, PyObject *, |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
55 PyObject *, PyObject *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
56 static PyObject *cmp_outcome(int, PyObject *, PyObject *); |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
57 static PyObject *import_from(PyObject *, PyObject *); |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
58 static int import_all_from(PyObject *, PyObject *); |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
59 static PyObject *build_class(PyObject *, PyObject *, PyObject *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
60 static int exec_statement(PyFrameObject *, |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
61 PyObject *, PyObject *, PyObject *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
62 static void set_exc_info(PyThreadState *, PyObject *, PyObject *, PyObject *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
63 static void reset_exc_info(PyThreadState *); |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
64 static void format_exc_check_arg(PyObject *, char *, PyObject *); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
65 |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
66 #define NAME_ERROR_MSG \ |
| 15318 | 67 "name '%.200s' is not defined" |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
68 #define GLOBAL_NAME_ERROR_MSG \ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
69 "global name '%.200s' is not defined" |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
70 #define UNBOUNDLOCAL_ERROR_MSG \ |
| 15318 | 71 "local variable '%.200s' referenced before assignment" |
|
17494
a34293ced63b
Change error message raised when free variable is not yet bound. It
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17490
diff
changeset
|
72 #define UNBOUNDFREE_ERROR_MSG \ |
|
a34293ced63b
Change error message raised when free variable is not yet bound. It
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17490
diff
changeset
|
73 "free variable '%.200s' referenced before assignment" \ |
|
a34293ced63b
Change error message raised when free variable is not yet bound. It
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17490
diff
changeset
|
74 " in enclosing scope" |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
75 |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
76 /* Dynamic execution profile */ |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
77 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
78 #ifdef DXPAIRS |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
79 static long dxpairs[257][256]; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
80 #define dxp dxpairs[256] |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
81 #else |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
82 static long dxp[256]; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
83 #endif |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
84 #endif |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
85 |
|
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
|
86 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
|
87 |
|
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 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
|
89 PyObject_HEAD |
|
18288
6800bcce0455
Add "gi_" (generator-iterator) prefix to names of genobject members.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
90 /* 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
|
91 |
|
6800bcce0455
Add "gi_" (generator-iterator) prefix to names of genobject members.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
92 PyFrameObject *gi_frame; |
|
6800bcce0455
Add "gi_" (generator-iterator) prefix to names of genobject members.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
93 |
|
18293
0344e4ac70b0
gen_getattr: make the gi_running and gi_frame members discoverable (but
Tim Peters <tim.peters@gmail.com>
parents:
18288
diff
changeset
|
94 /* 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
|
95 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
|
96 } 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
|
97 |
|
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 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
|
99 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
|
100 { |
|
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 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
|
102 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
|
103 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
|
104 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
|
105 } |
|
18288
6800bcce0455
Add "gi_" (generator-iterator) prefix to names of genobject members.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
106 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
|
107 gen->gi_running = 0; |
|
18513
65afac84d4f7
GC for generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18374
diff
changeset
|
108 PyObject_GC_Init(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
|
109 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
|
110 } |
|
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 |
|
18513
65afac84d4f7
GC for generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18374
diff
changeset
|
112 static int |
|
65afac84d4f7
GC for generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18374
diff
changeset
|
113 gen_traverse(genobject *gen, visitproc visit, void *arg) |
|
65afac84d4f7
GC for generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18374
diff
changeset
|
114 { |
|
65afac84d4f7
GC for generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18374
diff
changeset
|
115 return visit((PyObject *)gen->gi_frame, arg); |
|
65afac84d4f7
GC for generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18374
diff
changeset
|
116 } |
|
65afac84d4f7
GC for generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18374
diff
changeset
|
117 |
|
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
|
118 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
|
119 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
|
120 { |
|
18513
65afac84d4f7
GC for generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18374
diff
changeset
|
121 PyObject_GC_Fini(gen); |
|
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 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
195 static struct memberlist gen_memberlist[] = { |
|
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 */ |
|
18513
65afac84d4f7
GC for generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18374
diff
changeset
|
205 sizeof(genobject) + PyGC_HEAD_SIZE, /* 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 */ |
|
18513
65afac84d4f7
GC for generator objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18374
diff
changeset
|
223 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /* tp_flags */ |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
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 */ |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
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 |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
498 PyObject **stack_pointer; |
|
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 |
| 543 #define PUSH(v) (BASIC_PUSH(v), lltrace && prtrace(TOP(), "push")) | |
| 544 #define POP() (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
|
545 #else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
546 #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
|
547 #define POP() BASIC_POP() |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
548 #endif |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
549 |
|
19611
8f035800a373
Do the int inlining only if the type is really an int, not whenever
Guido van Rossum <guido@python.org>
parents:
19600
diff
changeset
|
550 /* Strict int check macros */ |
|
8f035800a373
Do the int inlining only if the type is really an int, not whenever
Guido van Rossum <guido@python.org>
parents:
19600
diff
changeset
|
551 #define ISSTRICTINT(v) ((v)->ob_type == &PyInt_Type) |
|
8f035800a373
Do the int inlining only if the type is really an int, not whenever
Guido van Rossum <guido@python.org>
parents:
19600
diff
changeset
|
552 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
553 /* Local variable macros */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
554 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
555 #define GETLOCAL(i) (fastlocals[i]) |
| 5368 | 556 #define SETLOCAL(i, value) do { Py_XDECREF(GETLOCAL(i)); \ |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
557 GETLOCAL(i) = value; } while (0) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
558 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
559 /* Start of code */ |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
560 |
|
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
|
561 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
|
562 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
|
563 |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
564 #ifdef USE_STACKCHECK |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
565 if (tstate->recursion_depth%10 == 0 && PyOS_CheckStack()) { |
| 5368 | 566 PyErr_SetString(PyExc_MemoryError, "Stack overflow"); |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
567 return NULL; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
568 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
569 #endif |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
570 |
|
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
|
571 /* push frame */ |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14268
diff
changeset
|
572 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
|
573 --tstate->recursion_depth; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
574 PyErr_SetString(PyExc_RuntimeError, |
| 15318 | 575 "maximum recursion depth exceeded"); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
576 tstate->frame = f->f_back; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
577 return NULL; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
578 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
579 |
|
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
|
580 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
|
581 co = f->f_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
|
582 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
|
583 freevars = f->f_localsplus + f->f_nlocals; |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
584 _PyCode_GETCODEPTR(co, &first_instr); |
|
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
|
585 next_instr = first_instr + f->f_lasti; |
|
18237
f02605b8fdc1
PyFrameObject: rename f_stackbottom to f_stacktop, since it points to
Tim Peters <tim.peters@gmail.com>
parents:
18195
diff
changeset
|
586 stack_pointer = f->f_stacktop; |
|
f02605b8fdc1
PyFrameObject: rename f_stackbottom to f_stacktop, since it points to
Tim Peters <tim.peters@gmail.com>
parents:
18195
diff
changeset
|
587 assert(stack_pointer != NULL); |
|
f02605b8fdc1
PyFrameObject: rename f_stackbottom to f_stacktop, since it points to
Tim Peters <tim.peters@gmail.com>
parents:
18195
diff
changeset
|
588 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
|
589 |
|
19692
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->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
|
591 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
|
592 /* 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
|
593 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
|
594 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
|
595 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
|
596 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
|
597 (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
|
598 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
|
599 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
|
600 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
|
601 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
|
602 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
|
603 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
|
604 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
|
605 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
|
606 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
|
607 /* Trace function raised an error */ |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
608 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
|
609 } |
|
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 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
|
612 /* 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
|
613 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
|
614 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
|
615 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
|
616 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
|
617 /* Profile function raised an error */ |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
618 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
|
619 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
620 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
621 } |
|
04218e85b156
Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19611
diff
changeset
|
622 |
|
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
|
623 #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
|
624 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
|
625 #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
|
626 #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
|
627 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
|
628 #endif |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
629 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
630 why = WHY_NOT; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
631 err = 0; |
| 5368 | 632 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
|
633 w = NULL; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
634 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
635 for (;;) { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
636 /* 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
|
637 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
|
638 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
|
639 ``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
|
640 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
|
641 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
|
642 Py_MakePendingCalls() above. */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
643 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
644 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
|
645 tstate->ticker = tstate->interp->checkinterval; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
646 if (things_to_do) { |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
647 if (Py_MakePendingCalls() < 0) { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
648 why = WHY_EXCEPTION; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
649 goto on_error; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
650 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
651 } |
|
5551
34509c05266f
Logic for enabling mac-specific signal handling fixed (Jack)
Guido van Rossum <guido@python.org>
parents:
5492
diff
changeset
|
652 #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
|
653 /* 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
|
654 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
|
655 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
|
656 DOS, alas, we have to call it. */ |
| 5368 | 657 if (PyErr_CheckSignals()) { |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
658 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
659 goto on_error; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
660 } |
|
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
|
661 #endif |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
662 |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
663 #ifdef WITH_THREAD |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
664 if (interpreter_lock) { |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
665 /* Give another thread a chance */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
666 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
667 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
|
668 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
|
669 PyThread_release_lock(interpreter_lock); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
670 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
671 /* Other threads may run now */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
672 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9671
diff
changeset
|
673 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
|
674 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
|
675 Py_FatalError("ceval: orphan tstate"); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
676 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
677 #endif |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
678 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
815
diff
changeset
|
679 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
680 /* Extract opcode and argument */ |
|
1016
a41e3ba5b47d
Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents:
974
diff
changeset
|
681 |
|
4839
4567e158d20c
Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents:
4667
diff
changeset
|
682 #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
|
683 f->f_lasti = INSTR_OFFSET(); |
|
a41e3ba5b47d
Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents:
974
diff
changeset
|
684 #endif |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
685 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
686 opcode = NEXTOP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
687 if (HAS_ARG(opcode)) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
688 oparg = NEXTARG(); |
|
14147
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
689 dispatch_opcode: |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
690 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
691 #ifdef DXPAIRS |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
692 dxpairs[lastopcode][opcode]++; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
693 lastopcode = opcode; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
694 #endif |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
695 dxp[opcode]++; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
696 #endif |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
697 |
| 567 | 698 #ifdef LLTRACE |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
699 /* Instruction tracing */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
700 |
| 567 | 701 if (lltrace) { |
|
173
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 printf("%d: %d, %d\n", |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
704 (int) (INSTR_OFFSET() - 3), |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
705 opcode, oparg); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
706 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
707 else { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
708 printf("%d: %d\n", |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
709 (int) (INSTR_OFFSET() - 1), opcode); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
710 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
711 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
712 #endif |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
713 /* Main switch on opcode */ |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
714 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
715 switch (opcode) { |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
716 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
717 /* BEWARE! |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
718 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
|
719 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
|
720 and that no operation that succeeds does this! */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
721 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
722 /* case STOP_CODE: this is an error! */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
723 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
724 case POP_TOP: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
725 v = POP(); |
| 5368 | 726 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
|
727 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
728 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
729 case ROT_TWO: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
730 v = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
731 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
732 PUSH(v); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
733 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
|
734 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
735 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
736 case ROT_THREE: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
737 v = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
738 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
739 x = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
740 PUSH(v); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
741 PUSH(x); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
742 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
|
743 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
744 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
745 case ROT_FOUR: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
746 u = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
747 v = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
748 w = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
749 x = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
750 PUSH(u); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
751 PUSH(x); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
752 PUSH(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
753 PUSH(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
754 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
755 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
756 case DUP_TOP: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
757 v = TOP(); |
| 5368 | 758 Py_INCREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
759 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
|
760 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
761 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
762 case DUP_TOPX: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
763 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
|
764 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
|
765 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
|
766 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
|
767 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
|
768 continue; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
769 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
|
770 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
|
771 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
|
772 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
|
773 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
|
774 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
|
775 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
|
776 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
|
777 continue; |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
778 case 3: |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
779 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
|
780 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
|
781 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
|
782 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
|
783 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
|
784 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
|
785 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
|
786 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
|
787 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
|
788 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
|
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 continue; |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
791 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
|
792 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
|
793 Py_INCREF(x); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
794 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
|
795 Py_INCREF(w); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
796 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
|
797 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
|
798 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
|
799 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
|
800 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
|
801 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
|
802 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
|
803 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
|
804 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
|
805 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
|
806 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
|
807 continue; |
|
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
808 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
|
809 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
|
810 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
|
811 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
|
812 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
|
813 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
|
814 Py_INCREF(v); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
815 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
|
816 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
|
817 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
|
818 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
|
819 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
|
820 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
|
821 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
|
822 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
|
823 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
|
824 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
|
825 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
|
826 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
|
827 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
|
828 continue; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
829 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
|
830 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
|
831 " (bytecode corruption?)"); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
832 } |
|
15151
ca9f6a8e9885
Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
833 break; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
834 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
835 case UNARY_POSITIVE: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
836 v = POP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
837 x = PyNumber_Positive(v); |
| 5368 | 838 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
839 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
|
840 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
841 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
842 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
843 case UNARY_NEGATIVE: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
844 v = POP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
845 x = PyNumber_Negative(v); |
| 5368 | 846 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
847 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
|
848 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
849 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
850 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
851 case UNARY_NOT: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
852 v = POP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
853 err = PyObject_IsTrue(v); |
| 5368 | 854 Py_DECREF(v); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
855 if (err == 0) { |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
856 Py_INCREF(Py_True); |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
857 PUSH(Py_True); |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
858 continue; |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
859 } |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
860 else if (err > 0) { |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
861 Py_INCREF(Py_False); |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
862 PUSH(Py_False); |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
863 err = 0; |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
864 continue; |
|
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
865 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
866 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
867 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
868 case UNARY_CONVERT: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
869 v = POP(); |
| 5368 | 870 x = PyObject_Repr(v); |
| 871 Py_DECREF(v); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
872 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
|
873 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
874 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
875 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
876 case UNARY_INVERT: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
877 v = POP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
878 x = PyNumber_Invert(v); |
| 5368 | 879 Py_DECREF(v); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
880 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
|
881 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
882 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
883 |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3294
diff
changeset
|
884 case BINARY_POWER: |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3294
diff
changeset
|
885 w = POP(); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3294
diff
changeset
|
886 v = POP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
887 x = PyNumber_Power(v, w, Py_None); |
| 5368 | 888 Py_DECREF(v); |
| 889 Py_DECREF(w); | |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3294
diff
changeset
|
890 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
|
891 if (x != NULL) continue; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3294
diff
changeset
|
892 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
893 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
894 case BINARY_MULTIPLY: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
895 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
896 v = POP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
897 x = PyNumber_Multiply(v, w); |
| 5368 | 898 Py_DECREF(v); |
| 899 Py_DECREF(w); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
900 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
|
901 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
902 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
903 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
904 case BINARY_DIVIDE: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
905 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
906 v = POP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
907 x = PyNumber_Divide(v, w); |
| 5368 | 908 Py_DECREF(v); |
| 909 Py_DECREF(w); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
910 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
|
911 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
912 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
913 |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
914 case BINARY_FLOOR_DIVIDE: |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
915 w = POP(); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
916 v = POP(); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
917 x = PyNumber_FloorDivide(v, w); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
918 Py_DECREF(v); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
919 Py_DECREF(w); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
920 PUSH(x); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
921 if (x != NULL) continue; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
922 break; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
923 |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
924 case BINARY_TRUE_DIVIDE: |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
925 w = POP(); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
926 v = POP(); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
927 x = PyNumber_TrueDivide(v, w); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
928 Py_DECREF(v); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
929 Py_DECREF(w); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
930 PUSH(x); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
931 if (x != NULL) continue; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
932 break; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
933 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
934 case BINARY_MODULO: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
935 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
936 v = POP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
937 x = PyNumber_Remainder(v, w); |
| 5368 | 938 Py_DECREF(v); |
| 939 Py_DECREF(w); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
940 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
|
941 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
942 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
943 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
944 case BINARY_ADD: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
945 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
946 v = POP(); |
|
19611
8f035800a373
Do the int inlining only if the type is really an int, not whenever
Guido van Rossum <guido@python.org>
parents:
19600
diff
changeset
|
947 if (ISSTRICTINT(v) && ISSTRICTINT(w)) { |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
948 /* INLINE: int + int */ |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
949 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
|
950 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
|
951 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
|
952 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
|
953 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
|
954 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
|
955 x = PyInt_FromLong(i); |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
956 } |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
957 else { |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
958 slow_add: |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
959 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
|
960 } |
| 5368 | 961 Py_DECREF(v); |
| 962 Py_DECREF(w); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
963 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
|
964 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
965 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
966 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
967 case BINARY_SUBTRACT: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
968 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
969 v = POP(); |
|
19611
8f035800a373
Do the int inlining only if the type is really an int, not whenever
Guido van Rossum <guido@python.org>
parents:
19600
diff
changeset
|
970 if (ISSTRICTINT(v) && ISSTRICTINT(w)) { |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
971 /* INLINE: int - int */ |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
972 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
|
973 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
|
974 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
|
975 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
|
976 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
|
977 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
|
978 x = PyInt_FromLong(i); |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
979 } |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
980 else { |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
981 slow_sub: |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
982 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
|
983 } |
| 5368 | 984 Py_DECREF(v); |
| 985 Py_DECREF(w); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
986 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
|
987 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
988 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
989 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
990 case BINARY_SUBSCR: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
991 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
992 v = POP(); |
|
19611
8f035800a373
Do the int inlining only if the type is really an int, not whenever
Guido van Rossum <guido@python.org>
parents:
19600
diff
changeset
|
993 if (v->ob_type == &PyList_Type && ISSTRICTINT(w)) { |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
994 /* INLINE: list[int] */ |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
995 long i = PyInt_AsLong(w); |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
996 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
|
997 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
|
998 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
|
999 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
|
1000 PyErr_SetString(PyExc_IndexError, |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1001 "list index out of range"); |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1002 x = NULL; |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1003 } |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1004 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
|
1005 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
|
1006 Py_INCREF(x); |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1007 } |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1008 } |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1009 else |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1010 x = PyObject_GetItem(v, w); |
| 5368 | 1011 Py_DECREF(v); |
| 1012 Py_DECREF(w); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1013 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
|
1014 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1015 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1016 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1017 case BINARY_LSHIFT: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1018 w = POP(); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1019 v = POP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1020 x = PyNumber_Lshift(v, w); |
| 5368 | 1021 Py_DECREF(v); |
| 1022 Py_DECREF(w); | |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1023 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
|
1024 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1025 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1026 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1027 case BINARY_RSHIFT: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1028 w = POP(); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1029 v = POP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1030 x = PyNumber_Rshift(v, w); |
| 5368 | 1031 Py_DECREF(v); |
| 1032 Py_DECREF(w); | |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1033 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
|
1034 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1035 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1036 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1037 case BINARY_AND: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1038 w = POP(); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1039 v = POP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1040 x = PyNumber_And(v, w); |
| 5368 | 1041 Py_DECREF(v); |
| 1042 Py_DECREF(w); | |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1043 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
|
1044 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1045 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1046 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1047 case BINARY_XOR: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1048 w = POP(); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1049 v = POP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1050 x = PyNumber_Xor(v, w); |
| 5368 | 1051 Py_DECREF(v); |
| 1052 Py_DECREF(w); | |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1053 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
|
1054 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1055 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1056 |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1057 case BINARY_OR: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1058 w = POP(); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1059 v = POP(); |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1060 x = PyNumber_Or(v, w); |
| 5368 | 1061 Py_DECREF(v); |
| 1062 Py_DECREF(w); | |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1063 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
|
1064 if (x != NULL) continue; |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
401
diff
changeset
|
1065 break; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1066 |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1067 case INPLACE_POWER: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1068 w = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1069 v = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1070 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
|
1071 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1072 Py_DECREF(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1073 PUSH(x); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1074 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1075 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1076 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1077 case INPLACE_MULTIPLY: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1078 w = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1079 v = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1080 x = PyNumber_InPlaceMultiply(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1081 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1082 Py_DECREF(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1083 PUSH(x); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1084 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1085 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1086 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1087 case INPLACE_DIVIDE: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1088 w = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1089 v = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1090 x = PyNumber_InPlaceDivide(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1091 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1092 Py_DECREF(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1093 PUSH(x); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1094 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1095 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1096 |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1097 case INPLACE_FLOOR_DIVIDE: |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1098 w = POP(); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1099 v = POP(); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1100 x = PyNumber_InPlaceFloorDivide(v, w); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1101 Py_DECREF(v); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1102 Py_DECREF(w); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1103 PUSH(x); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1104 if (x != NULL) continue; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1105 break; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1106 |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1107 case INPLACE_TRUE_DIVIDE: |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1108 w = POP(); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1109 v = POP(); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1110 x = PyNumber_InPlaceTrueDivide(v, w); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1111 Py_DECREF(v); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1112 Py_DECREF(w); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1113 PUSH(x); |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1114 if (x != NULL) continue; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1115 break; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1116 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1117 case INPLACE_MODULO: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1118 w = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1119 v = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1120 x = PyNumber_InPlaceRemainder(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1121 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1122 Py_DECREF(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1123 PUSH(x); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1124 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1125 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1126 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1127 case INPLACE_ADD: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1128 w = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1129 v = POP(); |
|
19611
8f035800a373
Do the int inlining only if the type is really an int, not whenever
Guido van Rossum <guido@python.org>
parents:
19600
diff
changeset
|
1130 if (ISSTRICTINT(v) && ISSTRICTINT(w)) { |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1131 /* INLINE: int + int */ |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1132 register long a, b, i; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1133 a = PyInt_AS_LONG(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1134 b = PyInt_AS_LONG(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1135 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
|
1136 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
|
1137 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
|
1138 x = PyInt_FromLong(i); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1139 } |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1140 else { |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1141 slow_iadd: |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1142 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
|
1143 } |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1144 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1145 Py_DECREF(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1146 PUSH(x); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1147 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1148 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1149 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1150 case INPLACE_SUBTRACT: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1151 w = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1152 v = POP(); |
|
19611
8f035800a373
Do the int inlining only if the type is really an int, not whenever
Guido van Rossum <guido@python.org>
parents:
19600
diff
changeset
|
1153 if (ISSTRICTINT(v) && ISSTRICTINT(w)) { |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1154 /* INLINE: int - int */ |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1155 register long a, b, i; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1156 a = PyInt_AS_LONG(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1157 b = PyInt_AS_LONG(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1158 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
|
1159 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
|
1160 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
|
1161 x = PyInt_FromLong(i); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1162 } |
|
19434
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1163 else { |
|
c140bd7d3bdc
When an inlined operation on two small ints causes overflow, don't
Guido van Rossum <guido@python.org>
parents:
19369
diff
changeset
|
1164 slow_isub: |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1165 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
|
1166 } |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1167 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1168 Py_DECREF(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1169 PUSH(x); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1170 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1171 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1172 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1173 case INPLACE_LSHIFT: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1174 w = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1175 v = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1176 x = PyNumber_InPlaceLshift(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1177 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1178 Py_DECREF(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1179 PUSH(x); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1180 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1181 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1182 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1183 case INPLACE_RSHIFT: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1184 w = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1185 v = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1186 x = PyNumber_InPlaceRshift(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1187 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1188 Py_DECREF(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1189 PUSH(x); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1190 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1191 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1192 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1193 case INPLACE_AND: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1194 w = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1195 v = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1196 x = PyNumber_InPlaceAnd(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1197 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1198 Py_DECREF(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1199 PUSH(x); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1200 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1201 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1202 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1203 case INPLACE_XOR: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1204 w = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1205 v = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1206 x = PyNumber_InPlaceXor(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1207 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1208 Py_DECREF(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1209 PUSH(x); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1210 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1211 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1212 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1213 case INPLACE_OR: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1214 w = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1215 v = POP(); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1216 x = PyNumber_InPlaceOr(v, w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1217 Py_DECREF(v); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1218 Py_DECREF(w); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1219 PUSH(x); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1220 if (x != NULL) continue; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1221 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1222 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1223 case SLICE+0: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1224 case SLICE+1: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1225 case SLICE+2: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1226 case SLICE+3: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1227 if ((opcode-SLICE) & 2) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1228 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1229 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1230 w = NULL; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1231 if ((opcode-SLICE) & 1) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1232 v = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1233 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1234 v = NULL; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1235 u = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1236 x = apply_slice(u, v, w); |
| 5368 | 1237 Py_DECREF(u); |
| 1238 Py_XDECREF(v); | |
| 1239 Py_XDECREF(w); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1240 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
|
1241 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1242 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
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 STORE_SLICE+0: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1245 case STORE_SLICE+1: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1246 case STORE_SLICE+2: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1247 case STORE_SLICE+3: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1248 if ((opcode-STORE_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-STORE_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 t = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1258 err = assign_slice(u, v, w, t); /* u[v:w] = t */ |
| 5368 | 1259 Py_DECREF(t); |
| 1260 Py_DECREF(u); | |
| 1261 Py_XDECREF(v); | |
| 1262 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
|
1263 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1264 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1265 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1266 case DELETE_SLICE+0: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1267 case DELETE_SLICE+1: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1268 case DELETE_SLICE+2: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1269 case DELETE_SLICE+3: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1270 if ((opcode-DELETE_SLICE) & 2) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1271 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1272 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1273 w = NULL; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1274 if ((opcode-DELETE_SLICE) & 1) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1275 v = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1276 else |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1277 v = NULL; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1278 u = POP(); |
| 5368 | 1279 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
|
1280 /* del u[v:w] */ |
| 5368 | 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 STORE_SUBSCR: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1288 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1289 v = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1290 u = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1291 /* v[w] = u */ |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1292 err = PyObject_SetItem(v, w, u); |
| 5368 | 1293 Py_DECREF(u); |
| 1294 Py_DECREF(v); | |
| 1295 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
|
1296 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1297 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1298 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1299 case DELETE_SUBSCR: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1300 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1301 v = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1302 /* del v[w] */ |
|
5413
10267fdc7531
Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
1303 err = PyObject_DelItem(v, w); |
| 5368 | 1304 Py_DECREF(v); |
| 1305 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
|
1306 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1307 break; |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1308 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1309 case PRINT_EXPR: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1310 v = POP(); |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1311 w = PySys_GetObject("displayhook"); |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1312 if (w == NULL) { |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1313 PyErr_SetString(PyExc_RuntimeError, |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1314 "lost sys.displayhook"); |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1315 err = -1; |
|
15814
faaf9f10d849
Fixed bugs noted by Greg Stein
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15811
diff
changeset
|
1316 x = NULL; |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1317 } |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1318 if (err == 0) { |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1319 x = Py_BuildValue("(O)", v); |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1320 if (x == NULL) |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1321 err = -1; |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1322 } |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1323 if (err == 0) { |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1324 w = PyEval_CallObject(w, x); |
|
15814
faaf9f10d849
Fixed bugs noted by Greg Stein
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15811
diff
changeset
|
1325 Py_XDECREF(w); |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1326 if (w == NULL) |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1327 err = -1; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1328 } |
| 5368 | 1329 Py_DECREF(v); |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1330 Py_XDECREF(x); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1331 break; |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15809
diff
changeset
|
1332 |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1333 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
|
1334 w = stream = POP(); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1335 /* 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
|
1336 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1337 case PRINT_ITEM: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1338 v = POP(); |
|
14238
74f7f237f739
eval_code2(): Guido provides this patch for his suggested elaboration
Barry Warsaw <barry@python.org>
parents:
14232
diff
changeset
|
1339 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
|
1340 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
|
1341 if (w == NULL) { |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1342 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
|
1343 "lost sys.stdout"); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1344 err = -1; |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1345 } |
|
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
|
1346 } |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1347 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
|
1348 err = PyFile_WriteString(" ", w); |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
1349 if (err == 0) |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
1350 err = PyFile_WriteObject(v, w, Py_PRINT_RAW); |
| 5368 | 1351 if (err == 0 && PyString_Check(v)) { |
|
1400
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1352 /* XXX move into writeobject() ? */ |
| 5368 | 1353 char *s = PyString_AsString(v); |
| 1354 int len = PyString_Size(v); | |
| 2310 | 1355 if (len > 0 && |
| 1356 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
|
1357 s[len-1] != ' ') |
| 5368 | 1358 PyFile_SoftSpace(w, 0); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1359 } |
| 5368 | 1360 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
|
1361 Py_XDECREF(stream); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1362 stream = NULL; |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1363 if (err == 0) |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1364 continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1365 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1366 |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1367 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
|
1368 w = stream = POP(); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1369 /* 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
|
1370 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1371 case PRINT_NEWLINE: |
|
14238
74f7f237f739
eval_code2(): Guido provides this patch for his suggested elaboration
Barry Warsaw <barry@python.org>
parents:
14232
diff
changeset
|
1372 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
|
1373 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
|
1374 if (w == NULL) |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1375 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
|
1376 "lost sys.stdout"); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1377 } |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1378 if (w != NULL) { |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1379 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
|
1380 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
|
1381 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
|
1382 } |
|
14100
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1383 Py_XDECREF(stream); |
|
2de0cc174c3b
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14080
diff
changeset
|
1384 stream = NULL; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1385 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1386 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1387 |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1388 #ifdef CASE_TOO_BIG |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1389 default: switch (opcode) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1390 #endif |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1391 case BREAK_LOOP: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1392 why = WHY_BREAK; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1393 break; |
|
17114
6fe13d008e25
Use PyObject_IsInstance() to check whether the first argument to an
Guido van Rossum <guido@python.org>
parents:
17104
diff
changeset
|
1394 |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
1395 case CONTINUE_LOOP: |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
1396 retval = PyInt_FromLong(oparg); |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
1397 why = WHY_CONTINUE; |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
1398 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
|
1399 |
|
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
|
1400 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
|
1401 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
|
1402 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
|
1403 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
|
1404 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
|
1405 /* 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
|
1406 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
|
1407 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
|
1408 /* 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
|
1409 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
|
1410 w = POP(); /* exc */ |
|
7946
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
1411 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
|
1412 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
|
1413 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
|
1414 default: |
| 5368 | 1415 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
|
1416 "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
|
1417 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
|
1418 break; |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1419 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1420 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1421 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1422 case LOAD_LOCALS: |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1423 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
|
1424 PyErr_SetString(PyExc_SystemError, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1425 "no locals"); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1426 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1427 } |
| 5368 | 1428 Py_INCREF(x); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1429 PUSH(x); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1430 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1431 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1432 case RETURN_VALUE: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1433 retval = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1434 why = WHY_RETURN; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1435 break; |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1436 |
|
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
|
1437 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
|
1438 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
|
1439 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
|
1440 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
|
1441 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
|
1442 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
|
1443 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
1444 |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1445 case EXEC_STMT: |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1446 w = POP(); |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1447 v = POP(); |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1448 u = POP(); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1449 err = exec_statement(f, u, v, w); |
| 5368 | 1450 Py_DECREF(u); |
| 1451 Py_DECREF(v); | |
| 1452 Py_DECREF(w); | |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1453 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1454 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1455 case POP_BLOCK: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1456 { |
| 5368 | 1457 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
|
1458 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
|
1459 v = POP(); |
| 5368 | 1460 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1461 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1462 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1463 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1464 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1465 case END_FINALLY: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1466 v = POP(); |
| 5368 | 1467 if (PyInt_Check(v)) { |
| 1468 why = (enum why_code) PyInt_AsLong(v); | |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
1469 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
|
1470 why == WHY_YIELD || |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
1471 why == CONTINUE_LOOP) |
|
173
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 } |
| 5368 | 1474 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
|
1475 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
|
1476 u = POP(); |
| 5368 | 1477 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
|
1478 why = WHY_RERAISE; |
|
2872
d3b07ba3e12d
fix bogus DECREF in finally clause
Guido van Rossum <guido@python.org>
parents:
2866
diff
changeset
|
1479 break; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1480 } |
| 5368 | 1481 else if (v != Py_None) { |
| 1482 PyErr_SetString(PyExc_SystemError, | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1483 "'finally' pops bad exception"); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1484 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1485 } |
| 5368 | 1486 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1487 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1488 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1489 case BUILD_CLASS: |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
1490 u = POP(); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1491 v = POP(); |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
1492 w = POP(); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
1493 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
|
1494 PUSH(x); |
| 5368 | 1495 Py_DECREF(u); |
| 1496 Py_DECREF(v); | |
| 1497 Py_DECREF(w); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1498 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1499 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1500 case STORE_NAME: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1501 w = GETNAMEV(oparg); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1502 v = POP(); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1503 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
|
1504 PyErr_Format(PyExc_SystemError, |
|
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15948
diff
changeset
|
1505 "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
|
1506 PyObject_REPR(w)); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1507 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1508 } |
| 5368 | 1509 err = PyDict_SetItem(x, w, v); |
| 1510 Py_DECREF(v); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1511 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1512 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1513 case DELETE_NAME: |
|
334
449f5e5d9af6
Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents:
314
diff
changeset
|
1514 w = GETNAMEV(oparg); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1515 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
|
1516 PyErr_Format(PyExc_SystemError, |
|
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15948
diff
changeset
|
1517 "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
|
1518 PyObject_REPR(w)); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1519 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1520 } |
| 5368 | 1521 if ((err = PyDict_DelItem(x, w)) != 0) |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1522 format_exc_check_arg(PyExc_NameError, |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1523 NAME_ERROR_MSG ,w); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1524 break; |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
1525 |
|
13930
4eaa463c031a
Merge UNPACK_LIST and UNPACK_TUPLE into a single UNPACK_SEQUENCE, since they
Thomas Wouters <thomas@python.org>
parents:
13881
diff
changeset
|
1526 case UNPACK_SEQUENCE: |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1527 v = POP(); |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1528 if (PyTuple_Check(v)) { |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1529 if (PyTuple_Size(v) != oparg) { |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1530 PyErr_SetString(PyExc_ValueError, |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1531 "unpack tuple of wrong size"); |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1532 why = WHY_EXCEPTION; |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1533 } |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1534 else { |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1535 for (; --oparg >= 0; ) { |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1536 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
|
1537 Py_INCREF(w); |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1538 PUSH(w); |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1539 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1540 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1541 } |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1542 else if (PyList_Check(v)) { |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1543 if (PyList_Size(v) != oparg) { |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1544 PyErr_SetString(PyExc_ValueError, |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1545 "unpack list of wrong size"); |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1546 why = WHY_EXCEPTION; |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1547 } |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1548 else { |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1549 for (; --oparg >= 0; ) { |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1550 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
|
1551 Py_INCREF(w); |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1552 PUSH(w); |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1553 } |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1554 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1555 } |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
1556 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
|
1557 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
|
1558 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
|
1559 else |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
1560 why = WHY_EXCEPTION; |
| 5368 | 1561 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1562 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1563 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1564 case STORE_ATTR: |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1565 w = GETNAMEV(oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1566 v = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1567 u = POP(); |
| 5368 | 1568 err = PyObject_SetAttr(v, w, u); /* v.w = u */ |
| 1569 Py_DECREF(v); | |
| 1570 Py_DECREF(u); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1571 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1572 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1573 case DELETE_ATTR: |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1574 w = GETNAMEV(oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1575 v = POP(); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1576 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
|
1577 /* del v.w */ |
| 5368 | 1578 Py_DECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1579 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1580 |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1581 case STORE_GLOBAL: |
|
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1582 w = GETNAMEV(oparg); |
|
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1583 v = POP(); |
| 5368 | 1584 err = PyDict_SetItem(f->f_globals, w, v); |
| 1585 Py_DECREF(v); | |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1586 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1587 |
|
464
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1588 case DELETE_GLOBAL: |
|
90300ca21200
Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1589 w = GETNAMEV(oparg); |
| 5368 | 1590 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
|
1591 format_exc_check_arg( |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1592 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
|
1593 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1594 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1595 case LOAD_CONST: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1596 x = GETCONST(oparg); |
| 5368 | 1597 Py_INCREF(x); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1598 PUSH(x); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1599 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1600 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1601 case LOAD_NAME: |
|
334
449f5e5d9af6
Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents:
314
diff
changeset
|
1602 w = GETNAMEV(oparg); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1603 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
|
1604 PyErr_Format(PyExc_SystemError, |
|
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15948
diff
changeset
|
1605 "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
|
1606 PyObject_REPR(w)); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1607 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1608 } |
| 5368 | 1609 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
|
1610 if (x == NULL) { |
| 5368 | 1611 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
|
1612 if (x == NULL) { |
| 5368 | 1613 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
|
1614 if (x == NULL) { |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1615 format_exc_check_arg( |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1616 PyExc_NameError, |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1617 NAME_ERROR_MSG ,w); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1618 break; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1619 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1620 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1621 } |
| 5368 | 1622 Py_INCREF(x); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1623 PUSH(x); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1624 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1625 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1626 case LOAD_GLOBAL: |
|
334
449f5e5d9af6
Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents:
314
diff
changeset
|
1627 w = GETNAMEV(oparg); |
| 5368 | 1628 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
|
1629 if (x == NULL) { |
| 5368 | 1630 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
|
1631 if (x == NULL) { |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1632 format_exc_check_arg( |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1633 PyExc_NameError, |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1634 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
|
1635 break; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1636 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1637 } |
| 5368 | 1638 Py_INCREF(x); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1639 PUSH(x); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1640 break; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1641 |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1642 case LOAD_FAST: |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1643 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
|
1644 if (x == NULL) { |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1645 format_exc_check_arg( |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1646 PyExc_UnboundLocalError, |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1647 UNBOUNDLOCAL_ERROR_MSG, |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1648 PyTuple_GetItem(co->co_varnames, oparg) |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1649 ); |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1650 break; |
|
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1651 } |
| 5368 | 1652 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
|
1653 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
|
1654 if (x != NULL) continue; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1655 break; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1656 |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1657 case STORE_FAST: |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
1658 v = POP(); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1659 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
|
1660 continue; |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1661 |
|
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1662 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
|
1663 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
|
1664 if (x == NULL) { |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1665 format_exc_check_arg( |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1666 PyExc_UnboundLocalError, |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1667 UNBOUNDLOCAL_ERROR_MSG, |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1668 PyTuple_GetItem(co->co_varnames, oparg) |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
1669 ); |
|
8318
ec87b62466d3
DELETE_FAST should issue an exception when the local variable is undefined.
Guido van Rossum <guido@python.org>
parents:
7982
diff
changeset
|
1670 break; |
|
ec87b62466d3
DELETE_FAST should issue an exception when the local variable is undefined.
Guido van Rossum <guido@python.org>
parents:
7982
diff
changeset
|
1671 } |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1672 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
|
1673 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1674 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1675 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
|
1676 x = freevars[oparg]; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1677 Py_INCREF(x); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1678 PUSH(x); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1679 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1680 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1681 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
|
1682 x = freevars[oparg]; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1683 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
|
1684 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
|
1685 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
|
1686 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
|
1687 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
|
1688 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
|
1689 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
|
1690 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
|
1691 v); |
|
a34293ced63b
Change error message raised when free variable is not yet bound. It
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17490
diff
changeset
|
1692 } else { |
|
16453
2e3dd62ceac5
SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16398
diff
changeset
|
1693 v = PyTuple_GetItem( |
|
2e3dd62ceac5
SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16398
diff
changeset
|
1694 co->co_freevars, |
|
2e3dd62ceac5
SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16398
diff
changeset
|
1695 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
|
1696 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
|
1697 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
|
1698 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
|
1699 v); |
|
a34293ced63b
Change error message raised when free variable is not yet bound. It
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17490
diff
changeset
|
1700 } |
|
16453
2e3dd62ceac5
SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16398
diff
changeset
|
1701 err = -1; |
|
2e3dd62ceac5
SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16398
diff
changeset
|
1702 break; |
|
2e3dd62ceac5
SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16398
diff
changeset
|
1703 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1704 PUSH(w); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1705 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1706 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1707 case STORE_DEREF: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1708 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
|
1709 x = freevars[oparg]; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1710 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
|
1711 Py_DECREF(w); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1712 continue; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
1713 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1714 case BUILD_TUPLE: |
| 5368 | 1715 x = PyTuple_New(oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1716 if (x != NULL) { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1717 for (; --oparg >= 0;) { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1718 w = POP(); |
| 5368 | 1719 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
|
1720 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1721 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
|
1722 continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1723 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1724 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1725 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1726 case BUILD_LIST: |
| 5368 | 1727 x = PyList_New(oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1728 if (x != NULL) { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1729 for (; --oparg >= 0;) { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1730 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
|
1731 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
|
1732 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1733 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
|
1734 continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1735 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1736 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1737 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1738 case BUILD_MAP: |
| 5368 | 1739 x = PyDict_New(); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1740 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
|
1741 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1742 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1743 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1744 case LOAD_ATTR: |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1745 w = GETNAMEV(oparg); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1746 v = POP(); |
| 5368 | 1747 x = PyObject_GetAttr(v, w); |
| 1748 Py_DECREF(v); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1749 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
|
1750 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1751 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1752 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1753 case COMPARE_OP: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1754 w = POP(); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1755 v = POP(); |
|
19611
8f035800a373
Do the int inlining only if the type is really an int, not whenever
Guido van Rossum <guido@python.org>
parents:
19600
diff
changeset
|
1756 if (ISSTRICTINT(v) && ISSTRICTINT(w)) { |
|
5829
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1757 /* INLINE: cmp(int, int) */ |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1758 register long a, b; |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1759 register int res; |
|
9591
7f90736701a3
Use PyInt_AS_LONG macro instead of explicit inlining.
Guido van Rossum <guido@python.org>
parents:
9513
diff
changeset
|
1760 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
|
1761 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
|
1762 switch (oparg) { |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1763 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
|
1764 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
|
1765 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
|
1766 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
|
1767 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
|
1768 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
|
1769 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
|
1770 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
|
1771 default: goto slow_compare; |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1772 } |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1773 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
|
1774 Py_INCREF(x); |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1775 } |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1776 else { |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1777 slow_compare: |
|
f1127d6fcd74
Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1778 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
|
1779 } |
| 5368 | 1780 Py_DECREF(v); |
| 1781 Py_DECREF(w); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1782 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
|
1783 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1784 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1785 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1786 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
|
1787 w = GETNAMEV(oparg); |
| 5368 | 1788 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
|
1789 if (x == NULL) { |
| 5368 | 1790 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
|
1791 "__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
|
1792 break; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
1793 } |
|
14232
1f1a156ed5af
Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents:
14225
diff
changeset
|
1794 u = POP(); |
| 5368 | 1795 w = Py_BuildValue("(OOOO)", |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1796 w, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1797 f->f_globals, |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1798 f->f_locals == NULL ? |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
1799 Py_None : f->f_locals, |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1800 u); |
| 5368 | 1801 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
|
1802 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
|
1803 x = NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
1804 break; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
1805 } |
| 5368 | 1806 x = PyEval_CallObject(x, w); |
| 1807 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
|
1808 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
|
1809 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1810 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1811 |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
1812 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
|
1813 v = POP(); |
| 5368 | 1814 PyFrame_FastToLocals(f); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1815 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
|
1816 PyErr_SetString(PyExc_SystemError, |
|
16017
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15948
diff
changeset
|
1817 "no locals found during 'import *'"); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1818 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1819 } |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
1820 err = import_all_from(x, v); |
| 5368 | 1821 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
|
1822 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
|
1823 if (err == 0) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1824 break; |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
1825 |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
1826 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
|
1827 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
|
1828 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
|
1829 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
|
1830 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
|
1831 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
|
1832 break; |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
1833 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1834 case JUMP_FORWARD: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1835 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
|
1836 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1837 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1838 case JUMP_IF_FALSE: |
| 5368 | 1839 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
|
1840 if (err > 0) |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
1841 err = 0; |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
1842 else if (err == 0) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1843 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
|
1844 else |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1845 break; |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1846 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1847 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1848 case JUMP_IF_TRUE: |
| 5368 | 1849 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
|
1850 if (err > 0) { |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
1851 err = 0; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1852 JUMPBY(oparg); |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
1853 } |
|
5002
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1854 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
|
1855 ; |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1856 else |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1857 break; |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1858 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1859 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1860 case JUMP_ABSOLUTE: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1861 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
|
1862 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1863 |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1864 case GET_ITER: |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1865 /* before: [obj]; after [getiter(obj)] */ |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1866 v = POP(); |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1867 x = PyObject_GetIter(v); |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1868 Py_DECREF(v); |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1869 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
|
1870 PUSH(x); |
|
aac65f50df6f
Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents:
17600
diff
changeset
|
1871 continue; |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1872 } |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1873 break; |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1874 |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1875 case FOR_ITER: |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1876 /* before: [iter]; after: [iter, iter()] *or* [] */ |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1877 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
|
1878 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
|
1879 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
|
1880 PUSH(x); |
|
aac65f50df6f
Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents:
17600
diff
changeset
|
1881 continue; |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1882 } |
|
17683
e9a4e27e8d4e
Make PyIter_Next() a little smarter (wrt its knowledge of iterator
Tim Peters <tim.peters@gmail.com>
parents:
17636
diff
changeset
|
1883 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
|
1884 /* 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
|
1885 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
|
1886 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
|
1887 JUMPBY(oparg); |
|
aac65f50df6f
Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents:
17600
diff
changeset
|
1888 continue; |
|
aac65f50df6f
Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents:
17600
diff
changeset
|
1889 } |
|
aac65f50df6f
Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents:
17600
diff
changeset
|
1890 break; |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17494
diff
changeset
|
1891 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1892 case FOR_LOOP: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1893 /* for v in s: ... |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1894 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
|
1895 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
|
1896 but if loop exhausted: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1897 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
|
1898 w = POP(); /* Loop index */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1899 v = POP(); /* Sequence object */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1900 u = loop_subscript(v, w); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1901 if (u != NULL) { |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1902 PUSH(v); |
| 5368 | 1903 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
|
1904 PUSH(x); |
| 5368 | 1905 Py_DECREF(w); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1906 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
|
1907 if (x != NULL) continue; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1908 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1909 else { |
| 5368 | 1910 Py_DECREF(v); |
| 1911 Py_DECREF(w); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1912 /* 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
|
1913 but also an error: */ |
| 5368 | 1914 if (PyErr_Occurred()) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1915 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
|
1916 else { |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1917 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
|
1918 continue; |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1919 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1920 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1921 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1922 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1923 case SETUP_LOOP: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1924 case SETUP_EXCEPT: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1925 case SETUP_FINALLY: |
| 5368 | 1926 PyFrame_BlockSetup(f, opcode, INSTR_OFFSET() + oparg, |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
1927 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
|
1928 continue; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1929 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1930 case SET_LINENO: |
| 567 | 1931 #ifdef LLTRACE |
| 1932 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
|
1933 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
|
1934 #endif |
| 567 | 1935 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
|
1936 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
|
1937 continue; |
|
ae3b46a73765
Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents:
4992
diff
changeset
|
1938 /* 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
|
1939 f->f_lasti = INSTR_OFFSET(); |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
1940 /* 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
|
1941 tstate->tracing++; |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
1942 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
|
1943 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
|
1944 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
|
1945 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
|
1946 || 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
|
1947 tstate->tracing--; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
1948 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
|
1949 |
|
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
|
1950 case CALL_FUNCTION: |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1951 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1952 int na = oparg & 0xff; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1953 int nk = (oparg>>8) & 0xff; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1954 int n = na + 2 * nk; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1955 PyObject **pfunc = stack_pointer - n - 1; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1956 PyObject *func = *pfunc; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1957 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
|
1958 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1959 /* Always dispatch PyCFunction first, because |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1960 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
|
1961 callable object. |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1962 */ |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1963 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
|
1964 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
|
1965 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
|
1966 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
|
1967 na, nk); |
|
0769e11d9d5f
Fix bug reported by Tim Peters on python-dev:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17855
diff
changeset
|
1968 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
|
1969 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
|
1970 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
|
1971 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
|
1972 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
|
1973 } else |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
1974 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
|
1975 &stack_pointer, na); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1976 } else { |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1977 if (PyMethod_Check(func) |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1978 && PyMethod_GET_SELF(func) != NULL) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1979 /* optimize access to bound methods */ |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1980 PyObject *self = PyMethod_GET_SELF(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1981 Py_INCREF(self); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1982 func = PyMethod_GET_FUNCTION(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1983 Py_INCREF(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1984 Py_DECREF(*pfunc); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1985 *pfunc = self; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1986 na++; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1987 n++; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1988 } else |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1989 Py_INCREF(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1990 if (PyFunction_Check(func)) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1991 x = fast_function(func, &stack_pointer, |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
1992 n, na, nk); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1993 } else { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1994 x = do_call(func, &stack_pointer, |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1995 na, nk); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1996 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1997 Py_DECREF(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1998 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
1999 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2000 while (stack_pointer > pfunc) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2001 w = POP(); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2002 Py_DECREF(w); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2003 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2004 PUSH(x); |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2005 if (x != NULL) |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2006 continue; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2007 break; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2008 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2009 |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2010 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
|
2011 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
|
2012 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
|
2013 { |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2014 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
|
2015 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
|
2016 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
|
2017 int n = na + 2 * nk; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2018 PyObject **pfunc, *func; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2019 if (flags & CALL_FLAG_VAR) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2020 n++; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2021 if (flags & CALL_FLAG_KW) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2022 n++; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2023 pfunc = stack_pointer - n - 1; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2024 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
|
2025 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
|
2026 |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2027 if (PyMethod_Check(func) |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2028 && PyMethod_GET_SELF(func) != NULL) { |
|
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); |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2030 Py_INCREF(self); |
|
15711
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); |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2033 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
|
2034 *pfunc = self; |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2035 na++; |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
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 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
|
2040 Py_DECREF(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2041 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2042 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
|
2043 w = POP(); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2044 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
|
2045 } |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2046 PUSH(x); |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2047 if (x != NULL) |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2048 continue; |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11839
diff
changeset
|
2049 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
|
2050 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2051 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2052 case MAKE_FUNCTION: |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2053 v = POP(); /* code object */ |
| 5368 | 2054 x = PyFunction_New(v, f->f_globals); |
| 2055 Py_DECREF(v); | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2056 /* XXX Maybe this should be a separate opcode? */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2057 if (x != NULL && oparg > 0) { |
| 5368 | 2058 v = PyTuple_New(oparg); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2059 if (v == NULL) { |
| 5368 | 2060 Py_DECREF(x); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2061 x = NULL; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2062 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2063 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2064 while (--oparg >= 0) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2065 w = POP(); |
| 5368 | 2066 PyTuple_SET_ITEM(v, oparg, w); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2067 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2068 err = PyFunction_SetDefaults(x, v); |
| 5368 | 2069 Py_DECREF(v); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2070 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2071 PUSH(x); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2072 break; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2073 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2074 case MAKE_CLOSURE: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2075 { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2076 int nfree; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2077 v = POP(); /* code object */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2078 x = PyFunction_New(v, f->f_globals); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2079 nfree = PyTuple_GET_SIZE(((PyCodeObject *)v)->co_freevars); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2080 Py_DECREF(v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2081 /* XXX Maybe this should be a separate opcode? */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2082 if (x != NULL && nfree > 0) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2083 v = PyTuple_New(nfree); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2084 if (v == NULL) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2085 Py_DECREF(x); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2086 x = NULL; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2087 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2088 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2089 while (--nfree >= 0) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2090 w = POP(); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2091 PyTuple_SET_ITEM(v, nfree, w); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2092 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2093 err = PyFunction_SetClosure(x, v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2094 Py_DECREF(v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2095 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2096 if (x != NULL && oparg > 0) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2097 v = PyTuple_New(oparg); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2098 if (v == NULL) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2099 Py_DECREF(x); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2100 x = NULL; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2101 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2102 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2103 while (--oparg >= 0) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2104 w = POP(); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2105 PyTuple_SET_ITEM(v, oparg, w); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2106 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2107 err = PyFunction_SetDefaults(x, v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2108 Py_DECREF(v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2109 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2110 PUSH(x); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2111 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2112 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
2113 |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2114 case BUILD_SLICE: |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2115 if (oparg == 3) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2116 w = POP(); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2117 else |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2118 w = NULL; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2119 v = POP(); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2120 u = POP(); |
| 5018 | 2121 x = PySlice_New(u, v, w); |
| 5368 | 2122 Py_DECREF(u); |
| 2123 Py_DECREF(v); | |
| 2124 Py_XDECREF(w); | |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2125 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
|
2126 if (x != NULL) continue; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2127 break; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2128 |
|
14147
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
2129 case EXTENDED_ARG: |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
2130 opcode = NEXTOP(); |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
2131 oparg = oparg<<16 | NEXTARG(); |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14100
diff
changeset
|
2132 goto dispatch_opcode; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3694
diff
changeset
|
2133 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2134 default: |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2135 fprintf(stderr, |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2136 "XXX lineno: %d, opcode: %d\n", |
| 567 | 2137 f->f_lineno, opcode); |
| 5368 | 2138 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
|
2139 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2140 break; |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2141 |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2142 #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
|
2143 } |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2144 #endif |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
2145 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2146 } /* switch */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2147 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2148 on_error: |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2149 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2150 /* Quickly continue if no error occurred */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2151 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2152 if (why == WHY_NOT) { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2153 if (err == 0 && x != NULL) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2154 #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
|
2155 /* This check is expensive! */ |
| 5368 | 2156 if (PyErr_Occurred()) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2157 fprintf(stderr, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2158 "XXX undetected error\n"); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2159 else |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2160 #endif |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2161 continue; /* Normal, fast path */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2162 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2163 why = WHY_EXCEPTION; |
| 5368 | 2164 x = Py_None; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2165 err = 0; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2166 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2167 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2168 /* Double-check exception status */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2169 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2170 if (why == WHY_EXCEPTION || why == WHY_RERAISE) { |
| 5368 | 2171 if (!PyErr_Occurred()) { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2172 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
|
2173 "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
|
2174 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2175 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2176 } |
|
10363
4daab7a9f566
Always test for an error return (usually NULL or -1) without setting
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
2177 #ifdef CHECKEXC |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2178 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
|
2179 /* This check is expensive! */ |
| 5368 | 2180 if (PyErr_Occurred()) { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2181 fprintf(stderr, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2182 "XXX undetected error (why=%d)\n", |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2183 why); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2184 why = WHY_EXCEPTION; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2185 } |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2186 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2187 #endif |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2188 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2189 /* 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
|
2190 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2191 if (why == WHY_EXCEPTION) { |
| 567 | 2192 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
|
2193 if (HAS_ARG(opcode)) |
| 567 | 2194 f->f_lasti -= 2; |
| 5368 | 2195 PyTraceBack_Here(f); |
| 567 | 2196 |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2197 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
|
2198 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
|
2199 call_exc_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
|
2200 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
|
2201 if (tstate->c_profilefunc) |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2202 call_exc_trace(tstate->c_profilefunc, |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2203 tstate->c_profileobj,f); |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2204 } |
|
9513
350f24180dcb
Whoops! One the "redundant" initializations removed by Vladimir in
Guido van Rossum <guido@python.org>
parents:
9490
diff
changeset
|
2205 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2206 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2207 /* 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
|
2208 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2209 if (why == WHY_RERAISE) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2210 why = WHY_EXCEPTION; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2211 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2212 /* Unwind stacks if a (pseudo) exception occurred */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2213 |
|
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
|
2214 while (why != WHY_NOT && why != WHY_YIELD && f->f_iblock > 0) { |
| 5368 | 2215 PyTryBlock *b = PyFrame_BlockPop(f); |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2216 |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2217 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
|
2218 /* For a continue inside a try block, |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2219 don't pop the block for the loop. */ |
|
17114
6fe13d008e25
Use PyObject_IsInstance() to check whether the first argument to an
Guido van Rossum <guido@python.org>
parents:
17104
diff
changeset
|
2220 PyFrame_BlockSetup(f, b->b_type, b->b_level, |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2221 b->b_handler); |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2222 why = WHY_NOT; |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2223 JUMPTO(PyInt_AS_LONG(retval)); |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2224 Py_DECREF(retval); |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2225 break; |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2226 } |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2227 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2228 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
|
2229 v = POP(); |
| 5368 | 2230 Py_XDECREF(v); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2231 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2232 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
|
2233 why = WHY_NOT; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2234 JUMPTO(b->b_handler); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2235 break; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2236 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2237 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
|
2238 (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
|
2239 why == WHY_EXCEPTION)) { |
|
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) { |
| 5368 | 2241 PyObject *exc, *val, *tb; |
| 2242 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
|
2243 if (val == NULL) { |
| 5368 | 2244 val = Py_None; |
| 2245 Py_INCREF(val); | |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2246 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2247 /* Make the raw exception data |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2248 available to the handler, |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2249 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
|
2250 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
|
2251 this for 'finally'. */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2252 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
|
2253 PyErr_NormalizeException( |
|
32aacd753f34
eval_code2(), set_exc_info(): Call PyErr_NormalizeException() the
Barry Warsaw <barry@python.org>
parents:
6160
diff
changeset
|
2254 &exc, &val, &tb); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2255 set_exc_info(tstate, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2256 exc, val, tb); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2257 } |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
2258 PUSH(tb); |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2259 PUSH(val); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2260 PUSH(exc); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2261 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2262 else { |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2263 if (why == WHY_RETURN || |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
2264 why == CONTINUE_LOOP) |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2265 PUSH(retval); |
| 5368 | 2266 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
|
2267 PUSH(v); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2268 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2269 why = WHY_NOT; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2270 JUMPTO(b->b_handler); |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2271 break; |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2272 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2273 } /* unwind stack */ |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2274 |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2275 /* 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
|
2276 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2277 if (why != WHY_NOT) |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2278 break; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2279 |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2280 } /* main loop */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2281 |
|
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
|
2282 if (why != WHY_RETURN && why != WHY_YIELD) |
| 567 | 2283 retval = NULL; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2284 |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2285 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
|
2286 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
|
2287 && (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
|
2288 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
|
2289 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
|
2290 PyTrace_RETURN, retval)) { |
| 5368 | 2291 Py_XDECREF(retval); |
| 567 | 2292 retval = NULL; |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
2293 why = WHY_EXCEPTION; |
| 567 | 2294 } |
| 2295 } | |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2296 if (tstate->c_profilefunc |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2297 && (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
|
2298 if (call_trace(tstate->c_profilefunc, |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2299 tstate->c_profileobj, f, |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2300 PyTrace_RETURN, retval)) { |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2301 Py_XDECREF(retval); |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2302 retval = NULL; |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2303 why = WHY_EXCEPTION; |
|
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2304 } |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
2305 } |
| 567 | 2306 } |
|
5023
75c1ee882a4a
Kill all local variables on function return. This closes a gigantic
Guido van Rossum <guido@python.org>
parents:
5021
diff
changeset
|
2307 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2308 reset_exc_info(tstate); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2309 |
|
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
|
2310 /* pop frame */ |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2311 --tstate->recursion_depth; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2312 tstate->frame = f->f_back; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2313 |
| 567 | 2314 return retval; |
|
173
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2315 } |
|
4656452436e1
Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents:
159
diff
changeset
|
2316 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
2317 PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
2318 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
|
2319 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
|
2320 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
|
2321 { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2322 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
|
2323 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
|
2324 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
|
2325 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
|
2326 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
|
2327 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2328 if (globals == NULL) { |
|
19198
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19158
diff
changeset
|
2329 PyErr_SetString(PyExc_SystemError, |
|
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19158
diff
changeset
|
2330 "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
|
2331 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
|
2332 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2333 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2334 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
|
2335 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
|
2336 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
|
2337 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
|
2338 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
|
2339 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2340 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
|
2341 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
|
2342 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2343 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
|
2344 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
|
2345 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
|
2346 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
|
2347 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
|
2348 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
|
2349 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
|
2350 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
|
2351 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
|
2352 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
|
2353 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
|
2354 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
|
2355 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
|
2356 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2357 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
|
2358 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
|
2359 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
|
2360 "%.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
|
2361 "%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
|
2362 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
|
2363 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
|
2364 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
|
2365 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
|
2366 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
|
2367 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
|
2368 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
|
2369 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2370 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
|
2371 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2372 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
|
2373 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
|
2374 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
|
2375 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
|
2376 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2377 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
|
2378 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
|
2379 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
|
2380 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
|
2381 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
|
2382 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
|
2383 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
|
2384 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
|
2385 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
|
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 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2388 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
|
2389 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
|
2390 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
|
2391 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
|
2392 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
|
2393 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
|
2394 "%.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
|
2395 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
|
2396 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
|
2397 } |
|
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 /* 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
|
2399 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
|
2400 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
|
2401 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
|
2402 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
|
2403 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
|
2404 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
|
2405 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
|
2406 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
|
2407 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
|
2408 } |
|
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 /* 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
|
2410 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
|
2411 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
|
2412 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
|
2413 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
|
2414 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
|
2415 "%.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
|
2416 "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
|
2417 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
|
2418 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
|
2419 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
|
2420 } |
|
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 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
|
2422 } |
|
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 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
|
2424 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
|
2425 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
|
2426 "%.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
|
2427 "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
|
2428 "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
|
2429 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
|
2430 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
|
2431 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
|
2432 } |
|
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(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
|
2434 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
|
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 } |
|
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 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
|
2438 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
|
2439 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
|
2440 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
|
2441 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
|
2442 "%.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
|
2443 "%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
|
2444 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
|
2445 ((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
|
2446 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
|
2447 : "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
|
2448 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
|
2449 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
|
2450 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
|
2451 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2452 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2453 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
|
2454 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
|
2455 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
|
2456 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
|
2457 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
|
2458 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
|
2459 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
|
2460 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
|
2461 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
|
2462 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2463 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2464 } |
|
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 } |
|
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 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
|
2467 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
|
2468 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
|
2469 "%.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
|
2470 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
|
2471 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
|
2472 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
|
2473 } |
|
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 } |
|
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 /* 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
|
2476 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
|
2477 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
|
2478 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
|
2479 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
|
2480 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
|
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 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
|
2483 if (co->co_flags & CO_VARARGS) |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2484 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
|
2485 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
|
2486 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
|
2487 |
|
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 /* 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
|
2489 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
|
2490 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
|
2491 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
|
2492 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
|
2493 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
|
2494 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
|
2495 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
|
2496 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
|
2497 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
|
2498 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
|
2499 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
|
2500 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
|
2501 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
|
2502 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
|
2503 } |
|
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 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
|
2505 } |
|
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 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
|
2507 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
|
2508 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
|
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 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
|
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 } |
|
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 /* 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
|
2514 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
|
2515 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
|
2516 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
|
2517 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
|
2518 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
|
2519 i++; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2520 } |
|
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 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
|
2523 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
|
2524 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
|
2525 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
|
2526 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
|
2527 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
|
2528 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2529 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18136
diff
changeset
|
2530 |
|
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 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
|
2532 /* 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
|
2533 * 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
|
2534 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
|
2535 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
|
2536 |
|
990b73fa074c
Try to avoid creating reference cycles involving generators. Only keep a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18172
diff
changeset
|
2537 /* 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
|
2538 * 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
|
2539 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
|
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 |
|
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 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
|
2543 |
|
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 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
|
2545 |
|
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 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
|
2547 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
|
2548 } |
|
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 |
|
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 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2551 static void |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2552 set_exc_info(PyThreadState *tstate, |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2553 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
|
2554 { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2555 PyFrameObject *frame; |
|
5557
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
2556 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
|
2557 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2558 frame = tstate->frame; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2559 if (frame->f_exc_type == NULL) { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2560 /* 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
|
2561 /* 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
|
2562 if (tstate->exc_type == NULL) { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2563 Py_INCREF(Py_None); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2564 tstate->exc_type = Py_None; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2565 } |
|
5557
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
2566 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
|
2567 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
|
2568 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
|
2569 Py_XINCREF(tstate->exc_type); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2570 Py_XINCREF(tstate->exc_value); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2571 Py_XINCREF(tstate->exc_traceback); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2572 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
|
2573 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
|
2574 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
|
2575 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
|
2576 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
|
2577 Py_XDECREF(tmp_tb); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2578 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2579 /* 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
|
2580 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
|
2581 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
|
2582 tmp_tb = tstate->exc_traceback; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2583 Py_XINCREF(type); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2584 Py_XINCREF(value); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2585 Py_XINCREF(tb); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2586 tstate->exc_type = type; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2587 tstate->exc_value = value; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2588 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
|
2589 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
|
2590 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
|
2591 Py_XDECREF(tmp_tb); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2592 /* For b/w compatibility */ |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2593 PySys_SetObject("exc_type", type); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2594 PySys_SetObject("exc_value", value); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2595 PySys_SetObject("exc_traceback", tb); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2596 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2597 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2598 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
2599 reset_exc_info(PyThreadState *tstate) |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2600 { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2601 PyFrameObject *frame; |
|
5557
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
2602 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
|
2603 frame = tstate->frame; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2604 if (frame->f_exc_type != NULL) { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2605 /* 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
|
2606 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
|
2607 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
|
2608 tmp_tb = tstate->exc_traceback; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2609 Py_XINCREF(frame->f_exc_type); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2610 Py_XINCREF(frame->f_exc_value); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2611 Py_XINCREF(frame->f_exc_traceback); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2612 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
|
2613 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
|
2614 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
|
2615 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
|
2616 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
|
2617 Py_XDECREF(tmp_tb); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2618 /* For b/w compatibility */ |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2619 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
|
2620 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
|
2621 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
|
2622 } |
|
5557
4329e4077cf3
Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents:
5551
diff
changeset
|
2623 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
|
2624 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
|
2625 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
|
2626 frame->f_exc_type = NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2627 frame->f_exc_value = NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2628 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
|
2629 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
|
2630 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
|
2631 Py_XDECREF(tmp_tb); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2632 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2633 |
|
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
|
2634 /* 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
|
2635 This *consumes* a reference count to each of its arguments. */ |
| 5018 | 2636 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
|
2637 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
|
2638 { |
|
7946
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2639 if (type == NULL) { |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2640 /* Reraise */ |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2641 PyThreadState *tstate = PyThreadState_Get(); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2642 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
|
2643 value = tstate->exc_value; |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2644 tb = tstate->exc_traceback; |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2645 Py_XINCREF(type); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2646 Py_XINCREF(value); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2647 Py_XINCREF(tb); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
7014
diff
changeset
|
2648 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2649 |
|
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
|
2650 /* 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
|
2651 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
|
2652 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
|
2653 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
|
2654 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
|
2655 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
|
2656 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
|
2657 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
|
2658 |
|
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
|
2659 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
|
2660 |
|
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
|
2661 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
|
2662 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
|
2663 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
|
2664 |
|
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
|
2665 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
|
2666 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
|
2667 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
|
2668 |
|
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
|
2669 /* 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
|
2670 NULL. */ |
| 5368 | 2671 if (tb == Py_None) { |
| 2672 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
|
2673 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
|
2674 } |
|
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
|
2675 else if (tb != NULL && !PyTraceBack_Check(tb)) { |
| 5368 | 2676 PyErr_SetString(PyExc_TypeError, |
| 15318 | 2677 "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
|
2678 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
|
2679 } |
|
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
|
2680 |
|
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
|
2681 /* 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
|
2682 if (value == NULL) { |
| 5368 | 2683 value = Py_None; |
| 2684 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
|
2685 } |
|
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
|
2686 |
|
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
|
2687 /* Next, repeatedly, replace a tuple exception with its first item */ |
| 5368 | 2688 while (PyTuple_Check(type) && PyTuple_Size(type) > 0) { |
| 2689 PyObject *tmp = type; | |
| 2690 type = PyTuple_GET_ITEM(type, 0); | |
| 2691 Py_INCREF(type); | |
| 2692 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
|
2693 } |
|
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
|
2694 |
|
6147
b76a44163e0f
cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents:
6139
diff
changeset
|
2695 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
|
2696 ; |
|
6147
b76a44163e0f
cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents:
6139
diff
changeset
|
2697 |
|
b76a44163e0f
cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents:
6139
diff
changeset
|
2698 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
|
2699 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
|
2700 |
| 5368 | 2701 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
|
2702 /* Raising an instance. The value should be a dummy. */ |
| 5368 | 2703 if (value != Py_None) { |
| 2704 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
|
2705 "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
|
2706 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
|
2707 } |
|
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
|
2708 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
|
2709 /* Normalize to raise <class>, <instance> */ |
| 5368 | 2710 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
|
2711 value = type; |
| 5368 | 2712 type = (PyObject*) ((PyInstanceObject*)type)->in_class; |
| 2713 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
|
2714 } |
|
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
|
2715 } |
|
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
|
2716 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
|
2717 /* 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
|
2718 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
|
2719 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
|
2720 "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
|
2721 "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
|
2722 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
|
2723 } |
| 5368 | 2724 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
|
2725 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
|
2726 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
|
2727 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
|
2728 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
|
2729 raise_error: |
| 5368 | 2730 Py_XDECREF(value); |
| 2731 Py_XDECREF(type); | |
| 2732 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
|
2733 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
|
2734 } |
|
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 |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2736 /* 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
|
2737 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
|
2738 |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2739 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
|
2740 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
|
2741 { |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2742 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
|
2743 PyObject *it; /* iter(v) */ |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2744 PyObject *w; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
2745 |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2746 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
|
2747 |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2748 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
|
2749 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
|
2750 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
|
2751 |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2752 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
|
2753 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
|
2754 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
|
2755 /* 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
|
2756 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
|
2757 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
|
2758 "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
|
2759 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
|
2760 } |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2761 goto Error; |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2762 } |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2763 *--sp = w; |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2764 } |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2765 |
|
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2766 /* 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
|
2767 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
|
2768 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
|
2769 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
|
2770 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
|
2771 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
|
2772 return 1; |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2773 } |
|
18195
36e825660a24
Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
Tim Peters <tim.peters@gmail.com>
parents:
18194
diff
changeset
|
2774 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
|
2775 /* 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
|
2776 Error: |
|
6160
79592761b331
unpack_sequence(): In finally clause, watch out for Py_DECREF
Barry Warsaw <barry@python.org>
parents:
6157
diff
changeset
|
2777 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
|
2778 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
|
2779 Py_XDECREF(it); |
|
6157
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2780 return 0; |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2781 } |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2782 |
|
647e60fb3bac
eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents:
6147
diff
changeset
|
2783 |
| 567 | 2784 #ifdef LLTRACE |
| 86 | 2785 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
2786 prtrace(PyObject *v, char *str) |
| 69 | 2787 { |
| 86 | 2788 printf("%s ", str); |
| 5368 | 2789 if (PyObject_Print(v, stdout, 0) != 0) |
| 2790 PyErr_Clear(); /* Don't know what else to do */ | |
| 86 | 2791 printf("\n"); |
|
12579
978253542076
Add useless 'return 1' to prtrace() to shut up VC++.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
2792 return 1; |
| 69 | 2793 } |
| 86 | 2794 #endif |
| 69 | 2795 |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
2796 static void |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2797 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
|
2798 { |
| 5368 | 2799 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
|
2800 int err; |
| 5368 | 2801 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
|
2802 if (value == NULL) { |
| 5368 | 2803 value = Py_None; |
| 2804 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
|
2805 } |
| 5368 | 2806 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
|
2807 if (arg == NULL) { |
| 5368 | 2808 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
|
2809 return; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2006
diff
changeset
|
2810 } |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2811 err = call_trace(func, self, f, PyTrace_EXCEPTION, arg); |
| 5368 | 2812 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
|
2813 if (err == 0) |
| 5368 | 2814 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
|
2815 else { |
| 5368 | 2816 Py_XDECREF(type); |
| 2817 Py_XDECREF(value); | |
| 2818 Py_XDECREF(traceback); | |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
2819 } |
|
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
2820 } |
|
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
2821 |
|
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
2822 static int |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2823 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
|
2824 int what, PyObject *arg) |
| 567 | 2825 { |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2826 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
|
2827 int result; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2828 if (tstate->tracing) |
|
708
8bcb50f436fa
New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents:
688
diff
changeset
|
2829 return 0; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2830 tstate->tracing++; |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18326
diff
changeset
|
2831 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
|
2832 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
|
2833 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
|
2834 || (tstate->c_profilefunc != NULL)); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2835 tstate->tracing--; |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2836 return result; |
| 567 | 2837 } |
| 2838 | |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2839 void |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2840 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
|
2841 { |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2842 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
|
2843 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
|
2844 Py_XINCREF(arg); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2845 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
|
2846 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
|
2847 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
|
2848 Py_XDECREF(temp); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2849 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
|
2850 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
|
2851 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
|
2852 } |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2853 |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2854 void |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2855 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
|
2856 { |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2857 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
|
2858 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
|
2859 Py_XINCREF(arg); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2860 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
|
2861 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
|
2862 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
|
2863 Py_XDECREF(temp); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18293
diff
changeset
|
2864 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
|
2865 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
|
2866 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
|
2867 || (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
|
2868 } |
|
4cb34314bd97
Instead of initializing & interning the strings passed to the profile
Fred Drake <fdrake@acm.org>
parents:
18128
diff
changeset
|
2869 |
| 5368 | 2870 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
2871 PyEval_GetBuiltins(void) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
2872 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
2873 PyThreadState *tstate = PyThreadState_Get(); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
2874 PyFrameObject *current_frame = tstate->frame; |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
2875 if (current_frame == NULL) |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5911
diff
changeset
|
2876 return tstate->interp->builtins; |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
2877 else |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
2878 return current_frame->f_builtins; |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
2879 } |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
2880 |
| 5368 | 2881 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
2882 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
|
2883 { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2884 PyFrameObject *current_frame = PyThreadState_Get()->frame; |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2885 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
|
2886 return NULL; |
| 5368 | 2887 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
|
2888 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
|
2889 } |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2890 |
| 5368 | 2891 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
2892 PyEval_GetGlobals(void) |
| 69 | 2893 { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2894 PyFrameObject *current_frame = PyThreadState_Get()->frame; |
| 86 | 2895 if (current_frame == NULL) |
| 2896 return NULL; | |
| 2897 else | |
| 2898 return current_frame->f_globals; | |
| 69 | 2899 } |
| 2900 | |
| 5368 | 2901 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
2902 PyEval_GetFrame(void) |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
2903 { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2904 PyFrameObject *current_frame = PyThreadState_Get()->frame; |
| 5368 | 2905 return (PyObject *)current_frame; |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
2906 } |
|
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
2907 |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
2908 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
2909 PyEval_GetRestricted(void) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
2910 { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2911 PyFrameObject *current_frame = PyThreadState_Get()->frame; |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
2912 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
|
2913 } |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2088
diff
changeset
|
2914 |
|
5606
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
2915 int |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
2916 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
|
2917 { |
|
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
|
2918 PyFrameObject *current_frame = PyThreadState_Get()->frame; |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
2919 int result = 0; |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
2920 |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
2921 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
|
2922 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
|
2923 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
|
2924 if (compilerflags) { |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
2925 result = 1; |
|
19350
5b6a6d7d44ae
ceval, PyEval_MergeCompilerFlags: wasn't merging in the
Tim Peters <tim.peters@gmail.com>
parents:
19301
diff
changeset
|
2926 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
|
2927 } |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
2928 } |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
2929 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
|
2930 } |
|
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
|
2931 |
|
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
|
2932 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
2933 Py_FlushLine(void) |
| 69 | 2934 { |
| 5368 | 2935 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
|
2936 if (f == NULL) |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
2937 return 0; |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
2938 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
|
2939 return 0; |
|
495fbde64a73
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5557
diff
changeset
|
2940 return PyFile_WriteString("\n", f); |
| 69 | 2941 } |
| 2942 | |
| 86 | 2943 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2944 /* External interface to call any callable object. |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2945 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
|
2946 |
|
6206
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
2947 #undef PyEval_CallObject |
|
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
2948 /* for backward compatibility: export this interface */ |
|
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
2949 |
| 5368 | 2950 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
2951 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
|
2952 { |
| 5368 | 2953 return PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2954 } |
|
6206
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
2955 #define PyEval_CallObject(func,arg) \ |
|
77f5b6cbea66
Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents:
6185
diff
changeset
|
2956 PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2957 |
| 5368 | 2958 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
2959 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
|
2960 { |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2961 PyObject *result; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2962 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2963 if (arg == NULL) |
| 5368 | 2964 arg = PyTuple_New(0); |
| 2965 else if (!PyTuple_Check(arg)) { | |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2966 PyErr_SetString(PyExc_TypeError, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2967 "argument list must be a tuple"); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2968 return NULL; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2969 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2970 else |
| 5368 | 2971 Py_INCREF(arg); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2972 |
| 5368 | 2973 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
|
2974 PyErr_SetString(PyExc_TypeError, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
2975 "keyword list must be a dictionary"); |
|
12440
d47460b1a679
Charles Waldman writes:
Guido van Rossum <guido@python.org>
parents:
12320
diff
changeset
|
2976 Py_DECREF(arg); |
|
2894
4095782c940e
empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents:
2872
diff
changeset
|
2977 return NULL; |
|
4095782c940e
empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents:
2872
diff
changeset
|
2978 } |
|
4095782c940e
empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents:
2872
diff
changeset
|
2979 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
2980 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
|
2981 Py_DECREF(arg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2982 return result; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2983 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
2984 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
2985 char * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
2986 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
|
2987 { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
2988 if (PyMethod_Check(func)) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
2989 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
|
2990 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
|
2991 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
|
2992 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
|
2993 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
|
2994 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
|
2995 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
|
2996 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
|
2997 return PyString_AsString( |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
2998 ((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
|
2999 } else { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3000 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
|
3001 } |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3002 } |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3003 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3004 char * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3005 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
|
3006 { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3007 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
|
3008 return "()"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3009 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
|
3010 return "()"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3011 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
|
3012 return "()"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3013 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
|
3014 return " constructor"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3015 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
|
3016 return " instance"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3017 } else { |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3018 return " object"; |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3019 } |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3020 } |
|
c9e07bc303a2
Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17125
diff
changeset
|
3021 |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3022 #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
|
3023 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3024 /* 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
|
3025 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
|
3026 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
|
3027 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
|
3028 */ |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3029 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3030 static PyObject * |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3031 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
|
3032 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3033 PyCFunction meth = PyCFunction_GET_FUNCTION(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3034 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
|
3035 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
|
3036 |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3037 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
|
3038 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
|
3039 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
|
3040 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
|
3041 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
|
3042 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
|
3043 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
|
3044 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
|
3045 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
|
3046 } else { |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3047 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
|
3048 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
|
3049 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
|
3050 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
|
3051 } |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3052 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
|
3053 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
|
3054 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
|
3055 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
|
3056 "%.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
|
3057 ((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
|
3058 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
|
3059 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
|
3060 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
|
3061 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
|
3062 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
|
3063 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
|
3064 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
|
3065 } |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3066 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
|
3067 "%.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
|
3068 ((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
|
3069 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
|
3070 default: |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
3071 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
|
3072 ((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
|
3073 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
|
3074 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
|
3075 } |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3076 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3077 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3078 static PyObject * |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3079 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
|
3080 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3081 PyObject *co = PyFunction_GET_CODE(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3082 PyObject *globals = PyFunction_GET_GLOBALS(func); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3083 PyObject *argdefs = PyFunction_GET_DEFAULTS(func); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
3084 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
|
3085 PyObject **d = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3086 int nd = 0; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3087 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3088 if (argdefs != NULL) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3089 d = &PyTuple_GET_ITEM(argdefs, 0); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3090 nd = ((PyTupleObject *)argdefs)->ob_size; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3091 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3092 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
|
3093 (PyObject *)NULL, (*pp_stack)-n, na, |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
3094 (*pp_stack)-2*nk, nk, d, nd, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16017
diff
changeset
|
3095 closure); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3096 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3097 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3098 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
|
3099 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
|
3100 PyObject *func) |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3101 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3102 PyObject *kwdict = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3103 if (orig_kwdict == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3104 kwdict = PyDict_New(); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3105 else { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3106 kwdict = PyDict_Copy(orig_kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3107 Py_DECREF(orig_kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3108 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3109 if (kwdict == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3110 return NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3111 while (--nk >= 0) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3112 int err; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3113 PyObject *value = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3114 PyObject *key = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3115 if (PyDict_GetItem(kwdict, key) != NULL) { |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3116 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
|
3117 "%.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
|
3118 "for keyword argument '%.200s'", |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3119 PyEval_GetFuncName(func), |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3120 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
|
3121 PyString_AsString(key)); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3122 Py_DECREF(key); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3123 Py_DECREF(value); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3124 Py_DECREF(kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3125 return NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3126 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3127 err = PyDict_SetItem(kwdict, key, value); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3128 Py_DECREF(key); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3129 Py_DECREF(value); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3130 if (err) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3131 Py_DECREF(kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3132 return NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3133 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3134 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3135 return kwdict; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3136 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3137 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3138 static PyObject * |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3139 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
|
3140 PyObject ***pp_stack) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3141 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3142 PyObject *callargs, *w; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3143 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3144 callargs = PyTuple_New(nstack + nstar); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3145 if (callargs == NULL) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3146 return NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3147 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3148 if (nstar) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3149 int i; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3150 for (i = 0; i < nstar; i++) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3151 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
|
3152 Py_INCREF(a); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3153 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
|
3154 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3155 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3156 while (--nstack >= 0) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3157 w = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3158 PyTuple_SET_ITEM(callargs, nstack, w); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3159 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3160 return callargs; |
|
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 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3163 static PyObject * |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3164 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
|
3165 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3166 PyObject *args = PyTuple_New(na); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3167 PyObject *w; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3168 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3169 if (args == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3170 return NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3171 while (--na >= 0) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3172 w = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3173 PyTuple_SET_ITEM(args, na, w); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3174 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3175 return args; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3176 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3177 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3178 static PyObject * |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3179 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
|
3180 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3181 PyObject *callargs = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3182 PyObject *kwdict = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3183 PyObject *result = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3184 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3185 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
|
3186 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
|
3187 if (kwdict == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3188 goto call_fail; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3189 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3190 callargs = load_args(pp_stack, na); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3191 if (callargs == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3192 goto call_fail; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3193 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
|
3194 call_fail: |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3195 Py_XDECREF(callargs); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3196 Py_XDECREF(kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3197 return result; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3198 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3199 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3200 static PyObject * |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3201 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
|
3202 { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3203 int nstar = 0; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3204 PyObject *callargs = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3205 PyObject *stararg = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3206 PyObject *kwdict = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3207 PyObject *result = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3208 |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3209 if (flags & CALL_FLAG_KW) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3210 kwdict = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3211 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
|
3212 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
|
3213 "%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
|
3214 "must be a dictionary", |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3215 PyEval_GetFuncName(func), |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3216 PyEval_GetFuncDesc(func)); |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3217 goto ext_call_fail; |
|
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 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3220 if (flags & CALL_FLAG_VAR) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3221 stararg = EXT_POP(*pp_stack); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3222 if (!PyTuple_Check(stararg)) { |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3223 PyObject *t = NULL; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3224 t = PySequence_Tuple(stararg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3225 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
|
3226 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
|
3227 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
|
3228 "%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
|
3229 "must be a sequence", |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3230 PyEval_GetFuncName(func), |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3231 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
|
3232 } |
|
15711
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3233 goto ext_call_fail; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3234 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3235 Py_DECREF(stararg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3236 stararg = t; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3237 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3238 nstar = PyTuple_GET_SIZE(stararg); |
|
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 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
|
3241 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
|
3242 if (kwdict == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3243 goto ext_call_fail; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3244 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3245 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
|
3246 if (callargs == NULL) |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3247 goto ext_call_fail; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3248 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
|
3249 ext_call_fail: |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3250 Py_XDECREF(callargs); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3251 Py_XDECREF(kwdict); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3252 Py_XDECREF(stararg); |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3253 return result; |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3254 } |
|
2481b5fe86d6
Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15364
diff
changeset
|
3255 |
|
3863
4566a19c3438
Better error message if stride used on normal sequence object
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
3256 #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
|
3257 "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
|
3258 |
| 5368 | 3259 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3260 loop_subscript(PyObject *v, PyObject *w) |
| 69 | 3261 { |
| 5368 | 3262 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
|
3263 int i; |
|
8403
c4df8b6637b6
Moved cmp_member() to abstract.c, as PySequence_Contains() [with
Guido van Rossum <guido@python.org>
parents:
8328
diff
changeset
|
3264 if (sq == NULL || sq->sq_item == NULL) { |
| 5368 | 3265 PyErr_SetString(PyExc_TypeError, "loop over non-sequence"); |
| 69 | 3266 return NULL; |
| 3267 } | |
| 5368 | 3268 i = PyInt_AsLong(w); |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
3269 v = (*sq->sq_item)(v, i); |
|
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
3270 if (v) |
|
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
3271 return v; |
|
6147
b76a44163e0f
cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents:
6139
diff
changeset
|
3272 if (PyErr_ExceptionMatches(PyExc_IndexError)) |
| 5368 | 3273 PyErr_Clear(); |
|
1846
5243fb187d36
call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents:
1425
diff
changeset
|
3274 return NULL; |
| 69 | 3275 } |
| 3276 | |
| 12614 | 3277 /* Extract a slice index from a PyInt or PyLong, the index is bound to |
| 3278 the range [-INT_MAX+1, INTMAX]. Returns 0 and an exception if there is | |
| 3279 and error. Returns 1 on success.*/ | |
| 3280 | |
| 3281 int | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3282 _PyEval_SliceIndex(PyObject *v, int *pi) |
| 69 | 3283 { |
| 3284 if (v != NULL) { | |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3285 long x; |
|
11839
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3286 if (PyInt_Check(v)) { |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3287 x = PyInt_AsLong(v); |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3288 } else if (PyLong_Check(v)) { |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3289 x = PyLong_AsLong(v); |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3290 if (x==-1 && PyErr_Occurred()) { |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3291 PyObject *long_zero; |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3292 int cmp; |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3293 |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3294 if (!PyErr_ExceptionMatches( |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3295 PyExc_OverflowError)) { |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3296 /* 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
|
3297 signal an error */ |
| 12614 | 3298 return 0; |
|
11839
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3299 } |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3300 |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3301 /* Clear the OverflowError */ |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3302 PyErr_Clear(); |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3303 |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3304 /* It's an overflow error, so we need to |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3305 check the sign of the long integer, |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3306 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
|
3307 the error. */ |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3308 |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3309 /* 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
|
3310 long_zero = PyLong_FromLong(0L); |
| 12614 | 3311 if (long_zero == NULL) return 0; |
|
11839
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3312 |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3313 /* Check sign */ |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3314 cmp = PyObject_RichCompareBool(v, long_zero, |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3315 Py_GT); |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3316 Py_DECREF(long_zero); |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3317 if (cmp < 0) |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3318 return 0; |
|
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3319 else if (cmp > 0) |
|
11839
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3320 x = INT_MAX; |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3321 else |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3322 x = 0; |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3323 } |
|
91cfb6e68ca4
Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents:
11827
diff
changeset
|
3324 } else { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3325 PyErr_SetString(PyExc_TypeError, |
| 15318 | 3326 "slice indices must be integers"); |
| 12614 | 3327 return 0; |
| 69 | 3328 } |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3329 /* 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
|
3330 if (x > INT_MAX) |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3331 x = INT_MAX; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3332 else if (x < -INT_MAX) |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3333 x = 0; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5368
diff
changeset
|
3334 *pi = x; |
| 69 | 3335 } |
| 12614 | 3336 return 1; |
| 69 | 3337 } |
| 3338 | |
| 19369 | 3339 #undef ISINT |
| 3340 #define ISINT(x) ((x) == NULL || PyInt_Check(x) || PyLong_Check(x)) | |
| 3341 | |
| 5368 | 3342 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3343 apply_slice(PyObject *u, PyObject *v, PyObject *w) /* return u[v:w] */ |
| 69 | 3344 { |
| 19369 | 3345 PyTypeObject *tp = u->ob_type; |
| 3346 PySequenceMethods *sq = tp->tp_as_sequence; | |
| 3347 | |
| 3348 if (sq && sq->sq_slice && ISINT(v) && ISINT(w)) { | |
| 3349 int ilow = 0, ihigh = INT_MAX; | |
| 3350 if (!_PyEval_SliceIndex(v, &ilow)) | |
| 3351 return NULL; | |
| 3352 if (!_PyEval_SliceIndex(w, &ihigh)) | |
| 3353 return NULL; | |
| 3354 return PySequence_GetSlice(u, ilow, ihigh); | |
| 3355 } | |
| 3356 else { | |
| 3357 PyObject *slice = PySlice_New(v, w, NULL); | |
| 3358 if (slice != NULL) | |
| 3359 return PyObject_GetItem(u, slice); | |
| 3360 else | |
| 3361 return NULL; | |
| 3362 } | |
| 69 | 3363 } |
| 86 | 3364 |
| 3365 static int | |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3366 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
|
3367 /* u[v:w] = x */ |
| 69 | 3368 { |
| 19369 | 3369 PyTypeObject *tp = u->ob_type; |
| 3370 PySequenceMethods *sq = tp->tp_as_sequence; | |
| 3371 | |
| 3372 if (sq && sq->sq_slice && ISINT(v) && ISINT(w)) { | |
| 3373 int ilow = 0, ihigh = INT_MAX; | |
| 3374 if (!_PyEval_SliceIndex(v, &ilow)) | |
| 3375 return -1; | |
| 3376 if (!_PyEval_SliceIndex(w, &ihigh)) | |
| 3377 return -1; | |
| 3378 if (x == NULL) | |
| 3379 return PySequence_DelSlice(u, ilow, ihigh); | |
| 3380 else | |
| 3381 return PySequence_SetSlice(u, ilow, ihigh, x); | |
| 3382 } | |
| 3383 else { | |
| 3384 PyObject *slice = PySlice_New(v, w, NULL); | |
| 3385 if (slice != NULL) { | |
| 3386 if (x != NULL) | |
| 3387 return PyObject_SetItem(u, slice, x); | |
| 3388 else | |
| 3389 return PyObject_DelItem(u, slice); | |
| 3390 } | |
| 3391 else | |
| 3392 return -1; | |
| 3393 } | |
| 69 | 3394 } |
| 3395 | |
| 5368 | 3396 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3397 cmp_outcome(int op, register PyObject *v, register PyObject *w) |
| 69 | 3398 { |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3399 int res = 0; |
| 69 | 3400 switch (op) { |
| 86 | 3401 case IS: |
| 3402 case IS_NOT: | |
| 3403 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
|
3404 if (op == (int) IS_NOT) |
| 86 | 3405 res = !res; |
| 3406 break; | |
| 69 | 3407 case IN: |
| 3408 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
|
3409 res = PySequence_Contains(w, v); |
| 86 | 3410 if (res < 0) |
| 3411 return NULL; | |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
3412 if (op == (int) NOT_IN) |
| 86 | 3413 res = !res; |
| 69 | 3414 break; |
| 3415 case EXC_MATCH: | |
|
6147
b76a44163e0f
cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents:
6139
diff
changeset
|
3416 res = PyErr_GivenExceptionMatches(v, w); |
| 69 | 3417 break; |
| 3418 default: | |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3419 return PyObject_RichCompare(v, w, op); |
| 69 | 3420 } |
| 5368 | 3421 v = res ? Py_True : Py_False; |
| 3422 Py_INCREF(v); | |
| 69 | 3423 return v; |
| 3424 } | |
| 3425 | |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
3426 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
|
3427 import_from(PyObject *v, PyObject *name) |
|
72
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3428 { |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3429 PyObject *x; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3430 |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3431 x = PyObject_GetAttr(v, name); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3432 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
|
3433 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
|
3434 "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
|
3435 PyString_AsString(name)); |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3436 } |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
3437 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
|
3438 } |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3439 |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
3440 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
|
3441 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
|
3442 { |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3443 PyObject *all = PyObject_GetAttrString(v, "__all__"); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3444 PyObject *dict, *name, *value; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3445 int skip_leading_underscores = 0; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3446 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
|
3447 |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3448 if (all == NULL) { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3449 if (!PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3450 return -1; /* Unexpected error */ |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3451 PyErr_Clear(); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3452 dict = PyObject_GetAttrString(v, "__dict__"); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3453 if (dict == NULL) { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3454 if (!PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3455 return -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3456 PyErr_SetString(PyExc_ImportError, |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3457 "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
|
3458 return -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3459 } |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3460 all = PyMapping_Keys(dict); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3461 Py_DECREF(dict); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3462 if (all == NULL) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3463 return -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3464 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
|
3465 } |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
3466 |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3467 for (pos = 0, err = 0; ; pos++) { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3468 name = PySequence_GetItem(all, pos); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3469 if (name == NULL) { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3470 if (!PyErr_ExceptionMatches(PyExc_IndexError)) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3471 err = -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3472 else |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3473 PyErr_Clear(); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3474 break; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3475 } |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3476 if (skip_leading_underscores && |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3477 PyString_Check(name) && |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3478 PyString_AS_STRING(name)[0] == '_') |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3479 { |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3480 Py_DECREF(name); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3481 continue; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3482 } |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3483 value = PyObject_GetAttr(v, name); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3484 if (value == NULL) |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3485 err = -1; |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3486 else |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3487 err = PyDict_SetItem(locals, name, value); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3488 Py_DECREF(name); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3489 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
|
3490 if (err != 0) |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3491 break; |
|
72
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3492 } |
|
15830
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3493 Py_DECREF(all); |
|
e00f718e4d8a
Two changes to from...import:
Guido van Rossum <guido@python.org>
parents:
15814
diff
changeset
|
3494 return err; |
|
72
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3495 } |
|
5e8a0b40a4bd
Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3496 |
| 5368 | 3497 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3498 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
|
3499 { |
|
19890
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3500 PyObject *metaclass = NULL, *result, *base; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3501 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3502 if (PyDict_Check(methods)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18611
diff
changeset
|
3503 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
|
3504 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
|
3505 Py_INCREF(methods); |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3506 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
|
3507 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
|
3508 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
|
3509 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
|
3510 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
|
3511 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
|
3512 Py_INCREF(metaclass); |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
3513 } |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
3514 } |
|
19890
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3515 else { |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3516 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
|
3517 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
|
3518 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
|
3519 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
|
3520 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
|
3521 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
|
3522 } |
|
31fe8b3e276b
build_class(): one more (hopefully the last) step on the way to
Guido van Rossum <guido@python.org>
parents:
19692
diff
changeset
|
3523 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
|
3524 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
|
3525 return result; |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
3526 } |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
3527 |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3528 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3529 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
|
3530 PyObject *locals) |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3531 { |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3532 int n; |
| 5368 | 3533 PyObject *v; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3534 int plain = 0; |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3535 |
| 5368 | 3536 if (PyTuple_Check(prog) && globals == Py_None && locals == Py_None && |
| 3537 ((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
|
3538 /* Backward compatibility hack */ |
| 5368 | 3539 globals = PyTuple_GetItem(prog, 1); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3540 if (n == 3) |
| 5368 | 3541 locals = PyTuple_GetItem(prog, 2); |
| 3542 prog = PyTuple_GetItem(prog, 0); | |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3543 } |
| 5368 | 3544 if (globals == Py_None) { |
| 3545 globals = PyEval_GetGlobals(); | |
| 3546 if (locals == Py_None) { | |
| 3547 locals = PyEval_GetLocals(); | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3548 plain = 1; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3549 } |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3550 } |
| 5368 | 3551 else if (locals == Py_None) |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3552 locals = globals; |
| 5368 | 3553 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
|
3554 !PyUnicode_Check(prog) && |
| 5368 | 3555 !PyCode_Check(prog) && |
| 3556 !PyFile_Check(prog)) { | |
| 3557 PyErr_SetString(PyExc_TypeError, | |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3558 "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
|
3559 return -1; |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3560 } |
| 15318 | 3561 if (!PyDict_Check(globals)) { |
| 5368 | 3562 PyErr_SetString(PyExc_TypeError, |
| 15318 | 3563 "exec: arg 2 must be a dictionary or None"); |
| 3564 return -1; | |
| 3565 } | |
| 3566 if (!PyDict_Check(locals)) { | |
| 3567 PyErr_SetString(PyExc_TypeError, | |
| 3568 "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
|
3569 return -1; |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3570 } |
| 5368 | 3571 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
|
3572 PyDict_SetItemString(globals, "__builtins__", f->f_builtins); |
| 5368 | 3573 if (PyCode_Check(prog)) { |
|
11651
d88996e46cb2
Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents:
11468
diff
changeset
|
3574 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
|
3575 } |
|
11651
d88996e46cb2
Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents:
11468
diff
changeset
|
3576 else if (PyFile_Check(prog)) { |
| 5368 | 3577 FILE *fp = PyFile_AsFile(prog); |
| 3578 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
|
3579 PyCompilerFlags cf; |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3580 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
|
3581 if (PyEval_MergeCompilerFlags(&cf)) |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
3582 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
|
3583 locals, &cf); |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3584 else |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
3585 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
|
3586 locals); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3587 } |
|
11651
d88996e46cb2
Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents:
11468
diff
changeset
|
3588 else { |
|
14696
85038a024b19
This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents:
14375
diff
changeset
|
3589 char *str; |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3590 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
|
3591 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
|
3592 return -1; |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3593 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
|
3594 if (PyEval_MergeCompilerFlags(&cf)) |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
3595 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
|
3596 locals, &cf); |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18513
diff
changeset
|
3597 else |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
3598 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
|
3599 } |
|
11651
d88996e46cb2
Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents:
11468
diff
changeset
|
3600 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
|
3601 PyFrame_LocalsToFast(f, 0); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3602 if (v == NULL) |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3603 return -1; |
| 5368 | 3604 Py_DECREF(v); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3605 return 0; |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3606 } |
|
2338
4c2f1452125d
call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents:
2310
diff
changeset
|
3607 |
|
15948
3bc2440427d3
Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents:
15899
diff
changeset
|
3608 static void |
|
14268
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
3609 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
|
3610 { |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
3611 char *obj_str; |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
3612 |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
3613 if (!obj) |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
3614 return; |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
3615 |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
3616 obj_str = PyString_AsString(obj); |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
3617 if (!obj_str) |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
3618 return; |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
3619 |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
3620 PyErr_Format(exc, format_str, obj_str); |
|
cd8b815cb196
Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents:
14238
diff
changeset
|
3621 } |
|
5049
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3622 |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3623 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3624 |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3625 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3626 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
|
3627 { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3628 int i; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3629 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
|
3630 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
|
3631 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
|
3632 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
|
3633 if (x == NULL) { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3634 Py_DECREF(l); |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3635 return NULL; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3636 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3637 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
|
3638 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3639 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
|
3640 a[i] = 0; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3641 return l; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3642 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3643 |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3644 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
3645 _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
|
3646 { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3647 #ifndef DXPAIRS |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3648 return getarray(dxp); |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3649 #else |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3650 int i; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3651 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
|
3652 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
|
3653 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
|
3654 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
|
3655 if (x == NULL) { |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3656 Py_DECREF(l); |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3657 return NULL; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3658 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3659 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
|
3660 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3661 return l; |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3662 #endif |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3663 } |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3664 |
|
946b2b2a7622
Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents:
5048
diff
changeset
|
3665 #endif |
