annotate Python/ceval.c @ 68231:5fd74354d73b 2.0

Close 2.0 branch.
author Georg Brandl <georg@python.org>
date Sat, 05 Mar 2011 14:54:19 +0100
parents e61e64d1b5ec
children 8aa947e1eee8
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
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
32
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
33 /* Forward declarations */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
34
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
35 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
36 PyObject *, PyObject *,
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
37 PyObject **, int,
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,
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
40 PyObject *);
746
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
41 #ifdef LLTRACE
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
42 static int prtrace(PyObject *, char *);
746
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
43 #endif
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
44 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
45 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
46 PyFrameObject *, char *, PyObject *);
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
47 static PyObject *call_builtin(PyObject *, PyObject *, PyObject *);
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
48 static PyObject *call_function(PyObject *, PyObject *, PyObject *);
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
49 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
50 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
51 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
52 PyObject *, PyObject *);
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
53 static PyObject *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
54 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
55 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
56 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
57 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
58 PyObject *, PyObject *, PyObject *);
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
59 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
60 static void reset_exc_info(PyThreadState *);
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
61 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
62
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
63 #define NAME_ERROR_MSG \
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
64 "There is no variable named '%s'"
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
65 #define UNBOUNDLOCAL_ERROR_MSG \
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
66 "Local variable '%.200s' referenced before assignment"
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
67
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
68 /* Dynamic execution profile */
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
69 #ifdef DYNAMIC_EXECUTION_PROFILE
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
70 #ifdef DXPAIRS
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
71 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
72 #define dxp dxpairs[256]
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
73 #else
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
74 static long dxp[256];
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
75 #endif
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
76 #endif
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
77
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
78
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
79 #ifdef WITH_THREAD
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
80
10530
d834ecdf8c26 Changes by Mark Hammond for Windows CE. Mostly of the form
Guido van Rossum <guido@python.org>
parents: 10363
diff changeset
81 #ifndef DONT_HAVE_ERRNO_H
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
82 #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
83 #endif
9203
07dae6fdae79 Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents: 9048
diff changeset
84 #include "pythread.h"
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
85
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
86 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
87
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9671
diff changeset
88 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
89 static long main_thread = 0;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
90
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
91 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
92 PyEval_InitThreads(void)
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
93 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
94 if (interpreter_lock)
1179
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1132
diff changeset
95 return;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
96 _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
97 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
98 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
99 main_thread = PyThread_get_thread_ident();
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
100 }
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
101
5865
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
102 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
103 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
104 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9671
diff changeset
105 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
106 }
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5911
diff changeset
107
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5911
diff changeset
108 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
109 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
110 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9671
diff changeset
111 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
112 }
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5911
diff changeset
113
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5911
diff changeset
114 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
115 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
116 {
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
117 if (tstate == NULL)
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
118 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
119 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
120 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
121 Py_FatalError(
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
122 "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
123 }
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
124
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
125 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
126 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
127 {
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
128 if (tstate == NULL)
9841bce37c4d Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
Guido van Rossum <guido@python.org>
parents: 5846
diff changeset
129 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
130 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
131 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
132 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
133 }
14225
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
134
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
135 /* 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
136 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
137 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
138 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
139
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
140 void
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
141 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
142 {
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
143 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
144 return;
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 14163
diff changeset
145 /*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
146 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
147 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
148 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
149 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
150 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
151 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
152 }
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
153 #endif
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
154
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
155 /* Functions save_thread and restore_thread are always defined so
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
156 dynamically loaded modules needn't be compiled separately for use
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
157 with and without threads: */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
158
5846
852a1fa62a7c PyEval_SaveThread() and PyEval_RestoreThread() now return/take a
Guido van Rossum <guido@python.org>
parents: 5829
diff changeset
159 PyThreadState *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
160 PyEval_SaveThread(void)
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
161 {
6365
21b93d98926b Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents: 6243
diff changeset
162 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
163 if (tstate == NULL)
21b93d98926b Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents: 6243
diff changeset
164 Py_FatalError("PyEval_SaveThread: NULL tstate");
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
165 #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
166 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
167 PyThread_release_lock(interpreter_lock);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
168 #endif
6365
21b93d98926b Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents: 6243
diff changeset
169 return tstate;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
170 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
171
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
172 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
173 PyEval_RestoreThread(PyThreadState *tstate)
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
174 {
6365
21b93d98926b Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents: 6243
diff changeset
175 if (tstate == NULL)
21b93d98926b Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents: 6243
diff changeset
176 Py_FatalError("PyEval_RestoreThread: NULL tstate");
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
177 #ifdef WITH_THREAD
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
178 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
179 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
180 PyThread_acquire_lock(interpreter_lock, 1);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
181 errno = err;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
182 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
183 #endif
6365
21b93d98926b Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
Guido van Rossum <guido@python.org>
parents: 6243
diff changeset
184 PyThreadState_Swap(tstate);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
185 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
186
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
187
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
188 /* 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
189 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
190 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
191 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
192 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
193 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
194
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
195 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
196 (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
197 an exception condition).
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
198
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
199 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
200 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
201
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
202 #ifdef WITH_THREAD
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
203 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
204 will execute them.
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
205 #endif
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
206
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
207 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
208 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
209 (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
210 (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
211 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
212 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
213 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
214 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
215
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
216 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
217 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
218 */
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 #define NPENDINGCALLS 32
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
221 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
222 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
223 void *arg;
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
224 } pendingcalls[NPENDINGCALLS];
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
225 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
226 static volatile int pendinglast = 0;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
227 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
228
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
229 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
230 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
231 {
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
232 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
233 int i, j;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
234 /* 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
235 /* 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
236 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
237 if (busy)
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
238 return -1;
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
239 busy = 1;
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
240 i = pendinglast;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
241 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
242 if (j == pendingfirst)
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
243 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
244 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
245 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
246 pendinglast = j;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
247 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
248 busy = 0;
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
249 /* 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
250 return 0;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
251 }
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 int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
254 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
255 {
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
256 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
257 #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
258 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
259 return 0;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
260 #endif
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
261 if (busy)
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
262 return 0;
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
263 busy = 1;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
264 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
265 for (;;) {
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
266 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
267 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
268 void *arg;
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
269 i = pendingfirst;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
270 if (i == pendinglast)
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
271 break; /* Queue empty */
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
272 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
273 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
274 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
275 if (func(arg) < 0) {
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
276 busy = 0;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
277 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
278 return -1;
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
279 }
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
280 }
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
281 busy = 0;
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
282 return 0;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
283 }
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
284
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
285
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
286 /* The interpreter's recursion limit */
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
287
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
288 static int recursion_limit = 1000;
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
289
14348
6d0f64f7dedd Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 14333
diff changeset
290 int
6d0f64f7dedd Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 14333
diff changeset
291 Py_GetRecursionLimit(void)
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
292 {
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
293 return recursion_limit;
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
294 }
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
295
14348
6d0f64f7dedd Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 14333
diff changeset
296 void
6d0f64f7dedd Cosmetics on Py_Get/SetRecursionLimit (for the style guide)
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 14333
diff changeset
297 Py_SetRecursionLimit(int new_limit)
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
298 {
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
299 recursion_limit = new_limit;
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
300 }
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
301
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
302 /* 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
303
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
304 enum why_code {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
305 WHY_NOT, /* No error */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
306 WHY_EXCEPTION, /* Exception occurred */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
307 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
308 WHY_RETURN, /* 'return' statement */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
309 WHY_BREAK /* 'break' statement */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
310 };
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
311
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
312 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
313 static int unpack_sequence(PyObject *, int, PyObject **);
5018
001a5042b181 Cleanup:
Guido van Rossum <guido@python.org>
parents: 5014
diff changeset
314
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
315
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
316 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
317 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
318 {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
319 return eval_code2(co,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
320 globals, locals,
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
321 (PyObject **)NULL, 0,
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
322 (PyObject **)NULL, 0,
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
323 (PyObject **)NULL, 0,
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
324 (PyObject *)NULL);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
325 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
326
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
327
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
328 /* Interpreter main loop */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
329
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
330 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
331 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
332 PyObject **args, int argcount, PyObject **kws, int kwcount,
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
333 PyObject **defs, int defcount, PyObject *owner)
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
334 {
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
335 #ifdef DXPAIRS
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
336 int lastopcode = 0;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
337 #endif
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
338 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
339 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
340 register int oparg=0; /* Current opcode argument, if any */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
341 register PyObject **stack_pointer;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
342 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
343 register int err; /* Error status -- nonzero if error */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
344 register PyObject *x; /* Result object -- NULL if error */
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
345 register PyObject *v; /* Temporary objects popped off stack */
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
346 register PyObject *w;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
347 register PyObject *u;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
348 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
349 register PyObject *stream = NULL; /* for PRINT opcodes */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
350 register PyFrameObject *f; /* Current frame */
9490
b75d93ec8e5a Remove some redundant initializations -- patch by Vladimir Marangozov.
Guido van Rossum <guido@python.org>
parents: 9293
diff changeset
351 register PyObject **fastlocals;
9513
350f24180dcb Whoops! One the "redundant" initializations removed by Vladimir in
Guido van Rossum <guido@python.org>
parents: 9490
diff changeset
352 PyObject *retval = NULL; /* Return value */
9671
1d40bc25703a Use PyThreadState_GET() macro.
Guido van Rossum <guido@python.org>
parents: 9591
diff changeset
353 PyThreadState *tstate = PyThreadState_GET();
9293
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 9203
diff changeset
354 unsigned char *first_instr;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
355 #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
356 int lltrace;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
357 #endif
4839
4567e158d20c Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents: 4667
diff changeset
358 #if defined(Py_DEBUG) || defined(LLTRACE)
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
359 /* 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
360 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
361 #endif
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
362
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
363 /* Code access macros */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
364
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
365 #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
366 #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
367 #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
368 #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
369 #define NEXTOP() (*next_instr++)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
370 #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
371 #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
372 #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
373
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
374 /* Stack manipulation macros */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
375
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
376 #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
377 #define EMPTY() (STACK_LEVEL() == 0)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
378 #define TOP() (stack_pointer[-1])
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
379 #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
380 #define BASIC_POP() (*--stack_pointer)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
381
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
382 #ifdef LLTRACE
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
383 #define PUSH(v) (BASIC_PUSH(v), lltrace && prtrace(TOP(), "push"))
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
384 #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
385 #else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
386 #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
387 #define POP() BASIC_POP()
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
388 #endif
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
389
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
390 /* Local variable macros */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
391
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
392 #define GETLOCAL(i) (fastlocals[i])
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
393 #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
394 GETLOCAL(i) = value; } while (0)
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
395
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
396 /* Start of code */
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
397
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
398 #ifdef USE_STACKCHECK
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
399 if (tstate->recursion_depth%10 == 0 && PyOS_CheckStack()) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
400 PyErr_SetString(PyExc_MemoryError, "Stack overflow");
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
401 return NULL;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
402 }
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
403 #endif
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
404
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
405 if (globals == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
406 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
407 return NULL;
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
408 }
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
409
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
410 #ifdef LLTRACE
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
411 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
412 #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
413
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
414 f = PyFrame_New(
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
415 tstate, /*back*/
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
416 co, /*code*/
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
417 globals, /*globals*/
5014
0bfac89afc83 Changes for frame object speedup:
Guido van Rossum <guido@python.org>
parents: 5002
diff changeset
418 locals); /*locals*/
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
419 if (f == NULL)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
420 return NULL;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
421
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
422 tstate->frame = f;
5052
7841c48cdb5b Two small changes:
Guido van Rossum <guido@python.org>
parents: 5050
diff changeset
423 fastlocals = f->f_localsplus;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
424
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
425 if (co->co_argcount > 0 ||
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
426 co->co_flags & (CO_VARARGS | CO_VARKEYWORDS)) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
427 int i;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
428 int n = argcount;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
429 PyObject *kwdict = NULL;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
430 if (co->co_flags & CO_VARKEYWORDS) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
431 kwdict = PyDict_New();
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
432 if (kwdict == NULL)
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
433 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
434 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
435 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
436 i++;
fde73467b584 Change the control flow for error handling in the function prelude to
Guido van Rossum <guido@python.org>
parents: 5023
diff changeset
437 SETLOCAL(i, kwdict);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
438 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
439 if (argcount > co->co_argcount) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
440 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
441 PyErr_Format(PyExc_TypeError,
6d6fec2eeef6 Give more detailed error message when the argument count isn't right.
Guido van Rossum <guido@python.org>
parents: 6573
diff changeset
442 "too many arguments; expected %d, got %d",
6d6fec2eeef6 Give more detailed error message when the argument count isn't right.
Guido van Rossum <guido@python.org>
parents: 6573
diff changeset
443 co->co_argcount, argcount);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
444 goto fail;
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 n = co->co_argcount;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
447 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
448 for (i = 0; i < n; i++) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
449 x = args[i];
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
450 Py_INCREF(x);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
451 SETLOCAL(i, x);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
452 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
453 if (co->co_flags & CO_VARARGS) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
454 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
455 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
456 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
457 SETLOCAL(co->co_argcount, u);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
458 for (i = n; i < argcount; i++) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
459 x = args[i];
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
460 Py_INCREF(x);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
461 PyTuple_SET_ITEM(u, i-n, x);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
462 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
463 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
464 for (i = 0; i < kwcount; i++) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
465 PyObject *keyword = kws[2*i];
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
466 PyObject *value = kws[2*i + 1];
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
467 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
468 if (keyword == NULL || !PyString_Check(keyword)) {
507546a87dcf Fix PR117. The error message is "keywords must be strings". Perhaps
Guido van Rossum <guido@python.org>
parents: 11263
diff changeset
469 PyErr_SetString(PyExc_TypeError,
507546a87dcf Fix PR117. The error message is "keywords must be strings". Perhaps
Guido van Rossum <guido@python.org>
parents: 11263
diff changeset
470 "keywords must be strings");
507546a87dcf Fix PR117. The error message is "keywords must be strings". Perhaps
Guido van Rossum <guido@python.org>
parents: 11263
diff changeset
471 goto fail;
507546a87dcf Fix PR117. The error message is "keywords must be strings". Perhaps
Guido van Rossum <guido@python.org>
parents: 11263
diff changeset
472 }
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
473 /* XXX slow -- speed up using dictionary? */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
474 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
475 PyObject *nm = PyTuple_GET_ITEM(
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
476 co->co_varnames, j);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
477 if (PyObject_Compare(keyword, nm) == 0)
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
478 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
479 }
5610
10e9cfa010f0 PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents: 5606
diff changeset
480 /* Check errors from Compare */
10e9cfa010f0 PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents: 5606
diff changeset
481 if (PyErr_Occurred())
10e9cfa010f0 PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents: 5606
diff changeset
482 goto fail;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
483 if (j >= co->co_argcount) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
484 if (kwdict == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
485 PyErr_Format(PyExc_TypeError,
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
486 "unexpected keyword argument: %.400s",
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
487 PyString_AsString(keyword));
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
488 goto fail;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
489 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
490 PyDict_SetItem(kwdict, keyword, value);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
491 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
492 else {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
493 if (GETLOCAL(j) != NULL) {
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
494 PyErr_Format(PyExc_TypeError,
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
495 "keyword parameter redefined: %.400s",
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
496 PyString_AsString(keyword));
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
497 goto fail;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
498 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
499 Py_INCREF(value);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
500 SETLOCAL(j, value);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
501 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
502 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
503 if (argcount < co->co_argcount) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
504 int m = co->co_argcount - defcount;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
505 for (i = argcount; i < m; i++) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
506 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
507 PyErr_Format(PyExc_TypeError,
6d6fec2eeef6 Give more detailed error message when the argument count isn't right.
Guido van Rossum <guido@python.org>
parents: 6573
diff changeset
508 "not enough arguments; expected %d, got %d",
6d6fec2eeef6 Give more detailed error message when the argument count isn't right.
Guido van Rossum <guido@python.org>
parents: 6573
diff changeset
509 m, i);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
510 goto fail;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
511 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
512 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
513 if (n > m)
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
514 i = n - m;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
515 else
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
516 i = 0;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
517 for (; i < defcount; i++) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
518 if (GETLOCAL(m+i) == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
519 PyObject *def = defs[i];
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
520 Py_INCREF(def);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
521 SETLOCAL(m+i, def);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
522 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
523 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
524 }
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 (argcount > 0 || kwcount > 0) {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
528 PyErr_SetString(PyExc_TypeError,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
529 "no arguments expected");
5048
fde73467b584 Change the control flow for error handling in the function prelude to
Guido van Rossum <guido@python.org>
parents: 5023
diff changeset
530 goto fail;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
531 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
532 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
533
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
534 if (tstate->sys_tracefunc != NULL) {
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
535 /* 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
536 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
537 Its return value, if not None, is a function that
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
538 will be called at the start of each executed line
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
539 of code. (Actually, the function must return
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
540 itself in order to continue tracing.)
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
541 The trace functions are called with three arguments:
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
542 a pointer to the current frame, a string indicating
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
543 why the function is called, and an argument which
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
544 depends on the situation. The global trace function
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
545 (sys.trace) is also called whenever an exception
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
546 is detected. */
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
547 if (call_trace(&tstate->sys_tracefunc,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
548 &f->f_trace, f, "call",
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
549 Py_None/*XXX how to compute arguments now?*/)) {
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
550 /* 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
551 goto fail;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
552 }
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
553 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
554
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
555 if (tstate->sys_profilefunc != NULL) {
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
556 /* 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
557 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
558 if (call_trace(&tstate->sys_profilefunc,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
559 (PyObject**)0, f, "call",
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
560 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
561 goto fail;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
562 }
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
563 }
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
564
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14268
diff changeset
565 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
566 --tstate->recursion_depth;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
567 PyErr_SetString(PyExc_RuntimeError,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
568 "Maximum recursion depth exceeded");
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
569 tstate->frame = f->f_back;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
570 Py_DECREF(f);
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
571 return NULL;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
572 }
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
573
9293
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 9203
diff changeset
574 _PyCode_GETCODEPTR(co, &first_instr);
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 9203
diff changeset
575 next_instr = first_instr;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
576 stack_pointer = f->f_valuestack;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
577
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
578 why = WHY_NOT;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
579 err = 0;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
580 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
581 w = NULL;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
582
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
583 for (;;) {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
584 /* 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
585 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
586 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
587 ``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
588 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
589 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
590 Py_MakePendingCalls() above. */
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
591
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
592 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
593 tstate->ticker = tstate->interp->checkinterval;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
594 if (things_to_do) {
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
595 if (Py_MakePendingCalls() < 0) {
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
596 why = WHY_EXCEPTION;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
597 goto on_error;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
598 }
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
599 }
5551
34509c05266f Logic for enabling mac-specific signal handling fixed (Jack)
Guido van Rossum <guido@python.org>
parents: 5492
diff changeset
600 #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
601 /* 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
602 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
603 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
604 DOS, alas, we have to call it. */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
605 if (PyErr_CheckSignals()) {
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
606 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
607 goto on_error;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
608 }
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
609 #endif
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
610
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
611 #ifdef WITH_THREAD
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
612 if (interpreter_lock) {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
613 /* Give another thread a chance */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
614
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5911
diff changeset
615 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
616 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
617 PyThread_release_lock(interpreter_lock);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
618
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
619 /* Other threads may run now */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
620
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9671
diff changeset
621 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
622 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
623 Py_FatalError("ceval: orphan tstate");
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
624 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
625 #endif
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
626 }
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
627
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
628 /* Extract opcode and argument */
1016
a41e3ba5b47d Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents: 974
diff changeset
629
4839
4567e158d20c Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents: 4667
diff changeset
630 #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
631 f->f_lasti = INSTR_OFFSET();
a41e3ba5b47d Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents: 974
diff changeset
632 #endif
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
633
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
634 opcode = NEXTOP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
635 if (HAS_ARG(opcode))
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
636 oparg = NEXTARG();
14147
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14100
diff changeset
637 dispatch_opcode:
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
638 #ifdef DYNAMIC_EXECUTION_PROFILE
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
639 #ifdef DXPAIRS
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
640 dxpairs[lastopcode][opcode]++;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
641 lastopcode = opcode;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
642 #endif
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
643 dxp[opcode]++;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
644 #endif
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
645
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
646 #ifdef LLTRACE
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
647 /* Instruction tracing */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
648
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
649 if (lltrace) {
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
650 if (HAS_ARG(opcode)) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
651 printf("%d: %d, %d\n",
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
652 (int) (INSTR_OFFSET() - 3),
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
653 opcode, oparg);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
654 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
655 else {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
656 printf("%d: %d\n",
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
657 (int) (INSTR_OFFSET() - 1), opcode);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
658 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
659 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
660 #endif
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
661 /* Main switch on opcode */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
662
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
663 switch (opcode) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
664
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
665 /* BEWARE!
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
666 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
667 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
668 and that no operation that succeeds does this! */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
669
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
670 /* case STOP_CODE: this is an error! */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
671
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
672 case POP_TOP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
673 v = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
674 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
675 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
676
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
677 case ROT_TWO:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
678 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
679 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
680 PUSH(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
681 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
682 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
683
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
684 case ROT_THREE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
685 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
686 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
687 x = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
688 PUSH(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
689 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
690 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
691 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
692
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
693 case ROT_FOUR:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
694 u = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
695 v = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
696 w = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
697 x = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
698 PUSH(u);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
699 PUSH(x);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
700 PUSH(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
701 PUSH(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
702 continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
703
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
704 case DUP_TOP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
705 v = TOP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
706 Py_INCREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
707 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
708 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
709
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
710 case DUP_TOPX:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
711 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
712 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
713 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
714 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
715 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
716 continue;
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
717 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
718 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
719 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
720 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
721 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
722 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
723 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
724 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
725 continue;
ca9f6a8e9885 Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents: 14869
diff changeset
726 case 3:
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
727 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
728 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
729 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
730 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
731 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
732 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
733 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
734 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
735 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
736 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
737 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
738 continue;
ca9f6a8e9885 Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents: 14869
diff changeset
739 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
740 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
741 Py_INCREF(x);
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
742 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
743 Py_INCREF(w);
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
744 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
745 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
746 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
747 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
748 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
749 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
750 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
751 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
752 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
753 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
754 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
755 continue;
ca9f6a8e9885 Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents: 14869
diff changeset
756 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
757 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
758 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
759 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
760 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
761 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
762 Py_INCREF(v);
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
763 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
764 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
765 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
766 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
767 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
768 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
769 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
770 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
771 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
772 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
773 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
774 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
775 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
776 continue;
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
777 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
778 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
779 " (bytecode corruption?)");
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
780 }
15151
ca9f6a8e9885 Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
Tim Peters <tim.peters@gmail.com>
parents: 14869
diff changeset
781 break;
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
782
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
783 case UNARY_POSITIVE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
784 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
785 x = PyNumber_Positive(v);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
786 Py_DECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
787 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
788 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
789 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
790
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
791 case UNARY_NEGATIVE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
792 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
793 x = PyNumber_Negative(v);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
794 Py_DECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
795 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
796 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
797 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
798
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
799 case UNARY_NOT:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
800 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
801 err = PyObject_IsTrue(v);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
802 Py_DECREF(v);
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
803 if (err == 0) {
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
804 Py_INCREF(Py_True);
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
805 PUSH(Py_True);
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
806 continue;
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
807 }
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
808 else if (err > 0) {
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
809 Py_INCREF(Py_False);
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
810 PUSH(Py_False);
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
811 err = 0;
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
812 continue;
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
813 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
814 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
815
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
816 case UNARY_CONVERT:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
817 v = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
818 x = PyObject_Repr(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
819 Py_DECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
820 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
821 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
822 break;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
823
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
824 case UNARY_INVERT:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
825 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
826 x = PyNumber_Invert(v);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
827 Py_DECREF(v);
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
828 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
829 if (x != NULL) continue;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
830 break;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
831
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
832 case BINARY_POWER:
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
833 w = POP();
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
834 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
835 x = PyNumber_Power(v, w, Py_None);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
836 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
837 Py_DECREF(w);
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
838 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
839 if (x != NULL) continue;
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
840 break;
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
841
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
842 case BINARY_MULTIPLY:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
843 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
844 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
845 x = PyNumber_Multiply(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
846 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
847 Py_DECREF(w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
848 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
849 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
850 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
851
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
852 case BINARY_DIVIDE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
853 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
854 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
855 x = PyNumber_Divide(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
856 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
857 Py_DECREF(w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
858 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
859 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
860 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
861
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
862 case BINARY_MODULO:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
863 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
864 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
865 x = PyNumber_Remainder(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
866 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
867 Py_DECREF(w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
868 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
869 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
870 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
871
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
872 case BINARY_ADD:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
873 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
874 v = POP();
5829
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
875 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
876 /* INLINE: int + int */
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
877 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
878 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
879 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
880 i = a + b;
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
881 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
882 PyErr_SetString(PyExc_OverflowError,
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
883 "integer addition");
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
884 x = NULL;
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
885 }
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
886 else
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
887 x = PyInt_FromLong(i);
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
888 }
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
889 else
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
890 x = PyNumber_Add(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
891 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
892 Py_DECREF(w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
893 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
894 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
895 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
896
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
897 case BINARY_SUBTRACT:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
898 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
899 v = POP();
5829
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
900 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
901 /* INLINE: int - int */
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
902 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
903 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
904 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
905 i = a - b;
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
906 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
907 PyErr_SetString(PyExc_OverflowError,
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
908 "integer subtraction");
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
909 x = NULL;
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
910 }
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
911 else
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
912 x = PyInt_FromLong(i);
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
913 }
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
914 else
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
915 x = PyNumber_Subtract(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
916 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
917 Py_DECREF(w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
918 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
919 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
920 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
921
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
922 case BINARY_SUBSCR:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
923 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
924 v = POP();
5829
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
925 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
926 /* INLINE: list[int] */
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
927 long i = PyInt_AsLong(w);
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
928 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
929 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
930 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
931 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
932 PyErr_SetString(PyExc_IndexError,
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
933 "list index out of range");
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
934 x = NULL;
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
935 }
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
936 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
937 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
938 Py_INCREF(x);
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
939 }
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
940 }
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
941 else
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
942 x = PyObject_GetItem(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
943 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
944 Py_DECREF(w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
945 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
946 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
947 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
948
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
949 case BINARY_LSHIFT:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
950 w = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
951 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
952 x = PyNumber_Lshift(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
953 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
954 Py_DECREF(w);
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
955 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
956 if (x != NULL) continue;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
957 break;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
958
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
959 case BINARY_RSHIFT:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
960 w = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
961 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
962 x = PyNumber_Rshift(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
963 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
964 Py_DECREF(w);
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
965 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
966 if (x != NULL) continue;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
967 break;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
968
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
969 case BINARY_AND:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
970 w = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
971 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
972 x = PyNumber_And(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
973 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
974 Py_DECREF(w);
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
975 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
976 if (x != NULL) continue;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
977 break;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
978
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
979 case BINARY_XOR:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
980 w = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
981 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
982 x = PyNumber_Xor(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
983 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
984 Py_DECREF(w);
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
985 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
986 if (x != NULL) continue;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
987 break;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
988
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
989 case BINARY_OR:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
990 w = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
991 v = POP();
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
992 x = PyNumber_Or(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
993 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
994 Py_DECREF(w);
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
995 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
996 if (x != NULL) continue;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
997 break;
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
998
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
999 case INPLACE_POWER:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1000 w = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1001 v = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1002 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
1003 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1004 Py_DECREF(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1005 PUSH(x);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1006 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1007 break;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1008
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1009 case INPLACE_MULTIPLY:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1010 w = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1011 v = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1012 x = PyNumber_InPlaceMultiply(v, w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1013 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1014 Py_DECREF(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1015 PUSH(x);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1016 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1017 break;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1018
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1019 case INPLACE_DIVIDE:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1020 w = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1021 v = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1022 x = PyNumber_InPlaceDivide(v, w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1023 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1024 Py_DECREF(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1025 PUSH(x);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1026 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1027 break;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1028
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1029 case INPLACE_MODULO:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1030 w = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1031 v = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1032 x = PyNumber_InPlaceRemainder(v, w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1033 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1034 Py_DECREF(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1035 PUSH(x);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1036 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1037 break;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1038
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1039 case INPLACE_ADD:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1040 w = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1041 v = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1042 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
1043 /* INLINE: int + int */
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1044 register long a, b, i;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1045 a = PyInt_AS_LONG(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1046 b = PyInt_AS_LONG(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1047 i = a + b;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1048 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
1049 PyErr_SetString(PyExc_OverflowError,
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1050 "integer addition");
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1051 x = NULL;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1052 }
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1053 else
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1054 x = PyInt_FromLong(i);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1055 }
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1056 else
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1057 x = PyNumber_InPlaceAdd(v, w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1058 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1059 Py_DECREF(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1060 PUSH(x);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1061 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1062 break;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1063
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1064 case INPLACE_SUBTRACT:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1065 w = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1066 v = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1067 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
1068 /* INLINE: int - int */
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1069 register long a, b, i;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1070 a = PyInt_AS_LONG(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1071 b = PyInt_AS_LONG(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1072 i = a - b;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1073 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
1074 PyErr_SetString(PyExc_OverflowError,
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1075 "integer subtraction");
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1076 x = NULL;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1077 }
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1078 else
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1079 x = PyInt_FromLong(i);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1080 }
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1081 else
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1082 x = PyNumber_InPlaceSubtract(v, w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1083 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1084 Py_DECREF(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1085 PUSH(x);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1086 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1087 break;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1088
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1089 case INPLACE_LSHIFT:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1090 w = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1091 v = POP();
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1092 x = PyNumber_InPlaceLshift(v, w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1093 Py_DECREF(v);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1094 Py_DECREF(w);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1095 PUSH(x);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1096 if (x != NULL) continue;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1097 break;
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_RSHIFT:
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_InPlaceRshift(v, w);
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;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1108
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1109 case INPLACE_AND:
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_InPlaceAnd(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;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1118
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1119 case INPLACE_XOR:
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_InPlaceXor(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;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1128
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1129 case INPLACE_OR:
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_InPlaceOr(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;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1138
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1139 case SLICE+0:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1140 case SLICE+1:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1141 case SLICE+2:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1142 case SLICE+3:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1143 if ((opcode-SLICE) & 2)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1144 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1145 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1146 w = NULL;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1147 if ((opcode-SLICE) & 1)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1148 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1149 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1150 v = NULL;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1151 u = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1152 x = apply_slice(u, v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1153 Py_DECREF(u);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1154 Py_XDECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1155 Py_XDECREF(w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1156 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
1157 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1158 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1159
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1160 case STORE_SLICE+0:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1161 case STORE_SLICE+1:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1162 case STORE_SLICE+2:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1163 case STORE_SLICE+3:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1164 if ((opcode-STORE_SLICE) & 2)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1165 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1166 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1167 w = NULL;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1168 if ((opcode-STORE_SLICE) & 1)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1169 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1170 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1171 v = NULL;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1172 u = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1173 t = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1174 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
1175 Py_DECREF(t);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1176 Py_DECREF(u);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1177 Py_XDECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1178 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
1179 if (err == 0) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1180 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1181
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1182 case DELETE_SLICE+0:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1183 case DELETE_SLICE+1:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1184 case DELETE_SLICE+2:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1185 case DELETE_SLICE+3:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1186 if ((opcode-DELETE_SLICE) & 2)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1187 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1188 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1189 w = NULL;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1190 if ((opcode-DELETE_SLICE) & 1)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1191 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1192 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1193 v = NULL;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1194 u = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1195 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
1196 /* del u[v:w] */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1197 Py_DECREF(u);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1198 Py_XDECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1199 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
1200 if (err == 0) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1201 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1202
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1203 case STORE_SUBSCR:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1204 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1205 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1206 u = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1207 /* v[w] = u */
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1208 err = PyObject_SetItem(v, w, u);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1209 Py_DECREF(u);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1210 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1211 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
1212 if (err == 0) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1213 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1214
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1215 case DELETE_SUBSCR:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1216 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1217 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1218 /* del v[w] */
5413
10267fdc7531 Used operators from abstract.h where possible (arithmetic operators,
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
1219 err = PyObject_DelItem(v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1220 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1221 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
1222 if (err == 0) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1223 break;
14100
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1224
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1225 case PRINT_EXPR:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1226 v = POP();
6945
f14e4459fb94 Plug the most annoying recursive printing problem -- reset '_' to None
Guido van Rossum <guido@python.org>
parents: 6599
diff changeset
1227 /* Print value except if None */
f14e4459fb94 Plug the most annoying recursive printing problem -- reset '_' to None
Guido van Rossum <guido@python.org>
parents: 6599
diff changeset
1228 /* After printing, also assign to '_' */
f14e4459fb94 Plug the most annoying recursive printing problem -- reset '_' to None
Guido van Rossum <guido@python.org>
parents: 6599
diff changeset
1229 /* Before, set '_' to None to avoid recursion */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1230 if (v != Py_None &&
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
1231 (err = PyDict_SetItemString(
6945
f14e4459fb94 Plug the most annoying recursive printing problem -- reset '_' to None
Guido van Rossum <guido@python.org>
parents: 6599
diff changeset
1232 f->f_builtins, "_", Py_None)) == 0) {
5606
495fbde64a73 Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents: 5557
diff changeset
1233 err = Py_FlushLine();
5829
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1234 if (err == 0) {
5606
495fbde64a73 Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents: 5557
diff changeset
1235 x = PySys_GetObject("stdout");
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
1236 if (x == NULL) {
c75d899e666f Last-minute fix for Jim H: don't die after del sys.stdout
Guido van Rossum <guido@python.org>
parents: 6945
diff changeset
1237 PyErr_SetString(
c75d899e666f Last-minute fix for Jim H: don't die after del sys.stdout
Guido van Rossum <guido@python.org>
parents: 6945
diff changeset
1238 PyExc_RuntimeError,
c75d899e666f Last-minute fix for Jim H: don't die after del sys.stdout
Guido van Rossum <guido@python.org>
parents: 6945
diff changeset
1239 "lost sys.stdout");
5606
495fbde64a73 Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents: 5557
diff changeset
1240 err = -1;
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
1241 }
5606
495fbde64a73 Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents: 5557
diff changeset
1242 }
495fbde64a73 Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents: 5557
diff changeset
1243 if (err == 0)
495fbde64a73 Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents: 5557
diff changeset
1244 err = PyFile_WriteObject(v, x, 0);
495fbde64a73 Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents: 5557
diff changeset
1245 if (err == 0) {
495fbde64a73 Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents: 5557
diff changeset
1246 PyFile_SoftSpace(x, 1);
495fbde64a73 Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents: 5557
diff changeset
1247 err = Py_FlushLine();
495fbde64a73 Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents: 5557
diff changeset
1248 }
6945
f14e4459fb94 Plug the most annoying recursive printing problem -- reset '_' to None
Guido van Rossum <guido@python.org>
parents: 6599
diff changeset
1249 if (err == 0) {
f14e4459fb94 Plug the most annoying recursive printing problem -- reset '_' to None
Guido van Rossum <guido@python.org>
parents: 6599
diff changeset
1250 err = PyDict_SetItemString(
f14e4459fb94 Plug the most annoying recursive printing problem -- reset '_' to None
Guido van Rossum <guido@python.org>
parents: 6599
diff changeset
1251 f->f_builtins, "_", v);
f14e4459fb94 Plug the most annoying recursive printing problem -- reset '_' to None
Guido van Rossum <guido@python.org>
parents: 6599
diff changeset
1252 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1253 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1254 Py_DECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1255 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1256
14100
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1257 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
1258 w = stream = POP();
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1259 /* 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
1260
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1261 case PRINT_ITEM:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1262 v = POP();
14238
74f7f237f739 eval_code2(): Guido provides this patch for his suggested elaboration
Barry Warsaw <barry@python.org>
parents: 14232
diff changeset
1263 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
1264 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
1265 if (w == NULL) {
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1266 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
1267 "lost sys.stdout");
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1268 err = -1;
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1269 }
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
1270 }
14100
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1271 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
1272 err = PyFile_WriteString(" ", w);
495fbde64a73 Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents: 5557
diff changeset
1273 if (err == 0)
495fbde64a73 Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents: 5557
diff changeset
1274 err = PyFile_WriteObject(v, w, Py_PRINT_RAW);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1275 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
1276 /* XXX move into writeobject() ? */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1277 char *s = PyString_AsString(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1278 int len = PyString_Size(v);
2310
07913fb8f92f use Py_CHARMASK
Guido van Rossum <guido@python.org>
parents: 2295
diff changeset
1279 if (len > 0 &&
07913fb8f92f use Py_CHARMASK
Guido van Rossum <guido@python.org>
parents: 2295
diff changeset
1280 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
1281 s[len-1] != ' ')
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1282 PyFile_SoftSpace(w, 0);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1283 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1284 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
1285 Py_XDECREF(stream);
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1286 stream = NULL;
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1287 if (err == 0)
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1288 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1289 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1290
14100
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1291 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
1292 w = stream = POP();
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1293 /* 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
1294
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1295 case PRINT_NEWLINE:
14238
74f7f237f739 eval_code2(): Guido provides this patch for his suggested elaboration
Barry Warsaw <barry@python.org>
parents: 14232
diff changeset
1296 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
1297 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
1298 if (w == NULL)
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1299 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
1300 "lost sys.stdout");
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1301 }
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1302 if (w != NULL) {
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1303 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
1304 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
1305 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
1306 }
14100
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1307 Py_XDECREF(stream);
2de0cc174c3b PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14080
diff changeset
1308 stream = NULL;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1309 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1310
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1311
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1312 #ifdef CASE_TOO_BIG
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1313 default: switch (opcode) {
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1314 #endif
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1315 case BREAK_LOOP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1316 why = WHY_BREAK;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1317 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
1318
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
1319 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
1320 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
1321 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
1322 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
1323 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
1324 /* 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
1325 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
1326 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
1327 /* 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
1328 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
1329 w = POP(); /* exc */
7946
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
1330 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
1331 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
1332 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
1333 default:
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1334 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
1335 "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
1336 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
1337 break;
464
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1338 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1339 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1340
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1341 case LOAD_LOCALS:
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1342 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
1343 PyErr_SetString(PyExc_SystemError,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
1344 "no locals");
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1345 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1346 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1347 Py_INCREF(x);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1348 PUSH(x);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1349 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1350
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1351 case RETURN_VALUE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1352 retval = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1353 why = WHY_RETURN;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1354 break;
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
1355
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
1356 case EXEC_STMT:
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
1357 w = POP();
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
1358 v = POP();
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
1359 u = POP();
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
1360 err = exec_statement(f, u, v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1361 Py_DECREF(u);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1362 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1363 Py_DECREF(w);
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
1364 break;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1365
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1366 case POP_BLOCK:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1367 {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1368 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
1369 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
1370 v = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1371 Py_DECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1372 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1373 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1374 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1375
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1376 case END_FINALLY:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1377 v = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1378 if (PyInt_Check(v)) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1379 why = (enum why_code) PyInt_AsLong(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1380 if (why == WHY_RETURN)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1381 retval = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1382 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1383 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
1384 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
1385 u = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1386 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
1387 why = WHY_RERAISE;
2872
d3b07ba3e12d fix bogus DECREF in finally clause
Guido van Rossum <guido@python.org>
parents: 2866
diff changeset
1388 break;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1389 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1390 else if (v != Py_None) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1391 PyErr_SetString(PyExc_SystemError,
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1392 "'finally' pops bad exception");
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1393 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1394 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1395 Py_DECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1396 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1397
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1398 case BUILD_CLASS:
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
1399 u = POP();
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1400 v = POP();
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
1401 w = POP();
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
1402 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
1403 PUSH(x);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1404 Py_DECREF(u);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1405 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1406 Py_DECREF(w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1407 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1408
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1409 case STORE_NAME:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1410 w = GETNAMEV(oparg);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1411 v = POP();
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1412 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
1413 PyErr_SetString(PyExc_SystemError,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
1414 "no locals");
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1415 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1416 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1417 err = PyDict_SetItem(x, w, v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1418 Py_DECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1419 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1420
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1421 case DELETE_NAME:
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
1422 w = GETNAMEV(oparg);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1423 if ((x = f->f_locals) == NULL) {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
1424 PyErr_SetString(PyExc_SystemError,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
1425 "no locals");
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1426 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1427 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1428 if ((err = PyDict_DelItem(x, w)) != 0)
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1429 format_exc_check_arg(PyExc_NameError,
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1430 NAME_ERROR_MSG ,w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1431 break;
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1432
13930
4eaa463c031a Merge UNPACK_LIST and UNPACK_TUPLE into a single UNPACK_SEQUENCE, since they
Thomas Wouters <thomas@python.org>
parents: 13881
diff changeset
1433 case UNPACK_SEQUENCE:
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1434 v = POP();
6157
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1435 if (PyTuple_Check(v)) {
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1436 if (PyTuple_Size(v) != oparg) {
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1437 PyErr_SetString(PyExc_ValueError,
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1438 "unpack tuple of wrong size");
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1439 why = WHY_EXCEPTION;
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1440 }
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1441 else {
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1442 for (; --oparg >= 0; ) {
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1443 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
1444 Py_INCREF(w);
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1445 PUSH(w);
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1446 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1447 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1448 }
6157
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1449 else if (PyList_Check(v)) {
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1450 if (PyList_Size(v) != oparg) {
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1451 PyErr_SetString(PyExc_ValueError,
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1452 "unpack list of wrong size");
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1453 why = WHY_EXCEPTION;
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1454 }
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1455 else {
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1456 for (; --oparg >= 0; ) {
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1457 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
1458 Py_INCREF(w);
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1459 PUSH(w);
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1460 }
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1461 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1462 }
6157
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1463 else if (PySequence_Check(v)) {
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1464 if (unpack_sequence(v, oparg,
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1465 stack_pointer + oparg))
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1466 stack_pointer += oparg;
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1467 else
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1468 why = WHY_EXCEPTION;
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 else {
6157
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1471 PyErr_SetString(PyExc_TypeError,
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1472 "unpack non-sequence");
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
1473 why = WHY_EXCEPTION;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1474 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1475 Py_DECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1476 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1477
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1478 case STORE_ATTR:
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1479 w = GETNAMEV(oparg);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1480 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1481 u = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1482 err = PyObject_SetAttr(v, w, u); /* v.w = u */
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1483 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1484 Py_DECREF(u);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1485 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1486
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1487 case DELETE_ATTR:
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1488 w = GETNAMEV(oparg);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1489 v = POP();
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
1490 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
1491 /* del v.w */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1492 Py_DECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1493 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1494
464
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1495 case STORE_GLOBAL:
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1496 w = GETNAMEV(oparg);
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1497 v = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1498 err = PyDict_SetItem(f->f_globals, w, v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1499 Py_DECREF(v);
464
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1500 break;
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1501
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1502 case DELETE_GLOBAL:
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1503 w = GETNAMEV(oparg);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1504 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
1505 format_exc_check_arg(
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1506 PyExc_NameError, NAME_ERROR_MSG ,w);
464
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1507 break;
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1508
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1509 case LOAD_CONST:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1510 x = GETCONST(oparg);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1511 Py_INCREF(x);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1512 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1513 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1514
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1515 case LOAD_NAME:
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
1516 w = GETNAMEV(oparg);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1517 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
1518 PyErr_SetString(PyExc_SystemError,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
1519 "no locals");
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1520 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1521 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1522 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
1523 if (x == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1524 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
1525 if (x == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1526 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
1527 if (x == NULL) {
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1528 format_exc_check_arg(
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1529 PyExc_NameError,
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;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1532 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1533 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1534 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1535 Py_INCREF(x);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1536 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1537 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1538
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1539 case LOAD_GLOBAL:
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
1540 w = GETNAMEV(oparg);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1541 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
1542 if (x == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1543 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
1544 if (x == NULL) {
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1545 format_exc_check_arg(
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1546 PyExc_NameError,
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1547 NAME_ERROR_MSG ,w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1548 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1549 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1550 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1551 Py_INCREF(x);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1552 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1553 break;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1554
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1555 case LOAD_FAST:
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1556 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
1557 if (x == NULL) {
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1558 format_exc_check_arg(
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1559 PyExc_UnboundLocalError,
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1560 UNBOUNDLOCAL_ERROR_MSG,
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1561 PyTuple_GetItem(co->co_varnames, oparg)
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1562 );
1262
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1563 break;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1564 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1565 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
1566 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
1567 if (x != NULL) continue;
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1568 break;
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1569
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1570 case STORE_FAST:
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
1571 v = POP();
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1572 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
1573 continue;
1262
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1574
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1575 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
1576 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
1577 if (x == NULL) {
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1578 format_exc_check_arg(
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1579 PyExc_UnboundLocalError,
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1580 UNBOUNDLOCAL_ERROR_MSG,
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1581 PyTuple_GetItem(co->co_varnames, oparg)
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
1582 );
8318
ec87b62466d3 DELETE_FAST should issue an exception when the local variable is undefined.
Guido van Rossum <guido@python.org>
parents: 7982
diff changeset
1583 break;
ec87b62466d3 DELETE_FAST should issue an exception when the local variable is undefined.
Guido van Rossum <guido@python.org>
parents: 7982
diff changeset
1584 }
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1585 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
1586 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1587
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1588 case BUILD_TUPLE:
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1589 x = PyTuple_New(oparg);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1590 if (x != NULL) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1591 for (; --oparg >= 0;) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1592 w = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1593 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
1594 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1595 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
1596 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1597 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1598 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1599
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1600 case BUILD_LIST:
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1601 x = PyList_New(oparg);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1602 if (x != NULL) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1603 for (; --oparg >= 0;) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1604 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
1605 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
1606 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1607 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
1608 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1609 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1610 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1611
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1612 case BUILD_MAP:
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1613 x = PyDict_New();
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1614 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
1615 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1616 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1617
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1618 case LOAD_ATTR:
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1619 w = GETNAMEV(oparg);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1620 v = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1621 x = PyObject_GetAttr(v, w);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1622 Py_DECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1623 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
1624 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1625 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1626
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1627 case COMPARE_OP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1628 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1629 v = POP();
5829
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1630 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
1631 /* INLINE: cmp(int, int) */
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1632 register long a, b;
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1633 register int res;
9591
7f90736701a3 Use PyInt_AS_LONG macro instead of explicit inlining.
Guido van Rossum <guido@python.org>
parents: 9513
diff changeset
1634 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
1635 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
1636 switch (oparg) {
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1637 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
1638 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
1639 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
1640 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
1641 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
1642 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
1643 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
1644 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
1645 default: goto slow_compare;
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1646 }
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1647 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
1648 Py_INCREF(x);
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1649 }
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1650 else {
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1651 slow_compare:
f1127d6fcd74 Huge speedup by inlining some common integer operations:
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
1652 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
1653 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1654 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1655 Py_DECREF(w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1656 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
1657 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1658 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1659
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1660 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
1661 w = GETNAMEV(oparg);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1662 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
1663 if (x == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1664 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
1665 "__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
1666 break;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1667 }
14232
1f1a156ed5af Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents: 14225
diff changeset
1668 u = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1669 w = Py_BuildValue("(OOOO)",
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1670 w,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1671 f->f_globals,
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
1672 f->f_locals == NULL ?
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
1673 Py_None : f->f_locals,
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1674 u);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1675 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
1676 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
1677 x = NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1678 break;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1679 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1680 x = PyEval_CallObject(x, w);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1681 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
1682 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
1683 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1684 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1685
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
1686 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
1687 v = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1688 PyFrame_FastToLocals(f);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1689 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
1690 PyErr_SetString(PyExc_SystemError,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
1691 "no locals");
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1692 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1693 }
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
1694 err = import_all_from(x, v);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1695 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
1696 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
1697 if (err == 0) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1698 break;
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
1699
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
1700 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
1701 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
1702 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
1703 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
1704 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
1705 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
1706 break;
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
1707
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1708 case JUMP_FORWARD:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1709 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
1710 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1711
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1712 case JUMP_IF_FALSE:
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1713 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
1714 if (err > 0)
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1715 err = 0;
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1716 else if (err == 0)
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1717 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
1718 else
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1719 break;
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1720 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1721
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1722 case JUMP_IF_TRUE:
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1723 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
1724 if (err > 0) {
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1725 err = 0;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1726 JUMPBY(oparg);
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1727 }
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1728 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
1729 ;
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1730 else
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1731 break;
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1732 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1733
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1734 case JUMP_ABSOLUTE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1735 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
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 case FOR_LOOP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1739 /* for v in s: ...
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1740 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
1741 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
1742 but if loop exhausted:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1743 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
1744 w = POP(); /* Loop index */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1745 v = POP(); /* Sequence object */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1746 u = loop_subscript(v, w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1747 if (u != NULL) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1748 PUSH(v);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1749 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
1750 PUSH(x);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1751 Py_DECREF(w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1752 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
1753 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1754 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1755 else {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1756 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1757 Py_DECREF(w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1758 /* 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
1759 but also an error: */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1760 if (PyErr_Occurred())
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1761 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
1762 else {
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1763 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
1764 continue;
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1765 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1766 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1767 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1768
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1769 case SETUP_LOOP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1770 case SETUP_EXCEPT:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1771 case SETUP_FINALLY:
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1772 PyFrame_BlockSetup(f, opcode, INSTR_OFFSET() + oparg,
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1773 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
1774 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1775
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1776 case SET_LINENO:
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1777 #ifdef LLTRACE
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1778 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
1779 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
1780 #endif
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1781 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
1782 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
1783 continue;
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1784 /* 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
1785 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
1786 err = call_trace(&f->f_trace, &f->f_trace,
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1787 f, "line", Py_None);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1788 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
1789
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
1790 case CALL_FUNCTION:
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1791 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
1792 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
1793 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
1794 {
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1795 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
1796 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
1797 int flags = (opcode - CALL_FUNCTION) & 3;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1798 int n = na + 2*nk + (flags & 1) + ((flags >> 1) & 1);
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1799 PyObject **pfunc = stack_pointer - n - 1;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1800 PyObject *func = *pfunc;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1801 PyObject *self = NULL;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1802 PyObject *class = NULL;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1803 f->f_lasti = INSTR_OFFSET() - 3; /* For tracing */
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1804 if (PyMethod_Check(func)) {
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1805 self = PyMethod_Self(func);
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1806 class = PyMethod_Class(func);
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1807 func = PyMethod_Function(func);
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1808 Py_INCREF(func);
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1809 if (self != NULL) {
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1810 Py_INCREF(self);
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1811 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
1812 *pfunc = self;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1813 na++;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1814 n++;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1815 }
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1816 else {
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1817 /* Unbound methods must be called with an
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1818 instance of the class (or a derived
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1819 class) as first argument */
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1820 if (na > 0 && (self = stack_pointer[-n]) != NULL
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1821 && PyInstance_Check(self)
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1822 && PyClass_IsSubclass((PyObject *)
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1823 (((PyInstanceObject *)self)->in_class),
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1824 class))
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1825 /* Handy-dandy */ ;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1826 else {
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1827 PyErr_SetString(PyExc_TypeError,
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1828 "unbound method must be called with class instance 1st argument");
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1829 x = NULL;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1830 break;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1831 }
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1832 }
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1833 }
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1834 else
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1835 Py_INCREF(func);
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1836 if (PyFunction_Check(func) && flags == 0) {
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1837 PyObject *co = PyFunction_GetCode(func);
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1838 PyObject *globals = PyFunction_GetGlobals(func);
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1839 PyObject *argdefs = PyFunction_GetDefaults(func);
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1840 PyObject **d;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1841 int nd;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1842 if (argdefs != NULL) {
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1843 d = &PyTuple_GET_ITEM(argdefs, 0);
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1844 nd = ((PyTupleObject *)argdefs)->ob_size;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1845 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1846 else {
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1847 d = NULL;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1848 nd = 0;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1849 }
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1850 x = eval_code2((PyCodeObject *)co, globals,
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1851 (PyObject *)NULL, stack_pointer-n, na,
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1852 stack_pointer-2*nk, nk, d, nd,
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1853 class);
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1854 }
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1855 else {
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1856 int nstar = 0;
12149
0ac577eb8282 rename args variable in CALL_FUNCTION to callargs (avoids name
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12133
diff changeset
1857 PyObject *callargs;
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1858 PyObject *stararg = 0;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1859 PyObject *kwdict = NULL;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1860 if (flags & 2) {
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1861 kwdict = POP();
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1862 if (!PyDict_Check(kwdict)) {
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1863 PyErr_SetString(PyExc_TypeError,
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1864 "** argument must be a dictionary");
12440
d47460b1a679 Charles Waldman writes:
Guido van Rossum <guido@python.org>
parents: 12320
diff changeset
1865 goto extcall_fail;
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1866 }
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1867 }
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1868 if (flags & 1) {
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1869 stararg = POP();
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1870 if (!PySequence_Check(stararg)) {
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1871 PyErr_SetString(PyExc_TypeError,
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1872 "* argument must be a sequence");
12440
d47460b1a679 Charles Waldman writes:
Guido van Rossum <guido@python.org>
parents: 12320
diff changeset
1873 goto extcall_fail;
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1874 }
12133
711340d44777 Two fixes for extended call syntax:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12111
diff changeset
1875 /* Convert abstract sequence to concrete tuple */
711340d44777 Two fixes for extended call syntax:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12111
diff changeset
1876 if (!PyTuple_Check(stararg)) {
711340d44777 Two fixes for extended call syntax:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12111
diff changeset
1877 PyObject *t = NULL;
711340d44777 Two fixes for extended call syntax:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12111
diff changeset
1878 t = PySequence_Tuple(stararg);
711340d44777 Two fixes for extended call syntax:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12111
diff changeset
1879 if (t == NULL) {
12440
d47460b1a679 Charles Waldman writes:
Guido van Rossum <guido@python.org>
parents: 12320
diff changeset
1880 goto extcall_fail;
12133
711340d44777 Two fixes for extended call syntax:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12111
diff changeset
1881 }
711340d44777 Two fixes for extended call syntax:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12111
diff changeset
1882 Py_DECREF(stararg);
711340d44777 Two fixes for extended call syntax:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12111
diff changeset
1883 stararg = t;
711340d44777 Two fixes for extended call syntax:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12111
diff changeset
1884 }
711340d44777 Two fixes for extended call syntax:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12111
diff changeset
1885 nstar = PyTuple_GET_SIZE(stararg);
12110
92ec78e217d2 eval_code2(): In the extended calling syntax opcodes, you must check
Barry Warsaw <barry@python.org>
parents: 12082
diff changeset
1886 if (nstar < 0) {
12440
d47460b1a679 Charles Waldman writes:
Guido van Rossum <guido@python.org>
parents: 12320
diff changeset
1887 goto extcall_fail;
12110
92ec78e217d2 eval_code2(): In the extended calling syntax opcodes, you must check
Barry Warsaw <barry@python.org>
parents: 12082
diff changeset
1888 }
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1889 }
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1890 if (nk > 0) {
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1891 if (kwdict == NULL) {
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1892 kwdict = PyDict_New();
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1893 if (kwdict == NULL) {
12440
d47460b1a679 Charles Waldman writes:
Guido van Rossum <guido@python.org>
parents: 12320
diff changeset
1894 goto extcall_fail;
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1895 }
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1896 }
12133
711340d44777 Two fixes for extended call syntax:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12111
diff changeset
1897 else {
711340d44777 Two fixes for extended call syntax:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12111
diff changeset
1898 PyObject *d = PyDict_Copy(kwdict);
711340d44777 Two fixes for extended call syntax:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12111
diff changeset
1899 if (d == NULL) {
12440
d47460b1a679 Charles Waldman writes:
Guido van Rossum <guido@python.org>
parents: 12320
diff changeset
1900 goto extcall_fail;
12133
711340d44777 Two fixes for extended call syntax:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12111
diff changeset
1901 }
711340d44777 Two fixes for extended call syntax:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12111
diff changeset
1902 Py_DECREF(kwdict);
711340d44777 Two fixes for extended call syntax:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12111
diff changeset
1903 kwdict = d;
711340d44777 Two fixes for extended call syntax:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12111
diff changeset
1904 }
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1905 err = 0;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1906 while (--nk >= 0) {
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1907 PyObject *value = POP();
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1908 PyObject *key = POP();
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1909 if (PyDict_GetItem(kwdict, key) != NULL) {
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1910 err = 1;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1911 PyErr_Format(PyExc_TypeError,
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1912 "keyword parameter redefined: %.400s",
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1913 PyString_AsString(key));
12149
0ac577eb8282 rename args variable in CALL_FUNCTION to callargs (avoids name
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12133
diff changeset
1914 Py_DECREF(key);
0ac577eb8282 rename args variable in CALL_FUNCTION to callargs (avoids name
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12133
diff changeset
1915 Py_DECREF(value);
12440
d47460b1a679 Charles Waldman writes:
Guido van Rossum <guido@python.org>
parents: 12320
diff changeset
1916 goto extcall_fail;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1917 }
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1918 err = PyDict_SetItem(kwdict, key, value);
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1919 Py_DECREF(key);
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1920 Py_DECREF(value);
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1921 if (err)
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1922 break;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1923 }
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1924 if (err) {
12440
d47460b1a679 Charles Waldman writes:
Guido van Rossum <guido@python.org>
parents: 12320
diff changeset
1925 extcall_fail:
d47460b1a679 Charles Waldman writes:
Guido van Rossum <guido@python.org>
parents: 12320
diff changeset
1926 Py_XDECREF(kwdict);
d47460b1a679 Charles Waldman writes:
Guido van Rossum <guido@python.org>
parents: 12320
diff changeset
1927 Py_XDECREF(stararg);
d47460b1a679 Charles Waldman writes:
Guido van Rossum <guido@python.org>
parents: 12320
diff changeset
1928 Py_DECREF(func);
d47460b1a679 Charles Waldman writes:
Guido van Rossum <guido@python.org>
parents: 12320
diff changeset
1929 x=NULL;
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1930 break;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1931 }
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1932 }
12149
0ac577eb8282 rename args variable in CALL_FUNCTION to callargs (avoids name
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12133
diff changeset
1933 callargs = PyTuple_New(na + nstar);
0ac577eb8282 rename args variable in CALL_FUNCTION to callargs (avoids name
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12133
diff changeset
1934 if (callargs == NULL) {
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1935 x = NULL;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1936 break;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1937 }
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1938 if (stararg) {
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1939 int i;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1940 for (i = 0; i < nstar; i++) {
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1941 PyObject *a = PyTuple_GET_ITEM(stararg, i);
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1942 Py_INCREF(a);
12149
0ac577eb8282 rename args variable in CALL_FUNCTION to callargs (avoids name
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12133
diff changeset
1943 PyTuple_SET_ITEM(callargs, na + i, a);
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1944 }
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1945 Py_DECREF(stararg);
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
1946 }
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1947 while (--na >= 0) {
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1948 w = POP();
12149
0ac577eb8282 rename args variable in CALL_FUNCTION to callargs (avoids name
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12133
diff changeset
1949 PyTuple_SET_ITEM(callargs, na, w);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1950 }
12149
0ac577eb8282 rename args variable in CALL_FUNCTION to callargs (avoids name
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12133
diff changeset
1951 x = PyEval_CallObjectWithKeywords(func,
0ac577eb8282 rename args variable in CALL_FUNCTION to callargs (avoids name
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12133
diff changeset
1952 callargs,
0ac577eb8282 rename args variable in CALL_FUNCTION to callargs (avoids name
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12133
diff changeset
1953 kwdict);
0ac577eb8282 rename args variable in CALL_FUNCTION to callargs (avoids name
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12133
diff changeset
1954 Py_DECREF(callargs);
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1955 Py_XDECREF(kwdict);
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1956 }
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1957 Py_DECREF(func);
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1958 while (stack_pointer > pfunc) {
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1959 w = POP();
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1960 Py_DECREF(w);
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1961 }
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1962 PUSH(x);
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1963 if (x != NULL) continue;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11839
diff changeset
1964 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
1965 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1966
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1967 case MAKE_FUNCTION:
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1968 v = POP(); /* code object */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1969 x = PyFunction_New(v, f->f_globals);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1970 Py_DECREF(v);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1971 /* XXX Maybe this should be a separate opcode? */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1972 if (x != NULL && oparg > 0) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1973 v = PyTuple_New(oparg);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1974 if (v == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1975 Py_DECREF(x);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1976 x = NULL;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1977 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1978 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1979 while (--oparg >= 0) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1980 w = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1981 PyTuple_SET_ITEM(v, oparg, w);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1982 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1983 err = PyFunction_SetDefaults(x, v);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1984 Py_DECREF(v);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1985 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1986 PUSH(x);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1987 break;
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
1988
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
1989 case BUILD_SLICE:
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
1990 if (oparg == 3)
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
1991 w = POP();
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
1992 else
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
1993 w = NULL;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
1994 v = POP();
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
1995 u = POP();
5018
001a5042b181 Cleanup:
Guido van Rossum <guido@python.org>
parents: 5014
diff changeset
1996 x = PySlice_New(u, v, w);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1997 Py_DECREF(u);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1998 Py_DECREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
1999 Py_XDECREF(w);
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2000 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
2001 if (x != NULL) continue;
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2002 break;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2003
14147
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14100
diff changeset
2004 case EXTENDED_ARG:
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14100
diff changeset
2005 opcode = NEXTOP();
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14100
diff changeset
2006 oparg = oparg<<16 | NEXTARG();
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14100
diff changeset
2007 goto dispatch_opcode;
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14100
diff changeset
2008 break;
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
2009
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2010 default:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2011 fprintf(stderr,
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2012 "XXX lineno: %d, opcode: %d\n",
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2013 f->f_lineno, opcode);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2014 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
2015 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2016 break;
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2017
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2018 #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
2019 }
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2020 #endif
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2021
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2022 } /* switch */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2023
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2024 on_error:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2025
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2026 /* Quickly continue if no error occurred */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2027
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2028 if (why == WHY_NOT) {
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2029 if (err == 0 && x != NULL) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2030 #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
2031 /* This check is expensive! */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2032 if (PyErr_Occurred())
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2033 fprintf(stderr,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2034 "XXX undetected error\n");
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2035 else
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2036 #endif
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2037 continue; /* Normal, fast path */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2038 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2039 why = WHY_EXCEPTION;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2040 x = Py_None;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2041 err = 0;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2042 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2043
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2044 /* Double-check exception status */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2045
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2046 if (why == WHY_EXCEPTION || why == WHY_RERAISE) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2047 if (!PyErr_Occurred()) {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2048 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
2049 "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
2050 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2051 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2052 }
10363
4daab7a9f566 Always test for an error return (usually NULL or -1) without setting
Guido van Rossum <guido@python.org>
parents: 9679
diff changeset
2053 #ifdef CHECKEXC
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2054 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
2055 /* This check is expensive! */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2056 if (PyErr_Occurred()) {
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2057 fprintf(stderr,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2058 "XXX undetected error (why=%d)\n",
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2059 why);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2060 why = WHY_EXCEPTION;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2061 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2062 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2063 #endif
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2064
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2065 /* Log traceback info if this is a real exception */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2066
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2067 if (why == WHY_EXCEPTION) {
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2068 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
2069 if (HAS_ARG(opcode))
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2070 f->f_lasti -= 2;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2071 PyTraceBack_Here(f);
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2072
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2073 if (f->f_trace)
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2074 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
2075 if (tstate->sys_profilefunc)
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2076 call_exc_trace(&tstate->sys_profilefunc,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2077 (PyObject**)0, f);
9513
350f24180dcb Whoops! One the "redundant" initializations removed by Vladimir in
Guido van Rossum <guido@python.org>
parents: 9490
diff changeset
2078 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2079
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2080 /* For the rest, treat WHY_RERAISE as WHY_EXCEPTION */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2081
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2082 if (why == WHY_RERAISE)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2083 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2084
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2085 /* Unwind stacks if a (pseudo) exception occurred */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2086
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2087 while (why != WHY_NOT && f->f_iblock > 0) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2088 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
2089 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
2090 v = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2091 Py_XDECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2092 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2093 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
2094 why = WHY_NOT;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2095 JUMPTO(b->b_handler);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2096 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2097 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2098 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
2099 (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
2100 why == WHY_EXCEPTION)) {
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2101 if (why == WHY_EXCEPTION) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2102 PyObject *exc, *val, *tb;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2103 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
2104 if (val == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2105 val = Py_None;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2106 Py_INCREF(val);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2107 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2108 /* Make the raw exception data
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2109 available to the handler,
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2110 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
2111 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
2112 this for 'finally'. */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2113 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
2114 PyErr_NormalizeException(
32aacd753f34 eval_code2(), set_exc_info(): Call PyErr_NormalizeException() the
Barry Warsaw <barry@python.org>
parents: 6160
diff changeset
2115 &exc, &val, &tb);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2116 set_exc_info(tstate,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2117 exc, val, tb);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2118 }
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
2119 PUSH(tb);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2120 PUSH(val);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2121 PUSH(exc);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2122 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2123 else {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2124 if (why == WHY_RETURN)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2125 PUSH(retval);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2126 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
2127 PUSH(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2128 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2129 why = WHY_NOT;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2130 JUMPTO(b->b_handler);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2131 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2132 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2133 } /* unwind stack */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2134
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2135 /* End the loop if we still have an error (or return) */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2136
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2137 if (why != WHY_NOT)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2138 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2139
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2140 } /* main loop */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2141
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2142 /* Pop remaining stack entries */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2143
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2144 while (!EMPTY()) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2145 v = POP();
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2146 Py_XDECREF(v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2147 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2148
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2149 if (why != WHY_RETURN)
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2150 retval = NULL;
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2151
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2152 if (f->f_trace) {
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2153 if (why == WHY_RETURN) {
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2154 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
2155 "return", retval)) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2156 Py_XDECREF(retval);
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2157 retval = NULL;
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2158 why = WHY_EXCEPTION;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2159 }
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2160 }
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2161 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2162
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2163 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
2164 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
2165 f, "return", retval)) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2166 Py_XDECREF(retval);
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2167 retval = NULL;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2168 why = WHY_EXCEPTION;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2169 }
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2170 }
5023
75c1ee882a4a Kill all local variables on function return. This closes a gigantic
Guido van Rossum <guido@python.org>
parents: 5021
diff changeset
2171
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2172 reset_exc_info(tstate);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2173
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2174 --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
2175
fde73467b584 Change the control flow for error handling in the function prelude to
Guido van Rossum <guido@python.org>
parents: 5023
diff changeset
2176 fail: /* Jump here from prelude on failure */
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2177
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2178 /* 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
2179
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2180 tstate->frame = f->f_back;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2181 Py_DECREF(f);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2182
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2183 return retval;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2184 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
2185
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2186 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2187 set_exc_info(PyThreadState *tstate, 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
2188 {
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2189 PyFrameObject *frame;
5557
4329e4077cf3 Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents: 5551
diff changeset
2190 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
2191
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2192 frame = tstate->frame;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2193 if (frame->f_exc_type == NULL) {
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2194 /* 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
2195 /* 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
2196 if (tstate->exc_type == NULL) {
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2197 Py_INCREF(Py_None);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2198 tstate->exc_type = Py_None;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2199 }
5557
4329e4077cf3 Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents: 5551
diff changeset
2200 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
2201 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
2202 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
2203 Py_XINCREF(tstate->exc_type);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2204 Py_XINCREF(tstate->exc_value);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2205 Py_XINCREF(tstate->exc_traceback);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2206 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
2207 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
2208 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
2209 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
2210 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
2211 Py_XDECREF(tmp_tb);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2212 }
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2213 /* 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
2214 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
2215 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
2216 tmp_tb = tstate->exc_traceback;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2217 Py_XINCREF(type);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2218 Py_XINCREF(value);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2219 Py_XINCREF(tb);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2220 tstate->exc_type = type;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2221 tstate->exc_value = value;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2222 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
2223 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
2224 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
2225 Py_XDECREF(tmp_tb);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2226 /* For b/w compatibility */
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2227 PySys_SetObject("exc_type", type);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2228 PySys_SetObject("exc_value", value);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2229 PySys_SetObject("exc_traceback", tb);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2230 }
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2231
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2232 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2233 reset_exc_info(PyThreadState *tstate)
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2234 {
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2235 PyFrameObject *frame;
5557
4329e4077cf3 Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents: 5551
diff changeset
2236 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
2237 frame = tstate->frame;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2238 if (frame->f_exc_type != NULL) {
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2239 /* 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
2240 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
2241 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
2242 tmp_tb = tstate->exc_traceback;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2243 Py_XINCREF(frame->f_exc_type);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2244 Py_XINCREF(frame->f_exc_value);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2245 Py_XINCREF(frame->f_exc_traceback);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2246 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
2247 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
2248 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
2249 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
2250 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
2251 Py_XDECREF(tmp_tb);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2252 /* For b/w compatibility */
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2253 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
2254 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
2255 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
2256 }
5557
4329e4077cf3 Plug leak of stack frame object in exception handling code.
Guido van Rossum <guido@python.org>
parents: 5551
diff changeset
2257 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
2258 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
2259 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
2260 frame->f_exc_type = NULL;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2261 frame->f_exc_value = NULL;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2262 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
2263 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
2264 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
2265 Py_XDECREF(tmp_tb);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2266 }
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2267
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
2268 /* 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
2269 This *consumes* a reference count to each of its arguments. */
5018
001a5042b181 Cleanup:
Guido van Rossum <guido@python.org>
parents: 5014
diff changeset
2270 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
2271 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
2272 {
7946
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
2273 if (type == NULL) {
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
2274 /* Reraise */
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
2275 PyThreadState *tstate = PyThreadState_Get();
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
2276 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
2277 value = tstate->exc_value;
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
2278 tb = tstate->exc_traceback;
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
2279 Py_XINCREF(type);
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
2280 Py_XINCREF(value);
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
2281 Py_XINCREF(tb);
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
2282 }
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 7014
diff changeset
2283
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
2284 /* 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
2285 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
2286 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
2287 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
2288 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
2289 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
2290 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
2291 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
2292
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
2293 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
2294
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
2295 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
2296 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
2297 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
2298
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
2299 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
2300 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
2301 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
2302
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
2303 /* 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
2304 NULL. */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2305 if (tb == Py_None) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2306 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
2307 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
2308 }
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
2309 else if (tb != NULL && !PyTraceBack_Check(tb)) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2310 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
2311 "raise 3rd arg must be traceback or 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
2312 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
2313 }
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
2314
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
2315 /* 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
2316 if (value == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2317 value = Py_None;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2318 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
2319 }
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
2320
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
2321 /* Next, repeatedly, replace a tuple exception with its first item */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2322 while (PyTuple_Check(type) && PyTuple_Size(type) > 0) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2323 PyObject *tmp = type;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2324 type = PyTuple_GET_ITEM(type, 0);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2325 Py_INCREF(type);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2326 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
2327 }
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
2328
6147
b76a44163e0f cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents: 6139
diff changeset
2329 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
2330 ;
6147
b76a44163e0f cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents: 6139
diff changeset
2331
b76a44163e0f cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents: 6139
diff changeset
2332 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
2333 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
2334
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2335 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
2336 /* Raising an instance. The value should be a dummy. */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2337 if (value != Py_None) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2338 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
2339 "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
2340 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
2341 }
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
2342 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
2343 /* Normalize to raise <class>, <instance> */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2344 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
2345 value = type;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2346 type = (PyObject*) ((PyInstanceObject*)type)->in_class;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2347 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
2348 }
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
2349 }
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
2350 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
2351 /* 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
2352 anyway, just not what you specified :-) */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2353 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
2354 "exceptions must be strings, classes, or instances");
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
2355 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
2356 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2357 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
2358 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
2359 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
2360 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
2361 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
2362 raise_error:
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2363 Py_XDECREF(value);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2364 Py_XDECREF(type);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2365 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
2366 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
2367 }
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
2368
6157
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2369 static int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2370 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
2371 {
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2372 int i;
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2373 PyObject *w;
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2374
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2375 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
2376 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
2377 if (PyErr_ExceptionMatches(PyExc_IndexError))
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2378 PyErr_SetString(PyExc_ValueError,
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2379 "unpack sequence of wrong size");
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2380 goto finally;
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2381 }
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2382 *--sp = w;
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2383 }
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2384 /* 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
2385 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
2386 if (PyErr_ExceptionMatches(PyExc_IndexError)) {
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2387 PyErr_Clear();
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2388 return 1;
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2389 }
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2390 /* 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
2391 }
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2392 else
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2393 PyErr_SetString(PyExc_ValueError,
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2394 "unpack sequence of wrong size");
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2395 /* fall through */
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2396 finally:
6160
79592761b331 unpack_sequence(): In finally clause, watch out for Py_DECREF
Barry Warsaw <barry@python.org>
parents: 6157
diff changeset
2397 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
2398 Py_DECREF(*sp);
6157
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2399
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2400 return 0;
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2401 }
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2402
647e60fb3bac eval_code2(): collapsed the implementations of UNPACK_TUPLE and
Barry Warsaw <barry@python.org>
parents: 6147
diff changeset
2403
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2404 #ifdef LLTRACE
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2405 static int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2406 prtrace(PyObject *v, char *str)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2407 {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2408 printf("%s ", str);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2409 if (PyObject_Print(v, stdout, 0) != 0)
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2410 PyErr_Clear(); /* Don't know what else to do */
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2411 printf("\n");
12579
978253542076 Add useless 'return 1' to prtrace() to shut up VC++.
Guido van Rossum <guido@python.org>
parents: 12576
diff changeset
2412 return 1;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2413 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2414 #endif
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2415
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2416 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2417 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
2418 {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2419 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
2420 int err;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2421 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
2422 if (value == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2423 value = Py_None;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2424 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
2425 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2426 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
2427 if (arg == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2428 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
2429 return;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
2430 }
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2431 err = call_trace(p_trace, p_newtrace, f, "exception", arg);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2432 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
2433 if (err == 0)
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2434 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
2435 else {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2436 Py_XDECREF(type);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2437 Py_XDECREF(value);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2438 Py_XDECREF(traceback);
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2439 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2440 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2441
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2442 /* 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
2443 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
2444 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
2445 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
2446 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
2447
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2448 static int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2449 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
2450 char *msg, PyObject *arg)
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2451 {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2452 PyThreadState *tstate = f->f_tstate;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2453 PyObject *args, *what;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2454 PyObject *res = NULL;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2455
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2456 if (tstate->tracing) {
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2457 /* 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
2458 if (p_newtrace) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2459 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
2460 *p_newtrace = NULL;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2461 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2462 return 0;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2463 }
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2464
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2465 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
2466 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
2467 goto cleanup;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2468 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
2469 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
2470 goto cleanup;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2471 Py_INCREF(f);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2472 PyTuple_SET_ITEM(args, 0, (PyObject *)f);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2473 PyTuple_SET_ITEM(args, 1, what);
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2474 if (arg == NULL)
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2475 arg = Py_None;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2476 Py_INCREF(arg);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2477 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
2478 tstate->tracing++;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2479 PyFrame_FastToLocals(f);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2480 res = PyEval_CallObject(*p_trace, args); /* May clear *p_trace! */
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2481 PyFrame_LocalsToFast(f, 1);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2482 tstate->tracing--;
5937
5a4d181ffffd Renamed a local label that was accidentally grandly renamed to
Guido van Rossum <guido@python.org>
parents: 5926
diff changeset
2483 cleanup:
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2484 Py_XDECREF(args);
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2485 if (res == NULL) {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2486 /* The trace proc raised an exception */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2487 PyTraceBack_Here(f);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2488 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
2489 *p_trace = NULL;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2490 if (p_newtrace) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2491 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
2492 *p_newtrace = NULL;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2493 }
11263
47171f2d7d58 call_trace(): A fix for PR#73, if an exception occurred in the
Barry Warsaw <barry@python.org>
parents: 11030
diff changeset
2494 /* 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
2495 * 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
2496 * 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
2497 */
47171f2d7d58 call_trace(): A fix for PR#73, if an exception occurred in the
Barry Warsaw <barry@python.org>
parents: 11030
diff changeset
2498 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
2499 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
2500 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
2501 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
2502 return -1;
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2503 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2504 else {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2505 if (p_newtrace) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2506 Py_XDECREF(*p_newtrace);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2507 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
2508 *p_newtrace = NULL;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2509 else {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2510 Py_INCREF(res);
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2511 *p_newtrace = res;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2512 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2513 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2514 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
2515 return 0;
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
2516 }
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2517 }
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
2518
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2519 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2520 PyEval_GetBuiltins(void)
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
2521 {
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5911
diff changeset
2522 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
2523 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
2524 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
2525 return tstate->interp->builtins;
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
2526 else
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
2527 return current_frame->f_builtins;
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
2528 }
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
2529
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2530 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2531 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
2532 {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2533 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
2534 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
2535 return NULL;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2536 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
2537 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
2538 }
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
2539
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2540 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2541 PyEval_GetGlobals(void)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2542 {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2543 PyFrameObject *current_frame = PyThreadState_Get()->frame;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2544 if (current_frame == NULL)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2545 return NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2546 else
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2547 return current_frame->f_globals;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2548 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2549
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2550 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2551 PyEval_GetFrame(void)
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2552 {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2553 PyFrameObject *current_frame = PyThreadState_Get()->frame;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2554 return (PyObject *)current_frame;
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2555 }
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2556
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
2557 int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2558 PyEval_GetRestricted(void)
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
2559 {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2560 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
2561 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
2562 }
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
2563
5606
495fbde64a73 Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents: 5557
diff changeset
2564 int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2565 Py_FlushLine(void)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2566 {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2567 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
2568 if (f == NULL)
495fbde64a73 Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents: 5557
diff changeset
2569 return 0;
495fbde64a73 Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents: 5557
diff changeset
2570 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
2571 return 0;
495fbde64a73 Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents: 5557
diff changeset
2572 return PyFile_WriteString("\n", f);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2573 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2574
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2575
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2576 /* External interface to call any callable object.
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2577 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
2578
6206
77f5b6cbea66 Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents: 6185
diff changeset
2579 #undef PyEval_CallObject
77f5b6cbea66 Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents: 6185
diff changeset
2580 /* for backward compatibility: export this interface */
77f5b6cbea66 Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents: 6185
diff changeset
2581
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2582 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2583 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
2584 {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2585 return PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2586 }
6206
77f5b6cbea66 Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents: 6185
diff changeset
2587 #define PyEval_CallObject(func,arg) \
77f5b6cbea66 Inline PyObject_CallObject (Marc-Andre Lemburg).
Guido van Rossum <guido@python.org>
parents: 6185
diff changeset
2588 PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL)
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2589
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2590 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2591 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
2592 {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2593 ternaryfunc call;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2594 PyObject *result;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2595
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2596 if (arg == NULL)
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2597 arg = PyTuple_New(0);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2598 else if (!PyTuple_Check(arg)) {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2599 PyErr_SetString(PyExc_TypeError,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2600 "argument list must be a tuple");
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2601 return NULL;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2602 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2603 else
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2604 Py_INCREF(arg);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2605
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2606 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
2607 PyErr_SetString(PyExc_TypeError,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2608 "keyword list must be a dictionary");
12440
d47460b1a679 Charles Waldman writes:
Guido van Rossum <guido@python.org>
parents: 12320
diff changeset
2609 Py_DECREF(arg);
2894
4095782c940e empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents: 2872
diff changeset
2610 return NULL;
4095782c940e empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents: 2872
diff changeset
2611 }
4095782c940e empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents: 2872
diff changeset
2612
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
2613 if ((call = func->ob_type->tp_call) != NULL)
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2614 result = (*call)(func, arg, kw);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2615 else if (PyMethod_Check(func) || PyFunction_Check(func))
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2616 result = call_function(func, arg, kw);
314
e83852d1a5e2 Add interface to call a Python function (or other callable) object
Guido van Rossum <guido@python.org>
parents: 312
diff changeset
2617 else
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2618 result = call_builtin(func, arg, kw);
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2619
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2620 Py_DECREF(arg);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2621
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2622 if (result == NULL && !PyErr_Occurred())
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2623 PyErr_SetString(PyExc_SystemError,
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2624 "NULL result without error in call_object");
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2625
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2626 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
2627 }
e83852d1a5e2 Add interface to call a Python function (or other callable) object
Guido van Rossum <guido@python.org>
parents: 312
diff changeset
2628
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2629 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2630 call_builtin(PyObject *func, PyObject *arg, PyObject *kw)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2631 {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2632 if (PyCFunction_Check(func)) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2633 PyCFunction meth = PyCFunction_GetFunction(func);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2634 PyObject *self = PyCFunction_GetSelf(func);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2635 int flags = PyCFunction_GetFlags(func);
2866
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
2636 if (!(flags & METH_VARARGS)) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2637 int size = PyTuple_Size(arg);
481
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
2638 if (size == 1)
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2639 arg = PyTuple_GET_ITEM(arg, 0);
481
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
2640 else if (size == 0)
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
2641 arg = NULL;
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
2642 }
2866
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
2643 if (flags & METH_KEYWORDS)
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
2644 return (*(PyCFunctionWithKeywords)meth)(self, arg, kw);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2645 if (kw != NULL && PyDict_Size(kw) != 0) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2646 PyErr_SetString(PyExc_TypeError,
2866
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
2647 "this function takes no keyword arguments");
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
2648 return NULL;
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
2649 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2650 return (*meth)(self, arg);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2651 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2652 if (PyClass_Check(func)) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2653 return PyInstance_New(func, arg, kw);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2654 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2655 if (PyInstance_Check(func)) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2656 PyObject *res, *call = PyObject_GetAttrString(func,"__call__");
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2657 if (call == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2658 PyErr_Clear();
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2659 PyErr_SetString(PyExc_AttributeError,
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2660 "no __call__ method defined");
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2661 return NULL;
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2662 }
2866
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
2663 res = PyEval_CallObjectWithKeywords(call, arg, kw);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2664 Py_DECREF(call);
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2665 return res;
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2666 }
11468
1855131a4dcd Change the last PyErr_Format %s format to %.400s.
Guido van Rossum <guido@python.org>
parents: 11407
diff changeset
2667 PyErr_Format(PyExc_TypeError, "call of non-function (type %.400s)",
9048
118f9f73abe9 Add the type of the object to the error message about calling a non-function.
Guido van Rossum <guido@python.org>
parents: 8811
diff changeset
2668 func->ob_type->tp_name);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2669 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2670 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2671
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2672 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2673 call_function(PyObject *func, PyObject *arg, PyObject *kw)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2674 {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2675 PyObject *class = NULL; /* == owner */
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2676 PyObject *argdefs;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2677 PyObject **d, **k;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2678 int nk, nd;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2679 PyObject *result;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2680
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2681 if (kw != NULL && !PyDict_Check(kw)) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2682 PyErr_BadInternalCall();
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2683 return NULL;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2684 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2685
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2686 if (PyMethod_Check(func)) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2687 PyObject *self = PyMethod_Self(func);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2688 class = PyMethod_Class(func);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2689 func = PyMethod_Function(func);
1290
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2690 if (self == NULL) {
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2691 /* Unbound methods must be called with an instance of
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2692 the class (or a derived class) as first argument */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2693 if (PyTuple_Size(arg) >= 1) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2694 self = PyTuple_GET_ITEM(arg, 0);
1290
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2695 if (self != NULL &&
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2696 PyInstance_Check(self) &&
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2697 PyClass_IsSubclass((PyObject *)
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2698 (((PyInstanceObject *)self)->in_class),
1290
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2699 class))
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2700 /* Handy-dandy */ ;
1290
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2701 else
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2702 self = NULL;
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2703 }
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2704 if (self == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2705 PyErr_SetString(PyExc_TypeError,
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2706 "unbound method must be called with class instance 1st argument");
1290
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2707 return NULL;
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2708 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2709 Py_INCREF(arg);
1290
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2710 }
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2711 else {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2712 int argcount = PyTuple_Size(arg);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2713 PyObject *newarg = PyTuple_New(argcount + 1);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2714 int i;
1289
4d292c7857d4 Access checks now work, at least for instance data (not for methods
Guido van Rossum <guido@python.org>
parents: 1288
diff changeset
2715 if (newarg == NULL)
4d292c7857d4 Access checks now work, at least for instance data (not for methods
Guido van Rossum <guido@python.org>
parents: 1288
diff changeset
2716 return NULL;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2717 Py_INCREF(self);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2718 PyTuple_SET_ITEM(newarg, 0, self);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2719 for (i = 0; i < argcount; i++) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2720 PyObject *v = PyTuple_GET_ITEM(arg, i);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2721 Py_XINCREF(v);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2722 PyTuple_SET_ITEM(newarg, i+1, v);
1289
4d292c7857d4 Access checks now work, at least for instance data (not for methods
Guido van Rossum <guido@python.org>
parents: 1288
diff changeset
2723 }
4d292c7857d4 Access checks now work, at least for instance data (not for methods
Guido van Rossum <guido@python.org>
parents: 1288
diff changeset
2724 arg = newarg;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2725 }
8651
4ba9b70ca56e Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents: 8403
diff changeset
2726 if (!PyFunction_Check(func)) {
4ba9b70ca56e Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents: 8403
diff changeset
2727 result = PyEval_CallObjectWithKeywords(func, arg, kw);
4ba9b70ca56e Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents: 8403
diff changeset
2728 Py_DECREF(arg);
4ba9b70ca56e Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents: 8403
diff changeset
2729 return result;
4ba9b70ca56e Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents: 8403
diff changeset
2730 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2731 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2732 else {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2733 if (!PyFunction_Check(func)) {
9048
118f9f73abe9 Add the type of the object to the error message about calling a non-function.
Guido van Rossum <guido@python.org>
parents: 8811
diff changeset
2734 PyErr_Format(PyExc_TypeError,
12320
5de0b939fe61 Skip Montanaro: add string precisions to calls to PyErr_Format
Guido van Rossum <guido@python.org>
parents: 12174
diff changeset
2735 "call of non-function (type %.200s)",
9048
118f9f73abe9 Add the type of the object to the error message about calling a non-function.
Guido van Rossum <guido@python.org>
parents: 8811
diff changeset
2736 func->ob_type->tp_name);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2737 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2738 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2739 Py_INCREF(arg);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2740 }
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2741
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2742 argdefs = PyFunction_GetDefaults(func);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2743 if (argdefs != NULL && PyTuple_Check(argdefs)) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2744 d = &PyTuple_GET_ITEM((PyTupleObject *)argdefs, 0);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2745 nd = PyTuple_Size(argdefs);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2746 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2747 else {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2748 d = NULL;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2749 nd = 0;
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2750 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2751
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2752 if (kw != NULL) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2753 int pos, i;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2754 nk = PyDict_Size(kw);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2755 k = PyMem_NEW(PyObject *, 2*nk);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2756 if (k == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2757 PyErr_NoMemory();
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2758 Py_DECREF(arg);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2759 return NULL;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2760 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2761 pos = i = 0;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2762 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
2763 i += 2;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2764 nk = i/2;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2765 /* XXX This is broken if the caller deletes dict items! */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2766 }
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2767 else {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2768 k = NULL;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2769 nk = 0;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2770 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2771
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2772 result = eval_code2(
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2773 (PyCodeObject *)PyFunction_GetCode(func),
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2774 PyFunction_GetGlobals(func), (PyObject *)NULL,
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2775 &PyTuple_GET_ITEM(arg, 0), PyTuple_Size(arg),
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2776 k, nk,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2777 d, nd,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2778 class);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2779
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2780 Py_DECREF(arg);
12576
1c7c2dd1beb1 Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents: 12440
diff changeset
2781 if (k != NULL)
1c7c2dd1beb1 Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents: 12440
diff changeset
2782 PyMem_DEL(k);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2783
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2784 return result;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2785 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2786
3863
4566a19c3438 Better error message if stride used on normal sequence object
Guido van Rossum <guido@python.org>
parents: 3839
diff changeset
2787 #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
2788 "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
2789
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2790 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2791 loop_subscript(PyObject *v, PyObject *w)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2792 {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2793 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
2794 int i;
8403
c4df8b6637b6 Moved cmp_member() to abstract.c, as PySequence_Contains() [with
Guido van Rossum <guido@python.org>
parents: 8328
diff changeset
2795 if (sq == NULL || sq->sq_item == NULL) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2796 PyErr_SetString(PyExc_TypeError, "loop over non-sequence");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2797 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2798 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2799 i = PyInt_AsLong(w);
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2800 v = (*sq->sq_item)(v, i);
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2801 if (v)
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2802 return v;
6147
b76a44163e0f cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents: 6139
diff changeset
2803 if (PyErr_ExceptionMatches(PyExc_IndexError))
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2804 PyErr_Clear();
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2805 return NULL;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2806 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2807
12614
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
2808 /* 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
2809 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
2810 and error. Returns 1 on success.*/
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
2811
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
2812 int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2813 _PyEval_SliceIndex(PyObject *v, int *pi)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2814 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2815 if (v != NULL) {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2816 long x;
11839
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2817 if (PyInt_Check(v)) {
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2818 x = PyInt_AsLong(v);
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2819 } else if (PyLong_Check(v)) {
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2820 x = PyLong_AsLong(v);
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2821 if (x==-1 && PyErr_Occurred()) {
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2822 PyObject *long_zero;
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2823
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2824 if (!PyErr_ExceptionMatches( PyExc_OverflowError ) ) {
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2825 /* It's not an overflow error, so just
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2826 signal an error */
12614
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
2827 return 0;
11839
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2828 }
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2829
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2830 /* It's an overflow error, so we need to
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2831 check the sign of the long integer,
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2832 set the value to INT_MAX or 0, and clear
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2833 the error. */
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2834
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2835 /* Create a long integer with a value of 0 */
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2836 long_zero = PyLong_FromLong( 0L );
12614
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
2837 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
2838
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2839 /* Check sign */
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2840 if (PyObject_Compare(long_zero, v) < 0)
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2841 x = INT_MAX;
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2842 else
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2843 x = 0;
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2844
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2845 /* Free the long integer we created, and clear the
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2846 OverflowError */
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2847 Py_DECREF(long_zero);
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2848 PyErr_Clear();
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2849 }
91cfb6e68ca4 Allow using long integers as slice indexes
Andrew M. Kuchling <amk@amk.ca>
parents: 11827
diff changeset
2850 } else {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2851 PyErr_SetString(PyExc_TypeError,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2852 "slice index must be int");
12614
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
2853 return 0;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2854 }
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2855 /* 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
2856 if (x > INT_MAX)
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2857 x = INT_MAX;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2858 else if (x < -INT_MAX)
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2859 x = 0;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2860 *pi = x;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2861 }
12614
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
2862 return 1;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2863 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2864
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2865 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2866 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
2867 {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2868 int ilow = 0, ihigh = INT_MAX;
12614
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
2869 if (!_PyEval_SliceIndex(v, &ilow))
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2870 return NULL;
12614
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
2871 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
2872 return NULL;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2873 return PySequence_GetSlice(u, ilow, ihigh);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2874 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2875
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2876 static int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2877 assign_slice(PyObject *u, PyObject *v, PyObject *w, PyObject *x) /* u[v:w] = x */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2878 {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2879 int ilow = 0, ihigh = INT_MAX;
12614
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
2880 if (!_PyEval_SliceIndex(v, &ilow))
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2881 return -1;
12614
8d7ad3818ea6 Trent Mick:
Guido van Rossum <guido@python.org>
parents: 12579
diff changeset
2882 if (!_PyEval_SliceIndex(w, &ihigh))
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2883 return -1;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2884 if (x == NULL)
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2885 return PySequence_DelSlice(u, ilow, ihigh);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2886 else
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2887 return PySequence_SetSlice(u, ilow, ihigh, x);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2888 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2889
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2890 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2891 cmp_outcome(int op, register PyObject *v, register PyObject *w)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2892 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2893 register int cmp;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2894 register int res = 0;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2895 switch (op) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2896 case IS:
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2897 case IS_NOT:
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2898 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
2899 if (op == (int) IS_NOT)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2900 res = !res;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2901 break;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2902 case IN:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2903 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
2904 res = PySequence_Contains(w, v);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2905 if (res < 0)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2906 return NULL;
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2907 if (op == (int) NOT_IN)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2908 res = !res;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2909 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2910 case EXC_MATCH:
6147
b76a44163e0f cmp_exception gets promoted (essentially) to the C API function
Barry Warsaw <barry@python.org>
parents: 6139
diff changeset
2911 res = PyErr_GivenExceptionMatches(v, w);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2912 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2913 default:
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2914 cmp = PyObject_Compare(v, w);
5610
10e9cfa010f0 PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents: 5606
diff changeset
2915 if (cmp && PyErr_Occurred())
10e9cfa010f0 PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents: 5606
diff changeset
2916 return NULL;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2917 switch (op) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2918 case LT: res = cmp < 0; break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2919 case LE: res = cmp <= 0; break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2920 case EQ: res = cmp == 0; break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2921 case NE: res = cmp != 0; break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2922 case GT: res = cmp > 0; break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2923 case GE: res = cmp >= 0; break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2924 /* XXX no default? (res is initialized to 0 though) */
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2925 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2926 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2927 v = res ? Py_True : Py_False;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2928 Py_INCREF(v);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2929 return v;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2930 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2931
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2932 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
2933 import_from(PyObject *v, PyObject *name)
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2934 {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2935 PyObject *w, *x;
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2936 if (!PyModule_Check(v)) {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2937 PyErr_SetString(PyExc_TypeError,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2938 "import-from requires module object");
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2939 return NULL;
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2940 }
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2941 w = PyModule_GetDict(v); /* TDB: can this not fail ? */
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2942 x = PyDict_GetItem(w, name);
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2943 if (x == NULL) {
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2944 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
2945 "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
2946 PyString_AsString(name));
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2947 } else
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2948 Py_INCREF(x);
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2949 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
2950 }
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2951
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2952 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
2953 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
2954 {
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2955 int pos = 0, err;
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2956 PyObject *name, *value;
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2957 PyObject *w;
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2958
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2959 if (!PyModule_Check(v)) {
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2960 PyErr_SetString(PyExc_TypeError,
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2961 "import-from requires module object");
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
2962 return -1;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
2963 }
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2964 w = PyModule_GetDict(v); /* TBD: can this not fail ? */
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2965
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2966 while (PyDict_Next(w, &pos, &name, &value)) {
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2967 if (!PyString_Check(name) ||
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2968 PyString_AsString(name)[0] == '_')
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2969 continue;
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2970 Py_INCREF(value);
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2971 err = PyDict_SetItem(locals, name, value);
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2972 Py_DECREF(value);
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2973 if (err != 0)
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2974 return -1;
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2975 }
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13930
diff changeset
2976 return 0;
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2977 }
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2978
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2979 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
2980 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
2981 {
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
2982 int i, n;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2983 if (!PyTuple_Check(bases)) {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2984 PyErr_SetString(PyExc_SystemError,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2985 "build_class with non-tuple bases");
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2986 return NULL;
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2987 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2988 if (!PyDict_Check(methods)) {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2989 PyErr_SetString(PyExc_SystemError,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2990 "build_class with non-dictionary");
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2991 return NULL;
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2992 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
2993 if (!PyString_Check(name)) {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5368
diff changeset
2994 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
2995 "build_class with non-string name");
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2996 return NULL;
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2997 }
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
2998 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
2999 for (i = 0; i < n; i++) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3000 PyObject *base = PyTuple_GET_ITEM(bases, i);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3001 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
3002 /* 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
3003 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
3004 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
3005 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
3006 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
3007 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
3008 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
3009 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
3010 protocol! */
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3011 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
3012 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
3013 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
3014 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
3015 else
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3016 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
3017 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
3018 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
3019 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
3020 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
3021 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
3022 "(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
3023 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
3024 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
3025 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
3026 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
3027 }
7982
a909a2869ac5 Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 7946
diff changeset
3028 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
3029 Py_DECREF(callable);
7982
a909a2869ac5 Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 7946
diff changeset
3030 }
5911
6986781a07ef Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
Guido van Rossum <guido@python.org>
parents: 5865
diff changeset
3031 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
3032 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3033 PyErr_SetString(PyExc_TypeError,
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
3034 "base is not a class object");
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
3035 return NULL;
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
3036 }
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
3037 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3038 return PyClass_New(bases, methods, name);
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
3039 }
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
3040
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3041 static int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3042 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
3043 PyObject *locals)
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3044 {
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3045 int n;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3046 PyObject *v;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3047 int plain = 0;
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3048
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3049 if (PyTuple_Check(prog) && globals == Py_None && locals == Py_None &&
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3050 ((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
3051 /* Backward compatibility hack */
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3052 globals = PyTuple_GetItem(prog, 1);
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3053 if (n == 3)
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3054 locals = PyTuple_GetItem(prog, 2);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3055 prog = PyTuple_GetItem(prog, 0);
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3056 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3057 if (globals == Py_None) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3058 globals = PyEval_GetGlobals();
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3059 if (locals == Py_None) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3060 locals = PyEval_GetLocals();
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3061 plain = 1;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3062 }
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3063 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3064 else if (locals == Py_None)
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3065 locals = globals;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3066 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
3067 !PyUnicode_Check(prog) &&
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3068 !PyCode_Check(prog) &&
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3069 !PyFile_Check(prog)) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3070 PyErr_SetString(PyExc_TypeError,
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3071 "exec 1st arg must be string, code or file object");
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3072 return -1;
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3073 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3074 if (!PyDict_Check(globals) || !PyDict_Check(locals)) {
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3075 PyErr_SetString(PyExc_TypeError,
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3076 "exec 2nd/3rd args must be dict or None");
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3077 return -1;
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3078 }
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3079 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
3080 PyDict_SetItemString(globals, "__builtins__", f->f_builtins);
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3081 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
3082 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
3083 }
11651
d88996e46cb2 Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents: 11468
diff changeset
3084 else if (PyFile_Check(prog)) {
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3085 FILE *fp = PyFile_AsFile(prog);
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3086 char *name = PyString_AsString(PyFile_Name(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
3087 v = PyRun_File(fp, name, Py_file_input, globals, locals);
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3088 }
11651
d88996e46cb2 Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents: 11468
diff changeset
3089 else {
14696
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
3090 char *str;
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
3091 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
3092 return -1;
14696
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
3093 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
3094 }
11651
d88996e46cb2 Fix a bug in exec_statement() noted incidentally by Tim Peters in
Guido van Rossum <guido@python.org>
parents: 11468
diff changeset
3095 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
3096 PyFrame_LocalsToFast(f, 0);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3097 if (v == NULL)
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3098 return -1;
5368
f2132d1f66a6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5177
diff changeset
3099 Py_DECREF(v);
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3100 return 0;
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3101 }
2338
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
3102
14268
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3103 static void
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3104 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
3105 {
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3106 char *obj_str;
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3107
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3108 if (!obj)
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3109 return;
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3110
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3111 obj_str = PyString_AsString(obj);
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3112 if (!obj_str)
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3113 return;
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3114
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3115 PyErr_Format(exc, format_str, obj_str);
cd8b815cb196 Better error message with UnboundLocalError
Paul Prescod <prescod@prescod.net>
parents: 14238
diff changeset
3116 }
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3117
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3118 #ifdef DYNAMIC_EXECUTION_PROFILE
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3119
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3120 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3121 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
3122 {
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3123 int i;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3124 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
3125 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
3126 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
3127 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
3128 if (x == NULL) {
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3129 Py_DECREF(l);
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3130 return NULL;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3131 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3132 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
3133 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3134 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
3135 a[i] = 0;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3136 return l;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3137 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3138
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3139 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
3140 _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
3141 {
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3142 #ifndef DXPAIRS
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3143 return getarray(dxp);
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3144 #else
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3145 int i;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3146 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
3147 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
3148 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
3149 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
3150 if (x == NULL) {
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3151 Py_DECREF(l);
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3152 return NULL;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3153 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3154 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
3155 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3156 return l;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3157 #endif
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3158 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3159
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3160 #endif