Bug 4593 – (DMD 2.047) Access Violation in unittest build

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2010-08-07T08:14:00Z
Last change time
2010-08-11T04:54:30Z
Assigned to
nobody
Creator
adrian

Comments

Comment #0 by adrian — 2010-08-07T08:14:50Z
Hi, I encountered a strange problem that appears when I build my project with -unittest switch on. The executable fails giving a message "object.Error: Access Violation", despite that without "-unittest" it works correctly. I tried to successively cut different parts of code to find a source of problem, and I came up with an example which may be close to a minimal one. It consists of two files, "a.d": ------------------------- import std.string; import std.stdio; static string foo(string path) { auto strs = path.split("."); return strs.length ? strs[$ - 1] : ""; } ------------------------- and "b.d": ------------------------- import std.stdio; import a; void main() { writeln("Hello, world!"); } ------------------------- Compile it using: dmd -oftest.exe -unittest a.d b.d and then launch it, and you'll see the "Access violation" message. However, when you drop -unittest switch, or replace `path.split(".")' with, for example, `[ "" ]', or merge both sources together into a single source file, the program displays "Hello, world!" as expected. I have no idea what could be the actual source of problem, but I hope the example can help fixing it. Regards, Adrian Matoga
Comment #1 by andrej.mitrovich — 2010-08-07T11:32:05Z
I can't reproduce this on XP SP3, the output is fine for me: b.d -------------------------------- import std.stdio; import a; void main() { writeln("Hello, world!"); writeln(foo("some.path")); } -------------------------------- a.d -------------------------------- import std.string; import std.stdio; static string foo(string path) { auto strs = path.split("."); return strs.length ? strs[$ - 1] : ""; } -------------------------------- C:\Test>dmd -oftest.exe -unittest a.d b.d C:\Test>test Hello, world! path Same thing when using a unittest block in b.d.
Comment #2 by adrian — 2010-08-07T12:47:35Z
Mhm, on XP SP3 it works fine for me also. But on Win7 (x86_64)
Comment #3 by andrej.mitrovich — 2010-08-07T12:50:29Z
I'm not sure if DMD is fully supported on x64 yet(?) Someone else will have to fill in.
Comment #4 by adrian — 2010-08-07T13:44:35Z
Hmm, this seems to be a lot more subtle thing. Could you try the following: image.d: -------------------- import std.string; import std.contracts; import std.conv; interface Image { static Image open(string path, string type, bool readOnly = true) { auto img = newObj(path, type); img.openImpl(path, readOnly); return img; } static Image open(string path, bool readOnly = true) { return open(path, autoType(path), readOnly); } protected: void openImpl(string path, bool readOnly); private: static Image newObj(string path, string type) { auto image = cast(Image) Object.factory(tolower(type) ~ "." ~ capitalize(type) ~ "Image"); version (unittest) { if (image is null) image = cast(Image) Object.factory("image." ~ capitalize(type) ~ "Image"); } enforce(image, "Unknown image format: " ~ type); return image; } static string autoType(string path) { auto sp = path.split("."); return sp.length ? sp[$ - 1] : ""; } } -------------------- main.d -------------------- import std.stdio; void main() { writeln("Hello world!"); } -------------------- dmd -oftest.exe -unittest main.d image.d For me, this also fails on XP SP3 (x86).
Comment #5 by andrej.mitrovich — 2010-08-07T14:00:10Z
You forgot to put an import to image in main.d . Without it, I'll get that object error thing. Otherwise, this will work fine: import image; import std.stdio; void main() { writeln("Hello world!"); }
Comment #6 by adrian — 2010-08-11T04:54:30Z
Seems like it's fixed now with 2.048.