__builtins__ mods (and sys_checkinterval for ceval.c)
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 59e15e1..5577f03 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -392,6 +392,17 @@
 			&Mappingtype, &globals,
 			&Mappingtype, &locals))
 		return NULL;
+	if (globals == NULL) {
+		globals = getglobals();
+		if (globals == NULL)
+			return NULL;
+	}
+	if (locals == NULL)
+		locals = globals;
+	if (dictlookup(globals, "__builtins__") == NULL) {
+		if (dictinsert(globals, "__builtins__", getbuiltins()) != 0)
+			return NULL;
+	}
 	if (is_codeobject(cmd))
 		return eval_code((codeobject *) cmd, globals, locals,
 				 (object *)NULL, (object *)NULL);
@@ -428,6 +439,17 @@
 			&Mappingtype, &globals,
 			&Mappingtype, &locals))
 		return NULL;
+	if (globals == NULL) {
+		globals = getglobals();
+		if (globals == NULL)
+			return NULL;
+	}
+	if (locals == NULL)
+		locals = globals;
+	if (dictlookup(globals, "__builtins__") == NULL) {
+		if (dictinsert(globals, "__builtins__", getbuiltins()) != 0)
+			return NULL;
+	}
 	BGN_SAVE
 	fp = fopen(filename, "r");
 	END_SAVE
@@ -725,6 +747,7 @@
 	object *line;
 	char *str;
 	object *res;
+	object *globals, *locals;
 
 	line = builtin_raw_input(self, args);
 	if (line == NULL)
@@ -733,7 +756,13 @@
 		return NULL;
 	while (*str == ' ' || *str == '\t')
 			str++;
-	res = run_string(str, eval_input, (object *)NULL, (object *)NULL);
+	globals = getglobals();
+	locals = getlocals();
+	if (dictlookup(globals, "__builtins__") == NULL) {
+		if (dictinsert(globals, "__builtins__", getbuiltins()) != 0)
+			return NULL;
+	}
+	res = run_string(str, eval_input, globals, locals);
 	DECREF(line);
 	return res;
 }
@@ -1363,25 +1392,9 @@
 static object *builtin_dict;
 
 object *
-getbuiltin(name)
-	object *name;
+getbuiltindict()
 {
-	return mappinglookup(builtin_dict, name);
-}
-
-object *
-getbuiltins(name)
-	char *name;
-{
-	return dictlookup(builtin_dict, name);
-}
-
-int
-setbuiltin(cname, value)
-	char *cname;
-	object *value;
-{
-	return dictinsert(builtin_dict, cname, value);
+	return builtin_dict;
 }
 
 /* Predefined exceptions */
diff --git a/Python/ceval.c b/Python/ceval.c
index 410384e..79874ef 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -33,7 +33,6 @@
 #include "eval.h"
 #include "ceval.h"
 #include "opcode.h"
-#include "bltinmodule.h"
 #include "traceback.h"
 #include "graminit.h"
 #include "pythonrun.h"
@@ -285,7 +284,6 @@
 	char *name;		/* Name used by some instructions */
 	int needmerge = 0;	/* Set if need to merge locals back at end */
 	int defmode = 0;	/* Default access mode for new variables */
-	int ticker_count = 10;	/* Check for intr every Nth instruction */
 #ifdef LLTRACE
 	int lltrace;
 #endif
@@ -325,16 +323,9 @@
 #define POP()		BASIC_POP()
 #endif
 
-	if (globals == NULL) {
-		globals = getglobals();
-		if (locals == NULL) {
-			locals = getlocals();
-			needmerge = 1;
-		}
-	}
-	else {
-		if (locals == NULL)
-			locals = globals;
+	if (globals == NULL || locals == NULL) {
+		err_setstr(SystemError, "eval_code: NULL globals or locals");
+		return NULL;
 	}
 
 #ifdef LLTRACE
@@ -385,10 +376,6 @@
 		}
 	}
 
-	x = sysget("check_interval");
-	if (x != NULL && is_intobject(x))
-		ticker_count = getintvalue(x);
-	
 	next_instr = GETUSTRINGVALUE(f->f_code->co_code);
 	stack_pointer = f->f_valuestack;
 	
