mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
#1535: rename __builtin__ module to builtins.
This commit is contained in:
parent
87f9c53937
commit
1a3284ed69
70 changed files with 246 additions and 247 deletions
|
@ -1851,7 +1851,7 @@ PyObject *
|
|||
_PyBuiltin_Init(void)
|
||||
{
|
||||
PyObject *mod, *dict, *debug;
|
||||
mod = Py_InitModule4("__builtin__", builtin_methods,
|
||||
mod = Py_InitModule4("builtins", builtin_methods,
|
||||
builtin_doc, (PyObject *)NULL,
|
||||
PYTHON_API_VERSION);
|
||||
if (mod == NULL)
|
||||
|
@ -1859,7 +1859,7 @@ _PyBuiltin_Init(void)
|
|||
dict = PyModule_GetDict(mod);
|
||||
|
||||
#ifdef Py_TRACE_REFS
|
||||
/* __builtin__ exposes a number of statically allocated objects
|
||||
/* "builtins" exposes a number of statically allocated objects
|
||||
* that, before this code was added in 2.3, never showed up in
|
||||
* the list of "all objects" maintained by Py_TRACE_REFS. As a
|
||||
* result, programs leaking references to None and False (etc)
|
||||
|
|
|
@ -645,7 +645,7 @@ PyErr_WriteUnraisable(PyObject *obj)
|
|||
else {
|
||||
char* modstr = PyUnicode_AsString(moduleName);
|
||||
if (modstr &&
|
||||
strcmp(modstr, "__builtin__") != 0)
|
||||
strcmp(modstr, "builtins") != 0)
|
||||
{
|
||||
PyFile_WriteString(modstr, f);
|
||||
PyFile_WriteString(".", f);
|
||||
|
|
|
@ -400,11 +400,11 @@ PyImport_Cleanup(void)
|
|||
deleted *last* of all, they would come too late in the normal
|
||||
destruction order. Sigh. */
|
||||
|
||||
value = PyDict_GetItemString(modules, "__builtin__");
|
||||
value = PyDict_GetItemString(modules, "builtins");
|
||||
if (value != NULL && PyModule_Check(value)) {
|
||||
dict = PyModule_GetDict(value);
|
||||
if (Py_VerboseFlag)
|
||||
PySys_WriteStderr("# clear __builtin__._\n");
|
||||
PySys_WriteStderr("# clear builtins._\n");
|
||||
PyDict_SetItemString(dict, "_", Py_None);
|
||||
}
|
||||
value = PyDict_GetItemString(modules, "sys");
|
||||
|
@ -436,11 +436,11 @@ PyImport_Cleanup(void)
|
|||
PyDict_SetItemString(modules, "__main__", Py_None);
|
||||
}
|
||||
|
||||
/* The special treatment of __builtin__ here is because even
|
||||
/* The special treatment of "builtins" here is because even
|
||||
when it's not referenced as a module, its dictionary is
|
||||
referenced by almost every module's __builtins__. Since
|
||||
deleting a module clears its dictionary (even if there are
|
||||
references left to it), we need to delete the __builtin__
|
||||
references left to it), we need to delete the "builtins"
|
||||
module last. Likewise, we don't delete sys until the very
|
||||
end because it is implicitly referenced (e.g. by print).
|
||||
|
||||
|
@ -451,7 +451,7 @@ PyImport_Cleanup(void)
|
|||
re-imported. */
|
||||
|
||||
/* Next, repeatedly delete modules with a reference count of
|
||||
one (skipping __builtin__ and sys) and delete them */
|
||||
one (skipping builtins and sys) and delete them */
|
||||
do {
|
||||
ndone = 0;
|
||||
pos = 0;
|
||||
|
@ -460,7 +460,7 @@ PyImport_Cleanup(void)
|
|||
continue;
|
||||
if (PyUnicode_Check(key) && PyModule_Check(value)) {
|
||||
name = PyUnicode_AsString(key);
|
||||
if (strcmp(name, "__builtin__") == 0)
|
||||
if (strcmp(name, "builtins") == 0)
|
||||
continue;
|
||||
if (strcmp(name, "sys") == 0)
|
||||
continue;
|
||||
|
@ -474,12 +474,12 @@ PyImport_Cleanup(void)
|
|||
}
|
||||
} while (ndone > 0);
|
||||
|
||||
/* Next, delete all modules (still skipping __builtin__ and sys) */
|
||||
/* Next, delete all modules (still skipping builtins and sys) */
|
||||
pos = 0;
|
||||
while (PyDict_Next(modules, &pos, &key, &value)) {
|
||||
if (PyUnicode_Check(key) && PyModule_Check(value)) {
|
||||
name = PyUnicode_AsString(key);
|
||||
if (strcmp(name, "__builtin__") == 0)
|
||||
if (strcmp(name, "builtins") == 0)
|
||||
continue;
|
||||
if (strcmp(name, "sys") == 0)
|
||||
continue;
|
||||
|
@ -490,7 +490,7 @@ PyImport_Cleanup(void)
|
|||
}
|
||||
}
|
||||
|
||||
/* Next, delete sys and __builtin__ (in that order) */
|
||||
/* Next, delete sys and builtins (in that order) */
|
||||
value = PyDict_GetItemString(modules, "sys");
|
||||
if (value != NULL && PyModule_Check(value)) {
|
||||
if (Py_VerboseFlag)
|
||||
|
@ -498,12 +498,12 @@ PyImport_Cleanup(void)
|
|||
_PyModule_Clear(value);
|
||||
PyDict_SetItemString(modules, "sys", Py_None);
|
||||
}
|
||||
value = PyDict_GetItemString(modules, "__builtin__");
|
||||
value = PyDict_GetItemString(modules, "builtins");
|
||||
if (value != NULL && PyModule_Check(value)) {
|
||||
if (Py_VerboseFlag)
|
||||
PySys_WriteStderr("# cleanup __builtin__\n");
|
||||
PySys_WriteStderr("# cleanup builtins\n");
|
||||
_PyModule_Clear(value);
|
||||
PyDict_SetItemString(modules, "__builtin__", Py_None);
|
||||
PyDict_SetItemString(modules, "builtins", Py_None);
|
||||
}
|
||||
|
||||
/* Finally, clear and delete the modules directory */
|
||||
|
@ -2491,7 +2491,7 @@ PyImport_Import(PyObject *module_name)
|
|||
/* No globals -- use standard builtins, and fake globals */
|
||||
PyErr_Clear();
|
||||
|
||||
builtins = PyImport_ImportModuleLevel("__builtin__",
|
||||
builtins = PyImport_ImportModuleLevel("builtins",
|
||||
NULL, NULL, NULL, 0);
|
||||
if (builtins == NULL)
|
||||
return NULL;
|
||||
|
|
|
@ -211,7 +211,7 @@ Py_InitializeEx(int install_sigs)
|
|||
|
||||
bimod = _PyBuiltin_Init();
|
||||
if (bimod == NULL)
|
||||
Py_FatalError("Py_Initialize: can't initialize __builtin__");
|
||||
Py_FatalError("Py_Initialize: can't initialize builtins modules");
|
||||
interp->builtins = PyModule_GetDict(bimod);
|
||||
if (interp->builtins == NULL)
|
||||
Py_FatalError("Py_Initialize: can't initialize builtins dict");
|
||||
|
@ -243,7 +243,7 @@ Py_InitializeEx(int install_sigs)
|
|||
_PyImport_Init();
|
||||
|
||||
/* phase 2 of builtins */
|
||||
_PyImport_FixupExtension("__builtin__", "__builtin__");
|
||||
_PyImport_FixupExtension("builtins", "builtins");
|
||||
|
||||
_PyImportHooks_Init();
|
||||
|
||||
|
@ -572,7 +572,7 @@ Py_NewInterpreter(void)
|
|||
interp->modules = PyDict_New();
|
||||
interp->modules_reloading = PyDict_New();
|
||||
|
||||
bimod = _PyImport_FindExtension("__builtin__", "__builtin__");
|
||||
bimod = _PyImport_FindExtension("builtins", "builtins");
|
||||
if (bimod != NULL) {
|
||||
interp->builtins = PyModule_GetDict(bimod);
|
||||
if (interp->builtins == NULL)
|
||||
|
@ -682,7 +682,7 @@ initmain(void)
|
|||
Py_FatalError("can't create __main__ module");
|
||||
d = PyModule_GetDict(m);
|
||||
if (PyDict_GetItemString(d, "__builtins__") == NULL) {
|
||||
PyObject *bimod = PyImport_ImportModule("__builtin__");
|
||||
PyObject *bimod = PyImport_ImportModule("builtins");
|
||||
if (bimod == NULL ||
|
||||
PyDict_SetItemString(d, "__builtins__", bimod) != 0)
|
||||
Py_FatalError("can't add __builtins__ to __main__");
|
||||
|
@ -717,7 +717,7 @@ initsite(void)
|
|||
}
|
||||
}
|
||||
|
||||
/* Initialize sys.stdin, stdout, stderr and __builtin__.open */
|
||||
/* Initialize sys.stdin, stdout, stderr and builtins.open */
|
||||
static int
|
||||
initstdio(void)
|
||||
{
|
||||
|
@ -739,7 +739,7 @@ initstdio(void)
|
|||
}
|
||||
Py_DECREF(m);
|
||||
|
||||
if (!(bimod = PyImport_ImportModule("__builtin__"))) {
|
||||
if (!(bimod = PyImport_ImportModule("builtins"))) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
@ -750,7 +750,7 @@ initstdio(void)
|
|||
goto error;
|
||||
}
|
||||
|
||||
/* Set __builtin__.open */
|
||||
/* Set builtins.open */
|
||||
if (PyObject_SetAttrString(bimod, "open", wrapper) == -1) {
|
||||
goto error;
|
||||
}
|
||||
|
@ -1362,7 +1362,7 @@ PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
|
|||
}
|
||||
else {
|
||||
char* modstr = PyUnicode_AsString(moduleName);
|
||||
if (modstr && strcmp(modstr, "__builtin__"))
|
||||
if (modstr && strcmp(modstr, "builtins"))
|
||||
{
|
||||
err = PyFile_WriteString(modstr, f);
|
||||
err += PyFile_WriteString(".", f);
|
||||
|
|
|
@ -72,10 +72,10 @@ sys_displayhook(PyObject *self, PyObject *o)
|
|||
PyObject *outf;
|
||||
PyInterpreterState *interp = PyThreadState_GET()->interp;
|
||||
PyObject *modules = interp->modules;
|
||||
PyObject *builtins = PyDict_GetItemString(modules, "__builtin__");
|
||||
PyObject *builtins = PyDict_GetItemString(modules, "builtins");
|
||||
|
||||
if (builtins == NULL) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "lost __builtin__");
|
||||
PyErr_SetString(PyExc_RuntimeError, "lost builtins module");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ sys_displayhook(PyObject *self, PyObject *o)
|
|||
PyDoc_STRVAR(displayhook_doc,
|
||||
"displayhook(object) -> None\n"
|
||||
"\n"
|
||||
"Print an object to sys.stdout and also save it in __builtin__.\n"
|
||||
"Print an object to sys.stdout and also save it in builtins.\n"
|
||||
);
|
||||
|
||||
static PyObject *
|
||||
|
@ -896,7 +896,7 @@ __excepthook__ -- the original excepthook; don't touch!\n\
|
|||
\n\
|
||||
Functions:\n\
|
||||
\n\
|
||||
displayhook() -- print an object to the screen, and save it in __builtin__._\n\
|
||||
displayhook() -- print an object to the screen, and save it in builtins._\n\
|
||||
excepthook() -- print an exception and its traceback to sys.stderr\n\
|
||||
exc_info() -- return thread-safe information about the current exception\n\
|
||||
exit() -- exit the interpreter by raising SystemExit\n\
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue