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
55299fff
Commit
55299fff
authored
Apr 26, 2018
by
Serhiy Storchaka
Committed by
GitHub
Apr 26, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.7] bpo-33330: Improve error handling in PyImport_Cleanup(). (GH-6564). (GH-6605)
(cherry picked from commit
e9d9494d
)
parent
730fb07c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
8 deletions
+30
-8
Python/import.c
Python/import.c
+30
-8
No files found.
Python/import.c
View file @
55299fff
...
...
@@ -447,7 +447,9 @@ PyImport_Cleanup(void)
dict
=
PyModule_GetDict
(
value
);
if
(
Py_VerboseFlag
)
PySys_WriteStderr
(
"# clear __builtin__._
\n
"
);
PyDict_SetItemString
(
dict
,
"_"
,
Py_None
);
if
(
PyDict_SetItemString
(
dict
,
"_"
,
Py_None
)
<
0
)
{
PyErr_Clear
();
}
}
value
=
PyDict_GetItemString
(
modules
,
"sys"
);
if
(
value
!=
NULL
&&
PyModule_Check
(
value
))
{
...
...
@@ -457,7 +459,9 @@ PyImport_Cleanup(void)
for
(
p
=
sys_deletes
;
*
p
!=
NULL
;
p
++
)
{
if
(
Py_VerboseFlag
)
PySys_WriteStderr
(
"# clear sys.%s
\n
"
,
*
p
);
PyDict_SetItemString
(
dict
,
*
p
,
Py_None
);
if
(
PyDict_SetItemString
(
dict
,
*
p
,
Py_None
)
<
0
)
{
PyErr_Clear
();
}
}
for
(
p
=
sys_files
;
*
p
!=
NULL
;
p
+=
2
)
{
if
(
Py_VerboseFlag
)
...
...
@@ -465,7 +469,9 @@ PyImport_Cleanup(void)
v
=
PyDict_GetItemString
(
dict
,
*
(
p
+
1
));
if
(
v
==
NULL
)
v
=
Py_None
;
PyDict_SetItemString
(
dict
,
*
p
,
v
);
if
(
PyDict_SetItemString
(
dict
,
*
p
,
v
)
<
0
)
{
PyErr_Clear
();
}
}
}
...
...
@@ -475,7 +481,9 @@ PyImport_Cleanup(void)
if
(
Py_VerboseFlag
)
PySys_WriteStderr
(
"# cleanup __main__
\n
"
);
_PyModule_Clear
(
value
);
PyDict_SetItemString
(
modules
,
"__main__"
,
Py_None
);
if
(
PyDict_SetItemString
(
modules
,
"__main__"
,
Py_None
)
<
0
)
{
PyErr_Clear
();
}
}
/* The special treatment of __builtin__ here is because even
...
...
@@ -510,10 +518,15 @@ PyImport_Cleanup(void)
PySys_WriteStderr
(
"# cleanup[1] %s
\n
"
,
name
);
_PyModule_Clear
(
value
);
PyDict_SetItem
(
modules
,
key
,
Py_None
);
if
(
PyDict_SetItem
(
modules
,
key
,
Py_None
)
<
0
)
{
PyErr_Clear
();
}
ndone
++
;
}
}
if
(
PyErr_Occurred
())
{
PyErr_Clear
();
}
}
while
(
ndone
>
0
);
/* Next, delete all modules (still skipping __builtin__ and sys) */
...
...
@@ -528,7 +541,12 @@ PyImport_Cleanup(void)
if
(
Py_VerboseFlag
)
PySys_WriteStderr
(
"# cleanup[2] %s
\n
"
,
name
);
_PyModule_Clear
(
value
);
PyDict_SetItem
(
modules
,
key
,
Py_None
);
if
(
PyDict_SetItem
(
modules
,
key
,
Py_None
)
<
0
)
{
PyErr_Clear
();
}
}
if
(
PyErr_Occurred
())
{
PyErr_Clear
();
}
}
...
...
@@ -538,14 +556,18 @@ PyImport_Cleanup(void)
if
(
Py_VerboseFlag
)
PySys_WriteStderr
(
"# cleanup sys
\n
"
);
_PyModule_Clear
(
value
);
PyDict_SetItemString
(
modules
,
"sys"
,
Py_None
);
if
(
PyDict_SetItemString
(
modules
,
"sys"
,
Py_None
)
<
0
)
{
PyErr_Clear
();
}
}
value
=
PyDict_GetItemString
(
modules
,
"__builtin__"
);
if
(
value
!=
NULL
&&
PyModule_Check
(
value
))
{
if
(
Py_VerboseFlag
)
PySys_WriteStderr
(
"# cleanup __builtin__
\n
"
);
_PyModule_Clear
(
value
);
PyDict_SetItemString
(
modules
,
"__builtin__"
,
Py_None
);
if
(
PyDict_SetItemString
(
modules
,
"__builtin__"
,
Py_None
)
<
0
)
{
PyErr_Clear
();
}
}
/* Finally, clear and delete the modules directory */
...
...
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