-
Notifications
You must be signed in to change notification settings - Fork 62
Fix uniqint SIGSEGV for objects with no int overload #138
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
base: master
Are you sure you want to change the base?
Conversation
In case uniqint takes several objects, it always tries to call their int overload using amagic_call. This patch fixes the case when amagic_call returned NULL resulting into Segmentation Violation. Several tests are also added to ensure proper objects handling. Signed-off-by: Sergei Zhmylev <zhmylove@narod.ru>
76bb5f9 to
39e539e
Compare
| if(SvAMAGIC(arg) && (arg = AMG_CALLun(arg, int))) | ||
| ; /* nothing to do */ | ||
| if(SvAMAGIC(arg)) { | ||
| if(!(arg = AMG_CALLun(arg, int))) |
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.
Hmm. This adds a new exception condition where there didn't used to be one. I wonder if that change in behaviour would break too much.
I'd prefer to preserve the existing condition, but without trashing the arg value. Instead, perhaps have:
SV *mgret;
if(SvAMAGIC(arg) && (mgret = AMG_CALLun(arg, int)))
arg = mgret;
else ...that way, it keeps the existing condition, but does not trash the value in arg when there is some magic but no int_amg.
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.
Thanks!
Yes, I actually suggested this particular change in #137
But after that I thought a little bit more about that and decided to write this with croak just like int() does in this situation. Mostly due to uniqint() means literally: "remove subsequent duplicates based on int() values of the list supplied to it" and in turn int() does croak() for such objects.
This change will definitely not break any existing code as it croaks only instead of Segmentation Violation error which causes exit even inside eval
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.
A croak seems appropriate to me, since that is what a missing overload does anywhere else.
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.
Ahyes. In that case, does the message match what would happen normally?
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.
The message does not match.
But looking at the code for amagic_call, it isn't obvious why the previous code isn't already working correctly. It seems like it should already be producing an appropriate croak if the overload doesn't exist.
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.
@leonerd > what would happen normally
In 5.42.0, just like in the older versions, it still results into a crash with segmentation violation.
Typical error of missing "int" overload looks like:
Operation "+": no method found,
left argument has no overloaded magic,
right argument in overloaded package OverloadedPackageWithoutInt at -e line 1.
To me, this does not look meaningful in case of uniqint().
Maybe we should merge this PR to avoid segmentation faults in Perl core modules?
In my solution the message tells No "int" method found in overloaded package and highlights the line with uniqint() call.
|
The Perl 5.6 smoker looks unhappy, but looks like a machine setup issue, unrelated to this change. |
In case uniqint takes several objects, it always tries to call their int overload using amagic_call. This patch fixes the case when amagic_call returned NULL resulting into Segmentation Violation. Several tests are also added to ensure proper objects handling.
Problem:
The code below expected to work but crashes with SIGSEGV.