Deprecate the non-nogc userData overload.

This allows more of the implementation to become nogc.
This commit is contained in:
Sönke Ludwig 2018-10-22 11:05:30 +02:00
parent 73abd867b4
commit 0b73eda8d5

View file

@ -352,38 +352,34 @@ interface EventDriverSockets {
/** Retrieves a reference to a user-defined value associated with a descriptor. /** Retrieves a reference to a user-defined value associated with a descriptor.
*/ */
@property final ref T userData(T, FD)(FD descriptor) @trusted
if (!hasNoGCLifetime!T)
{
import std.conv : emplace;
static void init(void* ptr) { emplace(cast(T*)ptr); }
static void destr(void* ptr) { destroy(*cast(T*)ptr); }
return *cast(T*)rawUserData(descriptor, T.sizeof, &init, &destr);
}
/// ditto
@property final ref T userData(T, FD)(FD descriptor) @trusted @nogc @property final ref T userData(T, FD)(FD descriptor) @trusted @nogc
if (hasNoGCLifetime!T) if (hasNoGCLifetime!T)
{ {
import std.conv : emplace; import std.conv : emplace;
static void init(void* ptr) @nogc { emplace(cast(T*)ptr); } static void init(void* ptr) @nogc { emplace(cast(T*)ptr); }
static void destr(void* ptr) @nogc { destroy(*cast(T*)ptr); } static void destr(void* ptr) @nogc { destroy(*cast(T*)ptr); }
return *cast(T*)rawUserData(descriptor, T.sizeof, &init, &destr);
scope getter = { }
return cast(T*)rawUserData(descriptor, T.sizeof, &init, &destr); /// ditto
}; deprecated("Only @nogc constructible and destructible user data allowed.")
@property final ref T userData(T, FD)(FD descriptor) @trusted
static if (__traits(compiles, () nothrow @trusted { getter(); })) if (!hasNoGCLifetime!T)
return *(cast(T* delegate() @nogc nothrow)getter)(); {
else import std.conv : emplace;
return *(cast(T* delegate() @nogc)getter)(); static void init(void* ptr) { emplace(cast(T*)ptr); }
static void destr(void* ptr) { destroy(*cast(T*)ptr); }
static if (__traits(compiles, () nothrow { init(null); destr(null); }))
alias F = void function(void*) @nogc nothrow;
else alias F = void function(void*) @nogc;
return *cast(T*)rawUserData(descriptor, T.sizeof, cast(F)&init, cast(F)&destr);
} }
/// Low-level user data access. Use `getUserData` instead. /// Low-level user data access. Use `getUserData` instead.
protected void* rawUserData(StreamSocketFD descriptor, size_t size, DataInitializer initialize, DataInitializer destroy) @system; protected void* rawUserData(StreamSocketFD descriptor, size_t size, DataInitializer initialize, DataInitializer destroy) @system @nogc;
/// ditto /// ditto
protected void* rawUserData(StreamListenSocketFD descriptor, size_t size, DataInitializer initialize, DataInitializer destroy) @system; protected void* rawUserData(StreamListenSocketFD descriptor, size_t size, DataInitializer initialize, DataInitializer destroy) @system @nogc;
/// ditto /// ditto
protected void* rawUserData(DatagramSocketFD descriptor, size_t size, DataInitializer initialize, DataInitializer destroy) @system; protected void* rawUserData(DatagramSocketFD descriptor, size_t size, DataInitializer initialize, DataInitializer destroy) @system @nogc;
} }
enum hasNoGCLifetime(T) = __traits(compiles, () @nogc @trusted { import std.conv : emplace; T b = void; emplace!T(&b); destroy(b); }); enum hasNoGCLifetime(T) = __traits(compiles, () @nogc @trusted { import std.conv : emplace; T b = void; emplace!T(&b); destroy(b); });
@ -668,7 +664,7 @@ alias EventCallback = void delegate(EventID);
alias SignalCallback = void delegate(SignalListenID, SignalStatus, int); alias SignalCallback = void delegate(SignalListenID, SignalStatus, int);
alias TimerCallback = void delegate(TimerID); alias TimerCallback = void delegate(TimerID);
alias FileChangesCallback = void delegate(WatcherID, in ref FileChange change); alias FileChangesCallback = void delegate(WatcherID, in ref FileChange change);
@system alias DataInitializer = void function(void*); @system alias DataInitializer = void function(void*) @nogc;
enum ExitReason { enum ExitReason {
timeout, timeout,