[lug] C extensions of PostgreSQL

B Giles bldrbear at hotmail.com
Wed Aug 6 14:52:14 MDT 2003


>It is. In the version 1 interface all variable length parameters (text, 
>varchar) must be passed by reference.  All pass-by-reference are allocated 
>with palloc. I am passing a short varchar string (C type VarChar). I would 
>allocate with malloc, but this would either seg fault or be a memory leak, 
>since PostegreSQL wouldn't know to deallocate.

Yup, although there should be convenience routines for varchar objects 
(psprintf, pstrcpy, pstrcat, etc).   These functions handle populating the 
header for you - it's not hard, but requires some tiresome casting. That's 
why I wrote a bunch of my own convenience functions to glue PostgreSQL data 
buffers and OpenSSL BIO buffers.

>I just want to know what lib to link...the sample code I have is fine, it 
>is coded and complete...what I need is for a lib that implements 
>functionality for palloc (those symbols missing are because palloc 
>references them).

I keep thinking that you're missing some registration functions, but maybe 
that's only with user-defined types or people who need to initialize an 
external library.  E.g., I had to initialize the OpenSSL library and 
configure it to use palloc instead of the default memory allocation 
routines.

Anyway, the full source includes a number of contributed extensions that use 
the same interface you're struggling with.  Figure out how earthdistance or 
the pqcrypto (which is very lame) or the other user-defined types link - 
these are also user-defined functions.

But PostGIS, user-defined types for GIS information, would be overwhelming.  
Ditto my outdated PKIX library.

Bear

_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online  
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963




More information about the LUG mailing list