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 #909 from MartinNowak/fix13084
Browse files Browse the repository at this point in the history
fix Issue 13084 - ModuleInfo.opApply delegate expects immutable parameter
  • Loading branch information
WalterBright authored and MartinNowak committed Jul 25, 2014
1 parent 5dbccd4 commit 1aabbb2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
13 changes: 12 additions & 1 deletion src/object.di
Expand Up @@ -279,6 +279,17 @@ struct ModuleInfo
uint _flags;
uint _index;

version (all)
{
deprecated("ModuleInfo cannot be copy-assigned because it is a variable-sized struct.")
void opAssign(in ModuleInfo m) { _flags = m._flags; _index = m._index; }
}
else
{
@disable this();
@disable this(this) const;
}

const:
@property uint index() nothrow pure;
@property uint flags() nothrow pure;
Expand All @@ -293,7 +304,7 @@ const:
@property TypeInfo_Class[] localClasses() nothrow pure;
@property string name() nothrow pure;

static int opApply(scope int delegate(immutable(ModuleInfo*)) dg);
static int opApply(scope int delegate(ModuleInfo*) dg);
}

class Throwable : Object
Expand Down
22 changes: 17 additions & 5 deletions src/object_.d
Expand Up @@ -1591,6 +1591,17 @@ struct ModuleInfo
uint _flags;
uint _index; // index into _moduleinfo_array[]

version (all)
{
deprecated("ModuleInfo cannot be copy-assigned because it is a variable-sized struct.")
void opAssign(in ModuleInfo m) { _flags = m._flags; _index = m._index; }
}
else
{
@disable this();
@disable this(this) const;
}

const:
private void* addrOf(int flag) nothrow pure
in
Expand Down Expand Up @@ -1724,20 +1735,21 @@ const:
// return null;
}

static int opApply(scope int delegate(immutable(ModuleInfo*)) dg)
static int opApply(scope int delegate(ModuleInfo*) dg)
{
import rt.minfo;
return rt.minfo.moduleinfos_apply(dg);
// Bugzilla 13084 - enforcing immutable ModuleInfo would break client code
return rt.minfo.moduleinfos_apply(
(immutable(ModuleInfo*)m) => dg(cast(ModuleInfo*)m));
}
}

unittest
{
ModuleInfo mi;
ModuleInfo* m1;
foreach (m; ModuleInfo)
{
mi = *m;
break;
m1 = m;
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/rt/minfo.d
Expand Up @@ -392,6 +392,11 @@ unittest

static struct UTModuleInfo
{
this(uint flags)
{
mi._flags = flags;
}

void setImports(immutable(ModuleInfo)*[] imports...)
{
import core.bitop;
Expand All @@ -413,7 +418,7 @@ unittest

static UTModuleInfo mockMI(uint flags)
{
auto mi = UTModuleInfo(ModuleInfo(flags | MIimportedModules));
auto mi = UTModuleInfo(flags | MIimportedModules);
auto p = cast(void function()*)&mi.pad;
if (flags & MItlsctor) *p++ = &stub;
if (flags & MItlsdtor) *p++ = &stub;
Expand Down
2 changes: 1 addition & 1 deletion src/test_runner.d
@@ -1,7 +1,7 @@
import core.runtime, core.time : TickDuration;
import core.stdc.stdio;

immutable(ModuleInfo*) getModuleInfo(string name)
ModuleInfo* getModuleInfo(string name)
{
foreach (m; ModuleInfo)
if (m.name == name) return m;
Expand Down

0 comments on commit 1aabbb2

Please sign in to comment.