mirror of
https://gitee.com/openharmony/third_party_rust_bindgen
synced 2024-12-11 17:14:31 +00:00
Use panic hooks instead of using catch_unwind
One of the advantages of doing this is that `ParseCallbacks` no longer needs to implement `UnwindSafe` which means that users can rely on `RefCell` and `Cell` to extract information from the callbacks. Users relying on `catch_unwind` can still achieve similar behavior using `std:🧵:spawn`. Fixes #2147.
This commit is contained in:
parent
61ced32b93
commit
0142c0aaf7
@ -6,7 +6,6 @@ extern crate env_logger;
|
||||
extern crate log;
|
||||
|
||||
use std::env;
|
||||
use std::panic;
|
||||
|
||||
mod options;
|
||||
use crate::options::builder_from_flags;
|
||||
@ -41,18 +40,18 @@ pub fn main() {
|
||||
Ok((builder, output, verbose)) => {
|
||||
#[cfg(feature = "logging")]
|
||||
clang_version_check();
|
||||
let builder_result = panic::catch_unwind(|| {
|
||||
builder.generate().expect("Unable to generate bindings")
|
||||
});
|
||||
|
||||
if builder_result.is_err() {
|
||||
std::panic::set_hook(Box::new(move |_info| {
|
||||
if verbose {
|
||||
print_verbose_err();
|
||||
print_verbose_err()
|
||||
}
|
||||
std::process::exit(1);
|
||||
}
|
||||
}));
|
||||
|
||||
let bindings =
|
||||
builder.generate().expect("Unable to generate bindings");
|
||||
|
||||
let _ = std::panic::take_hook();
|
||||
|
||||
let bindings = builder_result.unwrap();
|
||||
bindings.write(output).expect("Unable to write output");
|
||||
}
|
||||
Err(error) => {
|
||||
|
@ -5,7 +5,6 @@ pub use crate::ir::derive::CanDerive as ImplementsTrait;
|
||||
pub use crate::ir::enum_ty::{EnumVariantCustomBehavior, EnumVariantValue};
|
||||
pub use crate::ir::int::IntKind;
|
||||
use std::fmt;
|
||||
use std::panic::UnwindSafe;
|
||||
|
||||
/// An enum to allow ignoring parsing of macros.
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
@ -25,7 +24,7 @@ impl Default for MacroParsingBehavior {
|
||||
|
||||
/// A trait to allow configuring different kinds of types in different
|
||||
/// situations.
|
||||
pub trait ParseCallbacks: fmt::Debug + UnwindSafe {
|
||||
pub trait ParseCallbacks: fmt::Debug {
|
||||
/// This function will be run on every macro that is identified.
|
||||
fn will_parse_macro(&self, _name: &str) -> MacroParsingBehavior {
|
||||
MacroParsingBehavior::Default
|
||||
|
@ -2103,11 +2103,6 @@ struct BindgenOptions {
|
||||
merge_extern_blocks: bool,
|
||||
}
|
||||
|
||||
/// TODO(emilio): This is sort of a lie (see the error message that results from
|
||||
/// removing this), but since we don't share references across panic boundaries
|
||||
/// it's ok.
|
||||
impl ::std::panic::UnwindSafe for BindgenOptions {}
|
||||
|
||||
impl BindgenOptions {
|
||||
fn build(&mut self) {
|
||||
let mut regex_sets = [
|
||||
|
Loading…
Reference in New Issue
Block a user