Skip to content

Make resolveInternalPointer @safe#5783

Merged
andralex merged 2 commits intodlang:masterfrom
edi33416:safe_alloc_resolv_int_ptr
Oct 30, 2017
Merged

Make resolveInternalPointer @safe#5783
andralex merged 2 commits intodlang:masterfrom
edi33416:safe_alloc_resolv_int_ptr

Conversation

@edi33416
Copy link
Contributor

For stand-alone allocators, such as GCAllocator, resolveInternalPointer is a @safe function.
Allocators that are building on top of such allocators should infer the safety from their parents.

This PR is a subset of #5330, as this approach will provide us with better granularity. More smaller PRs to come :)

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @edi33416! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.

Some tips to help speed things up:

  • smaller, focused PRs are easier to review than big ones

  • try not to mix up refactoring or style changes with bug fixes or feature enhancements

  • provide helpful commit messages explaining the rationale behind each change

Bear in mind that large or tricky changes may require multiple rounds of review and revision.

Please see CONTRIBUTING.md for more information.

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.

Copy link
Member

@andralex andralex left a comment

Choose a reason for hiding this comment

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

Cool. One question is whether we should make this pure as well.

bool deallocate(void[] b)
{
if (!b.ptr) return;
if (!b.ptr) return true;
Copy link
Member

Choose a reason for hiding this comment

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

how in the world did this pass until now?

Copy link
Member

@PetarKirov PetarKirov Oct 16, 2017

Choose a reason for hiding this comment

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

The only reasonable explanation is that the member function or its parent template were never instantiated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code doesn't get hit because of the __EOF__ here.

@edi33416
Copy link
Contributor Author

edi33416 commented Oct 16, 2017

@andralex I missed that. I think we should make this pure as well

assert(r == Ternary.yes && &p[0] == &buffer[0] && p.length >= buffer.length);
assert(GCAllocator.instance.resolveInternalPointer(null, p) == Ternary.no);
void *badPtr = (() @trusted => cast(void*)(0xdeadbeef))();
assert(GCAllocator.instance.resolveInternalPointer(badPtr, p) == Ternary.no);
Copy link
Member

@PetarKirov PetarKirov Oct 16, 2017

Choose a reason for hiding this comment

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

@edi33416 Circle CI fails with:

std/experimental/allocator/gc_allocator.d(180:56)[warn]: Argument 2 is named 'p', but this is the name of parameter 1

So the course of action is to use a slightly more informative name for the local variables. I would suggest renaming:

  • void[] p -> void[] result
  • Ternary r -> Ternary found

Copy link
Member

Choose a reason for hiding this comment

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

Or alternatively, void[] p -> void[] res and Ternary r -> Ternary ok if you prefer to be more terse.

@edi33416
Copy link
Contributor Author

Should I remove this __EOF__ ?

Please note that by doing so, we will make struct ThreadLocal public.

@andralex
Copy link
Member

Yes, ThreadLocal is good but let's make that a separate PR with a changelog entry associated. Thanks!

@edi33416 edi33416 force-pushed the safe_alloc_resolv_int_ptr branch 3 times, most recently from cf2307a to 88f806e Compare October 25, 2017 13:47
@andralex
Copy link
Member

@edi33416 rebase

@edi33416 edi33416 force-pushed the safe_alloc_resolv_int_ptr branch from 88f806e to c1efb05 Compare October 28, 2017 22:31
@andralex
Copy link
Member

cc @CyberShadow, DAutoTest fails with:

Root package assert_writeln_magic references unknown package libdparse

Will force pull this.

@andralex andralex merged commit 2882ff1 into dlang:master Oct 30, 2017
@CyberShadow
Copy link
Member

references unknown package

This usually means that code.dlang.org is down.

@andralex
Copy link
Member

@CyberShadow thx, can you translate to a more informative error message on the scripting side? Thx!

@CyberShadow
Copy link
Member

CyberShadow commented Oct 30, 2017

I feel really bad about doing that. @s-ludwig Could you please fix Dub to provide a better error message instead?

@wilzbach
Copy link
Contributor

wilzbach commented Nov 2, 2017

I feel really bad about doing that. @s-ludwig Could you please fix Dub to provide a better error message instead?

The 2.077.0 release contains DUB 1.6.0 which has fallback mirrors and better error messages, so the easiest path would be to bump the D compiler version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants