a template-based, DLL-capable classloader

Discussion in 'C++' started by stephan beal, Oct 28, 2003.

  1. stephan beal

    stephan beal Guest

    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.
     
    stephan beal, Oct 28, 2003
    #1
    1. Advertising

  2. stephan beal

    tom_usenet Guest

    On Tue, 28 Oct 2003 14:00:46 +0100, stephan beal
    <> 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
     
    tom_usenet, Oct 28, 2003
    #2
    1. Advertising

  3. stephan beal

    stephan beal Guest

    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.
     
    stephan beal, Oct 28, 2003
    #3
  4. stephan beal

    Roger Leigh Guest

    On 2003-10-28, stephan beal <> 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.
     
    Roger Leigh, Oct 28, 2003
    #4
  5. stephan beal

    stephan beal Guest

    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.
     
    stephan beal, Oct 29, 2003
    #5
  6. stephan beal

    stephan beal Guest

    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.
     
    stephan beal, Oct 29, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ramon
    Replies:
    1
    Views:
    388
    Ramon F Herrera
    Apr 3, 2005
  2. kizuna
    Replies:
    0
    Views:
    2,001
    kizuna
    Apr 21, 2005
  3. -
    Replies:
    3
    Views:
    471
    Thomas Fritsch
    Jul 24, 2005
  4. sushil
    Replies:
    3
    Views:
    510
    Andrew Thompson
    Sep 27, 2005
  5. Replies:
    2
    Views:
    1,154
Loading...

Share This Page