Jump to page: 1 2
Thread overview
[Issue 10970] New: Segfault in a simple test compiled without -g.
Sep 05, 2013
Zhouxuan
Sep 05, 2013
Zhouxuan
Sep 05, 2013
Zhouxuan
Sep 06, 2013
Andrej Mitrovic
Sep 06, 2013
Andrej Mitrovic
Sep 06, 2013
Zhouxuan
Sep 06, 2013
Andrej Mitrovic
Sep 06, 2013
Zhouxuan
Sep 06, 2013
Zhouxuan
Sep 07, 2013
Andrej Mitrovic
Sep 07, 2013
Andrej Mitrovic
Sep 07, 2013
Andrej Mitrovic
Sep 22, 2013
Kenji Hara
Sep 23, 2013
Kenji Hara
September 05, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10970

           Summary: Segfault in a simple test compiled without -g.
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Windows
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: pycerl@qq.com


--- Comment #0 from Zhouxuan <pycerl@qq.com> 2013-09-05 04:34:18 PDT ---
http://dpaste.dzfl.pl/8cc57a33

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 05, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10970



--- Comment #1 from Zhouxuan <pycerl@qq.com> 2013-09-05 05:29:12 PDT ---
After some test, the bug is likely to be that, an Array instantiated by make!(Array!T) WITHOUT ANY ARGUMENT, cannot be used as a value of AA.

following code fail to run:

alias Array!int A;
A[int] m;
m[0] = make!A;

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 05, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10970



--- Comment #2 from Zhouxuan <pycerl@qq.com> 2013-09-05 05:48:14 PDT ---
Further test shows that, Array just cann't be used as an value of AA in dmd2.063(on dpaste), while under git-head version of dmd, segfault only occured when an array is created by make!Array without any argument.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 06, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10970


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich@gmail.com


--- Comment #3 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-09-05 19:34:24 PDT ---
I think this is a 64-bit only bug. Could you try compiling with -m32 to confirm?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 06, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10970



