pyo3_ffi/
pyhash.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
use crate::pyport::{Py_hash_t, Py_ssize_t};
#[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
use std::os::raw::{c_char, c_void};

use std::os::raw::{c_int, c_ulong};

extern "C" {
    // skipped non-limited _Py_HashDouble
    // skipped non-limited _Py_HashPointer
    // skipped non-limited _Py_HashPointerRaw

    #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
    pub fn _Py_HashBytes(src: *const c_void, len: Py_ssize_t) -> Py_hash_t;
}

pub const _PyHASH_MULTIPLIER: c_ulong = 1000003;

// skipped _PyHASH_BITS

// skipped non-limited _Py_HashSecret_t

#[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct PyHash_FuncDef {
    pub hash: Option<extern "C" fn(arg1: *const c_void, arg2: Py_ssize_t) -> Py_hash_t>,
    pub name: *const c_char,
    pub hash_bits: c_int,
    pub seed_bits: c_int,
}

#[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
impl Default for PyHash_FuncDef {
    #[inline]
    fn default() -> Self {
        unsafe { std::mem::zeroed() }
    }
}

extern "C" {
    #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
    pub fn PyHash_GetFuncDef() -> *mut PyHash_FuncDef;
}

// skipped Py_HASH_CUTOFF

pub const Py_HASH_EXTERNAL: c_int = 0;
pub const Py_HASH_SIPHASH24: c_int = 1;
pub const Py_HASH_FNV: c_int = 2;

// skipped Py_HASH_ALGORITHM