Skip to content

Commit

Permalink
rust: support 1.57
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Dec 7, 2021
1 parent 8a03778 commit 5d19269
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fix undefined symbol for `PyObject_HasAttr` on PyPy. [#2025](https://github.com/PyO3/pyo3/pull/2025)
- Fix memory leak in `PyErr::into_value`. [#2026](https://github.com/PyO3/pyo3/pull/2026)
- Fix clippy warning `needless-option-as-deref` in code generated by `#[pyfunction]` and `#[pymethods]`. [#2040](https://github.com/PyO3/pyo3/pull/2040)

## [0.15.1] - 2021-11-19

Expand Down
1 change: 1 addition & 0 deletions pyo3-macros-backend/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ fn impl_arg_param(

Ok(quote_arg_span! {
let #mut_ _tmp: #target_ty = #arg_value_or_default;
#[allow(clippy::needless_option_as_deref)]
let #arg_name = #borrow_tmp;
})
} else {
Expand Down
4 changes: 4 additions & 0 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ fn is_matching_endian(c: u8) -> bool {
}

/// Trait implemented for possible element types of `PyBuffer`.
///
/// # Safety
///
/// This trait must only be implemented for types which represent valid elements of Python buffers.
pub unsafe trait Element: Copy {
/// Gets whether the element specified in the format string is potentially compatible.
/// Alignment and size are checked separately from this function.
Expand Down
4 changes: 4 additions & 0 deletions src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,10 @@ impl IntoPy<Py<PyTuple>> for () {
}

/// Raw level conversion between `*mut ffi::PyObject` and PyO3 types.
///
/// # Safety
///
/// See safety notes on individual functions.
pub unsafe trait FromPyPointer<'p>: Sized {
/// Convert from an arbitrary `PyObject`.
///
Expand Down
4 changes: 4 additions & 0 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ use std::ptr::NonNull;
/// PyO3 is designed in a way that all references to those types are bound
/// to the GIL, which is why you can get a token from all references of those
/// types.
///
/// # Safety
///
/// This trait must only be implemented for types which cannot be accessed without the GIL.
pub unsafe trait PyNativeType: Sized {
/// Returns a GIL marker constrained to the lifetime of this type.
#[inline]
Expand Down
11 changes: 11 additions & 0 deletions src/type_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ use std::thread::{self, ThreadId};
/// is of `PyAny`.
///
/// This trait is intended to be used internally.
///
/// # Safety
///
/// This trait must only be implemented for types which represent valid layouts of Python objects.
pub unsafe trait PyLayout<T> {}

/// `T: PySizedLayout<U>` represents that `T` is not a instance of
Expand All @@ -31,6 +35,11 @@ pub trait PySizedLayout<T>: PyLayout<T> + Sized {}
/// - the return value of type_object must always point to the same PyTypeObject instance
///
/// It is safely implemented by the `pyclass` macro.
///
/// # Safety
///
/// Implementations must provide an implementation for `type_object_raw` which infallibly produces a
/// non-null pointer to the corresponding Python type object.
pub unsafe trait PyTypeInfo: Sized {
/// Class name.
const NAME: &'static str;
Expand All @@ -57,6 +66,8 @@ pub unsafe trait PyTypeInfo: Sized {

/// Python object types that have a corresponding type object.
///
/// # Safety
///
/// This trait is marked unsafe because not fulfilling the contract for type_object
/// leads to UB.
///
Expand Down
21 changes: 11 additions & 10 deletions tests/test_compile_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ fn _test_compile_errors() {
t.compile_fail("tests/ui/invalid_argument_attributes.rs");
t.compile_fail("tests/ui/missing_clone.rs");
t.compile_fail("tests/ui/reject_generics.rs");
t.compile_fail("tests/ui/wrong_aspyref_lifetimes.rs");

tests_rust_1_49(&t);
tests_rust_1_54(&t);
tests_rust_1_55(&t);
tests_rust_1_56(&t);
tests_rust_1_57(&t);

#[rustversion::since(1.49)]
fn tests_rust_1_49(t: &trybuild::TestCases) {
Expand All @@ -42,14 +41,6 @@ fn _test_compile_errors() {
#[rustversion::before(1.49)]
fn tests_rust_1_49(_t: &trybuild::TestCases) {}

#[rustversion::since(1.54)]
fn tests_rust_1_54(t: &trybuild::TestCases) {
t.compile_fail("tests/ui/invalid_frompy_derive.rs");
t.compile_fail("tests/ui/static_ref.rs");
}
#[rustversion::before(1.54)]
fn tests_rust_1_54(_t: &trybuild::TestCases) {}

#[rustversion::since(1.55)]
fn tests_rust_1_55(t: &trybuild::TestCases) {
t.compile_fail("tests/ui/invalid_pymethod_receiver.rs");
Expand All @@ -70,4 +61,14 @@ fn _test_compile_errors() {

#[rustversion::before(1.56)]
fn tests_rust_1_56(_t: &trybuild::TestCases) {}

#[rustversion::since(1.57)]
fn tests_rust_1_57(t: &trybuild::TestCases) {
t.compile_fail("tests/ui/invalid_frompy_derive.rs");
t.compile_fail("tests/ui/static_ref.rs");
t.compile_fail("tests/ui/wrong_aspyref_lifetimes.rs");
}

#[rustversion::before(1.57)]
fn tests_rust_1_57(_t: &trybuild::TestCases) {}
}
4 changes: 2 additions & 2 deletions tests/ui/invalid_argument_attributes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ error: expected `from_py_with`
| ^^^

error: expected `=`
--> tests/ui/invalid_argument_attributes.rs:7:32
--> tests/ui/invalid_argument_attributes.rs:7:45
|
7 | fn from_py_with_no_value(#[pyo3(from_py_with)] param: String) {}
| ^^^^^^^^^^^^^^
| ^

error: expected `from_py_with`
--> tests/ui/invalid_argument_attributes.rs:10:31
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/invalid_frompy_derive.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ error: attribute name cannot be empty
| ^^

error: unexpected end of input, expected string literal
--> tests/ui/invalid_frompy_derive.rs:100:21
--> tests/ui/invalid_frompy_derive.rs:100:22
|
100 | #[pyo3(attribute())]
| ^^
| ^

error: expected at most one argument: `item` or `item(key)`
--> tests/ui/invalid_frompy_derive.rs:106:20
Expand All @@ -121,10 +121,10 @@ error: expected at most one argument: `item` or `item(key)`
| ^

error: unexpected end of input, expected literal
--> tests/ui/invalid_frompy_derive.rs:112:16
--> tests/ui/invalid_frompy_derive.rs:112:17
|
112 | #[pyo3(item())]
| ^^
| ^

error: only one of `attribute` or `item` can be provided
--> tests/ui/invalid_frompy_derive.rs:118:5
Expand Down Expand Up @@ -171,10 +171,10 @@ error: cannot derive FromPyObject for empty structs and variants
= note: this error originates in the derive macro `FromPyObject` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected `=`
--> tests/ui/invalid_frompy_derive.rs:158:11
--> tests/ui/invalid_frompy_derive.rs:158:24
|
158 | #[pyo3(from_py_with)]
| ^^^^^^^^^^^^^^
| ^

error: expected string literal
--> tests/ui/invalid_frompy_derive.rs:164:27
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/static_ref.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'py`
4 | #[pyfunction]
| ^^^^^^^^^^^^^
|
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the body at 4:1...
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined here...
--> tests/ui/static_ref.rs:4:1
|
4 | #[pyfunction]
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/wrong_aspyref_lifetimes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ error[E0505]: cannot move out of `gil` because it is borrowed
--> tests/ui/wrong_aspyref_lifetimes.rs:7:10
|
6 | let dict: &PyDict = dict.as_ref(gil.python());
| --- borrow of `gil` occurs here
| ------------ borrow of `gil` occurs here
7 | drop(gil);
| ^^^ move out of `gil` occurs here
8 |
9 | let _py: Python = dict.py(); // Obtain a Python<'p> without GIL.
| ---- borrow later used here
| --------- borrow later used here

0 comments on commit 5d19269

Please sign in to comment.