Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/thread.d
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,7 @@ private:
return cast(Mutex)_locks[1].ptr;
}

__gshared byte[__traits(classInstanceSize, Mutex)][2] _locks;
__gshared void[__traits(classInstanceSize, Mutex)][2] _locks;

static void initLocks()
{
Expand Down
2 changes: 1 addition & 1 deletion src/gc/gc.d
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ struct GC
// We can't allocate a Mutex on the GC heap because we are the GC.
// Store it in the static data segment instead.
__gshared GCMutex gcLock; // global lock
__gshared byte[__traits(classInstanceSize, GCMutex)] mutexStorage;
__gshared void[__traits(classInstanceSize, GCMutex)] mutexStorage;

__gshared Config config;

Expand Down
2 changes: 1 addition & 1 deletion src/object.di
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class TypeInfo_Class : TypeInfo
@property auto info() @safe nothrow pure const { return this; }
@property auto typeinfo() @safe nothrow pure const { return this; }

byte[] init; // class static initializer
byte[] m_init; // class static initializer
Copy link
Member

Choose a reason for hiding this comment

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

urgh... we really should have a compiler error for this stuff

string name; // class name
void*[] vtbl; // virtual function pointer table
Interface[] interfaces;
Expand Down
18 changes: 17 additions & 1 deletion src/object_.d
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,8 @@ class TypeInfo_Class : TypeInfo
return Object.sizeof;
}

override const(void)[] init() nothrow pure const @safe { return m_init; }

override @property uint flags() nothrow pure const { return 1; }

override @property const(OffsetTypeInfo)[] offTi() nothrow pure const
Expand All @@ -834,7 +836,7 @@ class TypeInfo_Class : TypeInfo
@property auto info() @safe nothrow pure const { return this; }
@property auto typeinfo() @safe nothrow pure const { return this; }

byte[] init; /** class static initializer
byte[] m_init; /** class static initializer
* (init.length gives size in bytes of class)
*/
string name; /// class name
Expand Down Expand Up @@ -903,6 +905,20 @@ class TypeInfo_Class : TypeInfo

alias TypeInfo_Class ClassInfo;

unittest
{
// Bugzilla 14401
static class X
{
int a;
}

assert(typeid(X).init is typeid(X).m_init);
assert(typeid(X).init.length == typeid(const(X)).init.length);
assert(typeid(X).init.length == typeid(shared(X)).init.length);
assert(typeid(X).init.length == typeid(immutable(X)).init.length);
}

class TypeInfo_Interface : TypeInfo
{
override string toString() const { return info.name; }
Expand Down
8 changes: 4 additions & 4 deletions src/rt/lifetime.d
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ extern (C) Object _d_newclass(const ClassInfo ci)
}

// initialize it
(cast(byte*) p)[0 .. ci.init.length] = ci.init[];
p[0 .. ci.init.length] = ci.init[];

debug(PRINTF) printf("initialization done\n");
return cast(Object) p;
Expand Down Expand Up @@ -1412,10 +1412,10 @@ extern (C) void rt_finalize2(void* p, bool det = true, bool resetMemory = true)
if (ppv[1]) // if monitor is not null
_d_monitordelete(cast(Object) p, det);

if(resetMemory)
if (resetMemory)
{
byte[] w = (*pc).init;
(cast(byte*) p)[0 .. w.length] = w[];
auto w = (*pc).init;
p[0 .. w.length] = w[];
}
}
catch (Exception e)
Expand Down