digitalmars.D.learn - Corruption Rant update
- Jesse Phillips (72/72) May 26 2011 So I've had some time to reduce my code it the smallest kernel I could m...
- Jesse Phillips (3/4) May 26 2011
So I've had some time to reduce my code it the smallest kernel I could make. Unfortunately it still relies on a dll I can't distribute, so I'd need to see if I could create one that could be used to cause the issue (I wasn't able to use just any function from within the dll). This is a reduction of a little bit different problem then the last one (It isn't crashing from just checking if the object is null). I've left many comments on what changes make the access violation disappear, and they don't require combination just making the one change fixes it without other modification. This has got to be a code generation issue, and I'll probably have to look at the ASM. pragma(lib, "libs\\lua51.lib"); import std.datetime; import std.conv; import std.exception; import std.file; import std.format; import std.process; import std.stdio; import std.string; import core.stdc.stdlib; import dllstuff : dll; import luad.all; import luad.c.all; class MyClass { void updateStatus(string msg) { writeln(msg); } } struct MyStruct { // string[] sa; // Uncommenting fixes issue } LuaState setupLua(MyStruct m) { // Must take a struct, class works auto L = luaL_newstate(); auto lua = new LuaState(L); lua.openLibs(); return lua; } void main(string[] args) { MyStruct ms; auto someclass = new MyClass(); auto dg = () {// Works outside the delegate // creating the session after creating lua fixes it auto session = dllmanager("company.dll", "MyH"); auto lua = setupLua(ms);// Must contruct lua from other function someclass.updateStatus("start loading"); // removal fixes it session.load(r"path to file"); // can't be just any function from the dll writeln("Done with loading"); writeln(someclass is null); // This one isn't failing, prints false // Causes access violation for some reason someclass.updateStatus("message"); // removal fixes it writeln("message"); }; dg(); } DllWrapper dllmanager(string dllFile, string nickname) { DllWrapper rt = new DllWrapper(); rt.nickname = nickname; // Using a dll loader found on SO // Separate file sets up functions which can be // called directly on the dll object if(!dll) dll = new typeof(dll)(dllFile); auto err = dll.Init(); // May not be needed but the dllmanager seems to hold these things. auto value = cast(char*)malloc(char.sizeof * nickname.length); value[0..nickname.length] = nickname[]; err = dll.RuntimeNew(&rt.handle, value, 0); return rt; } final class DllWrapper { private: string nickname; uint handle; public: void load(string path) { enforce(exists(path)); char* errMsg; auto err = dll.ReadFiles(handle, toStringz(path), &errMsg); } }
May 26 2011
Oh, but now that I have it is so small I can compile it with debug symbols on Yay. Jesse Phillips Wrote:So I've had some time to reduce my code it the smallest kernel I could make. Unfortunately it still relies on a dll I can't distribute, so I'd need to see if I could create one that could be used to cause the issue (I wasn't able to use just any function from within the dll).
May 26 2011