Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading classes in runtime #17601

Open
dlangBugzillaToGithub opened this issue Jul 26, 2013 · 2 comments
Open

Loading classes in runtime #17601

dlangBugzillaToGithub opened this issue Jul 26, 2013 · 2 comments

Comments

@dlangBugzillaToGithub
Copy link

Roman reported this on 2013-07-26T17:37:00Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=10719

CC List

  • Steve Teale

Description

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;
}
@dlangBugzillaToGithub
Copy link
Author

ssteale commented on 2014-03-14T04:54:38Z

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.

@dlangBugzillaToGithub
Copy link
Author

ssteale commented on 2014-03-14T05:23:13Z

Checked with code included in bug report - OK with 2.064 64 bit - fails with 32 bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant