Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
54b721d2
Commit
54b721d2
authored
Jun 03, 2009
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ticket #326, coerce -1 to -2 for __hash__
parent
04df35ec
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
0 deletions
+34
-0
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+5
-0
tests/run/hash_T326.pyx
tests/run/hash_T326.pyx
+29
-0
No files found.
Cython/Compiler/Nodes.py
View file @
54b721d2
...
...
@@ -1228,6 +1228,11 @@ class FuncDefNode(StatNode, BlockNode):
code
.
put_finish_refcount_context
()
if
self
.
entry
.
is_special
and
self
.
entry
.
name
==
"__hash__"
:
# Returning -1 for __hash__ is supposed to signal an error
# We do as Python instances and coerce -1 into -2.
code
.
putln
(
"if (unlikely(%s == -1) && !PyErr_Occurred()) %s = -2;"
%
(
Naming
.
retval_cname
,
Naming
.
retval_cname
))
if
acquire_gil
:
code
.
putln
(
"PyGILState_Release(_save);"
)
...
...
tests/run/hash_T326.pyx
0 → 100644
View file @
54b721d2
__doc__
=
u"""
>>> hash(A(5))
5
>>> hash(A(-1))
-2
>>> hash(A(-2))
-2
>>> hash(A(100))
Traceback (most recent call last):
...
TypeError: That's kind of a round number...
>>> __hash__(-1)
-1
"""
cdef
class
A
:
cdef
long
a
def
__init__
(
self
,
a
):
self
.
a
=
a
def
__hash__
(
self
):
if
self
.
a
==
100
:
raise
TypeError
,
"That's kind of a round number..."
else
:
return
self
.
a
cpdef
long
__hash__
(
long
x
):
return
x
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