Replace defaultAllocator with theAllocator

This commit is contained in:
Eugen Wissner 2016-11-30 21:54:31 +01:00
parent ed0eb4ac74
commit 9fdcef86e7
8 changed files with 106 additions and 117 deletions

View File

@ -27,7 +27,7 @@ class SList(T)
* allocator = The allocator should be used for the element * allocator = The allocator should be used for the element
* allocations. * allocations.
*/ */
this(IAllocator allocator = defaultAllocator) this(IAllocator allocator = theAllocator)
{ {
this.allocator = allocator; this.allocator = allocator;
reset(); reset();
@ -79,7 +79,7 @@ class SList(T)
/// ///
unittest unittest
{ {
auto l = make!(SList!int)(defaultAllocator); auto l = make!(SList!int)(theAllocator);
int[2] values = [8, 9]; int[2] values = [8, 9];
l.front = values[0]; l.front = values[0];
@ -87,7 +87,7 @@ class SList(T)
l.front = values[1]; l.front = values[1];
assert(l.front == values[1]); assert(l.front == values[1]);
dispose(defaultAllocator, l); dispose(theAllocator, l);
} }
/** /**
@ -108,7 +108,7 @@ class SList(T)
/// ///
unittest unittest
{ {
auto l = make!(SList!int)(defaultAllocator); auto l = make!(SList!int)(theAllocator);
int value = 5; int value = 5;
assert(l.empty); assert(l.empty);
@ -118,7 +118,7 @@ class SList(T)
assert(l.front == value); assert(l.front == value);
assert(!l.empty); assert(!l.empty);
dispose(defaultAllocator, l); dispose(theAllocator, l);
} }
/** /**
@ -153,7 +153,7 @@ class SList(T)
/// ///
unittest unittest
{ {
auto l = make!(SList!int)(defaultAllocator); auto l = make!(SList!int)(theAllocator);
int[2] values = [8, 9]; int[2] values = [8, 9];
l.front = values[0]; l.front = values[0];
@ -162,7 +162,7 @@ class SList(T)
l.popFront(); l.popFront();
assert(l.front == values[0]); assert(l.front == values[0]);
dispose(defaultAllocator, l); dispose(theAllocator, l);
} }
/** /**
@ -192,7 +192,7 @@ class SList(T)
/// ///
unittest unittest
{ {
auto l = make!(SList!int)(defaultAllocator); auto l = make!(SList!int)(theAllocator);
int[3] values = [8, 5, 4]; int[3] values = [8, 5, 4];
l.front = values[0]; l.front = values[0];
@ -203,7 +203,7 @@ class SList(T)
assert(l.remove() == 8); assert(l.remove() == 8);
assert(l.empty); assert(l.empty);
dispose(defaultAllocator, l); dispose(theAllocator, l);
} }
/** /**
@ -220,7 +220,7 @@ class SList(T)
/// ///
unittest unittest
{ {
auto l = make!(SList!int)(defaultAllocator); auto l = make!(SList!int)(theAllocator);
int[2] values = [8, 5]; int[2] values = [8, 5];
l.current = values[0]; l.current = values[0];
@ -231,7 +231,7 @@ class SList(T)
l.reset(); l.reset();
assert(l.current == 5); assert(l.current == 5);
dispose(defaultAllocator, l); dispose(theAllocator, l);
} }
/** /**
@ -262,7 +262,7 @@ class SList(T)
/// ///
unittest unittest
{ {
auto l = make!(SList!int)(defaultAllocator); auto l = make!(SList!int)(theAllocator);
int[3] values = [5, 4, 9]; int[3] values = [5, 4, 9];
l.front = values[0]; l.front = values[0];
@ -275,7 +275,7 @@ class SList(T)
assert(i != 2 || e == values[0]); assert(i != 2 || e == values[0]);
} }
dispose(defaultAllocator, l); dispose(theAllocator, l);
} }
/// Ditto. /// Ditto.
@ -300,7 +300,7 @@ class SList(T)
/// ///
unittest unittest
{ {
auto l = make!(SList!int)(defaultAllocator); auto l = make!(SList!int)(theAllocator);
int[3] values = [5, 4, 9]; int[3] values = [5, 4, 9];
size_t i; size_t i;
@ -315,7 +315,7 @@ class SList(T)
++i; ++i;
} }
dispose(defaultAllocator, l); dispose(theAllocator, l);
} }
/** /**
@ -398,7 +398,7 @@ interface Stuff
/// ///
unittest unittest
{ {
auto l = make!(SList!Stuff)(defaultAllocator); auto l = make!(SList!Stuff)(theAllocator);
dispose(defaultAllocator, l); dispose(theAllocator, l);
} }

View File

@ -27,7 +27,7 @@ class Queue(T)
* allocator = The allocator should be used for the element * allocator = The allocator should be used for the element
* allocations. * allocations.
*/ */
this(IAllocator allocator = defaultAllocator) this(IAllocator allocator = theAllocator)
{ {
this.allocator = allocator; this.allocator = allocator;
} }
@ -91,7 +91,7 @@ class Queue(T)
/// ///
unittest unittest
{ {
auto q = make!(Queue!int)(defaultAllocator); auto q = make!(Queue!int)(theAllocator);
int[2] values = [8, 9]; int[2] values = [8, 9];
q.insertBack(values[0]); q.insertBack(values[0]);
@ -99,7 +99,7 @@ class Queue(T)
q.insertBack(values[1]); q.insertBack(values[1]);
assert(q.front is values[0]); assert(q.front is values[0]);
dispose(defaultAllocator, q); dispose(theAllocator, q);
} }
/** /**
@ -119,7 +119,7 @@ class Queue(T)
/// ///
unittest unittest
{ {
auto q = make!(Queue!int)(defaultAllocator); auto q = make!(Queue!int)(theAllocator);
int value = 5; int value = 5;
assert(q.empty); assert(q.empty);
@ -129,7 +129,7 @@ class Queue(T)
assert(q.front == value); assert(q.front == value);
assert(!q.empty); assert(!q.empty);
dispose(defaultAllocator, q); dispose(theAllocator, q);
} }
/** /**
@ -143,14 +143,14 @@ class Queue(T)
/// ///
unittest unittest
{ {
auto q = make!(Queue!int)(defaultAllocator); auto q = make!(Queue!int)(theAllocator);
int value = 7; int value = 7;
assert(q.empty); assert(q.empty);
q.insertBack(value); q.insertBack(value);
assert(!q.empty); assert(!q.empty);
dispose(defaultAllocator, q); dispose(theAllocator, q);
} }
/** /**
@ -176,7 +176,7 @@ class Queue(T)
/// ///
unittest unittest
{ {
auto q = make!(Queue!int)(defaultAllocator); auto q = make!(Queue!int)(theAllocator);
int[2] values = [8, 9]; int[2] values = [8, 9];
q.insertBack(values[0]); q.insertBack(values[0]);
@ -185,7 +185,7 @@ class Queue(T)
q.popFront(); q.popFront();
assert(q.front is values[1]); assert(q.front is values[1]);
dispose(defaultAllocator, q); dispose(theAllocator, q);
} }
/** /**
@ -212,7 +212,7 @@ class Queue(T)
/// ///
unittest unittest
{ {
auto q = make!(Queue!int)(defaultAllocator); auto q = make!(Queue!int)(theAllocator);
dispose(defaultAllocator, q); dispose(theAllocator, q);
} }

View File

@ -17,12 +17,12 @@ import tanya.memory;
* *
* If you assign a value: * If you assign a value:
* --- * ---
* auto v = make!(Vector!int)(defaultAllocator); * auto v = make!(Vector!int)(theAllocator);
* int value = 5; * int value = 5;
* *
* v[1000] = value; * v[1000] = value;
* *
* dispose(defaultAllocator, v); * dispose(theAllocator, v);
* --- * ---
* it will allocate not only for one, but for 1000 elements. So this * it will allocate not only for one, but for 1000 elements. So this
* implementation is more suitable for sequential data with random access. * implementation is more suitable for sequential data with random access.
@ -40,14 +40,14 @@ class Vector(T)
* allocator = The allocator should be used for the element * allocator = The allocator should be used for the element
* allocations. * allocations.
*/ */
this(size_t length, IAllocator allocator = defaultAllocator) this(size_t length, IAllocator allocator = theAllocator)
{ {
this.allocator = allocator; this.allocator = allocator;
vector = makeArray!T(allocator, length); vector = makeArray!T(allocator, length);
} }
/// Ditto. /// Ditto.
this(IAllocator allocator = defaultAllocator) this(IAllocator allocator = theAllocator)
{ {
this(0, allocator); this(0, allocator);
} }
@ -82,19 +82,18 @@ class Vector(T)
/// ///
unittest unittest
{ {
auto v = make!(Vector!int)(defaultAllocator); auto v = make!(Vector!int)(theAllocator);
v.length = 5; v.length = 5;
assert(v.length == 5); assert(v.length == 5);
// TODO
v.length = 7; v.length = 7;
assert(v.length == 7); assert(v.length == 7);
v.length = 0; v.length = 0;
assert(v.length == 0); assert(v.length == 0);
dispose(defaultAllocator, v); dispose(theAllocator, v);
} }
/** /**
@ -140,7 +139,7 @@ class Vector(T)
/// ///
unittest unittest
{ {
auto v = make!(Vector!int)(defaultAllocator); auto v = make!(Vector!int)(theAllocator);
int[2] values = [5, 15]; int[2] values = [5, 15];
assert(v.length == 0); assert(v.length == 0);
@ -151,7 +150,7 @@ class Vector(T)
v[4] = values[1]; v[4] = values[1];
assert(v.length == 5); assert(v.length == 5);
dispose(defaultAllocator, v); dispose(theAllocator, v);
} }
/** /**
@ -170,7 +169,7 @@ class Vector(T)
/// ///
unittest unittest
{ {
auto v = make!(Vector!int)(defaultAllocator); auto v = make!(Vector!int)(theAllocator);
int[2] values = [5, 15]; int[2] values = [5, 15];
v[1] = values[0]; v[1] = values[0];
@ -182,7 +181,7 @@ class Vector(T)
v[0] = values[1]; v[0] = values[1];
assert(v[0] is values[1]); assert(v[0] is values[1]);
dispose(defaultAllocator, v); dispose(theAllocator, v);
} }
/** /**
@ -227,7 +226,7 @@ class Vector(T)
/// ///
unittest unittest
{ {
auto v = make!(Vector!int)(defaultAllocator, 1); auto v = make!(Vector!int)(theAllocator, 1);
int[3] values = [5, 15, 8]; int[3] values = [5, 15, 8];
v[0] = values[0]; v[0] = values[0];
@ -250,7 +249,7 @@ class Vector(T)
assert(j != 2 || e is values[2]); assert(j != 2 || e is values[2]);
} }
dispose(defaultAllocator, v); dispose(theAllocator, v);
} }
/** /**
@ -280,7 +279,7 @@ class Vector(T)
/// ///
unittest unittest
{ {
auto v = make!(Vector!int)(defaultAllocator, 1); auto v = make!(Vector!int)(theAllocator, 1);
int[2] values = [5, 15]; int[2] values = [5, 15];
v.front = values[0]; v.front = values[0];
@ -289,7 +288,7 @@ class Vector(T)
v.front = values[1]; v.front = values[1];
assert(v.front == 15); assert(v.front == 15);
dispose(defaultAllocator, v); dispose(theAllocator, v);
} }
/** /**
@ -312,7 +311,7 @@ class Vector(T)
/// ///
unittest unittest
{ {
auto v = make!(Vector!int)(defaultAllocator, 1); auto v = make!(Vector!int)(theAllocator, 1);
int[2] values = [5, 15]; int[2] values = [5, 15];
v[0] = values[0]; v[0] = values[0];
@ -325,7 +324,7 @@ class Vector(T)
v.popFront(); v.popFront();
assert(v.empty); assert(v.empty);
dispose(defaultAllocator, v); dispose(theAllocator, v);
} }
/** /**
@ -355,7 +354,7 @@ class Vector(T)
/// ///
unittest unittest
{ {
auto v = make!(Vector!int)(defaultAllocator, 1); auto v = make!(Vector!int)(theAllocator, 1);
int[2] values = [5, 15]; int[2] values = [5, 15];
v.back = values[0]; v.back = values[0];
@ -364,7 +363,7 @@ class Vector(T)
v.back = values[1]; v.back = values[1];
assert(v.back == 15); assert(v.back == 15);
dispose(defaultAllocator, v); dispose(theAllocator, v);
} }
/** /**
@ -386,7 +385,7 @@ class Vector(T)
/// ///
unittest unittest
{ {
auto v = make!(Vector!int)(defaultAllocator, 1); auto v = make!(Vector!int)(theAllocator, 1);
int[2] values = [5, 15]; int[2] values = [5, 15];
v[0] = values[0]; v[0] = values[0];
@ -399,7 +398,7 @@ class Vector(T)
v.popBack(); v.popBack();
assert(v.empty); assert(v.empty);
dispose(defaultAllocator, v); dispose(theAllocator, v);
} }
/// Container. /// Container.
@ -411,7 +410,7 @@ class Vector(T)
/// ///
unittest unittest
{ {
auto v = make!(Vector!int)(defaultAllocator); auto v = make!(Vector!int)(theAllocator);
dispose(defaultAllocator, v); dispose(theAllocator, v);
} }

View File

@ -44,7 +44,7 @@ enum PaddingMode
ubyte[] pad(ref ubyte[] input, ubyte[] pad(ref ubyte[] input,
in PaddingMode mode, in PaddingMode mode,
in ushort blockSize, in ushort blockSize,
IAllocator allocator = defaultAllocator) IAllocator allocator = theAllocator)
in in
{ {
assert(blockSize > 0 && blockSize <= 256); assert(blockSize > 0 && blockSize <= 256);
@ -86,7 +86,7 @@ body
unittest unittest
{ {
{ // Zeros { // Zeros
auto input = defaultAllocator.makeArray!ubyte(50); auto input = theAllocator.makeArray!ubyte(50);
pad(input, PaddingMode.zero, 64); pad(input, PaddingMode.zero, 64);
assert(input.length == 64); assert(input.length == 64);
@ -95,10 +95,10 @@ unittest
assert(input.length == 64); assert(input.length == 64);
assert(input[63] == 0); assert(input[63] == 0);
defaultAllocator.dispose(input); theAllocator.dispose(input);
} }
{ // PKCS#7 { // PKCS#7
auto input = defaultAllocator.makeArray!ubyte(50); auto input = theAllocator.makeArray!ubyte(50);
for (ubyte i; i < 40; ++i) for (ubyte i; i < 40; ++i)
{ {
input[i] = i; input[i] = i;
@ -140,10 +140,10 @@ unittest
} }
} }
defaultAllocator.dispose(input); theAllocator.dispose(input);
} }
{ // ANSI X.923 { // ANSI X.923
auto input = defaultAllocator.makeArray!ubyte(50); auto input = theAllocator.makeArray!ubyte(50);
for (ubyte i; i < 40; ++i) for (ubyte i; i < 40; ++i)
{ {
input[i] = i; input[i] = i;
@ -185,7 +185,7 @@ unittest
} }
} }
defaultAllocator.dispose(input); theAllocator.dispose(input);
} }
} }
@ -204,7 +204,7 @@ unittest
ref ubyte[] unpad(ref ubyte[] input, ref ubyte[] unpad(ref ubyte[] input,
in PaddingMode mode, in PaddingMode mode,
in ushort blockSize, in ushort blockSize,
IAllocator allocator = defaultAllocator) IAllocator allocator = theAllocator)
in in
{ {
assert(input.length != 0); assert(input.length != 0);
@ -231,8 +231,8 @@ body
unittest unittest
{ {
{ // Zeros { // Zeros
auto input = defaultAllocator.makeArray!ubyte(50); auto input = theAllocator.makeArray!ubyte(50);
auto inputDup = defaultAllocator.makeArray!ubyte(50); auto inputDup = theAllocator.makeArray!ubyte(50);
pad(input, PaddingMode.zero, 64); pad(input, PaddingMode.zero, 64);
pad(inputDup, PaddingMode.zero, 64); pad(inputDup, PaddingMode.zero, 64);
@ -240,13 +240,13 @@ unittest
unpad(input, PaddingMode.zero, 64); unpad(input, PaddingMode.zero, 64);
assert(input == inputDup); assert(input == inputDup);
defaultAllocator.dispose(input); theAllocator.dispose(input);
defaultAllocator.dispose(inputDup); theAllocator.dispose(inputDup);
} }
{ // PKCS#7 { // PKCS#7
auto input = defaultAllocator.makeArray!ubyte(50); auto input = theAllocator.makeArray!ubyte(50);
auto inputDup = defaultAllocator.makeArray!ubyte(50); auto inputDup = theAllocator.makeArray!ubyte(50);
for (ubyte i; i < 40; ++i) for (ubyte i; i < 40; ++i)
{ {
input[i] = i; input[i] = i;
@ -257,12 +257,12 @@ unittest
unpad(input, PaddingMode.pkcs7, 64); unpad(input, PaddingMode.pkcs7, 64);
assert(input == inputDup); assert(input == inputDup);
defaultAllocator.dispose(input); theAllocator.dispose(input);
defaultAllocator.dispose(inputDup); theAllocator.dispose(inputDup);
} }
{ // ANSI X.923 { // ANSI X.923
auto input = defaultAllocator.makeArray!ubyte(50); auto input = theAllocator.makeArray!ubyte(50);
auto inputDup = defaultAllocator.makeArray!ubyte(50); auto inputDup = theAllocator.makeArray!ubyte(50);
for (ubyte i; i < 40; ++i) for (ubyte i; i < 40; ++i)
{ {
input[i] = i; input[i] = i;
@ -273,7 +273,7 @@ unittest
unpad(input, PaddingMode.pkcs7, 64); unpad(input, PaddingMode.pkcs7, 64);
assert(input == inputDup); assert(input == inputDup);
defaultAllocator.dispose(input); theAllocator.dispose(input);
defaultAllocator.dispose(inputDup); theAllocator.dispose(inputDup);
} }
} }

View File

@ -14,13 +14,8 @@ import std.experimental.allocator;
import std.traits; import std.traits;
import std.typecons : Ternary; import std.typecons : Ternary;
version (unittest)
{
import tanya.memory : defaultAllocator;
}
/** /**
* Allocator interface. * Abstract class implementing a basic allocator.
*/ */
abstract class Allocator : IAllocator abstract class Allocator : IAllocator
{ {
@ -170,16 +165,16 @@ unittest
{ {
int[] p; int[] p;
defaultAllocator.resizeArray(p, 20); theAllocator.resizeArray(p, 20);
assert(p.length == 20); assert(p.length == 20);
defaultAllocator.resizeArray(p, 30); theAllocator.resizeArray(p, 30);
assert(p.length == 30); assert(p.length == 30);
defaultAllocator.resizeArray(p, 10); theAllocator.resizeArray(p, 10);
assert(p.length == 10); assert(p.length == 10);
defaultAllocator.resizeArray(p, 0); theAllocator.resizeArray(p, 0);
assert(p is null); assert(p is null);
} }

View File

@ -12,8 +12,3 @@ module tanya.memory;
public import tanya.memory.allocator; public import tanya.memory.allocator;
public import std.experimental.allocator; public import std.experimental.allocator;
@property IAllocator defaultAllocator()
{
return theAllocator;
}

View File

@ -252,7 +252,7 @@ else version (Windows)
if (result == SOCKET_ERROR && !wouldHaveBlocked) if (result == SOCKET_ERROR && !wouldHaveBlocked)
{ {
throw defaultAllocator.make!SocketException("Unable to receive"); throw theAllocator.make!SocketException("Unable to receive");
} }
return result == 0; return result == 0;
} }
@ -282,7 +282,7 @@ else version (Windows)
if (result == FALSE && !wouldHaveBlocked) if (result == FALSE && !wouldHaveBlocked)
{ {
disconnected_ = true; disconnected_ = true;
throw defaultAllocator.make!SocketException("Unable to receive"); throw theAllocator.make!SocketException("Unable to receive");
} }
if (lpNumber == 0) if (lpNumber == 0)
{ {
@ -324,7 +324,7 @@ else version (Windows)
if (result == SOCKET_ERROR && !wouldHaveBlocked) if (result == SOCKET_ERROR && !wouldHaveBlocked)
{ {
disconnected_ = true; disconnected_ = true;
throw defaultAllocator.make!SocketException("Unable to send"); throw theAllocator.make!SocketException("Unable to send");
} }
return result == 0; return result == 0;
} }
@ -354,7 +354,7 @@ else version (Windows)
if (result == FALSE && !wouldHaveBlocked) if (result == FALSE && !wouldHaveBlocked)
{ {
disconnected_ = true; disconnected_ = true;
throw defaultAllocator.make!SocketException("Unable to receive"); throw theAllocator.make!SocketException("Unable to receive");
} }
return lpNumber; return lpNumber;
} }
@ -396,7 +396,7 @@ else version (Windows)
NULL); NULL);
if (!result == SOCKET_ERROR) if (!result == SOCKET_ERROR)
{ {
throw defaultAllocator.make!SocketException("Unable to retrieve an accept extension function pointer"); throw theAllocator.make!SocketException("Unable to retrieve an accept extension function pointer");
} }
} }
@ -416,7 +416,7 @@ else version (Windows)
auto socket = cast(socket_t) socket(addressFamily, SOCK_STREAM, 0); auto socket = cast(socket_t) socket(addressFamily, SOCK_STREAM, 0);
if (socket == socket_t.init) if (socket == socket_t.init)
{ {
throw defaultAllocator.make!SocketException("Unable to create socket"); throw theAllocator.make!SocketException("Unable to create socket");
} }
scope (failure) scope (failure)
{ {
@ -426,7 +426,7 @@ else version (Windows)
overlapped.handle = cast(HANDLE) socket; overlapped.handle = cast(HANDLE) socket;
overlapped.event = OverlappedSocketEvent.accept; overlapped.event = OverlappedSocketEvent.accept;
overlapped.buffer.len = (sockaddr_in.sizeof + 16) * 2; overlapped.buffer.len = (sockaddr_in.sizeof + 16) * 2;
overlapped.buffer.buf = defaultAllocator.makeArray!char(overlapped.buffer.len).ptr; overlapped.buffer.buf = theAllocator.makeArray!char(overlapped.buffer.len).ptr;
// We don't want to get any data now, but only start to accept the connections // We don't want to get any data now, but only start to accept the connections
BOOL result = acceptExtension(handle_, BOOL result = acceptExtension(handle_,
@ -439,7 +439,7 @@ else version (Windows)
&overlapped.overlapped); &overlapped.overlapped);
if (result == FALSE && !wouldHaveBlocked) if (result == FALSE && !wouldHaveBlocked)
{ {
throw defaultAllocator.make!SocketException("Unable to accept socket connection"); throw theAllocator.make!SocketException("Unable to accept socket connection");
} }
return result == TRUE; return result == TRUE;
} }
@ -459,13 +459,13 @@ else version (Windows)
{ {
scope (exit) scope (exit)
{ {
defaultAllocator.dispose(overlapped.buffer.buf[0..overlapped.buffer.len]); theAllocator.dispose(overlapped.buffer.buf[0..overlapped.buffer.len]);
} }
auto socket = defaultAllocator.make!OverlappedConnectedSocket(cast(socket_t) overlapped.handle, auto socket = theAllocator.make!OverlappedConnectedSocket(cast(socket_t) overlapped.handle,
addressFamily); addressFamily);
scope (failure) scope (failure)
{ {
defaultAllocator.dispose(socket); theAllocator.dispose(socket);
} }
socket.setOption(SocketOptionLevel.SOCKET, socket.setOption(SocketOptionLevel.SOCKET,
cast(SocketOption) SO_UPDATE_ACCEPT_CONTEXT, cast(SocketOption) SO_UPDATE_ACCEPT_CONTEXT,
@ -737,7 +737,7 @@ abstract class Socket
result.ptr, result.ptr,
&length) == SOCKET_ERROR) &length) == SOCKET_ERROR)
{ {
throw defaultAllocator.make!SocketException("Unable to get socket option"); throw theAllocator.make!SocketException("Unable to get socket option");
} }
return length; return length;
} }
@ -797,7 +797,7 @@ abstract class Socket
value.ptr, value.ptr,
cast(uint) value.length) == SOCKET_ERROR) cast(uint) value.length) == SOCKET_ERROR)
{ {
throw defaultAllocator.make!SocketException("Unable to set socket option"); throw theAllocator.make!SocketException("Unable to set socket option");
} }
} }
@ -865,7 +865,7 @@ abstract class Socket
} }
if (fl == SOCKET_ERROR) if (fl == SOCKET_ERROR)
{ {
throw defaultAllocator.make!SocketException("Unable to set socket blocking"); throw theAllocator.make!SocketException("Unable to set socket blocking");
} }
} }
else version (Windows) else version (Windows)
@ -873,7 +873,7 @@ abstract class Socket
uint num = !yes; uint num = !yes;
if (ioctlsocket(handle_, FIONBIO, &num) == SOCKET_ERROR) if (ioctlsocket(handle_, FIONBIO, &num) == SOCKET_ERROR)
{ {
throw defaultAllocator.make!SocketException("Unable to set socket blocking"); throw theAllocator.make!SocketException("Unable to set socket blocking");
} }
blocking_ = yes; blocking_ = yes;
} }
@ -942,7 +942,7 @@ abstract class Socket
{ {
if (.listen(handle_, backlog) == SOCKET_ERROR) if (.listen(handle_, backlog) == SOCKET_ERROR)
{ {
throw defaultAllocator.make!SocketException("Unable to listen on socket"); throw theAllocator.make!SocketException("Unable to listen on socket");
} }
} }
@ -992,7 +992,7 @@ class StreamSocket : Socket, ConnectionOrientedSocket
auto handle = cast(socket_t) socket(af, SOCK_STREAM, 0); auto handle = cast(socket_t) socket(af, SOCK_STREAM, 0);
if (handle == socket_t.init) if (handle == socket_t.init)
{ {
throw defaultAllocator.make!SocketException("Unable to create socket"); throw theAllocator.make!SocketException("Unable to create socket");
} }
super(handle, af); super(handle, af);
} }
@ -1009,7 +1009,7 @@ class StreamSocket : Socket, ConnectionOrientedSocket
{ {
if (.bind(handle_, address.name, address.length) == SOCKET_ERROR) if (.bind(handle_, address.name, address.length) == SOCKET_ERROR)
{ {
throw defaultAllocator.make!SocketException("Unable to bind socket"); throw theAllocator.make!SocketException("Unable to bind socket");
} }
} }
@ -1048,10 +1048,10 @@ class StreamSocket : Socket, ConnectionOrientedSocket
{ {
return null; return null;
} }
throw defaultAllocator.make!SocketException("Unable to accept socket connection"); throw theAllocator.make!SocketException("Unable to accept socket connection");
} }
auto newSocket = defaultAllocator.make!ConnectedSocket(sock, addressFamily); auto newSocket = theAllocator.make!ConnectedSocket(sock, addressFamily);
version (linux) version (linux)
{ // Blocking mode already set { // Blocking mode already set
@ -1066,7 +1066,7 @@ class StreamSocket : Socket, ConnectionOrientedSocket
} }
catch (SocketException e) catch (SocketException e)
{ {
defaultAllocator.dispose(newSocket); theAllocator.dispose(newSocket);
throw e; throw e;
} }
} }
@ -1162,7 +1162,7 @@ class ConnectedSocket : Socket, ConnectionOrientedSocket
return 0; return 0;
} }
disconnected_ = true; disconnected_ = true;
throw defaultAllocator.make!SocketException("Unable to receive"); throw theAllocator.make!SocketException("Unable to receive");
} }
return ret; return ret;
} }
@ -1199,7 +1199,7 @@ class ConnectedSocket : Socket, ConnectionOrientedSocket
{ {
return 0; return 0;
} }
throw defaultAllocator.make!SocketException("Unable to send"); throw theAllocator.make!SocketException("Unable to send");
} }
} }
@ -1242,18 +1242,18 @@ class InternetAddress : Address
{ {
if (getaddrinfoPointer is null || freeaddrinfoPointer is null) if (getaddrinfoPointer is null || freeaddrinfoPointer is null)
{ {
throw defaultAllocator.make!AddressException("Address info lookup is not available on this system"); throw theAllocator.make!AddressException("Address info lookup is not available on this system");
} }
addrinfo* ai_res; addrinfo* ai_res;
port_ = port; port_ = port;
// Make C-string from host. // Make C-string from host.
char[] node = defaultAllocator.makeArray!char(host.length + 1); char[] node = theAllocator.makeArray!char(host.length + 1);
node[0.. $ - 1] = host; node[0.. $ - 1] = host;
node[$ - 1] = '\0'; node[$ - 1] = '\0';
scope (exit) scope (exit)
{ {
defaultAllocator.dispose(node); theAllocator.dispose(node);
} }
// Convert port to a C-string. // Convert port to a C-string.
@ -1278,7 +1278,7 @@ class InternetAddress : Address
auto ret = getaddrinfoPointer(node.ptr, servicePointer, null, &ai_res); auto ret = getaddrinfoPointer(node.ptr, servicePointer, null, &ai_res);
if (ret) if (ret)
{ {
throw defaultAllocator.make!AddressException("Address info lookup failed"); throw theAllocator.make!AddressException("Address info lookup failed");
} }
scope (exit) scope (exit)
{ {
@ -1292,7 +1292,7 @@ class InternetAddress : Address
} }
if (ai_res.ai_family != AddressFamily.INET && ai_res.ai_family != AddressFamily.INET6) if (ai_res.ai_family != AddressFamily.INET && ai_res.ai_family != AddressFamily.INET6)
{ {
throw defaultAllocator.make!AddressException("Wrong address family"); throw theAllocator.make!AddressException("Wrong address family");
} }
} }

View File

@ -148,13 +148,13 @@ version (linux)
/** /**
* Pseudorandom number generator. * Pseudorandom number generator.
* --- * ---
* auto entropy = defaultAllocator.make!Entropy; * auto entropy = theAllocator.make!Entropy;
* *
* ubyte[blockSize] output; * ubyte[blockSize] output;
* *
* output = entropy.random; * output = entropy.random;
* *
* defaultAllocator.finalize(entropy); * theAllocator.finalize(entropy);
* --- * ---
*/ */
class Entropy class Entropy
@ -175,7 +175,7 @@ class Entropy
* allocator = Allocator to allocate entropy sources available on the * allocator = Allocator to allocate entropy sources available on the
* system. * system.
*/ */
this(size_t maxSources = 20, IAllocator allocator = defaultAllocator) this(size_t maxSources = 20, IAllocator allocator = theAllocator)
in in
{ {
assert(maxSources > 0 && maxSources <= ubyte.max); assert(maxSources > 0 && maxSources <= ubyte.max);