1 module memutils.constants; 2 3 package: 4 version(unittest) enum HasUnittests = true; 5 else enum HasUnittests = false; 6 enum { // overhead allocator definitions, lazily loaded 7 NativeGC = 0x01, // instances are freed automatically when no references exist in the program's threads 8 LocklessFreeList = 0x02, // instances are owned by the creating thread thus must be freed by it 9 CryptoSafe = 0x03, // Same as above, but zeroise is called upon freeing 10 } 11 12 enum Mallocator = 0x05; // For use by the DebugAllocator. 13 14 const LogLevel = Debug; 15 version(CryptoSafe) const HasCryptoSafe = true; 16 else const HasCryptoSafe = false; 17 18 /// uses a swap protected pool on top of CryptoSafeAllocator 19 /// otherwise, uses a regular lockless freelist 20 version(SecurePool) const HasSecurePool = true; 21 else const HasSecurePool = false; 22 23 const SecurePool_MLock_Max = 524_287; 24 25 version(Have_botan) const HasBotan = true; 26 else const HasBotan = false; 27 28 version(EnableDebugger) const HasDebuggerEnabled = true; 29 else const HasDebuggerEnabled = false; 30 version(DisableDebugger) const DisableDebugAllocations = true; 31 else const DisableDebugAllocations = false; 32 33 static if (HasDebuggerEnabled && !DisableDebugAllocations ) const HasDebugAllocations = true; 34 else static if (!DisableDebugAllocations && HasUnittests) const HasDebugAllocations = true; 35 else const HasDebugAllocations = false; 36 37 version(SkipMemutilsTests) const SkipUnitTests = true; 38 else const SkipUnitTests = false; 39 40 enum { // LogLevel 41 Trace, 42 Info, 43 Debug, 44 Error, 45 None 46 } 47 48 void logTrace(ARGS...)(ARGS args) { 49 static if (LogLevel <= Trace) { 50 import std.stdio: writeln; 51 writeln("T: ", args); 52 } 53 } 54 55 void logInfo(ARGS...)(ARGS args) { 56 static if (LogLevel <= Info) { 57 import std.stdio: writeln; 58 writeln("I: ", args); 59 } 60 } 61 62 void logDebug(ARGS...)(ARGS args) { 63 64 static if (LogLevel <= Debug) { 65 import std.stdio: writeln; 66 writeln("D: ", args); 67 } 68 } 69 70 void logError(ARGS...)(ARGS args) { 71 static if (LogLevel <= Error) { 72 import std.stdio: writeln, stderr; 73 stderr.writeln("E: ", args); 74 } 75 }