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
5c6b3e21
Commit
5c6b3e21
authored
Nov 07, 2012
by
Hynek Schlawack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #15001: fix segfault on "del sys.module['__main__']"
Patch by Victor Stinner.
parent
692b023f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
6 deletions
+21
-6
Lib/test/test_cmd_line.py
Lib/test/test_cmd_line.py
+12
-0
Misc/NEWS
Misc/NEWS
+3
-0
Python/pythonrun.c
Python/pythonrun.c
+6
-6
No files found.
Lib/test/test_cmd_line.py
View file @
5c6b3e21
...
...
@@ -364,6 +364,18 @@ class CmdLineTest(unittest.TestCase):
self
.
assertEqual
(
rc
,
0
)
self
.
assertIn
(
b'random is 1'
,
out
)
def
test_del___main__
(
self
):
# Issue #15001: PyRun_SimpleFileExFlags() did crash because it kept a
# borrowed reference to the dict of __main__ module and later modify
# the dict whereas the module was destroyed
filename
=
test
.
support
.
TESTFN
self
.
addCleanup
(
test
.
support
.
unlink
,
filename
)
with
open
(
filename
,
"w"
)
as
script
:
print
(
"import sys"
,
file
=
script
)
print
(
"del sys.modules['__main__']"
,
file
=
script
)
assert_python_ok
(
filename
)
def
test_main
():
test
.
support
.
run_unittest
(
CmdLineTest
)
test
.
support
.
reap_children
()
...
...
Misc/NEWS
View file @
5c6b3e21
...
...
@@ -10,6 +10,9 @@ What's New in Python 3.2.4
Core and Builtins
-----------------
- Issue #15001: fix segfault on "del sys.module['__main__']". Patch by Victor
Stinner.
- Issue #5057: the peepholer no longer optimizes subscription on unicode
literals (e.g. u'foo'[0]) in order to produce compatible pyc files between
narrow and wide builds.
...
...
Python/pythonrun.c
View file @
5c6b3e21
...
...
@@ -1257,25 +1257,26 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit,
{
PyObject
*
m
,
*
d
,
*
v
;
const
char
*
ext
;
int
set_file_name
=
0
,
ret
;
int
set_file_name
=
0
,
ret
=
-
1
;
size_t
len
;
m
=
PyImport_AddModule
(
"__main__"
);
if
(
m
==
NULL
)
return
-
1
;
Py_INCREF
(
m
);
d
=
PyModule_GetDict
(
m
);
if
(
PyDict_GetItemString
(
d
,
"__file__"
)
==
NULL
)
{
PyObject
*
f
;
f
=
PyUnicode_DecodeFSDefault
(
filename
);
if
(
f
==
NULL
)
return
-
1
;
goto
done
;
if
(
PyDict_SetItemString
(
d
,
"__file__"
,
f
)
<
0
)
{
Py_DECREF
(
f
);
return
-
1
;
goto
done
;
}
if
(
PyDict_SetItemString
(
d
,
"__cached__"
,
Py_None
)
<
0
)
{
Py_DECREF
(
f
);
return
-
1
;
goto
done
;
}
set_file_name
=
1
;
Py_DECREF
(
f
);
...
...
@@ -1288,7 +1289,6 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit,
fclose
(
fp
);
if
((
fp
=
fopen
(
filename
,
"rb"
))
==
NULL
)
{
fprintf
(
stderr
,
"python: Can't reopen .pyc file
\n
"
);
ret
=
-
1
;
goto
done
;
}
/* Turn on optimization if a .pyo file is given */
...
...
@@ -1302,7 +1302,6 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit,
flush_io
();
if
(
v
==
NULL
)
{
PyErr_Print
();
ret
=
-
1
;
goto
done
;
}
Py_DECREF
(
v
);
...
...
@@ -1310,6 +1309,7 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit,
done:
if
(
set_file_name
&&
PyDict_DelItemString
(
d
,
"__file__"
))
PyErr_Clear
();
Py_DECREF
(
m
);
return
ret
;
}
...
...
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