Index: doc/src/sgml/extend.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/extend.sgml,v
retrieving revision 1.42
diff -c -c -r1.42 extend.sgml
*** doc/src/sgml/extend.sgml 1 Jun 2010 03:19:36 -0000 1.42
--- doc/src/sgml/extend.sgml 2 Jun 2010 03:25:30 -0000
***************
*** 273,280 ****
&xoper;
&xindex;
-
--- 282,338 ----
It is possible to use a compiler in C++ mode to build
! PostgreSQL extensions by following these
! guidelines:
! All functions accessed by the backend must present a C interface
! to the backend; these C functions can then call C++ functions.
! For example, extern C> linkage is required for
! backend-accessed functions. This is also necessary for any
! functions that are passed as pointers between the backend and
! C++ code.
! Free memory using the appropriate deallocation method. For example,
! most backend memory is allocated using palloc()>, so use
! pfree()> to free it, i.e. using C++
! delete()> in such cases will fail.
! Prevent exceptions from propagating into the C code (use a
! catch-all block at the top level of all extern C>
! functions). This is necessary even if the C++ code does not
! throw any exceptions because events like out-of-memory still
! throw exceptions. Any exceptions must be caught and appropriate
! errors passed back to the C interface. If possible, compile C++
! with
! If calling backend functions from C++ code, be sure that the
! C++ call stack contains only plain old data structure
! (POD>). This is necessary because backend errors
! generate a longjump()> that does not properly unroll
! a C++ call stack with non-POD objects.
+
+ In summary, it is best to place C++ code behind a wall of
+ extern C> functions that interface to the backend,
+ and avoid exception, memory, and call stack leakage.
+