469,575 Members | 1,268 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,575 developers. It's quick & easy.

C Function causes backend to die in 7.4.3

I have written a C function for postgres. I developed and got this
function working on postgres 7.3.2, however the production system was

On my initial dev setup it worked perfectly, however on the 7.4.3 it
caused the backend to terminate abnormaly!, I upgraded my dev system to
be the same version to ensure it wasn't just the production box, and
sure enough the function now also fails on my dev system!

I have commented out the entire function body looking for the cause of
the crash, and it seems that it is being cause by calling
PointerGetDatum() on the return. If I set return to NULL, then the
insert on the table doesn't cause a crash of the backend.

Any ideas? The C segment for my code on 7.4.3 which is crashing is as

extern Datum updatetrig(PG_FUNCTION_ARGS);


Datum updatetrig(PG_FUNCTION_ARGS)
TriggerData *trigdata = (TriggerData *) fcinfo->context;
char *name;
char *data; // Temporary string
char *ptr; // Temp string for building

char *sql; // The SQL statement to add the update row
char *id; // The id of the row the update is for
char *idfield; // The field name of the id column
char *table; // The name of the table being modified
char *action; // The action undertaken by the update
char *update; // The update SQL itself

int noatts=0; // Number of attributes
int len=0; // Length of string needed
int a=0;

HeapTuple rettuple;

// Commented out code is here

return PointerGetDatum(rettuple);

thanks for any help

Graeme Hinchliffe (BSc)
Core Internet Systems Designer
Zen Internet (http://www.zen.co.uk/)

Direct: 0845 058 9074
Main : 0845 058 9000
Fax : 0845 058 9005

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #1
1 1322
Graeme Hinchliffe <gr***************@zeninternet.co.uk> writes:
HeapTuple rettuple; // Commented out code is here return PointerGetDatum(rettuple);

It surprises you that returning an uninitialized pointer value will
crash the code that tries to use the pointer?

I strongly recommend using a compiler that will warn about uninitialized
values. If using gcc, you should use -O1 (at least).

I dunno what the original problem was, but maybe you just neglected to
recompile the function against 7.4 headers? We don't generally
guarantee binary compatibility of user-defined functions across major

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Derickson | last post: by
7 posts views Thread by Jim Crate | last post: by
4 posts views Thread by Dawid Kuroczko | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.