diff --git a/Cargo.lock b/Cargo.lock index d10a91c4f7f..fac281c3bb6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3181,9 +3181,9 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.29.3" +version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "700d18fa267b73b9b521fd7e13580e2f446916f176cacee1ab63fcc8191f1655" +checksum = "229ca13b8a15bb0d1487b81ab975bfcd97513416499a8312011b6036e42e0de4" dependencies = [ "libc", "once_cell", @@ -3195,18 +3195,18 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.29.3" +version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b3fc0c4d08f6bb10e71fe39dfb9e2f59c6eb6854e22ec8092f50c69a4499adb" +checksum = "70130e2b6dd1ee589a8788026a429561ca5c40fa7a2fa7914c2282eddae24700" dependencies = [ "target-lexicon", ] [[package]] name = "pyo3-ffi" -version = "0.29.3" +version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc0b8e19df29aad7086cf977bb0c2a2f143e30567eb113e9cf72b62ca698330" +checksum = "5e7ff73c555c286d212d4ce7e5fbda845a973c4f61bd5f160f5f2c3c2a04d1c4" dependencies = [ "libc", "pyo3-build-config", @@ -3214,26 +3214,26 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.29.3" +version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6100e8a4b5eba53afaa5ed078364851a0b2499c553a44c31026b929049b49dc6" +checksum = "c46d2e5862c7bb8207e3b639f713dda3c499933444784154c11d013c5a691b60" dependencies = [ "proc-macro2", "pyo3-macros-backend", "quote", - "syn 2.0.119", + "syn 3.0.3", ] [[package]] name = "pyo3-macros-backend" -version = "0.29.3" +version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6143877a16e82b5a727b7127ff4cd86858a24a28d745d72f43e6f227c7b1bdb3" +checksum = "38b89f066f2ae72a2aef52d1537ca2fcd104440ebfadee06e97aa90738a25b9b" dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.119", + "syn 3.0.3", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 72f06ffd758..2c09ae8041c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -267,7 +267,7 @@ pkcs8 = "0.11" proc-macro2 = "1.0.105" psm = "0.1" pymath = { git = "https://github.com/RustPython/pymath.git", rev = "dd1e9a4cf26d68caf3b549c09476f52e356e16a3", features = ["mul_add", "malachite-bigint", "complex"] } -pyo3 = "0.29" +pyo3 = "0.30" quote = "1.0.45" radium = "1.1.1" rand = "0.10" diff --git a/crates/capi/src/abstract_/iter.rs b/crates/capi/src/abstract_/iter.rs index 75834b22657..03f9fb14b1d 100644 --- a/crates/capi/src/abstract_/iter.rs +++ b/crates/capi/src/abstract_/iter.rs @@ -106,7 +106,7 @@ pub unsafe extern "C" fn PyIter_Send( #[cfg(test)] mod tests { use pyo3::prelude::*; - use pyo3::types::{PyAnyMethods, PyIterator, PyList, PySendResult}; + use pyo3::types::{PyAnyMethods, PyIterator, PyList, iterator::PySendResult}; #[test] fn next_item() { diff --git a/crates/capi/src/methodobject.rs b/crates/capi/src/methodobject.rs index 2e82c5e9daa..1f2a3baa731 100644 --- a/crates/capi/src/methodobject.rs +++ b/crates/capi/src/methodobject.rs @@ -113,25 +113,25 @@ pub(crate) fn build_method_def( }, PyMethodFlags::VARARGS => { let callable = move |args: PosArgs, vm: &VirtualMachine| unsafe { - call_function(vm, method, flags, Some(args)) + call_function(vm, method, has_self, Some(args)) }; Ok(vm.ctx.new_method_def(name, callable, flags, doc)) }, PyMethodFlags::VARARGS | PyMethodFlags::KEYWORDS => { let callable = move | args: FuncArgs, vm: &VirtualMachine| unsafe { - call_function_with_keywords(vm, method, flags, args) + call_function_with_keywords(vm, method, has_self, args) }; Ok(vm.ctx.new_method_def(name, callable, flags, doc)) }, PyMethodFlags::FASTCALL | PyMethodFlags::KEYWORDS => { let callable = move |args: FuncArgs, vm: &VirtualMachine| unsafe { - call_fast_function_with_keywords(vm, method, flags, args) + call_fast_function_with_keywords(vm, method, has_self, args) }; Ok(vm.ctx.new_method_def(name, callable, flags, doc)) }, PyMethodFlags::FASTCALL => { let callable = move |args: PosArgs, vm: &VirtualMachine| unsafe { - call_fast_function(vm, method, flags, args) + call_fast_function(vm, method, has_self, args) }; Ok(vm.ctx.new_method_def(name, callable, flags, doc)) }, @@ -160,12 +160,12 @@ pub(crate) fn build_method_def( unsafe fn call_function>( vm: &VirtualMachine, method: PyMethodPointer, - flags: PyMethodFlags, + has_self: bool, args: Option, ) -> PyResult { let f = unsafe { method.PyCFunction }; let (slf, arg_tuple) = if let Some(mut args) = args.map(Into::into) { - let slf = take_self_arg(&mut args, flags); + let slf = take_self_arg(&mut args, has_self); let arg_tuple = vm.ctx.new_tuple(args.args); (slf, Some(arg_tuple)) } else { @@ -188,11 +188,11 @@ unsafe fn call_function>( unsafe fn call_function_with_keywords( vm: &VirtualMachine, method: PyMethodPointer, - flags: PyMethodFlags, + has_self: bool, mut args: FuncArgs, ) -> PyResult { let f = unsafe { method.PyCFunctionWithKeywords }; - let slf = take_self_arg(&mut args, flags); + let slf = take_self_arg(&mut args, has_self); let slf_ptr = slf .as_ref() .map(|obj| obj.as_object().as_raw().cast_mut()) @@ -215,11 +215,11 @@ unsafe fn call_function_with_keywords( unsafe fn call_fast_function_with_keywords( vm: &VirtualMachine, method: PyMethodPointer, - flags: PyMethodFlags, + has_self: bool, mut args: FuncArgs, ) -> PyResult { let f = unsafe { method.PyCFunctionFastWithKeywords }; - let slf = take_self_arg(&mut args, flags); + let slf = take_self_arg(&mut args, has_self); let slf_ptr = slf .as_ref() .map(|obj| obj.as_object().as_raw().cast_mut()) @@ -250,12 +250,12 @@ unsafe fn call_fast_function_with_keywords( unsafe fn call_fast_function( vm: &VirtualMachine, method: PyMethodPointer, - flags: PyMethodFlags, + has_self: bool, args: PosArgs, ) -> PyResult { let f = unsafe { method.PyCFunctionFast }; let mut args: FuncArgs = args.into(); - let slf = take_self_arg(&mut args, flags); + let slf = take_self_arg(&mut args, has_self); let slf_ptr = slf .as_ref() .map(|obj| obj.as_object().as_raw().cast_mut()) @@ -267,8 +267,8 @@ unsafe fn call_fast_function( unsafe { f(slf_ptr, fastcall_arg_ptrs, args.args.len() as isize).assume_owned_or_err(vm) } } -fn take_self_arg(args: &mut FuncArgs, flags: PyMethodFlags) -> Option { - if flags.contains(PyMethodFlags::STATIC) { +fn take_self_arg(args: &mut FuncArgs, has_self: bool) -> Option { + if !has_self { None } else { args.take_positional() @@ -386,6 +386,19 @@ mod tests { }); } + #[test] + fn wrap_one_arg_function_with_no_module() { + #[pyfunction] + fn one_arg(value: i64) -> i64 { + value + } + + Python::attach(|py| { + let func = wrap_pyfunction!(one_arg, py).unwrap(); + func.call1((7,)).unwrap(); + }); + } + #[test] fn no_keywords_before_arity() { Python::attach(|py| { diff --git a/crates/capi/src/pybuffer.rs b/crates/capi/src/pybuffer.rs index b20f07c6d1b..1eec20cd3a5 100644 --- a/crates/capi/src/pybuffer.rs +++ b/crates/capi/src/pybuffer.rs @@ -326,7 +326,8 @@ mod tests { let buffer = PyBuffer::::get(&bytearray).unwrap(); assert_eq!(buffer.dimensions(), 1); assert_eq!(buffer.item_count(), 5); - buffer.as_mut_slice(py).unwrap()[0].replace(b'H'); + // SAFETY: There are no other references to the buffer. + unsafe { buffer.as_slice_ptr().unwrap().as_mut()[0] = b'H' }; drop(buffer); assert_eq!(bytearray.to_vec(), b"Hello"); });