Implicit @Safe Resources
Paul Backus
snarwin at gmail.com
Sun Sep 3 16:39:18 UTC 2023
On Sunday, 3 September 2023 at 14:15:42 UTC, Menshikov wrote:
> Hi all.
> I'm currently doing OpenGL type binding, and I noticed one
> assumption in the @safe code.
> @safe, scope work only with explicit reference types, if your
> structure does not have such fields, then checks do not work.
> In opengl, and in other APIs, we work with resources not
> through memory references, but through an integer descriptor.
>
> ```d
> @safe:
>
> struct BufferView {
> GLuint id;
>
> //...
>
> void destroy() @trusted scope {
> //...
> }
> }
> ```
This is one of the problems [DIP 1035's][1] @system variables
were designed to solve:
```d
struct BufferView {
@system GLuint id
//...
}
```
When compiling with `-preview=systemVariables`, Variables with
the @system cannot be accessed from @safe code, and are protected
against accidental corruption via aliasing, unions, and so on
(like how built-in reference types are protected).
[1]:
https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1035.md
More information about the Digitalmars-d
mailing list