Skip to content

Skip export prefix on certain objects #1061

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

Open
Cryoris opened this issue Mar 14, 2025 · 0 comments · May be fixed by #1064
Open

Skip export prefix on certain objects #1061

Cryoris opened this issue Mar 14, 2025 · 0 comments · May be fixed by #1064

Comments

@Cryoris
Copy link

Cryoris commented Mar 14, 2025

Problem

We'd like to expose a C API from Rust where all objects we define obtain a prefix, which can be very nicely done with

[export]
prefix = "MyPackage_" 

However, some function signatures use existing C objects, which should not obtain the prefix.

For example, say we have something like

use pyo3::ffi::PyObject;

#[repr(C)]
pub struct Thing { .. }

#[no_mangle]
#[cfg(feature = "cbinding")]
pub unsafe extern "C" fn thing_to_py(thing: *mut Thing) -> *mut PyObject { .. }

Then the resulting header looks like

typedef struct { .. } MyPackage_Thing;  // has prefix

MyPackage_PyObject* thing_to_py(MyPackage_Thing thing);  // PyObject should not have the prefix!

which is not quite what we want.

Workaround

This can be worked around by doing the prefix manual, e.g. do not set the export.prefix but instead do

[export.rename]
"Thing" = "MyPackage_Thing"
# repeat for every object, except for PyObject... 

Proposal

It would be great if there was a way to exclude objects from prefix. E.g. something like

[export]
prefix = "MyPackage_"
prefix_ignores = ["PyObject"]

But maybe I'm just missing an already existing solution (which would be even better).

@Cryoris Cryoris changed the title Skip prefix on certain objects Skip export prefix on certain objects Mar 14, 2025
@Cryoris Cryoris linked a pull request Apr 4, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant