Re: [HACKERS] using C++ to define new functions - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [HACKERS] using C++ to define new functions
Date
Msg-id 14641.900946091@sss.pgh.pa.us
Whole thread Raw
In response to Re: [HACKERS] using C++ to define new functions  (Michal Mosiewicz <mimo@interdata.com.pl>)
List pgsql-hackers
Michal Mosiewicz <mimo@interdata.com.pl> writes:
> David Gross wrote:
>> but the linking style of c++ is rather different.
>> Do you have an idea ?

> How about using extern "C" {...} ?

I think the major problem here is that David would probably like the
constructors for any global-level variables in his C++ code to be called
when his shared library is loaded into the backend.  (If his C++ code
hasn't got *any* global variables with nontrivial constructors, then
he could maybe survive without this.  But it'd be a necessary part of
a general-purpose solution.)

This is doable.  I routinely use a system that does dynamic loading
of C++ code (Ptolemy, http://ptolemy.eecs.berkeley.edu).  It's fairly
messy and unportable however, because you have to be aware of the
machine-and-compiler-dependent conventions for naming and finding
the global constructors.

David would probably also want to link the C++ library into the backend
(as a shared library, otherwise the linker will optimize it away) so
that his shared library doesn't need to include C++ library routines.
There might be a few other little changes to make in the link that
builds the backend.

In short, this could be supported if we wanted to invest a sufficient
amount of effort in it.  I'm not sure it's worth the trouble.

            regards, tom lane

pgsql-hackers by date:

Previous
From: darcy@druid.net (D'Arcy J.M. Cain)
Date:
Subject: Finding primary keys in a table
Next
From: "Gene Selkov, Jr."
Date:
Subject: Re: [GENERAL] Recalling previous commands at the PSQL prompt