Allow setting the panic hook with parity-clib#9292
Conversation
| } | ||
|
|
||
| #[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.
should this not be unsafe to invoke?
There was a problem hiding this comment.
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. |
| /// 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.
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"
| 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.
"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!
niklasad1
left a comment
There was a problem hiding this comment.
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_hookfunction in the API of parity-as-a-library, so that we can choose what happens in case of a panic.