Re: server-side extension in c++ - Mailing list pgsql-general

From Craig Ringer
Subject Re: server-side extension in c++
Date
Msg-id 4BA99185.5030304@postnewspapers.com.au
Whole thread Raw
In response to server-side extension in c++  (Igor <igor@carcass.ath.cx>)
Responses Re: server-side extension in c++  (Bruce Momjian <bruce@momjian.us>)
List pgsql-general
Igor wrote:
> Hi All,
>
> Is there an easy way to add c++ files to my simple pgsql module ? My Makefile
> is as follows -
>
> ===
> MODULES = pg_uservars
> DATA_built = pg_uservars.sql
> PGXS := $(shell pg_config --pgxs)
> include $(PGXS)
> ===
>
> I've got "pg_uservars.c" and "hv.cc" and I'd like to compile hv.cc via g++.
> I'm aware of c++ name [de]mangling, just looking if there's a standard way of
> using C++ when it comes to pgxs.

It should "just work". Simply make sure to follow the usual rules for
calling into C++ code from C and vice versa:

- Use "extern C" linkage for all functions that must be accessible by
  dlopen(), and preferably also for any functions that you might take
  a function pointer to and pass to C code

- Never return new()'d memory that might be free()'d by the C code; use
  malloc()

- Never delete() memory that was malloc()'d by the C code; use free()

- Never let an exception propagate into the C code; use a catch-all
  block at the top level of all "extern C" functions

... and probably other things I've missed.

--
Craig Ringer

pgsql-general by date:

Previous
From: Dean Rasheed
Date:
Subject: Re: Help me with this multi-table query
Next
From: Craig Ringer
Date:
Subject: Re: Avoiding deadlocks on mass delete / update