_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.

This commit is contained in:
Tim Peters 2001-09-13 21:37:17 +00:00
parent 8fa45677c1
commit 4b7625ee83

View file

@ -1837,58 +1837,33 @@ _PyBuiltin_Init(void)
if (mod == NULL) if (mod == NULL)
return NULL; return NULL;
dict = PyModule_GetDict(mod); dict = PyModule_GetDict(mod);
if (PyDict_SetItemString(dict, "None", Py_None) < 0)
return NULL; #define SETBUILTIN(NAME, OBJECT) \
if (PyDict_SetItemString(dict, "Ellipsis", Py_Ellipsis) < 0) if (PyDict_SetItemString(dict, NAME, (PyObject *)OBJECT) < 0) \
return NULL; return NULL
if (PyDict_SetItemString(dict, "NotImplemented",
Py_NotImplemented) < 0) SETBUILTIN("None", Py_None);
return NULL; SETBUILTIN("Ellipsis", Py_Ellipsis);
if (PyDict_SetItemString(dict, "classmethod", SETBUILTIN("NotImplemented", Py_NotImplemented);
(PyObject *) &PyClassMethod_Type) < 0) SETBUILTIN("classmethod", &PyClassMethod_Type);
return NULL;
#ifndef WITHOUT_COMPLEX #ifndef WITHOUT_COMPLEX
if (PyDict_SetItemString(dict, "complex", SETBUILTIN("complex", &PyComplex_Type);
(PyObject *) &PyComplex_Type) < 0)
return NULL;
#endif #endif
if (PyDict_SetItemString(dict, "dictionary", SETBUILTIN("dictionary", &PyDict_Type);
(PyObject *) &PyDict_Type) < 0) SETBUILTIN("float", &PyFloat_Type);
return NULL; SETBUILTIN("property", &PyProperty_Type);
if (PyDict_SetItemString(dict, "float", SETBUILTIN("int", &PyInt_Type);
(PyObject *) &PyFloat_Type) < 0) SETBUILTIN("list", &PyList_Type);
return NULL; SETBUILTIN("long", &PyLong_Type);
if (PyDict_SetItemString(dict, "property", SETBUILTIN("object", &PyBaseObject_Type);
(PyObject *) &PyProperty_Type) < 0) SETBUILTIN("staticmethod", &PyStaticMethod_Type);
return NULL; SETBUILTIN("str", &PyString_Type);
if (PyDict_SetItemString(dict, "int", (PyObject *) &PyInt_Type) < 0) SETBUILTIN("super", &PySuper_Type);
return NULL; SETBUILTIN("tuple", &PyTuple_Type);
if (PyDict_SetItemString(dict, "list", (PyObject *) &PyList_Type) < 0) SETBUILTIN("type", &PyType_Type);
return NULL; SETBUILTIN("file", &PyFile_Type);
if (PyDict_SetItemString(dict, "long", (PyObject *) &PyLong_Type) < 0)
return NULL;
if (PyDict_SetItemString(dict, "object",
(PyObject *) &PyBaseObject_Type) < 0)
return NULL;
if (PyDict_SetItemString(dict, "staticmethod",
(PyObject *) &PyStaticMethod_Type) < 0)
return NULL;
if (PyDict_SetItemString(dict, "str", (PyObject *) &PyString_Type) < 0)
return NULL;
if (PyDict_SetItemString(dict, "super",
(PyObject *) &PySuper_Type) < 0)
return NULL;
if (PyDict_SetItemString(dict, "tuple",
(PyObject *) &PyTuple_Type) < 0)
return NULL;
if (PyDict_SetItemString(dict, "type", (PyObject *) &PyType_Type) < 0)
return NULL;
if (PyDict_SetItemString(dict, "file", (PyObject *) &PyFile_Type) < 0)
return NULL;
#ifdef Py_USING_UNICODE #ifdef Py_USING_UNICODE
if (PyDict_SetItemString(dict, "unicode", SETBUILTIN("unicode", &PyUnicode_Type);
(PyObject *) &PyUnicode_Type) < 0)
return NULL;
#endif #endif
debug = PyInt_FromLong(Py_OptimizeFlag == 0); debug = PyInt_FromLong(Py_OptimizeFlag == 0);
if (PyDict_SetItemString(dict, "__debug__", debug) < 0) { if (PyDict_SetItemString(dict, "__debug__", debug) < 0) {
@ -1898,6 +1873,7 @@ _PyBuiltin_Init(void)
Py_XDECREF(debug); Py_XDECREF(debug);
return mod; return mod;
#undef SETBUILTIN
} }
/* Helper for filter(): filter a tuple through a function */ /* Helper for filter(): filter a tuple through a function */