nothrow function callbacks in extern(C) code - solution

Rainer Schuetze via Digitalmars-d digitalmars-d at puremagic.com
Sun Jun 22 01:43:15 PDT 2014



On 22.06.2014 02:23, Andrei Alexandrescu wrote:
> On 6/20/14, 3:14 AM, Rainer Schuetze wrote:
>> We either have to be more conservative with annotating OS functions or
>> relax the guarantees of nothrow or @nogc. Both alternatives are not very
>> compelling.
>
> Callbacks passed into OS/clib functions are never supposed to throw so
> we must annotate them all with nothrow. C functions are never designed
> under the assumption callbacks may throw. -- Andrei

For nothrow that restriction makes sense, though there are functions in 
the Windows "C API" that actually may throw, e.g. HeapAlloc [1] and 
MmProbeAndLockPages [2]. No callbacks are involved in these examples, 
though.
Under unix, signal handlers that throw exceptions seem to be used, 
though this might be non-standard. We even have one in druntime [3].

I'm ok with the current treatment of nothrow, but what can we do about 
@nogc?


[1] 
http://msdn.microsoft.com/en-us/library/windows/desktop/aa366597%28v=vs.85%29.aspx
[2] 
http://msdn.microsoft.com/en-us/library/windows/hardware/ff554664%28v=vs.85%29.aspx
[3] 
https://github.com/D-Programming-Language/druntime/blob/master/src/etc/linux/memoryerror.d

BTW: The D exception handling is compatible with SEH for Win32, but not 
for Win64. You cannot handle exceptions by type across languages, 
though, only unwinding and "catch(Throwable)" works here.



More information about the Digitalmars-d mailing list