mirror of
https://github.com/python/cpython.git
synced 2025-07-10 04:45:36 +00:00
gh-105922: Add PyImport_AddModuleRef() function (#105923)
* Add tests on PyImport_AddModuleRef(), PyImport_AddModule() and PyImport_AddModuleObject(). * pythonrun.c: Replace Py_XNewRef(PyImport_AddModule(name)) with PyImport_AddModuleRef(name).
This commit is contained in:
parent
7f97c8e367
commit
03f1a132ee
13 changed files with 150 additions and 25 deletions
|
@ -406,7 +406,7 @@ _PyRun_SimpleFileObject(FILE *fp, PyObject *filename, int closeit,
|
|||
{
|
||||
int ret = -1;
|
||||
|
||||
PyObject *main_module = Py_XNewRef(PyImport_AddModule("__main__"));
|
||||
PyObject *main_module = PyImport_AddModuleRef("__main__");
|
||||
if (main_module == NULL)
|
||||
return -1;
|
||||
PyObject *dict = PyModule_GetDict(main_module); // borrowed ref
|
||||
|
@ -502,7 +502,7 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit,
|
|||
int
|
||||
PyRun_SimpleStringFlags(const char *command, PyCompilerFlags *flags)
|
||||
{
|
||||
PyObject *main_module = Py_XNewRef(PyImport_AddModule("__main__"));
|
||||
PyObject *main_module = PyImport_AddModuleRef("__main__");
|
||||
if (main_module == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue