Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > a template-based, DLL-capable classloader

Reply
Thread Tools

a template-based, DLL-capable classloader

 
 
stephan beal
Guest
Posts: n/a
 
      10-28-2003
Good afternoon, C++ers,

(i hope this is not viewed as an advertisement or shameless plug, and i
appologize if it is interpretted that way.)

i have developed a template-based classloader which is capable of loading
from DLLs (on Linux-ish systems, as i have little experience with other
platforms, but the platform-specific code is limited to about 4 lines). i
mention this not the world needs another classloader, but because i think
the model and implementation might be interesting for class template fans,
primarily for it's two main features:

- compile-time type safety even for classes loaded via DLLs (i know nobody's
gonna believe me on that .

- NO casts are necessary, neither client-side nor in the core library.

(Well, okay, and admittedly because it would tickle me pink if someone more
well-versed in class templates than i would have a look at them.

The code is not structurally suitable for pasting into a usenet post, but
the source tree is avaiable here:

http://s11n.net/class_loader/

Caveat: it's only known to build with gcc 3.3x, and known to NOT work with
gcc 2.x. YMMV with other compilers.

(PS: how the no-casts-necessary-type-safety for DLLs is achieved is
explained in the library manual, availabe in PDF/PS/HTML formats at the
above link.)

Take care,

--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.

 
Reply With Quote
 
 
 
 
tom_usenet
Guest
Posts: n/a
 
      10-28-2003
On Tue, 28 Oct 2003 14:00:46 +0100, stephan beal
<(E-Mail Removed)> wrote:

>Good afternoon, C++ers,
>
>(i hope this is not viewed as an advertisement or shameless plug, and i
>appologize if it is interpretted that way.)
>
>i have developed a template-based classloader which is capable of loading
>from DLLs (on Linux-ish systems, as i have little experience with other
>platforms, but the platform-specific code is limited to about 4 lines). i
>mention this not the world needs another classloader, but because i think
>the model and implementation might be interesting for class template fans,
>primarily for it's two main features:
>
>- compile-time type safety even for classes loaded via DLLs (i know nobody's
>gonna believe me on that .
>
>- NO casts are necessary, neither client-side nor in the core library.
>
>(Well, okay, and admittedly because it would tickle me pink if someone more
>well-versed in class templates than i would have a look at them.
>
>The code is not structurally suitable for pasting into a usenet post, but
>the source tree is avaiable here:
>
>http://s11n.net/class_loader/
>
>Caveat: it's only known to build with gcc 3.3x, and known to NOT work with
>gcc 2.x. YMMV with other compilers.
>
>(PS: how the no-casts-necessary-type-safety for DLLs is achieved is
>explained in the library manual, availabe in PDF/PS/HTML formats at the
>above link.)


A quick comment

static int register_factory( const KeyType & key, factory_type factory
= 0 );

could be (to avoid an implementation detail being in the interface):
static void register_factory( const KeyType & key, factory_type
factory = 0);

by using the comma operator at the registration site:

namespace
{
int global = (factory::register_factory(key), 0);
}

It looks nicely documented, but I haven't got a unix system to try it
out on...

Tom
 
Reply With Quote
 
 
 
 
stephan beal
Guest
Posts: n/a
 
      10-28-2003
tom_usenet wrote:
> A quick comment
>
> static int register_factory( const KeyType & key, factory_type factory
> = 0 );
>
> could be (to avoid an implementation detail being in the interface):
> static void register_factory( const KeyType & key, factory_type
> factory = 0);
>
> by using the comma operator at the registration site:
>
> namespace
> {
> int global = (factory::register_factory(key), 0);
> }


Oh, weird!
That's an excellent solution to the problem. i have considered using the int
in cases where a class_registerer<> fails (e.g., in client-supplied
registerers, should someone really feel the need to write one). i'm glad to
now have a way around needing it, though.

> It looks nicely documented,


Thank you . i've spent a lot of time on the docs.

> but I haven't got a unix system to try it
> out on...


And i haven't got a Windows box to port it to . Apparently Cygwin
installations are missing libdl, and i don't know an alternative to using
libdl with dlopen() ("don't know" as in "haven't been doing this very
long", as opposed to "there isn't one").

Thanks for your comments!

--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.

 
Reply With Quote
 
Roger Leigh
Guest
Posts: n/a
 
      10-28-2003
On 2003-10-28, stephan beal <(E-Mail Removed)> wrote:
> tom_usenet wrote:
>> but I haven't got a unix system to try it
>> out on...

>
> And i haven't got a Windows box to port it to . Apparently Cygwin
> installations are missing libdl, and i don't know an alternative to using
> libdl with dlopen() ("don't know" as in "haven't been doing this very
> long", as opposed to "there isn't one").


There's GNU libltdl, part of GNU libtool, which is a
platform-independent libdl abstraction. It wraps LoadLibrary() on
Windows, for example. It probably wouldn't take much effort to use
libltdl, since you just need to change dlopen() to lt_dlopen() etc.. In
the Gimp-Print project (written in C), I allow both to be used, selected
at configure time and just a few #ifdefs to use one or the other.

If you're interested, I can give you pointers to the configure checks
and the module loader code.


--
Roger Leigh

Printing on GNU/Linux? http://gimp-print.sourceforge.net/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
 
Reply With Quote
 
stephan beal
Guest
Posts: n/a
 
      10-29-2003
tom_usenet wrote:
> A quick comment
>
> static int register_factory( const KeyType & key, factory_type factory
> = 0 );
>
> could be (to avoid an implementation detail being in the interface):
> static void register_factory( const KeyType & key, factory_type
> factory = 0);


Just follow up:

Tom, i implemented this last night and it works like a charm. i'm making a
new release today with your name in the credit.

(The hard part was removing all of the documentation which explained the
reason for the bogus int return value!

Thanks again,

--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.

 
Reply With Quote
 
stephan beal
Guest
Posts: n/a
 
      10-29-2003
Roger Leigh wrote:
> There's GNU libltdl, part of GNU libtool, which is a
> platform-independent libdl abstraction. It wraps LoadLibrary() on
> Windows, for example. It probably wouldn't take much effort to use
> libltdl, since you just need to change dlopen() to lt_dlopen() etc.. In
> the Gimp-Print project (written in C), I allow both to be used, selected
> at configure time and just a few #ifdefs to use one or the other.
>
> If you're interested, I can give you pointers to the configure checks
> and the module loader code.


(tried off-list, but it bounced)

Hi, Roger! Yes, any pointers would be wonderful! This is my first time using
dlopen(), so i'm not at all aware what the various alternatives are. A week
or two ago i found libltdl on a Cygwin box (while looking for libdl), but
couldn't figure out if it was related to what i needed or not. :/

Thanks very much in advance,

--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ClassLoader problem Emmanuel PIC Java 3 08-04-2003 09:55 AM
How to find the ClassLoader with a static method ? Philippe Poulard Java 1 07-22-2003 02:32 PM
ClassLoader or Class.newInstance Miguel De Anda Java 1 07-15-2003 07:39 PM
ClassLoader + tomcat read-the-signature@send-spam-to-dev-null.com Java 5 07-15-2003 01:28 PM
classloader in tomcat Mr. Miguel Java 2 07-14-2003 06:18 PM



Advertisments