Issue 19842 - std.signals Segfault could take other delegates than member function pointers
Summary: std.signals Segfault could take other delegates than member function pointers
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 Linux
: P2 major
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-05-02 17:23 UTC by codemyst
Modified: 2024-12-01 16:34 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description codemyst 2019-05-02 17:23:17 UTC
When passing a lambda instead of a delegate to connect, it causes the app to segfault.

Tested with DMD 2.085.1.

Here's the most basic sample app that will reproduce the issue:

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

class Test
{
    mixin Signal!(int);

    void run ()
    {
        emit (1);
    }
}

class Tester
{
    void initialize ()
    {
        Test test = new Test ();
        test.connect ((int a) => trigger (a));
    }

    void trigger (int a)
    {
        writeln (a);
    }
}

void main ()
{
    Tester t = new Tester ();
    t.initialize ();
}
==========
Comment 1 Ate Eskola 2021-06-07 13:22:26 UTC
Lambda is a delegate in this context. I'm testing with v2.096.0 release canditate and latest Phobos.

This bug does not trigger only with lambda, it triggers with any delegate that is not a class member function.

The documentation does warn that the delegates must be class delegates, but it does not say that that they must be member function pointers. This needs to be clarified, or preferably it should be made to work with non-member-function delegates too.
Comment 2 Dlang Bot 2021-06-07 13:59:02 UTC
@dukc created dlang/phobos pull request #8137 "Issue 19842 - only class member functions must be used be used as slots" mentioning this issue:

- Issue 19842 - only class member functions must be used be used as slots

https://github.com/dlang/phobos/pull/8137
Comment 3 Dlang Bot 2021-06-08 12:32:38 UTC
@dukc created dlang/phobos pull request #8139 "Issue 19842 - only class member functions must be used be used as slots" mentioning this issue:

- Issue 19842 - only class member functions must be used be used as slots

https://github.com/dlang/phobos/pull/8139
Comment 4 Dlang Bot 2021-06-08 12:34:02 UTC
@dukc created dlang/phobos pull request #8140 "Issue 19842 - only class member functions must be used be used as slots" mentioning this issue:

- Issue 19842 - only class member functions must be used be used as slots

https://github.com/dlang/phobos/pull/8140
Comment 5 Dlang Bot 2021-07-13 10:33:44 UTC
dlang/phobos pull request #8140 "Issue 19842 - only class member functions must be used be used as slots" was merged into stable:

- 235d3ba9bedf8cd7a9f697231b03f37bac9fd7d3 by Ate Eskola:
  Issue 19842 - only class member functions must be used be used as slots

https://github.com/dlang/phobos/pull/8140
Comment 6 Dlang Bot 2021-07-20 08:54:53 UTC
@MartinNowak created dlang/phobos pull request #8172 "merge stable" mentioning this issue:

- Issue 19842 - only class member functions must be used be used as slots

https://github.com/dlang/phobos/pull/8172
Comment 7 Dlang Bot 2021-07-23 06:23:41 UTC
dlang/phobos pull request #8172 "merge stable" was merged into master:

- 06983381cf824cfae7b8a77d29b0b2fa8fe13c6f by Ate Eskola:
  Issue 19842 - only class member functions must be used be used as slots

https://github.com/dlang/phobos/pull/8172
Comment 8 Ate Eskola 2021-08-25 13:41:01 UTC
The documetation is now clarified, but it still would be a nice plus for the slot to accept any delegate of the correct type. I changed the severity to enhancement.
Comment 9 dlangBugzillaToGithub 2024-12-01 16:34:58 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/9772

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB