Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get all the tests building and passing! #1189

Merged
merged 1 commit into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion guide/src/class.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ You can also inherit native types such as `PyDict`, if they implement
However, because of some technical problems, we don't currently provide safe upcasting methods for types
that inherit native types. Even in such cases, you can unsafely get a base class by raw pointer conversion.

```rust
```rust,no_run
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the problem with this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subclasses a builtin type which isn't support on abi3 (and I don't know how to make a doc test no_run only in some cfgs)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, though I'll have to modify this when it is changed to raise a compile error.

# use pyo3::prelude::*;
use pyo3::types::PyDict;
use pyo3::{AsPyPointer, PyNativeType};
Expand Down
3 changes: 1 addition & 2 deletions pyo3-derive-backend/src/from_pyobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl<'a> Container<'a> {
let self_ty = &self.path;
let mut fields: Punctuated<TokenStream, syn::Token![,]> = Punctuated::new();
for i in 0..len {
fields.push(quote!(slice[#i].extract()?));
fields.push(quote!(s.get_item(#i).extract()?));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the memory layout different for PyTuples with limited ABI? I know this change here is necessary because as_slice() is no longer available on PyTuple:

pyo3/src/types/tuple.rs

Lines 84 to 93 in 2ec1c3b

#[cfg(not(Py_LIMITED_API))]
pub fn as_slice(&self) -> &[&PyAny] {
// This is safe because &PyAny has the same memory layout as *mut ffi::PyObject,
// and because tuples are immutable.
unsafe {
let ptr = self.as_ptr() as *mut ffi::PyTupleObject;
let slice = slice::from_raw_parts((*ptr).ob_item.as_ptr(), self.len());
&*(slice as *const [*mut ffi::PyObject] as *const [&PyAny])
}
}

It probably won't have a measurable impact anyways, just curious..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They can be, which is the whole point of the limited ABI :-)

}
let msg = if self.is_enum_variant {
quote!(format!(
Expand All @@ -265,7 +265,6 @@ impl<'a> Container<'a> {
if s.len() != #len {
return Err(::pyo3::exceptions::PyValueError::new_err(#msg))
}
let slice = s.as_slice();
Ok(#self_ty(#fields))
)
}
Expand Down
4 changes: 3 additions & 1 deletion src/types/floatob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ impl<'source> FromPyObject<'source> for f32 {
mod test {
#[cfg(not(Py_LIMITED_API))]
use crate::ffi::PyFloat_AS_DOUBLE;
use crate::{AsPyPointer, Python, ToPyObject};
#[cfg(not(Py_LIMITED_API))]
use crate::AsPyPointer;
use crate::{Python, ToPyObject};

macro_rules! num_to_py_object_and_back (
($func_name:ident, $t1:ty, $t2:ty) => (
Expand Down
2 changes: 2 additions & 0 deletions tests/test_buffer_protocol.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(not(Py_LIMITED_API))]

use pyo3::buffer::PyBuffer;
use pyo3::class::PyBufferProtocol;
use pyo3::exceptions::PyBufferError;
Expand Down
4 changes: 4 additions & 0 deletions tests/test_dunder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ fn test_cls_impl() {
struct DunderDictSupport {}

#[test]
#[cfg_attr(Py_LIMITED_API, ignore)]
fn dunder_dict_support() {
let gil = Python::acquire_gil();
let py = gil.python();
Expand All @@ -472,6 +473,7 @@ fn dunder_dict_support() {
}

#[test]
#[cfg_attr(Py_LIMITED_API, ignore)]
fn access_dunder_dict() {
let gil = Python::acquire_gil();
let py = gil.python();
Expand All @@ -493,6 +495,7 @@ struct InheritDict {
}

#[test]
#[cfg_attr(Py_LIMITED_API, ignore)]
fn inherited_dict() {
let gil = Python::acquire_gil();
let py = gil.python();
Expand All @@ -511,6 +514,7 @@ fn inherited_dict() {
struct WeakRefDunderDictSupport {}

#[test]
#[cfg_attr(Py_LIMITED_API, ignore)]
fn weakref_dunder_dict_support() {
let gil = Python::acquire_gil();
let py = gil.python();
Expand Down
14 changes: 13 additions & 1 deletion tests/test_gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ fn gc_integration2() {
struct WeakRefSupport {}

#[test]
#[cfg_attr(Py_LIMITED_API, ignore)]
fn weakref_support() {
let gil = Python::acquire_gil();
let py = gil.python();
Expand All @@ -168,6 +169,7 @@ struct InheritWeakRef {
}

#[test]
#[cfg_attr(Py_LIMITED_API, ignore)]
fn inherited_weakref() {
let gil = Python::acquire_gil();
let py = gil.python();
Expand Down Expand Up @@ -269,6 +271,16 @@ impl PyGCProtocol for TraversableClass {
}
}

#[cfg(PyPy)]
unsafe fn get_type_traverse(tp: *mut pyo3::ffi::PyTypeObject) -> Option<pyo3::ffi::traverseproc> {
(*tp).tp_traverse
}

#[cfg(not(PyPy))]
unsafe fn get_type_traverse(tp: *mut pyo3::ffi::PyTypeObject) -> Option<pyo3::ffi::traverseproc> {
std::mem::transmute(pyo3::ffi::PyType_GetSlot(tp, pyo3::ffi::Py_tp_traverse))
}

#[test]
fn gc_during_borrow() {
let gil = Python::acquire_gil();
Expand All @@ -285,7 +297,7 @@ fn gc_during_borrow() {

// get the traverse function
let ty = TraversableClass::type_object(py).as_type_ptr();
let traverse = (*ty).tp_traverse.unwrap();
let traverse = get_type_traverse(ty).unwrap();

// create an object and check that traversing it works normally
// when it's not borrowed
Expand Down
4 changes: 4 additions & 0 deletions tests/test_inheritance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ impl SetWithName {
}
}

// Subclassing builtin types is not allowed in the LIMITED API.
#[test]
#[cfg_attr(Py_LIMITED_API, should_panic)]
fn inherit_set() {
let gil = Python::acquire_gil();
let py = gil.python();
Expand All @@ -195,7 +197,9 @@ impl DictWithName {
}
}

// Subclassing builtin types is not allowed in the LIMITED API.
#[test]
#[cfg_attr(Py_LIMITED_API, should_panic)]
fn inherit_dict() {
let gil = Python::acquire_gil();
let py = gil.python();
Expand Down
3 changes: 3 additions & 0 deletions tests/test_pyfunction.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(not(Py_LIMITED_API))]
use pyo3::buffer::PyBuffer;
use pyo3::prelude::*;
use pyo3::types::{PyCFunction, PyFunction};
Expand All @@ -23,6 +24,7 @@ fn test_optional_bool() {
py_assert!(py, f, "f(None) == 'None'");
}

#[cfg(not(Py_LIMITED_API))]
#[pyfunction]
fn buffer_inplace_add(py: Python, x: PyBuffer<i32>, y: PyBuffer<i32>) {
let x = x.as_mut_slice(py).unwrap();
Expand All @@ -33,6 +35,7 @@ fn buffer_inplace_add(py: Python, x: PyBuffer<i32>, y: PyBuffer<i32>) {
}
}

#[cfg(not(Py_LIMITED_API))]
#[test]
fn test_buffer_add() {
let gil = Python::acquire_gil();
Expand Down
2 changes: 2 additions & 0 deletions tests/test_unsendable_dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ impl UnsendableDictClass {
}

#[test]
#[cfg_attr(Py_LIMITED_API, ignore)]
fn test_unsendable_dict() {
let gil = Python::acquire_gil();
let py = gil.python();
Expand All @@ -32,6 +33,7 @@ impl UnsendableDictClassWithWeakRef {
}

#[test]
#[cfg_attr(Py_LIMITED_API, ignore)]
fn test_unsendable_dict_with_weakref() {
let gil = Python::acquire_gil();
let py = gil.python();
Expand Down
1 change: 1 addition & 0 deletions tests/test_various.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ fn add_module(py: Python, module: &PyModule) -> PyResult<()> {
}

#[test]
#[cfg_attr(Py_LIMITED_API, ignore)]
fn test_pickle() {
let gil = Python::acquire_gil();
let py = gil.python();
Expand Down