annotate Python/ceval.c @ 5223:bc8832b52b50 legacy-trunk

1. Add string conversions to int(), long(), float(). (Not to complex()!) 2. Fix two bugs in complex(): - Memory leak when using complex(classinstance) -- r was never DECREF'ed. - Conversion of the second argument, if not complex, was done using the type vector of the 1st.
author Guido van Rossum <guido@python.org>
date Mon, 31 Mar 1997 17:15:43 +0000
parents b18e03ba4817
children f2132d1f66a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5177
b18e03ba4817 Clarify error message for unexpected keyword parameter.
Guido van Rossum <guido@python.org>
parents: 5099
diff changeset
1
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
2 /***********************************************************
2062
d0d0a69b5ca3 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 2052
diff changeset
3 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
d0d0a69b5ca3 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 2052
diff changeset
4 The Netherlands.
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
5
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
6 All Rights Reserved
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
7
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4040
diff changeset
8 Permission to use, copy, modify, and distribute this software and its
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4040
diff changeset
9 documentation for any purpose and without fee is hereby granted,
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
10 provided that the above copyright notice appear in all copies and that
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4040
diff changeset
11 both that copyright notice and this permission notice appear in
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
12 supporting documentation, and that the names of Stichting Mathematisch
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4040
diff changeset
13 Centrum or CWI or Corporation for National Research Initiatives or
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4040
diff changeset
14 CNRI not be used in advertising or publicity pertaining to
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4040
diff changeset
15 distribution of the software without specific, written prior
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4040
diff changeset
16 permission.
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
17
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4040
diff changeset
18 While CWI is the initial source for this software, a modified version
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4040
diff changeset
19 is made available by the Corporation for National Research Initiatives
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4040
diff changeset
20 (CNRI) at the Internet address ftp://ftp.python.org.
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4040
diff changeset
21
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4040
diff changeset
22 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4040
diff changeset
23 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4040
diff changeset
24 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4040
diff changeset
25 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4040
diff changeset
26 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4040
diff changeset
27 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4040
diff changeset
28 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4040
diff changeset
29 PERFORMANCE OF THIS SOFTWARE.
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
30
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
31 ******************************************************************/
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
32
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
33 /* Execute compiled code */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
34
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
35 /* XXX TO DO:
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
36 XXX how to pass arguments to call_trace?
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
37 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
38 XXX document it!
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
39 */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
40
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
41 #include "allobjects.h"
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
42
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 #include "compile.h"
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
44 #include "frameobject.h"
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
45 #include "eval.h"
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 #include "opcode.h"
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
47 #include "graminit.h"
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
48
1400
aac8231a715c * mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents: 1391
diff changeset
49 #include <ctype.h>
aac8231a715c * mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents: 1391
diff changeset
50
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
51 /* 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
52 /* #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
53
4839
4567e158d20c Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents: 4667
diff changeset
54 #ifdef Py_DEBUG
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
55 /* For debugging the interpreter: */
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
56 #define LLTRACE 1 /* Low-level trace feature */
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
57 #define CHECKEXC 1 /* Double-check exception checking */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 #endif
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
59
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
60
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
61 /* Forward declarations */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
62
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
63 static object *eval_code2 PROTO((codeobject *,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
64 object *, object *,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
65 object **, int,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
66 object **, int,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
67 object **, int,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
68 object *));
746
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
69 #ifdef LLTRACE
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
70 static int prtrace PROTO((object *, char *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
71 #endif
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
72 static void call_exc_trace PROTO((object **, object**, frameobject *));
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
73 static int call_trace
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
74 PROTO((object **, object **, frameobject *, char *, object *));
746
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
75 static object *add PROTO((object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
76 static object *sub PROTO((object *, object *));
3694
581f073f071d Renamed static pow() to powerop() to avoid name conflict in some compilers.
Guido van Rossum <guido@python.org>
parents: 3610
diff changeset
77 static object *powerop PROTO((object *, object *));
746
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
78 static object *mul PROTO((object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
79 static object *divide PROTO((object *, object *));
2088
1940e1e0cedf Use new instancebinop interface
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
80 static object *mod PROTO((object *, object *));
746
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
81 static object *neg PROTO((object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
82 static object *pos PROTO((object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
83 static object *not PROTO((object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
84 static object *invert PROTO((object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
85 static object *lshift PROTO((object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
86 static object *rshift PROTO((object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
87 static object *and PROTO((object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
88 static object *xor PROTO((object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
89 static object *or PROTO((object *, object *));
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
90 static object *call_builtin PROTO((object *, object *, object *));
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
91 static object *call_function PROTO((object *, object *, object *));
746
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
92 static object *apply_subscript PROTO((object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
93 static object *loop_subscript PROTO((object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
94 static int slice_index PROTO((object *, int, int *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
95 static object *apply_slice PROTO((object *, object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
96 static int assign_subscript PROTO((object *, object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
97 static int assign_slice PROTO((object *, object *, object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
98 static int cmp_exception PROTO((object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
99 static int cmp_member PROTO((object *, object *));
802
3d6541a2eca5 Arg of cmp_outcome becomes an int for portability to the Mac
Guido van Rossum <guido@python.org>
parents: 789
diff changeset
100 static object *cmp_outcome PROTO((int, object *, object *));
746
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
101 static int import_from PROTO((object *, object *, object *));
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
102 static object *build_class PROTO((object *, object *, object *));
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
103 static int exec_statement PROTO((object *, object *, object *));
2338
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
104 static object *find_from_args PROTO((frameobject *, int));
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
105
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
106
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
107 /* Dynamic execution profile */
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
108 #ifdef DYNAMIC_EXECUTION_PROFILE
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
109 #ifdef DXPAIRS
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
110 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
111 #define dxp dxpairs[256]
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
112 #else
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
113 static long dxp[256];
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
114 #endif
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
115 #endif
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
116
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
117
746
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
118 /* Pointer to current frame, used to link new frames to */
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
119
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
120 static frameobject *current_frame;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
121
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
122 #ifdef WITH_THREAD
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
123
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
124 #include <errno.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
125 #include "thread.h"
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
126
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
127 static type_lock interpreter_lock = 0;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
128 static long main_thread = 0;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
129
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
130 void
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
131 init_save_thread()
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
132 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
133 if (interpreter_lock)
1179
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1132
diff changeset
134 return;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
135 interpreter_lock = allocate_lock();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
136 acquire_lock(interpreter_lock, 1);
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
137 main_thread = get_thread_ident();
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
138 }
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
139
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
140 #endif
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
141
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
142 /* Functions save_thread and restore_thread are always defined so
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
143 dynamically loaded modules needn't be compiled separately for use
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
144 with and without threads: */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
145
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
146 object *
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
147 save_thread()
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
148 {
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
149 #ifdef WITH_THREAD
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
150 if (interpreter_lock) {
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
151 object *res;
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
152 res = (object *)current_frame;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
153 current_frame = NULL;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
154 release_lock(interpreter_lock);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
155 return res;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
156 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
157 #endif
1271
2919b448e385 * Microscopic corrections to make things compile on the Cray APP.
Guido van Rossum <guido@python.org>
parents: 1263
diff changeset
158 return NULL;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
159 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
160
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
161 void
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
162 restore_thread(x)
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
163 object *x;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
164 {
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
165 #ifdef WITH_THREAD
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
166 if (interpreter_lock) {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
167 int err;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
168 err = errno;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
169 acquire_lock(interpreter_lock, 1);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
170 errno = err;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
171 current_frame = (frameobject *)x;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
172 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
173 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
174 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
175
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
176
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
177 /* 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
178 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
179 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
180 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
181 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
182 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
183
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
184 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
185 (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
186 an exception condition).
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
187
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
188 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
189 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
190
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
191 #ifdef WITH_THREAD
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
192 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
193 will execute them.
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
194 #endif
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
195
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
196 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
197 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
198 (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
199 (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
200 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
201 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
202 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
203 thread (the main thread) ever takes things out of the queue.
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
204 */
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
205
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
206 static int ticker = 0; /* main loop counter to do periodic things */
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
207
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
208 #define NPENDINGCALLS 32
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
209 static struct {
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
210 int (*func) PROTO((ANY *));
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
211 ANY *arg;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
212 } pendingcalls[NPENDINGCALLS];
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
213 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
214 static volatile int pendinglast = 0;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
215
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
216 int
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
217 Py_AddPendingCall(func, arg)
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
218 int (*func) PROTO((ANY *));
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
219 ANY *arg;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
220 {
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
221 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
222 int i, j;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
223 /* 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
224 /* 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
225 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
226 if (busy)
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
227 return -1;
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
228 busy = 1;
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
229 i = pendinglast;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
230 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
231 if (j == pendingfirst)
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
232 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
233 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
234 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
235 pendinglast = j;
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
236 ticker = 0; /* Signal main loop */
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
237 busy = 0;
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
238 /* 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
239 return 0;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
240 }
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
241
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
242 int
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
243 Py_MakePendingCalls()
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
244 {
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
245 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
246 #ifdef WITH_THREAD
5018
001a5042b181 Cleanup:
Guido van Rossum <guido@python.org>
parents: 5014
diff changeset
247 if (main_thread && get_thread_ident() != main_thread) {
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
248 ticker = 0; /* 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
249 return 0;
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
250 }
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
251 #endif
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
252 if (busy) {
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
253 ticker = 0; /* We're not done yet */
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
254 return 0;
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
255 }
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
256 busy = 1;
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
257 for (;;) {
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
258 int i;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
259 int (*func) PROTO((ANY *));
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
260 ANY *arg;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
261 i = pendingfirst;
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
262 if (i == pendinglast)
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
263 break; /* Queue empty */
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
264 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
265 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
266 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
267 if (func(arg) < 0) {
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
268 busy = 0;
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
269 ticker = 0; /* 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
270 return -1;
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
271 }
1887
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
272 }
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
273 busy = 0;
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 }
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
276
e7c6a18381d9 * Python/ceval.c (eval_code): added registry of pending functions
Guido van Rossum <guido@python.org>
parents: 1846
diff changeset
277
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
278 /* 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
279
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
280 enum why_code {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
281 WHY_NOT, /* No error */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
282 WHY_EXCEPTION, /* Exception occurred */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
283 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
284 WHY_RETURN, /* 'return' statement */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
285 WHY_BREAK /* 'break' statement */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
286 };
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
287
5018
001a5042b181 Cleanup:
Guido van Rossum <guido@python.org>
parents: 5014
diff changeset
288 static enum why_code do_raise PROTO((object *, object *, object *));
001a5042b181 Cleanup:
Guido van Rossum <guido@python.org>
parents: 5014
diff changeset
289
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
290
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
291 /* Backward compatible interface */
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
292
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
293 object *
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
294 eval_code(co, globals, locals)
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
295 codeobject *co;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
296 object *globals;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
297 object *locals;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
298 {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
299 return eval_code2(co,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
300 globals, locals,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
301 (object **)NULL, 0,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
302 (object **)NULL, 0,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
303 (object **)NULL, 0,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
304 (object *)NULL);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
305 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
306
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
307
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
308 /* Interpreter main loop */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
309
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
310 #ifndef MAX_RECURSION_DEPTH
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
311 #define MAX_RECURSION_DEPTH 10000
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
312 #endif
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
313
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
314 static int recursion_depth = 0;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
315
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
316 static object *
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
317 eval_code2(co, globals, locals,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
318 args, argcount, kws, kwcount, defs, defcount, owner)
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
319 codeobject *co;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
320 object *globals;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
321 object *locals;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
322 object **args;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
323 int argcount;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
324 object **kws; /* length: 2*kwcount */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
325 int kwcount;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
326 object **defs;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
327 int defcount;
1293
ac3c80abbf43 * classobject.c: in instance_getattr, don't make a method out of a
Guido van Rossum <guido@python.org>
parents: 1290
diff changeset
328 object *owner;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
329 {
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
330 #ifdef DXPAIRS
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
331 int lastopcode = 0;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
332 #endif
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
333 register unsigned char *next_instr;
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
334 register int opcode = 0; /* Current opcode */
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
335 register int oparg = 0; /* Current opcode argument, if any */
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
336 register object **stack_pointer;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
337 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
338 register int err; /* Error status -- nonzero if error */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
339 register object *x; /* Result object -- NULL if error */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
340 register object *v; /* Temporary objects popped off stack */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
341 register object *w;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
342 register object *u;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
343 register object *t;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
344 register frameobject *f; /* Current frame */
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
345 register object **fastlocals = NULL;
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
346 object *retval = NULL; /* Return value */
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
347 #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
348 int lltrace;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
349 #endif
4839
4567e158d20c Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents: 4667
diff changeset
350 #if defined(Py_DEBUG) || defined(LLTRACE)
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
351 /* Make it easier to find out where we are with a debugger */
1016
a41e3ba5b47d Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents: 974
diff changeset
352 char *filename = getstringvalue(co->co_filename);
a41e3ba5b47d Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents: 974
diff changeset
353 #endif
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
354
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
355 /* Code access macros */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
356
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
357 #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
358 #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
359 #define GETNAMEV(i) Getnamev(f, i)
5052
7841c48cdb5b Two small changes:
Guido van Rossum <guido@python.org>
parents: 5050
diff changeset
360 #define FIRST_INSTR() (GETUSTRINGVALUE(co->co_code))
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
361 #define INSTR_OFFSET() (next_instr - FIRST_INSTR())
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
362 #define NEXTOP() (*next_instr++)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
363 #define NEXTARG() (next_instr += 2, (next_instr[-1]<<8) + next_instr[-2])
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
364 #define JUMPTO(x) (next_instr = FIRST_INSTR() + (x))
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
365 #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
366
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
367 /* Stack manipulation macros */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
368
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
369 #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
370 #define EMPTY() (STACK_LEVEL() == 0)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
371 #define TOP() (stack_pointer[-1])
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
372 #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
373 #define BASIC_POP() (*--stack_pointer)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
374
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
375 #ifdef LLTRACE
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
376 #define PUSH(v) (BASIC_PUSH(v), lltrace && prtrace(TOP(), "push"))
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
377 #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
378 #else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
379 #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
380 #define POP() BASIC_POP()
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
381 #endif
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
382
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
383 /* Local variable macros */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
384
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
385 #define GETLOCAL(i) (fastlocals[i])
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
386 #define SETLOCAL(i, value) do { XDECREF(GETLOCAL(i)); \
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
387 GETLOCAL(i) = value; } while (0)
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
388
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
389 #ifdef USE_STACKCHECK
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
390 if (recursion_depth%10 == 0 && PyOS_CheckStack()) {
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
391 err_setstr(MemoryError, "Stack overflow");
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
392 return NULL;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
393 }
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
394 #endif
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
395
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
396 if (globals == NULL) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
397 err_setstr(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
398 return NULL;
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
399 }
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
400
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
401 #ifdef LLTRACE
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
402 lltrace = dictlookup(globals, "__lltrace__") != NULL;
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
403 #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
404
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
405 f = newframeobject(
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
406 current_frame, /*back*/
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
407 co, /*code*/
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
408 globals, /*globals*/
5014
0bfac89afc83 Changes for frame object speedup:
Guido van Rossum <guido@python.org>
parents: 5002
diff changeset
409 locals); /*locals*/
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
410 if (f == NULL)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
411 return NULL;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
412
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
413 current_frame = f;
5052
7841c48cdb5b Two small changes:
Guido van Rossum <guido@python.org>
parents: 5050
diff changeset
414 fastlocals = f->f_localsplus;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
415
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
416 if (co->co_argcount > 0 ||
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
417 co->co_flags & (CO_VARARGS | CO_VARKEYWORDS)) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
418 int i;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
419 int n = argcount;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
420 object *kwdict = NULL;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
421 if (co->co_flags & CO_VARKEYWORDS) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
422 kwdict = newmappingobject();
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
423 if (kwdict == NULL)
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
424 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
425 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
426 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
427 i++;
fde73467b584 Change the control flow for error handling in the function prelude to
Guido van Rossum <guido@python.org>
parents: 5023
diff changeset
428 SETLOCAL(i, kwdict);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
429 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
430 if (argcount > co->co_argcount) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
431 if (!(co->co_flags & CO_VARARGS)) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
432 err_setstr(TypeError, "too many arguments");
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
433 goto fail;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
434 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
435 n = co->co_argcount;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
436 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
437 for (i = 0; i < n; i++) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
438 x = args[i];
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
439 INCREF(x);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
440 SETLOCAL(i, x);
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 (co->co_flags & CO_VARARGS) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
443 u = newtupleobject(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
444 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
445 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
446 SETLOCAL(co->co_argcount, u);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
447 for (i = n; i < argcount; i++) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
448 x = args[i];
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
449 INCREF(x);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
450 SETTUPLEITEM(u, i-n, x);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
451 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
452 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
453 for (i = 0; i < kwcount; i++) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
454 object *keyword = kws[2*i];
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
455 object *value = kws[2*i + 1];
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
456 int j;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
457 /* XXX slow -- speed up using dictionary? */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
458 for (j = 0; j < co->co_argcount; j++) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
459 object *nm = GETTUPLEITEM(co->co_varnames, j);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
460 if (cmpobject(keyword, nm) == 0)
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
461 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
462 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
463 if (j >= co->co_argcount) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
464 if (kwdict == NULL) {
5177
b18e03ba4817 Clarify error message for unexpected keyword parameter.
Guido van Rossum <guido@python.org>
parents: 5099
diff changeset
465 PyErr_Format(TypeError,
b18e03ba4817 Clarify error message for unexpected keyword parameter.
Guido van Rossum <guido@python.org>
parents: 5099
diff changeset
466 "unexpected keyword argument: %.400s",
b18e03ba4817 Clarify error message for unexpected keyword parameter.
Guido van Rossum <guido@python.org>
parents: 5099
diff changeset
467 getstringvalue(keyword));
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
468 goto fail;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
469 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
470 mappinginsert(kwdict, keyword, value);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
471 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
472 else {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
473 if (GETLOCAL(j) != NULL) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
474 err_setstr(TypeError,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
475 "keyword parameter redefined");
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
476 goto fail;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
477 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
478 INCREF(value);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
479 SETLOCAL(j, value);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
480 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
481 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
482 if (argcount < co->co_argcount) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
483 int m = co->co_argcount - defcount;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
484 for (i = argcount; i < m; i++) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
485 if (GETLOCAL(i) == NULL) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
486 err_setstr(TypeError,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
487 "not enough arguments");
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
488 goto fail;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
489 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
490 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
491 if (n > m)
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
492 i = n - m;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
493 else
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
494 i = 0;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
495 for (; i < defcount; i++) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
496 if (GETLOCAL(m+i) == NULL) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
497 object *def = defs[i];
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
498 INCREF(def);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
499 SETLOCAL(m+i, def);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
500 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
501 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
502 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
503 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
504 else {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
505 if (argcount > 0 || kwcount > 0) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
506 err_setstr(TypeError, "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
507 goto fail;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
508 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
509 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
510
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
511 if (sys_trace != NULL) {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
512 /* sys_trace, if defined, is a function that will
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
513 be called on *every* entry to a code block.
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
514 Its return value, if not None, is a function that
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
515 will be called at the start of each executed line
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
516 of code. (Actually, the function must return
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
517 itself in order to continue tracing.)
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
518 The trace functions are called with three arguments:
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
519 a pointer to the current frame, a string indicating
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
520 why the function is called, and an argument which
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
521 depends on the situation. The global trace function
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
522 (sys.trace) is also called whenever an exception
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
523 is detected. */
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
524 if (call_trace(&sys_trace, &f->f_trace, f, "call",
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
525 None/*XXX how to compute arguments now?*/)) {
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
526 /* 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
527 goto fail;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
528 }
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
529 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
530
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
531 if (sys_profile != NULL) {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
532 /* Similar for sys_profile, except it needn't return
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
533 itself and isn't called for "line" events */
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
534 if (call_trace(&sys_profile, (object**)0, f, "call",
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
535 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
536 goto fail;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
537 }
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
538 }
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
539
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
540 if (++recursion_depth > MAX_RECURSION_DEPTH) {
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
541 --recursion_depth;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
542 err_setstr(RuntimeError, "Maximum recursion depth exceeded");
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
543 current_frame = f->f_back;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
544 DECREF(f);
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
545 return NULL;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
546 }
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
547
5052
7841c48cdb5b Two small changes:
Guido van Rossum <guido@python.org>
parents: 5050
diff changeset
548 next_instr = GETUSTRINGVALUE(co->co_code);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
549 stack_pointer = f->f_valuestack;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
550
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
551 why = WHY_NOT;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
552 err = 0;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
553 x = None; /* Not a reference, just anything non-NULL */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
554
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
555 for (;;) {
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
556 /* Do periodic things.
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
557 Doing this every time through the loop would add
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
558 too much overhead (a function call per instruction).
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
559 So we do it only every Nth instruction.
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
560
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
561 The ticker is reset to zero if there are pending
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
562 calls (see Py_AddPendingCall() and
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
563 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
564
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
565 if (--ticker < 0) {
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
566 ticker = sys_checkinterval;
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
567 if (pendingfirst != pendinglast) {
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
568 if (Py_MakePendingCalls() < 0) {
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
569 why = WHY_EXCEPTION;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
570 goto on_error;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
571 }
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
572 }
5048
fde73467b584 Change the control flow for error handling in the function prelude to
Guido van Rossum <guido@python.org>
parents: 5023
diff changeset
573 #ifdef macintosh
fde73467b584 Change the control flow for error handling in the function prelude to
Guido van Rossum <guido@python.org>
parents: 5023
diff changeset
574 #undef HAVE_SIGNAL_H
fde73467b584 Change the control flow for error handling in the function prelude to
Guido van Rossum <guido@python.org>
parents: 5023
diff changeset
575 #endif
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
576 #ifndef HAVE_SIGNAL_H /* Is this the right #define? */
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
577 /* If we have true signals, the signal handler will call
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
578 Py_AddPendingCall() so we don't have to call sigcheck().
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
579 On the Mac and DOS, alas, we have to call it. */
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
580 if (sigcheck()) {
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
581 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
582 goto on_error;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
583 }
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
584 #endif
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
585
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
586 #ifdef WITH_THREAD
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
587 if (interpreter_lock) {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
588 /* Give another thread a chance */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
589
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
590 current_frame = NULL;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
591 release_lock(interpreter_lock);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
592
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
593 /* Other threads may run now */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
594
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
595 acquire_lock(interpreter_lock, 1);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
596 current_frame = f;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
597 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
598 #endif
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
599 }
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
600
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
601 /* Extract opcode and argument */
1016
a41e3ba5b47d Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents: 974
diff changeset
602
4839
4567e158d20c Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents: 4667
diff changeset
603 #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
604 f->f_lasti = INSTR_OFFSET();
a41e3ba5b47d Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents: 974
diff changeset
605 #endif
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
606
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
607 opcode = NEXTOP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
608 if (HAS_ARG(opcode))
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
609 oparg = NEXTARG();
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
610 #ifdef DYNAMIC_EXECUTION_PROFILE
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
611 #ifdef DXPAIRS
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
612 dxpairs[lastopcode][opcode]++;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
613 lastopcode = opcode;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
614 #endif
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
615 dxp[opcode]++;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
616 #endif
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
617
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
618 #ifdef LLTRACE
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
619 /* Instruction tracing */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
620
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
621 if (lltrace) {
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
622 if (HAS_ARG(opcode)) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
623 printf("%d: %d, %d\n",
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
624 (int) (INSTR_OFFSET() - 3),
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
625 opcode, oparg);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
626 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
627 else {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
628 printf("%d: %d\n",
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
629 (int) (INSTR_OFFSET() - 1), opcode);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
630 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
631 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
632 #endif
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
633
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
634 /* Main switch on opcode */
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 switch (opcode) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
637
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
638 /* BEWARE!
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
639 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
640 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
641 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
642
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
643 /* 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
644
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
645 case POP_TOP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
646 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
647 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
648 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
649
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
650 case ROT_TWO:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
651 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
652 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
653 PUSH(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
654 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
655 continue;
173
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 case ROT_THREE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
658 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
659 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
660 x = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
661 PUSH(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
662 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
663 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
664 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
665
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
666 case DUP_TOP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
667 v = TOP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
668 INCREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
669 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
670 continue;
173
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 UNARY_POSITIVE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
673 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
674 x = pos(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
675 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
676 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
677 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
678 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
679
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
680 case UNARY_NEGATIVE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
681 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
682 x = neg(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
683 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
684 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
685 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
686 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
687
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
688 case UNARY_NOT:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
689 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
690 x = not(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
691 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
692 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
693 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
694 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
695
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
696 case UNARY_CONVERT:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
697 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
698 x = reprobject(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
699 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
700 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
701 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
702 break;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
703
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
704 case UNARY_INVERT:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
705 v = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
706 x = invert(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
707 DECREF(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
708 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
709 if (x != NULL) continue;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
710 break;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
711
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
712 case BINARY_POWER:
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
713 w = POP();
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
714 v = POP();
3694
581f073f071d Renamed static pow() to powerop() to avoid name conflict in some compilers.
Guido van Rossum <guido@python.org>
parents: 3610
diff changeset
715 x = powerop(v, w);
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
716 DECREF(v);
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
717 DECREF(w);
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
718 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
719 if (x != NULL) continue;
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
720 break;
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
721
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
722 case BINARY_MULTIPLY:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
723 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
724 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
725 x = mul(v, w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
726 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
727 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
728 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
729 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
730 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
731
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
732 case BINARY_DIVIDE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
733 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
734 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
735 x = divide(v, w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
736 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
737 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
738 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
739 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
740 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
741
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
742 case BINARY_MODULO:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
743 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
744 v = POP();
2088
1940e1e0cedf Use new instancebinop interface
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
745 x = mod(v, w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
746 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
747 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
748 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
749 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
750 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
751
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
752 case BINARY_ADD:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
753 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
754 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
755 x = add(v, w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
756 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
757 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
758 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
759 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
760 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
761
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
762 case BINARY_SUBTRACT:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
763 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
764 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
765 x = sub(v, w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
766 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
767 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
768 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
769 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
770 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
771
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
772 case BINARY_SUBSCR:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
773 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
774 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
775 x = apply_subscript(v, w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
776 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
777 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
778 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
779 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
780 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
781
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
782 case BINARY_LSHIFT:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
783 w = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
784 v = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
785 x = lshift(v, w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
786 DECREF(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
787 DECREF(w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
788 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
789 if (x != NULL) continue;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
790 break;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
791
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
792 case BINARY_RSHIFT:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
793 w = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
794 v = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
795 x = rshift(v, w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
796 DECREF(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
797 DECREF(w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
798 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
799 if (x != NULL) continue;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
800 break;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
801
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
802 case BINARY_AND:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
803 w = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
804 v = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
805 x = and(v, w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
806 DECREF(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
807 DECREF(w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
808 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
809 if (x != NULL) continue;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
810 break;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
811
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
812 case BINARY_XOR:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
813 w = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
814 v = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
815 x = xor(v, w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
816 DECREF(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
817 DECREF(w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
818 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
819 if (x != NULL) continue;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
820 break;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
821
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
822 case BINARY_OR:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
823 w = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
824 v = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
825 x = or(v, w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
826 DECREF(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
827 DECREF(w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
828 PUSH(x);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
829 if (x != NULL) continue;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
830 break;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
831
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
832 case SLICE+0:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
833 case SLICE+1:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
834 case SLICE+2:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
835 case SLICE+3:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
836 if ((opcode-SLICE) & 2)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
837 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
838 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
839 w = NULL;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
840 if ((opcode-SLICE) & 1)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
841 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
842 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
843 v = NULL;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
844 u = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
845 x = apply_slice(u, v, w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
846 DECREF(u);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
847 XDECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
848 XDECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
849 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
850 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
851 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
852
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
853 case STORE_SLICE+0:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
854 case STORE_SLICE+1:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
855 case STORE_SLICE+2:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
856 case STORE_SLICE+3:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
857 if ((opcode-STORE_SLICE) & 2)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
858 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
859 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
860 w = NULL;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
861 if ((opcode-STORE_SLICE) & 1)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
862 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
863 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
864 v = NULL;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
865 u = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
866 t = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
867 err = assign_slice(u, v, w, t); /* u[v:w] = t */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
868 DECREF(t);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
869 DECREF(u);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
870 XDECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
871 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
872 if (err == 0) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
873 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
874
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
875 case DELETE_SLICE+0:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
876 case DELETE_SLICE+1:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
877 case DELETE_SLICE+2:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
878 case DELETE_SLICE+3:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
879 if ((opcode-DELETE_SLICE) & 2)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
880 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
881 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
882 w = NULL;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
883 if ((opcode-DELETE_SLICE) & 1)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
884 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
885 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
886 v = NULL;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
887 u = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
888 err = assign_slice(u, v, w, (object *)NULL);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
889 /* del u[v:w] */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
890 DECREF(u);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
891 XDECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
892 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
893 if (err == 0) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
894 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
895
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
896 case STORE_SUBSCR:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
897 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
898 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
899 u = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
900 /* v[w] = u */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
901 err = assign_subscript(v, w, u);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
902 DECREF(u);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
903 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
904 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
905 if (err == 0) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
906 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
907
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
908 case DELETE_SUBSCR:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
909 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
910 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
911 /* del v[w] */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
912 err = assign_subscript(v, w, (object *)NULL);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
913 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
914 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
915 if (err == 0) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
916 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
917
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
918 case PRINT_EXPR:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
919 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
920 /* Print value except if procedure result */
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
921 /* Before printing, also assign to '_' */
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
922 if (v != None &&
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
923 (err = dictinsert(f->f_builtins, "_", v)) == 0 &&
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
924 !suppress_print) {
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
925 flushline();
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
926 x = sysget("stdout");
2151
5fd8524dd03a different init for __builtins__
Guido van Rossum <guido@python.org>
parents: 2128
diff changeset
927 err = writeobject(v, x, 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
928 softspace(x, 1);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
929 flushline();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
930 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
931 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
932 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
933
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
934 case PRINT_ITEM:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
935 v = POP();
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
936 w = sysget("stdout");
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
937 if (softspace(w, 1))
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
938 writestring(" ", w);
1400
aac8231a715c * mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents: 1391
diff changeset
939 err = writeobject(v, w, PRINT_RAW);
aac8231a715c * mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents: 1391
diff changeset
940 if (err == 0 && is_stringobject(v)) {
aac8231a715c * mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents: 1391
diff changeset
941 /* XXX move into writeobject() ? */
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
942 char *s = getstringvalue(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
943 int len = getstringsize(v);
2310
07913fb8f92f use Py_CHARMASK
Guido van Rossum <guido@python.org>
parents: 2295
diff changeset
944 if (len > 0 &&
07913fb8f92f use Py_CHARMASK
Guido van Rossum <guido@python.org>
parents: 2295
diff changeset
945 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
946 s[len-1] != ' ')
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
947 softspace(w, 0);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
948 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
949 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
950 if (err == 0) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
951 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
952
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
953 case PRINT_NEWLINE:
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
954 x = sysget("stdout");
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
955 if (x == NULL)
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
956 err_setstr(RuntimeError, "lost sys.stdout");
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
957 else {
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
958 writestring("\n", x);
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
959 softspace(x, 0);
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
960 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
961 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
962
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
963 case BREAK_LOOP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
964 why = WHY_BREAK;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
965 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
966
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
967 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
968 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
969 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
970 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
971 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
972 /* 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
973 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
974 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
975 /* 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
976 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
977 w = POP(); /* exc */
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
978 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
979 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
980 default:
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
981 err_setstr(SystemError,
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
982 "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
983 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
984 break;
464
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
985 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
986 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
987
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
988 case LOAD_LOCALS:
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
989 if ((x = f->f_locals) == NULL) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
990 err_setstr(SystemError, "no locals");
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
991 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
992 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
993 INCREF(x);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
994 PUSH(x);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
995 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
996
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
997 case RETURN_VALUE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
998 retval = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
999 why = WHY_RETURN;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1000 break;
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
1001
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
1002 case EXEC_STMT:
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
1003 w = POP();
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
1004 v = POP();
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
1005 u = POP();
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
1006 err = exec_statement(u, v, w);
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
1007 DECREF(u);
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
1008 DECREF(v);
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
1009 DECREF(w);
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
1010 break;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1011
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1012 case POP_BLOCK:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1013 {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1014 block *b = pop_block(f);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1015 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
1016 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1017 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1018 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1019 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1020 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1021
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1022 case END_FINALLY:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1023 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1024 if (is_intobject(v)) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1025 why = (enum why_code) getintvalue(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1026 if (why == WHY_RETURN)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1027 retval = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1028 }
2366
94bf2f05da31 fix bug in try-finally with class exceptions; declare different func pointers for different uses
Guido van Rossum <guido@python.org>
parents: 2338
diff changeset
1029 else if (is_stringobject(v) || is_classobject(v)) {
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1030 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
1031 u = POP();
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
1032 err_restore(v, w, u);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1033 why = WHY_RERAISE;
2872
d3b07ba3e12d fix bogus DECREF in finally clause
Guido van Rossum <guido@python.org>
parents: 2866
diff changeset
1034 break;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1035 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1036 else if (v != None) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1037 err_setstr(SystemError,
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1038 "'finally' pops bad exception");
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1039 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1040 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1041 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1042 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1043
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1044 case BUILD_CLASS:
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
1045 u = POP();
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1046 v = POP();
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
1047 w = POP();
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
1048 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
1049 PUSH(x);
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
1050 DECREF(u);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1051 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1052 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1053 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1054
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1055 case STORE_NAME:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1056 w = GETNAMEV(oparg);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1057 v = POP();
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1058 if ((x = f->f_locals) == NULL) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1059 err_setstr(SystemError, "no locals");
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1060 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1061 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1062 err = dict2insert(x, w, v);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1063 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1064 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1065
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1066 case DELETE_NAME:
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
1067 w = GETNAMEV(oparg);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1068 if ((x = f->f_locals) == NULL) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1069 err_setstr(SystemError, "no locals");
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1070 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1071 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1072 if ((err = dict2remove(x, w)) != 0)
1356
043da19302ef Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1354
diff changeset
1073 err_setval(NameError, w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1074 break;
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1075
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1076 #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
1077 default: switch (opcode) {
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1078 #endif
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1079
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1080 case UNPACK_TUPLE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1081 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1082 if (!is_tupleobject(v)) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1083 err_setstr(TypeError, "unpack non-tuple");
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1084 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1085 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1086 else if (gettuplesize(v) != oparg) {
464
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1087 err_setstr(ValueError,
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1088 "unpack tuple of wrong size");
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1089 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1090 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1091 else {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1092 for (; --oparg >= 0; ) {
2503
4dd1af0ddef0 various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents: 2366
diff changeset
1093 w = GETTUPLEITEM(v, oparg);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1094 INCREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1095 PUSH(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1096 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1097 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1098 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1099 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1100
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1101 case UNPACK_LIST:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1102 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1103 if (!is_listobject(v)) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1104 err_setstr(TypeError, "unpack non-list");
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1105 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1106 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1107 else if (getlistsize(v) != oparg) {
464
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1108 err_setstr(ValueError,
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1109 "unpack list of wrong size");
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1110 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1111 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1112 else {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1113 for (; --oparg >= 0; ) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1114 w = getlistitem(v, oparg);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1115 INCREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1116 PUSH(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1117 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1118 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1119 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1120 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1121
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1122 case STORE_ATTR:
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1123 w = GETNAMEV(oparg);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1124 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1125 u = POP();
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1126 err = setattro(v, w, u); /* v.w = u */
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1127 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1128 DECREF(u);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1129 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1130
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1131 case DELETE_ATTR:
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1132 w = GETNAMEV(oparg);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1133 v = POP();
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1134 err = setattro(v, w, (object *)NULL); /* del v.w */
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1135 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1136 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1137
464
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1138 case STORE_GLOBAL:
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1139 w = GETNAMEV(oparg);
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1140 v = POP();
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1141 err = dict2insert(f->f_globals, w, v);
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1142 DECREF(v);
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1143 break;
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1144
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1145 case DELETE_GLOBAL:
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1146 w = GETNAMEV(oparg);
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1147 if ((err = dict2remove(f->f_globals, w)) != 0)
1356
043da19302ef Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1354
diff changeset
1148 err_setval(NameError, w);
464
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1149 break;
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1150
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1151 case LOAD_CONST:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1152 x = GETCONST(oparg);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1153 INCREF(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1154 PUSH(x);
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 LOAD_NAME:
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
1158 w = GETNAMEV(oparg);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1159 if ((x = f->f_locals) == NULL) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1160 err_setstr(SystemError, "no locals");
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1161 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1162 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1163 x = dict2lookup(x, w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1164 if (x == NULL) {
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
1165 err_clear();
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
1166 x = dict2lookup(f->f_globals, w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1167 if (x == NULL) {
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
1168 err_clear();
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
1169 x = dict2lookup(f->f_builtins, w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1170 if (x == NULL) {
1356
043da19302ef Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1354
diff changeset
1171 err_setval(NameError, w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1172 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1173 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1174 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1175 }
5018
001a5042b181 Cleanup:
Guido van Rossum <guido@python.org>
parents: 5014
diff changeset
1176 INCREF(x);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1177 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1178 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1179
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1180 case LOAD_GLOBAL:
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
1181 w = GETNAMEV(oparg);
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
1182 x = dict2lookup(f->f_globals, w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1183 if (x == NULL) {
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
1184 err_clear();
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
1185 x = dict2lookup(f->f_builtins, w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1186 if (x == NULL) {
1356
043da19302ef Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1354
diff changeset
1187 err_setval(NameError, w);
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 }
5018
001a5042b181 Cleanup:
Guido van Rossum <guido@python.org>
parents: 5014
diff changeset
1191 INCREF(x);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1192 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1193 break;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1194
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1195 case LOAD_FAST:
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1196 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
1197 if (x == NULL) {
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
1198 err_setval(NameError,
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1199 gettupleitem(co->co_varnames,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1200 oparg));
1262
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1201 break;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1202 }
5018
001a5042b181 Cleanup:
Guido van Rossum <guido@python.org>
parents: 5014
diff changeset
1203 INCREF(x);
1262
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1204 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
1205 if (x != NULL) continue;
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1206 break;
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1207
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1208 case STORE_FAST:
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
1209 v = POP();
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1210 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
1211 continue;
1262
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1212
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1213 case DELETE_FAST:
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1214 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
1215 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1216
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1217 case BUILD_TUPLE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1218 x = newtupleobject(oparg);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1219 if (x != NULL) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1220 for (; --oparg >= 0;) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1221 w = POP();
2503
4dd1af0ddef0 various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents: 2366
diff changeset
1222 SETTUPLEITEM(x, oparg, w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1223 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1224 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
1225 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1226 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1227 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1228
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1229 case BUILD_LIST:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1230 x = newlistobject(oparg);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1231 if (x != NULL) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1232 for (; --oparg >= 0;) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1233 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1234 err = setlistitem(x, oparg, w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1235 if (err != 0)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1236 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1237 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1238 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
1239 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1240 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1241 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1242
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1243 case BUILD_MAP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1244 x = newdictobject();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1245 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
1246 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1247 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1248
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1249 case LOAD_ATTR:
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1250 w = GETNAMEV(oparg);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1251 v = POP();
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1252 x = getattro(v, w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1253 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1254 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
1255 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1256 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1257
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1258 case COMPARE_OP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1259 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1260 v = POP();
802
3d6541a2eca5 Arg of cmp_outcome becomes an int for portability to the Mac
Guido van Rossum <guido@python.org>
parents: 789
diff changeset
1261 x = cmp_outcome(oparg, v, w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1262 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1263 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1264 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
1265 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1266 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1267
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1268 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
1269 w = GETNAMEV(oparg);
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
1270 x = dictlookup(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
1271 if (x == NULL) {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1272 err_setstr(ImportError,
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1273 "__import__ not found");
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1274 break;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1275 }
2338
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
1276 if (is_methodobject(x)) {
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
1277 u = None;
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
1278 INCREF(u);
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
1279 }
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
1280 else {
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
1281 u = find_from_args(f, INSTR_OFFSET());
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
1282 if (u == NULL) {
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
1283 x = u;
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
1284 break;
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
1285 }
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
1286 }
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1287 w = mkvalue("(OOOO)",
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1288 w,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1289 f->f_globals,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1290 f->f_locals == NULL ? None : f->f_locals,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1291 u);
2338
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
1292 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
1293 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
1294 x = NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1295 break;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1296 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1297 x = call_object(x, w);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1298 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
1299 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
1300 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1301 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1302
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1303 case IMPORT_FROM:
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
1304 w = GETNAMEV(oparg);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1305 v = TOP();
2338
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
1306 fast_2_locals(f);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1307 if ((x = f->f_locals) == NULL) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1308 err_setstr(SystemError, "no locals");
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1309 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1310 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1311 err = import_from(x, v, w);
1262
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1312 locals_2_fast(f, 0);
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1313 if (err == 0) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1314 break;
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
1315
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1316 case JUMP_FORWARD:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1317 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
1318 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1319
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1320 case JUMP_IF_FALSE:
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1321 err = testbool(TOP());
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1322 if (err > 0)
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1323 err = 0;
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1324 else if (err == 0)
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1325 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
1326 else
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1327 break;
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1328 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1329
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1330 case JUMP_IF_TRUE:
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1331 err = testbool(TOP());
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1332 if (err > 0) {
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1333 err = 0;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1334 JUMPBY(oparg);
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1335 }
5002
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1336 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
1337 ;
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1338 else
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1339 break;
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1340 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1341
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1342 case JUMP_ABSOLUTE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1343 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
1344 continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1345
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1346 case FOR_LOOP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1347 /* for v in s: ...
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1348 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
1349 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
1350 but if loop exhausted:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1351 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
1352 w = POP(); /* Loop index */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1353 v = POP(); /* Sequence object */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1354 u = loop_subscript(v, w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1355 if (u != NULL) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1356 PUSH(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1357 x = newintobject(getintvalue(w)+1);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1358 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1359 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1360 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
1361 if (x != NULL) continue;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1362 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1363 else {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1364 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1365 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1366 /* 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
1367 but also an error: */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1368 if (err_occurred())
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1369 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
1370 else {
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1371 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
1372 continue;
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1373 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1374 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1375 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1376
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1377 case SETUP_LOOP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1378 case SETUP_EXCEPT:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1379 case SETUP_FINALLY:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1380 setup_block(f, opcode, INSTR_OFFSET() + oparg,
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1381 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
1382 continue;
173
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 SET_LINENO:
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1385 #ifdef LLTRACE
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1386 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
1387 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
1388 #endif
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1389 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
1390 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
1391 continue;
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1392 /* 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
1393 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
1394 err = call_trace(&f->f_trace, &f->f_trace,
ae3b46a73765 Add "if (x != NULL) continue;" (or similar for err==0) before the
Guido van Rossum <guido@python.org>
parents: 4992
diff changeset
1395 f, "line", None);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1396 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
1397
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
1398 case CALL_FUNCTION:
999b5bdc18ce 3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents: 2612
diff changeset
1399 {
999b5bdc18ce 3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents: 2612
diff changeset
1400 int na = oparg & 0xff;
999b5bdc18ce 3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents: 2612
diff changeset
1401 int nk = (oparg>>8) & 0xff;
999b5bdc18ce 3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents: 2612
diff changeset
1402 int n = na + 2*nk;
999b5bdc18ce 3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents: 2612
diff changeset
1403 object **pfunc = stack_pointer - n - 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
1404 object *func = *pfunc;
999b5bdc18ce 3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents: 2612
diff changeset
1405 object *self = 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
1406 object *class = 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
1407 f->f_lasti = INSTR_OFFSET() - 3; /* For tracing */
999b5bdc18ce 3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents: 2612
diff changeset
1408 if (is_instancemethodobject(func)) {
999b5bdc18ce 3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents: 2612
diff changeset
1409 self = instancemethodgetself(func);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1410 class = instancemethodgetclass(func);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1411 func = instancemethodgetfunc(func);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1412 INCREF(func);
2813
999b5bdc18ce 3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents: 2612
diff changeset
1413 if (self != 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
1414 INCREF(self);
999b5bdc18ce 3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents: 2612
diff changeset
1415 DECREF(*pfunc);
999b5bdc18ce 3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents: 2612
diff changeset
1416 *pfunc = self;
999b5bdc18ce 3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents: 2612
diff changeset
1417 na++;
999b5bdc18ce 3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents: 2612
diff changeset
1418 n++;
999b5bdc18ce 3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents: 2612
diff changeset
1419 }
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1420 else {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1421 /* Unbound methods must be
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1422 called with an instance of
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1423 the class (or a derived
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1424 class) as first argument */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1425 if (na > 0 &&
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1426 (self = stack_pointer[-n])
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1427 != NULL &&
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1428 is_instanceobject(self) &&
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1429 issubclass(
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1430 (object *)
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1431 (((instanceobject *)self)
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1432 ->in_class),
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1433 class))
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1434 /* Handy-dandy */ ;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1435 else {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1436 err_setstr(TypeError,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1437 "unbound method must be called with class instance 1st argument");
3294
2bddfb3cfcf1 don't return from main loop when error occurs
Guido van Rossum <guido@python.org>
parents: 3099
diff changeset
1438 x = NULL;
2bddfb3cfcf1 don't return from main loop when error occurs
Guido van Rossum <guido@python.org>
parents: 3099
diff changeset
1439 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
1440 }
999b5bdc18ce 3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents: 2612
diff changeset
1441 }
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1442 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1443 else
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1444 INCREF(func);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1445 if (is_funcobject(func)) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1446 object *co = getfunccode(func);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1447 object *globals = getfuncglobals(func);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1448 object *argdefs = PyFunction_GetDefaults(func);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1449 object **d;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1450 int nd;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1451 if (argdefs != NULL) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1452 d = &GETTUPLEITEM(argdefs, 0);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1453 nd = ((tupleobject *)argdefs)->ob_size;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1454 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1455 else {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1456 d = NULL;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1457 nd = 0;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1458 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1459 x = eval_code2(
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1460 (codeobject *)co,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1461 globals, (object *)NULL,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1462 stack_pointer-n, na,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1463 stack_pointer-2*nk, nk,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1464 d, nd,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1465 class);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1466 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1467 else {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1468 object *args = newtupleobject(na);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1469 object *kwdict = NULL;
2866
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1470 if (args == NULL) {
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1471 x = NULL;
2866
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1472 break;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1473 }
2866
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1474 if (nk > 0) {
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1475 kwdict = newdictobject();
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1476 if (kwdict == NULL) {
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1477 x = NULL;
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1478 break;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1479 }
2866
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1480 err = 0;
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1481 while (--nk >= 0) {
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1482 object *value = POP();
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1483 object *key = POP();
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1484 err = mappinginsert(
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1485 kwdict, key, value);
5050
8579e3441d9b Plug a leak with calling something other than a function or method is
Guido van Rossum <guido@python.org>
parents: 5049
diff changeset
1486 DECREF(key);
8579e3441d9b Plug a leak with calling something other than a function or method is
Guido van Rossum <guido@python.org>
parents: 5049
diff changeset
1487 DECREF(value);
8579e3441d9b Plug a leak with calling something other than a function or method is
Guido van Rossum <guido@python.org>
parents: 5049
diff changeset
1488 if (err)
2866
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1489 break;
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1490 }
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1491 if (err) {
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1492 DECREF(args);
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1493 DECREF(kwdict);
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1494 break;
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1495 }
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1496 }
2866
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1497 while (--na >= 0) {
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1498 w = POP();
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1499 SETTUPLEITEM(args, na, w);
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1500 }
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1501 x = PyEval_CallObjectWithKeywords(
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1502 func, args, kwdict);
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1503 DECREF(args);
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1504 XDECREF(kwdict);
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
1505 }
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
1506 DECREF(func);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1507 while (stack_pointer > pfunc) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1508 w = POP();
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1509 DECREF(w);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1510 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1511 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
1512 if (x != NULL) continue;
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
1513 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
1514 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1515
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1516 case MAKE_FUNCTION:
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1517 v = POP(); /* code object */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1518 x = newfuncobject(v, f->f_globals);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1519 DECREF(v);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1520 /* XXX Maybe this should be a separate opcode? */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1521 if (x != NULL && oparg > 0) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1522 v = newtupleobject(oparg);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1523 if (v == NULL) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1524 DECREF(x);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1525 x = NULL;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1526 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1527 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1528 while (--oparg >= 0) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1529 w = POP();
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1530 SETTUPLEITEM(v, oparg, w);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1531 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1532 err = PyFunction_SetDefaults(x, v);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1533 DECREF(v);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1534 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1535 PUSH(x);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1536 break;
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
1537
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
1538 case BUILD_SLICE:
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
1539 if (oparg == 3)
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
1540 w = POP();
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
1541 else
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
1542 w = NULL;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
1543 v = POP();
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
1544 u = POP();
5018
001a5042b181 Cleanup:
Guido van Rossum <guido@python.org>
parents: 5014
diff changeset
1545 x = PySlice_New(u, v, w);
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
1546 DECREF(u);
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
1547 DECREF(v);
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
1548 XDECREF(w);
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
1549 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
1550 if (x != NULL) continue;
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
1551 break;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
1552
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3694
diff changeset
1553
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1554 default:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1555 fprintf(stderr,
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1556 "XXX lineno: %d, opcode: %d\n",
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1557 f->f_lineno, opcode);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1558 err_setstr(SystemError, "unknown opcode");
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1559 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1560 break;
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1561
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1562 #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
1563 }
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1564 #endif
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1565
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1566 } /* switch */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1567
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1568 on_error:
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 /* 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
1571
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1572 if (why == WHY_NOT) {
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1573 if (err == 0 && x != NULL) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1574 #ifdef CHECKEXC
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1575 if (err_occurred())
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1576 fprintf(stderr,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1577 "XXX undetected error\n");
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1578 else
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1579 #endif
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1580 continue; /* Normal, fast path */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1581 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1582 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1583 x = None;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1584 err = 0;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1585 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1586
814
f08d34499269 reverse sense of test for CHECKEXC
Guido van Rossum <guido@python.org>
parents: 802
diff changeset
1587 #ifdef CHECKEXC
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1588 /* Double-check exception status */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1589
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1590 if (why == WHY_EXCEPTION || why == WHY_RERAISE) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1591 if (!err_occurred()) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1592 fprintf(stderr, "XXX ghost error\n");
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1593 err_setstr(SystemError, "ghost error");
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1594 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1595 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1596 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1597 else {
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1598 if (err_occurred()) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1599 fprintf(stderr,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1600 "XXX undetected error (why=%d)\n",
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1601 why);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1602 why = WHY_EXCEPTION;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
1603 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1604 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1605 #endif
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1606
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1607 /* 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
1608
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1609 if (why == WHY_EXCEPTION) {
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1610 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
1611 if (HAS_ARG(opcode))
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1612 f->f_lasti -= 2;
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1613 tb_here(f);
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1614
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
1615 if (f->f_trace)
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
1616 call_exc_trace(&f->f_trace, &f->f_trace, f);
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1617 if (sys_profile)
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1618 call_exc_trace(&sys_profile, (object**)0, f);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1619 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1620
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1621 /* 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
1622
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1623 if (why == WHY_RERAISE)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1624 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1625
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1626 /* 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
1627
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1628 while (why != WHY_NOT && f->f_iblock > 0) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1629 block *b = pop_block(f);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1630 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
1631 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1632 XDECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1633 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1634 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
1635 why = WHY_NOT;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1636 JUMPTO(b->b_handler);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1637 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1638 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1639 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
1640 (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
1641 why == WHY_EXCEPTION)) {
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1642 if (why == WHY_EXCEPTION) {
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1643 object *exc, *val, *tb;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1644 err_fetch(&exc, &val, &tb);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1645 if (val == NULL) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1646 val = None;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1647 INCREF(val);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1648 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1649 /* Make the raw exception data
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1650 available to the handler,
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1651 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
1652 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
1653 this for 'finally'. */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1654 if (b->b_type == SETUP_EXCEPT) {
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1655 sysset("exc_traceback", tb);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1656 sysset("exc_value", val);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1657 sysset("exc_type", exc);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1658 }
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1659 PUSH(tb);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1660 PUSH(val);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1661 PUSH(exc);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1662 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1663 else {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1664 if (why == WHY_RETURN)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1665 PUSH(retval);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1666 v = newintobject((long)why);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1667 PUSH(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1668 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1669 why = WHY_NOT;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1670 JUMPTO(b->b_handler);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1671 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1672 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1673 } /* unwind stack */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1674
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1675 /* 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
1676
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1677 if (why != WHY_NOT)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1678 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1679
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1680 } /* main loop */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1681
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1682 /* Pop remaining stack entries */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1683
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1684 while (!EMPTY()) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1685 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1686 XDECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1687 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1688
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1689 if (why != WHY_RETURN)
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1690 retval = NULL;
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1691
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
1692 if (f->f_trace) {
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1693 if (why == WHY_RETURN) {
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
1694 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
1695 "return", retval)) {
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1696 XDECREF(retval);
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1697 retval = NULL;
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1698 why = WHY_EXCEPTION;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1699 }
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1700 }
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1701 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1702
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1703 if (sys_profile && why == WHY_RETURN) {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1704 if (call_trace(&sys_profile, (object**)0,
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1705 f, "return", retval)) {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1706 XDECREF(retval);
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1707 retval = NULL;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1708 why = WHY_EXCEPTION;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1709 }
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1710 }
5023
75c1ee882a4a Kill all local variables on function return. This closes a gigantic
Guido van Rossum <guido@python.org>
parents: 5021
diff changeset
1711
5048
fde73467b584 Change the control flow for error handling in the function prelude to
Guido van Rossum <guido@python.org>
parents: 5023
diff changeset
1712 --recursion_depth;
fde73467b584 Change the control flow for error handling in the function prelude to
Guido van Rossum <guido@python.org>
parents: 5023
diff changeset
1713
fde73467b584 Change the control flow for error handling in the function prelude to
Guido van Rossum <guido@python.org>
parents: 5023
diff changeset
1714 fail: /* Jump here from prelude on failure */
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1715
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1716 /* 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
1717
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1718 current_frame = f->f_back;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1719 DECREF(f);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1720
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1721 return retval;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1722 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1723
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
1724 /* 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
1725 This *consumes* a reference count to each of its arguments. */
5018
001a5042b181 Cleanup:
Guido van Rossum <guido@python.org>
parents: 5014
diff changeset
1726 static enum why_code
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
1727 do_raise(type, value, tb)
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1728 object *type, *value, *tb;
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1729 {
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1730 /* 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
1731 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
1732 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
1733 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
1734 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
1735 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
1736 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
1737 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
1738
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1739 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
1740
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1741 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
1742 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
1743 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
1744
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1745 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
1746 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
1747 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
1748
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1749 /* 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
1750 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
1751 if (tb == 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
1752 DECREF(tb);
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1753 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
1754 }
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1755 else if (tb != NULL && !PyTraceBack_Check(tb)) {
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1756 err_setstr(TypeError,
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1757 "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
1758 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
1759 }
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1760
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1761 /* 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
1762 if (value == 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
1763 value = 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
1764 INCREF(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
1765 }
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1766
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1767 /* Next, repeatedly, replace a tuple exception with its first item */
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1768 while (is_tupleobject(type) && gettuplesize(type) > 0) {
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1769 object *tmp = type;
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1770 type = GETTUPLEITEM(type, 0);
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1771 INCREF(type);
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1772 DECREF(tmp);
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1773 }
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1774
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1775 /* Now switch on the exception's type */
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1776 if (is_stringobject(type)) {
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1777 ;
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1778 }
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1779 else if (is_classobject(type)) {
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1780 /* Raising a class. If the value is an instance, 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
1781 better be an instance of the class. If it is not,
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1782 it will be used to create an instance. */
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1783 if (is_instanceobject(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
1784 object *inclass = (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
1785 (((instanceobject*)value)->in_class);
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1786 if (!issubclass(inclass, type)) {
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1787 err_setstr(TypeError,
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1788 "raise <class>, <instance> requires that <instance> is a member of <class>");
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1789 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
1790 }
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1791 }
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1792 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
1793 /* Go instantiate the class */
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1794 object *args, *res;
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1795 if (value == 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
1796 args = mkvalue("()");
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1797 else if (is_tupleobject(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
1798 INCREF(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
1799 args = 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
1800 }
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1801 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
1802 args = mkvalue("(O)", 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
1803 if (args == 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
1804 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
1805 res = call_object(type, args);
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1806 DECREF(args);
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1807 if (res == 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
1808 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
1809 DECREF(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
1810 value = res;
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1811 }
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1812 }
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1813 else if (is_instanceobject(type)) {
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1814 /* Raising an instance. The value should be a dummy. */
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1815 if (value != 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
1816 err_setstr(TypeError,
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1817 "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
1818 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
1819 }
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1820 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
1821 /* Normalize to raise <class>, <instance> */
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1822 DECREF(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
1823 value = type;
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1824 type = (object*) ((instanceobject*)type)->in_class;
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1825 INCREF(type);
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1826 }
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1827 }
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1828 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
1829 /* 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
1830 anyway, just not what you specified :-) */
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1831 err_setstr(TypeError,
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1832 "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
1833 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
1834 }
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1835 err_restore(type, value, tb);
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1836 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
1837 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
1838 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
1839 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
1840 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
1841 XDECREF(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
1842 XDECREF(type);
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1843 XDECREF(tb);
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1844 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
1845 }
c42379e4653b Moved the raise logic out of the main interpreter loop to a separate function.
Guido van Rossum <guido@python.org>
parents: 4594
diff changeset
1846
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1847 #ifdef LLTRACE
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1848 static int
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1849 prtrace(v, str)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1850 object *v;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1851 char *str;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1852 {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1853 printf("%s ", str);
284
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 260
diff changeset
1854 if (printobject(v, stdout, 0) != 0)
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 260
diff changeset
1855 err_clear(); /* Don't know what else to do */
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1856 printf("\n");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1857 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1858 #endif
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1859
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1860 static void
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1861 call_exc_trace(p_trace, p_newtrace, f)
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1862 object **p_trace, **p_newtrace;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1863 frameobject *f;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1864 {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1865 object *type, *value, *traceback, *arg;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1866 int err;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1867 err_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
1868 if (value == NULL) {
6508c93f9472 Test for NULL coming out of err_get() in call_exc_trace()
Guido van Rossum <guido@python.org>
parents: 814
diff changeset
1869 value = None;
6508c93f9472 Test for NULL coming out of err_get() in call_exc_trace()
Guido van Rossum <guido@python.org>
parents: 814
diff changeset
1870 INCREF(value);
6508c93f9472 Test for NULL coming out of err_get() in call_exc_trace()
Guido van Rossum <guido@python.org>
parents: 814
diff changeset
1871 }
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1872 arg = mkvalue("(OOO)", type, value, traceback);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1873 if (arg == NULL) {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1874 err_restore(type, value, traceback);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1875 return;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1876 }
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1877 err = call_trace(p_trace, p_newtrace, f, "exception", arg);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1878 DECREF(arg);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1879 if (err == 0)
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1880 err_restore(type, value, traceback);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1881 else {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1882 XDECREF(type);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1883 XDECREF(value);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
1884 XDECREF(traceback);
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1885 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1886 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1887
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1888 static int
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1889 call_trace(p_trace, p_newtrace, f, msg, arg)
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1890 object **p_trace; /* in/out; may not be NULL;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1891 may not point to NULL variable initially */
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1892 object **p_newtrace; /* in/out; may be NULL;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1893 may point to NULL variable;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1894 may be same variable as p_newtrace */
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1895 frameobject *f;
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1896 char *msg;
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1897 object *arg;
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1898 {
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
1899 object *args, *what;
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1900 object *res = NULL;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1901 static int tracing = 0;
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1902
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1903 if (tracing) {
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1904 /* 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
1905 if (p_newtrace) {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1906 XDECREF(*p_newtrace);
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1907 *p_newtrace = NULL;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1908 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1909 return 0;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1910 }
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1911
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
1912 args = newtupleobject(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
1913 if (args == NULL)
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1914 goto cleanup;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1915 what = newstringobject(msg);
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1916 if (what == NULL)
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1917 goto cleanup;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1918 INCREF(f);
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
1919 SETTUPLEITEM(args, 0, (object *)f);
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
1920 SETTUPLEITEM(args, 1, what);
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1921 if (arg == NULL)
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1922 arg = None;
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1923 INCREF(arg);
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
1924 SETTUPLEITEM(args, 2, arg);
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1925 tracing++;
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1926 fast_2_locals(f);
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
1927 res = call_object(*p_trace, args); /* May clear *p_trace! */
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1928 locals_2_fast(f, 1);
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1929 tracing--;
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1930 cleanup:
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
1931 XDECREF(args);
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1932 if (res == NULL) {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1933 /* The trace proc raised an exception */
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1934 tb_here(f);
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
1935 XDECREF(*p_trace);
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1936 *p_trace = NULL;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1937 if (p_newtrace) {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1938 XDECREF(*p_newtrace);
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1939 *p_newtrace = NULL;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1940 }
789
f565cf7f9aba (Hopefully) fix bug in reference count in call_exc_trace()
Guido van Rossum <guido@python.org>
parents: 746
diff changeset
1941 return -1;
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1942 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1943 else {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1944 if (p_newtrace) {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1945 XDECREF(*p_newtrace);
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1946 if (res == None)
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1947 *p_newtrace = NULL;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1948 else {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1949 INCREF(res);
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1950 *p_newtrace = res;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1951 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1952 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1953 DECREF(res);
789
f565cf7f9aba (Hopefully) fix bug in reference count in call_exc_trace()
Guido van Rossum <guido@python.org>
parents: 746
diff changeset
1954 return 0;
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1955 }
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1956 }
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1957
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1958 object *
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
1959 getbuiltins()
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
1960 {
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
1961 if (current_frame == NULL)
2151
5fd8524dd03a different init for __builtins__
Guido van Rossum <guido@python.org>
parents: 2128
diff changeset
1962 return getbuiltinmod();
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
1963 else
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
1964 return current_frame->f_builtins;
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
1965 }
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
1966
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
1967 object *
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1968 getlocals()
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1969 {
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1970 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
1971 return NULL;
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1972 fast_2_locals(current_frame);
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1973 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
1974 }
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1975
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1976 object *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1977 getglobals()
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1978 {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1979 if (current_frame == NULL)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1980 return NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1981 else
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1982 return current_frame->f_globals;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1983 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1984
1289
4d292c7857d4 Access checks now work, at least for instance data (not for methods
Guido van Rossum <guido@python.org>
parents: 1288
diff changeset
1985 object *
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
1986 getframe()
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
1987 {
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
1988 return (object *)current_frame;
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
1989 }
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
1990
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
1991 int
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
1992 getrestricted()
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
1993 {
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
1994 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
1995 }
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
1996
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1997 void
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1998 flushline()
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1999 {
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
2000 object *f = sysget("stdout");
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
2001 if (softspace(f, 0))
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
2002 writestring("\n", f);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2003 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2004
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2005
2088
1940e1e0cedf Use new instancebinop interface
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
2006 #define BINOP(opname, ropname, thisfunc) \
1940e1e0cedf Use new instancebinop interface
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
2007 if (!is_instanceobject(v) && !is_instanceobject(w)) \
1940e1e0cedf Use new instancebinop interface
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
2008 ; \
1940e1e0cedf Use new instancebinop interface
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
2009 else \
1940e1e0cedf Use new instancebinop interface
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
2010 return instancebinop(v, w, opname, ropname, thisfunc)
1914
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
2011
893412101296 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents: 1887
diff changeset
2012
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2013 static object *
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2014 or(v, w)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2015 object *v, *w;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2016 {
2088
1940e1e0cedf Use new instancebinop interface
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
2017 BINOP("__or__", "__ror__", or);
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2018 if (v->ob_type->tp_as_number != NULL) {
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
2019 object *x = NULL;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2020 object * (*f) FPROTO((object *, object *));
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2021 if (coerce(&v, &w) != 0)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2022 return NULL;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2023 if ((f = v->ob_type->tp_as_number->nb_or) != NULL)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2024 x = (*f)(v, w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2025 DECREF(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2026 DECREF(w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2027 if (f != NULL)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2028 return x;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2029 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2030 err_setstr(TypeError, "bad operand type(s) for |");
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2031 return NULL;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2032 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2033
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2034 static object *
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2035 xor(v, w)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2036 object *v, *w;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2037 {
2088
1940e1e0cedf Use new instancebinop interface
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
2038 BINOP("__xor__", "__rxor__", xor);
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2039 if (v->ob_type->tp_as_number != NULL) {
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
2040 object *x = NULL;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2041 object * (*f) FPROTO((object *, object *));
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2042 if (coerce(&v, &w) != 0)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2043 return NULL;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2044 if ((f = v->ob_type->tp_as_number->nb_xor) != NULL)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2045 x = (*f)(v, w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2046 DECREF(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2047 DECREF(w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2048 if (f != NULL)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2049 return x;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2050 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2051 err_setstr(TypeError, "bad operand type(s) for ^");
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2052 return NULL;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2053 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2054
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2055 static object *
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2056 and(v, w)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2057 object *v, *w;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2058 {
2088
1940e1e0cedf Use new instancebinop interface
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
2059 BINOP("__and__", "__rand__", and);
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2060 if (v->ob_type->tp_as_number != NULL) {
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
2061 object *x = NULL;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2062 object * (*f) FPROTO((object *, object *));
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2063 if (coerce(&v, &w) != 0)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2064 return NULL;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2065 if ((f = v->ob_type->tp_as_number->nb_and) != NULL)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2066 x = (*f)(v, w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2067 DECREF(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2068 DECREF(w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2069 if (f != NULL)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2070 return x;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2071 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2072 err_setstr(TypeError, "bad operand type(s) for &");
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2073 return NULL;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2074 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2075
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2076 static object *
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2077 lshift(v, w)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2078 object *v, *w;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2079 {
2088
1940e1e0cedf Use new instancebinop interface
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
2080 BINOP("__lshift__", "__rlshift__", lshift);
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2081 if (v->ob_type->tp_as_number != NULL) {
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
2082 object *x = NULL;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2083 object * (*f) FPROTO((object *, object *));
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2084 if (coerce(&v, &w) != 0)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2085 return NULL;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2086 if ((f = v->ob_type->tp_as_number->nb_lshift) != NULL)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2087 x = (*f)(v, w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2088 DECREF(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2089 DECREF(w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2090 if (f != NULL)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2091 return x;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2092 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2093 err_setstr(TypeError, "bad operand type(s) for <<");
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2094 return NULL;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2095 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2096
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2097 static object *
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2098 rshift(v, w)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2099 object *v, *w;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2100 {
2088
1940e1e0cedf Use new instancebinop interface
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
2101 BINOP("__rshift__", "__rrshift__", rshift);
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2102 if (v->ob_type->tp_as_number != NULL) {
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
2103 object *x = NULL;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2104 object * (*f) FPROTO((object *, object *));
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2105 if (coerce(&v, &w) != 0)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2106 return NULL;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2107 if ((f = v->ob_type->tp_as_number->nb_rshift) != NULL)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2108 x = (*f)(v, w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2109 DECREF(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2110 DECREF(w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2111 if (f != NULL)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2112 return x;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2113 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2114 err_setstr(TypeError, "bad operand type(s) for >>");
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2115 return NULL;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2116 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2117
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2118 static object *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2119 add(v, w)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2120 object *v, *w;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2121 {
2088
1940e1e0cedf Use new instancebinop interface
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
2122 BINOP("__add__", "__radd__", add);
955
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
2123 if (v->ob_type->tp_as_sequence != NULL)
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
2124 return (*v->ob_type->tp_as_sequence->sq_concat)(v, w);
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
2125 else if (v->ob_type->tp_as_number != NULL) {
302
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2126 object *x;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2127 if (coerce(&v, &w) != 0)
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2128 return NULL;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2129 x = (*v->ob_type->tp_as_number->nb_add)(v, w);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2130 DECREF(v);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2131 DECREF(w);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2132 return x;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2133 }
1198
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1181
diff changeset
2134 err_setstr(TypeError, "bad operand type(s) for +");
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1181
diff changeset
2135 return NULL;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2136 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2137
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2138 static object *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2139 sub(v, w)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2140 object *v, *w;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2141 {
2088
1940e1e0cedf Use new instancebinop interface
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
2142 BINOP("__sub__", "__rsub__", sub);
302
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2143 if (v->ob_type->tp_as_number != NULL) {
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2144 object *x;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2145 if (coerce(&v, &w) != 0)
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2146 return NULL;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2147 x = (*v->ob_type->tp_as_number->nb_subtract)(v, w);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2148 DECREF(v);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2149 DECREF(w);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2150 return x;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2151 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2152 err_setstr(TypeError, "bad operand type(s) for -");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2153 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2154 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2155
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2156 static object *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2157 mul(v, w)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2158 object *v, *w;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2159 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2160 typeobject *tp;
955
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
2161 tp = v->ob_type;
2088
1940e1e0cedf Use new instancebinop interface
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
2162 BINOP("__mul__", "__rmul__", mul);
955
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
2163 if (tp->tp_as_number != NULL &&
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
2164 w->ob_type->tp_as_sequence != NULL &&
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
2165 !is_instanceobject(v)) {
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
2166 /* number*sequence -- swap v and w */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2167 object *tmp = v;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2168 v = w;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2169 w = tmp;
955
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
2170 tp = v->ob_type;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2171 }
302
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2172 if (tp->tp_as_number != NULL) {
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2173 object *x;
955
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
2174 if (is_instanceobject(v)) {
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
2175 /* Instances of user-defined classes get their
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
2176 other argument uncoerced, so they may
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
2177 implement sequence*number as well as
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
2178 number*number. */
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
2179 INCREF(v);
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
2180 INCREF(w);
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
2181 }
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
2182 else if (coerce(&v, &w) != 0)
302
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2183 return NULL;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2184 x = (*v->ob_type->tp_as_number->nb_multiply)(v, w);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2185 DECREF(v);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2186 DECREF(w);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2187 return x;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2188 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2189 if (tp->tp_as_sequence != NULL) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2190 if (!is_intobject(w)) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2191 err_setstr(TypeError,
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2192 "can't multiply sequence with non-int");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2193 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2194 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2195 return (*tp->tp_as_sequence->sq_repeat)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2196 (v, (int)getintvalue(w));
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2197 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2198 err_setstr(TypeError, "bad operand type(s) for *");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2199 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2200 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2201
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2202 static object *
88
16e8c5d16493 Change div() into divide(); div() is a Standard C function.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
2203 divide(v, w)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2204 object *v, *w;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2205 {
2088
1940e1e0cedf Use new instancebinop interface
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
2206 BINOP("__div__", "__rdiv__", divide);
302
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2207 if (v->ob_type->tp_as_number != NULL) {
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2208 object *x;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2209 if (coerce(&v, &w) != 0)
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2210 return NULL;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2211 x = (*v->ob_type->tp_as_number->nb_divide)(v, w);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2212 DECREF(v);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2213 DECREF(w);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2214 return x;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2215 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2216 err_setstr(TypeError, "bad operand type(s) for /");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2217 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2218 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2219
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2220 static object *
2088
1940e1e0cedf Use new instancebinop interface
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
2221 mod(v, w)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2222 object *v, *w;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2223 {
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
2224 if (is_stringobject(v)) {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
2225 return formatstring(v, w);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
2226 }
2088
1940e1e0cedf Use new instancebinop interface
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
2227 BINOP("__mod__", "__rmod__", mod);
302
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2228 if (v->ob_type->tp_as_number != NULL) {
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2229 object *x;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2230 if (coerce(&v, &w) != 0)
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2231 return NULL;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2232 x = (*v->ob_type->tp_as_number->nb_remainder)(v, w);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2233 DECREF(v);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2234 DECREF(w);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2235 return x;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2236 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2237 err_setstr(TypeError, "bad operand type(s) for %");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2238 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2239 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2240
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2241 static object *
3694
581f073f071d Renamed static pow() to powerop() to avoid name conflict in some compilers.
Guido van Rossum <guido@python.org>
parents: 3610
diff changeset
2242 powerop(v, w)
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
2243 object *v, *w;
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
2244 {
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
2245 object *res;
3694
581f073f071d Renamed static pow() to powerop() to avoid name conflict in some compilers.
Guido van Rossum <guido@python.org>
parents: 3610
diff changeset
2246 BINOP("__pow__", "__rpow__", powerop);
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
2247 if (v->ob_type->tp_as_number == NULL ||
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
2248 w->ob_type->tp_as_number == NULL) {
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
2249 err_setstr(TypeError, "pow() requires numeric arguments");
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
2250 return NULL;
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
2251 }
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
2252 if (coerce(&v, &w) != 0)
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
2253 return NULL;
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
2254 res = (*v->ob_type->tp_as_number->nb_power)(v, w, None);
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
2255 DECREF(v);
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
2256 DECREF(w);
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
2257 return res;
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
2258 }
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
2259
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3294
diff changeset
2260 static object *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2261 neg(v)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2262 object *v;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2263 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2264 if (v->ob_type->tp_as_number != NULL)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2265 return (*v->ob_type->tp_as_number->nb_negative)(v);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2266 err_setstr(TypeError, "bad operand type(s) for unary -");
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2267 return NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2268 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2269
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2270 static object *
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2271 pos(v)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2272 object *v;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2273 {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2274 if (v->ob_type->tp_as_number != NULL)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2275 return (*v->ob_type->tp_as_number->nb_positive)(v);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2276 err_setstr(TypeError, "bad operand type(s) for unary +");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2277 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2278 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2279
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2280 static object *
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2281 invert(v)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2282 object *v;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2283 {
671
10002e1bc526 Use correct prototype for invert().
Guido van Rossum <guido@python.org>
parents: 661
diff changeset
2284 object * (*f) FPROTO((object *));
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2285 if (v->ob_type->tp_as_number != NULL &&
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2286 (f = v->ob_type->tp_as_number->nb_invert) != NULL)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2287 return (*f)(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2288 err_setstr(TypeError, "bad operand type(s) for unary ~");
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2289 return NULL;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2290 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2291
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
2292 static object *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2293 not(v)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2294 object *v;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2295 {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2296 int outcome = testbool(v);
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2297 object *w;
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2298 if (outcome < 0)
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2299 return NULL;
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2300 if (outcome == 0)
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2301 w = True;
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2302 else
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2303 w = False;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2304 INCREF(w);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2305 return w;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2306 }
1313
6ee380349c84 * Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents: 1293
diff changeset
2307
6ee380349c84 * Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents: 1293
diff changeset
2308
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2309 /* External interface to call any callable object.
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2310 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
2311
e83852d1a5e2 Add interface to call a Python function (or other callable) object
Guido van Rossum <guido@python.org>
parents: 312
diff changeset
2312 object *
e83852d1a5e2 Add interface to call a Python function (or other callable) object
Guido van Rossum <guido@python.org>
parents: 312
diff changeset
2313 call_object(func, arg)
e83852d1a5e2 Add interface to call a Python function (or other callable) object
Guido van Rossum <guido@python.org>
parents: 312
diff changeset
2314 object *func;
e83852d1a5e2 Add interface to call a Python function (or other callable) object
Guido van Rossum <guido@python.org>
parents: 312
diff changeset
2315 object *arg;
e83852d1a5e2 Add interface to call a Python function (or other callable) object
Guido van Rossum <guido@python.org>
parents: 312
diff changeset
2316 {
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2317 return PyEval_CallObjectWithKeywords(func, arg, (object *)NULL);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2318 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2319
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2320 object *
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2321 PyEval_CallObjectWithKeywords(func, arg, kw)
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2322 object *func;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2323 object *arg;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2324 object *kw;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2325 {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2326 ternaryfunc call;
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2327 object *result;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2328
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2329 if (arg == NULL)
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2330 arg = newtupleobject(0);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2331 else if (!is_tupleobject(arg)) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2332 err_setstr(TypeError, "argument list must be a tuple");
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2333 return NULL;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2334 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2335 else
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2336 INCREF(arg);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2337
2894
4095782c940e empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents: 2872
diff changeset
2338 if (kw != NULL && !is_dictobject(kw)) {
4095782c940e empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents: 2872
diff changeset
2339 err_setstr(TypeError, "keyword list must be a dictionary");
4095782c940e empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents: 2872
diff changeset
2340 return NULL;
4095782c940e empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents: 2872
diff changeset
2341 }
4095782c940e empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents: 2872
diff changeset
2342
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
2343 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
2344 result = (*call)(func, arg, kw);
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2345 else if (is_instancemethodobject(func) || is_funcobject(func))
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2346 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
2347 else
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2348 result = call_builtin(func, arg, kw);
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2349
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2350 DECREF(arg);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2351
2006
3aa9184cff8b replace abort() calls by fatal()
Guido van Rossum <guido@python.org>
parents: 1914
diff changeset
2352 if (result == NULL && !err_occurred())
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2353 err_setstr(SystemError,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2354 "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
2355
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2356 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
2357 }
e83852d1a5e2 Add interface to call a Python function (or other callable) object
Guido van Rossum <guido@python.org>
parents: 312
diff changeset
2358
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2359 static object *
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2360 call_builtin(func, arg, kw)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2361 object *func;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2362 object *arg;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2363 object *kw;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2364 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2365 if (is_methodobject(func)) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2366 method meth = getmethod(func);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2367 object *self = getself(func);
2866
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
2368 int flags = getflags(func);
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
2369 if (!(flags & METH_VARARGS)) {
481
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
2370 int size = gettuplesize(arg);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
2371 if (size == 1)
2503
4dd1af0ddef0 various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents: 2366
diff changeset
2372 arg = GETTUPLEITEM(arg, 0);
481
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
2373 else if (size == 0)
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
2374 arg = NULL;
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
2375 }
2866
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
2376 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
2377 return (*(PyCFunctionWithKeywords)meth)(self, arg, kw);
2894
4095782c940e empty kw dict is ok for builtins
Guido van Rossum <guido@python.org>
parents: 2872
diff changeset
2378 if (kw != NULL && getmappingsize(kw) != 0) {
2866
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
2379 err_setstr(TypeError,
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
2380 "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
2381 return NULL;
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
2382 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2383 return (*meth)(self, arg);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2384 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2385 if (is_classobject(func)) {
2866
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
2386 return newinstanceobject(func, arg, kw);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2387 }
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2388 if (is_instanceobject(func)) {
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2389 object *res, *call = getattr(func,"__call__");
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2390 if (call == NULL) {
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2391 err_clear();
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2392 err_setstr(AttributeError,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2393 "no __call__ method defined");
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2394 return NULL;
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2395 }
2866
14111d66577d changes for keyword args to built-in functions and classes
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
2396 res = PyEval_CallObjectWithKeywords(call, arg, kw);
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2397 DECREF(call);
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2398 return res;
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2399 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2400 err_setstr(TypeError, "call of non-function");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2401 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2402 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2403
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2404 static object *
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2405 call_function(func, arg, kw)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2406 object *func;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2407 object *arg;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2408 object *kw;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2409 {
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2410 object *class = NULL; /* == owner */
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2411 object *argdefs;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2412 object **d, **k;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2413 int nk, nd;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2414 object *result;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2415
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2416 if (kw != NULL && !is_dictobject(kw)) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2417 err_badcall();
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2418 return NULL;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2419 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2420
224
e71b6fec86e5 Renamed class methods to instance methods (which they are)
Guido van Rossum <guido@python.org>
parents: 173
diff changeset
2421 if (is_instancemethodobject(func)) {
e71b6fec86e5 Renamed class methods to instance methods (which they are)
Guido van Rossum <guido@python.org>
parents: 173
diff changeset
2422 object *self = instancemethodgetself(func);
1289
4d292c7857d4 Access checks now work, at least for instance data (not for methods
Guido van Rossum <guido@python.org>
parents: 1288
diff changeset
2423 class = instancemethodgetclass(func);
224
e71b6fec86e5 Renamed class methods to instance methods (which they are)
Guido van Rossum <guido@python.org>
parents: 173
diff changeset
2424 func = instancemethodgetfunc(func);
1290
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2425 if (self == NULL) {
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2426 /* 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
2427 the class (or a derived class) as first argument */
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2428 if (gettuplesize(arg) >= 1) {
2503
4dd1af0ddef0 various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents: 2366
diff changeset
2429 self = GETTUPLEITEM(arg, 0);
1290
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2430 if (self != NULL &&
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2431 is_instanceobject(self) &&
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2432 issubclass((object *)
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2433 (((instanceobject *)self)->in_class),
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2434 class))
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2435 /* Handy-dandy */ ;
1290
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2436 else
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2437 self = NULL;
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2438 }
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2439 if (self == NULL) {
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2440 err_setstr(TypeError,
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2441 "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
2442 return NULL;
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2443 }
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2444 INCREF(arg);
1290
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2445 }
7971fecbf28e * Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
2446 else {
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2447 int argcount = gettuplesize(arg);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2448 object *newarg = newtupleobject(argcount + 1);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2449 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
2450 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
2451 return NULL;
4d292c7857d4 Access checks now work, at least for instance data (not for methods
Guido van Rossum <guido@python.org>
parents: 1288
diff changeset
2452 INCREF(self);
2503
4dd1af0ddef0 various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents: 2366
diff changeset
2453 SETTUPLEITEM(newarg, 0, self);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2454 for (i = 0; i < argcount; i++) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2455 object *v = GETTUPLEITEM(arg, i);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2456 XINCREF(v);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2457 SETTUPLEITEM(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
2458 }
4d292c7857d4 Access checks now work, at least for instance data (not for methods
Guido van Rossum <guido@python.org>
parents: 1288
diff changeset
2459 arg = newarg;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2460 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2461 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2462 else {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2463 if (!is_funcobject(func)) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2464 err_setstr(TypeError, "call of non-function");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2465 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2466 }
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2467 INCREF(arg);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2468 }
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2469
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2470 argdefs = PyFunction_GetDefaults(func);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2471 if (argdefs != NULL && is_tupleobject(argdefs)) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2472 d = &GETTUPLEITEM((tupleobject *)argdefs, 0);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2473 nd = gettuplesize(argdefs);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2474 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2475 else {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2476 d = NULL;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2477 nd = 0;
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2478 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2479
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2480 if (kw != NULL) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2481 int pos, i;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2482 nk = getmappingsize(kw);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2483 k = NEW(object *, 2*nk);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2484 if (k == NULL) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2485 err_nomem();
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2486 DECREF(arg);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2487 return NULL;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2488 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2489 pos = i = 0;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2490 while (mappinggetnext(kw, &pos, &k[i], &k[i+1]))
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2491 i += 2;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2492 nk = i/2;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2493 /* XXX This is broken if the caller deletes dict items! */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2494 }
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2495 else {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2496 k = NULL;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2497 nk = 0;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2498 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2499
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2500 result = eval_code2(
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2501 (codeobject *)getfunccode(func),
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2502 getfuncglobals(func), (object *)NULL,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2503 &GETTUPLEITEM(arg, 0), gettuplesize(arg),
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2504 k, nk,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2505 d, nd,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2506 class);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2507
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2508 DECREF(arg);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2509 XDEL(k);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2510
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2511 return result;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2512 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2513
3863
4566a19c3438 Better error message if stride used on normal sequence object
Guido van Rossum <guido@python.org>
parents: 3839
diff changeset
2514 #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
2515 "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
2516
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2517 static object *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2518 apply_subscript(v, w)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2519 object *v, *w;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2520 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2521 typeobject *tp = v->ob_type;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2522 if (tp->tp_as_sequence == NULL && tp->tp_as_mapping == NULL) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2523 err_setstr(TypeError, "unsubscriptable object");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2524 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2525 }
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2526 if (tp->tp_as_mapping != NULL) {
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2527 return (*tp->tp_as_mapping->mp_subscript)(v, w);
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2528 }
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2529 else {
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2530 int i;
3863
4566a19c3438 Better error message if stride used on normal sequence object
Guido van Rossum <guido@python.org>
parents: 3839
diff changeset
2531 if (!is_intobject(w)) {
4566a19c3438 Better error message if stride used on normal sequence object
Guido van Rossum <guido@python.org>
parents: 3839
diff changeset
2532 if (PySlice_Check(w)) {
4566a19c3438 Better error message if stride used on normal sequence object
Guido van Rossum <guido@python.org>
parents: 3839
diff changeset
2533 err_setstr(ValueError, SLICE_ERROR_MSG);
4566a19c3438 Better error message if stride used on normal sequence object
Guido van Rossum <guido@python.org>
parents: 3839
diff changeset
2534 } else {
4566a19c3438 Better error message if stride used on normal sequence object
Guido van Rossum <guido@python.org>
parents: 3839
diff changeset
2535 err_setstr(TypeError,
4566a19c3438 Better error message if stride used on normal sequence object
Guido van Rossum <guido@python.org>
parents: 3839
diff changeset
2536 "sequence subscript not int");
4566a19c3438 Better error message if stride used on normal sequence object
Guido van Rossum <guido@python.org>
parents: 3839
diff changeset
2537 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2538 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2539 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2540 i = getintvalue(w);
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2541 if (i < 0) {
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2542 int len = (*tp->tp_as_sequence->sq_length)(v);
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2543 if (len < 0)
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2544 return NULL;
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2545 i += len;
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2546 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2547 return (*tp->tp_as_sequence->sq_item)(v, i);
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 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2550
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2551 static object *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2552 loop_subscript(v, w)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2553 object *v, *w;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2554 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2555 sequence_methods *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
2556 int i;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2557 if (sq == NULL) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2558 err_setstr(TypeError, "loop over non-sequence");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2559 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2560 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2561 i = getintvalue(w);
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2562 v = (*sq->sq_item)(v, i);
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2563 if (v)
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2564 return v;
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2565 if (err_occurred() == IndexError)
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2566 err_clear();
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2567 return NULL;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2568 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2569
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2570 static int
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2571 slice_index(v, isize, pi)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2572 object *v;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2573 int isize;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2574 int *pi;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2575 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2576 if (v != NULL) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2577 if (!is_intobject(v)) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2578 err_setstr(TypeError, "slice index must be int");
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2579 return -1;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2580 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2581 *pi = getintvalue(v);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2582 if (*pi < 0)
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2583 *pi += isize;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2584 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2585 return 0;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2586 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2587
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2588 static object *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2589 apply_slice(u, v, w) /* return u[v:w] */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2590 object *u, *v, *w;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2591 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2592 typeobject *tp = u->ob_type;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2593 int ilow, ihigh, isize;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2594 if (tp->tp_as_sequence == NULL) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2595 err_setstr(TypeError, "only sequences can be sliced");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2596 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2597 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2598 ilow = 0;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2599 isize = ihigh = (*tp->tp_as_sequence->sq_length)(u);
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2600 if (isize < 0)
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2601 return NULL;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2602 if (slice_index(v, isize, &ilow) != 0)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2603 return NULL;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2604 if (slice_index(w, isize, &ihigh) != 0)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2605 return NULL;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2606 return (*tp->tp_as_sequence->sq_slice)(u, ilow, ihigh);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2607 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2608
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2609 static int
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2610 assign_subscript(w, key, v) /* w[key] = v */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2611 object *w;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2612 object *key;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2613 object *v;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2614 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2615 typeobject *tp = w->ob_type;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2616 sequence_methods *sq;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2617 mapping_methods *mp;
2366
94bf2f05da31 fix bug in try-finally with class exceptions; declare different func pointers for different uses
Guido van Rossum <guido@python.org>
parents: 2338
diff changeset
2618 int (*func1)();
94bf2f05da31 fix bug in try-finally with class exceptions; declare different func pointers for different uses
Guido van Rossum <guido@python.org>
parents: 2338
diff changeset
2619 int (*func2)();
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2620 if ((mp = tp->tp_as_mapping) != NULL &&
2366
94bf2f05da31 fix bug in try-finally with class exceptions; declare different func pointers for different uses
Guido van Rossum <guido@python.org>
parents: 2338
diff changeset
2621 (func1 = mp->mp_ass_subscript) != NULL) {
94bf2f05da31 fix bug in try-finally with class exceptions; declare different func pointers for different uses
Guido van Rossum <guido@python.org>
parents: 2338
diff changeset
2622 return (*func1)(w, key, v);
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2623 }
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2624 else if ((sq = tp->tp_as_sequence) != NULL &&
2366
94bf2f05da31 fix bug in try-finally with class exceptions; declare different func pointers for different uses
Guido van Rossum <guido@python.org>
parents: 2338
diff changeset
2625 (func2 = sq->sq_ass_item) != NULL) {
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2626 if (!is_intobject(key)) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2627 err_setstr(TypeError,
506
9f7161db5669 Negative subscript are now allowed as in slices.
Guido van Rossum <guido@python.org>
parents: 481
diff changeset
2628 "sequence subscript must be integer (assign or del)");
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2629 return -1;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2630 }
506
9f7161db5669 Negative subscript are now allowed as in slices.
Guido van Rossum <guido@python.org>
parents: 481
diff changeset
2631 else {
9f7161db5669 Negative subscript are now allowed as in slices.
Guido van Rossum <guido@python.org>
parents: 481
diff changeset
2632 int i = getintvalue(key);
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2633 if (i < 0) {
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2634 int len = (*sq->sq_length)(w);
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2635 if (len < 0)
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2636 return -1;
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2637 i += len;
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2638 }
2366
94bf2f05da31 fix bug in try-finally with class exceptions; declare different func pointers for different uses
Guido van Rossum <guido@python.org>
parents: 2338
diff changeset
2639 return (*func2)(w, i, v);
506
9f7161db5669 Negative subscript are now allowed as in slices.
Guido van Rossum <guido@python.org>
parents: 481
diff changeset
2640 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2641 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2642 else {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2643 err_setstr(TypeError,
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2644 "can't assign to this subscripted object");
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2645 return -1;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2646 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2647 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2648
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2649 static int
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2650 assign_slice(u, v, w, x) /* u[v:w] = x */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2651 object *u, *v, *w, *x;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2652 {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2653 sequence_methods *sq = u->ob_type->tp_as_sequence;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2654 int ilow, ihigh, isize;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2655 if (sq == NULL) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2656 err_setstr(TypeError, "assign to slice of non-sequence");
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2657 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2658 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2659 if (sq == NULL || sq->sq_ass_slice == NULL) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2660 err_setstr(TypeError, "unassignable slice");
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2661 return -1;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2662 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2663 ilow = 0;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2664 isize = ihigh = (*sq->sq_length)(u);
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2665 if (isize < 0)
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2666 return -1;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2667 if (slice_index(v, isize, &ilow) != 0)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2668 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2669 if (slice_index(w, isize, &ihigh) != 0)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2670 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2671 return (*sq->sq_ass_slice)(u, ilow, ihigh, x);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2672 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2673
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2674 static int
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2675 cmp_exception(err, v)
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2676 object *err, *v;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2677 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2678 if (is_tupleobject(v)) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2679 int i, n;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2680 n = gettuplesize(v);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2681 for (i = 0; i < n; i++) {
464
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
2682 /* Test recursively */
2503
4dd1af0ddef0 various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents: 2366
diff changeset
2683 if (cmp_exception(err, GETTUPLEITEM(v, i)))
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2684 return 1;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2685 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2686 return 0;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2687 }
2243
283a8eb2e317 allow classes as exceptions
Guido van Rossum <guido@python.org>
parents: 2201
diff changeset
2688 if (is_classobject(v) && is_classobject(err))
283a8eb2e317 allow classes as exceptions
Guido van Rossum <guido@python.org>
parents: 2201
diff changeset
2689 return issubclass(err, v);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2690 return err == v;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2691 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2692
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2693 static int
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2694 cmp_member(v, w)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2695 object *v, *w;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2696 {
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2697 int i, cmp;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2698 object *x;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2699 sequence_methods *sq;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2700 /* Special case for char in string */
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2701 if (is_stringobject(w)) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2702 register char *s, *end;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2703 register char c;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2704 if (!is_stringobject(v) || getstringsize(v) != 1) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2705 err_setstr(TypeError,
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2706 "string member test needs char left operand");
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2707 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2708 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2709 c = getstringvalue(v)[0];
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2710 s = getstringvalue(w);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2711 end = s + getstringsize(w);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2712 while (s < end) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2713 if (c == *s++)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2714 return 1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2715 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2716 return 0;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2717 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2718 sq = w->ob_type->tp_as_sequence;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2719 if (sq == NULL) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2720 err_setstr(TypeError,
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2721 "'in' or 'not in' needs sequence right argument");
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2722 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2723 }
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2724 for (i = 0; ; i++) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2725 x = (*sq->sq_item)(w, i);
1846
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2726 if (x == NULL) {
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2727 if (err_occurred() == IndexError) {
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2728 err_clear();
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2729 break;
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2730 }
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2731 return -1;
5243fb187d36 call_object: print message before abort()
Guido van Rossum <guido@python.org>
parents: 1425
diff changeset
2732 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2733 cmp = cmpobject(v, x);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2734 XDECREF(x);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2735 if (cmp == 0)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2736 return 1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2737 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2738 return 0;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2739 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2740
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2741 static object *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2742 cmp_outcome(op, v, w)
802
3d6541a2eca5 Arg of cmp_outcome becomes an int for portability to the Mac
Guido van Rossum <guido@python.org>
parents: 789
diff changeset
2743 int op;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2744 register object *v;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2745 register object *w;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2746 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2747 register int cmp;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2748 register int res = 0;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2749 switch (op) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2750 case IS:
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2751 case IS_NOT:
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2752 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
2753 if (op == (int) IS_NOT)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2754 res = !res;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2755 break;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2756 case IN:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2757 case NOT_IN:
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2758 res = cmp_member(v, w);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2759 if (res < 0)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2760 return NULL;
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2761 if (op == (int) NOT_IN)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2762 res = !res;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2763 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2764 case EXC_MATCH:
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2765 res = cmp_exception(v, w);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2766 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2767 default:
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2768 cmp = cmpobject(v, w);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2769 switch (op) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2770 case LT: res = cmp < 0; break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2771 case LE: res = cmp <= 0; break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2772 case EQ: res = cmp == 0; break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2773 case NE: res = cmp != 0; break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2774 case GT: res = cmp > 0; break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2775 case GE: res = cmp >= 0; break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2776 /* XXX no default? (res is initialized to 0 though) */
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2777 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2778 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2779 v = res ? True : False;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2780 INCREF(v);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2781 return v;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2782 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2783
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2784 static int
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2785 import_from(locals, v, name)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2786 object *locals;
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2787 object *v;
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
2788 object *name;
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2789 {
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2790 object *w, *x;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
2791 if (!is_moduleobject(v)) {
2201
8f1daffe799b add missing INCREF in RAISE_EXCEPTION
Guido van Rossum <guido@python.org>
parents: 2151
diff changeset
2792 err_setstr(TypeError, "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
2793 return -1;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2006
diff changeset
2794 }
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2795 w = getmoduledict(v);
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
2796 if (getstringvalue(name)[0] == '*') {
1293
ac3c80abbf43 * classobject.c: in instance_getattr, don't make a method out of a
Guido van Rossum <guido@python.org>
parents: 1290
diff changeset
2797 int pos, err;
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2798 object *name, *value;
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2799 pos = 0;
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2800 while (mappinggetnext(w, &pos, &name, &value)) {
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2801 if (!is_stringobject(name) ||
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2802 getstringvalue(name)[0] == '_')
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2803 continue;
5018
001a5042b181 Cleanup:
Guido van Rossum <guido@python.org>
parents: 5014
diff changeset
2804 INCREF(value);
1293
ac3c80abbf43 * classobject.c: in instance_getattr, don't make a method out of a
Guido van Rossum <guido@python.org>
parents: 1290
diff changeset
2805 err = dict2insert(locals, name, value);
ac3c80abbf43 * classobject.c: in instance_getattr, don't make a method out of a
Guido van Rossum <guido@python.org>
parents: 1290
diff changeset
2806 DECREF(value);
ac3c80abbf43 * classobject.c: in instance_getattr, don't make a method out of a
Guido van Rossum <guido@python.org>
parents: 1290
diff changeset
2807 if (err != 0)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2808 return -1;
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2809 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2810 return 0;
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2811 }
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2812 else {
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
2813 x = dict2lookup(w, name);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2814 if (x == NULL) {
506
9f7161db5669 Negative subscript are now allowed as in slices.
Guido van Rossum <guido@python.org>
parents: 481
diff changeset
2815 char buf[250];
661
7e5f4d9aee77 Limit length of name passed to sprintf.
Guido van Rossum <guido@python.org>
parents: 607
diff changeset
2816 sprintf(buf, "cannot import name %.230s",
506
9f7161db5669 Negative subscript are now allowed as in slices.
Guido van Rossum <guido@python.org>
parents: 481
diff changeset
2817 getstringvalue(name));
9f7161db5669 Negative subscript are now allowed as in slices.
Guido van Rossum <guido@python.org>
parents: 481
diff changeset
2818 err_setstr(ImportError, buf);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2819 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2820 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2821 else
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
2822 return dict2insert(locals, name, x);
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2823 }
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2824 }
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2825
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2826 static object *
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2827 build_class(methods, bases, name)
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2828 object *methods; /* dictionary */
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2829 object *bases; /* tuple containing classes */
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2830 object *name; /* string */
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2831 {
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2832 int i;
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2833 if (!is_tupleobject(bases)) {
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2834 err_setstr(SystemError, "build_class with non-tuple bases");
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2835 return NULL;
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2836 }
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2837 if (!is_dictobject(methods)) {
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2838 err_setstr(SystemError, "build_class with non-dictionary");
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2839 return NULL;
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2840 }
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2841 if (!is_stringobject(name)) {
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2842 err_setstr(SystemError, "build_class witn non-string name");
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2843 return NULL;
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2844 }
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2845 for (i = gettuplesize(bases); --i >= 0; ) {
2503
4dd1af0ddef0 various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents: 2366
diff changeset
2846 object *base = GETTUPLEITEM(bases, i);
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2847 if (!is_classobject(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
2848 /* 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
2849 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
2850 and Jim Fulton's type extensions. In
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
2851 unexended Python it will never be triggered
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
2852 since its types are not 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
2853 if (base->ob_type->ob_type->tp_call) {
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
2854 object *args;
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
2855 object *class;
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
2856 args = mkvalue("(OOO)", name, bases, methods);
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
2857 class = call_object((object *)base->ob_type,
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
2858 args);
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
2859 DECREF(args);
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
2860 return class;
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
2861 }
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2862 err_setstr(TypeError,
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2863 "base is not a class object");
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2864 return NULL;
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2865 }
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2866 }
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2867 return newclassobject(bases, methods, name);
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2868 }
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
2869
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2870 static int
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2871 exec_statement(prog, globals, locals)
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2872 object *prog;
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2873 object *globals;
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2874 object *locals;
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2875 {
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2876 char *s;
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2877 int n;
2295
3d6c9a47ea44 DECREF result of run_string
Guido van Rossum <guido@python.org>
parents: 2271
diff changeset
2878 object *v;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2879 int plain = 0;
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2880
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2881 if (is_tupleobject(prog) && globals == None && locals == None &&
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2882 ((n = gettuplesize(prog)) == 2 || n == 3)) {
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2883 /* Backward compatibility hack */
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2884 globals = gettupleitem(prog, 1);
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2885 if (n == 3)
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2886 locals = gettupleitem(prog, 2);
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2887 prog = gettupleitem(prog, 0);
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2888 }
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2889 if (globals == None) {
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2890 globals = getglobals();
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2891 if (locals == None) {
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2892 locals = getlocals();
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2893 plain = 1;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2894 }
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2895 }
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2896 else if (locals == None)
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2897 locals = globals;
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2898 if (!is_stringobject(prog) &&
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2899 !is_codeobject(prog) &&
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2900 !is_fileobject(prog)) {
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2901 err_setstr(TypeError,
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2902 "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
2903 return -1;
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2904 }
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2905 if (!is_dictobject(globals) || !is_dictobject(locals)) {
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2906 err_setstr(TypeError,
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2907 "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
2908 return -1;
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2909 }
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
2910 if (dictlookup(globals, "__builtins__") == NULL)
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2088
diff changeset
2911 dictinsert(globals, "__builtins__", current_frame->f_builtins);
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2912 if (is_codeobject(prog)) {
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2913 if (eval_code((codeobject *) prog, globals, locals) == NULL)
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2914 return -1;
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2915 return 0;
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2916 }
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2917 if (is_fileobject(prog)) {
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2918 FILE *fp = getfilefile(prog);
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2919 char *name = getstringvalue(getfilename(prog));
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2920 if (run_file(fp, name, file_input, globals, locals) == NULL)
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2921 return -1;
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2922 return 0;
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2923 }
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2924 s = getstringvalue(prog);
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2925 if (strlen(s) != getstringsize(prog)) {
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2926 err_setstr(ValueError, "embedded '\\0' in exec string");
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2927 return -1;
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2928 }
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2929 v = run_string(s, file_input, globals, locals);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2930 if (v == NULL)
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2931 return -1;
2295
3d6c9a47ea44 DECREF result of run_string
Guido van Rossum <guido@python.org>
parents: 2271
diff changeset
2932 DECREF(v);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2933 if (plain)
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2934 locals_2_fast(current_frame, 0);
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2935 return 0;
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2936 }
2338
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2937
5018
001a5042b181 Cleanup:
Guido van Rossum <guido@python.org>
parents: 5014
diff changeset
2938 /* Hack for ni.py */
2338
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2939 static object *
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2940 find_from_args(f, nexti)
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2941 frameobject *f;
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2942 int nexti;
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2943 {
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2944 int opcode;
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2945 int oparg;
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2946 object *list, *name;
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2947 unsigned char *next_instr;
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2948
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2949 next_instr = GETUSTRINGVALUE(f->f_code->co_code) + nexti;
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2950 opcode = (*next_instr++);
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2951 if (opcode != IMPORT_FROM) {
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2952 INCREF(None);
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2953 return None;
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2954 }
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2955
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2956 list = newlistobject(0);
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2957 if (list == NULL)
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2958 return NULL;
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2959
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2960 do {
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2961 oparg = (next_instr[1]<<8) + next_instr[0];
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2962 next_instr += 2;
2338
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2963 name = Getnamev(f, oparg);
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2964 if (addlistitem(list, name) < 0) {
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2965 DECREF(list);
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2966 break;
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2967 }
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2968 opcode = (*next_instr++);
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2969 } while (opcode == IMPORT_FROM);
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2970
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2971 return list;
4c2f1452125d call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
2972 }
5049
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
2973
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
2974
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
2975 #ifdef DYNAMIC_EXECUTION_PROFILE
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
2976
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
2977 PyObject *
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
2978 getarray(a)
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
2979 long a[256];
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
2980 {
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
2981 int i;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
2982 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
2983 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
2984 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
2985 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
2986 if (x == NULL) {
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
2987 Py_DECREF(l);
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
2988 return NULL;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
2989 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
2990 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
2991 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
2992 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
2993 a[i] = 0;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
2994 return l;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
2995 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
2996
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
2997 PyObject *
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
2998 _Py_GetDXProfile(self, args)
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
2999 PyObject *self, *args;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3000 {
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3001 #ifndef DXPAIRS
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3002 return getarray(dxp);
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3003 #else
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3004 int i;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3005 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
3006 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
3007 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
3008 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
3009 if (x == NULL) {
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3010 Py_DECREF(l);
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3011 return NULL;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3012 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3013 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
3014 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3015 return l;
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3016 #endif
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3017 }
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3018
946b2b2a7622 Patches for (two forms of) optional dynamic execution profiling --
Guido van Rossum <guido@python.org>
parents: 5048
diff changeset
3019 #endif