From 76f2cd7080c948206d5a1b7486a5dfb95476f684 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sat, 23 Mar 2019 06:41:51 +0100 Subject: [PATCH] Add DIP25 compatibility. Fix #83 --- .travis.yml | 2 +- appveyor.yml | 4 ++-- dub.json | 1 + source/tanya/async/event/iocp.d | 18 +++------------ source/tanya/async/event/selector.d | 36 +++++------------------------ source/tanya/async/loop.d | 14 +++-------- source/tanya/async/transport.d | 10 ++------ source/tanya/async/watcher.d | 12 ++-------- source/tanya/format.d | 2 +- source/tanya/net/ip.d | 5 ++-- source/tanya/typecons.d | 2 +- 11 files changed, 24 insertions(+), 82 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1871bd1..8478837 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ language: d d: - dmd-2.085.0 -- dmd-2.082.1 +- dmd-2.081.2 env: global: diff --git a/appveyor.yml b/appveyor.yml index 1437042..ed63de4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,10 +10,10 @@ environment: DVersion: 2.085.0 arch: x86 - DC: dmd - DVersion: 2.082.1 + DVersion: 2.081.2 arch: x64 - DC: dmd - DVersion: 2.082.1 + DVersion: 2.081.2 arch: x86 skip_tags: true diff --git a/dub.json b/dub.json index 8a30c7b..8fcc299 100644 --- a/dub.json +++ b/dub.json @@ -53,6 +53,7 @@ { "name": "unittest", "versions": ["TanyaPhobos"], + "dflags": ["-dip25"], "importPaths": [ "./source", "./tests" diff --git a/source/tanya/async/event/iocp.d b/source/tanya/async/event/iocp.d index a32e04c..d7b782d 100644 --- a/source/tanya/async/event/iocp.d +++ b/source/tanya/async/event/iocp.d @@ -67,11 +67,7 @@ final class StreamTransport : SocketWatcher, DuplexTransport, SocketTransport * Postcondition: $(D_INLINECODE socket !is null) */ override @property OverlappedConnectedSocket socket() pure nothrow @safe @nogc - out (socket) - { - assert(socket !is null); - } - do + out (socket; socket !is null) { return cast(OverlappedConnectedSocket) socket_; } @@ -124,11 +120,7 @@ final class StreamTransport : SocketWatcher, DuplexTransport, SocketTransport * Precondition: $(D_INLINECODE protocol !is null) */ @property void protocol(Protocol protocol) pure nothrow @safe @nogc - in - { - assert(protocol !is null); - } - do + in (protocol !is null) { protocol_ = protocol; } @@ -264,11 +256,7 @@ final class IOCPLoop : Loop private void kill(StreamTransport transport, SocketException exception = null) @nogc - in - { - assert(transport !is null); - } - do + in (transport !is null) { transport.socket.shutdown(); defaultAllocator.dispose(transport.socket); diff --git a/source/tanya/async/event/selector.d b/source/tanya/async/event/selector.d index 1cc4515..5adc921 100644 --- a/source/tanya/async/event/selector.d +++ b/source/tanya/async/event/selector.d @@ -75,22 +75,14 @@ package class StreamTransport : SocketWatcher, DuplexTransport, SocketTransport * Postcondition: $(D_INLINECODE socket !is null) */ override @property ConnectedSocket socket() pure nothrow @safe @nogc - out (socket) - { - assert(socket !is null); - } - do + out (socket; socket !is null) { return cast(ConnectedSocket) socket_; } private @property void socket(ConnectedSocket socket) pure nothrow @safe @nogc - in - { - assert(socket !is null); - } - do + in (socket !is null) { socket_ = socket; } @@ -114,11 +106,7 @@ package class StreamTransport : SocketWatcher, DuplexTransport, SocketTransport * Precondition: $(D_INLINECODE protocol !is null) */ @property void protocol(Protocol protocol) pure nothrow @safe @nogc - in - { - assert(protocol !is null); - } - do + in (protocol !is null) { protocol_ = protocol; } @@ -257,11 +245,7 @@ abstract class SelectorLoop : Loop */ protected void kill(StreamTransport transport, SocketException exception = null) @nogc - in - { - assert(transport !is null); - } - do + in (transport !is null) { transport.socket.shutdown(); defaultAllocator.dispose(transport.socket); @@ -283,11 +267,7 @@ abstract class SelectorLoop : Loop */ protected bool feed(StreamTransport transport, SocketException exception = null) @nogc - in - { - assert(transport !is null); - } - do + in (transport !is null) { while (transport.input.length && transport.writeReady) { @@ -350,11 +330,7 @@ abstract class SelectorLoop : Loop * connection = Connection watcher ready to accept. */ package void acceptConnections(ConnectionWatcher connection) @nogc - in - { - assert(connection !is null); - } - do + in (connection !is null) { while (true) { diff --git a/source/tanya/async/loop.d b/source/tanya/async/loop.d index 2c13397..6a79b4b 100644 --- a/source/tanya/async/loop.d +++ b/source/tanya/async/loop.d @@ -262,12 +262,8 @@ abstract class Loop * $(D_PSYMBOL maxBlockTime). */ protected @property void blockTime(in Duration blockTime) @safe pure nothrow @nogc - in - { - assert(blockTime <= 1.dur!"hours", "Too long to wait."); - assert(!blockTime.isNegative); - } - do + in (blockTime <= 1.dur!"hours", "Too long to wait.") + in (!blockTime.isNegative) { blockTime_ = blockTime; } @@ -340,11 +336,7 @@ class BadLoopException : Exception * loop = The event loop. */ @property void defaultLoop(Loop loop) @nogc -in -{ - assert(loop !is null); -} -do +in (loop !is null) { defaultLoop_ = loop; } diff --git a/source/tanya/async/transport.d b/source/tanya/async/transport.d index c516ae2..a536e4b 100644 --- a/source/tanya/async/transport.d +++ b/source/tanya/async/transport.d @@ -57,10 +57,7 @@ interface DuplexTransport : ReadTransport, WriteTransport * Postcondition: $(D_INLINECODE protocol !is null) */ @property Protocol protocol() pure nothrow @safe @nogc - out (protocol) - { - assert(protocol !is null); - } + out (protocol; protocol !is null); /** * Switches the protocol. @@ -73,10 +70,7 @@ interface DuplexTransport : ReadTransport, WriteTransport * Precondition: $(D_INLINECODE protocol !is null) */ @property void protocol(Protocol protocol) pure nothrow @safe @nogc - in - { - assert(protocol !is null); - } + in (protocol !is null); /** diff --git a/source/tanya/async/watcher.d b/source/tanya/async/watcher.d index 9feb1df..a16fb90 100644 --- a/source/tanya/async/watcher.d +++ b/source/tanya/async/watcher.d @@ -52,11 +52,7 @@ abstract class SocketWatcher : Watcher * Precondition: $(D_INLINECODE socket !is null) */ this(Socket socket) pure nothrow @safe @nogc - in - { - assert(socket !is null); - } - do + in (socket !is null) { socket_ = socket; } @@ -102,11 +98,7 @@ class ConnectionWatcher : SocketWatcher * Invokes new connection callback. */ override void invoke() @nogc - in - { - assert(protocolFactory !is null, "Protocol isn't set."); - } - do + in (protocolFactory !is null, "Protocol isn't set.") { for (; !this.incoming.empty; this.incoming.removeFront()) { diff --git a/source/tanya/format.d b/source/tanya/format.d index 806fc1f..aa1c41f 100644 --- a/source/tanya/format.d +++ b/source/tanya/format.d @@ -1928,7 +1928,7 @@ private char[] errol3(double value, * $(D_PARAM sign). */ private const(char)[] real2String(double value, - ref char[512] buffer, + return ref char[512] buffer, out int exponent, out bool sign) @nogc nothrow pure @trusted { diff --git a/source/tanya/net/ip.d b/source/tanya/net/ip.d index 92acd3d..eff93ba 100644 --- a/source/tanya/net/ip.d +++ b/source/tanya/net/ip.d @@ -57,10 +57,9 @@ struct Address4 * Params: * address = The address as an unsigned integer in host byte order. */ - this(uint address) @nogc nothrow pure @safe + this(uint address) @nogc nothrow pure @trusted { - copy(NetworkOrder!4(address), - (() @trusted => (cast(ubyte*) &this.address)[0 .. 4])()); + copy(NetworkOrder!4(address), (cast(ubyte*) &this.address)[0 .. 4]); } /// diff --git a/source/tanya/typecons.d b/source/tanya/typecons.d index 02f5e72..1007246 100644 --- a/source/tanya/typecons.d +++ b/source/tanya/typecons.d @@ -608,7 +608,7 @@ if (isTypeTuple!Specs && NoDuplicates!Specs.length == Specs.length) return this; } - private ref typeof(this) copyAssign(T)(ref T that) + private ref typeof(this) copyAssign(T)(ref T that) return { this.tag = staticIndexOf!(T, Types);