-
Notifications
You must be signed in to change notification settings - Fork 707
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
Added checks for clang::Cursor::template_arg_value #215
Conversation
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @fitzgen (or someone else) soon. |
Is there any caller in this function? If not, let's rip it out. |
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 @cynicaldevil!
If we aren't using this method anywhere, then I agree with @emilio that the best thing to do is to remove the method (sorry for not catching this when filing the issue!). Would you like to morph this PR into the method's removal?
That said, I've left a couple comments for your benefit.
I would probably write this code in a way such that the bounds checking isn't "distant" from the FFI call, like this:
pub fn template_arg_value(&self, i: c_int) -> Option<c_longlong> {
match self.num_template_args() {
// Fold bounds check into match arm.
Some(n) if 0 <= i && i < n => {
// Ok, it is safe to make the FFI call.
Some(unsafe {
clang_Cursor_getTemplateArgumentValue(self.x, i as c_uint)
})
_ => None,
}
}
One could also use https://doc.rust-lang.org/nightly/std/option/enum.Option.html#method.map or https://doc.rust-lang.org/nightly/std/option/enum.Option.html#method.and_then here instead of a match, if one preferred.
None => false | ||
}; | ||
match within_bounds { | ||
true => { |
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.
In general, using if
is usually better than match
for boolean values:
if within_bounds {
...
} else {
...
}
287866e
to
c27fe68
Compare
@fitzgen I've removed the method and updated the PR. Think I'll pick up another issue to work on as well, since this one turned out to be really trivial. |
☀️ Test successful - status-travis |
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.
Could you also remove the c_longlong
imported at the top? It's causing the warnings (which we don't allow).
c27fe68
to
0e63240
Compare
@wafflespeanut I had forgotten to to run the build step after removing the method. All good now! |
@cynicaldevil has made the changes :)
@bors-servo r=emilio |
📌 Commit 0e63240 has been approved by |
Fixes #134.
r? @fitzgen