Skip to content

Commit

Permalink
Merge pull request #274 from schveiguy/fixfloattransmit
Browse files Browse the repository at this point in the history
Wrong range of data to write. This happened on the unsafe to safe
  • Loading branch information
schveiguy authored Jan 20, 2023
2 parents b9112f6 + 2894f06 commit 0ea6cb3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
41 changes: 26 additions & 15 deletions source/mysql/logger.d
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion source/mysql/protocol/comms.d
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions source/mysql/protocol/sockets.d
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -93,7 +93,7 @@ class MySQLSocketPhobos : MySQLSocket
}
}

void write(in ubyte[] bytes)
void write(const scope ubyte[] bytes)
{
socket.send(bytes);
}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 0ea6cb3

Please sign in to comment.