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
bf00bc78
Commit
bf00bc78
authored
Sep 07, 2016
by
Eric Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #15578: Correctly incref the parent module while importing.
parent
280bc223
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
0 deletions
+22
-0
Lib/test/test_import.py
Lib/test/test_import.py
+18
-0
Misc/NEWS
Misc/NEWS
+2
-0
Python/import.c
Python/import.c
+2
-0
No files found.
Lib/test/test_import.py
View file @
bf00bc78
...
...
@@ -397,6 +397,24 @@ class ImportTests(unittest.TestCase):
finally
:
sys
.
path
.
pop
(
0
)
def
test_replace_parent_in_sys_modules
(
self
):
dir_name
=
os
.
path
.
abspath
(
TESTFN
)
os
.
mkdir
(
dir_name
)
try
:
pkg_dir
=
os
.
path
.
join
(
dir_name
,
'sa'
)
os
.
mkdir
(
pkg_dir
)
with
open
(
os
.
path
.
join
(
pkg_dir
,
'__init__.py'
),
'w'
)
as
init_file
:
init_file
.
write
(
"import v1"
)
with
open
(
os
.
path
.
join
(
pkg_dir
,
'v1.py'
),
'w'
)
as
v1_file
:
v1_file
.
write
(
"import sys;"
"sys.modules['sa'] = sys.modules[__name__];"
"import sa"
)
sys
.
path
.
insert
(
0
,
dir_name
)
# a segfault means the test failed!
import
sa
finally
:
rmtree
(
dir_name
)
class
PycRewritingTests
(
unittest
.
TestCase
):
# Test that the `co_filename` attribute on code objects always points
...
...
Misc/NEWS
View file @
bf00bc78
...
...
@@ -7082,6 +7082,8 @@ Core and Builtins
-
Add
Py3k
warnings
for
parameter
names
in
parentheses
.
-
Issue
#
15578
:
Correctly
incref
the
parent
module
while
importing
.
-
Issue
#
7362
:
Give
a
proper
error
message
for
``
def
f
((
x
)=
3
):
pass
``.
-
Issue
#
7085
:
Fix
crash
when
importing
some
extensions
in
a
thread
on
MacOSX
...
...
Python/import.c
View file @
bf00bc78
...
...
@@ -2243,8 +2243,10 @@ import_module_level(char *name, PyObject *globals, PyObject *locals,
if
(
parent
==
NULL
)
goto
error_exit
;
Py_INCREF
(
parent
);
head
=
load_next
(
parent
,
level
<
0
?
Py_None
:
parent
,
&
name
,
buf
,
&
buflen
);
Py_DECREF
(
parent
);
if
(
head
==
NULL
)
goto
error_exit
;
...
...
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