Sign up

Making gir-to-d generate @safe code

Hello,

DIP1028 (@safe by default) got accepted yesterday, so I think it'd be nice if gir-to-d generated @safe code so users can use glibd>kd (and other projects generated by gir-to-d) in @safe environments. I suppose gir-to-d could do something similar to what gtk-rs' gir tool does: wrap the unsafe function and then make a the call to the C function in a @trusted lambda or something along those lines. If there's interest for that I could try to give it a go during semester holidays.

Re: Making gir-to-d generate @safe code

On 22-05-2020 18:01, Rasmus Thomsen wrote:

Hello,

DIP1028 (@safe by default) got accepted yesterday, so I think it'd be nice if gir-to-d generated @safe code so users can use glibd>kd (and other projects generated by gir-to-d) in @safe environments. I suppose gir-to-d could do something similar to what gtk-rs' gir tool does: wrap the unsafe function and then make a the call to the C function in a @trusted lambda or something along those lines. If there's interest for that I could try to give it a go during semester holidays.

First we would have to think long and hard if the functions in gtkD
could actually be @safe or at most @trusted with the way the reference
counting on the C side interacts with the GC.

With the C functions in GtkD marked as @system, and the functions from
GtkD marked as @trusted, you can use GtkD from @safe code without any
false promises about safety.