Simplification of @trusted
Sönke Ludwig
sludwig at outerproduct.org
Sat Jun 19 21:19:29 UTC 2021
Am 18.06.2021 um 04:07 schrieb Walter Bright:
> (...)
>
> m_core.m_handles[h] looks like it needs encapsulation in a proper
> function that takes m_core and h as arguments.
Accessing `m_core.m_handles[h]` is `@safe`, just taking the address of
the result is not. `scope slot = ...` might make it work in this
particular case, but of course only with the appropriate compiler
version and `-preview` switch.
> I got rid of a *lot* of memory management code in the back end by
> creating a container type to do it and prevent a safe interface.
The problem here is just escaping references to contained items. At some
point in the future, with DIP25/DIP1000 enabled by default, this will
hopefully become a non-issue.
> Unsafe system calls like CreateFileW() can be encapsulated with a
> wrapper that presents a safe interface.
>
> Yes, this is extra work. But it's good work. I bet you'll like the
> result! I sure have when I've done it.
The code that calls it *is* the `@safe` wrapper ;) (more or less, it
does a little bit more than that - but adding another wrapper in-between
wouldn't really add anything apart from complexity, because the function
is only used in a single place)
More information about the Digitalmars-d
mailing list