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
e9d9494d
Commit
e9d9494d
authored
Apr 25, 2018
by
Serhiy Storchaka
Committed by
GitHub
Apr 25, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-33330: Improve error handling in PyImport_Cleanup(). (GH-6564)
parent
67a8f4fe
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
9 deletions
+24
-9
Python/import.c
Python/import.c
+24
-9
No files found.
Python/import.c
View file @
e9d9494d
...
...
@@ -364,7 +364,7 @@ PyImport_GetModule(PyObject *name)
}
else
{
m
=
PyObject_GetItem
(
modules
,
name
);
if
(
PyErr_ExceptionMatches
(
PyExc_KeyError
))
{
if
(
m
==
NULL
&&
PyErr_ExceptionMatches
(
PyExc_KeyError
))
{
PyErr_Clear
();
}
}
...
...
@@ -416,12 +416,16 @@ PyImport_Cleanup(void)
if
(
Py_VerboseFlag
)
PySys_WriteStderr
(
"# clear builtins._
\n
"
);
PyDict_SetItemString
(
interp
->
builtins
,
"_"
,
Py_None
);
if
(
PyDict_SetItemString
(
interp
->
builtins
,
"_"
,
Py_None
)
<
0
)
{
PyErr_Clear
();
}
for
(
p
=
sys_deletes
;
*
p
!=
NULL
;
p
++
)
{
if
(
Py_VerboseFlag
)
PySys_WriteStderr
(
"# clear sys.%s
\n
"
,
*
p
);
PyDict_SetItemString
(
interp
->
sysdict
,
*
p
,
Py_None
);
if
(
PyDict_SetItemString
(
interp
->
sysdict
,
*
p
,
Py_None
)
<
0
)
{
PyErr_Clear
();
}
}
for
(
p
=
sys_files
;
*
p
!=
NULL
;
p
+=
2
)
{
if
(
Py_VerboseFlag
)
...
...
@@ -429,7 +433,9 @@ PyImport_Cleanup(void)
value
=
PyDict_GetItemString
(
interp
->
sysdict
,
*
(
p
+
1
));
if
(
value
==
NULL
)
value
=
Py_None
;
PyDict_SetItemString
(
interp
->
sysdict
,
*
p
,
value
);
if
(
PyDict_SetItemString
(
interp
->
sysdict
,
*
p
,
value
)
<
0
)
{
PyErr_Clear
();
}
}
/* We prepare a list which will receive (name, weakref) tuples of
...
...
@@ -443,21 +449,26 @@ PyImport_Cleanup(void)
#define STORE_MODULE_WEAKREF(name, mod) \
if (weaklist != NULL) { \
PyObject *wr = PyWeakref_NewRef(mod, NULL); \
if (
name &&
wr) { \
if (wr) { \
PyObject *tup = PyTuple_Pack(2, name, wr); \
PyList_Append(weaklist, tup); \
if (!tup || PyList_Append(weaklist, tup) < 0) { \
PyErr_Clear(); \
} \
Py_XDECREF(tup); \
Py_DECREF(wr); \
} \
Py_XDECREF(wr); \
if (PyErr_Occurred()) \
else { \
PyErr_Clear(); \
} \
}
#define CLEAR_MODULE(name, mod) \
if (PyModule_Check(mod)) { \
if (Py_VerboseFlag && PyUnicode_Check(name)) \
PySys_FormatStderr("# cleanup[2] removing %U\n", name); \
STORE_MODULE_WEAKREF(name, mod); \
PyObject_SetItem(modules, name, Py_None); \
if (PyObject_SetItem(modules, name, Py_None) < 0) { \
PyErr_Clear(); \
} \
}
/* Remove all modules from sys.modules, hoping that garbage collection
...
...
@@ -484,6 +495,9 @@ PyImport_Cleanup(void)
Py_DECREF
(
value
);
Py_DECREF
(
key
);
}
if
(
PyErr_Occurred
())
{
PyErr_Clear
();
}
Py_DECREF
(
iterator
);
}
}
...
...
@@ -564,6 +578,7 @@ PyImport_Cleanup(void)
/* Once more */
_PyGC_CollectNoFail
();
#undef CLEAR_MODULE
#undef STORE_MODULE_WEAKREF
}
...
...
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