Skip to content

Latest commit

 

History

History
4148 lines (3743 loc) · 97.3 KB

File metadata and controls

4148 lines (3743 loc) · 97.3 KB
 
Feb 19, 1991
Feb 19, 1991
1
Dec 20, 1990
Dec 20, 1990
2
/* Execute compiled code */
Nov 18, 1990
Nov 18, 1990
3
Jul 18, 1995
Jul 18, 1995
4
/* XXX TO DO:
5
XXX speed up searching for keywords by using a dictionary
6
XXX document it!
7
*/
8
Apr 29, 1997
Apr 29, 1997
9
#include "Python.h"
Nov 18, 1990
Nov 18, 1990
10
11
#include "compile.h"
Dec 20, 1990
Dec 20, 1990
12
#include "frameobject.h"
Aug 5, 1992
Aug 5, 1992
13
#include "eval.h"
Nov 18, 1990
Nov 18, 1990
14
#include "opcode.h"
Aug 2, 2001
Aug 2, 2001
15
#include "structmember.h"
Nov 18, 1990
Nov 18, 1990
16
Jul 11, 2000
Jul 11, 2000
17
#ifdef macintosh
18
#include "macglue.h"
19
#endif
20
Nov 5, 1993
Nov 5, 1993
21
#include <ctype.h>
22
Aug 12, 1992
Aug 12, 1992
23
/* Turn this on if your compiler chokes on the big switch: */
Jan 2, 1995
Jan 2, 1995
24
/* #define CASE_TOO_BIG 1 */
Aug 12, 1992
Aug 12, 1992
25
Dec 30, 1996
Dec 30, 1996
26
#ifdef Py_DEBUG
Jan 12, 1992
Jan 12, 1992
27
/* For debugging the interpreter: */
28
#define LLTRACE 1 /* Low-level trace feature */
29
#define CHECKEXC 1 /* Double-check exception checking */
Nov 18, 1990
Nov 18, 1990
30
#endif
31
Jan 3, 2001
Jan 3, 2001
32
typedef PyObject *(*callproc)(PyObject *, PyObject *, PyObject *);
Mar 30, 1993
Mar 30, 1993
33
Apr 4, 1991
Apr 4, 1991
34
/* Forward declarations */
Jun 18, 2001
Jun 18, 2001
35
static PyObject *eval_frame(PyFrameObject *);
Aug 16, 2002
Aug 16, 2002
36
static PyObject *call_function(PyObject ***, int);
Jan 3, 2001
Jan 3, 2001
37
static PyObject *fast_function(PyObject *, PyObject ***, int, int, int);
38
static PyObject *do_call(PyObject *, PyObject ***, int, int);
39
static PyObject *ext_do_call(PyObject *, PyObject ***, int, int, int);
Jan 17, 2001
Jan 17, 2001
40
static PyObject *update_keyword_args(PyObject *, int, PyObject ***,PyObject *);
Jan 15, 2001
Jan 15, 2001
41
static PyObject *update_star_args(int, int, PyObject *, PyObject ***);
Jan 3, 2001
Jan 3, 2001
42
static PyObject *load_args(PyObject ***, int);
43
#define CALL_FLAG_VAR 1
44
#define CALL_FLAG_KW 2
45
Mar 27, 1992
Mar 27, 1992
46
#ifdef LLTRACE
Jul 9, 2000
Jul 9, 2000
47
static int prtrace(PyObject *, char *);
Mar 27, 1992
Mar 27, 1992
48
#endif
Jun 27, 2001
Jun 27, 2001
49
static int call_trace(Py_tracefunc, PyObject *, PyFrameObject *,
50
int, PyObject *);
Oct 4, 2001
Oct 4, 2001
51
static void call_trace_protected(Py_tracefunc, PyObject *,
52
PyFrameObject *, int);
Jun 27, 2001
Jun 27, 2001
53
static void call_exc_trace(Py_tracefunc, PyObject *, PyFrameObject *);
Nov 8, 2002
Nov 8, 2002
54
static int maybe_call_line_trace(Py_tracefunc, PyObject *,
Aug 15, 2002
Aug 15, 2002
55
PyFrameObject *, int *, int *);
56
Jul 9, 2000
Jul 9, 2000
57
static PyObject *apply_slice(PyObject *, PyObject *, PyObject *);
58
static int assign_slice(PyObject *, PyObject *,
59
PyObject *, PyObject *);
60
static PyObject *cmp_outcome(int, PyObject *, PyObject *);
Aug 17, 2000
Aug 17, 2000
61
static PyObject *import_from(PyObject *, PyObject *);
62
static int import_all_from(PyObject *, PyObject *);
Jul 9, 2000
Jul 9, 2000
63
static PyObject *build_class(PyObject *, PyObject *, PyObject *);
64
static int exec_statement(PyFrameObject *,
65
PyObject *, PyObject *, PyObject *);
66
static void set_exc_info(PyThreadState *, PyObject *, PyObject *, PyObject *);
67
static void reset_exc_info(PyThreadState *);
Aug 30, 2000
Aug 30, 2000
68
static void format_exc_check_arg(PyObject *, char *, PyObject *);
Mar 27, 1992
Mar 27, 1992
69
Aug 30, 2000
Aug 30, 2000
70
#define NAME_ERROR_MSG \
Oct 24, 2000
Oct 24, 2000
71
"name '%.200s' is not defined"
Jan 25, 2001
Jan 25, 2001
72
#define GLOBAL_NAME_ERROR_MSG \
73
"global name '%.200s' is not defined"
Aug 30, 2000
Aug 30, 2000
74
#define UNBOUNDLOCAL_ERROR_MSG \
Oct 24, 2000
Oct 24, 2000
75
"local variable '%.200s' referenced before assignment"
Apr 13, 2001
Apr 13, 2001
76
#define UNBOUNDFREE_ERROR_MSG \
77
"free variable '%.200s' referenced before assignment" \
78
" in enclosing scope"
Nov 18, 1990
Nov 18, 1990
79
Jan 24, 1997
Jan 24, 1997
80
/* Dynamic execution profile */
81
#ifdef DYNAMIC_EXECUTION_PROFILE
82
#ifdef DXPAIRS
83
static long dxpairs[257][256];
84
#define dxp dxpairs[256]
85
#else
86
static long dxp[256];
87
#endif
88
#endif
89
Feb 5, 2003
Feb 5, 2003
90
/* Function call profile */
91
#ifdef CALL_PROFILE
92
#define PCALL_NUM 11
93
static int pcall[PCALL_NUM];
94
95
#define PCALL_ALL 0
96
#define PCALL_FUNCTION 1
97
#define PCALL_FAST_FUNCTION 2
98
#define PCALL_FASTER_FUNCTION 3
99
#define PCALL_METHOD 4
100
#define PCALL_BOUND_METHOD 5
101
#define PCALL_CFUNCTION 6
102
#define PCALL_TYPE 7
103
#define PCALL_GENERATOR 8
104
#define PCALL_OTHER 9
105
#define PCALL_POP 10
106
107
/* Notes about the statistics
108
109
PCALL_FAST stats
110
111
FAST_FUNCTION means no argument tuple needs to be created.
112
FASTER_FUNCTION means that the fast-path frame setup code is used.
113
114
If there is a method call where the call can be optimized by changing
115
the argument tuple and calling the function directly, it gets recorded
116
twice.
117
118
As a result, the relationship among the statistics appears to be
119
PCALL_ALL == PCALL_FUNCTION + PCALL_METHOD - PCALL_BOUND_METHOD +
120
PCALL_CFUNCTION + PCALL_TYPE + PCALL_GENERATOR + PCALL_OTHER
121
PCALL_FUNCTION > PCALL_FAST_FUNCTION > PCALL_FASTER_FUNCTION
122
PCALL_METHOD > PCALL_BOUND_METHOD
123
*/
124
125
#define PCALL(POS) pcall[POS]++
126
127
PyObject *
128
PyEval_GetCallStats(PyObject *self)
129
{
130
return Py_BuildValue("iiiiiiiiii",
131
pcall[0], pcall[1], pcall[2], pcall[3],
132
pcall[4], pcall[5], pcall[6], pcall[7],
133
pcall[8], pcall[9]);
134
}
135
#else
136
#define PCALL(O)
137
138
PyObject *
139
PyEval_GetCallStats(PyObject *self)
140
{
141
Py_INCREF(Py_None);
142
return Py_None;
143
}
144
#endif
145
Jul 17, 2002
Jul 17, 2002
146
static PyTypeObject gentype;
Jun 18, 2001
Jun 18, 2001
147
148
typedef struct {
149
PyObject_HEAD
Jun 26, 2001
Jun 26, 2001
150
/* The gi_ prefix is intended to remind of generator-iterator. */
151
152
PyFrameObject *gi_frame;
153
Jun 26, 2001
Jun 26, 2001
154
/* True if generator is being executed. */
155
int gi_running;
Aug 9, 2002
Aug 9, 2002
156
157
/* List of weak reference. */
158
PyObject *gi_weakreflist;
Jun 18, 2001
Jun 18, 2001
159
} genobject;
160
161
static PyObject *
162
gen_new(PyFrameObject *f)
163
{
Mar 18, 2002
Mar 18, 2002
164
genobject *gen = PyObject_GC_New(genobject, &gentype);
Jun 18, 2001
Jun 18, 2001
165
if (gen == NULL) {
166
Py_DECREF(f);
167
return NULL;
168
}
Jun 26, 2001
Jun 26, 2001
169
gen->gi_frame = f;
170
gen->gi_running = 0;
Aug 9, 2002
Aug 9, 2002
171
gen->gi_weakreflist = NULL;
Mar 18, 2002
Mar 18, 2002
172
_PyObject_GC_TRACK(gen);
Jun 18, 2001
Jun 18, 2001
173
return (PyObject *)gen;
174
}
175
Jul 12, 2001
Jul 12, 2001
176
static int
177
gen_traverse(genobject *gen, visitproc visit, void *arg)
178
{
179
return visit((PyObject *)gen->gi_frame, arg);
180
}
181
Jun 18, 2001
Jun 18, 2001
182
static void
183
gen_dealloc(genobject *gen)
184
{
Mar 18, 2002
Mar 18, 2002
185
_PyObject_GC_UNTRACK(gen);
Aug 9, 2002
Aug 9, 2002
186
if (gen->gi_weakreflist != NULL)
187
PyObject_ClearWeakRefs((PyObject *) gen);
Jun 26, 2001
Jun 26, 2001
188
Py_DECREF(gen->gi_frame);
Mar 18, 2002
Mar 18, 2002
189
PyObject_GC_Del(gen);
Jun 18, 2001
Jun 18, 2001
190
}
191
192
static PyObject *
193
gen_iternext(genobject *gen)
194
{
Jun 21, 2001
Jun 21, 2001
195
PyThreadState *tstate = PyThreadState_GET();
Jun 26, 2001
Jun 26, 2001
196
PyFrameObject *f = gen->gi_frame;
Jun 18, 2001
Jun 18, 2001
197
PyObject *result;
198
Jun 26, 2001
Jun 26, 2001
199
if (gen->gi_running) {
Jun 18, 2001
Jun 18, 2001
200
PyErr_SetString(PyExc_ValueError,
201
"generator already executing");
202
return NULL;
203
}
Jun 23, 2001
Jun 23, 2001
204
if (f->f_stacktop == NULL)
Jun 18, 2001
Jun 18, 2001
205
return NULL;
Jun 21, 2001
Jun 21, 2001
206
207
/* Generators always return to their most recent caller, not
208
* necessarily their creator. */
Jun 23, 2001
Jun 23, 2001
209
Py_XINCREF(tstate->frame);
Jun 21, 2001
Jun 21, 2001
210
assert(f->f_back == NULL);
211
f->f_back = tstate->frame;
212
Jun 26, 2001
Jun 26, 2001
213
gen->gi_running = 1;
Jun 18, 2001
Jun 18, 2001
214
result = eval_frame(f);
Jun 26, 2001
Jun 26, 2001
215
gen->gi_running = 0;
Jun 21, 2001
Jun 21, 2001
216
217
/* Don't keep the reference to f_back any longer than necessary. It
218
* may keep a chain of frames alive or it could create a reference
219
* cycle. */
Jun 23, 2001
Jun 23, 2001
220
Py_XDECREF(f->f_back);
Jun 20, 2001
Jun 20, 2001
221
f->f_back = NULL;
Jun 21, 2001
Jun 21, 2001
222
Jun 23, 2001
Jun 23, 2001
223
/* If the generator just returned (as opposed to yielding), signal
224
* that the generator is exhausted. */
225
if (result == Py_None && f->f_stacktop == NULL) {
226
Py_DECREF(result);
227
result = NULL;
228
}
229
Jun 21, 2001
Jun 21, 2001
230
return result;
Jun 18, 2001
Jun 18, 2001
231
}
232
233
static PyObject *
234
gen_getiter(PyObject *gen)
235
{
236
Py_INCREF(gen);
237
return gen;
238
}
239
Sep 20, 2001
Sep 20, 2001
240
static PyMemberDef gen_memberlist[] = {
Aug 2, 2001
Aug 2, 2001
241
{"gi_frame", T_OBJECT, offsetof(genobject, gi_frame), RO},
242
{"gi_running", T_INT, offsetof(genobject, gi_running), RO},
243
{NULL} /* Sentinel */
244
};
Jun 18, 2001
Jun 18, 2001
245
Jul 17, 2002
Jul 17, 2002
246
static PyTypeObject gentype = {
Jun 18, 2001
Jun 18, 2001
247
PyObject_HEAD_INIT(&PyType_Type)
248
0, /* ob_size */
249
"generator", /* tp_name */
Mar 18, 2002
Mar 18, 2002
250
sizeof(genobject), /* tp_basicsize */
Jun 18, 2001
Jun 18, 2001
251
0, /* tp_itemsize */
252
/* methods */
253
(destructor)gen_dealloc, /* tp_dealloc */
254
0, /* tp_print */
Aug 2, 2001
Aug 2, 2001
255
0, /* tp_getattr */
Jun 18, 2001
Jun 18, 2001
256
0, /* tp_setattr */
257
0, /* tp_compare */
258
0, /* tp_repr */
259
0, /* tp_as_number */
260
0, /* tp_as_sequence */
261
0, /* tp_as_mapping */
262
0, /* tp_hash */
263
0, /* tp_call */
264
0, /* tp_str */
Aug 2, 2001
Aug 2, 2001
265
PyObject_GenericGetAttr, /* tp_getattro */
Jun 18, 2001
Jun 18, 2001
266
0, /* tp_setattro */
267
0, /* tp_as_buffer */
Mar 18, 2002
Mar 18, 2002
268
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
Jun 18, 2001
Jun 18, 2001
269
0, /* tp_doc */
Jul 12, 2001
Jul 12, 2001
270
(traverseproc)gen_traverse, /* tp_traverse */
Jun 18, 2001
Jun 18, 2001
271
0, /* tp_clear */
272
0, /* tp_richcompare */
Aug 9, 2002
Aug 9, 2002
273
offsetof(genobject, gi_weakreflist), /* tp_weaklistoffset */
Jun 18, 2001
Jun 18, 2001
274
(getiterfunc)gen_getiter, /* tp_iter */
275
(iternextfunc)gen_iternext, /* tp_iternext */
Jul 17, 2002
Jul 17, 2002
276
0, /* tp_methods */
Aug 2, 2001
Aug 2, 2001
277
gen_memberlist, /* tp_members */
278
0, /* tp_getset */
279
0, /* tp_base */
280
0, /* tp_dict */
Jun 18, 2001
Jun 18, 2001
281
};
282
283
Aug 30, 1994
Aug 30, 1994
284
#ifdef WITH_THREAD
Aug 5, 1992
Aug 5, 1992
285
Apr 7, 1999
Apr 7, 1999
286
#ifndef DONT_HAVE_ERRNO_H
Aug 4, 1992
Aug 4, 1992
287
#include <errno.h>
Apr 7, 1999
Apr 7, 1999
288
#endif
Oct 1, 1998
Oct 1, 1998
289
#include "pythread.h"
Aug 5, 1992
Aug 5, 1992
290
May 5, 1997
May 5, 1997
291
extern int _PyThread_Started; /* Flag for Py_Exit */
292
Jun 28, 2003
Jun 28, 2003
293
static PyThread_type_lock interpreter_lock = 0; /* This is the GIL */
Sep 14, 1994
Sep 14, 1994
294
static long main_thread = 0;
Aug 4, 1992
Aug 4, 1992
295
296
void
Jul 22, 2000
Jul 22, 2000
297
PyEval_InitThreads(void)
Aug 4, 1992
Aug 4, 1992
298
{
299
if (interpreter_lock)
Jan 6, 1993
Jan 6, 1993
300
return;
May 5, 1997
May 5, 1997
301
_PyThread_Started = 1;
Dec 21, 1998
Dec 21, 1998
302
interpreter_lock = PyThread_allocate_lock();
303
PyThread_acquire_lock(interpreter_lock, 1);
304
main_thread = PyThread_get_thread_ident();
Aug 4, 1992
Aug 4, 1992
305
}
Aug 5, 1992
Aug 5, 1992
306
Aug 2, 1997
Aug 2, 1997
307
void
Jul 22, 2000
Jul 22, 2000
308
PyEval_AcquireLock(void)
Aug 2, 1997
Aug 2, 1997
309
{
Dec 21, 1998
Dec 21, 1998
310
PyThread_acquire_lock(interpreter_lock, 1);
Aug 2, 1997
Aug 2, 1997
311
}
312
313
void
Jul 22, 2000
Jul 22, 2000
314
PyEval_ReleaseLock(void)
Aug 2, 1997
Aug 2, 1997
315
{
Dec 21, 1998
Dec 21, 1998
316
PyThread_release_lock(interpreter_lock);
Aug 2, 1997
Aug 2, 1997
317
}
318
Jul 19, 1997
Jul 19, 1997
319
void
Jul 22, 2000
Jul 22, 2000
320
PyEval_AcquireThread(PyThreadState *tstate)
Jul 19, 1997
Jul 19, 1997
321
{
322
if (tstate == NULL)
323
Py_FatalError("PyEval_AcquireThread: NULL new thread state");
Apr 19, 2003
Apr 19, 2003
324
/* Check someone has called PyEval_InitThreads() to create the lock */
325
assert(interpreter_lock);
Dec 21, 1998
Dec 21, 1998
326
PyThread_acquire_lock(interpreter_lock, 1);
Jul 19, 1997
Jul 19, 1997
327
if (PyThreadState_Swap(tstate) != NULL)
328
Py_FatalError(
329
"PyEval_AcquireThread: non-NULL old thread state");
330
}
331
332
void
Jul 22, 2000
Jul 22, 2000
333
PyEval_ReleaseThread(PyThreadState *tstate)
Jul 19, 1997
Jul 19, 1997
334
{
335
if (tstate == NULL)
336
Py_FatalError("PyEval_ReleaseThread: NULL thread state");
337
if (PyThreadState_Swap(NULL) != tstate)
338
Py_FatalError("PyEval_ReleaseThread: wrong thread state");
Dec 21, 1998
Dec 21, 1998
339
PyThread_release_lock(interpreter_lock);
Jul 19, 1997
Jul 19, 1997
340
}
Aug 27, 2000
Aug 27, 2000
341
342
/* This function is called from PyOS_AfterFork to ensure that newly
343
created child processes don't hold locks referring to threads which
344
are not running in the child process. (This could also be done using
345
pthread_atfork mechanism, at least for the pthreads implementation.) */
346
347
void
348
PyEval_ReInitThreads(void)
349
{
350
if (!interpreter_lock)
351
return;
352
/*XXX Can't use PyThread_free_lock here because it does too
353
much error-checking. Doing this cleanly would require
354
adding a new function to each thread_*.h. Instead, just
355
create a new lock and waste a little bit of memory */
356
interpreter_lock = PyThread_allocate_lock();
357
PyThread_acquire_lock(interpreter_lock, 1);
358
main_thread = PyThread_get_thread_ident();
359
}
Aug 4, 1992
Aug 4, 1992
360
#endif
361
Aug 5, 1992
Aug 5, 1992
362
/* Functions save_thread and restore_thread are always defined so
363
dynamically loaded modules needn't be compiled separately for use
364
with and without threads: */
365
Jul 18, 1997
Jul 18, 1997
366
PyThreadState *
Jul 22, 2000
Jul 22, 2000
367
PyEval_SaveThread(void)
Aug 4, 1992
Aug 4, 1992
368
{
Sep 30, 1997
Sep 30, 1997
369
PyThreadState *tstate = PyThreadState_Swap(NULL);
370
if (tstate == NULL)
371
Py_FatalError("PyEval_SaveThread: NULL tstate");
Aug 30, 1994
Aug 30, 1994
372
#ifdef WITH_THREAD
Sep 30, 1997
Sep 30, 1997
373
if (interpreter_lock)
Dec 21, 1998
Dec 21, 1998
374
PyThread_release_lock(interpreter_lock);
Aug 4, 1992
Aug 4, 1992
375
#endif
Sep 30, 1997
Sep 30, 1997
376
return tstate;
Aug 4, 1992
Aug 4, 1992
377
}
378
379
void
Jul 22, 2000
Jul 22, 2000
380
PyEval_RestoreThread(PyThreadState *tstate)
Aug 4, 1992
Aug 4, 1992
381
{
Sep 30, 1997
Sep 30, 1997
382
if (tstate == NULL)
383
Py_FatalError("PyEval_RestoreThread: NULL tstate");
Aug 30, 1994
Aug 30, 1994
384
#ifdef WITH_THREAD
Aug 4, 1992
Aug 4, 1992
385
if (interpreter_lock) {
Sep 30, 1997
Sep 30, 1997
386
int err = errno;
Dec 21, 1998
Dec 21, 1998
387
PyThread_acquire_lock(interpreter_lock, 1);
Aug 4, 1992
Aug 4, 1992
388
errno = err;
389
}
390
#endif
Sep 30, 1997
Sep 30, 1997
391
PyThreadState_Swap(tstate);
Aug 4, 1992
Aug 4, 1992
392
}
393
394
Sep 14, 1994
Sep 14, 1994
395
/* Mechanism whereby asynchronously executing callbacks (e.g. UNIX
396
signal handlers or Mac I/O completion routines) can schedule calls
397
to a function to be called synchronously.
398
The synchronous function is called with one void* argument.
399
It should return 0 for success or -1 for failure -- failure should
400
be accompanied by an exception.
401
402
If registry succeeds, the registry function returns 0; if it fails
403
(e.g. due to too many pending calls) it returns -1 (without setting
404
an exception condition).
405
406
Note that because registry may occur from within signal handlers,
407
or other asynchronous events, calling malloc() is unsafe!
408
409
#ifdef WITH_THREAD
410
Any thread can schedule pending calls, but only the main thread
411
will execute them.
412
#endif
413
414
XXX WARNING! ASYNCHRONOUSLY EXECUTING CODE!
415
There are two possible race conditions:
416
(1) nested asynchronous registry calls;
417
(2) registry calls made while pending calls are being processed.
418
While (1) is very unlikely, (2) is a real possibility.
419
The current code is safe against (2), but not against (1).
420
The safety against (2) is derived from the fact that only one
421
thread (the main thread) ever takes things out of the queue.
422
May 5, 1997
May 5, 1997
423
XXX Darn! With the advent of thread state, we should have an array
424
of pending calls per thread in the thread state! Later...
425
*/
Jul 30, 1996
Jul 30, 1996
426
Sep 14, 1994
Sep 14, 1994
427
#define NPENDINGCALLS 32
428
static struct {
Jul 25, 2000
Jul 25, 2000
429
int (*func)(void *);
430
void *arg;
Sep 14, 1994
Sep 14, 1994
431
} pendingcalls[NPENDINGCALLS];
432
static volatile int pendingfirst = 0;
433
static volatile int pendinglast = 0;
May 5, 1997
May 5, 1997
434
static volatile int things_to_do = 0;
Sep 14, 1994
Sep 14, 1994
435
436
int
Jul 25, 2000
Jul 25, 2000
437
Py_AddPendingCall(int (*func)(void *), void *arg)
Sep 14, 1994
Sep 14, 1994
438
{
Sep 29, 1994
Sep 29, 1994
439
static int busy = 0;
Sep 14, 1994
Sep 14, 1994
440
int i, j;
441
/* XXX Begin critical section */
442
/* XXX If you want this to be safe against nested
443
XXX asynchronous calls, you'll have to work harder! */
Sep 29, 1994
Sep 29, 1994
444
if (busy)
445
return -1;
446
busy = 1;
Sep 14, 1994
Sep 14, 1994
447
i = pendinglast;
448
j = (i + 1) % NPENDINGCALLS;
Jul 17, 2002
Jul 17, 2002
449
if (j == pendingfirst) {
450
busy = 0;
Sep 14, 1994
Sep 14, 1994
451
return -1; /* Queue full */
Jul 17, 2002
Jul 17, 2002
452
}
Sep 14, 1994
Sep 14, 1994
453
pendingcalls[i].func = func;
454
pendingcalls[i].arg = arg;
455
pendinglast = j;
Sep 3, 2002
Sep 3, 2002
456
457
_Py_Ticker = 0;
May 5, 1997
May 5, 1997
458
things_to_do = 1; /* Signal main loop */
Sep 29, 1994
Sep 29, 1994
459
busy = 0;
Sep 14, 1994
Sep 14, 1994
460
/* XXX End critical section */
461
return 0;
462
}
463
Sep 29, 1994
Sep 29, 1994
464
int
Jul 22, 2000
Jul 22, 2000
465
Py_MakePendingCalls(void)
Sep 14, 1994
Sep 14, 1994
466
{
Sep 29, 1994
Sep 29, 1994
467
static int busy = 0;
Sep 14, 1994
Sep 14, 1994
468
#ifdef WITH_THREAD
Dec 21, 1998
Dec 21, 1998
469
if (main_thread && PyThread_get_thread_ident() != main_thread)
Sep 14, 1994
Sep 14, 1994
470
return 0;
471
#endif
May 5, 1997
May 5, 1997
472
if (busy)
Sep 29, 1994
Sep 29, 1994
473
return 0;
474
busy = 1;
May 5, 1997
May 5, 1997
475
things_to_do = 0;
Sep 14, 1994
Sep 14, 1994
476
for (;;) {
477
int i;
Jul 25, 2000
Jul 25, 2000
478
int (*func)(void *);
479
void *arg;
Sep 14, 1994
Sep 14, 1994
480
i = pendingfirst;
481
if (i == pendinglast)
482
break; /* Queue empty */
483
func = pendingcalls[i].func;
484
arg = pendingcalls[i].arg;
485
pendingfirst = (i + 1) % NPENDINGCALLS;
Sep 29, 1994
Sep 29, 1994
486
if (func(arg) < 0) {
487
busy = 0;
May 5, 1997
May 5, 1997
488
things_to_do = 1; /* We're not done yet */
Sep 14, 1994
Sep 14, 1994
489
return -1;
Sep 29, 1994
Sep 29, 1994
490
}
Sep 14, 1994
Sep 14, 1994
491
}
Sep 29, 1994
Sep 29, 1994
492
busy = 0;
Sep 14, 1994
Sep 14, 1994
493
return 0;
494
}
495
496
Aug 31, 2000
Aug 31, 2000
497
/* The interpreter's recursion limit */
498
Sep 1, 2000
Sep 1, 2000
499
static int recursion_limit = 1000;
Aug 31, 2000
Aug 31, 2000
500
Sep 1, 2000
Sep 1, 2000
501
int
502
Py_GetRecursionLimit(void)
Aug 31, 2000
Aug 31, 2000
503
{
504
return recursion_limit;
505
}
506
Sep 1, 2000
Sep 1, 2000
507
void
508
Py_SetRecursionLimit(int new_limit)
Aug 31, 2000
Aug 31, 2000
509
{
510
recursion_limit = new_limit;
511
}
512
Apr 4, 1991
Apr 4, 1991
513
/* Status code for main loop (reason for stack unwind) */
514
515
enum why_code {
516
WHY_NOT, /* No error */
517
WHY_EXCEPTION, /* Exception occurred */
518
WHY_RERAISE, /* Exception re-raised by 'finally' */
519
WHY_RETURN, /* 'return' statement */
Feb 1, 2001
Feb 1, 2001
520
WHY_BREAK, /* 'break' statement */
Jun 18, 2001
Jun 18, 2001
521
WHY_CONTINUE, /* 'continue' statement */
Oct 18, 2001
Oct 18, 2001
522
WHY_YIELD /* 'yield' operator */
Apr 4, 1991
Apr 4, 1991
523
};
Nov 18, 1990
Nov 18, 1990
524
Jul 9, 2000
Jul 9, 2000
525
static enum why_code do_raise(PyObject *, PyObject *, PyObject *);
Jun 21, 2001
Jun 21, 2001
526
static int unpack_iterable(PyObject *, int, PyObject **);
Jan 21, 1997
Jan 21, 1997
527
Sep 3, 2002
Sep 3, 2002
528
/* for manipulating the thread switch and periodic "stuff" - used to be
529
per thread, now just a pair o' globals */
Sep 3, 2002
Sep 3, 2002
530
int _Py_CheckInterval = 100;
531
volatile int _Py_Ticker = 100;
Nov 18, 1990
Nov 18, 1990
532
Apr 29, 1997
Apr 29, 1997
533
PyObject *
Jul 22, 2000
Jul 22, 2000
534
PyEval_EvalCode(PyCodeObject *co, PyObject *globals, PyObject *locals)
Jul 18, 1995
Jul 18, 1995
535
{
Feb 5, 2003
Feb 5, 2003
536
/* XXX raise SystemError if globals is NULL */
Aug 2, 2001
Aug 2, 2001
537
return PyEval_EvalCodeEx(co,
Jul 18, 1995
Jul 18, 1995
538
globals, locals,
Apr 29, 1997
Apr 29, 1997
539
(PyObject **)NULL, 0,
540
(PyObject **)NULL, 0,
Jan 25, 2001
Jan 25, 2001
541
(PyObject **)NULL, 0,
542
NULL);
Jul 18, 1995
Jul 18, 1995
543
}
544
545
546
/* Interpreter main loop */
547
Aug 2, 2001
Aug 2, 2001
548
static PyObject *
Jun 18, 2001
Jun 18, 2001
549
eval_frame(PyFrameObject *f)
Nov 18, 1990
Nov 18, 1990
550
{
Jan 24, 1997
Jan 24, 1997
551
#ifdef DXPAIRS
552
int lastopcode = 0;
553
#endif
Dec 19, 2001
Dec 19, 2001
554
PyObject **stack_pointer; /* Next free slot in value stack */
Apr 4, 1991
Apr 4, 1991
555
register unsigned char *next_instr;
Aug 7, 2000
Aug 7, 2000
556
register int opcode=0; /* Current opcode */
557
register int oparg=0; /* Current opcode argument, if any */
Apr 4, 1991
Apr 4, 1991
558
register enum why_code why; /* Reason for block stack unwind */
559
register int err; /* Error status -- nonzero if error */
Apr 29, 1997
Apr 29, 1997
560
register PyObject *x; /* Result object -- NULL if error */
561
register PyObject *v; /* Temporary objects popped off stack */
562
register PyObject *w;
563
register PyObject *u;
564
register PyObject *t;
Aug 21, 2000
Aug 21, 2000
565
register PyObject *stream = NULL; /* for PRINT opcodes */
Jan 29, 2001
Jan 29, 2001
566
register PyObject **fastlocals, **freevars;
Nov 23, 1998
Nov 23, 1998
567
PyObject *retval = NULL; /* Return value */
Dec 21, 1998
Dec 21, 1998
568
PyThreadState *tstate = PyThreadState_GET();
Jun 18, 2001
Jun 18, 2001
569
PyCodeObject *co;
Aug 15, 2002
Aug 15, 2002
570
571
/* when tracing we set things up so that
572
573
not (instr_lb <= current_bytecode_offset < instr_ub)
574
575
is true when the line being executed has changed. The
576
initial values are such as to make this false the first
577
time it is tested. */
578
int instr_ub = -1, instr_lb = 0;
579
Oct 7, 1998
Oct 7, 1998
580
unsigned char *first_instr;
Aug 4, 2002
Aug 4, 2002
581
PyObject *names;
582
PyObject *consts;
Jan 12, 1992
Jan 12, 1992
583
#ifdef LLTRACE
Apr 15, 1993
Apr 15, 1993
584
int lltrace;
Apr 4, 1991
Apr 4, 1991
585
#endif
Dec 30, 1996
Dec 30, 1996
586
#if defined(Py_DEBUG) || defined(LLTRACE)
Jul 18, 1995
Jul 18, 1995
587
/* Make it easier to find out where we are with a debugger */
Jun 18, 2001
Jun 18, 2001
588
char *filename;
Sep 3, 1992
Sep 3, 1992
589
#endif
Nov 18, 1990
Nov 18, 1990
590
Jul 14, 2002
Jul 14, 2002
591
/* Tuple access macros */
592
593
#ifndef Py_DEBUG
594
#define GETITEM(v, i) PyTuple_GET_ITEM((PyTupleObject *)(v), (i))
595
#else
596
#define GETITEM(v, i) PyTuple_GetItem((v), (i))
597
#endif
598
Apr 4, 1991
Apr 4, 1991
599
/* Code access macros */
Dec 20, 1990
Dec 20, 1990
600
Oct 7, 1998
Oct 7, 1998
601
#define INSTR_OFFSET() (next_instr - first_instr)
Apr 4, 1991
Apr 4, 1991
602
#define NEXTOP() (*next_instr++)
603
#define NEXTARG() (next_instr += 2, (next_instr[-1]<<8) + next_instr[-2])
Oct 7, 1998
Oct 7, 1998
604
#define JUMPTO(x) (next_instr = first_instr + (x))
Apr 4, 1991
Apr 4, 1991
605
#define JUMPBY(x) (next_instr += (x))
Dec 20, 1990
Dec 20, 1990
606
Mar 16, 2003
Mar 16, 2003
607
/* OpCode prediction macros
608
Some opcodes tend to come in pairs thus making it possible to predict
609
the second code when the first is run. For example, COMPARE_OP is often
610
followed by JUMP_IF_FALSE or JUMP_IF_TRUE. And, those opcodes are often
611
followed by a POP_TOP.
612
613
Verifying the prediction costs a single high-speed test of register
Mar 16, 2003
Mar 16, 2003
614
variable against a constant. If the pairing was good, then the
Mar 16, 2003
Mar 16, 2003
615
processor has a high likelihood of making its own successful branch
616
prediction which results in a nearly zero overhead transition to the
617
next opcode.
618
619
A successful prediction saves a trip through the eval-loop including
620
its two unpredictable branches, the HASARG test and the switch-case.
621
*/
622
Mar 16, 2003
Mar 16, 2003
623
#define PREDICT(op) if (*next_instr == op) goto PRED_##op
Mar 16, 2003
Mar 16, 2003
624
#define PREDICTED(op) PRED_##op: next_instr++
Mar 16, 2003
Mar 16, 2003
625
#define PREDICTED_WITH_ARG(op) PRED_##op: oparg = (next_instr[2]<<8) + \
626
next_instr[1]; next_instr += 3
Mar 16, 2003
Mar 16, 2003
627
Apr 4, 1991
Apr 4, 1991
628
/* Stack manipulation macros */
Nov 18, 1990
Nov 18, 1990
629
Apr 4, 1991
Apr 4, 1991
630
#define STACK_LEVEL() (stack_pointer - f->f_valuestack)
631
#define EMPTY() (STACK_LEVEL() == 0)
632
#define TOP() (stack_pointer[-1])
Jan 9, 2003
Jan 9, 2003
633
#define SECOND() (stack_pointer[-2])
634
#define THIRD() (stack_pointer[-3])
635
#define FOURTH() (stack_pointer[-4])
636
#define SET_TOP(v) (stack_pointer[-1] = (v))
637
#define SET_SECOND(v) (stack_pointer[-2] = (v))
638
#define SET_THIRD(v) (stack_pointer[-3] = (v))
639
#define SET_FOURTH(v) (stack_pointer[-4] = (v))
640
#define BASIC_STACKADJ(n) (stack_pointer += n)
Apr 4, 1991
Apr 4, 1991
641
#define BASIC_PUSH(v) (*stack_pointer++ = (v))
642
#define BASIC_POP() (*--stack_pointer)
Nov 18, 1990
Nov 18, 1990
643
Jan 12, 1992
Jan 12, 1992
644
#ifdef LLTRACE
Oct 17, 2001
Oct 17, 2001
645
#define PUSH(v) { (void)(BASIC_PUSH(v), \
646
lltrace && prtrace(TOP(), "push")); \
647
assert(STACK_LEVEL() <= f->f_stacksize); }
Oct 13, 2001
Oct 13, 2001
648
#define POP() ((void)(lltrace && prtrace(TOP(), "pop")), BASIC_POP())
Jan 9, 2003
Jan 9, 2003
649
#define STACKADJ(n) { (void)(BASIC_STACKADJ(n), \
650
lltrace && prtrace(TOP(), "stackadj")); \
651
assert(STACK_LEVEL() <= f->f_stacksize); }
Apr 4, 1991
Apr 4, 1991
652
#else
653
#define PUSH(v) BASIC_PUSH(v)
654
#define POP() BASIC_POP()
Jan 9, 2003
Jan 9, 2003
655
#define STACKADJ(n) BASIC_STACKADJ(n)
Apr 4, 1991
Apr 4, 1991
656
#endif
Nov 18, 1990
Nov 18, 1990
657
Jul 18, 1995
Jul 18, 1995
658
/* Local variable macros */
659
660
#define GETLOCAL(i) (fastlocals[i])
Mar 28, 2002
Mar 28, 2002
661
662
/* The SETLOCAL() macro must not DECREF the local variable in-place and
663
then store the new value; it must copy the old value to a temporary
664
value, then store the new value, and then DECREF the temporary value.
665
This is because it is possible that during the DECREF the frame is
666
accessed by other code (e.g. a __del__ method or gc.collect()) and the
667
variable would be pointing to already-freed memory. */
668
#define SETLOCAL(i, value) do { PyObject *tmp = GETLOCAL(i); \
669
GETLOCAL(i) = value; \
670
Py_XDECREF(tmp); } while (0)
Jul 18, 1995
Jul 18, 1995
671
May 5, 1997
May 5, 1997
672
/* Start of code */
673
Jun 18, 2001
Jun 18, 2001
674
if (f == NULL)
675
return NULL;
676
Jul 30, 1996
Jul 30, 1996
677
#ifdef USE_STACKCHECK
May 5, 1997
May 5, 1997
678
if (tstate->recursion_depth%10 == 0 && PyOS_CheckStack()) {
Apr 29, 1997
Apr 29, 1997
679
PyErr_SetString(PyExc_MemoryError, "Stack overflow");
Jul 30, 1996
Jul 30, 1996
680
return NULL;
681
}
682
#endif
683
Jun 18, 2001
Jun 18, 2001
684
/* push frame */
Aug 31, 2000
Aug 31, 2000
685
if (++tstate->recursion_depth > recursion_limit) {
May 5, 1997
May 5, 1997
686
--tstate->recursion_depth;
687
PyErr_SetString(PyExc_RuntimeError,
Oct 24, 2000
Oct 24, 2000
688
"maximum recursion depth exceeded");
May 5, 1997
May 5, 1997
689
tstate->frame = f->f_back;
Jul 30, 1996
Jul 30, 1996
690
return NULL;
691
}
692
Jun 18, 2001
Jun 18, 2001
693
tstate->frame = f;
694
Sep 4, 2001
Sep 4, 2001
695
if (tstate->use_tracing) {
696
if (tstate->c_tracefunc != NULL) {
697
/* tstate->c_tracefunc, if defined, is a
698
function that will be called on *every* entry
699
to a code block. Its return value, if not
700
None, is a function that will be called at
701
the start of each executed line of code.
702
(Actually, the function must return itself
703
in order to continue tracing.) The trace
704
functions are called with three arguments:
705
a pointer to the current frame, a string
706
indicating why the function is called, and
707
an argument which depends on the situation.
708
The global trace function is also called
709
whenever an exception is detected. */
710
if (call_trace(tstate->c_tracefunc, tstate->c_traceobj,
711
f, PyTrace_CALL, Py_None)) {
712
/* Trace function raised an error */
Oct 2, 2002
Oct 2, 2002
713
--tstate->recursion_depth;
714
tstate->frame = f->f_back;
Sep 4, 2001
Sep 4, 2001
715
return NULL;
716
}
717
}
718
if (tstate->c_profilefunc != NULL) {
719
/* Similar for c_profilefunc, except it needn't
720
return itself and isn't called for "line" events */
721
if (call_trace(tstate->c_profilefunc,
722
tstate->c_profileobj,
723
f, PyTrace_CALL, Py_None)) {
724
/* Profile function raised an error */
Oct 2, 2002
Oct 2, 2002
725
--tstate->recursion_depth;
726
tstate->frame = f->f_back;
Sep 4, 2001
Sep 4, 2001
727
return NULL;
728
}
729
}
730
}
731
Nov 8, 2002
Nov 8, 2002
732
co = f->f_code;
733
names = co->co_names;
734
consts = co->co_consts;
735
fastlocals = f->f_localsplus;
736
freevars = f->f_localsplus + f->f_nlocals;
737
_PyCode_GETCODEPTR(co, &first_instr);
738
/* An explanation is in order for the next line.
739
740
f->f_lasti now refers to the index of the last instruction
741
executed. You might think this was obvious from the name, but
742
this wasn't always true before 2.3! PyFrame_New now sets
743
f->f_lasti to -1 (i.e. the index *before* the first instruction)
744
and YIELD_VALUE doesn't fiddle with f_lasti any more. So this
745
does work. Promise. */
746
next_instr = first_instr + f->f_lasti + 1;
747
stack_pointer = f->f_stacktop;
748
assert(stack_pointer != NULL);
749
f->f_stacktop = NULL; /* remains NULL unless yield suspends frame */
750
Jun 18, 2001
Jun 18, 2001
751
#ifdef LLTRACE
752
lltrace = PyDict_GetItemString(f->f_globals,"__lltrace__") != NULL;
753
#endif
754
#if defined(Py_DEBUG) || defined(LLTRACE)
755
filename = PyString_AsString(co->co_filename);
756
#endif
Jan 17, 2001
Jan 17, 2001
757
Apr 4, 1991
Apr 4, 1991
758
why = WHY_NOT;
759
err = 0;
Apr 29, 1997
Apr 29, 1997
760
x = Py_None; /* Not a reference, just anything non-NULL */
Oct 11, 2000
Oct 11, 2000
761
w = NULL;
Jan 17, 2001
Jan 17, 2001
762
Apr 4, 1991
Apr 4, 1991
763
for (;;) {
Aug 15, 2002
Aug 15, 2002
764
assert(stack_pointer >= f->f_valuestack); /* else underflow */
765
assert(STACK_LEVEL() <= f->f_stacksize); /* else overflow */
766
May 5, 1997
May 5, 1997
767
/* Do periodic things. Doing this every time through
768
the loop would add too much overhead, so we do it
769
only every Nth instruction. We also do it if
770
``things_to_do'' is set, i.e. when an asynchronous
771
event needs attention (e.g. a signal handler or
772
async I/O handler); see Py_AddPendingCall() and
773
Py_MakePendingCalls() above. */
Jan 17, 2001
Jan 17, 2001
774
Sep 3, 2002
Sep 3, 2002
775
if (--_Py_Ticker < 0) {
Jun 28, 2003
Jun 28, 2003
776
if (*next_instr == SETUP_FINALLY) {
777
/* Make the last opcode before
778
a try: finally: block uninterruptable. */
779
goto fast_next_opcode;
780
}
Sep 3, 2002
Sep 3, 2002
781
_Py_Ticker = _Py_CheckInterval;
Nov 8, 2002
Nov 8, 2002
782
tstate->tick_counter++;
May 5, 1997
May 5, 1997
783
if (things_to_do) {
Jul 30, 1996
Jul 30, 1996
784
if (Py_MakePendingCalls() < 0) {
785
why = WHY_EXCEPTION;
786
goto on_error;
787
}
Dec 1, 2004
Dec 1, 2004
788
if (things_to_do)
789
/* MakePendingCalls() didn't succeed.
790
Force early re-execution of this
791
"periodic" code, possibly after
792
a thread switch */
793
_Py_Ticker = 0;
Jul 30, 1996
Jul 30, 1996
794
}
May 20, 1997
May 20, 1997
795
#if !defined(HAVE_SIGNAL_H) || defined(macintosh)
May 5, 1997
May 5, 1997
796
/* If we have true signals, the signal handler
797
will call Py_AddPendingCall() so we don't
Aug 15, 2002
Aug 15, 2002
798
have to call PyErr_CheckSignals(). On the
799
Mac and DOS, alas, we have to call it. */
Apr 29, 1997
Apr 29, 1997
800
if (PyErr_CheckSignals()) {
Apr 4, 1991
Apr 4, 1991
801
why = WHY_EXCEPTION;
802
goto on_error;
803
}
Jan 21, 1997
Jan 21, 1997
804
#endif
Aug 4, 1992
Aug 4, 1992
805
Aug 30, 1994
Aug 30, 1994
806
#ifdef WITH_THREAD
Aug 4, 1992
Aug 4, 1992
807
if (interpreter_lock) {
808
/* Give another thread a chance */
809
Aug 2, 1997
Aug 2, 1997
810
if (PyThreadState_Swap(NULL) != tstate)
811
Py_FatalError("ceval: tstate mix-up");
Dec 21, 1998
Dec 21, 1998
812
PyThread_release_lock(interpreter_lock);
Aug 4, 1992
Aug 4, 1992
813
814
/* Other threads may run now */
815
Dec 21, 1998
Dec 21, 1998
816
PyThread_acquire_lock(interpreter_lock, 1);
Aug 2, 1997
Aug 2, 1997
817
if (PyThreadState_Swap(tstate) != NULL)
818
Py_FatalError("ceval: orphan tstate");
Jun 28, 2003
Jun 28, 2003
819
820
/* Check for thread interrupts */
821
822
if (tstate->async_exc != NULL) {
823
x = tstate->async_exc;
824
tstate->async_exc = NULL;
825
PyErr_SetNone(x);
826
Py_DECREF(x);
827
why = WHY_EXCEPTION;
828
goto on_error;
829
}
Aug 4, 1992
Aug 4, 1992
830
}
831
#endif
Nov 18, 1990
Nov 18, 1990
832
}
Aug 4, 1992
Aug 4, 1992
833
Feb 17, 2002
Feb 17, 2002
834
fast_next_opcode:
Sep 3, 1992
Sep 3, 1992
835
f->f_lasti = INSTR_OFFSET();
Jan 17, 2001
Jan 17, 2001
836
Nov 8, 2002
Nov 8, 2002
837
/* line-by-line tracing support */
838
839
if (tstate->c_tracefunc != NULL && !tstate->tracing) {
840
/* see maybe_call_line_trace
841
for expository comments */
842
f->f_stacktop = stack_pointer;
Nov 8, 2002
Nov 8, 2002
843
Apr 29, 2003
Apr 29, 2003
844
err = maybe_call_line_trace(tstate->c_tracefunc,
845
tstate->c_traceobj,
846
f, &instr_lb, &instr_ub);
847
/* Reload possibly changed frame fields */
848
JUMPTO(f->f_lasti);
849
if (f->f_stacktop != NULL) {
850
stack_pointer = f->f_stacktop;
851
f->f_stacktop = NULL;
852
}
853
if (err) {
Nov 8, 2002
Nov 8, 2002
854
/* trace function raised an exception */
855
goto on_error;
856
}
Nov 8, 2002
Nov 8, 2002
857
}
858
859
/* Extract opcode and argument */
860
Apr 4, 1991
Apr 4, 1991
861
opcode = NEXTOP();
862
if (HAS_ARG(opcode))
863
oparg = NEXTARG();
Aug 24, 2000
Aug 24, 2000
864
dispatch_opcode:
Jan 24, 1997
Jan 24, 1997
865
#ifdef DYNAMIC_EXECUTION_PROFILE
866
#ifdef DXPAIRS
867
dxpairs[lastopcode][opcode]++;
868
lastopcode = opcode;
869
#endif
870
dxp[opcode]++;
871
#endif
Nov 18, 1990
Nov 18, 1990
872
Jan 12, 1992
Jan 12, 1992
873
#ifdef LLTRACE
Apr 4, 1991
Apr 4, 1991
874
/* Instruction tracing */
Jan 17, 2001
Jan 17, 2001
875
Jan 12, 1992
Jan 12, 1992
876
if (lltrace) {
Apr 4, 1991
Apr 4, 1991
877
if (HAS_ARG(opcode)) {
878
printf("%d: %d, %d\n",
Aug 15, 2002
Aug 15, 2002
879
f->f_lasti, opcode, oparg);
Apr 4, 1991
Apr 4, 1991
880
}
881
else {
882
printf("%d: %d\n",
Aug 15, 2002
Aug 15, 2002
883
f->f_lasti, opcode);
Apr 4, 1991
Apr 4, 1991
884
}
885
}
886
#endif
Aug 15, 2002
Aug 15, 2002
887
Dec 20, 1990
Dec 20, 1990
888
/* Main switch on opcode */
Jan 3, 2001
Jan 3, 2001
889
Dec 20, 1990
Dec 20, 1990
890
switch (opcode) {
Jan 17, 2001
Jan 17, 2001
891
Dec 20, 1990
Dec 20, 1990
892
/* BEWARE!
893
It is essential that any operation that fails sets either
894
x to NULL, err to nonzero, or why to anything but WHY_NOT,
895
and that no operation that succeeds does this! */
Jan 17, 2001
Jan 17, 2001
896
Dec 20, 1990
Dec 20, 1990
897
/* case STOP_CODE: this is an error! */
Jan 17, 2001
Jan 17, 2001
898
Feb 17, 2002
Feb 17, 2002
899
case LOAD_FAST:
900
x = GETLOCAL(oparg);
901
if (x != NULL) {
902
Py_INCREF(x);
903
PUSH(x);
904
goto fast_next_opcode;
905
}
906
format_exc_check_arg(PyExc_UnboundLocalError,
907
UNBOUNDLOCAL_ERROR_MSG,
908
PyTuple_GetItem(co->co_varnames, oparg));
909
break;
910
911
case LOAD_CONST:
Aug 4, 2002
Aug 4, 2002
912
x = GETITEM(consts, oparg);
Feb 17, 2002
Feb 17, 2002
913
Py_INCREF(x);
914
PUSH(x);
915
goto fast_next_opcode;
916
Mar 16, 2003
Mar 16, 2003
917
PREDICTED_WITH_ARG(STORE_FAST);
Feb 17, 2002
Feb 17, 2002
918
case STORE_FAST:
919
v = POP();
920
SETLOCAL(oparg, v);
921
goto fast_next_opcode;
922
Mar 16, 2003
Mar 16, 2003
923
PREDICTED(POP_TOP);
Nov 18, 1990
Nov 18, 1990
924
case POP_TOP:
925
v = POP();
Apr 29, 1997
Apr 29, 1997
926
Py_DECREF(v);
Feb 17, 2002
Feb 17, 2002
927
goto fast_next_opcode;
Jan 17, 2001
Jan 17, 2001
928
Nov 18, 1990
Nov 18, 1990
929
case ROT_TWO:
Jan 9, 2003
Jan 9, 2003
930
v = TOP();
931
w = SECOND();
932
SET_TOP(w);
933
SET_SECOND(v);
Mar 14, 2003
Mar 14, 2003
934
goto fast_next_opcode;
Jan 17, 2001
Jan 17, 2001
935
Nov 18, 1990
Nov 18, 1990
936
case ROT_THREE:
Jan 9, 2003
Jan 9, 2003
937
v = TOP();
938
w = SECOND();
939
x = THIRD();
940
SET_TOP(w);
941
SET_SECOND(x);
942
SET_THIRD(v);
Mar 14, 2003
Mar 14, 2003
943
goto fast_next_opcode;
Jan 17, 2001
Jan 17, 2001
944
Aug 24, 2000
Aug 24, 2000
945
case ROT_FOUR:
Jan 9, 2003
Jan 9, 2003
946
u = TOP();
947
v = SECOND();
948
w = THIRD();
949
x = FOURTH();
950
SET_TOP(v);
951
SET_SECOND(w);
952
SET_THIRD(x);
953
SET_FOURTH(u);
Mar 14, 2003
Mar 14, 2003
954
goto fast_next_opcode;
Jan 17, 2001
Jan 17, 2001
955
Dec 20, 1990
Dec 20, 1990
956
case DUP_TOP:
957
v = TOP();
Apr 29, 1997
Apr 29, 1997
958
Py_INCREF(v);
Dec 20, 1990
Dec 20, 1990
959
PUSH(v);
Mar 14, 2003
Mar 14, 2003
960
goto fast_next_opcode;
Jan 17, 2001
Jan 17, 2001
961
Aug 24, 2000
Aug 24, 2000
962
case DUP_TOPX:
Jan 19, 2003
Jan 19, 2003
963
if (oparg == 2) {
Jan 9, 2003
Jan 9, 2003
964
x = TOP();
Oct 11, 2000
Oct 11, 2000
965
Py_INCREF(x);
Jan 9, 2003
Jan 9, 2003
966
w = SECOND();
Oct 11, 2000
Oct 11, 2000
967
Py_INCREF(w);
Jan 9, 2003
Jan 9, 2003
968
STACKADJ(2);
969
SET_TOP(x);
970
SET_SECOND(w);
Mar 16, 2003
Mar 16, 2003
971
goto fast_next_opcode;
Jan 19, 2003
Jan 19, 2003
972
} else if (oparg == 3) {
Jan 9, 2003
Jan 9, 2003
973
x = TOP();
Oct 11, 2000
Oct 11, 2000
974
Py_INCREF(x);
Jan 9, 2003
Jan 9, 2003
975
w = SECOND();
Oct 11, 2000
Oct 11, 2000
976
Py_INCREF(w);
Jan 9, 2003
Jan 9, 2003
977
v = THIRD();
Oct 11, 2000
Oct 11, 2000
978
Py_INCREF(v);
Jan 9, 2003
Jan 9, 2003
979
STACKADJ(3);
980
SET_TOP(x);
981
SET_SECOND(w);
982
SET_THIRD(v);
Mar 16, 2003
Mar 16, 2003
983
goto fast_next_opcode;
Aug 24, 2000
Aug 24, 2000
984
}
Jan 19, 2003
Jan 19, 2003
985
Py_FatalError("invalid argument to DUP_TOPX"
986
" (bytecode corruption?)");
Oct 11, 2000
Oct 11, 2000
987
break;
Aug 24, 2000
Aug 24, 2000
988
Nov 18, 1990
Nov 18, 1990
989
case UNARY_POSITIVE:
Jan 9, 2003
Jan 9, 2003
990
v = TOP();
May 6, 1997
May 6, 1997
991
x = PyNumber_Positive(v);
Apr 29, 1997
Apr 29, 1997
992
Py_DECREF(v);
Jan 9, 2003
Jan 9, 2003
993
SET_TOP(x);
Jan 18, 1997
Jan 18, 1997
994
if (x != NULL) continue;
Nov 18, 1990
Nov 18, 1990
995
break;
Jan 17, 2001
Jan 17, 2001
996
Nov 18, 1990
Nov 18, 1990
997
case UNARY_NEGATIVE:
Jan 9, 2003
Jan 9, 2003
998
v = TOP();
May 6, 1997
May 6, 1997
999
x = PyNumber_Negative(v);
Apr 29, 1997
Apr 29, 1997
1000
Py_DECREF(v);