-
-
Notifications
You must be signed in to change notification settings - Fork 417
Fix Issue 4587 - Assert exception should not allocate #1714
Conversation
|
if( _assertHandler is null ) | ||
throw new AssertError( file, line ); | ||
import core.stdc.string : memcpy; | ||
char[1024] buffer; |
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.
declare this buffer just within the if
1024 is random and a magic number, you could be concrete with char[__traits(classInstanceSize, AssertError)] buffer;
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.
Not to mention the alignment issue - I don't think there is guarantee that char[x] array is properly aligned.
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.
Not to also mention -- this is a local buffer which you are throwing outside the function. This results in corruption. Make it a static buffer.
if( _assertHandler is null ) { | ||
enum size = __traits(classInstanceSize, AssertError); | ||
memcpy(buffer.ptr, typeid(AssertError).initializer().ptr, size); | ||
auto obj = cast(AssertError) buffer.ptr; |
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.
cast is ugly, could emplace be used?
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.
emplace is from Phobos, cannot be used.
I think we should close this in favor of #1710 |
Yah, let's focus on #1710 and friends. |
Work in Progress
https://issues.dlang.org/show_bug.cgi?id=4587