Skip to content

Comments

Make mmap_allocator allocate @safe#6405

Merged
wilzbach merged 2 commits intodlang:masterfrom
edi33416:mmap_allocator_allocate
Apr 4, 2018
Merged

Make mmap_allocator allocate @safe#6405
wilzbach merged 2 commits intodlang:masterfrom
edi33416:mmap_allocator_allocate

Conversation

@edi33416
Copy link
Contributor

@edi33416 edi33416 commented Apr 2, 2018

This is a subset of the old #5879

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @edi33416! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the annotated coverage diff directly on GitHub with CodeCov's browser extension
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "master + phobos#6405"

@edi33416 edi33416 requested a review from PetarKirov as a code owner April 2, 2018 12:55
@jercaianu
Copy link
Contributor

Looks fine to me

nothrow @trusted @nogc
void[] allocate(size_t bytes) shared
{
import core.sys.posix.sys.mman : mmap, MAP_ANON, PROT_READ,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a second look, it might be better to use a @trusted lambda around mmap as @trusted on functions is a really anti-pattern that we soon might automatically check against.

auto p = alloc.allocate(100);
assert(p.length == 100);
() nothrow @nogc { alloc.deallocate(p); }();
() @trusted { alloc.deallocate(p); }();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also need to nullify p in the @trusted section. Else you have a dangling pointer in @safe code.

@edi33416 edi33416 force-pushed the mmap_allocator_allocate branch from 4add68a to 199bffb Compare April 3, 2018 11:29
@edi33416
Copy link
Contributor Author

edi33416 commented Apr 3, 2018

@wilzbach @aG0aep6G Can we make make mmap and VirtualAlloc pure?

@wilzbach
Copy link
Contributor

wilzbach commented Apr 3, 2018

@edi33416 have a look at dlang/druntime#1718

auto p = alloc.allocate(100);
assert(p.length == 100);
() nothrow @nogc { alloc.deallocate(p); }();
() @trusted { alloc.deallocate(p); p = null; }();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aG0aep6G good point, operated the change myself

@wilzbach wilzbach merged commit 307dd15 into dlang:master Apr 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants