Hi,
While integrating C stub in stored procedure, I came across the
following problem whenever the DB triggered the SP:
"
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
"

My C code looks like this:
"
PG_FUNCTION_INFO_V1(abc);
Datum abc(PG_FUNCTION_ARGS)
{
VarChar *arg1 ;
char *str;
arg1=(VarChar *) PG_GETARG_VARCHAR_P(0);
int str1Size = VARSIZE(arg1) - VARHDRSZ;
if (arg1) str = (char *) VARDATA(arg1);
short int ret ;

str[str1Size]='\0';
ret =anotherfunc(str); // anotherfunc() returns smallint

PG_RETURN_INT16(ret);
}
"

I am not sure what I am doing wrong, but I notice whenever I comment out
the code for extraction of the arguments,
"
arg1=(VarChar *) PG_GETARG_VARCHAR_P(0);
int str1Size = VARSIZE(arg1) - VARHDRSZ;
if (arg1) str = (char *) VARDATA(arg1);
"
the DB ceases to throw the error.

The function has been declared as
"
CREATE FUNCTION abc(varchar) RETURNS smallint AS '/path/abc.so', 'abc'
LANGUAGE C STRICT;
"

Am I missing something?

Thanks,
Smita

Search Discussions

  • Tom Lane at Feb 7, 2008 at 4:17 pm

    Smita Vijayakumar writes:
    While integrating C stub in stored procedure, I came across the
    following problem whenever the DB triggered the SP:
    "
    server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.
    My C code looks like this:
    str[str1Size]='\0';
    Scribbling on pass-by-reference arguments is verboten. Scribbling past
    the end of one is even worse.

    regards, tom lane

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppgsql-novice @
categoriespostgresql
postedFeb 7, '08 at 10:10a
activeFeb 7, '08 at 4:17p
posts2
users2
websitepostgresql.org
irc#postgresql

2 users in discussion

Smita Vijayakumar: 1 post Tom Lane: 1 post

People

Translate

site design / logo © 2022 Grokbase