Skip to content

Commit 0ea6cb3

Browse files
authored
Merge pull request #274 from schveiguy/fixfloattransmit
Wrong range of data to write. This happened on the unsafe to safe
2 parents b9112f6 + 2894f06 commit 0ea6cb3

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

source/mysql/logger.d

+26-15
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,23 @@ version(Have_vibe_core) {
3434
alias logError = vibe.core.log.logError;
3535
alias logCritical = vibe.core.log.logCritical;
3636
//alias logFatal = vibe.core.log.logFatal;
37-
} else static if(__traits(compiles, (){ import std.experimental.logger; } )) {
38-
import std.experimental.logger;
39-
40-
alias logTrace = std.experimental.logger.tracef;
41-
alias logDebug = std.experimental.logger.tracef; // no debug level in std.experimental.logger but arguably trace/debug/verbose all mean the same
42-
alias logInfo = std.experimental.logger.infof;
43-
alias logWarn = std.experimental.logger.warningf;
44-
alias logError = std.experimental.logger.errorf;
45-
alias logCritical = std.experimental.logger.criticalf;
46-
//alias logFatal = std.experimental.logger.fatalf;
47-
} else static assert(false);
37+
} else {
38+
static if(__traits(compiles, (){ import std.experimental.logger; } )) {
39+
import stdlog = std.experimental.logger;
40+
} else static if(__traits(compiles, (){ import std.logger; })) {
41+
import stdlog = std.logger;
42+
} else {
43+
static assert(false, "no std.logger detected");
44+
}
45+
46+
alias logTrace = stdlog.tracef;
47+
alias logDebug = stdlog.tracef; // no debug level in stdlog but arguably trace/debug/verbose all mean the same
48+
alias logInfo = stdlog.infof;
49+
alias logWarn = stdlog.warningf;
50+
alias logError = stdlog.errorf;
51+
alias logCritical = stdlog.criticalf;
52+
//alias logFatal = stdlog.fatalf;
53+
}
4854

4955
unittest {
5056
version(Have_vibe_core) {
@@ -59,18 +65,18 @@ unittest {
5965
logError("Test that a call to mysql.logger.logError maps to vibe.core.log.logError");
6066
logCritical("Test that a call to mysql.logger.logCritical maps to vibe.core.log.logCritical");
6167
//logFatal("Test that a call to mysql.logger.logFatal maps to vibe.core.log.logFatal");
62-
} else static if(__traits(compiles, (){ import std.experimental.logger; } )) {
68+
} else {
6369
// Checks that when using std.experimental.logger the log entry is correct.
6470
// This test kicks in when commenting out the 'vibe-core' dependency and running 'dub test', although
6571
// not ideal if vibe-core is availble the logging goes through vibe anyway.
6672
// Output can be seen in terminal when running 'dub test'.
67-
import std.experimental.logger : Logger, LogLevel, sharedLog;
6873
import std.stdio : writeln, writefln;
6974
import std.conv : to;
7075

7176
writeln("Running the logger tests using (std.experimental.logger)");
77+
alias LogLevel = stdlog.LogLevel;
7278

73-
class TestLogger : Logger {
79+
class TestLogger : stdlog.Logger {
7480
LogLevel logLevel;
7581
string file;
7682
string moduleName;
@@ -91,7 +97,12 @@ unittest {
9197
}
9298

9399
auto logger = new TestLogger(LogLevel.all);
94-
sharedLog = logger;
100+
// handle differences between std.experimental.logger and std.logger
101+
alias LogType = typeof(stdlog.sharedLog());
102+
static if(is(LogType == shared))
103+
stdlog.sharedLog = (() @trusted => cast(shared)logger)();
104+
else
105+
stdlog.sharedLog = logger;
95106

96107
// check that the various log alias functions get the expected results
97108
logDebug("This is a TRACE message");

source/mysql/protocol/comms.d

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ package struct ProtocolPrepared
251251
reAlloc(8);
252252
double[1] d = isRef? *v.get!DoubleRef : v.get!Double;
253253
ubyte[] uba = cast(ubyte[]) d[];
254-
vals[vcl .. uba.length] = uba[];
254+
vals[vcl .. vcl + uba.length] = uba[];
255255
vcl += uba.length;
256256
break;
257257
case DateRef:

source/mysql/protocol/sockets.d

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ interface MySQLSocket
4040
void close();
4141
@property bool connected() const;
4242
void read(ubyte[] dst);
43-
void write(in ubyte[] bytes);
43+
void write(const scope ubyte[] bytes);
4444

4545
void acquire();
4646
void release();
@@ -93,7 +93,7 @@ class MySQLSocketPhobos : MySQLSocket
9393
}
9494
}
9595

96-
void write(in ubyte[] bytes)
96+
void write(const scope ubyte[] bytes)
9797
{
9898
socket.send(bytes);
9999
}
@@ -143,7 +143,7 @@ version(Have_vibe_core) {
143143
socket.read(dst);
144144
}
145145

146-
void write(in ubyte[] bytes)
146+
void write(const scope ubyte[] bytes)
147147
{
148148
socket.write(bytes);
149149
}

0 commit comments

Comments
 (0)