comparison Python/pythonrun.c @ 1263:65a1e4e9cd54 legacy-trunk

* Fixed some subtleties with fastlocals. You can no longer access f_fastlocals in a traceback object (this is a core dump hazard if there are <nil> entries), but instead eval_code() merges the fast locals back into the locals dictionary if it looks like the local variables will be retained. Also, the merge routines save exceptions since this is sometimes needed (alas!). * Added id() to bltinmodule.c, which returns an object's address (identity). Useful to walk arbitrary data structures containing cycles. * Added compile() to bltinmodule.c and compile_string() to pythonrun.[ch]: support to exec/eval arbitrary code objects. The code that defaults globals and locals is moved from run_node in pythonrun.c (which is now identical to eval_node) to eval_code in ceval.c. [XXX For elegance a clean-up session is necessary.]
author Guido van Rossum <guido@python.org>
date Tue, 30 Mar 1993 17:46:03 +0000
parents f820e6917f07
children e0464e7115ca
comparison
equal deleted inserted replaced
1262:f820e6917f07 1263:65a1e4e9cd54
261 261
262 object * 262 object *
263 run_string(str, start, globals, locals) 263 run_string(str, start, globals, locals)
264 char *str; 264 char *str;
265 int start; 265 int start;
266 /*dict*/object *globals, *locals; 266 object *globals, *locals;
267 { 267 {
268 node *n; 268 node *n;
269 int err; 269 int err;
270 err = parse_string(str, start, &n); 270 err = parse_string(str, start, &n);
271 return run_err_node(err, n, "<string>", globals, locals); 271 return run_err_node(err, n, "<string>", globals, locals);
274 object * 274 object *
275 run_file(fp, filename, start, globals, locals) 275 run_file(fp, filename, start, globals, locals)
276 FILE *fp; 276 FILE *fp;
277 char *filename; 277 char *filename;
278 int start; 278 int start;
279 /*dict*/object *globals, *locals; 279 object *globals, *locals;
280 { 280 {
281 node *n; 281 node *n;
282 int err; 282 int err;
283 err = parse_file(fp, filename, start, &n); 283 err = parse_file(fp, filename, start, &n);
284 return run_err_node(err, n, filename, globals, locals); 284 return run_err_node(err, n, filename, globals, locals);
287 object * 287 object *
288 run_err_node(err, n, filename, globals, locals) 288 run_err_node(err, n, filename, globals, locals)
289 int err; 289 int err;
290 node *n; 290 node *n;
291 char *filename; 291 char *filename;
292 /*dict*/object *globals, *locals; 292 object *globals, *locals;
293 { 293 {
294 if (err != E_DONE) { 294 if (err != E_DONE) {
295 err_input(err); 295 err_input(err);
296 return NULL; 296 return NULL;
297 } 297 }
300 300
301 object * 301 object *
302 run_node(n, filename, globals, locals) 302 run_node(n, filename, globals, locals)
303 node *n; 303 node *n;
304 char *filename; 304 char *filename;
305 /*dict*/object *globals, *locals; 305 object *globals, *locals;
306 { 306 {
307 object *res; 307 return eval_node(n, filename, globals, locals);
308 int needmerge = 0;
309 if (globals == NULL) {
310 globals = getglobals();
311 if (locals == NULL) {
312 locals = getlocals();
313 needmerge = 1;
314 }
315 }
316 else {
317 if (locals == NULL)
318 locals = globals;
319 }
320 res = eval_node(n, filename, globals, locals);
321 if (needmerge)
322 mergelocals();
323 return res;
324 } 308 }
325 309
326 object * 310 object *
327 eval_node(n, filename, globals, locals) 311 eval_node(n, filename, globals, locals)
328 node *n; 312 node *n;
337 if (co == NULL) 321 if (co == NULL)
338 return NULL; 322 return NULL;
339 v = eval_code(co, globals, locals, (object *)NULL); 323 v = eval_code(co, globals, locals, (object *)NULL);
340 DECREF(co); 324 DECREF(co);
341 return v; 325 return v;
326 }
327
328 object *
329 compile_string(str, filename, start)
330 char *str;
331 char *filename;
332 int start;
333 {
334 node *n;
335 int err;
336 codeobject *co;
337 err = parse_string(str, start, &n);
338 if (err != E_DONE) {
339 err_input(err);
340 return NULL;
341 }
342 co = compile(n, filename);
343 freetree(n);
344 return (object *)co;
342 } 345 }
343 346
344 /* Simplified interface to parsefile */ 347 /* Simplified interface to parsefile */
345 348
346 int 349 int