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

Missing PySendResult return type for pyo3::ffi::PyIter_Send #4727

Open
francis-clairicia opened this issue Nov 24, 2024 · 1 comment · May be fixed by #4746
Open

Missing PySendResult return type for pyo3::ffi::PyIter_Send #4727

francis-clairicia opened this issue Nov 24, 2024 · 1 comment · May be fixed by #4746

Comments

@francis-clairicia
Copy link

Bug Description

I wanted to use PyIter_Send function for a generator and I can't have the function result:

https://github.com/PyO3/pyo3/blob/v0.23.1/pyo3-ffi/src/abstract_.rs#L123

Steps to Reproduce

An example which should work:

use pyo3::prelude::*;
use pyo3::ffi as pyo3_ffi;

let generator_module = PyModule::from_code(
    py,
    pyo3_ffi::c_str!(
        r#"
        def gen():
            val = yield 1
            yield val
    "#
    ),
    pyo3_ffi::c_str!("generator_module.py"),
    pyo3_ffi::c_str!("generator_module"),
)?;
let generator = generator_module.getattr("gen")?.call0()?;

unsafe {
    let presult: *mut pyo3_ffi::PyObject = std::ptr::null_mut();

    match pyo3_ffi::PyIter_Send(generator.as_ptr(), py.None().as_ptr(), &mut presult) {
        pyo3_ffi::PySendResult::PYGEN_RETURN => todo!(),
        pyo3_ffi::PySendResult::PYGEN_NEXT => todo!(),
        pyo3_ffi::PySendResult::PYGEN_ERROR => todo!(),
    }
}

Backtrace

No response

Your operating system and version

Manjaro Linux 24.1

Your Python version (python --version)

Python 3.11.10

Your Rust version (rustc --version)

rustc 1.82.0 (f6e511eec 2024-10-15)

Your PyO3 version

0.23.1

How did you install python? Did you use a virtualenv?

pyenv

Additional Info

No response

@ngoldbaum
Copy link
Contributor

It looks like that header was never properly updated to capture the new API added to abstract.h in 3.10. PRs to improve the bindings are very welcome :)

It looks like PySendResult is just an integer enum so that should also be straightforward to wrap.

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