@@ -417,7 +404,7 @@
 		}
 		
 		if (--ticker < 0) {
-			ticker = ticker_count;
+			ticker = sys_checkinterval;
 			if (sigcheck()) {
 				why = WHY_EXCEPTION;
 				goto on_error;
@@ -745,7 +732,7 @@
 			/* Print value except if procedure result */
 			/* Before printing, also assign to '_' */
 			if (v != None &&
-			    (err = setbuiltin("_", v)) == 0 &&
+			    (err = dictinsert(f->f_builtins, "_", v)) == 0 &&
 			    !suppress_print) {
 				flushline();
 				x = sysget("stdout");
@@ -1157,7 +1144,7 @@
 				x = dict2lookup(f->f_globals, w);
 				if (x == NULL) {
 					err_clear();
-					x = getbuiltin(w);
+					x = dict2lookup(f->f_builtins, w);
 					if (x == NULL) {
 						err_setval(NameError, w);
 						break;
@@ -1179,7 +1166,7 @@
 			x = dict2lookup(f->f_globals, w);
 			if (x == NULL) {
 				err_clear();
-				x = getbuiltin(w);
+				x = dict2lookup(f->f_builtins, w);
 				if (x == NULL) {
 					err_setval(NameError, w);
 					break;
@@ -1324,7 +1311,7 @@
 		
 		case IMPORT_NAME:
 			w = GETNAMEV(oparg);
-			x = getbuiltins("__import__");
+			x = dictlookup(f->f_builtins, "__import__");
 			if (x == NULL) {
 				err_setstr(ImportError,
 					   "__import__ not found");
@@ -1701,6 +1688,15 @@
 }
 
 object *
+getbuiltins()
+{
+	if (current_frame == NULL)
+		return NULL;
+	else
+		return current_frame->f_builtins;
+}
+
+object *
 getlocals()
 {
 	if (current_frame == NULL)
@@ -1733,6 +1729,12 @@
 	return (object *)current_frame;
 }
 
+int
+getrestricted()
+{
+	return current_frame == NULL ? 0 : current_frame->f_restricted;
+}
+
 void
 flushline()
 {
@@ -2660,6 +2662,8 @@
 		    "exec 2nd/3rd args must be dict or None");
 		return -1;
 	}
+	if (dictlookup(globals, "__builtins__") == NULL)
+		dictinsert(globals, "__builtins__", current_frame->f_builtins);
 	if (is_codeobject(prog)) {
 		if (eval_code((codeobject *) prog, globals, locals,
 				 (object *)NULL, (object *)NULL) == NULL)
diff --git a/Python/import.c b/Python/import.c
index ef24883..1d9ea35 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -32,6 +32,7 @@
 #include "import.h"
 #include "errcode.h"
 #include "sysmodule.h"
+#include "bltinmodule.h"
 #include "pythonrun.h"
 #include "marshal.h"
 #include "compile.h"
@@ -147,6 +148,10 @@
 	if (m == NULL)
 		return NULL;
 	d = getmoduledict(m);
+	if (dictlookup(d, "__builtins__") == NULL) {
+		if (dictinsert(d, "__builtins__", getbuiltindict()) != 0)
+			return NULL;
+	}
 	v = eval_code((codeobject *)co, d, d, d, (object *)NULL);
 	if (v == NULL)
 		return NULL;
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index c706081..a25cbba 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -32,6 +32,7 @@
 #include "graminit.h"
 #include "errcode.h"
 #include "sysmodule.h"
+#include "bltinmodule.h"
 #include "compile.h"
 #include "eval.h"
 #include "ceval.h"
@@ -48,6 +49,7 @@
 extern grammar gram; /* From graminit.c */
 
 /* Forward */
+static void initmain PROTO((void));
 static object *run_err_node PROTO((node *n, char *filename,
 				   object *globals, object *locals));
 static object *run_node PROTO((node *n, char *filename,
@@ -83,6 +85,24 @@
 	setpythonpath(getpythonpath());
 
 	initsigs(); /* Signal handling stuff, including initintr() */
+
+	initmain();
+}
+
+/* Create __main__ module */
+
+static void
+initmain()
+{
+	object *m, *d;
+	m = add_module("__main__");
+	if (m == NULL)
+		fatal("can't create __main__ module");
+	d = getmoduledict(m);
+	if (dictlookup(d, "__builtins__") == NULL) {
+		if (dictinsert(d, "__builtins__", getbuiltindict()))
+			fatal("can't add __builtins__ to __main__");
+	}
 }
 
 /* Parse input from a file and execute it */