1 /*-------------------------------------------------------------------------
4 * Definitions for the Postgres function manager and function-call
7 * This file must be included by all Postgres modules that either define
8 * or call fmgr-callable functions.
11 * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
12 * Portions Copyright (c) 1994, Regents of the University of California
16 *-------------------------------------------------------------------------
21 /* We don't want to include primnodes.h here, so make a stub reference */
22 typedef struct Node *fmNodePtr;
24 /* Likewise, avoid including stringinfo.h here */
25 typedef struct StringInfoData *fmStringInfo;
29 * All functions that can be called directly by fmgr must have this signature.
30 * (Other functions can be called by using a handler that does have this
34 typedef struct FunctionCallInfoData *FunctionCallInfo;
36 typedef Datum (*PGFunction) (FunctionCallInfo fcinfo);
39 * This struct holds the system-catalog information that must be looked up
40 * before a function can be called through fmgr. If the same function is
41 * to be called multiple times, the lookup need be done only once and the
42 * info struct saved for re-use.
44 * Note that fn_collation and fn_expr really are parse-time-determined
45 * information about the arguments, rather than about the function itself.
46 * But it's convenient to store them here rather than in FunctionCallInfoData,
47 * where they might more logically belong.
49 typedef struct FmgrInfo
51 PGFunction fn_addr; /* pointer to function or handler to be called */
52 Oid fn_oid; /* OID of function (NOT of handler, if any) */
53 short fn_nargs; /* 0..FUNC_MAX_ARGS, or -1 if variable arg
55 bool fn_strict; /* function is "strict" (NULL in => NULL out) */
56 bool fn_retset; /* function returns a set */
57 unsigned char fn_stats; /* collect stats if track_functions > this */
58 Oid fn_collation; /* collation that function should use */
59 void *fn_extra; /* extra space for use by handler */
60 MemoryContext fn_mcxt; /* memory context to store fn_extra in */
61 fmNodePtr fn_expr; /* expression parse tree for call, or NULL */
65 * This struct is the data actually passed to an fmgr-called function.
67 typedef struct FunctionCallInfoData
69 FmgrInfo *flinfo; /* ptr to lookup info used for this call */
70 fmNodePtr context; /* pass info about context of call */
71 fmNodePtr resultinfo; /* pass or return extra info about result */
72 bool isnull; /* function must set true if result is NULL */
73 short nargs; /* # arguments actually passed */
74 Datum arg[FUNC_MAX_ARGS]; /* Arguments passed to function */
75 bool argnull[FUNC_MAX_ARGS]; /* T if arg[i] is actually NULL */
76 } FunctionCallInfoData;
79 * This routine fills a FmgrInfo struct, given the OID
80 * of the function to be called.
82 extern void fmgr_info(Oid functionId, FmgrInfo *finfo);
85 * Same, when the FmgrInfo struct is in a memory context longer-lived than
86 * CurrentMemoryContext. The specified context will be set as fn_mcxt
87 * and used to hold all subsidiary data of finfo.
89 extern void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo,
92 /* Macros for setting the fn_collation and fn_expr fields */
93 #define fmgr_info_set_collation(collationId, finfo) \
94 ((finfo)->fn_collation = (collationId))
95 #define fmgr_info_set_expr(expr, finfo) \
96 ((finfo)->fn_expr = (expr))
99 * Copy an FmgrInfo struct
101 extern void fmgr_info_copy(FmgrInfo *dstinfo, FmgrInfo *srcinfo,
102 MemoryContext destcxt);
105 * This macro initializes all the fields of a FunctionCallInfoData except
106 * for the arg[] and argnull[] arrays. Performance testing has shown that
107 * the fastest way to set up argnull[] for small numbers of arguments is to
108 * explicitly set each required element to false, so we don't try to zero
109 * out the argnull[] array in the macro.
111 #define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Context, Resultinfo) \
113 (Fcinfo).flinfo = (Flinfo); \
114 (Fcinfo).context = (Context); \
115 (Fcinfo).resultinfo = (Resultinfo); \
116 (Fcinfo).isnull = false; \
117 (Fcinfo).nargs = (Nargs); \
121 * This macro invokes a function given a filled-in FunctionCallInfoData
122 * struct. The macro result is the returned Datum --- but note that
123 * caller must still check fcinfo->isnull! Also, if function is strict,
124 * it is caller's responsibility to verify that no null arguments are present
127 #define FunctionCallInvoke(fcinfo) ((* (fcinfo)->flinfo->fn_addr) (fcinfo))
130 /*-------------------------------------------------------------------------
131 * Support macros to ease writing fmgr-compatible functions
133 * A C-coded fmgr-compatible function should be declared as
136 * function_name(PG_FUNCTION_ARGS)
141 * It should access its arguments using appropriate PG_GETARG_xxx macros
142 * and should return its result using PG_RETURN_xxx.
144 *-------------------------------------------------------------------------
147 /* Standard parameter list for fmgr-compatible functions */
148 #define PG_FUNCTION_ARGS FunctionCallInfo fcinfo
151 * Get collation function should use.
153 #define PG_GET_COLLATION() \
154 (fcinfo->flinfo ? fcinfo->flinfo->fn_collation : InvalidOid)
157 * Get number of arguments passed to function.
159 #define PG_NARGS() (fcinfo->nargs)
162 * If function is not marked "proisstrict" in pg_proc, it must check for
163 * null arguments using this macro. Do not try to GETARG a null argument!
165 #define PG_ARGISNULL(n) (fcinfo->argnull[n])
168 * Support for fetching detoasted copies of toastable datatypes (all of
169 * which are varlena types). pg_detoast_datum() gives you either the input
170 * datum (if not toasted) or a detoasted copy allocated with palloc().
171 * pg_detoast_datum_copy() always gives you a palloc'd copy --- use it
172 * if you need a modifiable copy of the input. Caller is expected to have
173 * checked for null inputs first, if necessary.
175 * pg_detoast_datum_packed() will return packed (1-byte header) datums
176 * unmodified. It will still expand an externally toasted or compressed datum.
177 * The resulting datum can be accessed using VARSIZE_ANY() and VARDATA_ANY()
178 * (beware of multiple evaluations in those macros!)
180 * WARNING: It is only safe to use pg_detoast_datum_packed() and
181 * VARDATA_ANY() if you really don't care about the alignment. Either because
182 * you're working with something like text where the alignment doesn't matter
183 * or because you're not going to access its constituent parts and just use
184 * things like memcpy on it anyways.
186 * Note: it'd be nice if these could be macros, but I see no way to do that
187 * without evaluating the arguments multiple times, which is NOT acceptable.
189 extern struct varlena *pg_detoast_datum(struct varlena * datum);
190 extern struct varlena *pg_detoast_datum_copy(struct varlena * datum);
191 extern struct varlena *pg_detoast_datum_slice(struct varlena * datum,
192 int32 first, int32 count);
193 extern struct varlena *pg_detoast_datum_packed(struct varlena * datum);
195 #define PG_DETOAST_DATUM(datum) \
196 pg_detoast_datum((struct varlena *) DatumGetPointer(datum))
197 #define PG_DETOAST_DATUM_COPY(datum) \
198 pg_detoast_datum_copy((struct varlena *) DatumGetPointer(datum))
199 #define PG_DETOAST_DATUM_SLICE(datum,f,c) \
200 pg_detoast_datum_slice((struct varlena *) DatumGetPointer(datum), \
201 (int32) (f), (int32) (c))
202 /* WARNING -- unaligned pointer */
203 #define PG_DETOAST_DATUM_PACKED(datum) \
204 pg_detoast_datum_packed((struct varlena *) DatumGetPointer(datum))
207 * Support for cleaning up detoasted copies of inputs. This must only
208 * be used for pass-by-ref datatypes, and normally would only be used
209 * for toastable types. If the given pointer is different from the
210 * original argument, assume it's a palloc'd detoasted copy, and pfree it.
211 * NOTE: most functions on toastable types do not have to worry about this,
212 * but we currently require that support functions for indexes not leak
215 #define PG_FREE_IF_COPY(ptr,n) \
217 if ((Pointer) (ptr) != PG_GETARG_POINTER(n)) \
221 /* Macros for fetching arguments of standard types */
223 #define PG_GETARG_DATUM(n) (fcinfo->arg[n])
224 #define PG_GETARG_INT32(n) DatumGetInt32(PG_GETARG_DATUM(n))
225 #define PG_GETARG_UINT32(n) DatumGetUInt32(PG_GETARG_DATUM(n))
226 #define PG_GETARG_INT16(n) DatumGetInt16(PG_GETARG_DATUM(n))
227 #define PG_GETARG_UINT16(n) DatumGetUInt16(PG_GETARG_DATUM(n))
228 #define PG_GETARG_CHAR(n) DatumGetChar(PG_GETARG_DATUM(n))
229 #define PG_GETARG_BOOL(n) DatumGetBool(PG_GETARG_DATUM(n))
230 #define PG_GETARG_OID(n) DatumGetObjectId(PG_GETARG_DATUM(n))
231 #define PG_GETARG_POINTER(n) DatumGetPointer(PG_GETARG_DATUM(n))
232 #define PG_GETARG_CSTRING(n) DatumGetCString(PG_GETARG_DATUM(n))
233 #define PG_GETARG_NAME(n) DatumGetName(PG_GETARG_DATUM(n))
234 /* these macros hide the pass-by-reference-ness of the datatype: */
235 #define PG_GETARG_FLOAT4(n) DatumGetFloat4(PG_GETARG_DATUM(n))
236 #define PG_GETARG_FLOAT8(n) DatumGetFloat8(PG_GETARG_DATUM(n))
237 #define PG_GETARG_INT64(n) DatumGetInt64(PG_GETARG_DATUM(n))
238 /* use this if you want the raw, possibly-toasted input datum: */
239 #define PG_GETARG_RAW_VARLENA_P(n) ((struct varlena *) PG_GETARG_POINTER(n))
240 /* use this if you want the input datum de-toasted: */
241 #define PG_GETARG_VARLENA_P(n) PG_DETOAST_DATUM(PG_GETARG_DATUM(n))
242 /* and this if you can handle 1-byte-header datums: */
243 #define PG_GETARG_VARLENA_PP(n) PG_DETOAST_DATUM_PACKED(PG_GETARG_DATUM(n))
244 /* DatumGetFoo macros for varlena types will typically look like this: */
245 #define DatumGetByteaP(X) ((bytea *) PG_DETOAST_DATUM(X))
246 #define DatumGetByteaPP(X) ((bytea *) PG_DETOAST_DATUM_PACKED(X))
247 #define DatumGetTextP(X) ((text *) PG_DETOAST_DATUM(X))
248 #define DatumGetTextPP(X) ((text *) PG_DETOAST_DATUM_PACKED(X))
249 #define DatumGetBpCharP(X) ((BpChar *) PG_DETOAST_DATUM(X))
250 #define DatumGetBpCharPP(X) ((BpChar *) PG_DETOAST_DATUM_PACKED(X))
251 #define DatumGetVarCharP(X) ((VarChar *) PG_DETOAST_DATUM(X))
252 #define DatumGetVarCharPP(X) ((VarChar *) PG_DETOAST_DATUM_PACKED(X))
253 #define DatumGetHeapTupleHeader(X) ((HeapTupleHeader) PG_DETOAST_DATUM(X))
254 /* And we also offer variants that return an OK-to-write copy */
255 #define DatumGetByteaPCopy(X) ((bytea *) PG_DETOAST_DATUM_COPY(X))
256 #define DatumGetTextPCopy(X) ((text *) PG_DETOAST_DATUM_COPY(X))
257 #define DatumGetBpCharPCopy(X) ((BpChar *) PG_DETOAST_DATUM_COPY(X))
258 #define DatumGetVarCharPCopy(X) ((VarChar *) PG_DETOAST_DATUM_COPY(X))
259 #define DatumGetHeapTupleHeaderCopy(X) ((HeapTupleHeader) PG_DETOAST_DATUM_COPY(X))
260 /* Variants which return n bytes starting at pos. m */
261 #define DatumGetByteaPSlice(X,m,n) ((bytea *) PG_DETOAST_DATUM_SLICE(X,m,n))
262 #define DatumGetTextPSlice(X,m,n) ((text *) PG_DETOAST_DATUM_SLICE(X,m,n))
263 #define DatumGetBpCharPSlice(X,m,n) ((BpChar *) PG_DETOAST_DATUM_SLICE(X,m,n))
264 #define DatumGetVarCharPSlice(X,m,n) ((VarChar *) PG_DETOAST_DATUM_SLICE(X,m,n))
265 /* GETARG macros for varlena types will typically look like this: */
266 #define PG_GETARG_BYTEA_P(n) DatumGetByteaP(PG_GETARG_DATUM(n))
267 #define PG_GETARG_BYTEA_PP(n) DatumGetByteaPP(PG_GETARG_DATUM(n))
268 #define PG_GETARG_TEXT_P(n) DatumGetTextP(PG_GETARG_DATUM(n))
269 #define PG_GETARG_TEXT_PP(n) DatumGetTextPP(PG_GETARG_DATUM(n))
270 #define PG_GETARG_BPCHAR_P(n) DatumGetBpCharP(PG_GETARG_DATUM(n))
271 #define PG_GETARG_BPCHAR_PP(n) DatumGetBpCharPP(PG_GETARG_DATUM(n))
272 #define PG_GETARG_VARCHAR_P(n) DatumGetVarCharP(PG_GETARG_DATUM(n))
273 #define PG_GETARG_VARCHAR_PP(n) DatumGetVarCharPP(PG_GETARG_DATUM(n))
274 #define PG_GETARG_HEAPTUPLEHEADER(n) DatumGetHeapTupleHeader(PG_GETARG_DATUM(n))
275 /* And we also offer variants that return an OK-to-write copy */
276 #define PG_GETARG_BYTEA_P_COPY(n) DatumGetByteaPCopy(PG_GETARG_DATUM(n))
277 #define PG_GETARG_TEXT_P_COPY(n) DatumGetTextPCopy(PG_GETARG_DATUM(n))
278 #define PG_GETARG_BPCHAR_P_COPY(n) DatumGetBpCharPCopy(PG_GETARG_DATUM(n))
279 #define PG_GETARG_VARCHAR_P_COPY(n) DatumGetVarCharPCopy(PG_GETARG_DATUM(n))
280 #define PG_GETARG_HEAPTUPLEHEADER_COPY(n) DatumGetHeapTupleHeaderCopy(PG_GETARG_DATUM(n))
281 /* And a b-byte slice from position a -also OK to write */
282 #define PG_GETARG_BYTEA_P_SLICE(n,a,b) DatumGetByteaPSlice(PG_GETARG_DATUM(n),a,b)
283 #define PG_GETARG_TEXT_P_SLICE(n,a,b) DatumGetTextPSlice(PG_GETARG_DATUM(n),a,b)
284 #define PG_GETARG_BPCHAR_P_SLICE(n,a,b) DatumGetBpCharPSlice(PG_GETARG_DATUM(n),a,b)
285 #define PG_GETARG_VARCHAR_P_SLICE(n,a,b) DatumGetVarCharPSlice(PG_GETARG_DATUM(n),a,b)
287 /* To return a NULL do this: */
288 #define PG_RETURN_NULL() \
289 do { fcinfo->isnull = true; return (Datum) 0; } while (0)
291 /* A few internal functions return void (which is not the same as NULL!) */
292 #define PG_RETURN_VOID() return (Datum) 0
294 /* Macros for returning results of standard types */
296 #define PG_RETURN_DATUM(x) return (x)
297 #define PG_RETURN_INT32(x) return Int32GetDatum(x)
298 #define PG_RETURN_UINT32(x) return UInt32GetDatum(x)
299 #define PG_RETURN_INT16(x) return Int16GetDatum(x)
300 #define PG_RETURN_CHAR(x) return CharGetDatum(x)
301 #define PG_RETURN_BOOL(x) return BoolGetDatum(x)
302 #define PG_RETURN_OID(x) return ObjectIdGetDatum(x)
303 #define PG_RETURN_POINTER(x) return PointerGetDatum(x)
304 #define PG_RETURN_CSTRING(x) return CStringGetDatum(x)
305 #define PG_RETURN_NAME(x) return NameGetDatum(x)
306 /* these macros hide the pass-by-reference-ness of the datatype: */
307 #define PG_RETURN_FLOAT4(x) return Float4GetDatum(x)
308 #define PG_RETURN_FLOAT8(x) return Float8GetDatum(x)
309 #define PG_RETURN_INT64(x) return Int64GetDatum(x)
310 /* RETURN macros for other pass-by-ref types will typically look like this: */
311 #define PG_RETURN_BYTEA_P(x) PG_RETURN_POINTER(x)
312 #define PG_RETURN_TEXT_P(x) PG_RETURN_POINTER(x)
313 #define PG_RETURN_BPCHAR_P(x) PG_RETURN_POINTER(x)
314 #define PG_RETURN_VARCHAR_P(x) PG_RETURN_POINTER(x)
315 #define PG_RETURN_HEAPTUPLEHEADER(x) PG_RETURN_POINTER(x)
318 /*-------------------------------------------------------------------------
319 * Support for detecting call convention of dynamically-loaded functions
321 * Dynamically loaded functions may use either the version-1 ("new style")
322 * or version-0 ("old style") calling convention. Version 1 is the call
323 * convention defined in this header file; version 0 is the old "plain C"
324 * convention. A version-1 function must be accompanied by the macro call
326 * PG_FUNCTION_INFO_V1(function_name);
328 * Note that internal functions do not need this decoration since they are
329 * assumed to be version-1.
331 *-------------------------------------------------------------------------
336 int api_version; /* specifies call convention version number */
337 /* More fields may be added later, for version numbers > 1. */
340 /* Expected signature of an info function */
341 typedef const Pg_finfo_record *(*PGFInfoFunction) (void);
344 * Macro to build an info function associated with the given function name.
345 * Win32 loadable functions usually link with 'dlltool --export-all', but it
346 * doesn't hurt to add PGDLLIMPORT in case they don't.
348 #define PG_FUNCTION_INFO_V1(funcname) \
349 extern PGDLLEXPORT const Pg_finfo_record * CppConcat(pg_finfo_,funcname)(void); \
350 const Pg_finfo_record * \
351 CppConcat(pg_finfo_,funcname) (void) \
353 static const Pg_finfo_record my_finfo = { 1 }; \
356 extern int no_such_variable
359 /*-------------------------------------------------------------------------
360 * Support for verifying backend compatibility of loaded modules
362 * We require dynamically-loaded modules to include the macro call
364 * so that we can check for obvious incompatibility, such as being compiled
365 * for a different major PostgreSQL version.
367 * To compile with versions of PostgreSQL that do not support this,
368 * you may put an #ifdef/#endif test around it. Note that in a multiple-
369 * source-file module, the macro call should only appear once.
371 * The specific items included in the magic block are intended to be ones that
372 * are custom-configurable and especially likely to break dynamically loaded
373 * modules if they were compiled with other values. Also, the length field
374 * can be used to detect definition changes.
376 * Note: we compare magic blocks with memcmp(), so there had better not be
377 * any alignment pad bytes in them.
379 * Note: when changing the contents of magic blocks, be sure to adjust the
380 * incompatible_module_error() function in dfmgr.c.
381 *-------------------------------------------------------------------------
384 /* Definition of the magic block structure */
387 int len; /* sizeof(this struct) */
388 int version; /* PostgreSQL major version */
389 int funcmaxargs; /* FUNC_MAX_ARGS */
390 int indexmaxkeys; /* INDEX_MAX_KEYS */
391 int namedatalen; /* NAMEDATALEN */
392 int float4byval; /* FLOAT4PASSBYVAL */
393 int float8byval; /* FLOAT8PASSBYVAL */
396 /* The actual data block contents */
397 #define PG_MODULE_MAGIC_DATA \
399 sizeof(Pg_magic_struct), \
400 PG_VERSION_NUM / 100, \
409 * Declare the module magic function. It needs to be a function as the dlsym
410 * in the backend is only guaranteed to work on functions, not data
412 typedef const Pg_magic_struct *(*PGModuleMagicFunction) (void);
414 #define PG_MAGIC_FUNCTION_NAME Pg_magic_func
415 #define PG_MAGIC_FUNCTION_NAME_STRING "Pg_magic_func"
417 #define PG_MODULE_MAGIC \
418 extern PGDLLEXPORT const Pg_magic_struct *PG_MAGIC_FUNCTION_NAME(void); \
419 const Pg_magic_struct * \
420 PG_MAGIC_FUNCTION_NAME(void) \
422 static const Pg_magic_struct Pg_magic_data = PG_MODULE_MAGIC_DATA; \
423 return &Pg_magic_data; \
425 extern int no_such_variable
428 /*-------------------------------------------------------------------------
429 * Support routines and macros for callers of fmgr-compatible functions
430 *-------------------------------------------------------------------------
433 /* These are for invocation of a specifically named function with a
434 * directly-computed parameter list. Note that neither arguments nor result
435 * are allowed to be NULL.
437 extern Datum DirectFunctionCall1(PGFunction func, Datum arg1);
438 extern Datum DirectFunctionCall2(PGFunction func, Datum arg1, Datum arg2);
439 extern Datum DirectFunctionCall3(PGFunction func, Datum arg1, Datum arg2,
441 extern Datum DirectFunctionCall4(PGFunction func, Datum arg1, Datum arg2,
442 Datum arg3, Datum arg4);
443 extern Datum DirectFunctionCall5(PGFunction func, Datum arg1, Datum arg2,
444 Datum arg3, Datum arg4, Datum arg5);
445 extern Datum DirectFunctionCall6(PGFunction func, Datum arg1, Datum arg2,
446 Datum arg3, Datum arg4, Datum arg5,
448 extern Datum DirectFunctionCall7(PGFunction func, Datum arg1, Datum arg2,
449 Datum arg3, Datum arg4, Datum arg5,
450 Datum arg6, Datum arg7);
451 extern Datum DirectFunctionCall8(PGFunction func, Datum arg1, Datum arg2,
452 Datum arg3, Datum arg4, Datum arg5,
453 Datum arg6, Datum arg7, Datum arg8);
454 extern Datum DirectFunctionCall9(PGFunction func, Datum arg1, Datum arg2,
455 Datum arg3, Datum arg4, Datum arg5,
456 Datum arg6, Datum arg7, Datum arg8,
459 /* The same, but passing a collation to use */
460 extern Datum DirectFunctionCall1WithCollation(PGFunction func, Oid collation,
462 extern Datum DirectFunctionCall2WithCollation(PGFunction func, Oid collation,
463 Datum arg1, Datum arg2);
465 /* These are for invocation of a previously-looked-up function with a
466 * directly-computed parameter list. Note that neither arguments nor result
467 * are allowed to be NULL.
469 extern Datum FunctionCall1(FmgrInfo *flinfo, Datum arg1);
470 extern Datum FunctionCall2(FmgrInfo *flinfo, Datum arg1, Datum arg2);
471 extern Datum FunctionCall3(FmgrInfo *flinfo, Datum arg1, Datum arg2,
473 extern Datum FunctionCall4(FmgrInfo *flinfo, Datum arg1, Datum arg2,
474 Datum arg3, Datum arg4);
475 extern Datum FunctionCall5(FmgrInfo *flinfo, Datum arg1, Datum arg2,
476 Datum arg3, Datum arg4, Datum arg5);
477 extern Datum FunctionCall6(FmgrInfo *flinfo, Datum arg1, Datum arg2,
478 Datum arg3, Datum arg4, Datum arg5,
480 extern Datum FunctionCall7(FmgrInfo *flinfo, Datum arg1, Datum arg2,
481 Datum arg3, Datum arg4, Datum arg5,
482 Datum arg6, Datum arg7);
483 extern Datum FunctionCall8(FmgrInfo *flinfo, Datum arg1, Datum arg2,
484 Datum arg3, Datum arg4, Datum arg5,
485 Datum arg6, Datum arg7, Datum arg8);
486 extern Datum FunctionCall9(FmgrInfo *flinfo, Datum arg1, Datum arg2,
487 Datum arg3, Datum arg4, Datum arg5,
488 Datum arg6, Datum arg7, Datum arg8,
491 /* These are for invocation of a function identified by OID with a
492 * directly-computed parameter list. Note that neither arguments nor result
493 * are allowed to be NULL. These are essentially FunctionLookup() followed
494 * by FunctionCallN(). If the same function is to be invoked repeatedly,
495 * do the FunctionLookup() once and then use FunctionCallN().
497 extern Datum OidFunctionCall0(Oid functionId);
498 extern Datum OidFunctionCall1(Oid functionId, Datum arg1);
499 extern Datum OidFunctionCall2(Oid functionId, Datum arg1, Datum arg2);
500 extern Datum OidFunctionCall3(Oid functionId, Datum arg1, Datum arg2,
502 extern Datum OidFunctionCall4(Oid functionId, Datum arg1, Datum arg2,
503 Datum arg3, Datum arg4);
504 extern Datum OidFunctionCall5(Oid functionId, Datum arg1, Datum arg2,
505 Datum arg3, Datum arg4, Datum arg5);
506 extern Datum OidFunctionCall6(Oid functionId, Datum arg1, Datum arg2,
507 Datum arg3, Datum arg4, Datum arg5,
509 extern Datum OidFunctionCall7(Oid functionId, Datum arg1, Datum arg2,
510 Datum arg3, Datum arg4, Datum arg5,
511 Datum arg6, Datum arg7);
512 extern Datum OidFunctionCall8(Oid functionId, Datum arg1, Datum arg2,
513 Datum arg3, Datum arg4, Datum arg5,
514 Datum arg6, Datum arg7, Datum arg8);
515 extern Datum OidFunctionCall9(Oid functionId, Datum arg1, Datum arg2,
516 Datum arg3, Datum arg4, Datum arg5,
517 Datum arg6, Datum arg7, Datum arg8,
520 /* Special cases for convenient invocation of datatype I/O functions. */
521 extern Datum InputFunctionCall(FmgrInfo *flinfo, char *str,
522 Oid typioparam, int32 typmod);
523 extern Datum OidInputFunctionCall(Oid functionId, char *str,
524 Oid typioparam, int32 typmod);
525 extern char *OutputFunctionCall(FmgrInfo *flinfo, Datum val);
526 extern char *OidOutputFunctionCall(Oid functionId, Datum val);
527 extern Datum ReceiveFunctionCall(FmgrInfo *flinfo, fmStringInfo buf,
528 Oid typioparam, int32 typmod);
529 extern Datum OidReceiveFunctionCall(Oid functionId, fmStringInfo buf,
530 Oid typioparam, int32 typmod);
531 extern bytea *SendFunctionCall(FmgrInfo *flinfo, Datum val);
532 extern bytea *OidSendFunctionCall(Oid functionId, Datum val);
538 extern const Pg_finfo_record *fetch_finfo_record(void *filehandle, char *funcname);
539 extern void clear_external_function_hash(void *filehandle);
540 extern Oid fmgr_internal_function(const char *proname);
541 extern Oid get_fn_expr_rettype(FmgrInfo *flinfo);
542 extern Oid get_fn_expr_argtype(FmgrInfo *flinfo, int argnum);
543 extern Oid get_call_expr_argtype(fmNodePtr expr, int argnum);
544 extern bool get_fn_expr_arg_stable(FmgrInfo *flinfo, int argnum);
545 extern bool get_call_expr_arg_stable(fmNodePtr expr, int argnum);
548 * Routines in dfmgr.c
550 extern char *Dynamic_library_path;
552 extern PGFunction load_external_function(char *filename, char *funcname,
553 bool signalNotFound, void **filehandle);
554 extern PGFunction lookup_external_function(void *filehandle, char *funcname);
555 extern void load_file(const char *filename, bool restricted);
556 extern void **find_rendezvous_variable(const char *varName);
559 * Support for aggregate functions
561 * This is actually in executor/nodeAgg.c, but we declare it here since the
562 * whole point is for callers of it to not be overly friendly with nodeAgg.
565 /* AggCheckCallContext can return one of the following codes, or 0: */
566 #define AGG_CONTEXT_AGGREGATE 1 /* regular aggregate */
567 #define AGG_CONTEXT_WINDOW 2 /* window function */
569 extern int AggCheckCallContext(FunctionCallInfo fcinfo,
570 MemoryContext *aggcontext);
573 * We allow plugin modules to hook function entry/exit. This is intended
574 * as support for loadable security policy modules, which may want to
575 * perform additional privilege checks on function entry or exit, or to do
576 * other internal bookkeeping. To make this possible, such modules must be
577 * able not only to support normal function entry and exit, but also to trap
578 * the case where we bail out due to an error; and they must also be able to
581 typedef enum FmgrHookEventType
588 typedef bool (*needs_fmgr_hook_type)(Oid fn_oid);
590 typedef void (*fmgr_hook_type)(FmgrHookEventType event,
591 FmgrInfo *flinfo, Datum *arg);
593 extern PGDLLIMPORT needs_fmgr_hook_type needs_fmgr_hook;
594 extern PGDLLIMPORT fmgr_hook_type fmgr_hook;
596 #define FmgrHookIsNeeded(fn_oid) \
597 (!needs_fmgr_hook ? false : (*needs_fmgr_hook)(fn_oid))
600 * !!! OLD INTERFACE !!!
602 * fmgr() is the only remaining vestige of the old-style caller support
603 * functions. It's no longer used anywhere in the Postgres distribution,
604 * but we should leave it around for a release or two to ease the transition
605 * for user-supplied C functions. OidFunctionCallN() replaces it for new
610 * DEPRECATED, DO NOT USE IN NEW CODE
612 extern char *fmgr(Oid procedureId,...);