help wanted (fmgr.c)

Started by Gevik Babakhaniover 19 years ago3 messages
#1Gevik Babakhani
pgdev@xs4all.nl

I am a little stuck of a question.

In fmgr.c:1698, function "InputFunctionCall" at line 1718

/* Should get null result if and only if str is NULL */
if (str == NULL)
{
....
....

What are we testing to be NULL here?
Do we expect str to changed at line 1715
( result = FunctionCallInvoke(&fcinfo); )

Please advice,
Gevik.

In reply to: Gevik Babakhani (#1)
Re: help wanted (fmgr.c)

At 2006-09-11 10:25:22 +0200, pgdev@xs4all.nl wrote:

What are we testing to be NULL here?
Do we expect str to changed at line 1715

No. (Read the comment just above the function.)

The code is like this, starting from line 1703:

if (str == NULL && flinfo->fn_strict)
return (Datum) 0;

That is, if the function is declared strict, and the argument (str) is
0, just return NULL straightaway. Then it sets up the fcinfo and calls
the function, and then:

...

/* Should get null result if and only if str is NULL */
if (str == NULL)
{
if (!fcinfo.isnull)
elog(ERROR, "input function %u returned non-NULL",
fcinfo.flinfo->fn_oid);
}
else
{
if (fcinfo.isnull)
elog(ERROR, "input function %u returned NULL",
fcinfo.flinfo->fn_oid);
}

This says: If the argument is NULL and the input function didn't return
a NULL, log an error; but if the argument is non-NULL and the function
returned NULL, log this other error. (Note that a function would set
fcinfo->isnull to indicate that it wants to return an SQL NULL, as
explained in $DOC/plhandler.html)

-- ams

#3Gevik Babakhani
pgdev@xs4all.nl
In reply to: Abhijit Menon-Sen (#2)
Re: help wanted (fmgr.c)

Thank you for your reply.....
I found my bug in the code which made the function behave strangely.

Show quoted text

On Mon, 2006-09-11 at 14:23 +0530, Abhijit Menon-Sen wrote:

At 2006-09-11 10:25:22 +0200, pgdev@xs4all.nl wrote:

What are we testing to be NULL here?
Do we expect str to changed at line 1715

No. (Read the comment just above the function.)

The code is like this, starting from line 1703:

if (str == NULL && flinfo->fn_strict)
return (Datum) 0;

That is, if the function is declared strict, and the argument (str) is
0, just return NULL straightaway. Then it sets up the fcinfo and calls
the function, and then:

...

/* Should get null result if and only if str is NULL */
if (str == NULL)
{
if (!fcinfo.isnull)
elog(ERROR, "input function %u returned non-NULL",
fcinfo.flinfo->fn_oid);
}
else
{
if (fcinfo.isnull)
elog(ERROR, "input function %u returned NULL",
fcinfo.flinfo->fn_oid);
}

This says: If the argument is NULL and the input function didn't return
a NULL, log an error; but if the argument is non-NULL and the function
returned NULL, log this other error. (Note that a function would set
fcinfo->isnull to indicate that it wants to return an SQL NULL, as
explained in $DOC/plhandler.html)

-- ams