D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10719 - Loading classes in runtime
Summary: Loading classes in runtime
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Linux
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-26 17:37 UTC by Roman
Modified: 2024-12-13 18:09 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Roman 2013-07-26 17:37:00 UTC
There is kinda plugin here (code is for linux or other posix system with dlfcn)
Why does it crush when using interface instead of abstract class? (-version=inter)

//dinter.d
module dinter;

version(inter) {
    pragma(msg, "Using interface");
    interface Dinter {
        int foo(int a, int b);
    }
}
else {
    pragma(msg, "Using abstract class");
    abstract class Dinter {
        int foo(int a, int b);
    }
}

//dimpl.d
//dmd -shared -fPIC dimpl.d dinter.d -oflibdimpl.so
//dmd -shared -fPIC dimpl.d dinter.d -oflibdimpl.so -verstion=inter
module dimpl;
import dinter;

class Dimpl : Dinter {
    override int foo(int a, int b) {
        return a+b;
    }
}
extern(C) Dinter create() {
    return new Dimpl;
}

//dmain.d
//dmd dmain.d -L-rpath=. -L-ldl
//dmd dmain.d -L-rpath=. -L-ldl -version=inter

import dinter;
import std.c.linux.linux;
import std.string : toStringz;

alias extern(C) Dinter function() CreateFn;

int main(string[] args) {
    void* lib = dlopen(toStringz("./libdimpl.so"), RTLD_LAZY);
    assert(lib);
    auto create = cast(CreateFn)dlsym(lib, toStringz("create"));
    assert(create);
    Dinter d = create();
    assert(d.foo(3,7)==10);
    return 0;
}
Comment 1 Steve Teale 2014-03-14 04:54:38 UTC
This does not appear to be an all platforms issue. I have similar code and mine appears to work on a 64 bit system and fail on 32 bit, which in some ways is more serious.
Comment 2 Steve Teale 2014-03-14 05:23:13 UTC
Checked with code included in bug report - OK with 2.064 64 bit - fails with 32 bit.
Comment 3 dlangBugzillaToGithub 2024-12-13 18:09:52 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/17601

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB