-
-
Notifications
You must be signed in to change notification settings - Fork 706
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
Add std.internal.mmm and reap benefits in @safe-ty and OOM checking #3031
Conversation
|
I'm aware of the test failures and I'll fix them as soon as I can. |
|
Test success depends on #3032. |
1e8b8b9 to
7276f8c
Compare
|
How does test coverage look? |
I used DMD's coverage analysis when writing the tests. IIRC all paths are tested except the OOM paths. I'll confirm when all the dependencies are figured out. |
|
This passes now, finally. Review would be appreciated. I want to patch |
| // collectException(destroy(e)); // Issue 12647 | ||
| try | ||
| destroy(e); | ||
| catch(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.
You should have a utility function for this, destroyArrayReverse or so.
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.
+1
|
Looks great |
|
Would be awesome to address minor comments and move this in |
|
I have no skin in this game, but is there a better name we can use instead of |
ac1ce14 to
9b1963d
Compare
Also makes schwartzSort properly throw OutOfMemoryError on OOM
9b1963d to
f7c278f
Compare
|
Updated:
Passes the autotester again now. |
|
Maybe we should make destroy array deallocate the array itself, keeping in mind the use cases in schwartzSort. |
Destruction and deallocation need to be separate so that the caller can manually vet the memory safety of the deallocation with |
|
|
||
| Authors: Jakob Øvrum | ||
| */ | ||
| module std.internal.mmm; |
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 usually try to stay away from trivial matters, but mmm is quite out there. Where does it even come from?
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.
For posterity, it was meant to be "Manual Memory Management". It's an internal module so I didn't put much thought into it
|
I think this needs to be redone as a layer working with |
|
If I'm not mistaken, the two interesting/useful functions in this are essentially the same as |
|
I see that |
This patch adds a new internal module std.internal.mmm with the following functions:
Additionally, inferred purity can be supported if
mallocandcallocare markedpurein core.stdc.stdlib in the spirit of memory allocation being practically pure.Included are a few commits demonstrating how to reap benefits from this module. They can be moved to a different PR if desirable - the point is that they demonstrate the module's usefulness (hopefully).
It might be best to review this PR commit-wise.
edit:
These functions also handle OOM correctly; in Phobos, there are more examples of incorrect handling of OOM, like trying to dynamically allocate an exception, either directly or through
enforce, rather than useonOutOfMemoryError.