www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12190] New: runtime loaded shared library on osx: partially worked in 2.062, fails since 2.063

https://d.puremagic.com/issues/show_bug.cgi?id=12190

           Summary: runtime loaded shared library on osx: partially worked
                    in 2.062, fails since 2.063
           Product: D
           Version: D2
          Platform: All
        OS/Version: Mac OS X
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: timothee.cour2 gmail.com



00:44:37 PST ---
Now that issue 11478 is partially fixed (linktime shared libraries), on to
runtime loaded shared libraries:

----
module foo;
import std.stdio;

extern(C) void foo1(){
  printf("ok1\n");
  import core.runtime;
  bool ret=Runtime.initialize(); //is it necessary?
  printf("ret=%d\n",ret);
  printf("ok2\n");
  writeln("ok3");
  int[]a;
  a.length=2; //ok
  writeln(a.length); //dmd2.062 only crashes at this point
}
----
module main2;
import std.stdio, core.sys.posix.dlfcn;
void main(){
  string file="libfoo.dylib";
  auto handle = dlopen(file.ptr, RTLD_LAZY | RTLD_GLOBAL);
  auto funptr = cast(void function()) dlsym(handle, "foo1");
  funptr();
}
----
dmd -oflibfoo.dylib -shared foo.d;
dmd main.d
./main

--output:
2.062:
crashes at writeln(a.length)  (lldb shows it crashes inside LockingTextWriter),
which can still be useful for writing plugins.

git head: crashes upon loading


Also, note that dlopen() of a D shared library works when called from a C++
file, and that a C++ file can call multiple D shared libraries simultaneously
when using RTLD_LAZY option. 

Before waiting for a full solution with an integrated druntime, is there at
least a way to have a separate runtime in each shared library, so that dlopen()
can be called from a D file?

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 18 2014