Use isize for hash protocol

This commit is contained in:
messense 2017-06-24 23:42:13 +08:00
parent 3a2004eab2
commit 2d217be349
No known key found for this signature in database
GPG key ID: BB41A8A2C716CCA9
3 changed files with 6 additions and 6 deletions

View file

@ -97,7 +97,7 @@ pub trait PyObjectFormatProtocol<'p>: PyObjectProtocol<'p> {
type Result: Into<PyResult<Self::Success>>;
}
pub trait PyObjectHashProtocol<'p>: PyObjectProtocol<'p> {
type Result: Into<PyResult<usize>>;
type Result: Into<PyResult<isize>>;
}
pub trait PyObjectBoolProtocol<'p>: PyObjectProtocol<'p> {
type Result: Into<PyResult<bool>>;
@ -322,7 +322,7 @@ impl<T> PyObjectHashProtocolImpl for T
{
#[inline]
fn tp_hash() -> Option<ffi::hashfunc> {
py_unary_func!(PyObjectHashProtocol, T::__hash__, usize, HashConverter, ffi::Py_hash_t)
py_unary_func!(PyObjectHashProtocol, T::__hash__, isize, HashConverter, ffi::Py_hash_t)
}
}

View file

@ -85,7 +85,7 @@ pub trait ObjectProtocol {
/// Retrieves the hash code of the object.
/// This is equivalent to the Python expression: 'hash(self)'
fn hash(&self) -> PyResult<ffi::Py_hash_t>;
fn hash(&self) -> PyResult<isize>;
/// Returns whether the object is considered to be true.
/// This is equivalent to the Python expression: 'not not self'
@ -275,7 +275,7 @@ impl<T> ObjectProtocol for T where T: PyObjectWithToken + ToPyPointer {
}
#[inline]
fn hash(&self) -> PyResult<ffi::Py_hash_t> {
fn hash(&self) -> PyResult<isize> {
let v = unsafe { ffi::PyObject_Hash(self.as_ptr()) };
if v == -1 {
Err(PyErr::fetch(self.token()))

View file

@ -539,8 +539,8 @@ struct Comparisons {
#[py::proto]
impl PyObjectProtocol for Comparisons {
fn __hash__(&self) -> PyResult<usize> {
Ok(self.val as usize)
fn __hash__(&self) -> PyResult<isize> {
Ok(self.val as isize)
}
fn __bool__(&self) -> PyResult<bool> {
Ok(self.val != 0)