mirror of
https://github.com/python/cpython.git
synced 2025-07-12 13:55:34 +00:00
* 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.]
This commit is contained in:
parent
8b17d6bd89
commit
5b7221849e
5 changed files with 117 additions and 36 deletions
|
@ -263,7 +263,7 @@ object *
|
|||
run_string(str, start, globals, locals)
|
||||
char *str;
|
||||
int start;
|
||||
/*dict*/object *globals, *locals;
|
||||
object *globals, *locals;
|
||||
{
|
||||
node *n;
|
||||
int err;
|
||||
|
@ -276,7 +276,7 @@ run_file(fp, filename, start, globals, locals)
|
|||
FILE *fp;
|
||||
char *filename;
|
||||
int start;
|
||||
/*dict*/object *globals, *locals;
|
||||
object *globals, *locals;
|
||||
{
|
||||
node *n;
|
||||
int err;
|
||||
|
@ -289,7 +289,7 @@ run_err_node(err, n, filename, globals, locals)
|
|||
int err;
|
||||
node *n;
|
||||
char *filename;
|
||||
/*dict*/object *globals, *locals;
|
||||
object *globals, *locals;
|
||||
{
|
||||
if (err != E_DONE) {
|
||||
err_input(err);
|
||||
|
@ -302,25 +302,9 @@ object *
|
|||
run_node(n, filename, globals, locals)
|
||||
node *n;
|
||||
char *filename;
|
||||
/*dict*/object *globals, *locals;
|
||||
object *globals, *locals;
|
||||
{
|
||||
object *res;
|
||||
int needmerge = 0;
|
||||
if (globals == NULL) {
|
||||
globals = getglobals();
|
||||
if (locals == NULL) {
|
||||
locals = getlocals();
|
||||
needmerge = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (locals == NULL)
|
||||
locals = globals;
|
||||
}
|
||||
res = eval_node(n, filename, globals, locals);
|
||||
if (needmerge)
|
||||
mergelocals();
|
||||
return res;
|
||||
return eval_node(n, filename, globals, locals);
|
||||
}
|
||||
|
||||
object *
|
||||
|
@ -341,6 +325,25 @@ eval_node(n, filename, globals, locals)
|
|||
return v;
|
||||
}
|
||||
|
||||
object *
|
||||
compile_string(str, filename, start)
|
||||
char *str;
|
||||
char *filename;
|
||||
int start;
|
||||
{
|
||||
node *n;
|
||||
int err;
|
||||
codeobject *co;
|
||||
err = parse_string(str, start, &n);
|
||||
if (err != E_DONE) {
|
||||
err_input(err);
|
||||
return NULL;
|
||||
}
|
||||
co = compile(n, filename);
|
||||
freetree(n);
|
||||
return (object *)co;
|
||||
}
|
||||
|
||||
/* Simplified interface to parsefile */
|
||||
|
||||
int
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue