Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Fix _postblitRecurse for structs with private fields
Browse files Browse the repository at this point in the history
Fixup for #1181
  • Loading branch information
Jakob Ovrum committed May 6, 2015
1 parent b13ba0b commit 5318d24
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 53 deletions.
37 changes: 0 additions & 37 deletions src/core/internal/traits.d
Expand Up @@ -155,40 +155,3 @@ template hasElaborateCopyConstructor(T...)
else
enum bool hasElaborateCopyConstructor = false;
}

template staticMap(alias F, T...)
{
static if (T.length == 0)
{
alias staticMap = TypeTuple!();
}
else static if (T.length == 1)
{
alias staticMap = TypeTuple!(F!(T[0]));
}
else
{
alias staticMap =
TypeTuple!(
staticMap!(F, T[ 0 .. $/2]),
staticMap!(F, T[$/2 .. $ ]));
}
}

template isNested(T)
if(is(T == class) || is(T == struct) || is(T == union))
{
enum isNested = __traits(isNested, T);
}

private enum NameOf(alias T) = T.stringof;

template FieldNameTuple(T)
{
static if (is(T == struct) || is(T == union))
alias FieldNameTuple = staticMap!(NameOf, T.tupleof[0 .. $ - isNested!T]);
else static if (is(T == class))
alias FieldNameTuple = staticMap!(NameOf, T.tupleof);
else
alias FieldNameTuple = TypeTuple!"";
}
31 changes: 15 additions & 16 deletions src/object_.d
Expand Up @@ -170,7 +170,7 @@ auto opEquals(const Object lhs, const Object rhs)
}

private extern(C) void _d_setSameMutex(shared Object ownee, shared Object owner) nothrow;


void setSameMutex(shared Object ownee, shared Object owner)
{
_d_setSameMutex(ownee, owner);
Expand Down Expand Up @@ -213,8 +213,8 @@ class TypeInfo
override size_t toHash() @trusted const
{
import core.internal.traits : externDFunc;
alias hashOf = externDFunc!("rt.util.hash.hashOf",
size_t function(const(void)*, size_t, size_t) @trusted pure nothrow);
alias hashOf = externDFunc!("rt.util.hash.hashOf",
size_t function(const(void)*, size_t, size_t) @trusted pure nothrow);
try
{
auto data = this.toString();
Expand All @@ -232,7 +232,7 @@ class TypeInfo
override int opCmp(Object o)
{
import core.internal.traits : externDFunc;
alias dstrcmp = externDFunc!("rt.util.string.dstrcmp",
alias dstrcmp = externDFunc!("rt.util.string.dstrcmp",
int function(in char[] s1, in char[] s2) @trusted pure nothrow);

if (this is o)
Expand Down Expand Up @@ -500,7 +500,7 @@ class TypeInfo_StaticArray : TypeInfo
override string toString() const
{
import core.internal.traits : externDFunc;
alias sizeToTempString = externDFunc!("rt.util.string.sizeToTempString",
alias sizeToTempString = externDFunc!("rt.util.string.sizeToTempString",
char[] function(in size_t, char[]) @trusted pure nothrow);

char[20] tmpBuff = void;
Expand Down Expand Up @@ -1008,8 +1008,8 @@ class TypeInfo_Struct : TypeInfo
else
{
import core.internal.traits : externDFunc;
alias hashOf = externDFunc!("rt.util.hash.hashOf",
size_t function(const(void)*, size_t, size_t) @trusted pure nothrow);
alias hashOf = externDFunc!("rt.util.hash.hashOf",
size_t function(const(void)*, size_t, size_t) @trusted pure nothrow);
return hashOf(p, init().length, 0);
}
}
Expand Down Expand Up @@ -1612,7 +1612,7 @@ class Throwable : Object
void toString(scope void delegate(in char[]) sink) const
{
import core.internal.traits : externDFunc;
alias sizeToTempString = externDFunc!("rt.util.string.sizeToTempString",
alias sizeToTempString = externDFunc!("rt.util.string.sizeToTempString",
char[] function(in size_t, char[]) @trusted pure nothrow);

char[20] tmpBuff = void;
Expand Down Expand Up @@ -2281,7 +2281,7 @@ private void _destructRecurse(S)(ref S s)
static if (__traits(hasMember, S, "__dtor"))
s.__dtor();

foreach_reverse (i, ref field; s.tupleof)
foreach_reverse (ref field; s.tupleof)
{
static if (hasElaborateDestructor!(typeof(field)))
_destructRecurse(field);
Expand All @@ -2302,16 +2302,15 @@ private void _destructRecurse(E, size_t n)(ref E[n] arr)
private string _genFieldPostblit(S)()
{
import core.internal.traits : hasElaborateCopyConstructor;
import core.internal.traits : FieldNameTuple;

string code;
foreach(fieldName; FieldNameTuple!S)
foreach(i, FieldType; typeof(S.init.tupleof))
{
static if(hasElaborateCopyConstructor!(typeof(__traits(getMember, S.init, fieldName))))
static if(hasElaborateCopyConstructor!FieldType)
{
code ~= `
_postblitRecurse(s.` ~ fieldName ~ `);
scope(failure) _destructRecurse(s. ` ~ fieldName ~ `);
_postblitRecurse(s.tupleof[` ~ i.stringof ~ `]);
scope(failure) _destructRecurse(s.tupleof[` ~ i.stringof ~ `]);
`;
}
}
Expand Down Expand Up @@ -3064,8 +3063,8 @@ private size_t getArrayHash(in TypeInfo element, in void* ptr, in size_t count)
}

import core.internal.traits : externDFunc;
alias hashOf = externDFunc!("rt.util.hash.hashOf",
size_t function(const(void)*, size_t, size_t) @trusted pure nothrow);
alias hashOf = externDFunc!("rt.util.hash.hashOf",
size_t function(const(void)*, size_t, size_t) @trusted pure nothrow);
if(!hasCustomToHash(element))
return hashOf(ptr, elementSize * count, 0);

Expand Down

0 comments on commit 5318d24

Please sign in to comment.