From dd2ab7af1d3df8473d99867238032f8f4ebb158f Mon Sep 17 00:00:00 2001 From: Steven Schveighoffer Date: Thu, 19 Jan 2023 21:33:40 -0500 Subject: [PATCH 1/3] Wrong range of data to write. This happened on the unsafe to safe change, and just was never tested. Recently hit this. --- source/mysql/protocol/comms.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/mysql/protocol/comms.d b/source/mysql/protocol/comms.d index 2f23adb0..a40d901e 100644 --- a/source/mysql/protocol/comms.d +++ b/source/mysql/protocol/comms.d @@ -251,7 +251,7 @@ package struct ProtocolPrepared reAlloc(8); double[1] d = isRef? *v.get!DoubleRef : v.get!Double; ubyte[] uba = cast(ubyte[]) d[]; - vals[vcl .. uba.length] = uba[]; + vals[vcl .. vcl + uba.length] = uba[]; vcl += uba.length; break; case DateRef: From d14f6a7c1514f01ae660692cedc69fb48f9bcd81 Mon Sep 17 00:00:00 2001 From: Steven Schveighoffer Date: Thu, 19 Jan 2023 22:22:19 -0500 Subject: [PATCH 2/3] fix logger failures. --- source/mysql/logger.d | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/source/mysql/logger.d b/source/mysql/logger.d index 49d165ce..7e134ae5 100644 --- a/source/mysql/logger.d +++ b/source/mysql/logger.d @@ -34,17 +34,23 @@ version(Have_vibe_core) { alias logError = vibe.core.log.logError; alias logCritical = vibe.core.log.logCritical; //alias logFatal = vibe.core.log.logFatal; -} else static if(__traits(compiles, (){ import std.experimental.logger; } )) { - import std.experimental.logger; - - alias logTrace = std.experimental.logger.tracef; - alias logDebug = std.experimental.logger.tracef; // no debug level in std.experimental.logger but arguably trace/debug/verbose all mean the same - alias logInfo = std.experimental.logger.infof; - alias logWarn = std.experimental.logger.warningf; - alias logError = std.experimental.logger.errorf; - alias logCritical = std.experimental.logger.criticalf; - //alias logFatal = std.experimental.logger.fatalf; -} else static assert(false); +} else { + static if(__traits(compiles, (){ import std.experimental.logger; } )) { + import stdlog = std.experimental.logger; + } else static if(__traits(compiles, (){ import std.logger; })) { + import stdlog = std.logger; + } else { + static assert(false, "no std.logger detected"); + } + + alias logTrace = stdlog.tracef; + alias logDebug = stdlog.tracef; // no debug level in stdlog but arguably trace/debug/verbose all mean the same + alias logInfo = stdlog.infof; + alias logWarn = stdlog.warningf; + alias logError = stdlog.errorf; + alias logCritical = stdlog.criticalf; + //alias logFatal = stdlog.fatalf; +} unittest { version(Have_vibe_core) { @@ -59,18 +65,18 @@ unittest { logError("Test that a call to mysql.logger.logError maps to vibe.core.log.logError"); logCritical("Test that a call to mysql.logger.logCritical maps to vibe.core.log.logCritical"); //logFatal("Test that a call to mysql.logger.logFatal maps to vibe.core.log.logFatal"); - } else static if(__traits(compiles, (){ import std.experimental.logger; } )) { + } else { // Checks that when using std.experimental.logger the log entry is correct. // This test kicks in when commenting out the 'vibe-core' dependency and running 'dub test', although // not ideal if vibe-core is availble the logging goes through vibe anyway. // Output can be seen in terminal when running 'dub test'. - import std.experimental.logger : Logger, LogLevel, sharedLog; import std.stdio : writeln, writefln; import std.conv : to; writeln("Running the logger tests using (std.experimental.logger)"); + alias LogLevel = stdlog.LogLevel; - class TestLogger : Logger { + class TestLogger : stdlog.Logger { LogLevel logLevel; string file; string moduleName; @@ -91,7 +97,12 @@ unittest { } auto logger = new TestLogger(LogLevel.all); - sharedLog = logger; + // handle differences between std.experimental.logger and std.logger + alias LogType = typeof(stdlog.sharedLog()); + static if(is(LogType == shared)) + stdlog.sharedLog = (() @trusted => cast(shared)logger)(); + else + stdlog.sharedLog = logger; // check that the various log alias functions get the expected results logDebug("This is a TRACE message"); From 2894f06a805f5bd07787167a0aeddd7dad5efc12 Mon Sep 17 00:00:00 2001 From: Steven Schveighoffer Date: Thu, 19 Jan 2023 23:45:56 -0500 Subject: [PATCH 3/3] Fix socket scope issues (preparing for dip1000) --- source/mysql/protocol/sockets.d | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/mysql/protocol/sockets.d b/source/mysql/protocol/sockets.d index a9b2468d..a582fc93 100644 --- a/source/mysql/protocol/sockets.d +++ b/source/mysql/protocol/sockets.d @@ -40,7 +40,7 @@ interface MySQLSocket void close(); @property bool connected() const; void read(ubyte[] dst); - void write(in ubyte[] bytes); + void write(const scope ubyte[] bytes); void acquire(); void release(); @@ -93,7 +93,7 @@ class MySQLSocketPhobos : MySQLSocket } } - void write(in ubyte[] bytes) + void write(const scope ubyte[] bytes) { socket.send(bytes); } @@ -143,7 +143,7 @@ version(Have_vibe_core) { socket.read(dst); } - void write(in ubyte[] bytes) + void write(const scope ubyte[] bytes) { socket.write(bytes); }