www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12444] New: std.array uninitializedArray & minimallyInitializedArray missing APPENDABLE attribute / capacity info

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

           Summary: std.array uninitializedArray &
                    minimallyInitializedArray missing APPENDABLE attribute
                    / capacity info
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: safety0ff.bugz gmail.com


--- Comment #0 from safety0ff.bugz <safety0ff.bugz gmail.com> 2014-03-23
03:48:59 PDT ---
import std.array;
import std.stdio;
import core.memory;

void main()
{
    double[] a = uninitializedArray!(double[])(100);
    a = a[0 .. 1];
    assert(a.capacity == 0);
    a.assumeSafeAppend();
    assert(a.capacity != 0); // Error

    double[] b = minimallyInitializedArray!(double[])(100);
    b = b[0 .. 1];
    assert(b.capacity == 0);
    b.assumeSafeAppend();
    assert(b.capacity != 0); // Error

    double[] c = new double[100];
    c = c[0 .. 1];
    assert(c.capacity == 0);
    c.assumeSafeAppend();
    assert(c.capacity != 0); // OK!

    auto dptr = cast(double*)GC.malloc(100 * double.sizeof, GC.BlkAttr.NO_SCAN
| GC.BlkAttr.APPENDABLE);
    double[] d = dptr[0 .. 100];
    d = d[0 .. 1];
    assert(d.capacity == 0);
    d.assumeSafeAppend();
    assert(d.capacity != 0); // OK!
}

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 23 2014
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12444


safety0ff.bugz <safety0ff.bugz gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #1 from safety0ff.bugz <safety0ff.bugz gmail.com> 2014-03-23
21:30:08 PDT ---
https://github.com/D-Programming-Language/phobos/pull/2044

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 23 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12444


safety0ff.bugz <safety0ff.bugz gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 24 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12444


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |monarchdodra gmail.com
         Resolution|INVALID                     |


--- Comment #2 from monarchdodra gmail.com 2014-03-24 01:58:57 PDT ---
Just to be clear, this issue is NOT invalid. It's just that your proposed
solution doesn't work.

An implementation that could work is:

T[] uninitializedArray(T)(size_t n)
{
    T[] buff; //Declare buff.

    //Use the GC to do an Appendable allocation
    buff.reserve(n);

    //Slice out of bounds....
    buff = buff.ptr[0 .. n];

    //And tell the GC what the actual new bounds are.
    buff = assumeSafeAppend(buff);

    return buff;
}

This could not work up until now, because `assumeSafeAppend` was not nothrow.
It's not nothrow anymore, but it's not yet pure either, so it still isn't
useable.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 24 2014