Skip to content

Commit

Permalink
perform PyLong check for 3.8 too
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Jan 16, 2024
1 parent 8652664 commit 1daf803
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/conversions/std/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ macro_rules! extract_int {
};

($obj:ident, $error_val:expr, $pylong_as:expr, $force_index_call: literal) => {
// with python 3.8+ PyLong_AsLong takes care of calling PyNumber_Index itself
// with python 3.9+ PyLong_AsLong takes care of calling PyNumber_Index itself
// hence no need for the slow `PyNumber_Index` path
// `PyLong_AsUnsignedLongLong` does not call `__index__`, hence the `force_index_call` argument
// see https://github.com/PyO3/pyo3/pull/3742 for detials.
if cfg!(Py_3_8) && !$force_index_call {
// 3.8 is a special case where `PyNumber_Index` is called but has slightly different semantics
// thus we use the conservative path for 3.8
// See https://github.com/PyO3/pyo3/pull/3742 for detials
if cfg!(Py_3_9) && !$force_index_call {
err_if_invalid_value($obj.py(), $error_val, unsafe { $pylong_as($obj.as_ptr()) })
} else if let Ok(long) = $obj.downcast::<crate::types::PyLong>() {
// with 3.7 we have to do the `PyNumber_Index` check ourselves
Expand Down

0 comments on commit 1daf803

Please sign in to comment.