-
-
Notifications
You must be signed in to change notification settings - Fork 91
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
call on nil segfaults #78
Comments
As you found out on stackoverflow, |
Related to this most probably, the comparison operators also segfault on nil. You can see this by running example/palindrome.pn with no arguments. With the -B switch it completes successfully, but segfaults under the jit. |
The question is if we should slow down jit by checking argument types or not. |
I don't think it's necessary to type check arguments. The problem is in potion_x86_call, where it doesn't check for nil before attempting to dereference memory. I think this needs to be added to the beginning of the function, otherwise it attempts to call potion_obj_get_call which returns nil, which is then attempted to be deferenced as a memory location. Alternatively, the necessary code could be added just after the lines (in vm-x86.c) //[b]: got the method, call it (first special slot from PNClosure)
TAG_LABEL(tag_b); The memory deference for nil is in the line immediately following this. I'm not sure where the best place is to put it, nor do I have the necessary ASM skills to do the modification myself. |
Good idea. That would be only 2 lines.
I’ll try when I have a bit more time. |
Hi @rurban I've dug a bit deeper into this. This particular issue is caused by potion_object_size, which attempts to return the size of the object. Unfortunately, there are a few problems with this function.
I can confirm that the original code does not segfault when the line potion_method(obj_vt, "size", potion_object_size, 0); is commented out, indicating this is the problem. Changing the vm call function would not fix this problem, although it wouldn't hurt to still make those changes. In fact, I think the current code correctly handles null I really don't think this function is that useful and personally I would remove it unless we can find a reason to keep it. It can quite easily be confused with the length method, as we have already seen. |
Just fixed it, thanks.
size is a bit ill-defined and currently not used, yes. But I'll keep it asis for now |
I'm trying to make a program that print 100k-th odd prime number until 10M. The stackoverflow question.
But it gives
Segmentation fault (core dumped)
For reference, the working ruby version:
The text was updated successfully, but these errors were encountered: