public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "John (Eljay) Love-Jensen" <eljay@adobe.com>
To: "Kumar Bhaskar" <akumargolf2000@yahoo.com>
Cc: <gcc-help@gcc.gnu.org>
Subject: RE: Sub lib compatibility with g++
Date: Mon, 17 Dec 2007 00:24:00 -0000	[thread overview]
Message-ID: <EDC8DDD212FEB34C884CBB0EE8EC2D91081F68ED@namailgen.corp.adobe.com> (raw)
In-Reply-To: <271051.85458.qm@web46004.mail.sp1.yahoo.com>

Hi Kumar,

> Do you think this will work out ?

It can work.  It won't be fun.

> One other aspect I am concerned about is that with the above, myprog will eventually make use of both the gcc C++ runtime and the Sun C++ runtime (via the two MODULES A and B which respectively call into libs libA.so and libB.so).  Do you see any issues with that ?

The key issue is making sure that symbols are properly bound, such that the Sun C++ only binds to Sun C++ symbols by the loader, and GCC C++ only binds to GCC C++ symbols by the loader.

Another solution is to use separate processes, and then communicate to the Sun C++ "slave" process (assuming that's the one you'd make slave) through RPC or IPC or a listening socket.  That makes for a very clean demarcation between the GCC C++ process and the Sun C++ process.

> Also - do you know of any good examples and/or web resources that demonstrate how the "thunking" libs. should be created and provide more info. on the details ?

No, I'm not sure.

I learned it by working with Netwise RPC technology, before Microsoft acquired them.

Another good example of providing an opaque C interface to an object-oriented implementation is Apple's Carbon.  X11 is also a good example of object-oriented design, implemented in C (which could have been written in C++ -- maybe it is in some implementations).

If you only have one top level class to expose, say SunFoo...

class SunFoo
{
public:
    SunFoo();
    ~SunFoo();
    void DoSomething();
    void OtherSomething(std::string const&);
};

...you're thunking C interface will have to provide...

Initialize();
Terminate();
int ExceptionOccurred();
typedef struct OpaqueSunFoo* SunFoo_t;
SunFoo_t SunFooConstruct();
void SunFooDestruct(SunFoo_t);
void SunFooDoSomething(SunFoo_t);
void SunFooOtherSomething(SunFoo_t, char const*);

You'll need to have a "cookie" that represents a SunFoo on the GCC side.  Something like "typedef struct OpaqueSunFoo* SunFoo_t" can work well.

You'll need to "revive" all C-style parms into the SunFoo's C++ object parms.

You'll need to carefully manage memory allocation so the right side of the fence has ownership & responsibility to delete/free things.

You'll need to catch all exceptions and have some facility to query if an exception occurred.

If your Sun C++ has lots and lots of objects and methods that you want to expose... then that can be a considerable (and very unpleasant) challenge.

HTH,
--Eljay

  reply	other threads:[~2007-12-17  0:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-16 23:52 Kumar Bhaskar
2007-12-17  0:24 ` John (Eljay) Love-Jensen [this message]
  -- strict thread matches above, loose matches on Subject: below --
2007-12-16  8:20 Kumar Bhaskar
2007-12-16 14:18 ` John (Eljay) Love-Jensen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=EDC8DDD212FEB34C884CBB0EE8EC2D91081F68ED@namailgen.corp.adobe.com \
    --to=eljay@adobe.com \
    --cc=akumargolf2000@yahoo.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).