Skip to content

Commit

Permalink
use PyErr_Clear
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Jan 15, 2024
1 parent b81ae9f commit f997f9a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 17 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ extension-module = ["pyo3/extension-module"]
lto = "fat"
codegen-units = 1
strip = true
#debug = true

[profile.bench]
debug = true
Expand Down
17 changes: 1 addition & 16 deletions src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub fn safe_repr(v: &PyAny) -> Cow<str> {
pub fn extract_i64(obj: &PyAny) -> Option<i64> {
let val = unsafe { ffi::PyLong_AsLong(obj.as_ptr()) };
if val == -1 && PyErr::occurred(obj.py()) {
_take_err(obj.py());
unsafe { ffi::PyErr_Clear() };
None
} else {
Some(val)
Expand All @@ -120,18 +120,3 @@ pub fn extract_i64(v: &PyAny) -> Option<i64> {
None
}
}

#[cfg(not(Py_3_12))]
fn _take_err(_: Python) {
let mut ptype: *mut ffi::PyObject = std::ptr::null_mut();
let mut pvalue: *mut ffi::PyObject = std::ptr::null_mut();
let mut ptraceback: *mut ffi::PyObject = std::ptr::null_mut();
unsafe { ffi::PyErr_Fetch(&mut ptype, &mut pvalue, &mut ptraceback) };
}

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

0 comments on commit f997f9a

Please sign in to comment.