annotate Python/ceval.c @ 17683:e9a4e27e8d4e legacy-trunk

Make PyIter_Next() a little smarter (wrt its knowledge of iterator internals) so clients can be a lot dumber (wrt their knowledge).
author Tim Peters <tim.peters@gmail.com>
date Sat, 05 May 2001 00:14:56 +0000
parents 9921a9d27f72
children d2d3f88661a3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
1
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2 /* Execute compiled code */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
4 /* XXX TO DO:
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
5 XXX how to pass arguments to call_trace?
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
6 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
7 XXX document it!
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
8 */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
9
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
10 #include "Python.h"
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
11
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 #include "compile.h"
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
13 #include "frameobject.h"
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
14 #include "eval.h"
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 #include "opcode.h"
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
27 /* For debugging the interpreter: */
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
28 #define LLTRACE 1 /* Low-level trace feature */
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
29 #define CHECKEXC 1 /* Double-check exception checking */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 #endif
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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 */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
35
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
36 static PyObject *eval_code2(PyCodeObject *,
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
37 PyObject *, PyObject *,
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
38 PyObject **, int,
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
39 PyObject **, int,
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
40 PyObject **, int,
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
41 PyObject *);
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
42
17406
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
43 static char *get_func_name(PyObject *);
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
44 static char *get_func_desc(PyObject *);
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
45 static PyObject *call_object(PyObject *, PyObject *, PyObject *);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
46 static PyObject *call_cfunction(PyObject *, PyObject *, PyObject *);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
47 static PyObject *call_instance(PyObject *, PyObject *, PyObject *);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
48 static PyObject *call_method(PyObject *, PyObject *, PyObject *);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
49 static PyObject *call_eval_code2(PyObject *, PyObject *, PyObject *);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
50 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
51 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
52 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
53 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
54 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
55 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
56 static PyObject *load_args(PyObject ***, int);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
57 #define CALL_FLAG_VAR 1
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
58 #define CALL_FLAG_KW 2
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
59
746
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
60 #ifdef LLTRACE
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
61 static int prtrace(PyObject *, char *);
746
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
62 #endif
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
63 static void call_exc_trace(PyObject **, PyObject**, PyFrameObject *);
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
64 static int call_trace(PyObject **, PyObject **,
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
65 PyFrameObject *, char *, PyObject *);
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
66 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
67 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
68 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
69 PyObject *, PyObject *);
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
70 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
71 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
72 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
73 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
74 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
75 PyObject *, PyObject *, PyObject *);
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
76 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
77 static void reset_exc_info(PyThreadState *);
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
78 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
79
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
80 #define NAME_ERROR_MSG \
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 15166
diff changeset
81 "name '%.200s' is not defined"
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
82 #define GLOBAL_NAME_ERROR_MSG \
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
83 "global name '%.200s' is not defined"
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
84 #define UNBOUNDLOCAL_ERROR_MSG \
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 15166
diff changeset
85 "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
86 #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
87 "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
88 " in enclosing scope"
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
89
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
90 /* Dynamic execution profile */
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
91 #ifdef DYNAMIC_EXECUTION_PROFILE
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
92 #ifdef DXPAIRS
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
93 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
94 #define dxp dxpairs[256]
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
95 #else
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
96 static long dxp[256];
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
97 #endif
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
98 #endif
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
99
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
100 #ifdef WITH_THREAD
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
101
10530
d834ecdf8c26 Changes by Mark Hammond for Windows CE. Mostly of the form
Guido van Rossum <guido@python.org>
parents: 10363
diff changeset
102 #ifndef DONT_HAVE_ERRNO_H
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
103 #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
104 #endif
9203
07dae6fdae79 Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents: 9048
diff changeset
105 #include "pythread.h"
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
106
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
107 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
108
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9671
diff changeset
109 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
110 static long main_thread = 0;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
111
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
112 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
113 PyEval_InitThreads(void)
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
114 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
115 if (interpreter_lock)
1179
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1132
diff changeset
116 return;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
117 _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
118 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
119 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
120 main_thread = PyThread_get_thread_ident();
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
121 }
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
122
5865
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
123 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
124 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
125 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9671
diff changeset
126 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
127 }
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5911
diff changeset
128
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5911
diff changeset
129 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
130 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
131 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9671
diff changeset
132 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
133 }
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5911
diff changeset
134
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5911
diff changeset
135 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
136 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
137 {
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
138 if (tstate == NULL)
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
139 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
140 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
141 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
142 Py_FatalError(
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
143 "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
144 }
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
145
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
146 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
147 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
148 {
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
149 if (tstate == NULL)
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
150 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
151 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
152 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
153 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
154 }
14225
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
155
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
156 /* 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
157 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
158 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
159 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
160
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
161 void
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
162 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
163 {
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
164 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
165 return;
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
166 /*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
167 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
168 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
169 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
170 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
171 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
172 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
173 }
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
174 #endif
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
175
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
176 /* Functions save_thread and restore_thread are always defined so
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
177 dynamically loaded modules needn't be compiled separately for use
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
178 with and without threads: */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
179
5846
852a1fa62a7c PyEval_SaveThread() and PyEval_RestoreThread() now return/take a
Guido van Rossum <guido@python.org>
parents: 5829
diff changeset
180 PyThreadState *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
181 PyEval_SaveThread(void)
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
182 {
6365
21b93d98926b Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents: 6243
diff changeset
183 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
184 if (tstate == NULL)
21b93d98926b Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents: 6243
diff changeset
185 Py_FatalError("PyEval_SaveThread: NULL tstate");
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
186 #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
187 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
188 PyThread_release_lock(interpreter_lock);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
189 #endif
6365
21b93d98926b Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents: 6243
diff changeset
190 return tstate;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
191 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
192
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
193 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
194 PyEval_RestoreThread(PyThreadState *tstate)
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
195 {
6365
21b93d98926b Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents: 6243
diff changeset
196 if (tstate == NULL)
21b93d98926b Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents: 6243
diff changeset
197 Py_FatalError("PyEval_RestoreThread: NULL tstate");
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
198 #ifdef WITH_THREAD
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
199 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
200 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
201 PyThread_acquire_lock(interpreter_lock, 1);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
202 errno = err;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
203 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
204 #endif
6365
21b93d98926b Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents: 6243
diff changeset
205 PyThreadState_Swap(tstate);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
206 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
207
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
208
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
209 /* 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
210 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
211 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
212 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
213 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
214 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
215
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
216 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
217 (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
218 an exception condition).
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
219
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
220 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
221 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
222
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
223 #ifdef WITH_THREAD
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
224 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
225 will execute them.
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
226 #endif
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
227
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
228 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
229 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
230 (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
231 (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
232 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
233 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
234 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
235 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
236
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
237 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
238 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
239 */
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
240
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
241 #define NPENDINGCALLS 32
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
242 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
243 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
244 void *arg;
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
245 } pendingcalls[NPENDINGCALLS];
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
246 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
247 static volatile int pendinglast = 0;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
248 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
249
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
250 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
251 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
252 {
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
253 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
254 int i, j;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
255 /* 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
256 /* 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
257 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
258 if (busy)
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
259 return -1;
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
260 busy = 1;
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
261 i = pendinglast;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
262 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
263 if (j == pendingfirst)
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
264 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
265 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
266 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
267 pendinglast = j;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
268 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
269 busy = 0;
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
270 /* 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
271 return 0;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
272 }
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
273
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
274 int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
275 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
276 {
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
277 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
278 #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
279 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
280 return 0;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
281 #endif
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
282 if (busy)
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
283 return 0;
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
284 busy = 1;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
285 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
286 for (;;) {
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
287 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
288 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
289 void *arg;
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
290 i = pendingfirst;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
291 if (i == pendinglast)
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
292 break; /* Queue empty */
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
293 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
294 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
295 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
296 if (func(arg) < 0) {
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
297 busy = 0;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
298 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
299 return -1;
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
300 }
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
301 }
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
302 busy = 0;
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
303 return 0;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
304 }
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
305
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
306
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
307 /* The interpreter's recursion limit */
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
308
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
309 static int recursion_limit = 1000;
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
310
14348
6d0f64f7dedd Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 14333
diff changeset
311 int
6d0f64f7dedd Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 14333
diff changeset
312 Py_GetRecursionLimit(void)
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
313 {
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
314 return recursion_limit;
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
315 }
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
316
14348
6d0f64f7dedd Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 14333
diff changeset
317 void
6d0f64f7dedd Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 14333
diff changeset
318 Py_SetRecursionLimit(int new_limit)
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
319 {
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
320 recursion_limit = new_limit;
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
321 }
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
322
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
323 /* 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
324
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
325 enum why_code {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
326 WHY_NOT, /* No error */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
327 WHY_EXCEPTION, /* Exception occurred */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
328 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
329 WHY_RETURN, /* 'return' statement */
16398
80c0b280a4f9 Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16394
diff changeset
330 WHY_BREAK, /* 'break' statement */
16631
e38145306231 Remove trailing comma from 'why_code' enum, which was introduced by the
Thomas Wouters <thomas@python.org>
parents: 16544
diff changeset
331 WHY_CONTINUE /* 'continue' statement */
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
332 };
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
333
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
334 static enum why_code do_raise(PyObject *, PyObject *, PyObject *);
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
335 static int unpack_sequence(PyObject *, int, PyObject **);
5018
001a5042b181 Cleanup:
Guido van Rossum <guido@python.org>
parents: 5014
diff changeset
336
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
337
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
338 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
339 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
340 {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
341 return eval_code2(co,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
342 globals, locals,
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
343 (PyObject **)NULL, 0,
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
344 (PyObject **)NULL, 0,
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
345 (PyObject **)NULL, 0,
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
346 NULL);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
347 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
348
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
349
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
350 /* Interpreter main loop */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
351
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
352 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
353 eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
354 PyObject **args, int argcount, PyObject **kws, int kwcount,
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
355 PyObject **defs, int defcount, PyObject *closure)
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
356 {
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
357 #ifdef DXPAIRS
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
358 int lastopcode = 0;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
359 #endif
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
360 PyObject **stack_pointer;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
361 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
362 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
363 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
364 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
365 register int err; /* Error status -- nonzero if error */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
366 register PyObject *x; /* Result object -- NULL if error */
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
367 register PyObject *v; /* Temporary objects popped off stack */
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
368 register PyObject *w;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
369 register PyObject *u;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
370 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
371 register PyObject *stream = NULL; /* for PRINT opcodes */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
372 register PyFrameObject *f; /* Current frame */
16355
e4420c2468f9 Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16257
diff changeset
373 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
374 PyObject *retval = NULL; /* Return value */
9671
1d40bc25703a Use PyThreadState_GET() macro.
Guido van Rossum <guido@python.org>
parents: 9591
diff changeset
375 PyThreadState *tstate = PyThreadState_GET();
9293
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 9203
diff changeset
376 unsigned char *first_instr;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
377 #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
378 int lltrace;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
379 #endif
4839
4567e158d20c Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents: 4667
diff changeset
380 #if defined(Py_DEBUG) || defined(LLTRACE)
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
381 /* Make it easier to find out where we are with a debugger */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
382 char *filename = PyString_AsString(co->co_filename);
1016
a41e3ba5b47d Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents: 974
diff changeset
383 #endif
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
384
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
385 /* Code access macros */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
386
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
387 #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
388 #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
389 #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
390 #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
391 #define NEXTOP() (*next_instr++)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
392 #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
393 #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
394 #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
395
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
396 /* Stack manipulation macros */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
397
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
398 #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
399 #define EMPTY() (STACK_LEVEL() == 0)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
400 #define TOP() (stack_pointer[-1])
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
401 #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
402 #define BASIC_POP() (*--stack_pointer)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
403
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
404 #ifdef LLTRACE
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
405 #define PUSH(v) (BASIC_PUSH(v), lltrace && prtrace(TOP(), "push"))
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
406 #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
407 #else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
408 #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
409 #define POP() BASIC_POP()
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
410 #endif
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
411
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
412 /* Local variable macros */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
413
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
414 #define GETLOCAL(i) (fastlocals[i])
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
415 #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
416 GETLOCAL(i) = value; } while (0)
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
417
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
418 /* Start of code */
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
419
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
420 #ifdef USE_STACKCHECK
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
421 if (tstate->recursion_depth%10 == 0 && PyOS_CheckStack()) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
422 PyErr_SetString(PyExc_MemoryError, "Stack overflow");
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
423 return NULL;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
424 }
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
425 #endif
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
426
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
427 if (globals == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
428 PyErr_SetString(PyExc_SystemError, "eval_code2: NULL globals");
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
429 return NULL;
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
430 }
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
431
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
432 #ifdef LLTRACE
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
433 lltrace = PyDict_GetItemString(globals, "__lltrace__") != NULL;
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
434 #endif
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
435
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
436 f = PyFrame_New(tstate, /*back*/
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
437 co, /*code*/
17034
ba81d79dc3a3 Variety of small INC/DECREF patches that fix reported memory leaks
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16631
diff changeset
438 globals, locals);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
439 if (f == NULL)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
440 return NULL;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
441
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
442 tstate->frame = f;
5052
7841c48cdb5b Two small changes:
Guido van Rossum <guido@python.org>
parents: 5050
diff changeset
443 fastlocals = f->f_localsplus;
16355
e4420c2468f9 Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16257
diff changeset
444 freevars = f->f_localsplus + f->f_nlocals;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
445
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
446 if (co->co_argcount > 0 ||
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
447 co->co_flags & (CO_VARARGS | CO_VARKEYWORDS)) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
448 int i;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
449 int n = argcount;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
450 PyObject *kwdict = NULL;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
451 if (co->co_flags & CO_VARKEYWORDS) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
452 kwdict = PyDict_New();
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
453 if (kwdict == NULL)
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
454 goto fail;
5048
fde73467b584 Change the control flow for error handling in the function prelude to
Guido van Rossum <guido@python.org>
parents: 5023
diff changeset
455 i = co->co_argcount;
fde73467b584 Change the control flow for error handling in the function prelude to
Guido van Rossum <guido@python.org>
parents: 5023
diff changeset
456 if (co->co_flags & CO_VARARGS)
fde73467b584 Change the control flow for error handling in the function prelude to
Guido van Rossum <guido@python.org>
parents: 5023
diff changeset
457 i++;
fde73467b584 Change the control flow for error handling in the function prelude to
Guido van Rossum <guido@python.org>
parents: 5023
diff changeset
458 SETLOCAL(i, kwdict);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
459 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
460 if (argcount > co->co_argcount) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
461 if (!(co->co_flags & CO_VARARGS)) {
6599
6d6fec2eeef6 Give more detailed error message when the argument count isn't right.
Guido van Rossum <guido@python.org>
parents: 6573
diff changeset
462 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
463 "%.200s() takes %s %d "
152814f6cd11 This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents: 15830
diff changeset
464 "%sargument%s (%d given)",
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 15166
diff changeset
465 PyString_AsString(co->co_name),
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
466 defcount ? "at most" : "exactly",
152814f6cd11 This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents: 15830
diff changeset
467 co->co_argcount,
152814f6cd11 This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents: 15830
diff changeset
468 kwcount ? "non-keyword " : "",
152814f6cd11 This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents: 15830
diff changeset
469 co->co_argcount == 1 ? "" : "s",
152814f6cd11 This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents: 15830
diff changeset
470 argcount);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
471 goto fail;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
472 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
473 n = co->co_argcount;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
474 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
475 for (i = 0; i < n; i++) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
476 x = args[i];
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
477 Py_INCREF(x);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
478 SETLOCAL(i, x);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
479 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
480 if (co->co_flags & CO_VARARGS) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
481 u = PyTuple_New(argcount - n);
5048
fde73467b584 Change the control flow for error handling in the function prelude to
Guido van Rossum <guido@python.org>
parents: 5023
diff changeset
482 if (u == NULL)
fde73467b584 Change the control flow for error handling in the function prelude to
Guido van Rossum <guido@python.org>
parents: 5023
diff changeset
483 goto fail;
fde73467b584 Change the control flow for error handling in the function prelude to
Guido van Rossum <guido@python.org>
parents: 5023
diff changeset
484 SETLOCAL(co->co_argcount, u);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
485 for (i = n; i < argcount; i++) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
486 x = args[i];
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
487 Py_INCREF(x);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
488 PyTuple_SET_ITEM(u, i-n, x);
2844
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 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
491 for (i = 0; i < kwcount; i++) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
492 PyObject *keyword = kws[2*i];
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
493 PyObject *value = kws[2*i + 1];
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
494 int j;
11407
507546a87dcf Fix PR117. The error message is "keywords must be strings". Perhaps
Guido van Rossum <guido@python.org>
parents: 11263
diff changeset
495 if (keyword == NULL || !PyString_Check(keyword)) {
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
496 PyErr_Format(PyExc_TypeError,
152814f6cd11 This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents: 15830
diff changeset
497 "%.200s() keywords must be strings",
152814f6cd11 This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents: 15830
diff changeset
498 PyString_AsString(co->co_name));
11407
507546a87dcf Fix PR117. The error message is "keywords must be strings". Perhaps
Guido van Rossum <guido@python.org>
parents: 11263
diff changeset
499 goto fail;
507546a87dcf Fix PR117. The error message is "keywords must be strings". Perhaps
Guido van Rossum <guido@python.org>
parents: 11263
diff changeset
500 }
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
501 /* XXX slow -- speed up using dictionary? */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
502 for (j = 0; j < co->co_argcount; j++) {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
503 PyObject *nm = PyTuple_GET_ITEM(
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
504 co->co_varnames, j);
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
505 int cmp = PyObject_RichCompareBool(
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
506 keyword, nm, Py_EQ);
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
507 if (cmp > 0)
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
508 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
509 else if (cmp < 0)
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
510 goto fail;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
511 }
5610
10e9cfa010f0 PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents: 5606
diff changeset
512 /* Check errors from Compare */
10e9cfa010f0 PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents: 5606
diff changeset
513 if (PyErr_Occurred())
10e9cfa010f0 PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents: 5606
diff changeset
514 goto fail;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
515 if (j >= co->co_argcount) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
516 if (kwdict == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
517 PyErr_Format(PyExc_TypeError,
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 15166
diff changeset
518 "%.200s() got an unexpected "
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 15166
diff changeset
519 "keyword argument '%.400s'",
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 15166
diff changeset
520 PyString_AsString(co->co_name),
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
521 PyString_AsString(keyword));
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
522 goto fail;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
523 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
524 PyDict_SetItem(kwdict, keyword, value);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
525 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
526 else {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
527 if (GETLOCAL(j) != NULL) {
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
528 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
529 "%.200s() got multiple "
152814f6cd11 This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents: 15830
diff changeset
530 "values for keyword "
152814f6cd11 This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents: 15830
diff changeset
531 "argument '%.400s'",
152814f6cd11 This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents: 15830
diff changeset
532 PyString_AsString(co->co_name),
152814f6cd11 This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents: 15830
diff changeset
533 PyString_AsString(keyword));
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
534 goto fail;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
535 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
536 Py_INCREF(value);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
537 SETLOCAL(j, value);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
538 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
539 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
540 if (argcount < co->co_argcount) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
541 int m = co->co_argcount - defcount;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
542 for (i = argcount; i < m; i++) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
543 if (GETLOCAL(i) == NULL) {
6599
6d6fec2eeef6 Give more detailed error message when the argument count isn't right.
Guido van Rossum <guido@python.org>
parents: 6573
diff changeset
544 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
545 "%.200s() takes %s %d "
152814f6cd11 This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents: 15830
diff changeset
546 "%sargument%s (%d given)",
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 15166
diff changeset
547 PyString_AsString(co->co_name),
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
548 ((co->co_flags & CO_VARARGS) ||
152814f6cd11 This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents: 15830
diff changeset
549 defcount) ? "at least"
152814f6cd11 This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents: 15830
diff changeset
550 : "exactly",
152814f6cd11 This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents: 15830
diff changeset
551 m, kwcount ? "non-keyword " : "",
152814f6cd11 This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents: 15830
diff changeset
552 m == 1 ? "" : "s", i);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
553 goto fail;
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 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
556 if (n > m)
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
557 i = n - m;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
558 else
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
559 i = 0;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
560 for (; i < defcount; i++) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
561 if (GETLOCAL(m+i) == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
562 PyObject *def = defs[i];
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
563 Py_INCREF(def);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
564 SETLOCAL(m+i, def);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
565 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
566 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
567 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
568 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
569 else {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
570 if (argcount > 0 || kwcount > 0) {
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 15166
diff changeset
571 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
572 "%.200s() takes no arguments (%d given)",
152814f6cd11 This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents: 15830
diff changeset
573 PyString_AsString(co->co_name),
152814f6cd11 This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents: 15830
diff changeset
574 argcount + kwcount);
5048
fde73467b584 Change the control flow for error handling in the function prelude to
Guido van Rossum <guido@python.org>
parents: 5023
diff changeset
575 goto fail;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
576 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
577 }
17104
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
578 /* Allocate and initialize storage for cell vars, and copy free
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
579 vars into frame. This isn't too efficient right now. */
16355
e4420c2468f9 Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16257
diff changeset
580 if (f->f_ncells) {
17104
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
581 int i = 0, j = 0, nargs, found;
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
582 char *cellname, *argname;
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
583 PyObject *c;
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
584
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
585 nargs = co->co_argcount;
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
586 if (co->co_flags & CO_VARARGS)
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
587 nargs++;
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
588 if (co->co_flags & CO_VARKEYWORDS)
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
589 nargs++;
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
590
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
591 /* Check for cells that shadow args */
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
592 for (i = 0; i < f->f_ncells && j < nargs; ++i) {
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
593 cellname = PyString_AS_STRING(
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
594 PyTuple_GET_ITEM(co->co_cellvars, i));
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
595 found = 0;
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
596 while (j < nargs) {
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
597 argname = PyString_AS_STRING(
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
598 PyTuple_GET_ITEM(co->co_varnames, j));
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
599 if (strcmp(cellname, argname) == 0) {
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
600 c = PyCell_New(GETLOCAL(j));
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
601 if (c == NULL)
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
602 goto fail;
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
603 GETLOCAL(f->f_nlocals + i) = c;
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
604 found = 1;
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
605 break;
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
606 }
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
607 j++;
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
608 }
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
609 if (found == 0) {
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
610 c = PyCell_New(NULL);
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
611 if (c == NULL)
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
612 goto fail;
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
613 SETLOCAL(f->f_nlocals + i, c);
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
614 }
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
615 }
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
616 /* Initialize any that are left */
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
617 while (i < f->f_ncells) {
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
618 c = PyCell_New(NULL);
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
619 if (c == NULL)
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
620 goto fail;
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
621 SETLOCAL(f->f_nlocals + i, c);
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
622 i++;
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
623 }
16355
e4420c2468f9 Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16257
diff changeset
624 }
e4420c2468f9 Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16257
diff changeset
625 if (f->f_nfreevars) {
e4420c2468f9 Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16257
diff changeset
626 int i;
17034
ba81d79dc3a3 Variety of small INC/DECREF patches that fix reported memory leaks
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16631
diff changeset
627 for (i = 0; i < f->f_nfreevars; ++i) {
ba81d79dc3a3 Variety of small INC/DECREF patches that fix reported memory leaks
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16631
diff changeset
628 PyObject *o = PyTuple_GET_ITEM(closure, i);
ba81d79dc3a3 Variety of small INC/DECREF patches that fix reported memory leaks
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16631
diff changeset
629 Py_INCREF(o);
ba81d79dc3a3 Variety of small INC/DECREF patches that fix reported memory leaks
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16631
diff changeset
630 freevars[f->f_ncells + i] = o;
ba81d79dc3a3 Variety of small INC/DECREF patches that fix reported memory leaks
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16631
diff changeset
631 }
16355
e4420c2468f9 Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16257
diff changeset
632 }
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
633
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
634 if (tstate->sys_tracefunc != NULL) {
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
635 /* tstate->sys_tracefunc, if defined, is a function that
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
636 will be called on *every* entry to a code block.
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
637 Its return value, if not None, is a function that
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
638 will be called at the start of each executed line
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
639 of code. (Actually, the function must return
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
640 itself in order to continue tracing.)
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
641 The trace functions are called with three arguments:
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
642 a pointer to the current frame, a string indicating
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
643 why the function is called, and an argument which
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
644 depends on the situation. The global trace function
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
645 (sys.trace) is also called whenever an exception
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
646 is detected. */
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
647 if (call_trace(&tstate->sys_tracefunc,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
648 &f->f_trace, f, "call",
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
649 Py_None/*XXX how to compute arguments now?*/)) {
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
650 /* Trace function raised an error */
5048
fde73467b584 Change the control flow for error handling in the function prelude to
Guido van Rossum <guido@python.org>
parents: 5023
diff changeset
651 goto fail;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
652 }
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
653 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
654
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
655 if (tstate->sys_profilefunc != NULL) {
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
656 /* Similar for sys_profilefunc, except it needn't return
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
657 itself and isn't called for "line" events */
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
658 if (call_trace(&tstate->sys_profilefunc,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
659 (PyObject**)0, f, "call",
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
660 Py_None/*XXX*/)) {
5048
fde73467b584 Change the control flow for error handling in the function prelude to
Guido van Rossum <guido@python.org>
parents: 5023
diff changeset
661 goto fail;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
662 }
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
663 }
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
664
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
665 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
666 --tstate->recursion_depth;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
667 PyErr_SetString(PyExc_RuntimeError,
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 15166
diff changeset
668 "maximum recursion depth exceeded");
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
669 tstate->frame = f->f_back;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
670 Py_DECREF(f);
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
671 return NULL;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
672 }
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
673
9293
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 9203
diff changeset
674 _PyCode_GETCODEPTR(co, &first_instr);
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 9203
diff changeset
675 next_instr = first_instr;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
676 stack_pointer = f->f_valuestack;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
677
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
678 why = WHY_NOT;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
679 err = 0;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
680 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
681 w = NULL;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
682
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
683 for (;;) {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
684 /* 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
685 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
686 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
687 ``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
688 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
689 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
690 Py_MakePendingCalls() above. */
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
691
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
692 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
693 tstate->ticker = tstate->interp->checkinterval;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
694 if (things_to_do) {
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
695 if (Py_MakePendingCalls() < 0) {
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
696 why = WHY_EXCEPTION;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
697 goto on_error;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
698 }
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
699 }
5551
34509c05266f Logic for enabling mac-specific signal handling fixed (Jack)
Guido van Rossum <guido@python.org>
parents: 5492
diff changeset
700 #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
701 /* 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
702 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
703 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
704 DOS, alas, we have to call it. */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
705 if (PyErr_CheckSignals()) {
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
706 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
707 goto on_error;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
708 }
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
709 #endif
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
710
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
711 #ifdef WITH_THREAD
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
712 if (interpreter_lock) {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
713 /* Give another thread a chance */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
714
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5911
diff changeset
715 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
716 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
717 PyThread_release_lock(interpreter_lock);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
718
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
719 /* Other threads may run now */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
720
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9671
diff changeset
721 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
722 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
723 Py_FatalError("ceval: orphan tstate");
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
724 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
725 #endif
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
726 }
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
727
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
728 /* Extract opcode and argument */
1016
a41e3ba5b47d Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents: 974
diff changeset
729
4839
4567e158d20c Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents: 4667
diff changeset
730 #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
731 f->f_lasti = INSTR_OFFSET();
a41e3ba5b47d Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents: 974
diff changeset
732 #endif
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
733
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
734 opcode = NEXTOP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
735 if (HAS_ARG(opcode))
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
736 oparg = NEXTARG();
14147
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14100
diff changeset
737 dispatch_opcode:
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
738 #ifdef DYNAMIC_EXECUTION_PROFILE
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
739 #ifdef DXPAIRS
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
740 dxpairs[lastopcode][opcode]++;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
741 lastopcode = opcode;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
742 #endif
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
743 dxp[opcode]++;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
744 #endif
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
745
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
746 #ifdef LLTRACE
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
747 /* Instruction tracing */
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
748
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
749 if (lltrace) {
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
750 if (HAS_ARG(opcode)) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
751 printf("%d: %d, %d\n",
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
752 (int) (INSTR_OFFSET() - 3),
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
753 opcode, oparg);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
754 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
755 else {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
756 printf("%d: %d\n",
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
757 (int) (INSTR_OFFSET() - 1), opcode);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
758 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
759 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
760 #endif
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
761 /* Main switch on opcode */
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
762
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
763 switch (opcode) {
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
764
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
765 /* BEWARE!
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
766 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
767 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
768 and that no operation that succeeds does this! */
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
769
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
770 /* case STOP_CODE: this is an error! */
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
771
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
772 case POP_TOP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
773 v = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
774 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
775 continue;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
776
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
777 case ROT_TWO:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
778 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
779 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
780 PUSH(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
781 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
782 continue;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
783
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
784 case ROT_THREE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
785 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
786 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
787 x = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
788 PUSH(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
789 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
790 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
791 continue;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
792
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
793 case ROT_FOUR:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
794 u = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
795 v = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
796 w = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
797 x = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
798 PUSH(u);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
799 PUSH(x);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
800 PUSH(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
801 PUSH(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
802 continue;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
803
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
804 case DUP_TOP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
805 v = TOP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
806 Py_INCREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
807 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
808 continue;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
809
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
810 case DUP_TOPX:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
811 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
812 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
813 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
814 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
815 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
816 continue;
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
817 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
818 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
819 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
820 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
821 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
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(w);
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(x);
ca9f6a8e9885 Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents: 14869
diff changeset
825 continue;
ca9f6a8e9885 Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents: 14869
diff changeset
826 case 3:
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
827 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
828 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
829 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
830 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
831 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
832 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
833 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
834 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
835 PUSH(v);
ca9f6a8e9885 Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents: 14869
diff changeset
836 PUSH(w);
ca9f6a8e9885 Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents: 14869
diff changeset
837 PUSH(x);
ca9f6a8e9885 Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents: 14869
diff changeset
838 continue;
ca9f6a8e9885 Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents: 14869
diff changeset
839 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
840 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
841 Py_INCREF(x);
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
842 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
843 Py_INCREF(w);
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
844 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
845 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
846 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
847 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
848 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
849 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
850 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
851 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
852 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
853 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
854 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
855 continue;
ca9f6a8e9885 Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents: 14869
diff changeset
856 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
857 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
858 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
859 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
860 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
861 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
862 Py_INCREF(v);
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
863 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
864 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
865 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
866 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
867 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
868 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
869 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
870 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
871 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
872 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
873 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
874 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
875 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
876 continue;
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
877 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
878 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
879 " (bytecode corruption?)");
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
880 }
15151
ca9f6a8e9885 Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents: 14869
diff changeset
881 break;
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
882
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
883 case UNARY_POSITIVE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
884 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
885 x = PyNumber_Positive(v);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
886 Py_DECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
887 PUSH(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
888 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
889 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
890
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
891 case UNARY_NEGATIVE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
892 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
893 x = PyNumber_Negative(v);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
894 Py_DECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
895 PUSH(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
896 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
897 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
898
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
899 case UNARY_NOT:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
900 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
901 err = PyObject_IsTrue(v);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
902 Py_DECREF(v);
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
903 if (err == 0) {
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
904 Py_INCREF(Py_True);
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
905 PUSH(Py_True);
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
906 continue;
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
907 }
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
908 else if (err > 0) {
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
909 Py_INCREF(Py_False);
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
910 PUSH(Py_False);
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
911 err = 0;
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
912 continue;
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
913 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
914 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
915
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
916 case UNARY_CONVERT:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
917 v = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
918 x = PyObject_Repr(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
919 Py_DECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
920 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
921 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
922 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
923
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
924 case UNARY_INVERT:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
925 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
926 x = PyNumber_Invert(v);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
927 Py_DECREF(v);
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
928 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
929 if (x != NULL) continue;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
930 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
931
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
932 case BINARY_POWER:
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
933 w = POP();
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
934 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
935 x = PyNumber_Power(v, w, Py_None);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
936 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
937 Py_DECREF(w);
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
938 PUSH(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
939 if (x != NULL) continue;
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
940 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
941
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
942 case BINARY_MULTIPLY:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
943 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
944 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
945 x = PyNumber_Multiply(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
946 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
947 Py_DECREF(w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
948 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
949 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
950 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
951
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
952 case BINARY_DIVIDE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
953 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
954 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
955 x = PyNumber_Divide(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
956 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
957 Py_DECREF(w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
958 PUSH(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
959 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
960 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
961
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
962 case BINARY_MODULO:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
963 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
964 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
965 x = PyNumber_Remainder(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
966 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
967 Py_DECREF(w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
968 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
969 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
970 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
971
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
972 case BINARY_ADD:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
973 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
974 v = POP();
5829
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
975 if (PyInt_Check(v) && PyInt_Check(w)) {
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
976 /* INLINE: int + int */
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
977 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
978 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
979 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
980 i = a + b;
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
981 if ((i^a) < 0 && (i^b) < 0) {
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
982 PyErr_SetString(PyExc_OverflowError,
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
983 "integer addition");
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
984 x = NULL;
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
985 }
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
986 else
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
987 x = PyInt_FromLong(i);
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
988 }
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
989 else
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
990 x = PyNumber_Add(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
991 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
992 Py_DECREF(w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
993 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
994 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
995 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
996
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
997 case BINARY_SUBTRACT:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
998 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
999 v = POP();
5829
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1000 if (PyInt_Check(v) && PyInt_Check(w)) {
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1001 /* INLINE: int - int */
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1002 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
1003 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
1004 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
1005 i = a - b;
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1006 if ((i^a) < 0 && (i^~b) < 0) {
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1007 PyErr_SetString(PyExc_OverflowError,
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1008 "integer subtraction");
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1009 x = NULL;
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1010 }
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1011 else
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1012 x = PyInt_FromLong(i);
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1013 }
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1014 else
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1015 x = PyNumber_Subtract(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1016 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1017 Py_DECREF(w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1018 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
1019 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1020 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1021
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1022 case BINARY_SUBSCR:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1023 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1024 v = POP();
5829
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1025 if (PyList_Check(v) && PyInt_Check(w)) {
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1026 /* INLINE: list[int] */
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1027 long i = PyInt_AsLong(w);
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1028 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
1029 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
1030 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
1031 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
1032 PyErr_SetString(PyExc_IndexError,
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1033 "list index out of range");
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1034 x = NULL;
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1035 }
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1036 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
1037 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
1038 Py_INCREF(x);
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1039 }
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1040 }
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1041 else
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1042 x = PyObject_GetItem(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1043 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1044 Py_DECREF(w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1045 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
1046 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1047 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1048
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1049 case BINARY_LSHIFT:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1050 w = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1051 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1052 x = PyNumber_Lshift(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1053 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1054 Py_DECREF(w);
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1055 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
1056 if (x != NULL) continue;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1057 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1058
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1059 case BINARY_RSHIFT:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1060 w = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1061 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1062 x = PyNumber_Rshift(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1063 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1064 Py_DECREF(w);
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1065 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
1066 if (x != NULL) continue;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1067 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1068
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1069 case BINARY_AND:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1070 w = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1071 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1072 x = PyNumber_And(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1073 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1074 Py_DECREF(w);
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1075 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
1076 if (x != NULL) continue;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1077 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1078
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1079 case BINARY_XOR:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1080 w = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1081 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1082 x = PyNumber_Xor(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1083 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1084 Py_DECREF(w);
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1085 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
1086 if (x != NULL) continue;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1087 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1088
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1089 case BINARY_OR:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1090 w = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1091 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1092 x = PyNumber_Or(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1093 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1094 Py_DECREF(w);
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1095 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
1096 if (x != NULL) continue;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1097 break;
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1098
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1099 case INPLACE_POWER:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1100 w = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1101 v = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1102 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
1103 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1104 Py_DECREF(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1105 PUSH(x);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1106 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1107 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1108
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1109 case INPLACE_MULTIPLY:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1110 w = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1111 v = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1112 x = PyNumber_InPlaceMultiply(v, w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1113 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1114 Py_DECREF(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1115 PUSH(x);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1116 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1117 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1118
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1119 case INPLACE_DIVIDE:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1120 w = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1121 v = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1122 x = PyNumber_InPlaceDivide(v, w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1123 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1124 Py_DECREF(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1125 PUSH(x);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1126 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1127 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1128
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1129 case INPLACE_MODULO:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1130 w = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1131 v = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1132 x = PyNumber_InPlaceRemainder(v, w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1133 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1134 Py_DECREF(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1135 PUSH(x);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1136 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1137 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1138
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1139 case INPLACE_ADD:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1140 w = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1141 v = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1142 if (PyInt_Check(v) && PyInt_Check(w)) {
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1143 /* INLINE: int + int */
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1144 register long a, b, i;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1145 a = PyInt_AS_LONG(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1146 b = PyInt_AS_LONG(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1147 i = a + b;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1148 if ((i^a) < 0 && (i^b) < 0) {
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1149 PyErr_SetString(PyExc_OverflowError,
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1150 "integer addition");
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1151 x = NULL;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1152 }
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1153 else
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1154 x = PyInt_FromLong(i);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1155 }
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1156 else
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1157 x = PyNumber_InPlaceAdd(v, w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1158 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1159 Py_DECREF(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1160 PUSH(x);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1161 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1162 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1163
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1164 case INPLACE_SUBTRACT:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1165 w = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1166 v = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1167 if (PyInt_Check(v) && PyInt_Check(w)) {
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1168 /* INLINE: int - int */
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1169 register long a, b, i;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1170 a = PyInt_AS_LONG(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1171 b = PyInt_AS_LONG(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1172 i = a - b;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1173 if ((i^a) < 0 && (i^~b) < 0) {
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1174 PyErr_SetString(PyExc_OverflowError,
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1175 "integer subtraction");
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1176 x = NULL;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1177 }
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1178 else
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1179 x = PyInt_FromLong(i);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1180 }
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1181 else
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1182 x = PyNumber_InPlaceSubtract(v, w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1183 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1184 Py_DECREF(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1185 PUSH(x);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1186 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1187 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1188
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1189 case INPLACE_LSHIFT:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1190 w = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1191 v = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1192 x = PyNumber_InPlaceLshift(v, w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1193 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1194 Py_DECREF(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1195 PUSH(x);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1196 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1197 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1198
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1199 case INPLACE_RSHIFT:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1200 w = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1201 v = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1202 x = PyNumber_InPlaceRshift(v, w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1203 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1204 Py_DECREF(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1205 PUSH(x);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1206 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1207 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1208
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1209 case INPLACE_AND:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1210 w = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1211 v = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1212 x = PyNumber_InPlaceAnd(v, w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1213 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1214 Py_DECREF(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1215 PUSH(x);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1216 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1217 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1218
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1219 case INPLACE_XOR:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1220 w = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1221 v = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1222 x = PyNumber_InPlaceXor(v, w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1223 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1224 Py_DECREF(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1225 PUSH(x);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1226 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1227 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1228
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1229 case INPLACE_OR:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1230 w = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1231 v = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1232 x = PyNumber_InPlaceOr(v, w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1233 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1234 Py_DECREF(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1235 PUSH(x);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1236 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1237 break;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1238
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1239 case SLICE+0:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1240 case SLICE+1:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1241 case SLICE+2:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1242 case SLICE+3:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1243 if ((opcode-SLICE) & 2)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1244 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1245 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1246 w = NULL;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1247 if ((opcode-SLICE) & 1)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1248 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1249 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1250 v = NULL;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1251 u = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1252 x = apply_slice(u, v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1253 Py_DECREF(u);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1254 Py_XDECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1255 Py_XDECREF(w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1256 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
1257 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1258 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1259
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1260 case STORE_SLICE+0:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1261 case STORE_SLICE+1:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1262 case STORE_SLICE+2:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1263 case STORE_SLICE+3:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1264 if ((opcode-STORE_SLICE) & 2)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1265 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1266 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1267 w = NULL;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1268 if ((opcode-STORE_SLICE) & 1)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1269 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1270 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1271 v = NULL;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1272 u = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1273 t = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1274 err = assign_slice(u, v, w, t); /* u[v:w] = t */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1275 Py_DECREF(t);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1276 Py_DECREF(u);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1277 Py_XDECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1278 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
1279 if (err == 0) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1280 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1281
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1282 case DELETE_SLICE+0:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1283 case DELETE_SLICE+1:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1284 case DELETE_SLICE+2:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1285 case DELETE_SLICE+3:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1286 if ((opcode-DELETE_SLICE) & 2)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1287 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1288 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1289 w = NULL;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1290 if ((opcode-DELETE_SLICE) & 1)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1291 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1292 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1293 v = NULL;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1294 u = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1295 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
1296 /* del u[v:w] */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1297 Py_DECREF(u);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1298 Py_XDECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1299 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
1300 if (err == 0) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1301 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1302
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1303 case STORE_SUBSCR:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1304 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1305 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1306 u = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1307 /* v[w] = u */
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1308 err = PyObject_SetItem(v, w, u);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1309 Py_DECREF(u);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1310 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1311 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
1312 if (err == 0) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1313 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1314
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1315 case DELETE_SUBSCR:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1316 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1317 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1318 /* del v[w] */
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1319 err = PyObject_DelItem(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1320 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1321 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
1322 if (err == 0) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1323 break;
14100
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1324
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1325 case PRINT_EXPR:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1326 v = POP();
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1327 w = PySys_GetObject("displayhook");
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1328 if (w == NULL) {
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1329 PyErr_SetString(PyExc_RuntimeError,
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1330 "lost sys.displayhook");
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1331 err = -1;
15814
faaf9f10d849 Fixed bugs noted by Greg Stein
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15811
diff changeset
1332 x = NULL;
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1333 }
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1334 if (err == 0) {
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1335 x = Py_BuildValue("(O)", v);
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1336 if (x == NULL)
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1337 err = -1;
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1338 }
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1339 if (err == 0) {
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1340 w = PyEval_CallObject(w, x);
15814
faaf9f10d849 Fixed bugs noted by Greg Stein
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15811
diff changeset
1341 Py_XDECREF(w);
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1342 if (w == NULL)
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1343 err = -1;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1344 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1345 Py_DECREF(v);
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1346 Py_XDECREF(x);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1347 break;
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15809
diff changeset
1348
14100
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1349 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
1350 w = stream = POP();
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1351 /* 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
1352
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1353 case PRINT_ITEM:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1354 v = POP();
14238
74f7f237f739 eval_code2(): Guido provides this patch for his suggested elaboration
Barry Warsaw <barry@python.org>
parents: 14232
diff changeset
1355 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
1356 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
1357 if (w == NULL) {
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1358 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
1359 "lost sys.stdout");
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1360 err = -1;
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1361 }
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
1362 }
14100
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1363 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
1364 err = PyFile_WriteString(" ", w);
495fbde64a73 Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents: 5557
diff changeset
1365 if (err == 0)
495fbde64a73 Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents: 5557
diff changeset
1366 err = PyFile_WriteObject(v, w, Py_PRINT_RAW);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1367 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
1368 /* XXX move into writeobject() ? */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1369 char *s = PyString_AsString(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1370 int len = PyString_Size(v);
2310
07913fb8f92f use Py_CHARMASK
Guido van Rossum <guido@python.org>
parents: 2295
diff changeset
1371 if (len > 0 &&
07913fb8f92f use Py_CHARMASK
Guido van Rossum <guido@python.org>
parents: 2295
diff changeset
1372 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
1373 s[len-1] != ' ')
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1374 PyFile_SoftSpace(w, 0);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1375 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1376 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
1377 Py_XDECREF(stream);
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1378 stream = NULL;
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1379 if (err == 0)
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1380 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1381 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1382
14100
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1383 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
1384 w = stream = POP();
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1385 /* 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
1386
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1387 case PRINT_NEWLINE:
14238
74f7f237f739 eval_code2(): Guido provides this patch for his suggested elaboration
Barry Warsaw <barry@python.org>
parents: 14232
diff changeset
1388 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
1389 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
1390 if (w == NULL)
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1391 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
1392 "lost sys.stdout");
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1393 }
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1394 if (w != NULL) {
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1395 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
1396 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
1397 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
1398 }
14100
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1399 Py_XDECREF(stream);
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1400 stream = NULL;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1401 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1402
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1403
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1404 #ifdef CASE_TOO_BIG
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1405 default: switch (opcode) {
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1406 #endif
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1407 case BREAK_LOOP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1408 why = WHY_BREAK;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1409 break;
17114
6fe13d008e25 Use PyObject_IsInstance() to check whether the first argument to an
Guido van Rossum <guido@python.org>
parents: 17104
diff changeset
1410
16398
80c0b280a4f9 Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16394
diff changeset
1411 case CONTINUE_LOOP:
80c0b280a4f9 Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16394
diff changeset
1412 retval = PyInt_FromLong(oparg);
80c0b280a4f9 Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16394
diff changeset
1413 why = WHY_CONTINUE;
80c0b280a4f9 Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16394
diff changeset
1414 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
1415
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 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
1417 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
1418 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
1419 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
1420 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
1421 /* 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
1422 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
1423 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
1424 /* 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
1425 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
1426 w = POP(); /* exc */
7946
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
1427 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
1428 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
1429 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
1430 default:
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1431 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
1432 "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
1433 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
1434 break;
464
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1435 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1436 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1437
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1438 case LOAD_LOCALS:
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1439 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
1440 PyErr_SetString(PyExc_SystemError,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
1441 "no locals");
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1442 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1443 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1444 Py_INCREF(x);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1445 PUSH(x);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1446 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1447
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1448 case RETURN_VALUE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1449 retval = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1450 why = WHY_RETURN;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1451 break;
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
1452
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
1453 case EXEC_STMT:
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
1454 w = POP();
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
1455 v = POP();
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
1456 u = POP();
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
1457 err = exec_statement(f, u, v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1458 Py_DECREF(u);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1459 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1460 Py_DECREF(w);
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
1461 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1462
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1463 case POP_BLOCK:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1464 {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1465 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
1466 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
1467 v = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1468 Py_DECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1469 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1470 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1471 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1472
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1473 case END_FINALLY:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1474 v = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1475 if (PyInt_Check(v)) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1476 why = (enum why_code) PyInt_AsLong(v);
16398
80c0b280a4f9 Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16394
diff changeset
1477 if (why == WHY_RETURN ||
80c0b280a4f9 Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16394
diff changeset
1478 why == CONTINUE_LOOP)
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1479 retval = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1480 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1481 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
1482 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
1483 u = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1484 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
1485 why = WHY_RERAISE;
2872
d3b07ba3e12d fix bogus DECREF in finally clause
Guido van Rossum <guido@python.org>
parents: 2866
diff changeset
1486 break;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1487 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1488 else if (v != Py_None) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1489 PyErr_SetString(PyExc_SystemError,
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1490 "'finally' pops bad exception");
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1491 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1492 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1493 Py_DECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1494 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1495
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1496 case BUILD_CLASS:
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
1497 u = POP();
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1498 v = POP();
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
1499 w = POP();
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
1500 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
1501 PUSH(x);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1502 Py_DECREF(u);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1503 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1504 Py_DECREF(w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1505 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1506
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1507 case STORE_NAME:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1508 w = GETNAMEV(oparg);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1509 v = POP();
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1510 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
1511 PyErr_Format(PyExc_SystemError,
7234d7c3c29f clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15948
diff changeset
1512 "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
1513 PyObject_REPR(w));
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1514 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1515 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1516 err = PyDict_SetItem(x, w, v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1517 Py_DECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1518 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1519
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1520 case DELETE_NAME:
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
1521 w = GETNAMEV(oparg);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1522 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
1523 PyErr_Format(PyExc_SystemError,
7234d7c3c29f clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15948
diff changeset
1524 "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
1525 PyObject_REPR(w));
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1526 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1527 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1528 if ((err = PyDict_DelItem(x, w)) != 0)
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1529 format_exc_check_arg(PyExc_NameError,
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1530 NAME_ERROR_MSG ,w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1531 break;
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1532
13930
4eaa463c031a Merge UNPACK_LIST and UNPACK_TUPLE into a single UNPACK_SEQUENCE, since they
Thomas Wouters <thomas@python.org>
parents: 13881
diff changeset
1533 case UNPACK_SEQUENCE:
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1534 v = POP();
6157
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1535 if (PyTuple_Check(v)) {
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1536 if (PyTuple_Size(v) != oparg) {
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1537 PyErr_SetString(PyExc_ValueError,
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1538 "unpack tuple of wrong size");
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1539 why = WHY_EXCEPTION;
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1540 }
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1541 else {
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1542 for (; --oparg >= 0; ) {
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1543 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
1544 Py_INCREF(w);
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1545 PUSH(w);
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1546 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1547 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1548 }
6157
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1549 else if (PyList_Check(v)) {
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1550 if (PyList_Size(v) != oparg) {
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1551 PyErr_SetString(PyExc_ValueError,
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1552 "unpack list of wrong size");
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1553 why = WHY_EXCEPTION;
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1554 }
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1555 else {
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1556 for (; --oparg >= 0; ) {
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1557 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
1558 Py_INCREF(w);
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1559 PUSH(w);
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1560 }
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1561 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1562 }
6157
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1563 else if (PySequence_Check(v)) {
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1564 if (unpack_sequence(v, oparg,
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1565 stack_pointer + oparg))
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1566 stack_pointer += oparg;
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1567 else
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1568 why = WHY_EXCEPTION;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1569 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1570 else {
6157
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1571 PyErr_SetString(PyExc_TypeError,
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1572 "unpack non-sequence");
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1573 why = WHY_EXCEPTION;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1574 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1575 Py_DECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1576 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1577
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1578 case STORE_ATTR:
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1579 w = GETNAMEV(oparg);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1580 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1581 u = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1582 err = PyObject_SetAttr(v, w, u); /* v.w = u */
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1583 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1584 Py_DECREF(u);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1585 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1586
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1587 case DELETE_ATTR:
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1588 w = GETNAMEV(oparg);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1589 v = POP();
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
1590 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
1591 /* del v.w */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1592 Py_DECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1593 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1594
464
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1595 case STORE_GLOBAL:
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1596 w = GETNAMEV(oparg);
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1597 v = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1598 err = PyDict_SetItem(f->f_globals, w, v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1599 Py_DECREF(v);
464
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1600 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1601
464
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1602 case DELETE_GLOBAL:
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1603 w = GETNAMEV(oparg);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1604 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
1605 format_exc_check_arg(
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1606 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
1607 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1608
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1609 case LOAD_CONST:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1610 x = GETCONST(oparg);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1611 Py_INCREF(x);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1612 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1613 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1614
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1615 case LOAD_NAME:
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
1616 w = GETNAMEV(oparg);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1617 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
1618 PyErr_Format(PyExc_SystemError,
7234d7c3c29f clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15948
diff changeset
1619 "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
1620 PyObject_REPR(w));
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1621 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1622 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1623 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
1624 if (x == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1625 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
1626 if (x == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1627 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
1628 if (x == NULL) {
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1629 format_exc_check_arg(
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1630 PyExc_NameError,
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1631 NAME_ERROR_MSG ,w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1632 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1633 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1634 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1635 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1636 Py_INCREF(x);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1637 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1638 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1639
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1640 case LOAD_GLOBAL:
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
1641 w = GETNAMEV(oparg);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1642 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
1643 if (x == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1644 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
1645 if (x == NULL) {
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1646 format_exc_check_arg(
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1647 PyExc_NameError,
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1648 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
1649 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1650 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1651 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1652 Py_INCREF(x);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1653 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1654 break;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1655
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1656 case LOAD_FAST:
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1657 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
1658 if (x == NULL) {
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1659 format_exc_check_arg(
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1660 PyExc_UnboundLocalError,
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1661 UNBOUNDLOCAL_ERROR_MSG,
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1662 PyTuple_GetItem(co->co_varnames, oparg)
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1663 );
1262
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1664 break;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1665 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1666 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
1667 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
1668 if (x != NULL) continue;
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1669 break;
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1670
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1671 case STORE_FAST:
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
1672 v = POP();
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1673 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
1674 continue;
1262
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1675
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1676 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
1677 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
1678 if (x == NULL) {
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1679 format_exc_check_arg(
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1680 PyExc_UnboundLocalError,
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1681 UNBOUNDLOCAL_ERROR_MSG,
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1682 PyTuple_GetItem(co->co_varnames, oparg)
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1683 );
8318
ec87b62466d3 DELETE_FAST should issue an exception when the local variable is undefined.
Guido van Rossum <guido@python.org>
parents: 7982
diff changeset
1684 break;
ec87b62466d3 DELETE_FAST should issue an exception when the local variable is undefined.
Guido van Rossum <guido@python.org>
parents: 7982
diff changeset
1685 }
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1686 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
1687 continue;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1688
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1689 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
1690 x = freevars[oparg];
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1691 Py_INCREF(x);
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1692 PUSH(x);
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1693 break;
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1694
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1695 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
1696 x = freevars[oparg];
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1697 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
1698 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
1699 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
1700 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
1701 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
1702 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
1703 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
1704 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
1705 v);
a34293ced63b Change error message raised when free variable is not yet bound. It
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17490
diff changeset
1706 } else {
16453
2e3dd62ceac5 SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16398
diff changeset
1707 v = PyTuple_GetItem(
2e3dd62ceac5 SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16398
diff changeset
1708 co->co_freevars,
2e3dd62ceac5 SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16398
diff changeset
1709 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
1710 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
1711 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
1712 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
1713 v);
a34293ced63b Change error message raised when free variable is not yet bound. It
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17490
diff changeset
1714 }
16453
2e3dd62ceac5 SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16398
diff changeset
1715 err = -1;
2e3dd62ceac5 SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16398
diff changeset
1716 break;
2e3dd62ceac5 SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16398
diff changeset
1717 }
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1718 PUSH(w);
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1719 break;
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1720
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1721 case STORE_DEREF:
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1722 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
1723 x = freevars[oparg];
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1724 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
1725 Py_DECREF(w);
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1726 continue;
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
1727
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1728 case BUILD_TUPLE:
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1729 x = PyTuple_New(oparg);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1730 if (x != NULL) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1731 for (; --oparg >= 0;) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1732 w = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1733 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
1734 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1735 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
1736 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1737 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1738 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1739
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1740 case BUILD_LIST:
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1741 x = PyList_New(oparg);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1742 if (x != NULL) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1743 for (; --oparg >= 0;) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1744 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
1745 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
1746 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1747 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
1748 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1749 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1750 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1751
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1752 case BUILD_MAP:
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1753 x = PyDict_New();
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1754 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
1755 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1756 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1757
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1758 case LOAD_ATTR:
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1759 w = GETNAMEV(oparg);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1760 v = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1761 x = PyObject_GetAttr(v, w);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1762 Py_DECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1763 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
1764 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1765 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1766
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1767 case COMPARE_OP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1768 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1769 v = POP();
5829
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1770 if (PyInt_Check(v) && PyInt_Check(w)) {
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1771 /* INLINE: cmp(int, int) */
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1772 register long a, b;
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1773 register int res;
9591
7f90736701a3 Use PyInt_AS_LONG macro instead of explicit inlining.
Guido van Rossum <guido@python.org>
parents: 9513
diff changeset
1774 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
1775 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
1776 switch (oparg) {
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1777 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
1778 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
1779 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
1780 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
1781 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
1782 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
1783 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
1784 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
1785 default: goto slow_compare;
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1786 }
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1787 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
1788 Py_INCREF(x);
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1789 }
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1790 else {
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1791 slow_compare:
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1792 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
1793 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1794 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1795 Py_DECREF(w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1796 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
1797 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1798 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1799
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1800 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
1801 w = GETNAMEV(oparg);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1802 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
1803 if (x == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1804 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
1805 "__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
1806 break;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1807 }
14232
1f1a156ed5af Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents: 14225
diff changeset
1808 u = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1809 w = Py_BuildValue("(OOOO)",
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1810 w,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1811 f->f_globals,
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
1812 f->f_locals == NULL ?
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
1813 Py_None : f->f_locals,
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1814 u);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1815 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
1816 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
1817 x = NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1818 break;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1819 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1820 x = PyEval_CallObject(x, w);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1821 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
1822 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
1823 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1824 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1825
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_STAR:
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
1827 v = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1828 PyFrame_FastToLocals(f);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1829 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
1830 PyErr_SetString(PyExc_SystemError,
16017
7234d7c3c29f clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15948
diff changeset
1831 "no locals found during 'import *'");
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1832 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1833 }
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
1834 err = import_all_from(x, v);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1835 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
1836 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
1837 if (err == 0) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1838 break;
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
1839
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
1840 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
1841 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
1842 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
1843 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
1844 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
1845 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
1846 break;
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
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_FORWARD:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1849 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
1850 continue;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1851
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1852 case JUMP_IF_FALSE:
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1853 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
1854 if (err > 0)
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1855 err = 0;
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1856 else if (err == 0)
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1857 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
1858 else
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1859 break;
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1860 continue;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1861
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1862 case JUMP_IF_TRUE:
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1863 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
1864 if (err > 0) {
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1865 err = 0;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1866 JUMPBY(oparg);
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1867 }
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1868 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
1869 ;
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1870 else
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1871 break;
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1872 continue;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1873
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1874 case JUMP_ABSOLUTE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1875 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
1876 continue;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1877
17597
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
1878 case GET_ITER:
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
1879 /* before: [obj]; after [getiter(obj)] */
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
1880 v = POP();
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
1881 x = PyObject_GetIter(v);
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
1882 Py_DECREF(v);
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
1883 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
1884 PUSH(x);
aac65f50df6f Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents: 17600
diff changeset
1885 continue;
17597
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
1886 }
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
1887 break;
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
1888
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
1889 case FOR_ITER:
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
1890 /* before: [iter]; after: [iter, iter()] *or* [] */
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
1891 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
1892 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
1893 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
1894 PUSH(x);
aac65f50df6f Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents: 17600
diff changeset
1895 continue;
17597
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
1896 }
17683
e9a4e27e8d4e Make PyIter_Next() a little smarter (wrt its knowledge of iterator
Tim Peters <tim.peters@gmail.com>
parents: 17636
diff changeset
1897 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
1898 /* 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
1899 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
1900 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
1901 JUMPBY(oparg);
aac65f50df6f Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents: 17600
diff changeset
1902 continue;
aac65f50df6f Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents: 17600
diff changeset
1903 }
aac65f50df6f Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents: 17600
diff changeset
1904 break;
17597
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17494
diff changeset
1905
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1906 case FOR_LOOP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1907 /* for v in s: ...
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1908 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
1909 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
1910 but if loop exhausted:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1911 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
1912 w = POP(); /* Loop index */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1913 v = POP(); /* Sequence object */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1914 u = loop_subscript(v, w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1915 if (u != NULL) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1916 PUSH(v);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1917 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
1918 PUSH(x);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1919 Py_DECREF(w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1920 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
1921 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1922 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1923 else {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1924 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1925 Py_DECREF(w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1926 /* 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
1927 but also an error: */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1928 if (PyErr_Occurred())
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1929 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
1930 else {
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1931 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
1932 continue;
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1933 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1934 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1935 break;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1936
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1937 case SETUP_LOOP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1938 case SETUP_EXCEPT:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1939 case SETUP_FINALLY:
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1940 PyFrame_BlockSetup(f, opcode, INSTR_OFFSET() + oparg,
16398
80c0b280a4f9 Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16394
diff changeset
1941 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
1942 continue;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1943
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1944 case SET_LINENO:
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1945 #ifdef LLTRACE
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1946 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
1947 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
1948 #endif
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1949 f->f_lineno = 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
1950 if (f->f_trace == NULL)
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1951 continue;
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1952 /* 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
1953 f->f_lasti = INSTR_OFFSET();
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1954 err = call_trace(&f->f_trace, &f->f_trace,
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1955 f, "line", Py_None);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1956 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
1957
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
1958 case CALL_FUNCTION:
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1959 {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1960 int na = oparg & 0xff;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1961 int nk = (oparg>>8) & 0xff;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1962 int n = na + 2 * nk;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1963 PyObject **pfunc = stack_pointer - n - 1;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1964 PyObject *func = *pfunc;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1965 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
1966
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1967 /* Always dispatch PyCFunction first, because
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1968 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
1969 callable object.
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1970 */
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1971 if (PyCFunction_Check(func)) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1972 if (PyCFunction_GET_FLAGS(func) == 0) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1973 x = fast_cfunction(func,
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1974 &stack_pointer, na);
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1975 } else {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1976 x = do_call(func, &stack_pointer,
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1977 na, nk);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1978 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1979 } else {
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1980 if (PyMethod_Check(func)
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1981 && PyMethod_GET_SELF(func) != NULL) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1982 /* optimize access to bound methods */
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1983 PyObject *self = PyMethod_GET_SELF(func);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1984 Py_INCREF(self);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1985 func = PyMethod_GET_FUNCTION(func);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1986 Py_INCREF(func);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1987 Py_DECREF(*pfunc);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1988 *pfunc = self;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1989 na++;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1990 n++;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1991 } else
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1992 Py_INCREF(func);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1993 if (PyFunction_Check(func)) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1994 x = fast_function(func, &stack_pointer,
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
1995 n, na, nk);
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1996 } else {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1997 x = do_call(func, &stack_pointer,
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
1998 na, nk);
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 Py_DECREF(func);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2001 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2002
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2003 while (stack_pointer > pfunc) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2004 w = POP();
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2005 Py_DECREF(w);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2006 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2007 PUSH(x);
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2008 if (x != NULL)
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2009 continue;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2010 break;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2011 }
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2012
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
2013 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
2014 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
2015 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
2016 {
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
2017 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
2018 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
2019 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
2020 int n = na + 2 * nk;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2021 PyObject **pfunc, *func;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2022 if (flags & CALL_FLAG_VAR)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2023 n++;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2024 if (flags & CALL_FLAG_KW)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2025 n++;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2026 pfunc = stack_pointer - n - 1;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2027 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
2028 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
2029
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2030 if (PyMethod_Check(func)
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2031 && PyMethod_GET_SELF(func) != NULL) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2032 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
2033 Py_INCREF(self);
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2034 func = PyMethod_GET_FUNCTION(func);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2035 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
2036 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
2037 *pfunc = self;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
2038 na++;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
2039 n++;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2040 } else
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2041 Py_INCREF(func);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2042 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
2043 Py_DECREF(func);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2044
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2045 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
2046 w = POP();
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2047 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
2048 }
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
2049 PUSH(x);
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2050 if (x != NULL)
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2051 continue;
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
2052 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
2053 }
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2054
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2055 case MAKE_FUNCTION:
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2056 v = POP(); /* code object */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2057 x = PyFunction_New(v, f->f_globals);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2058 Py_DECREF(v);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2059 /* XXX Maybe this should be a separate opcode? */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2060 if (x != NULL && oparg > 0) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2061 v = PyTuple_New(oparg);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2062 if (v == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2063 Py_DECREF(x);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2064 x = NULL;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2065 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2066 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2067 while (--oparg >= 0) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2068 w = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2069 PyTuple_SET_ITEM(v, oparg, w);
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 err = PyFunction_SetDefaults(x, v);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2072 Py_DECREF(v);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2073 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2074 PUSH(x);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2075 break;
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2076
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2077 case MAKE_CLOSURE:
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2078 {
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2079 int nfree;
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2080 v = POP(); /* code object */
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2081 x = PyFunction_New(v, f->f_globals);
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2082 nfree = PyTuple_GET_SIZE(((PyCodeObject *)v)->co_freevars);
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2083 Py_DECREF(v);
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2084 /* XXX Maybe this should be a separate opcode? */
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2085 if (x != NULL && nfree > 0) {
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2086 v = PyTuple_New(nfree);
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2087 if (v == NULL) {
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2088 Py_DECREF(x);
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2089 x = NULL;
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2090 break;
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2091 }
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2092 while (--nfree >= 0) {
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2093 w = POP();
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2094 PyTuple_SET_ITEM(v, nfree, w);
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 err = PyFunction_SetClosure(x, v);
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2097 Py_DECREF(v);
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2098 }
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2099 if (x != NULL && oparg > 0) {
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2100 v = PyTuple_New(oparg);
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2101 if (v == NULL) {
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2102 Py_DECREF(x);
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2103 x = NULL;
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2104 break;
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2105 }
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2106 while (--oparg >= 0) {
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2107 w = POP();
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2108 PyTuple_SET_ITEM(v, oparg, w);
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 err = PyFunction_SetDefaults(x, v);
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2111 Py_DECREF(v);
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 PUSH(x);
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2114 break;
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2115 }
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2116
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2117 case BUILD_SLICE:
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2118 if (oparg == 3)
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2119 w = POP();
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2120 else
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2121 w = NULL;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2122 v = POP();
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2123 u = POP();
5018
001a5042b181 Cleanup:
Guido van Rossum <guido@python.org>
parents: 5014
diff changeset
2124 x = PySlice_New(u, v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2125 Py_DECREF(u);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2126 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2127 Py_XDECREF(w);
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2128 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
2129 if (x != NULL) continue;
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2130 break;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2131
14147
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14100
diff changeset
2132 case EXTENDED_ARG:
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14100
diff changeset
2133 opcode = NEXTOP();
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14100
diff changeset
2134 oparg = oparg<<16 | NEXTARG();
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14100
diff changeset
2135 goto dispatch_opcode;
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2136
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2137 default:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2138 fprintf(stderr,
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2139 "XXX lineno: %d, opcode: %d\n",
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2140 f->f_lineno, opcode);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2141 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
2142 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2143 break;
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2144
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2145 #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
2146 }
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2147 #endif
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2148
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2149 } /* switch */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2150
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2151 on_error:
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2152
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2153 /* Quickly continue if no error occurred */
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2154
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2155 if (why == WHY_NOT) {
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2156 if (err == 0 && x != NULL) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2157 #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
2158 /* This check is expensive! */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2159 if (PyErr_Occurred())
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2160 fprintf(stderr,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2161 "XXX undetected error\n");
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2162 else
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2163 #endif
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2164 continue; /* Normal, fast path */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2165 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2166 why = WHY_EXCEPTION;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2167 x = Py_None;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2168 err = 0;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2169 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2170
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2171 /* Double-check exception status */
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2172
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2173 if (why == WHY_EXCEPTION || why == WHY_RERAISE) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2174 if (!PyErr_Occurred()) {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2175 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
2176 "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
2177 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2178 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2179 }
10363
4daab7a9f566 Always test for an error return (usually NULL or -1) without setting
Guido van Rossum <guido@python.org>
parents: 9679
diff changeset
2180 #ifdef CHECKEXC
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2181 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
2182 /* This check is expensive! */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2183 if (PyErr_Occurred()) {
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2184 fprintf(stderr,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2185 "XXX undetected error (why=%d)\n",
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2186 why);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2187 why = WHY_EXCEPTION;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2188 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2189 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2190 #endif
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2191
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2192 /* 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
2193
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2194 if (why == WHY_EXCEPTION) {
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2195 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
2196 if (HAS_ARG(opcode))
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2197 f->f_lasti -= 2;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2198 PyTraceBack_Here(f);
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2199
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2200 if (f->f_trace)
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2201 call_exc_trace(&f->f_trace, &f->f_trace, f);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2202 if (tstate->sys_profilefunc)
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2203 call_exc_trace(&tstate->sys_profilefunc,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2204 (PyObject**)0, f);
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
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2214 while (why != WHY_NOT && f->f_iblock > 0) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
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
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
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
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2241 PyObject *exc, *val, *tb;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
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
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2244 val = Py_None;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
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
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
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
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2282 /* Pop remaining stack entries */
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2283
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2284 while (!EMPTY()) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2285 v = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2286 Py_XDECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2287 }
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2288
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2289 if (why != WHY_RETURN)
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2290 retval = NULL;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2291
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2292 if (f->f_trace) {
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2293 if (why == WHY_RETURN) {
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2294 if (call_trace(&f->f_trace, &f->f_trace, f,
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2295 "return", retval)) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2296 Py_XDECREF(retval);
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2297 retval = NULL;
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2298 why = WHY_EXCEPTION;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2299 }
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2300 }
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2301 }
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2302
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2303 if (tstate->sys_profilefunc && why == WHY_RETURN) {
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2304 if (call_trace(&tstate->sys_profilefunc, (PyObject**)0,
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2305 f, "return", retval)) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2306 Py_XDECREF(retval);
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2307 retval = NULL;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2308 why = WHY_EXCEPTION;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2309 }
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2310 }
5023
75c1ee882a4a Kill all local variables on function return. This closes a gigantic
Guido van Rossum <guido@python.org>
parents: 5021
diff changeset
2311
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2312 reset_exc_info(tstate);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2313
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2314 --tstate->recursion_depth;
5048
fde73467b584 Change the control flow for error handling in the function prelude to
Guido van Rossum <guido@python.org>
parents: 5023
diff changeset
2315
fde73467b584 Change the control flow for error handling in the function prelude to
Guido van Rossum <guido@python.org>
parents: 5023
diff changeset
2316 fail: /* Jump here from prelude on failure */
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2317
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2318 /* Restore previous frame and release the current one */
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2319
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2320 tstate->frame = f->f_back;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2321 Py_DECREF(f);
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2322
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2323 return retval;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2324 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2325
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2326 static void
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2327 set_exc_info(PyThreadState *tstate,
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2328 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
2329 {
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2330 PyFrameObject *frame;
5557
4329e4077cf3 Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents: 5551
diff changeset
2331 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
2332
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2333 frame = tstate->frame;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2334 if (frame->f_exc_type == NULL) {
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2335 /* 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
2336 /* 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
2337 if (tstate->exc_type == NULL) {
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2338 Py_INCREF(Py_None);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2339 tstate->exc_type = Py_None;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2340 }
5557
4329e4077cf3 Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents: 5551
diff changeset
2341 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
2342 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
2343 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
2344 Py_XINCREF(tstate->exc_type);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2345 Py_XINCREF(tstate->exc_value);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2346 Py_XINCREF(tstate->exc_traceback);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2347 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
2348 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
2349 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
2350 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
2351 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
2352 Py_XDECREF(tmp_tb);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2353 }
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2354 /* 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
2355 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
2356 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
2357 tmp_tb = tstate->exc_traceback;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2358 Py_XINCREF(type);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2359 Py_XINCREF(value);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2360 Py_XINCREF(tb);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2361 tstate->exc_type = type;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2362 tstate->exc_value = value;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2363 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
2364 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
2365 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
2366 Py_XDECREF(tmp_tb);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2367 /* For b/w compatibility */
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2368 PySys_SetObject("exc_type", type);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2369 PySys_SetObject("exc_value", value);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2370 PySys_SetObject("exc_traceback", tb);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2371 }
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2372
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2373 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2374 reset_exc_info(PyThreadState *tstate)
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2375 {
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2376 PyFrameObject *frame;
5557
4329e4077cf3 Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents: 5551
diff changeset
2377 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
2378 frame = tstate->frame;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2379 if (frame->f_exc_type != NULL) {
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2380 /* 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
2381 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
2382 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
2383 tmp_tb = tstate->exc_traceback;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2384 Py_XINCREF(frame->f_exc_type);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2385 Py_XINCREF(frame->f_exc_value);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2386 Py_XINCREF(frame->f_exc_traceback);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2387 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
2388 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
2389 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
2390 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
2391 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
2392 Py_XDECREF(tmp_tb);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2393 /* For b/w compatibility */
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2394 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
2395 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
2396 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
2397 }
5557
4329e4077cf3 Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents: 5551
diff changeset
2398 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
2399 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
2400 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
2401 frame->f_exc_type = NULL;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2402 frame->f_exc_value = NULL;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2403 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
2404 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
2405 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
2406 Py_XDECREF(tmp_tb);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2407 }
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2408
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
2409 /* 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
2410 This *consumes* a reference count to each of its arguments. */
5018
001a5042b181 Cleanup:
Guido van Rossum <guido@python.org>
parents: 5014
diff changeset
2411 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
2412 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
2413 {
7946
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
2414 if (type == NULL) {
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
2415 /* Reraise */
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
2416 PyThreadState *tstate = PyThreadState_Get();
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
2417 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
2418 value = tstate->exc_value;
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
2419 tb = tstate->exc_traceback;
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
2420 Py_XINCREF(type);
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
2421 Py_XINCREF(value);
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
2422 Py_XINCREF(tb);
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
2423 }
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2424
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
2425 /* 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
2426 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
2427 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
2428 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
2429 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
2430 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
2431 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
2432 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
2433
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
2434 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
2435
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
2436 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
2437 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
2438 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
2439
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
2440 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
2441 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
2442 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
2443
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
2444 /* 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
2445 NULL. */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2446 if (tb == Py_None) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2447 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
2448 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
2449 }
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
2450 else if (tb != NULL && !PyTraceBack_Check(tb)) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2451 PyErr_SetString(PyExc_TypeError,
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 15166
diff changeset
2452 "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
2453 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
2454 }
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
2455
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
2456 /* 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
2457 if (value == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2458 value = Py_None;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2459 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
2460 }
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
2461
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
2462 /* Next, repeatedly, replace a tuple exception with its first item */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2463 while (PyTuple_Check(type) && PyTuple_Size(type) > 0) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2464 PyObject *tmp = type;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2465 type = PyTuple_GET_ITEM(type, 0);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2466 Py_INCREF(type);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2467 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
2468 }
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
2469
6147
b76a44163e0f cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents: 6139
diff changeset
2470 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
2471 ;
6147
b76a44163e0f cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents: 6139
diff changeset
2472
b76a44163e0f cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents: 6139
diff changeset
2473 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
2474 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
2475
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2476 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
2477 /* Raising an instance. The value should be a dummy. */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2478 if (value != Py_None) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2479 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
2480 "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
2481 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
2482 }
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
2483 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
2484 /* Normalize to raise <class>, <instance> */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2485 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
2486 value = type;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2487 type = (PyObject*) ((PyInstanceObject*)type)->in_class;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2488 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
2489 }
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
2490 }
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
2491 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
2492 /* 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
2493 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
2494 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
2495 "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
2496 "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
2497 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
2498 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2499 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
2500 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
2501 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
2502 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
2503 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
2504 raise_error:
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2505 Py_XDECREF(value);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2506 Py_XDECREF(type);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2507 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
2508 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
2509 }
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
2510
6157
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2511 static int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2512 unpack_sequence(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
2513 {
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2514 int i;
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2515 PyObject *w;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2516
6157
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2517 for (i = 0; i < argcnt; i++) {
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2518 if (! (w = PySequence_GetItem(v, i))) {
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2519 if (PyErr_ExceptionMatches(PyExc_IndexError))
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2520 PyErr_SetString(PyExc_ValueError,
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2521 "unpack sequence of wrong size");
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2522 goto finally;
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2523 }
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2524 *--sp = w;
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2525 }
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2526 /* we better get an IndexError now */
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2527 if (PySequence_GetItem(v, i) == NULL) {
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2528 if (PyErr_ExceptionMatches(PyExc_IndexError)) {
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2529 PyErr_Clear();
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2530 return 1;
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2531 }
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2532 /* some other exception occurred. fall through to finally */
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2533 }
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2534 else
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2535 PyErr_SetString(PyExc_ValueError,
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2536 "unpack sequence of wrong size");
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2537 /* fall through */
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2538 finally:
6160
79592761b331 unpack_sequence(): In finally clause, watch out for Py_DECREF
Barry Warsaw <barry@python.org>
parents: 6157
diff changeset
2539 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
2540 Py_DECREF(*sp);
6157
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2541
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2542 return 0;
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2543 }
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2544
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2545
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2546 #ifdef LLTRACE
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2547 static int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2548 prtrace(PyObject *v, char *str)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2549 {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2550 printf("%s ", str);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2551 if (PyObject_Print(v, stdout, 0) != 0)
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2552 PyErr_Clear(); /* Don't know what else to do */
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2553 printf("\n");
12579
978253542076 Add useless 'return 1' to prtrace() to shut up VC++.
Guido van Rossum <guido@python.org>
parents: 12576
diff changeset
2554 return 1;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2555 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2556 #endif
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2557
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2558 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2559 call_exc_trace(PyObject **p_trace, PyObject **p_newtrace, PyFrameObject *f)
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2560 {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2561 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
2562 int err;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2563 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
2564 if (value == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2565 value = Py_None;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2566 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
2567 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2568 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
2569 if (arg == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2570 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
2571 return;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
2572 }
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2573 err = call_trace(p_trace, p_newtrace, f, "exception", arg);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2574 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
2575 if (err == 0)
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2576 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
2577 else {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2578 Py_XDECREF(type);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2579 Py_XDECREF(value);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2580 Py_XDECREF(traceback);
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2581 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2582 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2583
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2584 /* PyObject **p_trace: in/out; may not be NULL;
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2585 may not point to NULL variable initially
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2586 PyObject **p_newtrace: in/out; may be NULL;
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2587 may point to NULL variable;
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2588 may be same variable as p_newtrace */
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2589
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2590 static int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2591 call_trace(PyObject **p_trace, PyObject **p_newtrace, PyFrameObject *f,
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2592 char *msg, PyObject *arg)
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2593 {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2594 PyThreadState *tstate = f->f_tstate;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2595 PyObject *args, *what;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2596 PyObject *res = NULL;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2597
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2598 if (tstate->tracing) {
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2599 /* Don't do recursive traces */
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2600 if (p_newtrace) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2601 Py_XDECREF(*p_newtrace);
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2602 *p_newtrace = NULL;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2603 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2604 return 0;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2605 }
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2606
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2607 args = PyTuple_New(3);
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
2608 if (args == NULL)
5937
5a4d181ffffd Renamed a local label that was accidentally grandly renamed to
Guido van Rossum <guido@python.org>
parents: 5926
diff changeset
2609 goto cleanup;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2610 what = PyString_FromString(msg);
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2611 if (what == NULL)
5937
5a4d181ffffd Renamed a local label that was accidentally grandly renamed to
Guido van Rossum <guido@python.org>
parents: 5926
diff changeset
2612 goto cleanup;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2613 Py_INCREF(f);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2614 PyTuple_SET_ITEM(args, 0, (PyObject *)f);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2615 PyTuple_SET_ITEM(args, 1, what);
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2616 if (arg == NULL)
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2617 arg = Py_None;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2618 Py_INCREF(arg);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2619 PyTuple_SET_ITEM(args, 2, arg);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2620 tstate->tracing++;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2621 PyFrame_FastToLocals(f);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2622 res = PyEval_CallObject(*p_trace, args); /* May clear *p_trace! */
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2623 PyFrame_LocalsToFast(f, 1);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2624 tstate->tracing--;
5937
5a4d181ffffd Renamed a local label that was accidentally grandly renamed to
Guido van Rossum <guido@python.org>
parents: 5926
diff changeset
2625 cleanup:
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2626 Py_XDECREF(args);
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2627 if (res == NULL) {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2628 /* The trace proc raised an exception */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2629 PyTraceBack_Here(f);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2630 Py_XDECREF(*p_trace);
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2631 *p_trace = NULL;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2632 if (p_newtrace) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2633 Py_XDECREF(*p_newtrace);
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2634 *p_newtrace = NULL;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2635 }
11263
47171f2d7d58 call_trace(): A fix for PR#73, if an exception occurred in the
Barry Warsaw <barry@python.org>
parents: 11030
diff changeset
2636 /* to be extra double plus sure we don't get recursive
47171f2d7d58 call_trace(): A fix for PR#73, if an exception occurred in the
Barry Warsaw <barry@python.org>
parents: 11030
diff changeset
2637 * calls inf either tracefunc or profilefunc gets an
47171f2d7d58 call_trace(): A fix for PR#73, if an exception occurred in the
Barry Warsaw <barry@python.org>
parents: 11030
diff changeset
2638 * exception, zap the global variables.
47171f2d7d58 call_trace(): A fix for PR#73, if an exception occurred in the
Barry Warsaw <barry@python.org>
parents: 11030
diff changeset
2639 */
47171f2d7d58 call_trace(): A fix for PR#73, if an exception occurred in the
Barry Warsaw <barry@python.org>
parents: 11030
diff changeset
2640 Py_XDECREF(tstate->sys_tracefunc);
47171f2d7d58 call_trace(): A fix for PR#73, if an exception occurred in the
Barry Warsaw <barry@python.org>
parents: 11030
diff changeset
2641 tstate->sys_tracefunc = NULL;
47171f2d7d58 call_trace(): A fix for PR#73, if an exception occurred in the
Barry Warsaw <barry@python.org>
parents: 11030
diff changeset
2642 Py_XDECREF(tstate->sys_profilefunc);
47171f2d7d58 call_trace(): A fix for PR#73, if an exception occurred in the
Barry Warsaw <barry@python.org>
parents: 11030
diff changeset
2643 tstate->sys_profilefunc = NULL;
789
f565cf7f9aba (Hopefully) fix bug in reference count in call_exc_trace()
Guido van Rossum <guido@python.org>
parents: 746
diff changeset
2644 return -1;
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2645 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2646 else {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2647 if (p_newtrace) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2648 Py_XDECREF(*p_newtrace);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2649 if (res == Py_None)
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2650 *p_newtrace = NULL;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2651 else {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2652 Py_INCREF(res);
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2653 *p_newtrace = res;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2654 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2655 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2656 Py_DECREF(res);
789
f565cf7f9aba (Hopefully) fix bug in reference count in call_exc_trace()
Guido van Rossum <guido@python.org>
parents: 746
diff changeset
2657 return 0;
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2658 }
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2659 }
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2660
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2661 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2662 PyEval_GetBuiltins(void)
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
2663 {
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5911
diff changeset
2664 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
2665 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
2666 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
2667 return tstate->interp->builtins;
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
2668 else
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
2669 return current_frame->f_builtins;
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
2670 }
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
2671
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2672 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2673 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
2674 {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2675 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
2676 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
2677 return NULL;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2678 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
2679 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
2680 }
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
2681
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2682 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2683 PyEval_GetGlobals(void)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2684 {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2685 PyFrameObject *current_frame = PyThreadState_Get()->frame;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2686 if (current_frame == NULL)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2687 return NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2688 else
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2689 return current_frame->f_globals;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2690 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2691
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2692 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2693 PyEval_GetFrame(void)
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2694 {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2695 PyFrameObject *current_frame = PyThreadState_Get()->frame;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2696 return (PyObject *)current_frame;
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2697 }
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2698
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
2699 int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2700 PyEval_GetRestricted(void)
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
2701 {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2702 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
2703 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
2704 }
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
2705
5606
495fbde64a73 Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents: 5557
diff changeset
2706 int
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
2707 PyEval_GetNestedScopes(void)
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
2708 {
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
2709 PyFrameObject *current_frame = PyThreadState_Get()->frame;
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
2710 return current_frame == NULL ? 0 :
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
2711 current_frame->f_code->co_flags & CO_NESTED;
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
2712 }
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
2713
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
2714 int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2715 Py_FlushLine(void)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2716 {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2717 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
2718 if (f == NULL)
495fbde64a73 Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents: 5557
diff changeset
2719 return 0;
495fbde64a73 Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents: 5557
diff changeset
2720 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
2721 return 0;
495fbde64a73 Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents: 5557
diff changeset
2722 return PyFile_WriteString("\n", f);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2723 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2724
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2725
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2726 /* External interface to call any callable object.
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2727 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
2728
6206
77f5b6cbea66 Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents: 6185
diff changeset
2729 #undef PyEval_CallObject
77f5b6cbea66 Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents: 6185
diff changeset
2730 /* for backward compatibility: export this interface */
77f5b6cbea66 Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents: 6185
diff changeset
2731
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2732 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2733 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
2734 {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2735 return PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2736 }
6206
77f5b6cbea66 Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents: 6185
diff changeset
2737 #define PyEval_CallObject(func,arg) \
77f5b6cbea66 Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents: 6185
diff changeset
2738 PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL)
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2739
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2740 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2741 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
2742 {
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2743 PyObject *result;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2744
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2745 if (arg == NULL)
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2746 arg = PyTuple_New(0);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2747 else if (!PyTuple_Check(arg)) {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2748 PyErr_SetString(PyExc_TypeError,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2749 "argument list must be a tuple");
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2750 return NULL;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2751 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2752 else
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2753 Py_INCREF(arg);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2754
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2755 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
2756 PyErr_SetString(PyExc_TypeError,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2757 "keyword list must be a dictionary");
12440
d47460b1a679 Charles Waldman writes:
Guido van Rossum <guido@python.org>
parents: 12320
diff changeset
2758 Py_DECREF(arg);
2894
4095782c940e empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents: 2872
diff changeset
2759 return NULL;
4095782c940e empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents: 2872
diff changeset
2760 }
4095782c940e empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents: 2872
diff changeset
2761
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2762 result = call_object(func, arg, kw);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2763 Py_DECREF(arg);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2764 return result;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2765 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2766
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2767 /* How often is each kind of object called? The answer depends on the
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2768 program. An instrumented call_object() was used to run the Python
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2769 regression test suite. The results were:
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2770 4200000 PyCFunctions
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2771 390000 fast_function() calls
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2772 94000 other functions
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2773 480000 all functions (sum of prev two)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2774 150000 methods
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2775 100000 classes
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2776
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2777 Tests on other bodies of code show that PyCFunctions are still
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2778 most common, but not by such a large margin.
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2779 */
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2780
17406
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
2781 static char *
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
2782 get_func_name(PyObject *func)
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
2783 {
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
2784 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
2785 return get_func_name(PyMethod_GET_FUNCTION(func));
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
2786 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
2787 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
2788 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
2789 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
2790 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
2791 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
2792 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
2793 return PyString_AsString(
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
2794 ((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
2795 } else {
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
2796 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
2797 }
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
2798 }
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
2799
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
2800 static char *
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
2801 get_func_desc(PyObject *func)
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
2802 {
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
2803 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
2804 return "()";
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
2805 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
2806 return "()";
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
2807 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
2808 return "()";
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
2809 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
2810 return " constructor";
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
2811 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
2812 return " instance";
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
2813 } else {
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
2814 return " object";
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
2815 }
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
2816 }
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
2817
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2818 static PyObject *
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2819 call_object(PyObject *func, PyObject *arg, PyObject *kw)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2820 {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2821 ternaryfunc call;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2822 PyObject *result;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2823
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2824 if (PyMethod_Check(func))
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2825 result = call_method(func, arg, kw);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2826 else if (PyFunction_Check(func))
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2827 result = call_eval_code2(func, arg, kw);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2828 else if (PyCFunction_Check(func))
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2829 result = call_cfunction(func, arg, kw);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2830 else if (PyClass_Check(func))
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2831 result = PyInstance_New(func, arg, kw);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2832 else if (PyInstance_Check(func))
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2833 result = call_instance(func, arg, kw);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2834 else if ((call = func->ob_type->tp_call) != NULL)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2835 result = (*call)(func, arg, kw);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2836 else {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2837 PyErr_Format(PyExc_TypeError, "object is not callable: %s",
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2838 PyString_AS_STRING(PyObject_Repr(func)));
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2839 return NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2840 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2841 if (result == NULL && !PyErr_Occurred())
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2842 PyErr_SetString(PyExc_SystemError,
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2843 "NULL result without error in call_object");
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2844
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2845 return result;
314
e83852d1a5e2 Add interface to call a Python function (or other callable) object
Guido van Rossum <guido@python.org>
parents: 312
diff changeset
2846 }
e83852d1a5e2 Add interface to call a Python function (or other callable) object
Guido van Rossum <guido@python.org>
parents: 312
diff changeset
2847
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2848 static PyObject *
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2849 call_cfunction(PyObject *func, PyObject *arg, PyObject *kw)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2850 {
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2851 PyCFunctionObject* f = (PyCFunctionObject*)func;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2852 PyCFunction meth = PyCFunction_GET_FUNCTION(func);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2853 PyObject *self = PyCFunction_GET_SELF(func);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2854 int flags = PyCFunction_GET_FLAGS(func);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2855
15739
97821a46e000 When a PyCFunction that takes only positional parameters is called with
Fred Drake <fdrake@acm.org>
parents: 15711
diff changeset
2856 if (flags & METH_KEYWORDS) {
97821a46e000 When a PyCFunction that takes only positional parameters is called with
Fred Drake <fdrake@acm.org>
parents: 15711
diff changeset
2857 return (*(PyCFunctionWithKeywords)meth)(self, arg, kw);
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2858 }
15739
97821a46e000 When a PyCFunction that takes only positional parameters is called with
Fred Drake <fdrake@acm.org>
parents: 15711
diff changeset
2859 if (kw != NULL && PyDict_Size(kw) != 0) {
97821a46e000 When a PyCFunction that takes only positional parameters is called with
Fred Drake <fdrake@acm.org>
parents: 15711
diff changeset
2860 PyErr_Format(PyExc_TypeError,
97821a46e000 When a PyCFunction that takes only positional parameters is called with
Fred Drake <fdrake@acm.org>
parents: 15711
diff changeset
2861 "%.200s() takes no keyword arguments",
97821a46e000 When a PyCFunction that takes only positional parameters is called with
Fred Drake <fdrake@acm.org>
parents: 15711
diff changeset
2862 f->m_ml->ml_name);
97821a46e000 When a PyCFunction that takes only positional parameters is called with
Fred Drake <fdrake@acm.org>
parents: 15711
diff changeset
2863 return NULL;
97821a46e000 When a PyCFunction that takes only positional parameters is called with
Fred Drake <fdrake@acm.org>
parents: 15711
diff changeset
2864 }
97821a46e000 When a PyCFunction that takes only positional parameters is called with
Fred Drake <fdrake@acm.org>
parents: 15711
diff changeset
2865 if (flags & METH_VARARGS) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2866 return (*meth)(self, arg);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2867 }
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2868 if (!(flags & METH_VARARGS)) {
15739
97821a46e000 When a PyCFunction that takes only positional parameters is called with
Fred Drake <fdrake@acm.org>
parents: 15711
diff changeset
2869 /* the really old style */
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2870 int size = PyTuple_GET_SIZE(arg);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2871 if (size == 1)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2872 arg = PyTuple_GET_ITEM(arg, 0);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2873 else if (size == 0)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2874 arg = NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2875 return (*meth)(self, arg);
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2876 }
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2877 /* should never get here ??? */
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2878 PyErr_BadInternalCall();
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2879 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2880 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2881
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2882 static PyObject *
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2883 call_instance(PyObject *func, PyObject *arg, PyObject *kw)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2884 {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2885 PyObject *res, *call = PyObject_GetAttrString(func, "__call__");
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2886 if (call == NULL) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2887 PyInstanceObject *inst = (PyInstanceObject*) func;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2888 PyErr_Clear();
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2889 PyErr_Format(PyExc_AttributeError,
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2890 "%.200s instance has no __call__ method",
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2891 PyString_AsString(inst->in_class->cl_name));
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2892 return NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2893 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2894 res = call_object(call, arg, kw);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2895 Py_DECREF(call);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2896 return res;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2897 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2898
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2899 static PyObject *
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2900 call_method(PyObject *func, PyObject *arg, PyObject *kw)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2901 {
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2902 PyObject *self = PyMethod_GET_SELF(func);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2903 PyObject *class = PyMethod_GET_CLASS(func);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2904 PyObject *result;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2905
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2906 func = PyMethod_GET_FUNCTION(func);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2907 if (self == NULL) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2908 /* Unbound methods must be called with an instance of
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2909 the class (or a derived class) as first argument */
17114
6fe13d008e25 Use PyObject_IsInstance() to check whether the first argument to an
Guido van Rossum <guido@python.org>
parents: 17104
diff changeset
2910 int ok;
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2911 if (PyTuple_Size(arg) >= 1)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2912 self = PyTuple_GET_ITEM(arg, 0);
17114
6fe13d008e25 Use PyObject_IsInstance() to check whether the first argument to an
Guido van Rossum <guido@python.org>
parents: 17104
diff changeset
2913 if (self == NULL)
6fe13d008e25 Use PyObject_IsInstance() to check whether the first argument to an
Guido van Rossum <guido@python.org>
parents: 17104
diff changeset
2914 ok = 0;
6fe13d008e25 Use PyObject_IsInstance() to check whether the first argument to an
Guido van Rossum <guido@python.org>
parents: 17104
diff changeset
2915 else {
6fe13d008e25 Use PyObject_IsInstance() to check whether the first argument to an
Guido van Rossum <guido@python.org>
parents: 17104
diff changeset
2916 ok = PyObject_IsInstance(self, class);
6fe13d008e25 Use PyObject_IsInstance() to check whether the first argument to an
Guido van Rossum <guido@python.org>
parents: 17104
diff changeset
2917 if (ok < 0)
6fe13d008e25 Use PyObject_IsInstance() to check whether the first argument to an
Guido van Rossum <guido@python.org>
parents: 17104
diff changeset
2918 return NULL;
6fe13d008e25 Use PyObject_IsInstance() to check whether the first argument to an
Guido van Rossum <guido@python.org>
parents: 17104
diff changeset
2919 }
6fe13d008e25 Use PyObject_IsInstance() to check whether the first argument to an
Guido van Rossum <guido@python.org>
parents: 17104
diff changeset
2920 if (!ok) {
6fe13d008e25 Use PyObject_IsInstance() to check whether the first argument to an
Guido van Rossum <guido@python.org>
parents: 17104
diff changeset
2921 PyErr_Format(PyExc_TypeError,
17494
a34293ced63b Change error message raised when free variable is not yet bound. It
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17490
diff changeset
2922 "unbound method %s%s must be "
17114
6fe13d008e25 Use PyObject_IsInstance() to check whether the first argument to an
Guido van Rossum <guido@python.org>
parents: 17104
diff changeset
2923 "called with instance as first argument",
17494
a34293ced63b Change error message raised when free variable is not yet bound. It
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17490
diff changeset
2924 get_func_name(func), get_func_desc(func));
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2925 return NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2926 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2927 Py_INCREF(arg);
17114
6fe13d008e25 Use PyObject_IsInstance() to check whether the first argument to an
Guido van Rossum <guido@python.org>
parents: 17104
diff changeset
2928 }
6fe13d008e25 Use PyObject_IsInstance() to check whether the first argument to an
Guido van Rossum <guido@python.org>
parents: 17104
diff changeset
2929 else {
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2930 int argcount = PyTuple_Size(arg);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2931 PyObject *newarg = PyTuple_New(argcount + 1);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2932 int i;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2933 if (newarg == NULL)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2934 return NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2935 Py_INCREF(self);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2936 PyTuple_SET_ITEM(newarg, 0, self);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2937 for (i = 0; i < argcount; i++) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2938 PyObject *v = PyTuple_GET_ITEM(arg, i);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2939 Py_XINCREF(v);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2940 PyTuple_SET_ITEM(newarg, i+1, v);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2941 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2942 arg = newarg;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2943 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2944 result = call_object(func, arg, kw);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2945 Py_DECREF(arg);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2946 return result;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2947 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2948
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2949 static PyObject *
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2950 call_eval_code2(PyObject *func, PyObject *arg, PyObject *kw)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2951 {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2952 PyObject *result;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2953 PyObject *argdefs;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2954 PyObject **d, **k;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2955 int nk, nd;
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2956
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2957 argdefs = PyFunction_GET_DEFAULTS(func);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2958 if (argdefs != NULL && PyTuple_Check(argdefs)) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2959 d = &PyTuple_GET_ITEM((PyTupleObject *)argdefs, 0);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2960 nd = PyTuple_Size(argdefs);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2961 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2962 else {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2963 d = NULL;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2964 nd = 0;
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2965 }
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2966
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2967 if (kw != NULL) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2968 int pos, i;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2969 nk = PyDict_Size(kw);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2970 k = PyMem_NEW(PyObject *, 2*nk);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2971 if (k == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2972 PyErr_NoMemory();
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2973 Py_DECREF(arg);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2974 return NULL;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2975 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2976 pos = i = 0;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2977 while (PyDict_Next(kw, &pos, &k[i], &k[i+1]))
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2978 i += 2;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2979 nk = i/2;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2980 /* XXX This is broken if the caller deletes dict items! */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2981 }
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2982 else {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2983 k = NULL;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2984 nk = 0;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2985 }
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2986
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2987 result = eval_code2(
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2988 (PyCodeObject *)PyFunction_GET_CODE(func),
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
2989 PyFunction_GET_GLOBALS(func), (PyObject *)NULL,
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2990 &PyTuple_GET_ITEM(arg, 0), PyTuple_Size(arg),
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2991 k, nk, d, nd,
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
2992 PyFunction_GET_CLOSURE(func));
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2993
12576
1c7c2dd1beb1 Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents: 12440
diff changeset
2994 if (k != NULL)
1c7c2dd1beb1 Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents: 12440
diff changeset
2995 PyMem_DEL(k);
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
2996
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2997 return result;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2998 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2999
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3000 #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
3001
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3002 /* 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
3003 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
3004 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
3005 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
3006 */
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3007
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3008 static PyObject *
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3009 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
3010 {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3011 PyCFunction meth = PyCFunction_GET_FUNCTION(func);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3012 PyObject *self = PyCFunction_GET_SELF(func);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3013
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3014 if (na == 0)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3015 return (*meth)(self, NULL);
15809
f9772f87b13e Add missing Py_DECREF in fast_cfunction. Partial fix for SF bug
Charles G. Waldman <cgw@alum.mit.edu>
parents: 15739
diff changeset
3016 else if (na == 1) {
f9772f87b13e Add missing Py_DECREF in fast_cfunction. Partial fix for SF bug
Charles G. Waldman <cgw@alum.mit.edu>
parents: 15739
diff changeset
3017 PyObject *arg = EXT_POP(*pp_stack);
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3018 PyObject *result = (*meth)(self, arg);
15809
f9772f87b13e Add missing Py_DECREF in fast_cfunction. Partial fix for SF bug
Charles G. Waldman <cgw@alum.mit.edu>
parents: 15739
diff changeset
3019 Py_DECREF(arg);
f9772f87b13e Add missing Py_DECREF in fast_cfunction. Partial fix for SF bug
Charles G. Waldman <cgw@alum.mit.edu>
parents: 15739
diff changeset
3020 return result;
f9772f87b13e Add missing Py_DECREF in fast_cfunction. Partial fix for SF bug
Charles G. Waldman <cgw@alum.mit.edu>
parents: 15739
diff changeset
3021 } else {
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3022 PyObject *args = load_args(pp_stack, na);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3023 PyObject *result = (*meth)(self, args);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3024 Py_DECREF(args);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3025 return result;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3026 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3027 }
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 static PyObject *
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3030 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
3031 {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3032 PyObject *co = PyFunction_GET_CODE(func);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3033 PyObject *globals = PyFunction_GET_GLOBALS(func);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3034 PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
3035 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
3036 PyObject **d = NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3037 int nd = 0;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3038
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3039 if (argdefs != NULL) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3040 d = &PyTuple_GET_ITEM(argdefs, 0);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3041 nd = ((PyTupleObject *)argdefs)->ob_size;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3042 }
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3043 return eval_code2((PyCodeObject *)co, globals,
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3044 (PyObject *)NULL, (*pp_stack)-n, na,
16257
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
3045 (*pp_stack)-2*nk, nk, d, nd,
fd8c7203251f PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16017
diff changeset
3046 closure);
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3047 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3048
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3049 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
3050 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
3051 PyObject *func)
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3052 {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3053 PyObject *kwdict = NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3054 if (orig_kwdict == NULL)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3055 kwdict = PyDict_New();
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3056 else {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3057 kwdict = PyDict_Copy(orig_kwdict);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3058 Py_DECREF(orig_kwdict);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3059 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3060 if (kwdict == NULL)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3061 return NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3062 while (--nk >= 0) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3063 int err;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3064 PyObject *value = EXT_POP(*pp_stack);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3065 PyObject *key = EXT_POP(*pp_stack);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3066 if (PyDict_GetItem(kwdict, key) != NULL) {
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3067 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
3068 "%.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
3069 "for keyword argument '%.200s'",
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
3070 get_func_name(func),
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
3071 get_func_desc(func),
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
3072 PyString_AsString(key));
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3073 Py_DECREF(key);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3074 Py_DECREF(value);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3075 Py_DECREF(kwdict);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3076 return NULL;
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 err = PyDict_SetItem(kwdict, key, value);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3079 Py_DECREF(key);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3080 Py_DECREF(value);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3081 if (err) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3082 Py_DECREF(kwdict);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3083 return NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3084 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3085 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3086 return kwdict;
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
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3089 static PyObject *
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3090 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
3091 PyObject ***pp_stack)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3092 {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3093 PyObject *callargs, *w;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3094
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3095 callargs = PyTuple_New(nstack + nstar);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3096 if (callargs == NULL) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3097 return NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3098 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3099 if (nstar) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3100 int i;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3101 for (i = 0; i < nstar; i++) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3102 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
3103 Py_INCREF(a);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3104 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
3105 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3106 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3107 while (--nstack >= 0) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3108 w = EXT_POP(*pp_stack);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3109 PyTuple_SET_ITEM(callargs, nstack, w);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3110 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3111 return callargs;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3112 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3113
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3114 static PyObject *
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3115 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
3116 {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3117 PyObject *args = PyTuple_New(na);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3118 PyObject *w;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3119
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3120 if (args == NULL)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3121 return NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3122 while (--na >= 0) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3123 w = EXT_POP(*pp_stack);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3124 PyTuple_SET_ITEM(args, na, w);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3125 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3126 return args;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3127 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3128
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3129 static PyObject *
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3130 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
3131 {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3132 PyObject *callargs = NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3133 PyObject *kwdict = NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3134 PyObject *result = NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3135
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3136 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
3137 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
3138 if (kwdict == NULL)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3139 goto call_fail;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3140 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3141 callargs = load_args(pp_stack, na);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3142 if (callargs == NULL)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3143 goto call_fail;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3144 result = call_object(func, callargs, kwdict);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3145 call_fail:
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3146 Py_XDECREF(callargs);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3147 Py_XDECREF(kwdict);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3148 return result;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3149 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3150
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3151 static PyObject *
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3152 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
3153 {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3154 int nstar = 0;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3155 PyObject *callargs = NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3156 PyObject *stararg = NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3157 PyObject *kwdict = NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3158 PyObject *result = NULL;
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 if (flags & CALL_FLAG_KW) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3161 kwdict = EXT_POP(*pp_stack);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3162 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
3163 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
3164 "%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
3165 "must be a dictionary",
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
3166 get_func_name(func),
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
3167 get_func_desc(func));
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3168 goto ext_call_fail;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3169 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3170 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3171 if (flags & CALL_FLAG_VAR) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3172 stararg = EXT_POP(*pp_stack);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3173 if (!PyTuple_Check(stararg)) {
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3174 PyObject *t = NULL;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3175 t = PySequence_Tuple(stararg);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3176 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
3177 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
3178 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
3179 "%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
3180 "must be a sequence",
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
3181 get_func_name(func),
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
3182 get_func_desc(func));
c9e07bc303a2 Fix exception handling for non-PyFunction objects, SF bug 414743.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17125
diff changeset
3183 }
15711
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3184 goto ext_call_fail;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3185 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3186 Py_DECREF(stararg);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3187 stararg = t;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3188 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3189 nstar = PyTuple_GET_SIZE(stararg);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3190 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3191 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
3192 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
3193 if (kwdict == NULL)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3194 goto ext_call_fail;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3195 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3196 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
3197 if (callargs == NULL)
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3198 goto ext_call_fail;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3199 result = call_object(func, callargs, kwdict);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3200 ext_call_fail:
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3201 Py_XDECREF(callargs);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3202 Py_XDECREF(kwdict);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3203 Py_XDECREF(stararg);
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3204 return result;
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3205 }
2481b5fe86d6 Revised implementation of CALL_FUNCTION and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15364
diff changeset
3206
3863
4566a19c3438 Better error message if stride used on normal sequence object
Guido van Rossum <guido@python.org>
parents: 3839
diff changeset
3207 #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
3208 "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
3209
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3210 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3211 loop_subscript(PyObject *v, PyObject *w)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3212 {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3213 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
3214 int i;
8403
c4df8b6637b6 Moved cmp_member() to abstract.c, as PySequence_Contains() [with
Guido van Rossum <guido@python.org>
parents: 8328
diff changeset
3215 if (sq == NULL || sq->sq_item == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3216 PyErr_SetString(PyExc_TypeError, "loop over non-sequence");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3217 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3218 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3219 i = PyInt_AsLong(w);
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
3220 v = (*sq->sq_item)(v, i);
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
3221 if (v)
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
3222 return v;
6147
b76a44163e0f cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents: 6139
diff changeset
3223 if (PyErr_ExceptionMatches(PyExc_IndexError))
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3224 PyErr_Clear();
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
3225 return NULL;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3226 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3227
12614
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
3228 /* Extract a slice index from a PyInt or PyLong, the index is bound to
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
3229 the range [-INT_MAX+1, INTMAX]. Returns 0 and an exception if there is
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
3230 and error. Returns 1 on success.*/
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
3231
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
3232 int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3233 _PyEval_SliceIndex(PyObject *v, int *pi)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3234 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3235 if (v != NULL) {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3236 long x;
11839
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
3237 if (PyInt_Check(v)) {
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
3238 x = PyInt_AsLong(v);
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
3239 } else if (PyLong_Check(v)) {
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
3240 x = PyLong_AsLong(v);
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
3241 if (x==-1 && PyErr_Occurred()) {
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
3242 PyObject *long_zero;
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3243 int cmp;
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3244
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3245 if (!PyErr_ExceptionMatches(
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3246 PyExc_OverflowError)) {
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3247 /* 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
3248 signal an error */
12614
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
3249 return 0;
11839
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
3250 }
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
3251
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3252 /* Clear the OverflowError */
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3253 PyErr_Clear();
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3254
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3255 /* It's an overflow error, so we need to
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3256 check the sign of the long integer,
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3257 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
3258 the error. */
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
3259
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
3260 /* 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
3261 long_zero = PyLong_FromLong(0L);
12614
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
3262 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
3263
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
3264 /* Check sign */
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3265 cmp = PyObject_RichCompareBool(v, long_zero,
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3266 Py_GT);
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3267 Py_DECREF(long_zero);
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3268 if (cmp < 0)
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3269 return 0;
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3270 else if (cmp > 0)
11839
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
3271 x = INT_MAX;
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
3272 else
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
3273 x = 0;
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
3274 }
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
3275 } else {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3276 PyErr_SetString(PyExc_TypeError,
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 15166
diff changeset
3277 "slice indices must be integers");
12614
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
3278 return 0;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3279 }
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3280 /* 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
3281 if (x > INT_MAX)
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3282 x = INT_MAX;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3283 else if (x < -INT_MAX)
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3284 x = 0;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3285 *pi = x;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3286 }
12614
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
3287 return 1;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3288 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3289
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3290 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3291 apply_slice(PyObject *u, PyObject *v, PyObject *w) /* return u[v:w] */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3292 {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3293 int ilow = 0, ihigh = INT_MAX;
12614
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
3294 if (!_PyEval_SliceIndex(v, &ilow))
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3295 return NULL;
12614
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
3296 if (!_PyEval_SliceIndex(w, &ihigh))
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
3297 return NULL;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3298 return PySequence_GetSlice(u, ilow, ihigh);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3299 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3300
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3301 static int
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3302 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
3303 /* u[v:w] = x */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3304 {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3305 int ilow = 0, ihigh = INT_MAX;
12614
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
3306 if (!_PyEval_SliceIndex(v, &ilow))
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3307 return -1;
12614
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
3308 if (!_PyEval_SliceIndex(w, &ihigh))
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3309 return -1;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3310 if (x == NULL)
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3311 return PySequence_DelSlice(u, ilow, ihigh);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3312 else
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3313 return PySequence_SetSlice(u, ilow, ihigh, x);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3314 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3315
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3316 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3317 cmp_outcome(int op, register PyObject *v, register PyObject *w)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3318 {
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3319 int res = 0;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3320 switch (op) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3321 case IS:
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3322 case IS_NOT:
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3323 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
3324 if (op == (int) IS_NOT)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3325 res = !res;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3326 break;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3327 case IN:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3328 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
3329 res = PySequence_Contains(w, v);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3330 if (res < 0)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3331 return NULL;
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
3332 if (op == (int) NOT_IN)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
3333 res = !res;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3334 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3335 case EXC_MATCH:
6147
b76a44163e0f cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents: 6139
diff changeset
3336 res = PyErr_GivenExceptionMatches(v, w);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3337 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3338 default:
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3339 return PyObject_RichCompare(v, w, op);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3340 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3341 v = res ? Py_True : Py_False;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3342 Py_INCREF(v);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3343 return v;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3344 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3345
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
3346 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
3347 import_from(PyObject *v, PyObject *name)
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
3348 {
15830
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3349 PyObject *x;
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3350
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3351 x = PyObject_GetAttr(v, name);
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3352 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
3353 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
3354 "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
3355 PyString_AsString(name));
15830
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3356 }
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
3357 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
3358 }
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3359
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
3360 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
3361 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
3362 {
15830
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3363 PyObject *all = PyObject_GetAttrString(v, "__all__");
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3364 PyObject *dict, *name, *value;
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3365 int skip_leading_underscores = 0;
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3366 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
3367
15830
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3368 if (all == NULL) {
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3369 if (!PyErr_ExceptionMatches(PyExc_AttributeError))
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3370 return -1; /* Unexpected error */
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3371 PyErr_Clear();
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3372 dict = PyObject_GetAttrString(v, "__dict__");
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3373 if (dict == NULL) {
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3374 if (!PyErr_ExceptionMatches(PyExc_AttributeError))
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3375 return -1;
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3376 PyErr_SetString(PyExc_ImportError,
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3377 "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
3378 return -1;
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3379 }
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3380 all = PyMapping_Keys(dict);
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3381 Py_DECREF(dict);
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3382 if (all == NULL)
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3383 return -1;
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3384 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
3385 }
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
3386
15830
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3387 for (pos = 0, err = 0; ; pos++) {
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3388 name = PySequence_GetItem(all, pos);
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3389 if (name == NULL) {
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3390 if (!PyErr_ExceptionMatches(PyExc_IndexError))
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3391 err = -1;
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3392 else
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3393 PyErr_Clear();
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3394 break;
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3395 }
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3396 if (skip_leading_underscores &&
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3397 PyString_Check(name) &&
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3398 PyString_AS_STRING(name)[0] == '_')
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3399 {
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3400 Py_DECREF(name);
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3401 continue;
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3402 }
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3403 value = PyObject_GetAttr(v, name);
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3404 if (value == NULL)
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3405 err = -1;
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3406 else
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3407 err = PyDict_SetItem(locals, name, value);
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3408 Py_DECREF(name);
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3409 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
3410 if (err != 0)
15830
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3411 break;
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
3412 }
15830
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3413 Py_DECREF(all);
e00f718e4d8a Two changes to from...import:
Guido van Rossum <guido@python.org>
parents: 15814
diff changeset
3414 return err;
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
3415 }
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
3416
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3417 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3418 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
3419 {
6139
a287c5014e66 Reverse the search order for the Don Beaudry hook so that the first
Guido van Rossum <guido@python.org>
parents: 5937
diff changeset
3420 int i, n;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3421 if (!PyTuple_Check(bases)) {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3422 PyErr_SetString(PyExc_SystemError,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3423 "build_class with non-tuple bases");
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
3424 return NULL;
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
3425 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3426 if (!PyDict_Check(methods)) {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3427 PyErr_SetString(PyExc_SystemError,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3428 "build_class with non-dictionary");
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
3429 return NULL;
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
3430 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3431 if (!PyString_Check(name)) {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
3432 PyErr_SetString(PyExc_SystemError,
12174
2745dae8705f Thomas Heller fixes a typo in an error message.
Guido van Rossum <guido@python.org>
parents: 12149
diff changeset
3433 "build_class with non-string name");
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
3434 return NULL;
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
3435 }
6139
a287c5014e66 Reverse the search order for the Don Beaudry hook so that the first
Guido van Rossum <guido@python.org>
parents: 5937
diff changeset
3436 n = PyTuple_Size(bases);
a287c5014e66 Reverse the search order for the Don Beaudry hook so that the first
Guido van Rossum <guido@python.org>
parents: 5937
diff changeset
3437 for (i = 0; i < n; i++) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3438 PyObject *base = PyTuple_GET_ITEM(bases, i);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3439 if (!PyClass_Check(base)) {
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
3440 /* Call the base's *type*, if it is callable.
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
3441 This code is a hook for Donald Beaudry's
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
3442 and Jim Fulton's type extensions. In
13620
5b727ab37092 Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents: 13552
diff changeset
3443 unextended Python it will never be triggered
5911
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3444 since its types are not callable.
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3445 Ditto: call the bases's *class*, if it has
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3446 one. This makes the same thing possible
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3447 without writing C code. A true meta-object
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3448 protocol! */
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3449 PyObject *basetype = (PyObject *)base->ob_type;
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3450 PyObject *callable = NULL;
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3451 if (PyCallable_Check(basetype))
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3452 callable = basetype;
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3453 else
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3454 callable = PyObject_GetAttrString(
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3455 base, "__class__");
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3456 if (callable) {
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3457 PyObject *args;
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3458 PyObject *newclass = NULL;
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3459 args = Py_BuildValue(
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3460 "(OOO)", name, bases, methods);
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3461 if (args != NULL) {
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3462 newclass = PyEval_CallObject(
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3463 callable, args);
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3464 Py_DECREF(args);
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3465 }
7982
a909a2869ac5 Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 7946
diff changeset
3466 if (callable != basetype) {
5911
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3467 Py_DECREF(callable);
7982
a909a2869ac5 Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 7946
diff changeset
3468 }
5911
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3469 return newclass;
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
3470 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3471 PyErr_SetString(PyExc_TypeError,
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
3472 "base is not a class object");
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
3473 return NULL;
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
3474 }
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
3475 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3476 return PyClass_New(bases, methods, name);
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
3477 }
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
3478
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3479 static int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3480 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
3481 PyObject *locals)
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3482 {
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3483 int n;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3484 PyObject *v;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3485 int plain = 0;
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3486
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3487 if (PyTuple_Check(prog) && globals == Py_None && locals == Py_None &&
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3488 ((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
3489 /* Backward compatibility hack */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3490 globals = PyTuple_GetItem(prog, 1);
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3491 if (n == 3)
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3492 locals = PyTuple_GetItem(prog, 2);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3493 prog = PyTuple_GetItem(prog, 0);
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3494 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3495 if (globals == Py_None) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3496 globals = PyEval_GetGlobals();
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3497 if (locals == Py_None) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3498 locals = PyEval_GetLocals();
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3499 plain = 1;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3500 }
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3501 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3502 else if (locals == Py_None)
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3503 locals = globals;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3504 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
3505 !PyUnicode_Check(prog) &&
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3506 !PyCode_Check(prog) &&
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3507 !PyFile_Check(prog)) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3508 PyErr_SetString(PyExc_TypeError,
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3509 "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
3510 return -1;
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3511 }
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 15166
diff changeset
3512 if (!PyDict_Check(globals)) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3513 PyErr_SetString(PyExc_TypeError,
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 15166
diff changeset
3514 "exec: arg 2 must be a dictionary or None");
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 15166
diff changeset
3515 return -1;
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 15166
diff changeset
3516 }
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 15166
diff changeset
3517 if (!PyDict_Check(locals)) {
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 15166
diff changeset
3518 PyErr_SetString(PyExc_TypeError,
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 15166
diff changeset
3519 "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
3520 return -1;
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3521 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3522 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
3523 PyDict_SetItemString(globals, "__builtins__", f->f_builtins);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3524 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
3525 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
3526 }
11651
d88996e46cb2 Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents: 11468
diff changeset
3527 else if (PyFile_Check(prog)) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3528 FILE *fp = PyFile_AsFile(prog);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3529 char *name = PyString_AsString(PyFile_Name(prog));
17125
2054cea38754 Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17124
diff changeset
3530 if (PyEval_GetNestedScopes()) {
2054cea38754 Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17124
diff changeset
3531 PyCompilerFlags cf;
2054cea38754 Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17124
diff changeset
3532 cf.cf_nested_scopes = 1;
2054cea38754 Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17124
diff changeset
3533 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
3534 locals, &cf);
2054cea38754 Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17124
diff changeset
3535 } else {
2054cea38754 Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17124
diff changeset
3536 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
3537 locals);
2054cea38754 Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17124
diff changeset
3538 }
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3539 }
11651
d88996e46cb2 Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents: 11468
diff changeset
3540 else {
14696
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
3541 char *str;
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
3542 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
3543 return -1;
17125
2054cea38754 Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17124
diff changeset
3544 if (PyEval_GetNestedScopes()) {
2054cea38754 Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17124
diff changeset
3545 PyCompilerFlags cf;
2054cea38754 Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17124
diff changeset
3546 cf.cf_nested_scopes = 1;
2054cea38754 Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17124
diff changeset
3547 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
3548 locals, &cf);
2054cea38754 Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17124
diff changeset
3549 } else
2054cea38754 Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17124
diff changeset
3550 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
3551 }
11651
d88996e46cb2 Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents: 11468
diff changeset
3552 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
3553 PyFrame_LocalsToFast(f, 0);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3554 if (v == NULL)
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3555 return -1;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3556 Py_DECREF(v);
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3557 return 0;
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3558 }
2338
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
3559
15948
3bc2440427d3 Rich comparisons fall-out:
Guido van Rossum <guido@python.org>
parents: 15899
diff changeset
3560 static void
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3561 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
3562 {
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3563 char *obj_str;
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3564
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3565 if (!obj)
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3566 return;
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3567
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3568 obj_str = PyString_AsString(obj);
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3569 if (!obj_str)
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3570 return;
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3571
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3572 PyErr_Format(exc, format_str, obj_str);
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3573 }
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3574
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3575 #ifdef DYNAMIC_EXECUTION_PROFILE
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3576
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3577 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3578 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
3579 {
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3580 int i;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3581 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
3582 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
3583 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
3584 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
3585 if (x == NULL) {
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3586 Py_DECREF(l);
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3587 return NULL;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3588 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3589 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
3590 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3591 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
3592 a[i] = 0;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3593 return l;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3594 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3595
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3596 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3597 _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
3598 {
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3599 #ifndef DXPAIRS
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3600 return getarray(dxp);
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3601 #else
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3602 int i;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3603 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
3604 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
3605 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
3606 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
3607 if (x == NULL) {
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3608 Py_DECREF(l);
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3609 return NULL;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3610 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3611 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
3612 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3613 return l;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3614 #endif
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3615 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3616
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3617 #endif