-
-
Notifications
You must be signed in to change notification settings - Fork 739
Fix Issue 11338 - std.uri URIerror should be an Exception #1659
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
Conversation
DannyArends
commented
Oct 24, 2013
- URIerror renamed to URIException
- URIException class inherits from Exception
- Introduces human readable errors for URI parsing
- What to do when alloca returns NULL
- URIerror renamed to URIexception - URIexception class inherits from Exception
@@ -116,7 +116,7 @@ private string URI_Encode(dstring string, uint unescapedSet) | |||
{ | |||
R2 = cast(char *)alloca(Rsize * char.sizeof); | |||
if (!R2) |
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.
Uhm.. As far as I can tell alloca
doesn't return 0 like a regular malloc call, it's usually documented as:
alloca() returns a pointer to the beginning of the allocated space. If the allocation causes stack overflow, program behaviour is undefined.
So I'm not sure why there was a check here. But in any case, this is an error condition, not a regular exception.
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.
To be perfectly pedantic, if alloca
returns null then the appropriate exception should be something like AllocaError
(rather plain Error
to be realistic), as it has no defined cross-platform meaning. However, it's likely that the platforms that do return null from alloca
mean it to be OOM, so calling core.exception.onOutOfMemoryError
might be the right move, even though in certain programs it might result in misguided attempts at freeing heap memory then retrying, which may or may not run out of stack space again.
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.
Agreed. if alloca returns 0, then an error needs to be thrown. I think it would be wrong to call onOutOfMemoryError
, since we aren't strictly dealing with memory, but rather, throw a straight up throw new OutOfMemoryError("Alloca Failure")
. But I'm not certain about this.
Rest of the pull looks good (only gave it a quick glance though).
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.
a quick grep -r "alloca(" in phobos shows that in general the return value (0/NULL) is ignored:
stream.d: No check for NULL return value
process.d: No check for NULL return value
typecons.d: No check for NULL return value
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.
MSDN says they use SEH exceptions when alloca
fails, whereas for DMC/Posix I'm not really sure what alloca does if it fails.
True, didn't spot the allocation. Should it be separated then into an Error on allocation failure |
I think an As for the exception, it should also give some information as to what went wrong , |
@@ -36,7 +36,7 @@ private import std.c.stdlib; | |||
private import std.utf; | |||
import std.exception; | |||
|
|||
class URIerror : Error | |||
class URIexception : Exception |
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 believe the correct name would be URIException
, i.e. with a capital "E". (the old name was wrong too)
OK Thanks for your time, ps. I made a forum post also: http://forum.dlang.org/thread/xpiewrackieqynsmxmlb@forum.dlang.org |
Yep, saw it. Thanks. |
- Now call the onOutOfMemoryError() function when alloca returns NULL - Fixed the URIexception name to URIException - Added a string constructor for the URIException class - Added more informative messages to some of the errors
- Now all thrown URIException have human readable text - throw new OutOfMemoryError("Alloca Failure"); // Make code look more consistant
Hey people, Is there yet any consensus on how to handle the alloca errors ? The behaviour on an alloca failure only changes slightly with this fix.. The function used to throw an I changed it to throw OutOfMemoryError("Alloca Failure"), which is more descriptive then the previously thrown URIerror I think this is more or less the best we can do now (seeing as there is no default way to handle alloca failure under posix/unix like systems. |
if (!isHexDigit(s[k + 1]) || !isHexDigit(s[k + 2])) | ||
goto LthrowURIerror; | ||
throw new URIException("Expected HexDigit After '%'"); |
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.
"Expected two HexDigits After '%'"
also, english words: "Expected two hexadecimal digits After '%'"
LGTM appart from those two last nitpicks. Will pull after you fix and it greens. |
This is also a nitpick, but wouldn't sentence casing be better for the messages rather than the capitalization of each word? |
… for missing hexadecimals
There is a failure in the autotester (FreeBSD_64): Testing std.parallelism: FAIL Is this related to my commits ? Seems hardly possible |
Nope, it's a failure that happens from time to time. It's not your fault. Don't worry about, we know about it. |
Yes, LGTM too. We'll have to wait for the next test-run cycle so it greens. Sorry for the delay @DannyArends, we'll merge your first pull soon enough. :) |
Fix Issue 11338 - std.uri URIerror should be an Exception
TYVM for putting up with us :) |