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

From Tom Lane
Subject Re: selfmade datatype in C and server-crash
Date
Msg-id 13242.1128481290@sss.pgh.pa.us
Whole thread Raw
In response to selfmade datatype in C and server-crash  (Markus Schulz <msc@antzsystem.de>)
Responses Re: selfmade datatype in C and server-crash
List pgsql-general
Markus Schulz <msc@antzsystem.de> writes:
> This works fine and then i've created the new Type like:

> CREATE OR REPLACE FUNCTION etextin(cstring)
>   RETURNS etext AS
> '$libdir/new_types.so', 'etextin'
>   LANGUAGE 'c' VOLATILE;

> CREATE OR REPLACE FUNCTION etextout(etext)
>   RETURNS cstring AS
> '$libdir/new_types.so', 'etextout'
>   LANGUAGE 'c' VOLATILE;

You'd likely be well advised to declare these STRICT (hint: is the C
code checking for null input?) ... and unless the datatype has weird
semantics, its I/O functions should be IMMUTABLE.  This doesn't matter
too much for the system's ordinary use of I/O functions, but for
security you want to make sure the functions are properly marked in
case they get called directly.

> But if i'm trying to use the type in a table (for instance table with
> only one etext column) the server crashed after inserting the second
> (first insert works) tuple or on every select.

Getting a stack trace from the crash would be helpful.  But the fact
that it only fails on the second try makes me suspicious that it's
a memory-management issue.  Count thy pallocs.

            regards, tom lane

pgsql-general by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: Isolated transactions?
Next
From: Nitin Tarkar
Date:
Subject: PostgreSQL Database export from Linux to Windows