-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for Float Overflow resulting in VM Crash #837
Conversation
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.
Just a question, but LGTM!
@@ -53,32 +53,38 @@ from_list!(s_from_list_str, String); | |||
macro_rules! from_list_float { | |||
($name:ident, $type:ty, $module:ident) => { | |||
#[rustler::nif(schedule = "DirtyCpu")] | |||
pub fn $name(name: &str, val: Term) -> ExSeries { | |||
pub fn $name(name: &str, val: Term) -> NifResult<ExSeries> { |
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.
Is it necessary to use Rustler's NifResult here? Do you know if the Result<ExSeries, ExplorerError>
could be used instead?
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.
Two reasons:
Result<ExSeries, ExplorerError>
will unwrap to{:ok, series}
or{:error, _}
instead ofseries
. This will break our existing code as others return ex_series.NifResult<ExSeries>
will unwrap toseries
or raisesArgumentError/ErlangError
.NifResult<T>
is more than type alias ofResult<T, Error>
. It is special as it canReturn(T)
orRaise(T)
(anErlangError
) orBadArg
(anArgumentError
). ArgumentError is what other from_list raise - will help us in writing a wrapper for descriptive errors (Jose's suggestion in the other pr).
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.
Ok, thanks!
}), | ||
term_type => { | ||
let message = format!("from_list/2 not implemented for {term_type:?}"); | ||
Err(Error::RaiseTerm(Box::new(message))) |
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 be panic or ErlangError with message ? Let me know if I have to revert to panic!
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.
It doesn't matter much honestly. As long as it comes out properly when we show it to the user.
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.
There are other places in series.rs
file where panic!
is being used - won't it crash VM ? Is it the case that validations are done in Elixir, so these panic clause won't ever trigger ?
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.
won't it crash VM?
It won´t. Rustler catches the panics for us :)
Is it the case that validations are done in Elixir, so these panic clause won't ever trigger ?
yeah, normally we add validations so it won´t trigger the panics.
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.
Thank you
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.
@philss one last question, does rustler handle nifpanics differently in dev vs release builds? Looks like title of PR is valid only for dev/test environments.
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.
@lkarthee no, it shouldn´t be different. I guess the problem is related to the lib that catches the panics.
libunwind: stepWithCompactEncoding - invalid compact unwind encoding
I'm not sure, but looks like this is some encoding problem there.
@@ -53,32 +53,38 @@ from_list!(s_from_list_str, String); | |||
macro_rules! from_list_float { | |||
($name:ident, $type:ty, $module:ident) => { | |||
#[rustler::nif(schedule = "DirtyCpu")] | |||
pub fn $name(name: &str, val: Term) -> ExSeries { | |||
pub fn $name(name: &str, val: Term) -> NifResult<ExSeries> { |
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.
Two reasons:
Result<ExSeries, ExplorerError>
will unwrap to{:ok, series}
or{:error, _}
instead ofseries
. This will break our existing code as others return ex_series.NifResult<ExSeries>
will unwrap toseries
or raisesArgumentError/ErlangError
.NifResult<T>
is more than type alias ofResult<T, Error>
. It is special as it canReturn(T)
orRaise(T)
(anErlangError
) orBadArg
(anArgumentError
). ArgumentError is what other from_list raise - will help us in writing a wrapper for descriptive errors (Jose's suggestion in the other pr).
💚 💙 💜 💛 ❤️ |
Before
After