Skip to content

Commit

Permalink
clean up ffi from pyframe to pyhash
Browse files Browse the repository at this point in the history
  • Loading branch information
deantvv committed Aug 8, 2021
1 parent e9cccd7 commit 19eb313
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/ffi/pyframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ opaque_struct!(PyFrameObject);
extern "C" {
pub fn PyFrame_GetLineNumber(f: *mut PyFrameObject) -> c_int;
}
// skipped PyFrame_GetLineNumber
// skipped PyFrame_GetCode
34 changes: 31 additions & 3 deletions src/ffi/pyhash.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
#[cfg(not(Py_LIMITED_API))]
use crate::ffi::pyport::{Py_hash_t, Py_ssize_t};
use std::os::raw::{c_char, c_int, c_void};
#[cfg(not(Py_LIMITED_API))]
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)))]
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(Py_LIMITED_API))]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct PyHash_FuncDef {
Expand All @@ -10,6 +30,7 @@ pub struct PyHash_FuncDef {
pub seed_bits: c_int,
}

#[cfg(not(Py_LIMITED_API))]
impl Default for PyHash_FuncDef {
#[inline]
fn default() -> Self {
Expand All @@ -18,7 +39,14 @@ impl Default for PyHash_FuncDef {
}

extern "C" {
#[cfg(not(any(Py_LIMITED_API, PyPy)))]
pub fn PyHash_GetFuncDef() -> *mut PyHash_FuncDef;
#[cfg(not(PyPy))]
pub fn _Py_HashBytes(src: *const c_void, len: Py_ssize_t) -> Py_hash_t;
}

// 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

0 comments on commit 19eb313

Please sign in to comment.