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
2ca6315d
Commit
2ca6315d
authored
Jul 18, 2012
by
Meador Inge
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #15368: make bytecode generation deterministic.
parent
0b350c6b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
2 deletions
+25
-2
Misc/NEWS
Misc/NEWS
+3
-0
Python/compile.c
Python/compile.c
+22
-2
No files found.
Misc/NEWS
View file @
2ca6315d
...
...
@@ -10,6 +10,9 @@ What's New in Python 3.2.4
Core and Builtins
-----------------
- Issue #15368: An issue that caused bytecode generation to be
non-deterministic when using randomized hashing (-R) has been fixed.
- Issue #15020: The program name used to search for Python's path is now
"python3" under Unix, not "python".
...
...
Python/compile.c
View file @
2ca6315d
...
...
@@ -367,16 +367,33 @@ each key.
static
PyObject
*
dictbytype
(
PyObject
*
src
,
int
scope_type
,
int
flag
,
int
offset
)
{
Py_ssize_t
pos
=
0
,
i
=
offset
,
scope
;
Py_ssize_t
pos
=
0
,
i
=
offset
,
scope
,
num_keys
,
key_i
;
PyObject
*
k
,
*
v
,
*
dest
=
PyDict_New
();
PyObject
*
sorted_keys
;
assert
(
offset
>=
0
);
if
(
dest
==
NULL
)
return
NULL
;
while
(
PyDict_Next
(
src
,
&
pos
,
&
k
,
&
v
))
{
/* Sort the keys so that we have a deterministic order on the indexes
saved in the returned dictionary. These indexes are used as indexes
into the free and cell var storage. Therefore if they aren't
deterministic, then the generated bytecode is not deterministic.
*/
sorted_keys
=
PyDict_Keys
(
src
);
if
(
sorted_keys
==
NULL
)
return
NULL
;
if
(
PyList_Sort
(
sorted_keys
)
!=
0
)
{
Py_DECREF
(
sorted_keys
);
return
NULL
;
}
num_keys
=
PyList_GET_SIZE
(
src
);
for
(
key_i
=
0
;
key_i
<
num_keys
;
key_i
++
)
{
/* XXX this should probably be a macro in symtable.h */
long
vi
;
k
=
PyList_GET_ITEM
(
sorted_keys
,
key_i
);
v
=
PyDict_GetItem
(
src
,
k
);
assert
(
PyLong_Check
(
v
));
vi
=
PyLong_AS_LONG
(
v
);
scope
=
(
vi
>>
SCOPE_OFFSET
)
&
SCOPE_MASK
;
...
...
@@ -384,12 +401,14 @@ dictbytype(PyObject *src, int scope_type, int flag, int offset)
if
(
scope
==
scope_type
||
vi
&
flag
)
{
PyObject
*
tuple
,
*
item
=
PyLong_FromLong
(
i
);
if
(
item
==
NULL
)
{
Py_DECREF
(
sorted_keys
);
Py_DECREF
(
dest
);
return
NULL
;
}
i
++
;
tuple
=
PyTuple_Pack
(
2
,
k
,
k
->
ob_type
);
if
(
!
tuple
||
PyDict_SetItem
(
dest
,
tuple
,
item
)
<
0
)
{
Py_DECREF
(
sorted_keys
);
Py_DECREF
(
item
);
Py_DECREF
(
dest
);
Py_XDECREF
(
tuple
);
...
...
@@ -399,6 +418,7 @@ dictbytype(PyObject *src, int scope_type, int flag, int offset)
Py_DECREF
(
tuple
);
}
}
Py_DECREF
(
sorted_keys
);
return
dest
;
}
...
...
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