Discussion Thread: DIP 1035-- at system Variables--Final Review

Stanislav Blinov stanislav.blinov at gmail.com
Tue Feb 22 08:47:55 UTC 2022


On Monday, 21 February 2022 at 22:56:30 UTC, Dennis wrote:
> On Monday, 21 February 2022 at 21:50:31 UTC, Paul Backus wrote:
>> If the goal is being able to define custom pointer types, then 
>> the DIP should use that as an example instead of talking about 
>> file descriptors, and it should explain *exactly* which part 
>> of the example depends on this feature for memory safety (as 
>> the other examples do).
>
> A double `fclose` on a `FILE*` is basically a double free. I 
> thought the same would apply to raw file descriptors, but I 
> just read that a double `close` simply results in an `EBADF` 
> error, so maybe it's not a good example.

A more pertinent example around file descriptors and memory 
safety is void-initialization:

```d
struct File
{
     void write(const(void)[] data) @safe;
     // ...
     private int fd;
}

void main() @safe
{
     File f = void; // this compiles in current language, because 
`File` doesn't have pointers
     f.write("hello"); // may corrupt memory if 
(implementation-defined) value of `f.fd` happens to correspond to 
an existing mapping
}
```


More information about the Digitalmars-d mailing list