mirror of
https://github.com/python/cpython.git
synced 2025-08-23 02:04:56 +00:00
bpo-28411: Support other mappings in PyInterpreterState.modules. (#3593)
The concrete PyDict_* API is used to interact with PyInterpreterState.modules in a number of places. This isn't compatible with all dict subclasses, nor with other Mapping implementations. This patch switches the concrete API usage to the corresponding abstract API calls. We also add a PyImport_GetModule() function (and some other helpers) to reduce a bunch of code duplication.
This commit is contained in:
parent
e82c034496
commit
3f9eee6eb4
11 changed files with 216 additions and 113 deletions
|
@ -162,18 +162,16 @@ static PyObject *
|
|||
sys_displayhook(PyObject *self, PyObject *o)
|
||||
{
|
||||
PyObject *outf;
|
||||
PyObject *modules = PyImport_GetModuleDict();
|
||||
if (modules == NULL)
|
||||
return NULL;
|
||||
PyObject *builtins;
|
||||
static PyObject *newline = NULL;
|
||||
int err;
|
||||
|
||||
builtins = _PyDict_GetItemId(modules, &PyId_builtins);
|
||||
builtins = _PyImport_GetModuleId(&PyId_builtins);
|
||||
if (builtins == NULL) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "lost builtins module");
|
||||
return NULL;
|
||||
}
|
||||
Py_DECREF(builtins);
|
||||
|
||||
/* Print value except if None */
|
||||
/* After printing, also assign to '_' */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue