annotate Python/ceval.c @ 2612:ca6b60d4ea90 legacy-trunk

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