-
Notifications
You must be signed in to change notification settings - Fork 678
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3572 from davidhewitt/sequence2-try2
implement `PySequenceMethods`, try 2
- Loading branch information
Showing
9 changed files
with
398 additions
and
121 deletions.
There are no files selected for viewing
This file contains 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,28 @@ | ||
use crate::{ffi, instance::Py2, PyAny, PyResult, Python}; | ||
|
||
mod sealed { | ||
use super::*; | ||
|
||
pub trait Sealed {} | ||
|
||
impl Sealed for *mut ffi::PyObject {} | ||
} | ||
|
||
use sealed::Sealed; | ||
|
||
pub(crate) trait FfiPtrExt: Sealed { | ||
unsafe fn assume_owned_or_err(self, py: Python<'_>) -> PyResult<Py2<'_, PyAny>>; | ||
unsafe fn assume_owned(self, py: Python<'_>) -> Py2<'_, PyAny>; | ||
} | ||
|
||
impl FfiPtrExt for *mut ffi::PyObject { | ||
#[inline] | ||
unsafe fn assume_owned_or_err(self, py: Python<'_>) -> PyResult<Py2<'_, PyAny>> { | ||
Py2::from_owned_ptr_or_err(py, self) | ||
} | ||
|
||
#[inline] | ||
unsafe fn assume_owned(self, py: Python<'_>) -> Py2<'_, PyAny> { | ||
Py2::from_owned_ptr(py, self) | ||
} | ||
} |
This file contains 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 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 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 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,22 @@ | ||
use crate::{types::any::PyAnyMethods, Py2, PyAny, PyResult}; | ||
|
||
mod sealed { | ||
use super::*; | ||
|
||
pub trait Sealed {} | ||
|
||
impl Sealed for PyResult<Py2<'_, PyAny>> {} | ||
} | ||
|
||
use sealed::Sealed; | ||
|
||
pub(crate) trait PyResultExt<'py>: Sealed { | ||
unsafe fn downcast_into_unchecked<T>(self) -> PyResult<Py2<'py, T>>; | ||
} | ||
|
||
impl<'py> PyResultExt<'py> for PyResult<Py2<'py, PyAny>> { | ||
#[inline] | ||
unsafe fn downcast_into_unchecked<T>(self) -> PyResult<Py2<'py, T>> { | ||
self.map(|instance| instance.downcast_into_unchecked()) | ||
} | ||
} |
This file contains 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 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 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.