-
Notifications
You must be signed in to change notification settings - Fork 778
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
Python::allow_threads
is unsound in the presence of send_wrapper
.
#2141
Comments
One way to fix it would be to get Something we could do would be to require pub fn allow_threads<T, F>(self, f: F) -> T
where
F: FnOnce() -> T + 'static,
{
//...
} This would require removing |
Yikes, good spot! I definitely argue that it's our fault, we do slightly abuse the fact that gil-bound types don't implement I don't think I think your comment #2140 (comment) is exactly right - by having a nightly feature then users for whom the |
I'm thinking I'd like to use the |
I'd be fine with that. |
One thing I'm semi worried about is an interaction like this: pyo3's lib.rs #![feature(auto_traits, negative_impls)]
pub unsafe auto trait Foo{}
impl !Foo for Python<'_>{}
impl !Foo for PyAny{}
pub fn cant_use_non_foo<T: Foo>(_t: T){
// ...
} Users cargo.toml [dependencies]
numpy = "0.14" # Old version
pyo3 = { version = "0.15", path = "../pyo3", features = ["auto-initialize", "extension-module"]} Users code use numpy::{array, ToPyArray, Ix1, PyArray};
use pyo3::prelude::*;
fn main() {
Python::with_gil(|py| {
let py_array = array![[1i64, 2], [3, 4]].to_pyarray(py);
pyo3::cant_use_non_foo(py_array);
})
} This fails when it encounters two different
I really don't know enough about how dependencies are resolved and so on to tell whether there might be a problem with this approach. Can this be sound when different pyo3 versions are in use? |
I think there will be enough problems caused by conflicting pyo3 versions that users will find it very hard to compile a working program. And if their conflicting pyo3 versions are all >= 0.15, we have the TLDR, I don't think you need to worry about that. |
With This code is problematic with or without the use pyo3::prelude::*;
use pyo3::types::PyString;
use scoped_tls::scoped_thread_local;
fn main() {
Python::with_gil(|py| {
let string = PyString::new(py, "foo");
scoped_thread_local!(static WRAPPED: PyString);
WRAPPED.set(string, || {
py.allow_threads(|| {
WRAPPED.with(|smuggled: &PyString| {
println!("{:?}", smuggled);
});
});
});
});
} Edit: Made this a separate issue: |
It allows smuggling Python types into the closure:
Results in
error: process didn't exit successfully: target\debug\my_module.exe (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)
So I'm not sure whose fault it is:
Send
for something it wasn't meant to.send_wrapper
's, for assuming others didn't put arbitrary restrictions onSend
.The text was updated successfully, but these errors were encountered: