www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - inline trusted code

reply ikod <geller.garry gmail.com> writes:
Hello,

Several times I faced with next problem: I have " safe" routine 
with few calls to  system functions inside: OS calls (recv, send, 
kqueue) os some phobos unsafe functions like assumeUnique. I'd 
like not to wrap these  system functions in  trusted wrappers, 
but somehow mark these calls  trusted inline.

In ideal case this should look like

import std.exception;

void main()  safe
{
     ubyte[] a;
      trusted {
     	auto b = assumeUnique(a);
     };
}

But the closest variant is

import std.exception;

void main()  safe
{
     ubyte[] a;
     delegate void()  trusted {
     	auto b = assumeUnique(a);
     }();
}

Which looks a bit verbose.

How do you solve this problem?

Thanks!
Jan 30
parent kinke <kinke libero.it> writes:
On Tuesday, 30 January 2018 at 15:05:38 UTC, ikod wrote:
 Hello,

 Several times I faced with next problem: I have " safe" routine 
 with few calls to  system functions inside: OS calls (recv, 
 send, kqueue) os some phobos unsafe functions like 
 assumeUnique. I'd like not to wrap these  system functions in 
  trusted wrappers, but somehow mark these calls  trusted inline.

 In ideal case this should look like

 import std.exception;

 void main()  safe
 {
     ubyte[] a;
      trusted {
     	auto b = assumeUnique(a);
     };
 }

 But the closest variant is

 import std.exception;

 void main()  safe
 {
     ubyte[] a;
     delegate void()  trusted {
     	auto b = assumeUnique(a);
     }();
 }

 Which looks a bit verbose.

 How do you solve this problem?

 Thanks!
ubyte[] a; auto b = (() trusted => assumeUnique(a))();
Jan 30