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

Segfault when calling unknown method on PyObject #145

Closed
mre opened this issue Apr 30, 2018 · 0 comments · Fixed by #229
Closed

Segfault when calling unknown method on PyObject #145

mre opened this issue Apr 30, 2018 · 0 comments · Fixed by #229
Labels

Comments

@mre
Copy link

mre commented Apr 30, 2018

pyo3 version: 0.2.6
Operating System: MacOS 10.12.6

Trying to execute a non-existent method on a PyObject causes a segmentation fault.
I expected an AttributeError just like it's the case when calling a non-existent method on a &PyObjectRef.

extern crate pyo3;
use pyo3::{ObjectProtocol, PyObject, PyObjectRef, PyResult, Python};

fn main() {
    let gil = Python::acquire_gil();
    hello(gil.python()).unwrap_or_else(|e| e.print(gil.python()));
}

fn hello(py: Python) -> PyResult<()> {
    let io = py.import("io")?;
    let sio: &PyObjectRef = io.getattr("StringIO")?;

    // This works (throws an AttributeError as expected)
    // Comment this line to reproduce the segfault
    sio.call_method("asdf", (0,), pyo3::NoArgs)?;

    let sio_obj: PyObject = sio.into();
    // Segfault happens here:
    sio_obj.call_method(py, "asdf", (0,), pyo3::NoArgs)?;
    Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants