Skip to content

Commit

Permalink
Draft: Allows to introspect Python modules from cdylib
Browse files Browse the repository at this point in the history
  • Loading branch information
Tpt committed Jun 11, 2024
1 parent 344293c commit 88907c8
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions pyo3-macros-backend/src/introspection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,14 @@ pub fn function_introspection_code(pyo3_crate_path: &PyO3CratePath, name: &str)
}

fn stub_section(content: impl ToTokens) -> TokenStream {
if cfg!(target_family = "wasm") {
// Sadly WASM only supports in custom sections only static values without references.
return quote!();
}
let section_name = if cfg!(any(target_os = "macos", target_os = "ios")) {
"__TEXT,__pyo3i0"
} else {
".pyo3i0"
};
let static_name = format_ident!("PYO3_INTRS_{}", unique_element_id());
// #[no_mangle] is required to make sure some linkers like Linux ones do not mangle the section name too.
quote! {
const _: () = {
#[used]
#[link_section = #section_name]
#[cfg(not(target_family = "wasm"))]
#[cfg_attr(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos"), link_section = "__TEXT,__pyo3i0")]
#[cfg_attr(not(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos")), link_section = ".pyo3i0")]
#[no_mangle]
static #static_name: &'static str = #content;
};
Expand Down

0 comments on commit 88907c8

Please sign in to comment.