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
24cc0504
Commit
24cc0504
authored
Nov 04, 2012
by
Nick Coghlan
Browse files
Options
Browse Files
Download
Plain Diff
Issue #5765: Merge from 3.3
parents
ca74b21b
082777de
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
108 additions
and
44 deletions
+108
-44
Include/symtable.h
Include/symtable.h
+2
-0
Lib/test/crashers/compiler_recursion.py
Lib/test/crashers/compiler_recursion.py
+0
-13
Lib/test/test_compile.py
Lib/test/test_compile.py
+27
-0
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
Python/compile.c
Python/compile.c
+5
-0
Python/symtable.c
Python/symtable.c
+70
-31
No files found.
Include/symtable.h
View file @
24cc0504
...
@@ -30,6 +30,8 @@ struct symtable {
...
@@ -30,6 +30,8 @@ struct symtable {
PyObject
*
st_private
;
/* name of current class or NULL */
PyObject
*
st_private
;
/* name of current class or NULL */
PyFutureFeatures
*
st_future
;
/* module's future features that affect
PyFutureFeatures
*
st_future
;
/* module's future features that affect
the symbol table */
the symbol table */
int
recursion_depth
;
/* current recursion depth */
int
recursion_limit
;
/* recursion limit */
};
};
typedef
struct
_symtable_entry
{
typedef
struct
_symtable_entry
{
...
...
Lib/test/crashers/compiler_recursion.py
deleted
100644 → 0
View file @
ca74b21b
"""
The compiler (>= 2.5) recurses happily until it blows the stack.
Recorded on the tracker as http://bugs.python.org/issue11383
"""
# The variant below blows up in compiler_call, but there are assorted
# other variations that blow up in other functions
# e.g. '1*'*10**5+'1' will die in compiler_visit_expr
# The exact limit to destroy the stack will vary by platform
# but 10M should do the trick even with huge stack allocations
compile
(
'()'
*
10
**
7
,
'?'
,
'exec'
)
Lib/test/test_compile.py
View file @
24cc0504
...
@@ -474,6 +474,33 @@ if 1:
...
@@ -474,6 +474,33 @@ if 1:
self
.
assertInvalidSingle
(
'f()
\
n
xy # blah
\
n
blah()'
)
self
.
assertInvalidSingle
(
'f()
\
n
xy # blah
\
n
blah()'
)
self
.
assertInvalidSingle
(
'x = 5 # comment
\
n
x = 6
\
n
'
)
self
.
assertInvalidSingle
(
'x = 5 # comment
\
n
x = 6
\
n
'
)
@
support
.
cpython_only
def
test_compiler_recursion_limit
(
self
):
# Expected limit is sys.getrecursionlimit() * the scaling factor
# in symtable.c (currently 3)
# We expect to fail *at* that limit, because we use up some of
# the stack depth limit in the test suite code
# So we check the expected limit and 75% of that
# XXX (ncoghlan): duplicating the scaling factor here is a little
# ugly. Perhaps it should be exposed somewhere...
fail_depth
=
sys
.
getrecursionlimit
()
*
3
success_depth
=
int
(
fail_depth
*
0.75
)
def
check_limit
(
prefix
,
repeated
):
expect_ok
=
prefix
+
repeated
*
success_depth
self
.
compile_single
(
expect_ok
)
broken
=
prefix
+
repeated
*
fail_depth
details
=
"Compiling ({!r} + {!r} * {})"
.
format
(
prefix
,
repeated
,
fail_depth
)
with
self
.
assertRaises
(
RuntimeError
,
msg
=
details
):
self
.
compile_single
(
broken
)
check_limit
(
"a"
,
"()"
)
check_limit
(
"a"
,
".b"
)
check_limit
(
"a"
,
"[0]"
)
check_limit
(
"a"
,
"*a"
)
def
test_main
():
def
test_main
():
support
.
run_unittest
(
TestSpecifics
)
support
.
run_unittest
(
TestSpecifics
)
...
...
Misc/ACKS
View file @
24cc0504
...
@@ -431,6 +431,7 @@ Hans de Graaff
...
@@ -431,6 +431,7 @@ Hans de Graaff
Nathaniel Gray
Nathaniel Gray
Eddy De Greef
Eddy De Greef
Grant Griffin
Grant Griffin
Andrea Griffini
Duncan Grisby
Duncan Grisby
Fabian Groffen
Fabian Groffen
Eric Groo
Eric Groo
...
...
Misc/NEWS
View file @
24cc0504
...
@@ -10,6 +10,9 @@ What's New in Python 3.4.0 Alpha 1?
...
@@ -10,6 +10,9 @@ What's New in Python 3.4.0 Alpha 1?
Core and Builtins
Core and Builtins
-----------------
-----------------
- Issue #5765: Apply a hard recursion limit in the compiler instead of
blowing the stack and segfaulting.
- Issue #16402: When slicing a range, fix shadowing of exceptions from
- Issue #16402: When slicing a range, fix shadowing of exceptions from
__index__.
__index__.
...
...
Python/compile.c
View file @
24cc0504
...
@@ -141,6 +141,11 @@ struct compiler_unit {
...
@@ -141,6 +141,11 @@ struct compiler_unit {
The u pointer points to the current compilation unit, while units
The u pointer points to the current compilation unit, while units
for enclosing blocks are stored in c_stack. The u and c_stack are
for enclosing blocks are stored in c_stack. The u and c_stack are
managed by compiler_enter_scope() and compiler_exit_scope().
managed by compiler_enter_scope() and compiler_exit_scope().
Note that we don't track recursion levels during compilation - the
task of detecting and rejecting excessive levels of nesting is
handled by the symbol analysis pass.
*/
*/
struct
compiler
{
struct
compiler
{
...
...
Python/symtable.c
View file @
24cc0504
This diff is collapsed.
Click to expand it.
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