-
Notifications
You must be signed in to change notification settings - Fork 829
add Py_HashBuffer
to pyo3-ffi
#5086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d5589fe
add `Py_HashBuffer` to `pyo3-ffi`
bschoenmaeckers 595be1a
Add `Py_HashBuffer` binding when 3.14+
bschoenmaeckers ff3039c
Move to `cpython/pyhash.rs`
bschoenmaeckers dc4a817
Update changelog
bschoenmaeckers a4d88a6
Enable`Py_HashBuffer` compat on 3.14 abi3
bschoenmaeckers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
- add `Py_HashBuffer` to `pyo3-ffi` | ||
- add `Py_HashPointer` to `pyo3-ffi` | ||
- add `PyObject_GenericHash` to `pyo3-ffi` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
compat_function!( | ||
originally_defined_for(all(Py_3_14, not(Py_LIMITED_API))); | ||
|
||
#[inline] | ||
pub unsafe fn Py_HashBuffer( | ||
ptr: *const std::ffi::c_void, | ||
len: crate::Py_ssize_t, | ||
) -> crate::Py_hash_t { | ||
#[cfg(not(any(Py_LIMITED_API, PyPy)))] | ||
{ | ||
crate::_Py_HashBytes(ptr, len) | ||
} | ||
|
||
#[cfg(any(Py_LIMITED_API, PyPy))] | ||
{ | ||
let bytes = crate::PyBytes_FromStringAndSize(ptr as *const std::os::raw::c_char, len); | ||
if bytes.is_null() { | ||
-1 | ||
} else { | ||
let result = crate::PyObject_Hash(bytes); | ||
crate::Py_DECREF(bytes); | ||
result | ||
} | ||
} | ||
} | ||
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#[cfg(Py_3_13)] | ||
use crate::PyObject; | ||
use crate::{Py_hash_t, Py_ssize_t}; | ||
use std::os::raw::{c_char, c_int, c_void}; | ||
|
||
#[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, | ||
} | ||
|
||
impl Default for PyHash_FuncDef { | ||
#[inline] | ||
fn default() -> Self { | ||
unsafe { std::mem::zeroed() } | ||
} | ||
} | ||
|
||
extern "C" { | ||
pub fn PyHash_GetFuncDef() -> *mut PyHash_FuncDef; | ||
#[cfg(Py_3_13)] | ||
pub fn Py_HashPointer(ptr: *const c_void) -> Py_hash_t; | ||
#[cfg(Py_3_13)] | ||
pub fn PyObject_GenericHash(obj: *mut PyObject) -> Py_hash_t; | ||
#[cfg(Py_3_14)] | ||
pub fn Py_HashBuffer(ptr: *const c_void, len: Py_ssize_t) -> Py_hash_t; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... and similar for
PyHash_GetFuncDef
, perhaps.