annotate Python/ceval.c @ 14268:cd8b815cb196 legacy-trunk

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