Re: A couple more PostgreSQL C questions - Mailing list pgsql-general

From Tom Lane
Subject Re: A couple more PostgreSQL C questions
Date
Msg-id 16156.1162959480@sss.pgh.pa.us
Whole thread Raw
In response to A couple more PostgreSQL C questions  (Ron Peterson <ron.peterson@yellowbank.com>)
List pgsql-general
Ron Peterson <ron.peterson@yellowbank.com> writes:
> Datum
> y_somefunc ( PG_FUNCTION_ARGS )
> {
>    if( PG_ARGISNULL(0) ||
>        PG_ARGISNULL(1) ||
>        PG_ARGISNULL(2) )
>    {
>       PG_RETURN_NULL();
>    }
>    text* rand_dev = PG_GETARG_TEXT_P(0);
>    ...

> Should I be concerned by this?  What's the proper way to code this?

The proper way to code that is either

{
   text* rand_dev;

   if( PG_ARGISNULL(0) ||
       PG_ARGISNULL(1) ||
       PG_ARGISNULL(2) )
   {
      PG_RETURN_NULL();
   }
   rand_dev = PG_GETARG_TEXT_P(0);
   ...

or probably better, declare the function STRICT and drop the runtime
ARGISNULL tests entirely.

> I'm thinking the correct answer is "just live with
> it until your version of gcc uses c99 as the default standard".

Declarations in the middle of a code block are C++, not C; if you
try to hold your breath until your C compiler accepts it, you will die.

            regards, tom lane

pgsql-general by date:

Previous
From: Ron Peterson
Date:
Subject: Re: A couple more PostgreSQL C questions
Next
From: "Gurjeet Singh"
Date:
Subject: Re: Per-row security