Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
027b09c5
Commit
027b09c5
authored
Mar 25, 2019
by
Stefan Krah
Committed by
GitHub
Mar 25, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-36370: Check for PyErr_Occurred() after PyImport_GetModule() (GH-12504)
parent
d1e768a6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
11 deletions
+24
-11
Python/ceval.c
Python/ceval.c
+3
-3
Python/import.c
Python/import.c
+14
-5
Python/pylifecycle.c
Python/pylifecycle.c
+4
-2
Python/sysmodule.c
Python/sysmodule.c
+3
-1
No files found.
Python/ceval.c
View file @
027b09c5
...
...
@@ -4948,7 +4948,7 @@ import_from(PyObject *v, PyObject *name)
}
x
=
PyImport_GetModule
(
fullmodname
);
Py_DECREF
(
fullmodname
);
if
(
x
==
NULL
)
{
if
(
x
==
NULL
&&
!
PyErr_Occurred
()
)
{
goto
error
;
}
Py_DECREF
(
pkgname
);
...
...
@@ -4971,7 +4971,7 @@ import_from(PyObject *v, PyObject *name)
"cannot import name %R from %R (unknown location)"
,
name
,
pkgname_or_unknown
);
/* NULL check
for errmsg
done by PyErr_SetImportError. */
/* NULL check
s for errmsg and pkgname
done by PyErr_SetImportError. */
PyErr_SetImportError
(
errmsg
,
pkgname
,
NULL
);
}
else
{
...
...
@@ -4979,7 +4979,7 @@ import_from(PyObject *v, PyObject *name)
"cannot import name %R from %R (%S)"
,
name
,
pkgname_or_unknown
,
pkgpath
);
/* NULL check
for errmsg
done by PyErr_SetImportError. */
/* NULL check
s for errmsg and pkgname
done by PyErr_SetImportError. */
PyErr_SetImportError
(
errmsg
,
pkgname
,
pkgpath
);
}
...
...
Python/import.c
View file @
027b09c5
...
...
@@ -966,11 +966,10 @@ exec_code_in_module(PyObject *name, PyObject *module_dict, PyObject *code_object
Py_DECREF
(
v
);
m
=
PyImport_GetModule
(
name
);
if
(
m
==
NULL
)
{
if
(
m
==
NULL
&&
!
PyErr_Occurred
()
)
{
PyErr_Format
(
PyExc_ImportError
,
"Loaded module %R not found in sys.modules"
,
name
);
return
NULL
;
}
return
m
;
...
...
@@ -1735,6 +1734,10 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
}
mod
=
PyImport_GetModule
(
abs_name
);
if
(
mod
==
NULL
&&
PyErr_Occurred
())
{
goto
error
;
}
if
(
mod
!=
NULL
&&
mod
!=
Py_None
)
{
_Py_IDENTIFIER
(
__spec__
);
_Py_IDENTIFIER
(
_lock_unlock_module
);
...
...
@@ -1810,9 +1813,11 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
final_mod
=
PyImport_GetModule
(
to_return
);
Py_DECREF
(
to_return
);
if
(
final_mod
==
NULL
)
{
PyErr_Format
(
PyExc_KeyError
,
"%R not in sys.modules as expected"
,
to_return
);
if
(
!
PyErr_Occurred
())
{
PyErr_Format
(
PyExc_KeyError
,
"%R not in sys.modules as expected"
,
to_return
);
}
goto
error
;
}
}
...
...
@@ -1875,6 +1880,10 @@ PyImport_ReloadModule(PyObject *m)
PyObject
*
reloaded_module
=
NULL
;
PyObject
*
imp
=
_PyImport_GetModuleId
(
&
PyId_imp
);
if
(
imp
==
NULL
)
{
if
(
PyErr_Occurred
())
{
return
NULL
;
}
imp
=
PyImport_ImportModule
(
"imp"
);
if
(
imp
==
NULL
)
{
return
NULL
;
...
...
Python/pylifecycle.c
View file @
027b09c5
...
...
@@ -2157,8 +2157,10 @@ wait_for_thread_shutdown(void)
PyObject
*
result
;
PyObject
*
threading
=
_PyImport_GetModuleId
(
&
PyId_threading
);
if
(
threading
==
NULL
)
{
/* threading not imported */
PyErr_Clear
();
if
(
PyErr_Occurred
())
{
PyErr_WriteUnraisable
(
NULL
);
}
/* else: threading not imported */
return
;
}
result
=
_PyObject_CallMethodId
(
threading
,
&
PyId__shutdown
,
NULL
);
...
...
Python/sysmodule.c
View file @
027b09c5
...
...
@@ -283,7 +283,9 @@ sys_displayhook(PyObject *module, PyObject *o)
builtins
=
_PyImport_GetModuleId
(
&
PyId_builtins
);
if
(
builtins
==
NULL
)
{
PyErr_SetString
(
PyExc_RuntimeError
,
"lost builtins module"
);
if
(
!
PyErr_Occurred
())
{
PyErr_SetString
(
PyExc_RuntimeError
,
"lost builtins module"
);
}
return
NULL
;
}
Py_DECREF
(
builtins
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment