Skip to content

Commit

Permalink
apply code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ngoldbaum committed Aug 7, 2024
1 parent b2015e0 commit a0b87d5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pyo3-ffi/src/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ use crate::pyport::Py_ssize_t;
#[cfg(not(Py_3_13))]
use std::os::raw::c_int;

#[cfg_attr(docsrs, doc(cfg(all)))]
#[cfg_attr(docsrs, doc(cfg(all())))]
#[cfg(Py_3_13)]
pub use crate::dictobject::PyDict_GetItemRef;

#[cfg_attr(docsrs, doc(cfg(all)))]
#[cfg_attr(docsrs, doc(cfg(all())))]
#[cfg(not(Py_3_13))]
pub unsafe fn PyDict_GetItemRef(
dp: *mut PyObject,
Expand Down
10 changes: 4 additions & 6 deletions src/types/list.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::iter::FusedIterator;

use crate::err::{self, PyErr, PyResult};
use crate::err::{self, PyResult};
use crate::ffi::{self, Py_ssize_t};
use crate::ffi_ptr_ext::FfiPtrExt;
use crate::internal_tricks::get_ssize_index;
Expand Down Expand Up @@ -287,12 +287,10 @@ impl<'py> PyListMethods<'py> for Bound<'py, PyList> {
/// });
/// ```
fn get_item(&self, index: usize) -> PyResult<Bound<'py, PyAny>> {
let py = self.py();
let result = unsafe { ffi::compat::PyList_GetItemRef(self.as_ptr(), index as Py_ssize_t) };
if !result.is_null() {
return Ok(unsafe { result.assume_owned(py) });
unsafe {
ffi::compat::PyList_GetItemRef(self.as_ptr(), index as Py_ssize_t)
.assume_owned_or_err(self.py())
}
Err(PyErr::fetch(py))
}

/// Gets the list item at the specified index. Undefined behavior on bad index. Use with caution.
Expand Down

0 comments on commit a0b87d5

Please sign in to comment.