C Function causes backend to die in 7.4.3

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Graeme Hinchliffe

    C Function causes backend to die in 7.4.3

    Hiya,
    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
    7.4.3.

    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
    follows:

    extern Datum updatetrig(PG_F UNCTION_ARGS);

    PG_FUNCTION_INF O_V1(updatetrig );

    Datum updatetrig(PG_F UNCTION_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 majordomo@postg resql.org so that your
    message can get through to the mailing list cleanly

  • Tom Lane

    #2
    Re: C Function causes backend to die in 7.4.3

    Graeme Hinchliffe <graeme.hinchli ffe@zeninternet .co.uk> writes:
    [color=blue]
    > HeapTuple rettuple;[/color]
    [color=blue]
    > // Commented out code is here[/color]
    [color=blue]
    > return PointerGetDatum (rettuple);[/color]

    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
    releases.

    regards, tom lane

    ---------------------------(end of broadcast)---------------------------
    TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddres sHere" to majordomo@postg resql.org)

    Comment

    Working...