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
b7e1eff8
Commit
b7e1eff8
authored
Apr 19, 2018
by
Serhiy Storchaka
Committed by
GitHub
Apr 19, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-33299: Return an object itself for some types in _PyCode_ConstantKey(). (GH-6513)
parent
9009f3e3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
8 deletions
+17
-8
Objects/codeobject.c
Objects/codeobject.c
+11
-4
Python/compile.c
Python/compile.c
+6
-4
No files found.
Objects/codeobject.c
View file @
b7e1eff8
...
...
@@ -488,14 +488,21 @@ _PyCode_ConstantKey(PyObject *op)
{
PyObject
*
key
;
/* Py_None and Py_Ellipsis are singleton */
/* Py_None and Py_Ellipsis are singleton
s.
*/
if
(
op
==
Py_None
||
op
==
Py_Ellipsis
||
PyLong_CheckExact
(
op
)
||
PyBool_Check
(
op
)
||
PyBytes_CheckExact
(
op
)
||
PyUnicode_CheckExact
(
op
)
/* code_richcompare() uses _PyCode_ConstantKey() internally */
||
PyCode_Check
(
op
))
{
||
PyCode_Check
(
op
))
{
/* Objects of these types are always different from object of other
* type and from tuples. */
Py_INCREF
(
op
);
key
=
op
;
}
else
if
(
PyBool_Check
(
op
)
||
PyBytes_CheckExact
(
op
))
{
/* Make booleans different from integers 0 and 1.
* Avoid BytesWarning from comparing bytes with strings. */
key
=
PyTuple_Pack
(
2
,
Py_TYPE
(
op
),
op
);
}
else
if
(
PyFloat_CheckExact
(
op
))
{
...
...
Python/compile.c
View file @
b7e1eff8
...
...
@@ -5299,10 +5299,12 @@ dict_keys_inorder(PyObject *dict, Py_ssize_t offset)
return
NULL
;
while
(
PyDict_Next
(
dict
,
&
pos
,
&
k
,
&
v
))
{
i
=
PyLong_AS_LONG
(
v
);
/* The keys of the dictionary are tuples. (see compiler_add_o
* and _PyCode_ConstantKey). The object we want is always second,
* though. */
k
=
PyTuple_GET_ITEM
(
k
,
1
);
/* The keys of the dictionary can be tuples wrapping a contant.
* (see compiler_add_o and _PyCode_ConstantKey). In that case
* the object we want is always second. */
if
(
PyTuple_CheckExact
(
k
))
{
k
=
PyTuple_GET_ITEM
(
k
,
1
);
}
Py_INCREF
(
k
);
assert
((
i
-
offset
)
<
size
);
assert
((
i
-
offset
)
>=
0
);
...
...
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