What should happen here?

Steven Schveighoffer schveiguy at gmail.com
Wed Sep 22 19:56:23 UTC 2021


On 9/22/21 3:24 PM, Adam D Ruppe wrote:
> On Wednesday, 22 September 2021 at 19:14:43 UTC, Steven Schveighoffer 
> wrote:
>> What if you are calling D functions that call extern(C) functions?
> 
> Then it will be an argument to that other D function which makes it a 
> local variable there and the same rule can apply.
> 
> If the C function stores something beyond the immediate function, you 
> are already supposed to malloc it or addRoot etc, so I don't think the 
> depth of the call stack really makes a difference.

While I don't necessarily disagree with you, this removes all 
possibility of abstraction. Even a local function cannot be used to 
factor out initialization of a C resource.

I think code which does not properly do cleanup of C resources it uses, 
or does so with the expectation that the cleanup must be running after 
`main` exits is very suspect. But the fact that you can't rely on the 
recommended remedy in the spec needs fixing, and I don't think this 
fixes it.

This also introduces unnecessary storage of pointers when not necessary 
(probably the vast majority of extern(C) calls).

-Steve


More information about the Digitalmars-d mailing list