www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11494] New: std.array.appender is not nothrow

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

           Summary: std.array.appender is not nothrow
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: minor
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: destructionator gmail.com



15:45:58 PST ---
This propagates up to to!(array)(other_array) making it not work in nothrow
too, despite the fact they otherwise don't throw anything except out of memory
errors.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 10 2013
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11494


Adam D. Ruppe <destructionator gmail.com> changed:

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



08:20:50 PST ---
https://github.com/D-Programming-Language/phobos/pull/1690

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 13 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11494


monarchdodra gmail.com changed:

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




 This propagates up to to!(array)(other_array) making it not work in nothrow
 too, despite the fact they otherwise don't throw anything except out of memory
 errors.
What do you mean? This works fine on my HEAD. It's even safe and pure: //---- import std.conv, std.array; void main() nothrow safe pure { int[] arr; to!(int[])(arr); appender(arr); } //---- This is with 2.064.2. In 2.063.2 it's not safe. Are you sure the problem in "to" isn't that the duplicated array contains objects with throwing postblits by any chance? -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 13 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11494




09:22:14 PST ---
The specific thing that got this was here:

import std.conv;
import std.array;

void main() nothrow  safe {
    string s = "foo";
    auto b = to!(ubyte[])(s);
}

testarray.d(6): Error: 'std.conv.to!(ubyte[]).to!(string).to' is not nothrow


Though, now the change I did in the pull isn't fixing it. When I first played
with this, it was on my other computer which has an older dmd, so maybe
something else has changed since then, but this test here still fails to
compile on my desktop.

I'm not sure what's going on here, maybe it is trying to parse the string. But
the appender issue itself might be invalid and/or already fixed in the newest
dmd though.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 13 2013
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11494





 I'm not sure what's going on here, maybe it is trying to parse the string. But
 the appender issue itself might be invalid and/or already fixed in the newest
 dmd though.
It's trying to parse the string. If you want to "interpret" the string as ubytes, you can use "std.string.representation". This will "reinterpret" your string according to its type: string => immutable(ubyte)[] wchar[] => ushort[] dchar[] => uint[] However, this will not *allocate* a new array, and it is not safe either. It *is* nothrow though. If you want a new array, I'd recommend adding a ".dup", but that's not nothrow. I don't know any 1 liners that are safe, pure and nothrow. My recommendation would be to make an explicit trusted helper that will do it for you. Eg: ubyte[] str2ubyte(in char[] str) pure nothrow { auto arr = uninitializedArray!(ubyte[])(str.length); arr[]=str.representation()[]; return arr; } You could templatize too, just like representation, so as to work on any width. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 13 2013