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

Segmentation fault when unwrapping a PyResult #559

Closed
Alexander-N opened this issue Jul 28, 2019 · 2 comments · Fixed by #597
Closed

Segmentation fault when unwrapping a PyResult #559

Alexander-N opened this issue Jul 28, 2019 · 2 comments · Fixed by #597
Assignees

Comments

@Alexander-N
Copy link
Member

Calling .unwrap() on a PyResult causes a segfault.

🌍 Environment

  • Your operating system and version: Ubuntu 18.10
  • Your python version: 3.6.7
  • How did you install python (e.g. apt or pyenv)? Did you use a virtualenv?: apt
  • Your rust version (rustc --version): rustc 1.38.0-nightly (83e4eed16 2019-07-14)
  • Are you using the latest pyo3 version? Have you tried using latest master (replace version = "0.x.y" with git = "https://github.com/PyO3/pyo3")? yes

💥 Reproducing

use pyo3::PyResult;
use std::net::TcpListener;

fn connect() -> PyResult<bool> {
    TcpListener::bind("127.0.0.1:80")?;
    Ok(true)
}

fn main() {
    connect().unwrap();
}
@Alexander-N
Copy link
Member Author

I guess some kind of initialization for the exception type is missing. The following panics as expected:

use pyo3::prelude::*;

fn fails() -> PyResult<(u32)> {
    Ok("not an integer".parse::<u32>()?)
}

fn main() {
    // Removing these lines causes a segfault
    let gil = Python::acquire_gil();
    let _py = gil.python();

    fails().unwrap();
}

@konstin
Copy link
Member

konstin commented Aug 5, 2019

Seems like PyErr is calling the ffi functions without acquiring the GIL first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants