Skip to content
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

[Truffle] Sprintf check for too many args when $DEBUG is true #4380

Merged
merged 1 commit into from Dec 13, 2016

Conversation

bjfish
Copy link
Contributor

@bjfish bjfish commented Dec 13, 2016

Opening PR for feedback

@bjfish bjfish added the truffle label Dec 13, 2016
@@ -255,6 +264,13 @@ public PrintfSimpleParser(char[] source, Object[] arguments) {
}
}
}
if((argType == ArgType.UNNUMBERED || argType == ArgType.NONE) &&
arguments.length > argCount ){
if(isDebug){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spacing around here looks inconsistent with the rest.

} catch (InvalidFormatException e) {
throw new RaiseException(coreExceptions().argumentError(e.getMessage(), this));
}
}

protected boolean isDebug(VirtualFrame frame) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use a BooleanCastNode, using UnexpectedResultException directly is usually bad style.
MRI behaves with $DEBUG as 42 the same as true, and with nil the same as false.

@@ -1774,18 +1776,25 @@ public static long sleepFor(Node currentNode, RubyContext context, final long du

@Child private RopeNodes.MakeLeafRopeNode makeLeafRopeNode;
@Child private TaintNode taintNode;
@Child private ReadGlobalVariableNode readDebugGlobalNode;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BooleanCastNodeGen.create(ReadGlobalVariableNodeGen.create("$DEBUG"));

looks like a good way.
You need to remove the context and section from ReadGlobalVariableNode's constructor, which are not used anyway.

@eregon
Copy link
Member

eregon commented Dec 13, 2016

Looks good overall!

@bjfish bjfish force-pushed the truffle-sprintf-debug-arg-check branch from 1c9c38e to e57a242 Compare December 13, 2016 16:21
@bjfish bjfish force-pushed the truffle-sprintf-debug-arg-check branch from e57a242 to b21ffa5 Compare December 13, 2016 17:05
} catch (InvalidFormatException e) {
throw new RaiseException(coreExceptions().argumentError(e.getMessage(), this));
}
}

protected boolean isDebug(VirtualFrame frame) {
try {
return readDebugGlobalNode.executeBoolean(frame);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the right node/way equivalent of RTEST(ruby_debug) ?

Copy link
Member

@eregon eregon Dec 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BooleanCastNode. executeBoolean(frame, value).

@bjfish bjfish merged commit 37e90a2 into truffle-head Dec 13, 2016
@bjfish bjfish deleted the truffle-sprintf-debug-arg-check branch December 13, 2016 18:07
@enebo enebo modified the milestone: truffle-dev Jan 10, 2017
@enebo enebo added this to the Non-Release milestone Dec 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants