@@ -33,7 +33,6 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3333#include "eval.h"
3434#include "ceval.h"
3535#include "opcode.h"
36- #include "bltinmodule.h"
3736#include "traceback.h"
3837#include "graminit.h"
3938#include "pythonrun.h"
@@ -285,7 +284,6 @@ eval_code(co, globals, locals, owner, arg)
285284 char * name ; /* Name used by some instructions */
286285 int needmerge = 0 ; /* Set if need to merge locals back at end */
287286 int defmode = 0 ; /* Default access mode for new variables */
288- int ticker_count = 10 ; /* Check for intr every Nth instruction */
289287#ifdef LLTRACE
290288 int lltrace ;
291289#endif
@@ -325,16 +323,9 @@ eval_code(co, globals, locals, owner, arg)
325323#define POP () BASIC_POP()
326324#endif
327325
328- if (globals == NULL ) {
329- globals = getglobals ();
330- if (locals == NULL ) {
331- locals = getlocals ();
332- needmerge = 1 ;
333- }
334- }
335- else {
336- if (locals == NULL )
337- locals = globals ;
326+ if (globals == NULL || locals == NULL ) {
327+ err_setstr (SystemError , "eval_code: NULL globals or locals" );
328+ return NULL ;
338329 }
339330
340331#ifdef LLTRACE
@@ -385,10 +376,6 @@ eval_code(co, globals, locals, owner, arg)
385376 }
386377 }
387378
388- x = sysget ("check_interval" );
389- if (x != NULL && is_intobject (x ))
390- ticker_count = getintvalue (x );
391-
392379 next_instr = GETUSTRINGVALUE (f -> f_code -> co_code );
393380 stack_pointer = f -> f_valuestack ;
394381
@@ -417,7 +404,7 @@ eval_code(co, globals, locals, owner, arg)
417404 }
418405
419406 if (-- ticker < 0 ) {
420- ticker = ticker_count ;
407+ ticker = sys_checkinterval ;
421408 if (sigcheck ()) {
422409 why = WHY_EXCEPTION ;
423410 goto on_error ;
@@ -745,7 +732,7 @@ eval_code(co, globals, locals, owner, arg)
745732 /* Print value except if procedure result */
746733 /* Before printing, also assign to '_' */
747734 if (v != None &&
748- (err = setbuiltin ( "_" , v )) == 0 &&
735+ (err = dictinsert ( f -> f_builtins , "_" , v )) == 0 &&
749736 !suppress_print ) {
750737 flushline ();
751738 x = sysget ("stdout" );
@@ -1157,7 +1144,7 @@ eval_code(co, globals, locals, owner, arg)
11571144 x = dict2lookup (f -> f_globals , w );
11581145 if (x == NULL ) {
11591146 err_clear ();
1160- x = getbuiltin ( w );
1147+ x = dict2lookup ( f -> f_builtins , w );
11611148 if (x == NULL ) {
11621149 err_setval (NameError , w );
11631150 break ;
@@ -1179,7 +1166,7 @@ eval_code(co, globals, locals, owner, arg)
11791166 x = dict2lookup (f -> f_globals , w );
11801167 if (x == NULL ) {
11811168 err_clear ();
1182- x = getbuiltin ( w );
1169+ x = dict2lookup ( f -> f_builtins , w );
11831170 if (x == NULL ) {
11841171 err_setval (NameError , w );
11851172 break ;
@@ -1324,7 +1311,7 @@ eval_code(co, globals, locals, owner, arg)
13241311
13251312 case IMPORT_NAME :
13261313 w = GETNAMEV (oparg );
1327- x = getbuiltins ( "__import__" );
1314+ x = dictlookup ( f -> f_builtins , "__import__" );
13281315 if (x == NULL ) {
13291316 err_setstr (ImportError ,
13301317 "__import__ not found" );
@@ -1700,6 +1687,15 @@ call_trace(p_trace, p_newtrace, f, msg, arg)
17001687 }
17011688}
17021689
1690+ object *
1691+ getbuiltins ()
1692+ {
1693+ if (current_frame == NULL )
1694+ return NULL ;
1695+ else
1696+ return current_frame -> f_builtins ;
1697+ }
1698+
17031699object *
17041700getlocals ()
17051701{
@@ -1733,6 +1729,12 @@ getframe()
17331729 return (object * )current_frame ;
17341730}
17351731
1732+ int
1733+ getrestricted ()
1734+ {
1735+ return current_frame == NULL ? 0 : current_frame -> f_restricted ;
1736+ }
1737+
17361738void
17371739flushline ()
17381740{
@@ -2660,6 +2662,8 @@ exec_statement(prog, globals, locals)
26602662 "exec 2nd/3rd args must be dict or None" );
26612663 return -1 ;
26622664 }
2665+ if (dictlookup (globals , "__builtins__" ) == NULL )
2666+ dictinsert (globals , "__builtins__" , current_frame -> f_builtins );
26632667 if (is_codeobject (prog )) {
26642668 if (eval_code ((codeobject * ) prog , globals , locals ,
26652669 (object * )NULL , (object * )NULL ) == NULL )
0 commit comments