Index: Python/pythonrun.c =================================================================== --- Python/pythonrun.c (révision 67065) +++ Python/pythonrun.c (copie de travail) @@ -884,6 +884,22 @@ return PyRun_SimpleFileExFlags(fp, filename, closeit, flags); } +static void +PyRun_InteractiveCleanup(void) +{ + PyObject *value, *dict; + PyInterpreterState *interp = PyThreadState_GET()->interp; + PyObject *modules = interp->modules; + + value = PyDict_GetItemString(modules, "builtins"); + if (value != NULL && PyModule_Check(value)) { + dict = PyModule_GetDict(value); + if (Py_VerboseFlag) + PySys_WriteStderr("# clear builtins._\n"); + PyDict_SetItemString(dict, "_", Py_None); + } +} + int PyRun_InteractiveLoopFlags(FILE *fp, const char *filename, PyCompilerFlags *flags) { @@ -908,13 +924,19 @@ for (;;) { ret = PyRun_InteractiveOneFlags(fp, filename, flags); PRINT_TOTAL_REFS(); - if (ret == E_EOF) - return 0; + if (ret == E_EOF) { + ret = 0; + break; + } /* - if (ret == E_NOMEM) - return -1; + if (ret == E_NOMEM) { + ret = 1; + break; + } */ } + PyRun_InteractiveCleanup(); + return ret; } /* compute parser flags based on compiler flags */