Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4467959

Browse files
committed
Patch by Vladimir Marangozov to include the function name when
comparing code objects. This give sless surprising results in -Optimized code. It also sorts code objects by name, now. [I changed the patch to hash() slightly to touch fewer lines.]
1 parent 1a4b593 commit 4467959

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Python/compile.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ code_compare(co, cp)
140140
PyCodeObject *co, *cp;
141141
{
142142
int cmp;
143+
cmp = PyObject_Compare(co->co_name, cp->co_name);
144+
if (cmp) return cmp;
143145
cmp = co->co_argcount - cp->co_argcount;
144146
if (cmp) return cmp;
145147
cmp = co->co_nlocals - cp->co_nlocals;
@@ -160,7 +162,9 @@ static long
160162
code_hash(co)
161163
PyCodeObject *co;
162164
{
163-
long h, h1, h2, h3, h4;
165+
long h, h0, h1, h2, h3, h4;
166+
h0 = PyObject_Hash(co->co_name);
167+
if (h0 == -1) return -1;
164168
h1 = PyObject_Hash(co->co_code);
165169
if (h1 == -1) return -1;
166170
h2 = PyObject_Hash(co->co_consts);
@@ -169,7 +173,7 @@ code_hash(co)
169173
if (h3 == -1) return -1;
170174
h4 = PyObject_Hash(co->co_varnames);
171175
if (h4 == -1) return -1;
172-
h = h1 ^ h2 ^ h3 ^ h4 ^
176+
h = h0 ^ h1 ^ h2 ^ h3 ^ h4 ^
173177
co->co_argcount ^ co->co_nlocals ^ co->co_flags;
174178
if (h == -1) h = -2;
175179
return h;

0 commit comments

Comments
 (0)