Skip to content

Make the resolveInternalPointer method abide the IAllocator API#5274

Merged
dlang-bot merged 1 commit intodlang:masterfrom
edi33416:allocator_interface
Mar 15, 2017
Merged

Make the resolveInternalPointer method abide the IAllocator API#5274
dlang-bot merged 1 commit intodlang:masterfrom
edi33416:allocator_interface

Conversation

@edi33416
Copy link
Contributor

Have the resolveInternalPointer method defined in the module's static allocators abide the IAllocator API.

@JackStouffer
Copy link
Contributor

Ping @andralex

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.

Looking good, please mind coverage.

auto p2 = (p1.ptr + p1.length - stateSize!Suffix)
void[] p1;
Ternary r = parent.resolveInternalPointer(p, p1);
if (p1 is null)
Copy link
Member

Choose a reason for hiding this comment

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

Here you know that resolveInternalPointer is available in the parent so you need to consult its Ternary result first, not the target p1. So I think the most robust code here is:

if (r != Ternary.yes || p1 is null)
    return r;
p1 = p1[stateSize!Prefix .. $];
auto p2 = (p1.ptr + p1.length - stateSize!Suffix)
    alignDownTo(Suffix.alignof);
result = p1[0 .. p2 - p1.ptr];
return Ternary.yes;

return p1[0 .. p2 - p1.ptr];
result = p1[0 .. p2 - p1.ptr];
}
return r;
Copy link
Member

Choose a reason for hiding this comment

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

This function is also not covered, which makes the testers protest. Please add unittests (I know they should have been there before).

void[] resolveInternalPointer(void* p)
Ternary resolveInternalPointer(void* p, ref void[] result)
{
result = null;
Copy link
Member

Choose a reason for hiding this comment

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

The other path ends up assigning result twice, so move this inside the if.

Copy link
Member

Choose a reason for hiding this comment

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

On second thought I see you have two more paths that use this, so never mind. Looks good.

Copy link
Member

Choose a reason for hiding this comment

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

On third thought: we are under no obligation to assign anything to result if we return anything but Ternary.yes, so please remove this line entirely!

*/
void[] resolveInternalPointer(void*) shared const { return null; }
Ternary resolveInternalPointer(void*, ref void[]) shared const
{ return Ternary.no; }
Copy link
Member

Choose a reason for hiding this comment

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

not covered, please add unittest

{
result = impl.resolveInternalPointer(p);
return Ternary(result.ptr !is null);
return impl.resolveInternalPointer(p, result);
Copy link
Member

Choose a reason for hiding this comment

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

not covered, please add unittest

@edi33416 edi33416 force-pushed the allocator_interface branch from 21c1dfd to 85000db Compare March 15, 2017 15:05
@dlang-bot dlang-bot merged commit f76af48 into dlang:master Mar 15, 2017
@edi33416 edi33416 deleted the allocator_interface branch October 9, 2017 13:47
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.

4 participants