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

Commit

Permalink
Merge pull request #1054 from MartinNowak/fix13809
Browse files Browse the repository at this point in the history
fix Issue 13809 - dup no longer works with types with postblit and destructors
  • Loading branch information
9rnsr committed Dec 3, 2014
2 parents cad0f1d + 949e734 commit b66f2db
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
20 changes: 11 additions & 9 deletions src/object.di
Original file line number Diff line number Diff line change
Expand Up @@ -741,26 +741,28 @@ private inout(T)[] _rawDup(T)(inout(T)[] a)
return *cast(inout(T)[]*)&arr;
}

template _PostBlitType(T)
{
// assume that ref T and void* are equivalent in abi level.
static if (is(T == struct))
alias _PostBlitType = typeof(function (ref T t){ T a = t; });
else
alias _PostBlitType = typeof(delegate (ref T t){ T a = t; });
}

// Returns null, or a delegate to call postblit of T
private auto _getPostblit(T)() @trusted pure nothrow @nogc
{
// infer static postblit type, run postblit if any
static if (is(T == struct))
{
import core.internal.traits : Unqual;

// assume that ref T and void* are equivalent in abi level.
alias PostBlitT = typeof(function (ref T t){ T a = t; });

// use typeid(Unqual!T) here to skip TypeInfo_Const/Shared/...
return cast(PostBlitT)typeid(Unqual!T).xpostblit;
return cast(_PostBlitType!T)typeid(Unqual!T).xpostblit;
}
else if ((&typeid(T).postblit).funcptr !is &TypeInfo.postblit)
{
// assume that ref T and void* are equivalent in abi level.
alias PostBlitT = typeof(delegate (ref T t){ T a = t; });

return cast(PostBlitT)&typeid(T).postblit;
return cast(_PostBlitType!T)&typeid(T).postblit;
}
else
return null;
Expand Down
20 changes: 11 additions & 9 deletions src/object_.d
Original file line number Diff line number Diff line change
Expand Up @@ -2964,26 +2964,28 @@ private inout(T)[] _rawDup(T)(inout(T)[] a)
return *cast(inout(T)[]*)&arr;
}

template _PostBlitType(T)
{
// assume that ref T and void* are equivalent in abi level.
static if (is(T == struct))
alias _PostBlitType = typeof(function (ref T t){ T a = t; });
else
alias _PostBlitType = typeof(delegate (ref T t){ T a = t; });
}

// Returns null, or a delegate to call postblit of T
private auto _getPostblit(T)() @trusted pure nothrow @nogc
{
// infer static postblit type, run postblit if any
static if (is(T == struct))
{
import core.internal.traits : Unqual;

// assume that ref T and void* are equivalent in abi level.
alias PostBlitT = typeof(function (ref T t){ T a = t; });

// use typeid(Unqual!T) here to skip TypeInfo_Const/Shared/...
return cast(PostBlitT)typeid(Unqual!T).xpostblit;
return cast(_PostBlitType!T)typeid(Unqual!T).xpostblit;
}
else if ((&typeid(T).postblit).funcptr !is &TypeInfo.postblit)
{
// assume that ref T and void* are equivalent in abi level.
alias PostBlitT = typeof(delegate (ref T t){ T a = t; });

return cast(PostBlitT)&typeid(T).postblit;
return cast(_PostBlitType!T)&typeid(T).postblit;
}
else
return null;
Expand Down

0 comments on commit b66f2db

Please sign in to comment.