On Friday, 3 February 2017 at 12:25:42 UTC, Dominikus Dittes Scherkl wrote:
On Friday, 3 February 2017 at 09:28:26 UTC, yazd wrote:
Is it possible to have non-@safe callbacks be part of the non-deprecated API?
Why?
A @safe API allows you to use it within @safe code, but it doesn't require you to also write @safe code. Especially if you don't like to annotate your code to be @safe, even if you think it is safe, this doesn't hinders you to use other peoples @safe code. Only the reverse is a problem (other people, who like to annotate their code @safe, can't use your code if it is not annotated - so they start to ignore your code even if it would be @safe only because you don't bother).

What you are saying is true when you are the caller, but in this case, the callbacks provided to the API are what is required to be @safe and accordingly my code is required to be @safe.

For example, this is the signature for `setTimer`:
Timer setTimer(Duration timeout, void delegate() nothrow @safe callback, bool periodic = false) @safe nothrow;

I can't even use `logInfo("%s", ex)` where `ex` is an `Exception` in @safe code, because `Exception.toString()` isn't @safe and it can't be @safe because it is a virtual function, and there are many cases of such problems.

Reply via email to