Re: fmgr.h: PG_NARGS() for number of arguments passed

Lists: pgsql-patches
From: Lee Kindness <lkindness(at)csl(dot)co(dot)uk>
To: pgsql-patches(at)postgresql(dot)org
Cc: Lee Kindness <lkindness(at)csl(dot)co(dot)uk>
Subject: fmgr.h: PG_NARGS() for number of arguments passed
Date: 2002-09-11 13:25:01
Message-ID: 15743.17453.912687.96063@kelvin.csl.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-patches

The small context diff below corrects what seems to be an oversight in
fmgr.h - it's discouraged to access fcinfo directly but there is no
macro to get the number of arguments passed to the function. Checking
the number of arguments is often useful when you have a function which
can be called like:

func('arg');
func(null);
func();

all mapping to the same C function.

the macro has a function-like appearance to match the other PG_*
macros.

Regards, Lee Kindness.

Index: fmgr.h
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/include/fmgr.h,v
retrieving revision 1.24
diff -c -r1.24 fmgr.h
*** fmgr.h 2002/09/04 20:31:36 1.24
--- fmgr.h 2002/09/10 13:25:06
***************
*** 116,121 ****
--- 116,126 ----
#define PG_FUNCTION_ARGS FunctionCallInfo fcinfo

/*
+ * Get number of arguments passed to function.
+ */
+ #define PG_NARGS() (fcinfo->nargs)
+
+ /*
* If function is not marked "proisstrict" in pg_proc, it must check for
* null arguments using this macro. Do not try to GETARG a null argument!
*/


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Lee Kindness <lkindness(at)csl(dot)co(dot)uk>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: fmgr.h: PG_NARGS() for number of arguments passed
Date: 2002-09-11 23:56:09
Message-ID: 200209112356.g8BNu9B07004@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-patches


This is sort of a feature, but I don't think we need to wait for 7.4 for
a simple #define addition.

Your patch has been added to the PostgreSQL unapplied patches list at:

http://candle.pha.pa.us/cgi-bin/pgpatches

I will try to apply it within the next 48 hours.

---------------------------------------------------------------------------

Lee Kindness wrote:
> The small context diff below corrects what seems to be an oversight in
> fmgr.h - it's discouraged to access fcinfo directly but there is no
> macro to get the number of arguments passed to the function. Checking
> the number of arguments is often useful when you have a function which
> can be called like:
>
> func('arg');
> func(null);
> func();
>
> all mapping to the same C function.
>
> the macro has a function-like appearance to match the other PG_*
> macros.
>
> Regards, Lee Kindness.
>
> Index: fmgr.h
> ===================================================================
> RCS file: /projects/cvsroot/pgsql-server/src/include/fmgr.h,v
> retrieving revision 1.24
> diff -c -r1.24 fmgr.h
> *** fmgr.h 2002/09/04 20:31:36 1.24
> --- fmgr.h 2002/09/10 13:25:06
> ***************
> *** 116,121 ****
> --- 116,126 ----
> #define PG_FUNCTION_ARGS FunctionCallInfo fcinfo
>
> /*
> + * Get number of arguments passed to function.
> + */
> + #define PG_NARGS() (fcinfo->nargs)
> +
> + /*
> * If function is not marked "proisstrict" in pg_proc, it must check for
> * null arguments using this macro. Do not try to GETARG a null argument!
> */
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Lee Kindness <lkindness(at)csl(dot)co(dot)uk>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: fmgr.h: PG_NARGS() for number of arguments passed
Date: 2002-09-12 00:26:43
Message-ID: 200209120026.g8C0QiV16180@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-patches


Patch applied. Thanks.

---------------------------------------------------------------------------

Lee Kindness wrote:
> The small context diff below corrects what seems to be an oversight in
> fmgr.h - it's discouraged to access fcinfo directly but there is no
> macro to get the number of arguments passed to the function. Checking
> the number of arguments is often useful when you have a function which
> can be called like:
>
> func('arg');
> func(null);
> func();
>
> all mapping to the same C function.
>
> the macro has a function-like appearance to match the other PG_*
> macros.
>
> Regards, Lee Kindness.
>
> Index: fmgr.h
> ===================================================================
> RCS file: /projects/cvsroot/pgsql-server/src/include/fmgr.h,v
> retrieving revision 1.24
> diff -c -r1.24 fmgr.h
> *** fmgr.h 2002/09/04 20:31:36 1.24
> --- fmgr.h 2002/09/10 13:25:06
> ***************
> *** 116,121 ****
> --- 116,126 ----
> #define PG_FUNCTION_ARGS FunctionCallInfo fcinfo
>
> /*
> + * Get number of arguments passed to function.
> + */
> + #define PG_NARGS() (fcinfo->nargs)
> +
> + /*
> * If function is not marked "proisstrict" in pg_proc, it must check for
> * null arguments using this macro. Do not try to GETARG a null argument!
> */
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073