www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6646] New: [SafeD] array.reserve is not safe/trusted

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

           Summary: [SafeD] array.reserve is not  safe/trusted
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: druntime
        AssignedTo: nobody puremagic.com
        ReportedBy: dmitry.olsh gmail.com



10:13:37 PDT ---
I'm not sure if it's druntime or DMD problem.

Testcase:

 safe void bug()
{
    int[] a;
    a.reserve(10);
}

Fails to compile with:
Error: safe function 'bug' cannot call system function 'reserve'

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




IMO, reserve() should be at least  trusted. What's the use of safeD if even
language constructs like array.reserve can't be used?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 01 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6646


Steven Schveighoffer <schveiguy yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy yahoo.com



13:27:43 PDT ---
It should be  trusted.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 01 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6646




https://github.com/D-Programming-Language/druntime/pull/536

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 02 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6646




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

https://github.com/D-Programming-Language/druntime/commit/032bac64ef3e354da65da38314c51af09eebcf05
Fix issue 6646: array.reserve should be callable from SafeD.

https://github.com/D-Programming-Language/druntime/commit/fa85c1b413cbe81416f02995cfefe6107a4cbb4e


Fix issue 6646: array.reserve should be callable from SafeD.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 02 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6646


Alex Rønne Petersen <alex lycus.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |alex lycus.org
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 02 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6646


monarchdodra gmail.com changed:

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



I think this change is wrong. reserve can call postblit, wich may end up being
unsafe (or throwing).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 29 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6646




Hmph. I wish there was a consistent way of propagating attributes, or saying
"function X's purity depends on argument Y" or something along those lines.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 29 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6646




13:38:51 PDT ---
This can be fixed, since reserve is a template and not a compiler-builtin.

Unfortunately, we need to manually propagate the  safe/ nothrow to the high
level reserve call. something like:

 safe  nothrow reserve(T)(T[] t) if(isPostblitSafe!T && isPostblitNothrow!T)

etc.

Ugly...

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




14:13:05 PDT ---

 This can be fixed, since reserve is a template and not a compiler-builtin.
 
 Unfortunately, we need to manually propagate the  safe/ nothrow to the high
 level reserve call. something like:
 
  safe  nothrow reserve(T)(T[] t) if(isPostblitSafe!T && isPostblitNothrow!T)
 
 etc.
 
 Ugly...
Shouldn't auto-inference help + local trusted/nothrow lambdas to encapsulate dangerous code? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 05 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6646






 This can be fixed, since reserve is a template and not a compiler-builtin.
 
 Unfortunately, we need to manually propagate the  safe/ nothrow to the high
 level reserve call. something like:
 
  safe  nothrow reserve(T)(T[] t) if(isPostblitSafe!T && isPostblitNothrow!T)
 
 etc.
 
 Ugly...
Shouldn't auto-inference help + local trusted/nothrow lambdas to encapsulate dangerous code?
I was able to make it work simply by calling a dummy postblit: reserve(T)(T[] t) { if (is(typeof({T t2 = t;}))) if (0) T t2 = t; //Call C-reserve function here. } The forced postblit call makes sure the inference is ocrrectly computed. Unfortunately: 1) The C function is still marked nothrow, so all hell probably breaks loose *should* an exception be thrown 2) Hackish as hell. Might be worth it to find a better workaround. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 06 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6646


Dmitry Olshansky <dmitry.olsh gmail.com> changed:

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


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 09 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6646


monarchdodra gmail.com changed:

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



It's not fixed, because reserve is not  safe 100% of the time either.

 Shouldn't auto-inference help + local  trusted/nothrow lambdas to encapsulate
dangerous code? The problem is that everything is run in druntime, as an non-template extern(C) call to a function that takes a TypeInfo. So no inference here. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 09 2013