www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15341] New: segfault with std.signals slots

https://issues.dlang.org/show_bug.cgi?id=15341

          Issue ID: 15341
           Summary: segfault with std.signals slots
           Product: D
           Version: D2
          Hardware: x86
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: lt.infiltrator gmail.com

Modifying the example code from http://dlang.org/phobos/std_signals.html to add
a second slot causes a segfault.

Tested in 2.066 and 2.068 on X86 Linux, but I doubt that it's
platform-dependent.

==============
import std.signals;
import std.stdio;

class Observer {
   void watch(string, int) { }
   void watch2(string, int) { }
}

class Foo {
   int value(int v) {
      emit("setting new value", v);
      return v;
   }
   mixin Signal!(string, int);
}

void main() {
   auto a = new Foo;
   auto o = new Observer;

   a.connect(&o.watch);
   a.connect(&o.watch2); // not connecting watch2() or disconnecting it
manually fixes the issue
   a.disconnect(&o.watch); // NOT disconnecting watch() fixes the issue
   destroy(o); // destroying o should automatically disconnect it
   a.value = 7;   // should not call o.watch() or o.watch2()
}
==============

--
Nov 15 2015