-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cstring: when complaing about string containing NUL, show string.
- Loading branch information
1 parent
8ef420c
commit 4af6b7e
Showing
2 changed files
with
2 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4af6b7e
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.
This seems like it'll make the call to unsafe_convert more expensive due to the creation of a GC frame? Maybe that doesn't matter give the cost of the containsnul test?
4af6b7e
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.
Wouldn't creating an
ArgumentError
with string as argument already create a GC frame?Also #11508 should reduce the cost....
Edit: I guess it's a constant string so it didn't create a GC frame....
4af6b7e
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.
This is where it might be better as:
4af6b7e
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.
It would be nice to eliminate the GC frame. My impression was that there was work in progress to more generally solve this problem.
4af6b7e
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.
However, my approach works, and is rather easy to understand, isn't it?
4af6b7e
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.
Probably irrelevant but you appear to have deleted the actual NUL check.
4af6b7e
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.
Oops!!! Yes, that was meant to have been something more like:
4af6b7e
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.
I don't think that helps since the check function is called unconditionally and creates a GC frame.
4af6b7e
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.
I wouldn't have thought that just calling a function would create the GC frame... I thought that it required allocating something, like creating the ArgumentError... I'll have to go back and look at the
@code_native
output...4af6b7e
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.
This function has the exact same properties as the function it's replacing – if
unsafe_convert
has a GC frame in the current version, why would yourcheckfornul
function not have a GC frame?4af6b7e
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.
You need noinline.
This is also the transformation I'm trying to di in my other PR...... (which sadly does not cover this case though)
4af6b7e
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.
Don't you need
@noinline
and to have the function only be called if the NUL is found?4af6b7e
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.
Oh yes. I didn't noticed that the check function is called unconditionally and the logic is in the check function.
Yes you need a error throwing function that is specialized, not inlined and only call3d on the error path
4af6b7e
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.
OK, so the test should stay in-line (better for performance), but the function that does the throw is marked as
@noinline
. I'll need to add@noinline
to my error function (but I didn't see it being in-lined anyway looking at the code).4af6b7e
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.
it's actually the
string("", repr(s))
calls that had me concerned that this would add a GC frame. throw itself does not allocate a gc-frame, but the result ofrepr(s)
needs to be rooted in the gc-stack before the call tostring
can happen.4af6b7e
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.
@vtjnash The throw local gc frame PR I had create a local gc frame for evaluating the argument of
throw
so it includes evaluation ofstring
,repr
etc. It should also be fine if the error path is isolated in a@noinline
function that does all the allocation. And yes,throw
(is special cased) to not need it's only argument rooted at all.