Custom C function - is palloc broken?

From: "Nathan Thatcher" <n8thatcher(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Custom C function - is palloc broken?
Date: 2008-05-04 03:39:04
Message-ID: d9c17fb40805032039r29d75ac1i53addc025cdb0bc2@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

First off, I am developing custom c functions for PostgreSQL 8.3 in
Windows (sorry... not my choice). It appears that there is some
underlying problem in the server that is causing a runtime error to
crash the server when I use palloc. For example... I run the
following:

PG_FUNCTION_INFO_V1(add_one);
Datum
add_one(PG_FUNCTION_ARGS)
{
int32 arg = PG_GETARG_INT32(0);
PG_RETURN_INT32(arg + 1);
}

and it works just fine. NOTE: this is directly from the tutorial
directory. Now, when I add a palloc statement in there it crashes:

PG_FUNCTION_INFO_V1(add_one);
Datum
add_one(PG_FUNCTION_ARGS)
{
int32 arg = PG_GETARG_INT32(0);
palloc(sizeof(Point));
PG_RETURN_INT32(arg + 1);
}

Running "SELECT add_one(1);" crashes the server. The logs show this:

2008-05-03 21:29:08 MDT LOG: server process (PID 3008) was terminated
by exception 0xC0000005
2008-05-03 21:29:08 MDT HINT: See C include file "ntstatus.h" for a
description of the hexadecimal value.
2008-05-03 21:29:08 MDT LOG: terminating any other active server processes
2008-05-03 21:29:08 MDT LOG: all server processes terminated; reinitializing
2008-05-03 21:29:09 MDT FATAL: pre-existing shared memory block is still in use
2008-05-03 21:29:09 MDT HINT: Check if there are any old server
processes still running, and terminate them.

I also get the exact same error when I try to run either the copytext
or concat_text functions from the same funcs_new.c file in the
tutorial directory. This essentially means that I cannot write any
UDFs that require memory allocation or text parameters. Heron seems to
be experiencing the same thing. Is this a bug in 8.3? Can anyone help?

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2008-05-04 04:19:33 Re: Speed up repetitive queries
Previous Message Tom Lane 2008-05-04 01:04:13 Re: custom C function problem