www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Shared objects?

reply Wouter Verhelst <wouter grep.be> writes:
Hi group,

I've been reading up on D for the past few days--something I'd been
planning to do for quite a while--and find much to like and little to
dislike; as such, I am considering using it for my next project, which
would run on Linux (and possibly some other POSIX systems) and would
need to load plugins.

Now I've done such things in C in the past, and it's not too difficult:
you create a .so file, have it call some initial function right after
the dlopen(), and then have that initial function register the new
functionality available.

After looking at the documentation for a few days, I've come to the
conclusion that with Object.factory and interfaces, I believe I can
abstract things enough so that all a plugin would need to do is register
a new class, which could then be instantiated if needs be. However, what
I don't find is the answer to the two following questions:

- Does D support dlopen(), or some similar mechanism, to allow me to
  load plugins at runtime?
- If it does, does Object.factory() still work for new classes loaded in
  through dlopen() (or its functional equivalence)?

Thanks,

-- 
The volume of a pizza of thickness a and radius z can be described by
the following formula:

pi zz a
Jun 18 2012
next sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2012-06-18 16:56, Wouter Verhelst wrote:
 Hi group,

 I've been reading up on D for the past few days--something I'd been
 planning to do for quite a while--and find much to like and little to
 dislike; as such, I am considering using it for my next project, which
 would run on Linux (and possibly some other POSIX systems) and would
 need to load plugins.

 Now I've done such things in C in the past, and it's not too difficult:
 you create a .so file, have it call some initial function right after
 the dlopen(), and then have that initial function register the new
 functionality available.

 After looking at the documentation for a few days, I've come to the
 conclusion that with Object.factory and interfaces, I believe I can
 abstract things enough so that all a plugin would need to do is register
 a new class, which could then be instantiated if needs be.

Yes, in theory.
 However, what
 I don't find is the answer to the two following questions:

 - Does D support dlopen(), or some similar mechanism, to allow me to
    load plugins at runtime?

Yes. You can compile D code to a standard dynamic library, just as you would using C.
 - If it does, does Object.factory() still work for new classes loaded in
    through dlopen() (or its functional equivalence)?

No. Dynamic libraries are currently not working properly in D. The runtime needs to be updated to handle it. There are some problem with module info, exception handling tables and TLS. There might be some problem left with PIC as well. This is worked on and hopefully we will have a solution not too far in the future. -- /Jacob Carlborg
Jun 18 2012
parent Jacob Carlborg <doob me.com> writes:
On 2012-06-20 09:50, R. Grocott wrote:
 I'm not too experienced with Github - am I right in thinking that
 the SharedRuntime repository has been idle for six months? If so,
 does this indicate that Martin has likely abandoned the project?

The last commit was three months ago, Mars 20, 2012: https://github.com/dawgfoto/druntime/commits/SharedRuntime
 Like Wouter, I'm looking into developing a project with D that
 would eventually require plugins, and I could really do with a
 definite answer whether or not this functionality is expected to
 be available within, say, twelve months. Is there anybody I could
 contact who's likely to know the answer?

Yes, I think it will be available within twelve months.
 One last question - when you say that the runtime can't yet
 properly handle dynamic library loading, does this apply equally
 to both DMD and GDC? I know that both projects share a fair
 amount of common code.

I think it applies to GDC as well. Unless GDC uses its own fork of the runtime and have fixes for this. Note that you can load dynamic libraries wirtten in C. It probably works with D as well, just not all features. What probably will not work are: * Module constructors * Module info * Exceptions (not sure about this, might just be limited to crossing dynamic library boundaries) * TLS * Probably some other stuff I've forgotten -- /Jacob Carlborg
Jun 20 2012
prev sibling next sibling parent Wouter Verhelst <wouter grep.be> writes:
Jacob Carlborg <doob me.com> writes:

 On 2012-06-18 16:56, Wouter Verhelst wrote:
 However, what
 I don't find is the answer to the two following questions:

 - Does D support dlopen(), or some similar mechanism, to allow me to
    load plugins at runtime?

Yes. You can compile D code to a standard dynamic library, just as you would using C.

Cool.
 - If it does, does Object.factory() still work for new classes loaded in
    through dlopen() (or its functional equivalence)?

No. Dynamic libraries are currently not working properly in D. The runtime needs to be updated to handle it. There are some problem with module info, exception handling tables and TLS. There might be some problem left with PIC as well. This is worked on and hopefully we will have a solution not too far in the future.

Ah, too bad. Do you have a pointer to some more detailed information on this? Just so I can get a feel for how fast things are moving, and/or whether it's worth for me to wait for that -- I can get started on the other parts; while the plugin architecture would be crucial eventually, it's not something I'll need from the very beginning. Thanks, -- The volume of a pizza of thickness a and radius z can be described by the following formula: pi zz a
Jun 18 2012
prev sibling next sibling parent "Jacob Carlborg" <doob me.com> writes:
On Monday, 18 June 2012 at 15:22:19 UTC, Wouter Verhelst wrote:

 Ah, too bad.

 Do you have a pointer to some more detailed information on 
 this? Just so
 I can get a feel for how fast things are moving, and/or whether 
 it's
 worth for me to wait for that -- I can get started on the other 
 parts;
 while the plugin architecture would be crucial eventually, it's 
 not
 something I'll need from the very beginning.

 Thanks,

Martin Nowak is working on this: https://github.com/dawgfoto/druntime/tree/SharedRuntime -- /Jacob Carlborg
Jun 18 2012
prev sibling parent "R. Grocott" <rgrocottbugzilla gmail.com> writes:
I'm not too experienced with Github - am I right in thinking that
the SharedRuntime repository has been idle for six months? If so,
does this indicate that Martin has likely abandoned the project?

Like Wouter, I'm looking into developing a project with D that
would eventually require plugins, and I could really do with a
definite answer whether or not this functionality is expected to
be available within, say, twelve months. Is there anybody I could
contact who's likely to know the answer?

One last question - when you say that the runtime can't yet
properly handle dynamic library loading, does this apply equally
to both DMD and GDC? I know that both projects share a fair
amount of common code.
Jun 20 2012