-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Allow setting the panic hook with parity-clib #9292
Conversation
parity-clib/src/lib.rs
Outdated
@@ -162,3 +163,21 @@ pub extern fn parity_rpc(client: *mut c_void, query: *const char, len: usize, ou | |||
}).unwrap_or(1) | |||
} | |||
} | |||
|
|||
#[no_mangle] | |||
pub extern fn parity_set_panic_hook(callback: extern "C" fn(*mut c_void, *const c_char, usize), param: *mut c_void) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this not be unsafe
to invoke?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right now I can call this from Rust code with crap data and it will register it as a thread-safe panic hook
I made all the other FFI functions unsafe as well. |
util/panic_hook/src/lib.rs
Outdated
/// Set the panic hook with a closure to be called. The closure receives the panic message. | ||
/// | ||
/// Depending on how Parity was compiled, after the closure either returns the process aborts or | ||
/// unwinding starts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this, can you rephrase?
I guess it should be something like "after the closure has been executed it either returns the exit code when the process terminates or the unwinding starts"
parity-clib/src/lib.rs
Outdated
impl Cb { | ||
fn call(&self, new_chain: String) { | ||
if let Some(ref cb) = self.0 { | ||
cb(self.1, new_chain.as_bytes().as_ptr() as *const _, new_chain.len()) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Duplicate struct definition", the only thing the differs is that this one is inside an Option and https://github.com/paritytech/parity-ethereum/blob/4ce97f9554d2353f225d8f47f615e85a019e0316/parity-clib/src/lib.rs#L159-#L167 is not!
Can you move the "local struct definitions"
to one file scope definition (the Option variant)
and rename it to Callback
? I think the full name is worth the effort here!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, minor grumble on the Cb struct definition
…rp_sync_on_light_client * 'master' of https://github.com/paritytech/parity: Allow setting the panic hook with parity-clib (openethereum#9292) Prevent blockchain & miner racing when accessing pending block. (openethereum#9310) Docker alpine: use multi-stage concept (openethereum#9269) Update `log` -> 0.4, `env_logger` -> 0.5. (openethereum#9294) Update tobalaba.json (openethereum#9313) Allow tx pool to be Send (openethereum#9315) Fix codecov.io badge in README (openethereum#9327) Move ethereum-specific H256FastMap type to own crate (openethereum#9307) ethcore sync decodes rlp less often (openethereum#9264)
For example on Android, we want to present the panic message to the user with a dialog box, and put it in the logs (which are not the same as stderr).
This PR adds a
parity_set_panic_hook
function in the API of parity-as-a-library, so that we can choose what happens in case of a panic.