File tree Expand file tree Collapse file tree 3 files changed +9
-10
lines changed
Expand file tree Collapse file tree 3 files changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -179,18 +179,18 @@ pub fn lcg_urandom(mut x: u32, buf: &mut [u8]) {
179179 }
180180}
181181
182- pub fn hash_pointer_raw ( p : * const std :: ffi :: c_void ) -> PyHash {
182+ pub fn hash_object_id_raw ( p : usize ) -> PyHash {
183183 // TODO: Use commented logic when below issue resolved.
184184 // Ref: https://github.com/RustPython/RustPython/pull/3951#issuecomment-1193108966
185185
186- // let mut y = p as usize ;
186+ // let mut y = p;
187187 // /* bottom 3 or 4 bits are likely to be 0; rotate y by 4 to avoid
188188 // excessive hash collisions for dicts and sets */
189189 // y = (y >> 4) | (y << (8 * std::mem::size_of::<usize>() - 4));
190190 // y as PyHash
191191 p as PyHash
192192}
193193
194- pub fn hash_pointer ( p : * const std :: ffi :: c_void ) -> PyHash {
195- fix_sentinel ( hash_pointer_raw ( p) )
194+ pub fn hash_object_id ( p : usize ) -> PyHash {
195+ fix_sentinel ( hash_object_id_raw ( p) )
196196}
Original file line number Diff line number Diff line change @@ -420,11 +420,11 @@ impl Hashable for PyComplex {
420420 fn hash ( zelf : & crate :: Py < Self > , _vm : & VirtualMachine ) -> PyResult < hash:: PyHash > {
421421 let value = zelf. value ;
422422
423- let re_hash = hash :: hash_float ( value . re )
424- . unwrap_or_else ( || hash:: hash_pointer ( zelf as * const _ as * const std :: ffi :: c_void ) ) ;
423+ let re_hash =
424+ hash :: hash_float ( value . re ) . unwrap_or_else ( || hash:: hash_object_id ( zelf. get_id ( ) ) ) ;
425425
426- let im_hash = hash :: hash_float ( value . im )
427- . unwrap_or_else ( || hash:: hash_pointer ( zelf as * const _ as * const std :: ffi :: c_void ) ) ;
426+ let im_hash =
427+ hash :: hash_float ( value . im ) . unwrap_or_else ( || hash:: hash_object_id ( zelf. get_id ( ) ) ) ;
428428
429429 let Wrapping ( ret) = Wrapping ( re_hash) + Wrapping ( im_hash) * Wrapping ( hash:: IMAG ) ;
430430 Ok ( hash:: fix_sentinel ( ret) )
Original file line number Diff line number Diff line change @@ -539,8 +539,7 @@ impl Comparable for PyFloat {
539539impl Hashable for PyFloat {
540540 #[ inline]
541541 fn hash ( zelf : & crate :: Py < Self > , _vm : & VirtualMachine ) -> PyResult < hash:: PyHash > {
542- Ok ( hash:: hash_float ( zelf. to_f64 ( ) )
543- . unwrap_or_else ( || hash:: hash_pointer ( zelf as * const _ as * const libc:: c_void ) ) )
542+ Ok ( hash:: hash_float ( zelf. to_f64 ( ) ) . unwrap_or_else ( || hash:: hash_object_id ( zelf. get_id ( ) ) ) )
544543 }
545544}
546545
You can’t perform that action at this time.
0 commit comments