all OS functions should be "nothrow @trusted @nogc"
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jul 27 04:48:34 PDT 2017
On 7/27/17 7:27 AM, Timon Gehr wrote:
> On 27.07.2017 02:11, Steven Schveighoffer wrote:
>> On 7/26/17 7:56 PM, Andrei Alexandrescu wrote:
>>> On 07/26/2017 06:16 PM, Steven Schveighoffer wrote:
>>>> So I guess I should restate that we can assume no implementations
>>>> exist that intentionally cause UB when stream is NULL (as in Timon's
>>>> example). Either they check for null, and handle gracefully, or
>>>> don't check and segfault.
>>>
>>> No need to worry about that at all. If worse comes to worst - i.e. we
>>> do port to such an implementation - we can always provide a thin
>>> wrapper that checks for NULL then calls the native function. No need
>>> to change the signatures. -- Andrei
>>
>> Hm.. so you mean:
>>
>> pragma(mangle, "fgetc")
>> private extern(C) int real_fgetc(FILE * stream)
>>
>> extern(D) int fgetc(FILE *stream) @trusted
>> {
>> if(stream == null) assert(0);
>> return real_fgetc(stream);
>> }
>>
>> Yeah, that should work well actually. Nice!
>>
>
> That works but it changes the signature. (extern(D) vs. extern(C)).
Hm... you could use pragma(mangle) to get the signature the same. I was
just thinking since it's going to be a D wrapper, it could be extern(D).
But you are right, &fgetc would result in a different type, so we should
use pragma(mangle) instead.
-Steve
More information about the Digitalmars-d
mailing list