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
b1cc6aa2
Commit
b1cc6aa2
authored
Nov 25, 2012
by
Mark Dickinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #9011: AST creation no longer modifies CST for negated numeric literals.
parent
1658797a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
10 deletions
+29
-10
Lib/test/test_parser.py
Lib/test/test_parser.py
+11
-0
Misc/NEWS
Misc/NEWS
+3
-0
Python/ast.c
Python/ast.c
+15
-10
No files found.
Lib/test/test_parser.py
View file @
b1cc6aa2
...
@@ -567,6 +567,17 @@ class CompileTestCase(unittest.TestCase):
...
@@ -567,6 +567,17 @@ class CompileTestCase(unittest.TestCase):
st
=
parser
.
suite
(
'a = u"
\
u
1
"'
)
st
=
parser
.
suite
(
'a = u"
\
u
1
"'
)
self
.
assertRaises
(
SyntaxError
,
parser
.
compilest
,
st
)
self
.
assertRaises
(
SyntaxError
,
parser
.
compilest
,
st
)
def
test_issue_9011
(
self
):
# Issue 9011: compilation of an unary minus expression changed
# the meaning of the ST, so that a second compilation produced
# incorrect results.
st
=
parser
.
expr
(
'-3'
)
code1
=
parser
.
compilest
(
st
)
self
.
assertEqual
(
eval
(
code1
),
-
3
)
code2
=
parser
.
compilest
(
st
)
self
.
assertEqual
(
eval
(
code2
),
-
3
)
class
ParserStackLimitTestCase
(
unittest
.
TestCase
):
class
ParserStackLimitTestCase
(
unittest
.
TestCase
):
"""try to push the parser to/over it's limits.
"""try to push the parser to/over it's limits.
see http://bugs.python.org/issue1881 for a discussion
see http://bugs.python.org/issue1881 for a discussion
...
...
Misc/NEWS
View file @
b1cc6aa2
...
@@ -9,6 +9,9 @@ What's New in Python 2.7.4
...
@@ -9,6 +9,9 @@ What's New in Python 2.7.4
Core and Builtins
Core and Builtins
-----------------
-----------------
- Issue #9011: Fix hacky AST code that modified the CST when compiling
a negated numeric literal.
- Issue #16306: Fix multiple error messages when unknown command line
- Issue #16306: Fix multiple error messages when unknown command line
parameters where passed to the interpreter. Patch by Hieu Nguyen.
parameters where passed to the interpreter. Patch by Hieu Nguyen.
...
...
Python/ast.c
View file @
b1cc6aa2
...
@@ -1744,14 +1744,19 @@ ast_for_factor(struct compiling *c, const node *n)
...
@@ -1744,14 +1744,19 @@ ast_for_factor(struct compiling *c, const node *n)
NCH
(
ppower
)
==
1
&&
NCH
(
ppower
)
==
1
&&
TYPE
((
patom
=
CHILD
(
ppower
,
0
)))
==
atom
&&
TYPE
((
patom
=
CHILD
(
ppower
,
0
)))
==
atom
&&
TYPE
((
pnum
=
CHILD
(
patom
,
0
)))
==
NUMBER
)
{
TYPE
((
pnum
=
CHILD
(
patom
,
0
)))
==
NUMBER
)
{
PyObject
*
pynum
;
char
*
s
=
PyObject_MALLOC
(
strlen
(
STR
(
pnum
))
+
2
);
char
*
s
=
PyObject_MALLOC
(
strlen
(
STR
(
pnum
))
+
2
);
if
(
s
==
NULL
)
if
(
s
==
NULL
)
return
NULL
;
return
NULL
;
s
[
0
]
=
'-'
;
s
[
0
]
=
'-'
;
strcpy
(
s
+
1
,
STR
(
pnum
));
strcpy
(
s
+
1
,
STR
(
pnum
));
PyObject_FREE
(
STR
(
pnum
));
pynum
=
parsenumber
(
c
,
s
);
STR
(
pnum
)
=
s
;
PyObject_FREE
(
s
);
return
ast_for_atom
(
c
,
patom
);
if
(
!
pynum
)
return
NULL
;
PyArena_AddPyObject
(
c
->
c_arena
,
pynum
);
return
Num
(
pynum
,
LINENO
(
n
),
n
->
n_col_offset
,
c
->
c_arena
);
}
}
expression
=
ast_for_expr
(
c
,
CHILD
(
n
,
1
));
expression
=
ast_for_expr
(
c
,
CHILD
(
n
,
1
));
...
...
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