Re: selfmade datatype in C and server-crash - Mailing list pgsql-general

From Markus Schulz
Subject Re: selfmade datatype in C and server-crash
Date
Msg-id 200510051444.53118.msc@antzsystem.de
Whole thread Raw
In response to Re: selfmade datatype in C and server-crash  (Markus Schulz <msc@antzsystem.de>)
List pgsql-general
Now i have debugged the _first_ "Insert" Statement in my etextin
function cause i got a NULL value for inputText on second insert.
now etextin function looks like:
Datum
etextin(PG_FUNCTION_ARGS)
{
    char       *inputText = PG_GETARG_CSTRING(0);
    text       *result;
    int         len=0;

    if(!inputText)
            return CStringGetDatum("");//only for testing purpose
    /* verify encoding */
    len = strlen(inputText);
    pg_verifymbstr(inputText, len, false);

    result = (text *) palloc(len + VARHDRSZ);
    VARATT_SIZEP(result) = len + VARHDRSZ;

    memcpy(VARDATA(result), inputText, len);

    PG_RETURN_TEXT_P(result);
}


debug:(SQL=insert into test ( var1) values ('aiksnd');)

(gdb) break new_types.c:26
Breakpoint 1 at 0x40ffe888: file new_types.c, line 26.
(gdb) cont
Continuing.

Breakpoint 1, etextin (fcinfo=0x8332c90) at new_types.c:26
26              if(!inputText)
(gdb) display inputText
1: inputText = 0x8332c90 "@-3\b\020"

this looks weird to me. The content should be "aiksnd" or i'm wrong?

i think i have missed some precondition but don't know which.


With this additional if(!inputText) condition inserts don't crash
anymore. But each select on the table crashs now.


Markus Schulz

pgsql-general by date:

Previous
From: Douglas McNaught
Date:
Subject: Re: Or selection on index versus union
Next
From: Robert Osowiecki
Date:
Subject: Cast to integer