mirror of https://github.com/kivy/pyjnius.git
fixes hashCode overflow. (disclamer: i wont talk about collision probabiliity or whatever. In my point of view, it seems very low, as the id() is based on the address of the object, it except if you uses tons of memory, you wont get it. And whatever the changes are, this will never keep up safe from colliding with others java object.). Closes #146
This commit is contained in:
parent
a0c9467d42
commit
ce3572ba79
|
@ -15,15 +15,17 @@ from .reflect import *
|
|||
# XXX monkey patch methods that cannot be in cython.
|
||||
# Cython doesn't allow to set new attribute on methods it compiled
|
||||
|
||||
HASHCODE_MAX = 2 ** 31 - 1
|
||||
|
||||
class PythonJavaClass_(PythonJavaClass):
|
||||
|
||||
@java_method('()I', name='hashCode')
|
||||
def hashCode(self):
|
||||
return id(self)
|
||||
return id(self) % HASHCODE_MAX
|
||||
|
||||
@java_method('()Ljava/lang/String;', name='hashCode')
|
||||
def hashCode_(self):
|
||||
return '{}'.format(id(self))
|
||||
return '{}'.format(self.hashCode())
|
||||
|
||||
@java_method('()Ljava/lang/String;', name='toString')
|
||||
def toString(self):
|
||||
|
|
Loading…
Reference in New Issue