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

Commit

Permalink
Merge branch 'master' of https://github.com/schveiguy/druntime into s…
Browse files Browse the repository at this point in the history
…chveiguy-master
  • Loading branch information
andralex committed Feb 27, 2011
2 parents b403c3e + cae60ab commit ce6aab5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 42 deletions.
27 changes: 6 additions & 21 deletions import/object.di
Expand Up @@ -12,6 +12,11 @@
*/
module object;

private
{
extern(C) void rt_finalize(void *ptr, bool det=true);
}

alias typeof(int.sizeof) size_t;
alias typeof(cast(void*)0 - cast(void*)0) ptrdiff_t;
alias ptrdiff_t sizediff_t;
Expand Down Expand Up @@ -431,27 +436,7 @@ unittest

void clear(T)(T obj) if (is(T == class))
{
if (!obj) return;
auto ci = obj.classinfo;
auto defaultCtor =
cast(void function(Object)) ci.defaultConstructor;
version(none) // enforce isn't available in druntime
_enforce(defaultCtor || (ci.flags & 8) == 0);
immutable size = ci.init.length;

auto ci2 = ci;
do
{
auto dtor = cast(void function(Object))ci2.destructor;
if (dtor)
dtor(obj);
ci2 = ci2.base;
} while (ci2)

auto buf = (cast(void*) obj)[0 .. size];
buf[] = ci.init;
if (defaultCtor)
defaultCtor(obj);
rt_finalize(cast(void*)obj);
}

void clear(T)(ref T obj) if (is(T == struct))
Expand Down
25 changes: 4 additions & 21 deletions src/object_.d
Expand Up @@ -33,6 +33,7 @@ private
extern (C) Object _d_newclass(TypeInfo_Class ci);
extern (C) void _d_arrayshrinkfit(TypeInfo ti, void[] arr);
extern (C) size_t _d_arraysetcapacity(TypeInfo ti, size_t newcapacity, void *arrptr);
extern (C) void rt_finalize(void *data, bool det=true);
}

// NOTE: For some reason, this declaration method doesn't work
Expand Down Expand Up @@ -2540,27 +2541,7 @@ unittest

void clear(T)(T obj) if (is(T == class))
{
if (!obj) return;
auto ci = obj.classinfo;
auto defaultCtor =
cast(void function(Object)) ci.defaultConstructor;
version(none) // enforce isn't available in druntime
_enforce(defaultCtor || (ci.flags & 8) == 0);
immutable size = ci.init.length;

auto ci2 = ci;
do
{
auto dtor = cast(void function(Object))ci2.destructor;
if (dtor)
dtor(obj);
ci2 = ci2.base;
} while (ci2)

auto buf = (cast(void*) obj)[0 .. size];
buf[] = ci.init;
if (defaultCtor)
defaultCtor(obj);
rt_finalize(cast(void*)obj);
}

version(unittest) unittest
Expand Down Expand Up @@ -2589,6 +2570,8 @@ version(unittest) unittest
assert(destroyed);
assert(a.s == "B");
}
// this test is invalid now that the default ctor is not run after clearing
version(none)
{
class C
{
Expand Down

0 comments on commit ce6aab5

Please sign in to comment.