www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6436] New: Refcounted initialization bug

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6436

           Summary: Refcounted initialization bug
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com



13:35:13 PDT ---
import std.typecons;

struct Foo
{
    struct Payload
    {
        this(ref int bar, int value)
        { 
            bar = value;
            assert(bar == 5);   // ok
        }
    }

    alias RefCounted!(Payload, RefCountedAutoInitialize.yes) Data;
    Data data;

    int bar;

    this(int value) 
    {
        data = Data(bar, value);
        assert(bar == 5);  // throws, it's still 0
    }    
}

void main()
{
    auto foo = Foo(5);
}

import std.typecons;

struct Foo
{
    struct Payload
    {
        this(ref int bar, int value)
        { 
            bar = value;
            assert(bar == 5);   // ok..
        }
    }

    alias RefCounted!(Payload, RefCountedAutoInitialize.yes) Data;
    Data data;

    int bar;

    this(int value) 
    {
        data = Data(bar, value);  // initializes bar to 5
        assert(bar == 5);  // throws, it's still 0
    }    
}

void main()
{
    auto foo = Foo(5);
}

Foo's ctor is called, then Refcounted Payload's ctor is called which
initializes Foo's integer field, but upon return to the Foo ctor the integer
field seems to be reinitialized to 0.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 04 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6436




13:36:01 PDT ---
Oh damnit duplicated code sorry:

import std.typecons;

struct Foo
{
    struct Payload
    {
        this(ref int bar, int value)
        { 
            bar = value;
            assert(bar == 5);   // ok
        }
    }

    alias RefCounted!(Payload, RefCountedAutoInitialize.yes) Data;
    Data data;

    int bar;

    this(int value) 
    {
        data = Data(bar, value);
        assert(bar == 5);  // throws, it's still 0
    }    
}

void main()
{
    auto foo = Foo(5);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 04 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6436




18:45:56 PDT ---
Interestingly if you pass by pointer instead of by ref it works fine. Here's a
much more simplified example:

import std.typecons;
import std.stdio;

struct Struct1 {
    this(ref int val) { val = 5; }
}

struct Struct2 {
    this(int* val) { *val = 5; }
}

alias RefCounted!(Struct1) Str1;
alias RefCounted!(Struct2) Str2;

void main()
{
    Str1 str1;
    Str2 str2;
    int val;

    str1 = Str1(val);
    writeln(val);  // writes 0

    str2 = Str2(&val);
    writeln(val);  // writes 5    
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 19 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6436


Denis Shelomovskij <verylonglogin.reg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |verylonglogin.reg gmail.com



20:21:00 MSD ---
This issue is blocked by `emplace` issue which is fixed in pull 896:
https://github.com/D-Programming-Language/phobos/pull/896

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 26 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6436




20:47:37 MSD ---
OK. Full fix added to the pull:
https://github.com/D-Programming-Language/phobos/pull/896

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 26 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6436




Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/63503202b74a5e97e7755847feac886db0bbe64f
Fix `emplace` part of issue 6436

* Issue URL: http://d.puremagic.com/issues/show_bug.cgi?id=6436

https://github.com/D-Programming-Language/phobos/commit/dab3b2a7dda8459b5f609761a984811d3e7aec5d
Fix Issue 6436 - Refcounted initialization bug

* Issue URL: http://d.puremagic.com/issues/show_bug.cgi?id=6436

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 12 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6436


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED



13:19:58 PST ---
Thanks, fixed.

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