Move cxxbridge05$exception declaration to builtins
diff --git a/gen/src/builtin.rs b/gen/src/builtin.rs
index 4b8dce5..36e32f8 100644
--- a/gen/src/builtin.rs
+++ b/gen/src/builtin.rs
@@ -22,6 +22,7 @@
pub rust_str_repr: bool,
pub rust_slice_new: bool,
pub rust_slice_repr: bool,
+ pub exception: bool,
pub content: Content<'a>,
}
@@ -195,4 +196,13 @@
}
out.end_block(Block::Namespace("rust"));
+
+ if builtin.exception {
+ out.begin_block(Block::ExternC);
+ writeln!(
+ out,
+ "const char *cxxbridge05$exception(const char *, size_t);",
+ );
+ out.end_block(Block::ExternC);
+ }
}
diff --git a/gen/src/write.rs b/gen/src/write.rs
index 2b4e552..3498ef9 100644
--- a/gen/src/write.rs
+++ b/gen/src/write.rs
@@ -106,7 +106,6 @@
if !out.header {
out.begin_block(Block::ExternC);
- write_exception_glue(out, apis);
for api in apis {
match api {
Api::CxxFunction(efn) => write_cxx_function_shim(out, efn),
@@ -316,26 +315,6 @@
);
}
-fn write_exception_glue(out: &mut OutFile, apis: &[&Api]) {
- let mut has_cxx_throws = false;
- for api in apis {
- if let Api::CxxFunction(efn) = api {
- if efn.throws {
- has_cxx_throws = true;
- break;
- }
- }
- }
-
- if has_cxx_throws {
- out.next_section();
- writeln!(
- out,
- "const char *cxxbridge05$exception(const char *, size_t);",
- );
- }
-}
-
fn write_cxx_function_shim(out: &mut OutFile, efn: &ExternFn) {
out.next_section();
if let Some(annotation) = &out.opt.cxx_impl_annotations {
@@ -500,13 +479,14 @@
writeln!(out, ";");
if efn.throws {
out.include.cstring = true;
+ out.builtin.exception = true;
writeln!(out, " throw$.ptr = nullptr;");
writeln!(out, " }},");
writeln!(out, " [&](const char *catch$) noexcept {{");
writeln!(out, " throw$.len = ::std::strlen(catch$);");
writeln!(
out,
- " throw$.ptr = cxxbridge05$exception(catch$, throw$.len);",
+ " throw$.ptr = ::cxxbridge05$exception(catch$, throw$.len);",
);
writeln!(out, " }});");
writeln!(out, " return throw$;");