--- Comment #4 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-09-05 19:35:48 PDT ---
(In reply to comment #3)
> I think this is a 64-bit only bug. Could you try compiling with -m32 to confirm?

Ok nevermind, I was testing your http://d.puremagic.com/issues/show_bug.cgi?id=10970#c1 instead of the dpaste one (try not to use dpaste for short examples).

Your test-case:

-----
import std.stdio;
import std.container;
import std.process;

class A
{
    this(string name)
    {
        m[name] = make!Arr;
    }

    alias Array!A Arr;
    Arr[string] m;
}

int main()
{
    A a = new A("test");
    return 0;
}
-----

Crashes on win32 as well.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 06, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10970



--- Comment #5 from Zhouxuan <pycerl@qq.com> 2013-09-05 20:14:47 PDT ---
(In reply to comment #4)
> (In reply to comment #3)
> > I think this is a 64-bit only bug. Could you try compiling with -m32 to confirm?
> 
> Ok nevermind, I was testing your http://d.puremagic.com/issues/show_bug.cgi?id=10970#c1 instead of the dpaste one (try not to use dpaste for short examples).
> 
> Your test-case:
> 
> -----
> import std.stdio;
> import std.container;
> import std.process;
> 
> class A
> {
>     this(string name)
>     {
>         m[name] = make!Arr;
>     }
> 
>     alias Array!A Arr;
>     Arr[string] m;
> }
> 
> int main()
> {
>     A a = new A("test");
>     return 0;
> }
> -----
> 
> Crashes on win32 as well.

Hope it helps and the issue be fixed asap, thank you!

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 06, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10970


monarchdodra@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra@gmail.com


--- Comment #6 from monarchdodra@gmail.com 2013-09-06 02:10:45 PDT ---
(In reply to comment #5)
> Crashes on win32 as well.

If I recall correctly, I think the problem is "simply" that AA has *very* bad support for types with elaborate CC, and destruction. Take this "simple" use case:

//####
import std.stdio;

int count;

struct S
{
    this(int){++count; writeln("construction");}
    this(this){assert(0);} //never called
    ~this(){--count; writeln("destruction");}
}

void main()
{
    S[int] aa;
    writeln("----");
    aa[5] = S(3);
    writeln("----");
    aa.remove(5);
    writeln("----");
    assert(aa.length == 0);
    assert(count >= 0); //Fails here
}
//####
----
construction
destruction
destruction
----
----
//####

In just this little snippet, there are *all* kinds of wrong:
1. insertion: when inserting a new item, CC ("this(this)") is never called for
some strange reason. Furthermore, destruction happens *twice* (again, for some
strange reason).
2. removal: Where's the destructor?

These use cases are probably reported already, you are experiencing the results of these defects.

Long story short, at the end of the day, your array is "over-destroyed". Given that AA is a *strongly* relies on reference counting to provide deterministic behavior, things simply don't go well.

A lot of work is being done on fixing AAs (AFAIK), but don't expect it to be
fixed any time soon.

As a workaround, you could try using slices instead of AA's?

//----
import std.stdio;

class A
{
    this(string name)
    {
        m[name] = Arr.init;
    }

    alias A[] Arr;
    Arr[string] m;
}

int main()
{
    A a = new A("test");
    return 0;
}
//----

In particular, "A" is a class, so it can't have a destructor (in the sense that a *reference* doesn't get destroyed). As such, there is minimal use to keeping an Array over a slice.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 06, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10970



--- Comment #7 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-09-06 07:18:43 PDT ---
Yeah it's very unfortunate the AA situation we have in D today, it's really giving D a bad rep.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 06, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10970



--- Comment #8 from Zhouxuan <pycerl@qq.com> 2013-09-06 07:22:25 PDT ---
(In reply to comment #6)
> (In reply to comment #5)
> > Crashes on win32 as well.
> 
> If I recall correctly, I think the problem is "simply" that AA has *very* bad support for types with elaborate CC, and destruction. Take this "simple" use case:
> 
> //####
> import std.stdio;
> 
> int count;
> 
> struct S
> {
>     this(int){++count; writeln("construction");}
>     this(this){assert(0);} //never called
>     ~this(){--count; writeln("destruction");}
> }
> 
> void main()
> {
>     S[int] aa;
>     writeln("----");
>     aa[5] = S(3);
>     writeln("----");
>     aa.remove(5);
>     writeln("----");
>     assert(aa.length == 0);
>     assert(count >= 0); //Fails here
> }
> //####
> ----
> construction
> destruction
> destruction
> ----
> ----
> //####
> 
> In just this little snippet, there are *all* kinds of wrong:
> 1. insertion: when inserting a new item, CC ("this(this)") is never called for
> some strange reason. Furthermore, destruction happens *twice* (again, for some
> strange reason).
> 2. removal: Where's the destructor?
> 
> These use cases are probably reported already, you are experiencing the results of these defects.
> 
> Long story short, at the end of the day, your array is "over-destroyed". Given that AA is a *strongly* relies on reference counting to provide deterministic behavior, things simply don't go well.
> 
> A lot of work is being done on fixing AAs (AFAIK), but don't expect it to be
> fixed any time soon.
> 
> As a workaround, you could try using slices instead of AA's?
> 
> //----
> import std.stdio;
> 
> class A
> {
>     this(string name)
>     {
>         m[name] = Arr.init;
>     }
> 
>     alias A[] Arr;
>     Arr[string] m;
> }
> 
> int main()
> {
>     A a = new A("test");
>     return 0;
> }
> //----
> 
> In particular, "A" is a class, so it can't have a destructor (in the sense that a *reference* doesn't get destroyed). As such, there is minimal use to keeping an Array over a slice.

Thank you, I can work around it by changing the design, however, this really need to be fixed in the near future!

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 06, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10970



--- Comment #9 from Zhouxuan <pycerl@qq.com> 2013-09-06 07:29:53 PDT ---
(In reply to comment #7)
> Yeah it's very unfortunate the AA situation we have in D today, it's really giving D a bad rep.

Absolutely, after hanging around D community for days, I decide to start a private project in D, however, the first class I implemented broke by this issue!

FYI, I'm a game programmer and GC is an another trouble-maker for me, hope it can be improved in the near futher too.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2