digitalmars.D.bugs - [Issue 348] New: string concat in dynamically loaded dll code crashes program
- d-bugmail puremagic.com Sep 14 2006
- d-bugmail puremagic.com Sep 14 2006
- Sean Kelly <sean f4.ca> Sep 14 2006
- d-bugmail puremagic.com Jun 25 2008
http://d.puremagic.com/issues/show_bug.cgi?id=348 Summary: string concat in dynamically loaded dll code crashes program Product: D Version: 0.165 Platform: PC OS/Version: Windows Status: NEW Severity: major Priority: P2 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: default_357-line yahoo.de A string concat in a dynamically loaded C linkage function crashes the program with a SIGSEGV in _d_new (wtf) Files: _dll.d_ extern (C) { void test(char[] str) { char[] e=str~"bla"; } } _test.d_ import std.c.windows.windows; void main() { auto func=cast(void function(char[])) GetProcAddress(LoadLibraryA("dll.dll"), "test"); func("Bla bla bla "); } On gdcwin 0.19, this crashes with a SIGSEGV trying to access 0x0. The stack trace is: #0 0x610c1adb in _d_new () #1 0x610c1289 in _d_arraycatn () #2 0x610c1214 in test (str={length = 12, ptr = 0x41d00d "Bla bla bla "}) at dll.d:1 #3 0x00401321 in _Dmain () at quick.d:5 #4 0x004013df in _d_run_main2goFZv () #5 0x004014e4 in _d_run_main () #6 0x00401363 in main () --
Sep 14 2006
http://d.puremagic.com/issues/show_bug.cgi?id=348 ------- Comment #1 from default_357-line yahoo.de 2006-09-14 16:09 ------- (In reply to comment #0)Files: _dll.d_ extern (C) { void test(char[] str) { char[] e=str~"bla"; } } _test.d_
a) dmd generates an access error. b) Compile the first file into a dll with -Wl,--dll and -shared, and the second file into an executable normally. --
Sep 14 2006
d-bugmail puremagic.com wrote:A string concat in a dynamically loaded C linkage function crashes the program with a SIGSEGV in _d_new (wtf) Files: _dll.d_ extern (C) { void test(char[] str) { char[] e=str~"bla"; } } _test.d_ import std.c.windows.windows; void main() { auto func=cast(void function(char[])) GetProcAddress(LoadLibraryA("dll.dll"), "test"); func("Bla bla bla "); }
Given the above code, I think this is to be expected. See this link for a description of what must be done to produce a dynamic library in D: http://www.digitalmars.com/d/dll.html Basically, you must initialize the D compiler runtime, the garbage collector, and call module ctors when the library is loaded. The current method for doing this kind of stinks, but it wouldn't be terribly difficult to improve.
Sep 14 2006
http://d.puremagic.com/issues/show_bug.cgi?id=348 bugzilla digitalmars.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALID ------- Comment #3 from bugzilla digitalmars.com 2008-06-25 04:18 ------- Sean is correct. Also, dmd doesn't have flags -Wl,--dll and -shared. --
Jun 25 2008









d-bugmail puremagic.com 