[Issue 10821] New: .byKey erroneously returns a null key
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Aug 14 15:14:28 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10821
Summary: .byKey erroneously returns a null key
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: critical
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: andrej.mitrovich at gmail.com
--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-08-14 15:14:26 PDT ---
-----
import std.stdio;
struct Signal
{
void connect(void delegate(int) func)
{
stderr.writefln("Func connect: %s", *cast(void**)&func);
funcs[func] = 1;
}
void disconnect(void delegate(int) target)
{
stderr.writefln("Func disconnect: %s", *cast(void**)&target);
funcs.remove(target);
}
void emit(int i)
{
version(VERSION_OK)
{
foreach (func; funcs.keys)
{
stderr.writefln("Calling: %s", *cast(void**)&func);
func(i);
}
}
else
version(VERSION_CRASH)
{
foreach (func; funcs.byKey)
{
stderr.writefln("Calling: %s", *cast(void**)&func);
func(i);
}
}
}
int[void delegate(int)] funcs;
}
void main()
{
Signal signal;
void delegate(int) handler;
handler =
(int i)
{
signal.disconnect(handler);
};
signal.connect(handler);
signal.emit(1);
signal.emit(2);
}
-----
Ok version:
$ dmd -version=VERSION_OK -run test.d
> Func connect: 1BF2FF0
> Calling: 1BF2FF0
> Func disconnect: 1BF2FF0
Buggy version:
$ dmd -version=VERSION_CRASH -run test.d
> Func connect: 482FF0
> Calling: 482FF0
> Func disconnect: 482FF0
> Calling: null
> object.Error: Access Violation
It should have never called 'null', I don't know why byKey seems to return it
after the delegate was removed from the associative array.
This does not seem to be a regression (tested up to 2.050).
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list