Header And Logo

PostgreSQL
| The world's most advanced open source database.

fmgr.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * fmgr.h
00004  *    Definitions for the Postgres function manager and function-call
00005  *    interface.
00006  *
00007  * This file must be included by all Postgres modules that either define
00008  * or call fmgr-callable functions.
00009  *
00010  *
00011  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00012  * Portions Copyright (c) 1994, Regents of the University of California
00013  *
00014  * src/include/fmgr.h
00015  *
00016  *-------------------------------------------------------------------------
00017  */
00018 #ifndef FMGR_H
00019 #define FMGR_H
00020 
00021 /* We don't want to include primnodes.h here, so make a stub reference */
00022 typedef struct Node *fmNodePtr;
00023 
00024 /* Likewise, avoid including stringinfo.h here */
00025 typedef struct StringInfoData *fmStringInfo;
00026 
00027 
00028 /*
00029  * All functions that can be called directly by fmgr must have this signature.
00030  * (Other functions can be called by using a handler that does have this
00031  * signature.)
00032  */
00033 
00034 typedef struct FunctionCallInfoData *FunctionCallInfo;
00035 
00036 typedef Datum (*PGFunction) (FunctionCallInfo fcinfo);
00037 
00038 /*
00039  * This struct holds the system-catalog information that must be looked up
00040  * before a function can be called through fmgr.  If the same function is
00041  * to be called multiple times, the lookup need be done only once and the
00042  * info struct saved for re-use.
00043  *
00044  * Note that fn_expr really is parse-time-determined information about the
00045  * arguments, rather than about the function itself.  But it's convenient
00046  * to store it here rather than in FunctionCallInfoData, where it might more
00047  * logically belong.
00048  */
00049 typedef struct FmgrInfo
00050 {
00051     PGFunction  fn_addr;        /* pointer to function or handler to be called */
00052     Oid         fn_oid;         /* OID of function (NOT of handler, if any) */
00053     short       fn_nargs;       /* 0..FUNC_MAX_ARGS, or -1 if variable arg
00054                                  * count */
00055     bool        fn_strict;      /* function is "strict" (NULL in => NULL out) */
00056     bool        fn_retset;      /* function returns a set */
00057     unsigned char fn_stats;     /* collect stats if track_functions > this */
00058     void       *fn_extra;       /* extra space for use by handler */
00059     MemoryContext fn_mcxt;      /* memory context to store fn_extra in */
00060     fmNodePtr   fn_expr;        /* expression parse tree for call, or NULL */
00061 } FmgrInfo;
00062 
00063 /*
00064  * This struct is the data actually passed to an fmgr-called function.
00065  */
00066 typedef struct FunctionCallInfoData
00067 {
00068     FmgrInfo   *flinfo;         /* ptr to lookup info used for this call */
00069     fmNodePtr   context;        /* pass info about context of call */
00070     fmNodePtr   resultinfo;     /* pass or return extra info about result */
00071     Oid         fncollation;    /* collation for function to use */
00072     bool        isnull;         /* function must set true if result is NULL */
00073     short       nargs;          /* # arguments actually passed */
00074     Datum       arg[FUNC_MAX_ARGS];     /* Arguments passed to function */
00075     bool        argnull[FUNC_MAX_ARGS]; /* T if arg[i] is actually NULL */
00076 } FunctionCallInfoData;
00077 
00078 /*
00079  * This routine fills a FmgrInfo struct, given the OID
00080  * of the function to be called.
00081  */
00082 extern void fmgr_info(Oid functionId, FmgrInfo *finfo);
00083 
00084 /*
00085  * Same, when the FmgrInfo struct is in a memory context longer-lived than
00086  * CurrentMemoryContext.  The specified context will be set as fn_mcxt
00087  * and used to hold all subsidiary data of finfo.
00088  */
00089 extern void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo,
00090               MemoryContext mcxt);
00091 
00092 /* Convenience macro for setting the fn_expr field */
00093 #define fmgr_info_set_expr(expr, finfo) \
00094     ((finfo)->fn_expr = (expr))
00095 
00096 /*
00097  * Copy an FmgrInfo struct
00098  */
00099 extern void fmgr_info_copy(FmgrInfo *dstinfo, FmgrInfo *srcinfo,
00100                MemoryContext destcxt);
00101 
00102 /*
00103  * This macro initializes all the fields of a FunctionCallInfoData except
00104  * for the arg[] and argnull[] arrays.  Performance testing has shown that
00105  * the fastest way to set up argnull[] for small numbers of arguments is to
00106  * explicitly set each required element to false, so we don't try to zero
00107  * out the argnull[] array in the macro.
00108  */
00109 #define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo) \
00110     do { \
00111         (Fcinfo).flinfo = (Flinfo); \
00112         (Fcinfo).context = (Context); \
00113         (Fcinfo).resultinfo = (Resultinfo); \
00114         (Fcinfo).fncollation = (Collation); \
00115         (Fcinfo).isnull = false; \
00116         (Fcinfo).nargs = (Nargs); \
00117     } while (0)
00118 
00119 /*
00120  * This macro invokes a function given a filled-in FunctionCallInfoData
00121  * struct.  The macro result is the returned Datum --- but note that
00122  * caller must still check fcinfo->isnull!  Also, if function is strict,
00123  * it is caller's responsibility to verify that no null arguments are present
00124  * before calling.
00125  */
00126 #define FunctionCallInvoke(fcinfo)  ((* (fcinfo)->flinfo->fn_addr) (fcinfo))
00127 
00128 
00129 /*-------------------------------------------------------------------------
00130  *      Support macros to ease writing fmgr-compatible functions
00131  *
00132  * A C-coded fmgr-compatible function should be declared as
00133  *
00134  *      Datum
00135  *      function_name(PG_FUNCTION_ARGS)
00136  *      {
00137  *          ...
00138  *      }
00139  *
00140  * It should access its arguments using appropriate PG_GETARG_xxx macros
00141  * and should return its result using PG_RETURN_xxx.
00142  *
00143  *-------------------------------------------------------------------------
00144  */
00145 
00146 /* Standard parameter list for fmgr-compatible functions */
00147 #define PG_FUNCTION_ARGS    FunctionCallInfo fcinfo
00148 
00149 /*
00150  * Get collation function should use.
00151  */
00152 #define PG_GET_COLLATION()  (fcinfo->fncollation)
00153 
00154 /*
00155  * Get number of arguments passed to function.
00156  */
00157 #define PG_NARGS() (fcinfo->nargs)
00158 
00159 /*
00160  * If function is not marked "proisstrict" in pg_proc, it must check for
00161  * null arguments using this macro.  Do not try to GETARG a null argument!
00162  */
00163 #define PG_ARGISNULL(n)  (fcinfo->argnull[n])
00164 
00165 /*
00166  * Support for fetching detoasted copies of toastable datatypes (all of
00167  * which are varlena types).  pg_detoast_datum() gives you either the input
00168  * datum (if not toasted) or a detoasted copy allocated with palloc().
00169  * pg_detoast_datum_copy() always gives you a palloc'd copy --- use it
00170  * if you need a modifiable copy of the input.  Caller is expected to have
00171  * checked for null inputs first, if necessary.
00172  *
00173  * pg_detoast_datum_packed() will return packed (1-byte header) datums
00174  * unmodified.  It will still expand an externally toasted or compressed datum.
00175  * The resulting datum can be accessed using VARSIZE_ANY() and VARDATA_ANY()
00176  * (beware of multiple evaluations in those macros!)
00177  *
00178  * WARNING: It is only safe to use pg_detoast_datum_packed() and
00179  * VARDATA_ANY() if you really don't care about the alignment. Either because
00180  * you're working with something like text where the alignment doesn't matter
00181  * or because you're not going to access its constituent parts and just use
00182  * things like memcpy on it anyways.
00183  *
00184  * Note: it'd be nice if these could be macros, but I see no way to do that
00185  * without evaluating the arguments multiple times, which is NOT acceptable.
00186  */
00187 extern struct varlena *pg_detoast_datum(struct varlena * datum);
00188 extern struct varlena *pg_detoast_datum_copy(struct varlena * datum);
00189 extern struct varlena *pg_detoast_datum_slice(struct varlena * datum,
00190                        int32 first, int32 count);
00191 extern struct varlena *pg_detoast_datum_packed(struct varlena * datum);
00192 
00193 #define PG_DETOAST_DATUM(datum) \
00194     pg_detoast_datum((struct varlena *) DatumGetPointer(datum))
00195 #define PG_DETOAST_DATUM_COPY(datum) \
00196     pg_detoast_datum_copy((struct varlena *) DatumGetPointer(datum))
00197 #define PG_DETOAST_DATUM_SLICE(datum,f,c) \
00198         pg_detoast_datum_slice((struct varlena *) DatumGetPointer(datum), \
00199         (int32) (f), (int32) (c))
00200 /* WARNING -- unaligned pointer */
00201 #define PG_DETOAST_DATUM_PACKED(datum) \
00202     pg_detoast_datum_packed((struct varlena *) DatumGetPointer(datum))
00203 
00204 /*
00205  * Support for cleaning up detoasted copies of inputs.  This must only
00206  * be used for pass-by-ref datatypes, and normally would only be used
00207  * for toastable types.  If the given pointer is different from the
00208  * original argument, assume it's a palloc'd detoasted copy, and pfree it.
00209  * NOTE: most functions on toastable types do not have to worry about this,
00210  * but we currently require that support functions for indexes not leak
00211  * memory.
00212  */
00213 #define PG_FREE_IF_COPY(ptr,n) \
00214     do { \
00215         if ((Pointer) (ptr) != PG_GETARG_POINTER(n)) \
00216             pfree(ptr); \
00217     } while (0)
00218 
00219 /* Macros for fetching arguments of standard types */
00220 
00221 #define PG_GETARG_DATUM(n)   (fcinfo->arg[n])
00222 #define PG_GETARG_INT32(n)   DatumGetInt32(PG_GETARG_DATUM(n))
00223 #define PG_GETARG_UINT32(n)  DatumGetUInt32(PG_GETARG_DATUM(n))
00224 #define PG_GETARG_INT16(n)   DatumGetInt16(PG_GETARG_DATUM(n))
00225 #define PG_GETARG_UINT16(n)  DatumGetUInt16(PG_GETARG_DATUM(n))
00226 #define PG_GETARG_CHAR(n)    DatumGetChar(PG_GETARG_DATUM(n))
00227 #define PG_GETARG_BOOL(n)    DatumGetBool(PG_GETARG_DATUM(n))
00228 #define PG_GETARG_OID(n)     DatumGetObjectId(PG_GETARG_DATUM(n))
00229 #define PG_GETARG_POINTER(n) DatumGetPointer(PG_GETARG_DATUM(n))
00230 #define PG_GETARG_CSTRING(n) DatumGetCString(PG_GETARG_DATUM(n))
00231 #define PG_GETARG_NAME(n)    DatumGetName(PG_GETARG_DATUM(n))
00232 /* these macros hide the pass-by-reference-ness of the datatype: */
00233 #define PG_GETARG_FLOAT4(n)  DatumGetFloat4(PG_GETARG_DATUM(n))
00234 #define PG_GETARG_FLOAT8(n)  DatumGetFloat8(PG_GETARG_DATUM(n))
00235 #define PG_GETARG_INT64(n)   DatumGetInt64(PG_GETARG_DATUM(n))
00236 /* use this if you want the raw, possibly-toasted input datum: */
00237 #define PG_GETARG_RAW_VARLENA_P(n)  ((struct varlena *) PG_GETARG_POINTER(n))
00238 /* use this if you want the input datum de-toasted: */
00239 #define PG_GETARG_VARLENA_P(n) PG_DETOAST_DATUM(PG_GETARG_DATUM(n))
00240 /* and this if you can handle 1-byte-header datums: */
00241 #define PG_GETARG_VARLENA_PP(n) PG_DETOAST_DATUM_PACKED(PG_GETARG_DATUM(n))
00242 /* DatumGetFoo macros for varlena types will typically look like this: */
00243 #define DatumGetByteaP(X)           ((bytea *) PG_DETOAST_DATUM(X))
00244 #define DatumGetByteaPP(X)          ((bytea *) PG_DETOAST_DATUM_PACKED(X))
00245 #define DatumGetTextP(X)            ((text *) PG_DETOAST_DATUM(X))
00246 #define DatumGetTextPP(X)           ((text *) PG_DETOAST_DATUM_PACKED(X))
00247 #define DatumGetBpCharP(X)          ((BpChar *) PG_DETOAST_DATUM(X))
00248 #define DatumGetBpCharPP(X)         ((BpChar *) PG_DETOAST_DATUM_PACKED(X))
00249 #define DatumGetVarCharP(X)         ((VarChar *) PG_DETOAST_DATUM(X))
00250 #define DatumGetVarCharPP(X)        ((VarChar *) PG_DETOAST_DATUM_PACKED(X))
00251 #define DatumGetHeapTupleHeader(X)  ((HeapTupleHeader) PG_DETOAST_DATUM(X))
00252 /* And we also offer variants that return an OK-to-write copy */
00253 #define DatumGetByteaPCopy(X)       ((bytea *) PG_DETOAST_DATUM_COPY(X))
00254 #define DatumGetTextPCopy(X)        ((text *) PG_DETOAST_DATUM_COPY(X))
00255 #define DatumGetBpCharPCopy(X)      ((BpChar *) PG_DETOAST_DATUM_COPY(X))
00256 #define DatumGetVarCharPCopy(X)     ((VarChar *) PG_DETOAST_DATUM_COPY(X))
00257 #define DatumGetHeapTupleHeaderCopy(X)  ((HeapTupleHeader) PG_DETOAST_DATUM_COPY(X))
00258 /* Variants which return n bytes starting at pos. m */
00259 #define DatumGetByteaPSlice(X,m,n)  ((bytea *) PG_DETOAST_DATUM_SLICE(X,m,n))
00260 #define DatumGetTextPSlice(X,m,n)   ((text *) PG_DETOAST_DATUM_SLICE(X,m,n))
00261 #define DatumGetBpCharPSlice(X,m,n) ((BpChar *) PG_DETOAST_DATUM_SLICE(X,m,n))
00262 #define DatumGetVarCharPSlice(X,m,n) ((VarChar *) PG_DETOAST_DATUM_SLICE(X,m,n))
00263 /* GETARG macros for varlena types will typically look like this: */
00264 #define PG_GETARG_BYTEA_P(n)        DatumGetByteaP(PG_GETARG_DATUM(n))
00265 #define PG_GETARG_BYTEA_PP(n)       DatumGetByteaPP(PG_GETARG_DATUM(n))
00266 #define PG_GETARG_TEXT_P(n)         DatumGetTextP(PG_GETARG_DATUM(n))
00267 #define PG_GETARG_TEXT_PP(n)        DatumGetTextPP(PG_GETARG_DATUM(n))
00268 #define PG_GETARG_BPCHAR_P(n)       DatumGetBpCharP(PG_GETARG_DATUM(n))
00269 #define PG_GETARG_BPCHAR_PP(n)      DatumGetBpCharPP(PG_GETARG_DATUM(n))
00270 #define PG_GETARG_VARCHAR_P(n)      DatumGetVarCharP(PG_GETARG_DATUM(n))
00271 #define PG_GETARG_VARCHAR_PP(n)     DatumGetVarCharPP(PG_GETARG_DATUM(n))
00272 #define PG_GETARG_HEAPTUPLEHEADER(n)    DatumGetHeapTupleHeader(PG_GETARG_DATUM(n))
00273 /* And we also offer variants that return an OK-to-write copy */
00274 #define PG_GETARG_BYTEA_P_COPY(n)   DatumGetByteaPCopy(PG_GETARG_DATUM(n))
00275 #define PG_GETARG_TEXT_P_COPY(n)    DatumGetTextPCopy(PG_GETARG_DATUM(n))
00276 #define PG_GETARG_BPCHAR_P_COPY(n)  DatumGetBpCharPCopy(PG_GETARG_DATUM(n))
00277 #define PG_GETARG_VARCHAR_P_COPY(n) DatumGetVarCharPCopy(PG_GETARG_DATUM(n))
00278 #define PG_GETARG_HEAPTUPLEHEADER_COPY(n)   DatumGetHeapTupleHeaderCopy(PG_GETARG_DATUM(n))
00279 /* And a b-byte slice from position a -also OK to write */
00280 #define PG_GETARG_BYTEA_P_SLICE(n,a,b) DatumGetByteaPSlice(PG_GETARG_DATUM(n),a,b)
00281 #define PG_GETARG_TEXT_P_SLICE(n,a,b)  DatumGetTextPSlice(PG_GETARG_DATUM(n),a,b)
00282 #define PG_GETARG_BPCHAR_P_SLICE(n,a,b) DatumGetBpCharPSlice(PG_GETARG_DATUM(n),a,b)
00283 #define PG_GETARG_VARCHAR_P_SLICE(n,a,b) DatumGetVarCharPSlice(PG_GETARG_DATUM(n),a,b)
00284 
00285 /* To return a NULL do this: */
00286 #define PG_RETURN_NULL()  \
00287     do { fcinfo->isnull = true; return (Datum) 0; } while (0)
00288 
00289 /* A few internal functions return void (which is not the same as NULL!) */
00290 #define PG_RETURN_VOID()     return (Datum) 0
00291 
00292 /* Macros for returning results of standard types */
00293 
00294 #define PG_RETURN_DATUM(x)   return (x)
00295 #define PG_RETURN_INT32(x)   return Int32GetDatum(x)
00296 #define PG_RETURN_UINT32(x)  return UInt32GetDatum(x)
00297 #define PG_RETURN_INT16(x)   return Int16GetDatum(x)
00298 #define PG_RETURN_CHAR(x)    return CharGetDatum(x)
00299 #define PG_RETURN_BOOL(x)    return BoolGetDatum(x)
00300 #define PG_RETURN_OID(x)     return ObjectIdGetDatum(x)
00301 #define PG_RETURN_POINTER(x) return PointerGetDatum(x)
00302 #define PG_RETURN_CSTRING(x) return CStringGetDatum(x)
00303 #define PG_RETURN_NAME(x)    return NameGetDatum(x)
00304 /* these macros hide the pass-by-reference-ness of the datatype: */
00305 #define PG_RETURN_FLOAT4(x)  return Float4GetDatum(x)
00306 #define PG_RETURN_FLOAT8(x)  return Float8GetDatum(x)
00307 #define PG_RETURN_INT64(x)   return Int64GetDatum(x)
00308 /* RETURN macros for other pass-by-ref types will typically look like this: */
00309 #define PG_RETURN_BYTEA_P(x)   PG_RETURN_POINTER(x)
00310 #define PG_RETURN_TEXT_P(x)    PG_RETURN_POINTER(x)
00311 #define PG_RETURN_BPCHAR_P(x)  PG_RETURN_POINTER(x)
00312 #define PG_RETURN_VARCHAR_P(x) PG_RETURN_POINTER(x)
00313 #define PG_RETURN_HEAPTUPLEHEADER(x)  PG_RETURN_POINTER(x)
00314 
00315 
00316 /*-------------------------------------------------------------------------
00317  *      Support for detecting call convention of dynamically-loaded functions
00318  *
00319  * Dynamically loaded functions may use either the version-1 ("new style")
00320  * or version-0 ("old style") calling convention.  Version 1 is the call
00321  * convention defined in this header file; version 0 is the old "plain C"
00322  * convention.  A version-1 function must be accompanied by the macro call
00323  *
00324  *      PG_FUNCTION_INFO_V1(function_name);
00325  *
00326  * Note that internal functions do not need this decoration since they are
00327  * assumed to be version-1.
00328  *
00329  *-------------------------------------------------------------------------
00330  */
00331 
00332 typedef struct
00333 {
00334     int         api_version;    /* specifies call convention version number */
00335     /* More fields may be added later, for version numbers > 1. */
00336 } Pg_finfo_record;
00337 
00338 /* Expected signature of an info function */
00339 typedef const Pg_finfo_record *(*PGFInfoFunction) (void);
00340 
00341 /*
00342  *  Macro to build an info function associated with the given function name.
00343  *  Win32 loadable functions usually link with 'dlltool --export-all', but it
00344  *  doesn't hurt to add PGDLLIMPORT in case they don't.
00345  */
00346 #define PG_FUNCTION_INFO_V1(funcname) \
00347 extern PGDLLEXPORT const Pg_finfo_record * CppConcat(pg_finfo_,funcname)(void); \
00348 const Pg_finfo_record * \
00349 CppConcat(pg_finfo_,funcname) (void) \
00350 { \
00351     static const Pg_finfo_record my_finfo = { 1 }; \
00352     return &my_finfo; \
00353 } \
00354 extern int no_such_variable
00355 
00356 
00357 /*-------------------------------------------------------------------------
00358  *      Support for verifying backend compatibility of loaded modules
00359  *
00360  * We require dynamically-loaded modules to include the macro call
00361  *      PG_MODULE_MAGIC;
00362  * so that we can check for obvious incompatibility, such as being compiled
00363  * for a different major PostgreSQL version.
00364  *
00365  * To compile with versions of PostgreSQL that do not support this,
00366  * you may put an #ifdef/#endif test around it.  Note that in a multiple-
00367  * source-file module, the macro call should only appear once.
00368  *
00369  * The specific items included in the magic block are intended to be ones that
00370  * are custom-configurable and especially likely to break dynamically loaded
00371  * modules if they were compiled with other values.  Also, the length field
00372  * can be used to detect definition changes.
00373  *
00374  * Note: we compare magic blocks with memcmp(), so there had better not be
00375  * any alignment pad bytes in them.
00376  *
00377  * Note: when changing the contents of magic blocks, be sure to adjust the
00378  * incompatible_module_error() function in dfmgr.c.
00379  *-------------------------------------------------------------------------
00380  */
00381 
00382 /* Definition of the magic block structure */
00383 typedef struct
00384 {
00385     int         len;            /* sizeof(this struct) */
00386     int         version;        /* PostgreSQL major version */
00387     int         funcmaxargs;    /* FUNC_MAX_ARGS */
00388     int         indexmaxkeys;   /* INDEX_MAX_KEYS */
00389     int         namedatalen;    /* NAMEDATALEN */
00390     int         float4byval;    /* FLOAT4PASSBYVAL */
00391     int         float8byval;    /* FLOAT8PASSBYVAL */
00392 } Pg_magic_struct;
00393 
00394 /* The actual data block contents */
00395 #define PG_MODULE_MAGIC_DATA \
00396 { \
00397     sizeof(Pg_magic_struct), \
00398     PG_VERSION_NUM / 100, \
00399     FUNC_MAX_ARGS, \
00400     INDEX_MAX_KEYS, \
00401     NAMEDATALEN, \
00402     FLOAT4PASSBYVAL, \
00403     FLOAT8PASSBYVAL \
00404 }
00405 
00406 /*
00407  * Declare the module magic function.  It needs to be a function as the dlsym
00408  * in the backend is only guaranteed to work on functions, not data
00409  */
00410 typedef const Pg_magic_struct *(*PGModuleMagicFunction) (void);
00411 
00412 #define PG_MAGIC_FUNCTION_NAME Pg_magic_func
00413 #define PG_MAGIC_FUNCTION_NAME_STRING "Pg_magic_func"
00414 
00415 #define PG_MODULE_MAGIC \
00416 extern PGDLLEXPORT const Pg_magic_struct *PG_MAGIC_FUNCTION_NAME(void); \
00417 const Pg_magic_struct * \
00418 PG_MAGIC_FUNCTION_NAME(void) \
00419 { \
00420     static const Pg_magic_struct Pg_magic_data = PG_MODULE_MAGIC_DATA; \
00421     return &Pg_magic_data; \
00422 } \
00423 extern int no_such_variable
00424 
00425 
00426 /*-------------------------------------------------------------------------
00427  *      Support routines and macros for callers of fmgr-compatible functions
00428  *-------------------------------------------------------------------------
00429  */
00430 
00431 /* These are for invocation of a specifically named function with a
00432  * directly-computed parameter list.  Note that neither arguments nor result
00433  * are allowed to be NULL.
00434  */
00435 extern Datum DirectFunctionCall1Coll(PGFunction func, Oid collation,
00436                         Datum arg1);
00437 extern Datum DirectFunctionCall2Coll(PGFunction func, Oid collation,
00438                         Datum arg1, Datum arg2);
00439 extern Datum DirectFunctionCall3Coll(PGFunction func, Oid collation,
00440                         Datum arg1, Datum arg2,
00441                         Datum arg3);
00442 extern Datum DirectFunctionCall4Coll(PGFunction func, Oid collation,
00443                         Datum arg1, Datum arg2,
00444                         Datum arg3, Datum arg4);
00445 extern Datum DirectFunctionCall5Coll(PGFunction func, Oid collation,
00446                         Datum arg1, Datum arg2,
00447                         Datum arg3, Datum arg4, Datum arg5);
00448 extern Datum DirectFunctionCall6Coll(PGFunction func, Oid collation,
00449                         Datum arg1, Datum arg2,
00450                         Datum arg3, Datum arg4, Datum arg5,
00451                         Datum arg6);
00452 extern Datum DirectFunctionCall7Coll(PGFunction func, Oid collation,
00453                         Datum arg1, Datum arg2,
00454                         Datum arg3, Datum arg4, Datum arg5,
00455                         Datum arg6, Datum arg7);
00456 extern Datum DirectFunctionCall8Coll(PGFunction func, Oid collation,
00457                         Datum arg1, Datum arg2,
00458                         Datum arg3, Datum arg4, Datum arg5,
00459                         Datum arg6, Datum arg7, Datum arg8);
00460 extern Datum DirectFunctionCall9Coll(PGFunction func, Oid collation,
00461                         Datum arg1, Datum arg2,
00462                         Datum arg3, Datum arg4, Datum arg5,
00463                         Datum arg6, Datum arg7, Datum arg8,
00464                         Datum arg9);
00465 
00466 /* These are for invocation of a previously-looked-up function with a
00467  * directly-computed parameter list.  Note that neither arguments nor result
00468  * are allowed to be NULL.
00469  */
00470 extern Datum FunctionCall1Coll(FmgrInfo *flinfo, Oid collation,
00471                   Datum arg1);
00472 extern Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation,
00473                   Datum arg1, Datum arg2);
00474 extern Datum FunctionCall3Coll(FmgrInfo *flinfo, Oid collation,
00475                   Datum arg1, Datum arg2,
00476                   Datum arg3);
00477 extern Datum FunctionCall4Coll(FmgrInfo *flinfo, Oid collation,
00478                   Datum arg1, Datum arg2,
00479                   Datum arg3, Datum arg4);
00480 extern Datum FunctionCall5Coll(FmgrInfo *flinfo, Oid collation,
00481                   Datum arg1, Datum arg2,
00482                   Datum arg3, Datum arg4, Datum arg5);
00483 extern Datum FunctionCall6Coll(FmgrInfo *flinfo, Oid collation,
00484                   Datum arg1, Datum arg2,
00485                   Datum arg3, Datum arg4, Datum arg5,
00486                   Datum arg6);
00487 extern Datum FunctionCall7Coll(FmgrInfo *flinfo, Oid collation,
00488                   Datum arg1, Datum arg2,
00489                   Datum arg3, Datum arg4, Datum arg5,
00490                   Datum arg6, Datum arg7);
00491 extern Datum FunctionCall8Coll(FmgrInfo *flinfo, Oid collation,
00492                   Datum arg1, Datum arg2,
00493                   Datum arg3, Datum arg4, Datum arg5,
00494                   Datum arg6, Datum arg7, Datum arg8);
00495 extern Datum FunctionCall9Coll(FmgrInfo *flinfo, Oid collation,
00496                   Datum arg1, Datum arg2,
00497                   Datum arg3, Datum arg4, Datum arg5,
00498                   Datum arg6, Datum arg7, Datum arg8,
00499                   Datum arg9);
00500 
00501 /* These are for invocation of a function identified by OID with a
00502  * directly-computed parameter list.  Note that neither arguments nor result
00503  * are allowed to be NULL.  These are essentially FunctionLookup() followed
00504  * by FunctionCallN().  If the same function is to be invoked repeatedly,
00505  * do the FunctionLookup() once and then use FunctionCallN().
00506  */
00507 extern Datum OidFunctionCall0Coll(Oid functionId, Oid collation);
00508 extern Datum OidFunctionCall1Coll(Oid functionId, Oid collation,
00509                      Datum arg1);
00510 extern Datum OidFunctionCall2Coll(Oid functionId, Oid collation,
00511                      Datum arg1, Datum arg2);
00512 extern Datum OidFunctionCall3Coll(Oid functionId, Oid collation,
00513                      Datum arg1, Datum arg2,
00514                      Datum arg3);
00515 extern Datum OidFunctionCall4Coll(Oid functionId, Oid collation,
00516                      Datum arg1, Datum arg2,
00517                      Datum arg3, Datum arg4);
00518 extern Datum OidFunctionCall5Coll(Oid functionId, Oid collation,
00519                      Datum arg1, Datum arg2,
00520                      Datum arg3, Datum arg4, Datum arg5);
00521 extern Datum OidFunctionCall6Coll(Oid functionId, Oid collation,
00522                      Datum arg1, Datum arg2,
00523                      Datum arg3, Datum arg4, Datum arg5,
00524                      Datum arg6);
00525 extern Datum OidFunctionCall7Coll(Oid functionId, Oid collation,
00526                      Datum arg1, Datum arg2,
00527                      Datum arg3, Datum arg4, Datum arg5,
00528                      Datum arg6, Datum arg7);
00529 extern Datum OidFunctionCall8Coll(Oid functionId, Oid collation,
00530                      Datum arg1, Datum arg2,
00531                      Datum arg3, Datum arg4, Datum arg5,
00532                      Datum arg6, Datum arg7, Datum arg8);
00533 extern Datum OidFunctionCall9Coll(Oid functionId, Oid collation,
00534                      Datum arg1, Datum arg2,
00535                      Datum arg3, Datum arg4, Datum arg5,
00536                      Datum arg6, Datum arg7, Datum arg8,
00537                      Datum arg9);
00538 
00539 /* These macros allow the collation argument to be omitted (with a default of
00540  * InvalidOid, ie, no collation).  They exist mostly for backwards
00541  * compatibility of source code.
00542  */
00543 #define DirectFunctionCall1(func, arg1) \
00544     DirectFunctionCall1Coll(func, InvalidOid, arg1)
00545 #define DirectFunctionCall2(func, arg1, arg2) \
00546     DirectFunctionCall2Coll(func, InvalidOid, arg1, arg2)
00547 #define DirectFunctionCall3(func, arg1, arg2, arg3) \
00548     DirectFunctionCall3Coll(func, InvalidOid, arg1, arg2, arg3)
00549 #define DirectFunctionCall4(func, arg1, arg2, arg3, arg4) \
00550     DirectFunctionCall4Coll(func, InvalidOid, arg1, arg2, arg3, arg4)
00551 #define DirectFunctionCall5(func, arg1, arg2, arg3, arg4, arg5) \
00552     DirectFunctionCall5Coll(func, InvalidOid, arg1, arg2, arg3, arg4, arg5)
00553 #define DirectFunctionCall6(func, arg1, arg2, arg3, arg4, arg5, arg6) \
00554     DirectFunctionCall6Coll(func, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6)
00555 #define DirectFunctionCall7(func, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
00556     DirectFunctionCall7Coll(func, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
00557 #define DirectFunctionCall8(func, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \
00558     DirectFunctionCall8Coll(func, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
00559 #define DirectFunctionCall9(func, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) \
00560     DirectFunctionCall9Coll(func, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
00561 #define FunctionCall1(flinfo, arg1) \
00562     FunctionCall1Coll(flinfo, InvalidOid, arg1)
00563 #define FunctionCall2(flinfo, arg1, arg2) \
00564     FunctionCall2Coll(flinfo, InvalidOid, arg1, arg2)
00565 #define FunctionCall3(flinfo, arg1, arg2, arg3) \
00566     FunctionCall3Coll(flinfo, InvalidOid, arg1, arg2, arg3)
00567 #define FunctionCall4(flinfo, arg1, arg2, arg3, arg4) \
00568     FunctionCall4Coll(flinfo, InvalidOid, arg1, arg2, arg3, arg4)
00569 #define FunctionCall5(flinfo, arg1, arg2, arg3, arg4, arg5) \
00570     FunctionCall5Coll(flinfo, InvalidOid, arg1, arg2, arg3, arg4, arg5)
00571 #define FunctionCall6(flinfo, arg1, arg2, arg3, arg4, arg5, arg6) \
00572     FunctionCall6Coll(flinfo, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6)
00573 #define FunctionCall7(flinfo, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
00574     FunctionCall7Coll(flinfo, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
00575 #define FunctionCall8(flinfo, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \
00576     FunctionCall8Coll(flinfo, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
00577 #define FunctionCall9(flinfo, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) \
00578     FunctionCall9Coll(flinfo, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
00579 #define OidFunctionCall0(functionId) \
00580     OidFunctionCall0Coll(functionId, InvalidOid)
00581 #define OidFunctionCall1(functionId, arg1) \
00582     OidFunctionCall1Coll(functionId, InvalidOid, arg1)
00583 #define OidFunctionCall2(functionId, arg1, arg2) \
00584     OidFunctionCall2Coll(functionId, InvalidOid, arg1, arg2)
00585 #define OidFunctionCall3(functionId, arg1, arg2, arg3) \
00586     OidFunctionCall3Coll(functionId, InvalidOid, arg1, arg2, arg3)
00587 #define OidFunctionCall4(functionId, arg1, arg2, arg3, arg4) \
00588     OidFunctionCall4Coll(functionId, InvalidOid, arg1, arg2, arg3, arg4)
00589 #define OidFunctionCall5(functionId, arg1, arg2, arg3, arg4, arg5) \
00590     OidFunctionCall5Coll(functionId, InvalidOid, arg1, arg2, arg3, arg4, arg5)
00591 #define OidFunctionCall6(functionId, arg1, arg2, arg3, arg4, arg5, arg6) \
00592     OidFunctionCall6Coll(functionId, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6)
00593 #define OidFunctionCall7(functionId, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
00594     OidFunctionCall7Coll(functionId, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
00595 #define OidFunctionCall8(functionId, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \
00596     OidFunctionCall8Coll(functionId, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
00597 #define OidFunctionCall9(functionId, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) \
00598     OidFunctionCall9Coll(functionId, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
00599 
00600 
00601 /* Special cases for convenient invocation of datatype I/O functions. */
00602 extern Datum InputFunctionCall(FmgrInfo *flinfo, char *str,
00603                   Oid typioparam, int32 typmod);
00604 extern Datum OidInputFunctionCall(Oid functionId, char *str,
00605                      Oid typioparam, int32 typmod);
00606 extern char *OutputFunctionCall(FmgrInfo *flinfo, Datum val);
00607 extern char *OidOutputFunctionCall(Oid functionId, Datum val);
00608 extern Datum ReceiveFunctionCall(FmgrInfo *flinfo, fmStringInfo buf,
00609                     Oid typioparam, int32 typmod);
00610 extern Datum OidReceiveFunctionCall(Oid functionId, fmStringInfo buf,
00611                        Oid typioparam, int32 typmod);
00612 extern bytea *SendFunctionCall(FmgrInfo *flinfo, Datum val);
00613 extern bytea *OidSendFunctionCall(Oid functionId, Datum val);
00614 
00615 
00616 /*
00617  * Routines in fmgr.c
00618  */
00619 extern const Pg_finfo_record *fetch_finfo_record(void *filehandle, char *funcname);
00620 extern void clear_external_function_hash(void *filehandle);
00621 extern Oid  fmgr_internal_function(const char *proname);
00622 extern Oid  get_fn_expr_rettype(FmgrInfo *flinfo);
00623 extern Oid  get_fn_expr_argtype(FmgrInfo *flinfo, int argnum);
00624 extern Oid  get_call_expr_argtype(fmNodePtr expr, int argnum);
00625 extern bool get_fn_expr_arg_stable(FmgrInfo *flinfo, int argnum);
00626 extern bool get_call_expr_arg_stable(fmNodePtr expr, int argnum);
00627 extern bool get_fn_expr_variadic(FmgrInfo *flinfo);
00628 
00629 /*
00630  * Routines in dfmgr.c
00631  */
00632 extern char *Dynamic_library_path;
00633 
00634 extern PGFunction load_external_function(char *filename, char *funcname,
00635                        bool signalNotFound, void **filehandle);
00636 extern PGFunction lookup_external_function(void *filehandle, char *funcname);
00637 extern void load_file(const char *filename, bool restricted);
00638 extern void **find_rendezvous_variable(const char *varName);
00639 
00640 /*
00641  * Support for aggregate functions
00642  *
00643  * This is actually in executor/nodeAgg.c, but we declare it here since the
00644  * whole point is for callers of it to not be overly friendly with nodeAgg.
00645  */
00646 
00647 /* AggCheckCallContext can return one of the following codes, or 0: */
00648 #define AGG_CONTEXT_AGGREGATE   1       /* regular aggregate */
00649 #define AGG_CONTEXT_WINDOW      2       /* window function */
00650 
00651 extern int AggCheckCallContext(FunctionCallInfo fcinfo,
00652                     MemoryContext *aggcontext);
00653 
00654 /*
00655  * We allow plugin modules to hook function entry/exit.  This is intended
00656  * as support for loadable security policy modules, which may want to
00657  * perform additional privilege checks on function entry or exit, or to do
00658  * other internal bookkeeping.  To make this possible, such modules must be
00659  * able not only to support normal function entry and exit, but also to trap
00660  * the case where we bail out due to an error; and they must also be able to
00661  * prevent inlining.
00662  */
00663 typedef enum FmgrHookEventType
00664 {
00665     FHET_START,
00666     FHET_END,
00667     FHET_ABORT
00668 } FmgrHookEventType;
00669 
00670 typedef bool (*needs_fmgr_hook_type) (Oid fn_oid);
00671 
00672 typedef void (*fmgr_hook_type) (FmgrHookEventType event,
00673                                             FmgrInfo *flinfo, Datum *arg);
00674 
00675 extern PGDLLIMPORT needs_fmgr_hook_type needs_fmgr_hook;
00676 extern PGDLLIMPORT fmgr_hook_type fmgr_hook;
00677 
00678 #define FmgrHookIsNeeded(fn_oid)                            \
00679     (!needs_fmgr_hook ? false : (*needs_fmgr_hook)(fn_oid))
00680 
00681 /*
00682  * !!! OLD INTERFACE !!!
00683  *
00684  * fmgr() is the only remaining vestige of the old-style caller support
00685  * functions.  It's no longer used anywhere in the Postgres distribution,
00686  * but we should leave it around for a release or two to ease the transition
00687  * for user-supplied C functions.  OidFunctionCallN() replaces it for new
00688  * code.
00689  */
00690 
00691 /*
00692  * DEPRECATED, DO NOT USE IN NEW CODE
00693  */
00694 extern char *fmgr(Oid procedureId,...);
00695 
00696 #endif   /* FMGR_H */