Skip to content

Commit

Permalink
windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Jan 14, 2024
1 parent b474e09 commit f6240ea
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub fn safe_repr(v: &PyAny) -> Cow<str> {

/// Extract an i64 from a python object more quickly, see
/// https://github.com/PyO3/pyo3/pull/3742#discussion_r1451763928
#[cfg(not(any(target_pointer_width = "32", target_os = "windows")))]
pub fn extract_i64(obj: &PyAny) -> Option<i64> {
let val = unsafe { ffi::PyLong_AsLong(obj.as_ptr()) };
if val == -1 && PyErr::occurred(obj.py()) {
Expand All @@ -111,6 +112,15 @@ pub fn extract_i64(obj: &PyAny) -> Option<i64> {
}
}

#[cfg(any(target_pointer_width = "32", target_os = "windows"))]
pub fn extract_i64(v: &PyAny) -> Option<i64> {
if v.is_instance_of::<pyo3::types::PyInt>() {
v.extract().ok()
} else {
None
}
}

#[cfg(not(Py_3_12))]
fn _take_err(_: Python) {
let mut ptype: *mut ffi::PyObject = std::ptr::null_mut();
Expand All @@ -121,5 +131,7 @@ fn _take_err(_: Python) {

#[cfg(Py_3_12)]
fn _take_err(_: Python) {
unsafe { ffi::PyErr_GetRaisedException() }
unsafe {
ffi::PyErr_GetRaisedException();
}
}

0 comments on commit f6240ea

Please sign in to comment.