-
Notifications
You must be signed in to change notification settings - Fork 758
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
sclang: protect keysValuesArrayDo primitive #2799
sclang: protect keysValuesArrayDo primitive #2799
Conversation
This can happen in corner cases. Fixes supercollider#852.
It fails with a double error message:
But maybe someone can give me hints of how to improve it! |
lang/LangSource/PyrInterpreter3.cpp
Outdated
@@ -1758,6 +1758,18 @@ HOT void Interpret(VMGlobals *g) | |||
PyrSlot * vars = g->frame->vars; | |||
int m = slotRawInt(&vars[3]); | |||
PyrObject * obj = slotRawObject(&vars[1]); | |||
|
|||
if (IsNil(&vars[1])) { | |||
error("primitive failed: keysValuesArrayDo first argument should be an array.\n"); |
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.
Can this error message please match the others in this file? See above line 1666:
error("Integer-forBy : endval or stepval not an Integer.\n");
and below line 1967:
error("Number-forSeries : first, second or last not an Integer or Float.\n");
lang/LangSource/PyrInterpreter3.cpp
Outdated
@@ -1758,6 +1758,18 @@ HOT void Interpret(VMGlobals *g) | |||
PyrSlot * vars = g->frame->vars; | |||
int m = slotRawInt(&vars[3]); | |||
PyrObject * obj = slotRawObject(&vars[1]); | |||
|
|||
if (IsNil(&vars[1])) { |
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.
Shouldn't this check happen before lines 1759-1760?
That double error message matches what happens when hitting similar cases in 3.forBy("string");
// ERROR: Integer-forBy : endval or stepval not an Integer.
// ERROR: Primitive '_ObjectCompileString' failed.
3.forSeries("garbage");
// ERROR: Number-forSeries : first, second or last not an Integer or Float.
// ERROR: Primitive '_ObjectCompileString' failed. I think it's fine for the purposes of this PR. Thanks for this! |
There's an inconsistency between the check ( |
the check could be more elaborate, but given that this is an internal method, checking against nil is ok, I think. Alternatively, one can check how it's done in the array primitives - it is a little more complicated there. |
I still find it weird that the second error message is |
Can we get a unit test please? |
@telephon Can you give the code you used to produce that error message? I find it interesting that mine refers to the primitive The code looks pretty good; I am OK to merge once there's a unit test. :) |
I'll do a test next week. |
this code:
|
I'm not sure if I'm doing the right thing to the stack here:
|
Setting numArgsPushed = 0 fixes some issues (wrong error message and looped error handling).
Ok, setting |
(can be merged IMHO) |
I was wary of this one mainly because of the uncertain copy-pasting into the main interpreter loop, but I guess since the others seem to be similarly weird with posting |
Thanks! Eventually we should get to the bottom of why |
This can happen in corner cases. Fixes #852.