blob: 64fc52feb984dcb9d6a0a96fa5b01cdc93740fd2 [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001/***********************************************************
Guido van Rossum6610ad91995-01-04 19:07:38 +00002Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3The Netherlands.
Guido van Rossumf70e43a1991-02-19 12:39:46 +00004
5 All Rights Reserved
6
Guido van Rossumd266eb41996-10-25 14:44:06 +00007Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
Guido van Rossumf70e43a1991-02-19 12:39:46 +00009provided that the above copyright notice appear in all copies and that
Guido van Rossumd266eb41996-10-25 14:44:06 +000010both that copyright notice and this permission notice appear in
Guido van Rossumf70e43a1991-02-19 12:39:46 +000011supporting documentation, and that the names of Stichting Mathematisch
Guido van Rossumd266eb41996-10-25 14:44:06 +000012Centrum or CWI or Corporation for National Research Initiatives or
13CNRI not be used in advertising or publicity pertaining to
14distribution of the software without specific, written prior
15permission.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000016
Guido van Rossumd266eb41996-10-25 14:44:06 +000017While CWI is the initial source for this software, a modified version
18is made available by the Corporation for National Research Initiatives
19(CNRI) at the Internet address ftp://ftp.python.org.
20
21STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28PERFORMANCE OF THIS SOFTWARE.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000029
30******************************************************************/
31
Guido van Rossum3f5da241990-12-20 15:06:42 +000032/* Frame object implementation */
33
Guido van Rossum18752471997-04-29 14:49:28 +000034#include "Python.h"
Guido van Rossum3f5da241990-12-20 15:06:42 +000035
36#include "compile.h"
37#include "frameobject.h"
38#include "opcode.h"
39#include "structmember.h"
40
Guido van Rossum18752471997-04-29 14:49:28 +000041#define OFF(x) offsetof(PyFrameObject, x)
Guido van Rossum3f5da241990-12-20 15:06:42 +000042
43static struct memberlist frame_memberlist[] = {
Guido van Rossum1d5735e1994-08-30 08:27:36 +000044 {"f_back", T_OBJECT, OFF(f_back), RO},
45 {"f_code", T_OBJECT, OFF(f_code), RO},
Guido van Rossumc1134821995-01-10 10:39:16 +000046 {"f_builtins", T_OBJECT, OFF(f_builtins),RO},
Guido van Rossum1d5735e1994-08-30 08:27:36 +000047 {"f_globals", T_OBJECT, OFF(f_globals), RO},
48 {"f_locals", T_OBJECT, OFF(f_locals), RO},
Guido van Rossum1d5735e1994-08-30 08:27:36 +000049 {"f_lasti", T_INT, OFF(f_lasti), RO},
50 {"f_lineno", T_INT, OFF(f_lineno), RO},
Guido van Rossumc1134821995-01-10 10:39:16 +000051 {"f_restricted",T_INT, OFF(f_restricted),RO},
Guido van Rossum1d5735e1994-08-30 08:27:36 +000052 {"f_trace", T_OBJECT, OFF(f_trace)},
Guido van Rossuma027efa1997-05-05 20:56:21 +000053 {"f_exc_type", T_OBJECT, OFF(f_exc_type)},
54 {"f_exc_value", T_OBJECT, OFF(f_exc_value)},
55 {"f_exc_traceback", T_OBJECT, OFF(f_exc_traceback)},
Guido van Rossum3f5da241990-12-20 15:06:42 +000056 {NULL} /* Sentinel */
57};
58
Guido van Rossum18752471997-04-29 14:49:28 +000059static PyObject *
Guido van Rossum3f5da241990-12-20 15:06:42 +000060frame_getattr(f, name)
Guido van Rossum18752471997-04-29 14:49:28 +000061 PyFrameObject *f;
Guido van Rossum3f5da241990-12-20 15:06:42 +000062 char *name;
63{
Guido van Rossum1d5735e1994-08-30 08:27:36 +000064 if (strcmp(name, "f_locals") == 0)
Guido van Rossum18752471997-04-29 14:49:28 +000065 PyFrame_FastToLocals(f);
66 return PyMember_Get((char *)f, frame_memberlist, name);
Guido van Rossum3f5da241990-12-20 15:06:42 +000067}
68
Guido van Rossum1d5735e1994-08-30 08:27:36 +000069static int
70frame_setattr(f, name, value)
Guido van Rossum18752471997-04-29 14:49:28 +000071 PyFrameObject *f;
Guido van Rossum1d5735e1994-08-30 08:27:36 +000072 char *name;
Guido van Rossum18752471997-04-29 14:49:28 +000073 PyObject *value;
Guido van Rossum1d5735e1994-08-30 08:27:36 +000074{
Guido van Rossum18752471997-04-29 14:49:28 +000075 return PyMember_Set((char *)f, frame_memberlist, name, value);
Guido van Rossum1d5735e1994-08-30 08:27:36 +000076}
77
Guido van Rossuma9e7dc11992-10-18 18:53:57 +000078/* Stack frames are allocated and deallocated at a considerable rate.
79 In an attempt to improve the speed of function calls, we maintain a
80 separate free list of stack frames (just like integers are
81 allocated in a special way -- see intobject.c). When a stack frame
82 is on the free list, only the following members have a meaning:
83 ob_type == &Frametype
84 f_back next item on free list, or NULL
Guido van Rossumf3e85a01997-01-20 04:20:52 +000085 f_nlocals number of locals
86 f_stacksize size of value stack
Guido van Rossuma9e7dc11992-10-18 18:53:57 +000087 Note that the value and block stacks are preserved -- this can save
88 another malloc() call or two (and two free() calls as well!).
89 Also note that, unlike for integers, each frame object is a
90 malloc'ed object in its own right -- it is only the actual calls to
91 malloc() that we are trying to save here, not the administration.
92 After all, while a typical program may make millions of calls, a
93 call depth of more than 20 or 30 is probably already exceptional
94 unless the program contains run-away recursion. I hope.
95*/
96
Guido van Rossum18752471997-04-29 14:49:28 +000097static PyFrameObject *free_list = NULL;
Guido van Rossuma9e7dc11992-10-18 18:53:57 +000098
Guido van Rossum3f5da241990-12-20 15:06:42 +000099static void
100frame_dealloc(f)
Guido van Rossum18752471997-04-29 14:49:28 +0000101 PyFrameObject *f;
Guido van Rossum3f5da241990-12-20 15:06:42 +0000102{
Guido van Rossum7582bfb1997-02-14 16:27:29 +0000103 int i;
104 PyObject **fastlocals;
105
106 /* Kill all local variables */
107 fastlocals = f->f_localsplus;
108 for (i = f->f_nlocals; --i >= 0; ++fastlocals) {
Guido van Rossum18752471997-04-29 14:49:28 +0000109 Py_XDECREF(*fastlocals);
Guido van Rossum7582bfb1997-02-14 16:27:29 +0000110 }
111
Guido van Rossum18752471997-04-29 14:49:28 +0000112 Py_XDECREF(f->f_back);
113 Py_XDECREF(f->f_code);
114 Py_XDECREF(f->f_builtins);
115 Py_XDECREF(f->f_globals);
116 Py_XDECREF(f->f_locals);
117 Py_XDECREF(f->f_trace);
Guido van Rossuma027efa1997-05-05 20:56:21 +0000118 Py_XDECREF(f->f_exc_type);
119 Py_XDECREF(f->f_exc_value);
120 Py_XDECREF(f->f_exc_traceback);
Guido van Rossuma9e7dc11992-10-18 18:53:57 +0000121 f->f_back = free_list;
122 free_list = f;
Guido van Rossum3f5da241990-12-20 15:06:42 +0000123}
124
Guido van Rossum18752471997-04-29 14:49:28 +0000125PyTypeObject PyFrame_Type = {
126 PyObject_HEAD_INIT(&PyType_Type)
Guido van Rossum3f5da241990-12-20 15:06:42 +0000127 0,
128 "frame",
Guido van Rossum18752471997-04-29 14:49:28 +0000129 sizeof(PyFrameObject),
Guido van Rossum3f5da241990-12-20 15:06:42 +0000130 0,
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000131 (destructor)frame_dealloc, /*tp_dealloc*/
Guido van Rossum3f5da241990-12-20 15:06:42 +0000132 0, /*tp_print*/
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000133 (getattrfunc)frame_getattr, /*tp_getattr*/
134 (setattrfunc)frame_setattr, /*tp_setattr*/
Guido van Rossum3f5da241990-12-20 15:06:42 +0000135 0, /*tp_compare*/
136 0, /*tp_repr*/
137 0, /*tp_as_number*/
138 0, /*tp_as_sequence*/
139 0, /*tp_as_mapping*/
140};
141
Guido van Rossum18752471997-04-29 14:49:28 +0000142PyFrameObject *
Guido van Rossuma027efa1997-05-05 20:56:21 +0000143PyFrame_New(tstate, code, globals, locals)
144 PyThreadState *tstate;
Guido van Rossum18752471997-04-29 14:49:28 +0000145 PyCodeObject *code;
146 PyObject *globals;
147 PyObject *locals;
Guido van Rossum3f5da241990-12-20 15:06:42 +0000148{
Guido van Rossuma027efa1997-05-05 20:56:21 +0000149 PyFrameObject *back = tstate->frame;
Guido van Rossum18752471997-04-29 14:49:28 +0000150 static PyObject *builtin_object;
151 PyFrameObject *f;
152 PyObject *builtins;
Guido van Rossum67906af1998-09-25 14:11:46 +0000153 int extras;
Guido van Rossumf3e85a01997-01-20 04:20:52 +0000154
Sjoerd Mullender5b7f3cd1995-04-04 11:47:41 +0000155 if (builtin_object == NULL) {
Guido van Rossumb56933e1997-01-18 07:58:41 +0000156 builtin_object = PyString_InternFromString("__builtins__");
Sjoerd Mullender5b7f3cd1995-04-04 11:47:41 +0000157 if (builtin_object == NULL)
158 return NULL;
159 }
Guido van Rossum18752471997-04-29 14:49:28 +0000160 if ((back != NULL && !PyFrame_Check(back)) ||
161 code == NULL || !PyCode_Check(code) ||
162 globals == NULL || !PyDict_Check(globals) ||
163 (locals != NULL && !PyDict_Check(locals))) {
164 PyErr_BadInternalCall();
Guido van Rossum3f5da241990-12-20 15:06:42 +0000165 return NULL;
166 }
Guido van Rossum67906af1998-09-25 14:11:46 +0000167 extras = code->co_stacksize + code->co_nlocals;
Guido van Rossumbde6ff71998-02-19 20:48:26 +0000168 if (back == NULL || back->f_globals != globals) {
169 builtins = PyDict_GetItem(globals, builtin_object);
170 if (builtins != NULL && PyModule_Check(builtins))
171 builtins = PyModule_GetDict(builtins);
172 }
173 else {
174 /* If we share the globals, we share the builtins.
175 Save a lookup and a call. */
176 builtins = back->f_builtins;
177 }
Guido van Rossum404b95d1997-08-05 02:09:46 +0000178 if (builtins != NULL && !PyDict_Check(builtins))
179 builtins = NULL;
Guido van Rossuma9e7dc11992-10-18 18:53:57 +0000180 if (free_list == NULL) {
Guido van Rossum18752471997-04-29 14:49:28 +0000181 f = (PyFrameObject *)
182 malloc(sizeof(PyFrameObject) +
183 extras*sizeof(PyObject *));
Guido van Rossum2271bf71995-07-18 14:30:34 +0000184 if (f == NULL)
Guido van Rossum18752471997-04-29 14:49:28 +0000185 return (PyFrameObject *)PyErr_NoMemory();
186 f->ob_type = &PyFrame_Type;
187 _Py_NewReference(f);
Guido van Rossuma9e7dc11992-10-18 18:53:57 +0000188 }
189 else {
190 f = free_list;
191 free_list = free_list->f_back;
Guido van Rossumf3e85a01997-01-20 04:20:52 +0000192 if (f->f_nlocals + f->f_stacksize < extras) {
Guido van Rossum6345ac61997-10-31 20:32:13 +0000193 f = (PyFrameObject *)
194 realloc(f, sizeof(PyFrameObject) +
195 extras*sizeof(PyObject *));
Guido van Rossumf3e85a01997-01-20 04:20:52 +0000196 if (f == NULL)
Guido van Rossum18752471997-04-29 14:49:28 +0000197 return (PyFrameObject *)PyErr_NoMemory();
Guido van Rossumf3e85a01997-01-20 04:20:52 +0000198 }
Guido van Rossum747596a1997-01-24 04:00:21 +0000199 else
200 extras = f->f_nlocals + f->f_stacksize;
Guido van Rossum18752471997-04-29 14:49:28 +0000201 f->ob_type = &PyFrame_Type;
202 _Py_NewReference(f);
Guido van Rossuma9e7dc11992-10-18 18:53:57 +0000203 }
Guido van Rossum404b95d1997-08-05 02:09:46 +0000204 if (builtins == NULL) {
Guido van Rossumbde6ff71998-02-19 20:48:26 +0000205 /* No builtins! Make up a minimal one. */
Guido van Rossum404b95d1997-08-05 02:09:46 +0000206 builtins = PyDict_New();
Guido van Rossumf61618c1998-10-19 14:20:20 +0000207 if (builtins == NULL || /* Give them 'None', at least. */
208 PyDict_SetItemString(builtins, "None", Py_None) < 0) {
209 Py_DECREF(f);
Guido van Rossum404b95d1997-08-05 02:09:46 +0000210 return NULL;
Guido van Rossumf61618c1998-10-19 14:20:20 +0000211 }
Guido van Rossum404b95d1997-08-05 02:09:46 +0000212 }
213 else
214 Py_XINCREF(builtins);
215 f->f_builtins = builtins;
Guido van Rossum18752471997-04-29 14:49:28 +0000216 Py_XINCREF(back);
Guido van Rossum2271bf71995-07-18 14:30:34 +0000217 f->f_back = back;
Guido van Rossum18752471997-04-29 14:49:28 +0000218 Py_INCREF(code);
Guido van Rossum2271bf71995-07-18 14:30:34 +0000219 f->f_code = code;
Guido van Rossum18752471997-04-29 14:49:28 +0000220 Py_INCREF(globals);
Guido van Rossum2271bf71995-07-18 14:30:34 +0000221 f->f_globals = globals;
Guido van Rossumbdd207a1995-07-26 16:14:30 +0000222 if (code->co_flags & CO_NEWLOCALS) {
223 if (code->co_flags & CO_OPTIMIZED)
224 locals = NULL; /* Let fast_2_locals handle it */
225 else {
Guido van Rossum18752471997-04-29 14:49:28 +0000226 locals = PyDict_New();
Guido van Rossumbdd207a1995-07-26 16:14:30 +0000227 if (locals == NULL) {
Guido van Rossum18752471997-04-29 14:49:28 +0000228 Py_DECREF(f);
Guido van Rossumbdd207a1995-07-26 16:14:30 +0000229 return NULL;
230 }
Guido van Rossum3f5da241990-12-20 15:06:42 +0000231 }
Guido van Rossum3f5da241990-12-20 15:06:42 +0000232 }
Guido van Rossum2271bf71995-07-18 14:30:34 +0000233 else {
234 if (locals == NULL)
235 locals = globals;
Guido van Rossum18752471997-04-29 14:49:28 +0000236 Py_INCREF(locals);
Guido van Rossum2271bf71995-07-18 14:30:34 +0000237 }
238 f->f_locals = locals;
Guido van Rossumf3e85a01997-01-20 04:20:52 +0000239 f->f_trace = NULL;
Guido van Rossuma027efa1997-05-05 20:56:21 +0000240 f->f_exc_type = f->f_exc_value = f->f_exc_traceback = NULL;
Guido van Rossumeb46d671997-08-02 02:59:08 +0000241 f->f_tstate = tstate;
Guido van Rossumf3e85a01997-01-20 04:20:52 +0000242
Guido van Rossum2271bf71995-07-18 14:30:34 +0000243 f->f_lasti = 0;
Guido van Rossum747596a1997-01-24 04:00:21 +0000244 f->f_lineno = code->co_firstlineno;
Guido van Rossumeb46d671997-08-02 02:59:08 +0000245 f->f_restricted = (builtins != tstate->interp->builtins);
Guido van Rossumf3e85a01997-01-20 04:20:52 +0000246 f->f_iblock = 0;
247 f->f_nlocals = code->co_nlocals;
Guido van Rossum747596a1997-01-24 04:00:21 +0000248 f->f_stacksize = extras - code->co_nlocals;
Guido van Rossumf3e85a01997-01-20 04:20:52 +0000249
250 while (--extras >= 0)
251 f->f_localsplus[extras] = NULL;
252
253 f->f_valuestack = f->f_localsplus + f->f_nlocals;
254
Guido van Rossum3f5da241990-12-20 15:06:42 +0000255 return f;
256}
257
Guido van Rossum3f5da241990-12-20 15:06:42 +0000258/* Block management */
259
260void
Guido van Rossum18752471997-04-29 14:49:28 +0000261PyFrame_BlockSetup(f, type, handler, level)
262 PyFrameObject *f;
Guido van Rossum3f5da241990-12-20 15:06:42 +0000263 int type;
264 int handler;
265 int level;
266{
Guido van Rossum18752471997-04-29 14:49:28 +0000267 PyTryBlock *b;
Guido van Rossumf3e85a01997-01-20 04:20:52 +0000268 if (f->f_iblock >= CO_MAXBLOCKS)
Guido van Rossum18752471997-04-29 14:49:28 +0000269 Py_FatalError("XXX block stack overflow");
Guido van Rossum3f5da241990-12-20 15:06:42 +0000270 b = &f->f_blockstack[f->f_iblock++];
271 b->b_type = type;
272 b->b_level = level;
273 b->b_handler = handler;
274}
275
Guido van Rossum18752471997-04-29 14:49:28 +0000276PyTryBlock *
277PyFrame_BlockPop(f)
278 PyFrameObject *f;
Guido van Rossum3f5da241990-12-20 15:06:42 +0000279{
Guido van Rossum18752471997-04-29 14:49:28 +0000280 PyTryBlock *b;
Guido van Rossumd7047b31995-01-02 19:07:15 +0000281 if (f->f_iblock <= 0)
Guido van Rossum18752471997-04-29 14:49:28 +0000282 Py_FatalError("XXX block stack underflow");
Guido van Rossum3f5da241990-12-20 15:06:42 +0000283 b = &f->f_blockstack[--f->f_iblock];
284 return b;
285}
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000286
287/* Convert between "fast" version of locals and dictionary version */
288
289void
Guido van Rossum18752471997-04-29 14:49:28 +0000290PyFrame_FastToLocals(f)
291 PyFrameObject *f;
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000292{
Guido van Rossumf3e85a01997-01-20 04:20:52 +0000293 /* Merge fast locals into f->f_locals */
Guido van Rossum18752471997-04-29 14:49:28 +0000294 PyObject *locals, *map;
295 PyObject **fast;
296 PyObject *error_type, *error_value, *error_traceback;
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000297 int j;
298 if (f == NULL)
299 return;
Guido van Rossum2271bf71995-07-18 14:30:34 +0000300 locals = f->f_locals;
301 if (locals == NULL) {
Guido van Rossum18752471997-04-29 14:49:28 +0000302 locals = f->f_locals = PyDict_New();
Guido van Rossum2271bf71995-07-18 14:30:34 +0000303 if (locals == NULL) {
Guido van Rossum18752471997-04-29 14:49:28 +0000304 PyErr_Clear(); /* Can't report it :-( */
Guido van Rossum2271bf71995-07-18 14:30:34 +0000305 return;
306 }
307 }
Guido van Rossumf3e85a01997-01-20 04:20:52 +0000308 if (f->f_nlocals == 0)
Guido van Rossumbdd207a1995-07-26 16:14:30 +0000309 return;
310 map = f->f_code->co_varnames;
Guido van Rossum18752471997-04-29 14:49:28 +0000311 if (!PyDict_Check(locals) || !PyTuple_Check(map))
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000312 return;
Guido van Rossum18752471997-04-29 14:49:28 +0000313 PyErr_Fetch(&error_type, &error_value, &error_traceback);
Guido van Rossumf3e85a01997-01-20 04:20:52 +0000314 fast = f->f_localsplus;
Guido van Rossum18752471997-04-29 14:49:28 +0000315 j = PyTuple_Size(map);
Guido van Rossumf3e85a01997-01-20 04:20:52 +0000316 if (j > f->f_nlocals)
317 j = f->f_nlocals;
318 for (; --j >= 0; ) {
Guido van Rossum18752471997-04-29 14:49:28 +0000319 PyObject *key = PyTuple_GetItem(map, j);
320 PyObject *value = fast[j];
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000321 if (value == NULL) {
Guido van Rossum18752471997-04-29 14:49:28 +0000322 PyErr_Clear();
323 if (PyDict_DelItem(locals, key) != 0)
324 PyErr_Clear();
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000325 }
326 else {
Guido van Rossum18752471997-04-29 14:49:28 +0000327 if (PyDict_SetItem(locals, key, value) != 0)
328 PyErr_Clear();
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000329 }
330 }
Guido van Rossum18752471997-04-29 14:49:28 +0000331 PyErr_Restore(error_type, error_value, error_traceback);
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000332}
333
334void
Guido van Rossum18752471997-04-29 14:49:28 +0000335PyFrame_LocalsToFast(f, clear)
336 PyFrameObject *f;
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000337 int clear;
338{
Guido van Rossumf3e85a01997-01-20 04:20:52 +0000339 /* Merge f->f_locals into fast locals */
Guido van Rossum18752471997-04-29 14:49:28 +0000340 PyObject *locals, *map;
341 PyObject **fast;
342 PyObject *error_type, *error_value, *error_traceback;
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000343 int j;
344 if (f == NULL)
345 return;
346 locals = f->f_locals;
Guido van Rossum2271bf71995-07-18 14:30:34 +0000347 map = f->f_code->co_varnames;
Guido van Rossum3bb63a81997-01-20 04:29:16 +0000348 if (locals == NULL || f->f_code->co_nlocals == 0)
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000349 return;
Guido van Rossum18752471997-04-29 14:49:28 +0000350 if (!PyDict_Check(locals) || !PyTuple_Check(map))
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000351 return;
Guido van Rossum18752471997-04-29 14:49:28 +0000352 PyErr_Fetch(&error_type, &error_value, &error_traceback);
Guido van Rossumf3e85a01997-01-20 04:20:52 +0000353 fast = f->f_localsplus;
Guido van Rossum18752471997-04-29 14:49:28 +0000354 j = PyTuple_Size(map);
Guido van Rossumf3e85a01997-01-20 04:20:52 +0000355 if (j > f->f_nlocals)
356 j = f->f_nlocals;
357 for (; --j >= 0; ) {
Guido van Rossum18752471997-04-29 14:49:28 +0000358 PyObject *key = PyTuple_GetItem(map, j);
359 PyObject *value = PyDict_GetItem(locals, key);
Guido van Rossume23eb571998-05-14 01:49:48 +0000360 Py_XINCREF(value);
Guido van Rossumf3e85a01997-01-20 04:20:52 +0000361 if (value != NULL || clear) {
Guido van Rossum18752471997-04-29 14:49:28 +0000362 Py_XDECREF(fast[j]);
Guido van Rossumf3e85a01997-01-20 04:20:52 +0000363 fast[j] = value;
364 }
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000365 }
Guido van Rossum18752471997-04-29 14:49:28 +0000366 PyErr_Restore(error_type, error_value, error_traceback);
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000367}
Guido van Rossum404b95d1997-08-05 02:09:46 +0000368
369/* Clear out the free list */
370
371void
372PyFrame_Fini()
373{
374 while (free_list != NULL) {
375 PyFrameObject *f = free_list;
376 free_list = free_list->f_back;
377 PyMem_DEL(f);
378 }
379}