[lug] C extensions of PostgreSQL

B Giles bldrbear at hotmail.com
Wed Aug 6 18:35:35 MDT 2003


>I'm trying to write a C function for PostgreSQL on RH 7.3 (KRUD), and 
>running into a problem. The C code must apparently link against a library 
>that provides functions "CurrentMemoryContext" and "MemoryContextAlloc" 
>(probably due to palloc).

I just had a horrid thought.

What's your exact link command?

For 7.1, my package used automake so it's a bit harder to hit on the key 
aspects, but the key Makefile.am file was:

  AM_CFLAGS = -I./include -Wall -Wmissing-prototypes -Wmissing-declarations

  lib_LTLIBRARIES = libpkixpq.la

  libpkixpq_la_SOURCES = bio.c base.c bignum.c .... (long list of files)

  libpkixpq_la_ADD_LIBS = ../crypto/.libs/libpkixpq-crypto.a

  libpkixpq_la_LDFLAGS = -version 1

  INCLUDES = -I/usr/include/postgresql

(From the documentation, I should now add "-fpic" to AM_CFLAGS.)  The 
ADD_LIB is because I broke my code into two parts for legal and practical 
reasons, the -crypto library had all of the full-strength crypto and this 
part contained everything else.

Anyway, the final result was a shared library.  This library was then loaded 
and tied into the system by running a thousand line script containing 
thrilling lines like

  -- encrypt data with specified certificate and cipher
  create function encrypt(text, x509, text) returns pkcs7
      as '/usr/lib/libpkixpq.so', 'pg_pkcs7_encrypt' language 'C'
      with (isstrict); -- is not cachable due to random bits

where x509 and pkcs7 are types defined earlier.

Bear

P.S., now that I think about it, all of my public functions had to call an 
"initialize()" function upon entry. I floated the idea of functions that 
would be called when a module was loaded or unloaded, but it was shot down 
by the postgresql hackers.  I don't know if they changed their mind now.

_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*.  
http://join.msn.com/?page=features/featuredemail




More information about the LUG mailing list