diff --git a/test-crates/lib_with_disallowed_lib/Cargo.lock b/test-crates/lib_with_disallowed_lib/Cargo.lock index 9ee41a746..05dfb2d6d 100644 --- a/test-crates/lib_with_disallowed_lib/Cargo.lock +++ b/test-crates/lib_with_disallowed_lib/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "bitflags" version = "1.2.1" @@ -18,6 +20,29 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "indoc" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47741a8bc60fb26eb8d6e0238bbb26d8575ff623fdc97b1a2c00c050b9684ed8" +dependencies = [ + "indoc-impl", + "proc-macro-hack", +] + +[[package]] +name = "indoc-impl" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce046d161f000fffde5f432a0d034d0341dc152643b2598ed5bfce44c4f3a8f0" +dependencies = [ + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", + "unindent", +] + [[package]] name = "instant" version = "0.1.9" @@ -61,6 +86,12 @@ dependencies = [ "scopeguard", ] +[[package]] +name = "once_cell" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" + [[package]] name = "parking_lot" version = "0.11.1" @@ -86,21 +117,101 @@ dependencies = [ "winapi", ] +[[package]] +name = "paste" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45ca20c77d80be666aef2b45486da86238fabe33e38306bd3118fe4af33fa880" +dependencies = [ + "paste-impl", + "proc-macro-hack", +] + +[[package]] +name = "paste-impl" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d95a7db200b97ef370c8e6de0088252f7e0dfff7d047a28528e47456c0fc98b6" +dependencies = [ + "proc-macro-hack", +] + [[package]] name = "pkg-config" version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" +[[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + +[[package]] +name = "proc-macro2" +version = "1.0.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d" +dependencies = [ + "unicode-xid", +] + [[package]] name = "pyo3" -version = "0.13.2" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4837b8e8e18a102c23f79d1e9a110b597ea3b684c95e874eb1ad88f8683109c3" +checksum = "35100f9347670a566a67aa623369293703322bb9db77d99d7df7313b575ae0c8" dependencies = [ "cfg-if", + "indoc", "libc", "parking_lot", + "paste", + "pyo3-build-config", + "pyo3-macros", + "unindent", +] + +[[package]] +name = "pyo3-build-config" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d12961738cacbd7f91b7c43bc25cfeeaa2698ad07a04b3be0aa88b950865738f" +dependencies = [ + "once_cell", +] + +[[package]] +name = "pyo3-macros" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0bc5215d704824dfddddc03f93cb572e1155c68b6761c37005e1c288808ea8" +dependencies = [ + "pyo3-macros-backend", + "quote", + "syn", +] + +[[package]] +name = "pyo3-macros-backend" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71623fc593224afaab918aa3afcaf86ed2f43d34f6afde7f3922608f253240df" +dependencies = [ + "proc-macro2", + "pyo3-build-config", + "quote", + "syn", +] + +[[package]] +name = "quote" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +dependencies = [ + "proc-macro2", ] [[package]] @@ -124,6 +235,29 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" +[[package]] +name = "syn" +version = "1.0.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6f107db402c2c2055242dbf4d2af0e69197202e9faacbef9571bbe47f5a1b84" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "unindent" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f14ee04d9415b52b3aeab06258a3f07093182b88ba0f9b8d203f211a7a7d41c7" + [[package]] name = "vcpkg" version = "0.2.11" diff --git a/test-crates/lib_with_disallowed_lib/Cargo.toml b/test-crates/lib_with_disallowed_lib/Cargo.toml index a2aa3450d..28a578d56 100644 --- a/test-crates/lib_with_disallowed_lib/Cargo.toml +++ b/test-crates/lib_with_disallowed_lib/Cargo.toml @@ -9,5 +9,4 @@ crate-type = ["cdylib"] [dependencies] libz-sys = { version = "1.1.2", default-features = false } -# Don't use the macros feature, which makes compilation much faster -pyo3 = { version = "0.14.0", default-features = false, features = ["extension-module"] } +pyo3 = { version = "0.14.0", features = ["extension-module"] } diff --git a/test-crates/lib_with_disallowed_lib/src/lib.rs b/test-crates/lib_with_disallowed_lib/src/lib.rs index 574adbdd3..e0d8761ed 100644 --- a/test-crates/lib_with_disallowed_lib/src/lib.rs +++ b/test-crates/lib_with_disallowed_lib/src/lib.rs @@ -1,139 +1,15 @@ -/// We speed up compilation by using the expanded output and then deselecting the macro feature -/// of pyo3, removing syn and proc macros from the dependencies use pyo3::prelude::*; +#[pyfunction] fn add(x: usize, y: usize) -> usize { let _version = unsafe { libz_sys::zlibVersion() }; let sum = x + y; sum } -unsafe extern "C" fn __pyo3_raw_add( - _slf: *mut pyo3::ffi::PyObject, - _args: *mut pyo3::ffi::PyObject, - _kwargs: *mut pyo3::ffi::PyObject, -) -> *mut pyo3::ffi::PyObject { - const _LOCATION: &'static str = "add()"; +#[pymodule] +fn lib_with_disallowed_lib(_py: Python, m: &PyModule) -> PyResult<()> { + m.add_wrapped(wrap_pyfunction!(add))?; - let pool = ::pyo3::GILPool::new(); - let unwind_safe_py = std::panic::AssertUnwindSafe(pool.python()); - let result = match std::panic::catch_unwind(move || -> ::pyo3::PyResult<_> { - let _py = *unwind_safe_py; - ::pyo3::callback::convert(_py, { - let _args = _py.from_borrowed_ptr::(_args); - let _kwargs: Option<&pyo3::types::PyDict> = _py.from_borrowed_ptr_or_opt(_kwargs); - { - const PARAMS: &'static [pyo3::derive_utils::ParamDescription] = &[ - pyo3::derive_utils::ParamDescription { - name: "x", - is_optional: false, - kw_only: false, - }, - pyo3::derive_utils::ParamDescription { - name: "y", - is_optional: false, - kw_only: false, - }, - ]; - let mut output = [None; 2usize]; - let mut _args = _args; - let mut _kwargs = _kwargs; - let (_args, _kwargs) = pyo3::derive_utils::parse_fn_args( - Some(_LOCATION), - PARAMS, - _args, - _kwargs, - false, - false, - &mut output, - )?; - let arg0 = match output[0usize] { - Some(_obj) => _obj - .extract() - .map_err(|e| pyo3::derive_utils::argument_extraction_error(_py, "x", e))?, - None => { - panic!("Failed to extract required method argument") - } - }; - let arg1 = match output[1usize] { - Some(_obj) => _obj - .extract() - .map_err(|e| pyo3::derive_utils::argument_extraction_error(_py, "y", e))?, - None => { - panic!("Failed to extract required method argument") - } - }; - add(arg0, arg1) - } - }) - }) { - Ok(result) => result, - Err(e) => { - if let Some(string) = e.downcast_ref::() { - Err(::pyo3::panic::PanicException::new_err((string.clone(),))) - } else if let Some(s) = e.downcast_ref::<&str>() { - Err(::pyo3::panic::PanicException::new_err((s.to_string(),))) - } else { - Err(::pyo3::panic::PanicException::new_err(( - "panic from Rust code", - ))) - } - } - }; - result.unwrap_or_else(|e| { - e.restore(pool.python()); - ::pyo3::callback::callback_error() - }) -} -pub(crate) fn __pyo3_get_function_add<'a>( - args: impl Into>, -) -> pyo3::PyResult<&'a pyo3::types::PyCFunction> { - let name = "add\u{0}"; - let name = std::ffi::CStr::from_bytes_with_nul(name.as_bytes()).unwrap(); - let doc = std::ffi::CStr::from_bytes_with_nul(b"\x00").unwrap(); - pyo3::types::PyCFunction::internal_new( - name, - doc, - pyo3::class::PyMethodType::PyCFunctionWithKeywords(__pyo3_raw_add), - pyo3::ffi::METH_VARARGS | pyo3::ffi::METH_KEYWORDS, - args.into(), - ) -} - -fn pyo3_pure(_py: Python, m: &PyModule) -> PyResult<()> { - m.add_wrapped(&__pyo3_get_function_add)?; Ok(()) } - -#[no_mangle] -#[allow(non_snake_case)] -#[doc = r" This autogenerated function is called by the python interpreter when importing"] -#[doc = r" the module."] -pub unsafe extern "C" fn PyInit_lib_with_disallowed_lib() -> *mut pyo3::ffi::PyObject { - use pyo3::derive_utils::ModuleDef; - const NAME: &'static str = "pyo3_pure\u{0}"; - static MODULE_DEF: ModuleDef = unsafe { ModuleDef::new(NAME) }; - let pool = ::pyo3::GILPool::new(); - let unwind_safe_py = std::panic::AssertUnwindSafe(pool.python()); - let result = match std::panic::catch_unwind(move || -> ::pyo3::PyResult<_> { - let _py = *unwind_safe_py; - ::pyo3::callback::convert(_py, MODULE_DEF.make_module("", pyo3_pure)) - }) { - Ok(result) => result, - Err(e) => { - if let Some(string) = e.downcast_ref::() { - Err(::pyo3::panic::PanicException::new_err((string.clone(),))) - } else if let Some(s) = e.downcast_ref::<&str>() { - Err(::pyo3::panic::PanicException::new_err((s.to_string(),))) - } else { - Err(::pyo3::panic::PanicException::new_err(( - "panic from Rust code", - ))) - } - } - }; - result.unwrap_or_else(|e| { - e.restore(pool.python()); - ::pyo3::callback::callback_error() - }) -}