PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
fmgr.c File Reference
#include "postgres.h"
#include "access/tuptoaster.h"
#include "catalog/pg_language.h"
#include "catalog/pg_proc.h"
#include "executor/functions.h"
#include "lib/stringinfo.h"
#include "miscadmin.h"
#include "nodes/nodeFuncs.h"
#include "pgstat.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/fmgrtab.h"
#include "utils/guc.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
Include dependency graph for fmgr.c:

Go to the source code of this file.

Data Structures

struct  CFuncHashTabEntry
 
struct  fmgr_security_definer_cache
 

Functions

static void fmgr_info_cxt_security (Oid functionId, FmgrInfo *finfo, MemoryContext mcxt, bool ignore_security)
 
static void fmgr_info_C_lang (Oid functionId, FmgrInfo *finfo, HeapTuple procedureTuple)
 
static void fmgr_info_other_lang (Oid functionId, FmgrInfo *finfo, HeapTuple procedureTuple)
 
static CFuncHashTabEntrylookup_C_func (HeapTuple procedureTuple)
 
static void record_C_func (HeapTuple procedureTuple, PGFunction user_fn, const Pg_finfo_record *inforec)
 
static Datum fmgr_security_definer (PG_FUNCTION_ARGS)
 
static const FmgrBuiltinfmgr_isbuiltin (Oid id)
 
static const FmgrBuiltinfmgr_lookupByName (const char *name)
 
void fmgr_info (Oid functionId, FmgrInfo *finfo)
 
void fmgr_info_cxt (Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
 
const Pg_finfo_recordfetch_finfo_record (void *filehandle, const char *funcname)
 
void clear_external_function_hash (void *filehandle)
 
void fmgr_info_copy (FmgrInfo *dstinfo, FmgrInfo *srcinfo, MemoryContext destcxt)
 
Oid fmgr_internal_function (const char *proname)
 
Datum DirectFunctionCall1Coll (PGFunction func, Oid collation, Datum arg1)
 
Datum DirectFunctionCall2Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2)
 
Datum DirectFunctionCall3Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3)
 
Datum DirectFunctionCall4Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4)
 
Datum DirectFunctionCall5Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5)
 
Datum DirectFunctionCall6Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6)
 
Datum DirectFunctionCall7Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7)
 
Datum DirectFunctionCall8Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8)
 
Datum DirectFunctionCall9Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8, Datum arg9)
 
Datum CallerFInfoFunctionCall1 (PGFunction func, FmgrInfo *flinfo, Oid collation, Datum arg1)
 
Datum CallerFInfoFunctionCall2 (PGFunction func, FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
 
Datum FunctionCall1Coll (FmgrInfo *flinfo, Oid collation, Datum arg1)
 
Datum FunctionCall2Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
 
Datum FunctionCall3Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3)
 
Datum FunctionCall4Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4)
 
Datum FunctionCall5Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5)
 
Datum FunctionCall6Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6)
 
Datum FunctionCall7Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7)
 
Datum FunctionCall8Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8)
 
Datum FunctionCall9Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8, Datum arg9)
 
Datum OidFunctionCall0Coll (Oid functionId, Oid collation)
 
Datum OidFunctionCall1Coll (Oid functionId, Oid collation, Datum arg1)
 
Datum OidFunctionCall2Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2)
 
Datum OidFunctionCall3Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3)
 
Datum OidFunctionCall4Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4)
 
Datum OidFunctionCall5Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5)
 
Datum OidFunctionCall6Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6)
 
Datum OidFunctionCall7Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7)
 
Datum OidFunctionCall8Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8)
 
Datum OidFunctionCall9Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8, Datum arg9)
 
Datum InputFunctionCall (FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
 
char * OutputFunctionCall (FmgrInfo *flinfo, Datum val)
 
Datum ReceiveFunctionCall (FmgrInfo *flinfo, StringInfo buf, Oid typioparam, int32 typmod)
 
byteaSendFunctionCall (FmgrInfo *flinfo, Datum val)
 
Datum OidInputFunctionCall (Oid functionId, char *str, Oid typioparam, int32 typmod)
 
char * OidOutputFunctionCall (Oid functionId, Datum val)
 
Datum OidReceiveFunctionCall (Oid functionId, StringInfo buf, Oid typioparam, int32 typmod)
 
byteaOidSendFunctionCall (Oid functionId, Datum val)
 
Datum Int64GetDatum (int64 X)
 
Datum Float4GetDatum (float4 X)
 
Datum Float8GetDatum (float8 X)
 
struct varlenapg_detoast_datum (struct varlena *datum)
 
struct varlenapg_detoast_datum_copy (struct varlena *datum)
 
struct varlenapg_detoast_datum_slice (struct varlena *datum, int32 first, int32 count)
 
struct varlenapg_detoast_datum_packed (struct varlena *datum)
 
Oid get_fn_expr_rettype (FmgrInfo *flinfo)
 
Oid get_fn_expr_argtype (FmgrInfo *flinfo, int argnum)
 
Oid get_call_expr_argtype (Node *expr, int argnum)
 
bool get_fn_expr_arg_stable (FmgrInfo *flinfo, int argnum)
 
bool get_call_expr_arg_stable (Node *expr, int argnum)
 
bool get_fn_expr_variadic (FmgrInfo *flinfo)
 
bool CheckFunctionValidatorAccess (Oid validatorOid, Oid functionOid)
 

Variables

PGDLLIMPORT needs_fmgr_hook_type needs_fmgr_hook = NULL
 
PGDLLIMPORT fmgr_hook_type fmgr_hook = NULL
 
static HTABCFuncHash = NULL
 

Function Documentation

Datum CallerFInfoFunctionCall1 ( PGFunction  func,
FmgrInfo flinfo,
Oid  collation,
Datum  arg1 
)

Definition at line 980 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

981 {
982  FunctionCallInfoData fcinfo;
983  Datum result;
984 
985  InitFunctionCallInfoData(fcinfo, flinfo, 1, collation, NULL, NULL);
986 
987  fcinfo.arg[0] = arg1;
988  fcinfo.argnull[0] = false;
989 
990  result = (*func) (&fcinfo);
991 
992  /* Check for null result, since caller is clearly not expecting one */
993  if (fcinfo.isnull)
994  elog(ERROR, "function %p returned NULL", (void *) func);
995 
996  return result;
997 }
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum CallerFInfoFunctionCall2 ( PGFunction  func,
FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2 
)

Definition at line 1000 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

Referenced by gbt_enumge(), gbt_enumgt(), gbt_enumkey_cmp(), gbt_enumle(), gbt_enumlt(), gin_btree_compare_prefix(), and gin_enum_cmp().

1001 {
1002  FunctionCallInfoData fcinfo;
1003  Datum result;
1004 
1005  InitFunctionCallInfoData(fcinfo, flinfo, 2, collation, NULL, NULL);
1006 
1007  fcinfo.arg[0] = arg1;
1008  fcinfo.arg[1] = arg2;
1009  fcinfo.argnull[0] = false;
1010  fcinfo.argnull[1] = false;
1011 
1012  result = (*func) (&fcinfo);
1013 
1014  /* Check for null result, since caller is clearly not expecting one */
1015  if (fcinfo.isnull)
1016  elog(ERROR, "function %p returned NULL", (void *) func);
1017 
1018  return result;
1019 }
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
bool CheckFunctionValidatorAccess ( Oid  validatorOid,
Oid  functionOid 
)

Definition at line 2101 of file fmgr.c.

References ACL_EXECUTE, ACL_KIND_LANGUAGE, ACL_KIND_PROC, ACL_USAGE, aclcheck_error(), ACLCHECK_OK, elog, ereport, errcode(), errmsg(), ERROR, GETSTRUCT, GetUserId(), HeapTupleIsValid, LANGOID, NameStr, ObjectIdGetDatum, pg_language_aclcheck(), pg_proc_aclcheck(), PROCOID, ReleaseSysCache(), and SearchSysCache1.

Referenced by fmgr_c_validator(), fmgr_internal_validator(), fmgr_sql_validator(), plperl_validator(), plpgsql_validator(), and plpython_validator().

2102 {
2103  HeapTuple procTup;
2104  HeapTuple langTup;
2105  Form_pg_proc procStruct;
2106  Form_pg_language langStruct;
2107  AclResult aclresult;
2108 
2109  /*
2110  * Get the function's pg_proc entry. Throw a user-facing error for bad
2111  * OID, because validators can be called with user-specified OIDs.
2112  */
2113  procTup = SearchSysCache1(PROCOID, ObjectIdGetDatum(functionOid));
2114  if (!HeapTupleIsValid(procTup))
2115  ereport(ERROR,
2116  (errcode(ERRCODE_UNDEFINED_FUNCTION),
2117  errmsg("function with OID %u does not exist", functionOid)));
2118  procStruct = (Form_pg_proc) GETSTRUCT(procTup);
2119 
2120  /*
2121  * Fetch pg_language entry to know if this is the correct validation
2122  * function for that pg_proc entry.
2123  */
2124  langTup = SearchSysCache1(LANGOID, ObjectIdGetDatum(procStruct->prolang));
2125  if (!HeapTupleIsValid(langTup))
2126  elog(ERROR, "cache lookup failed for language %u", procStruct->prolang);
2127  langStruct = (Form_pg_language) GETSTRUCT(langTup);
2128 
2129  if (langStruct->lanvalidator != validatorOid)
2130  ereport(ERROR,
2131  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2132  errmsg("language validation function %u called for language %u instead of %u",
2133  validatorOid, procStruct->prolang,
2134  langStruct->lanvalidator)));
2135 
2136  /* first validate that we have permissions to use the language */
2137  aclresult = pg_language_aclcheck(procStruct->prolang, GetUserId(),
2138  ACL_USAGE);
2139  if (aclresult != ACLCHECK_OK)
2140  aclcheck_error(aclresult, ACL_KIND_LANGUAGE,
2141  NameStr(langStruct->lanname));
2142 
2143  /*
2144  * Check whether we are allowed to execute the function itself. If we can
2145  * execute it, there should be no possible side-effect of
2146  * compiling/validation that execution can't have.
2147  */
2148  aclresult = pg_proc_aclcheck(functionOid, GetUserId(), ACL_EXECUTE);
2149  if (aclresult != ACLCHECK_OK)
2150  aclcheck_error(aclresult, ACL_KIND_PROC, NameStr(procStruct->proname));
2151 
2152  ReleaseSysCache(procTup);
2153  ReleaseSysCache(langTup);
2154 
2155  return true;
2156 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
Oid GetUserId(void)
Definition: miscinit.c:283
int errcode(int sqlerrcode)
Definition: elog.c:575
AclResult pg_language_aclcheck(Oid lang_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4458
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:152
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
void aclcheck_error(AclResult aclerr, AclObjectKind objectkind, const char *objectname)
Definition: aclchk.c:3399
#define ACL_USAGE
Definition: parsenodes.h:80
#define ereport(elevel, rest)
Definition: elog.h:122
AclResult
Definition: acl.h:170
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:83
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
FormData_pg_language * Form_pg_language
Definition: pg_language.h:51
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define ACL_EXECUTE
Definition: parsenodes.h:79
AclResult pg_proc_aclcheck(Oid proc_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4446
#define NameStr(name)
Definition: c.h:499
#define elog
Definition: elog.h:219
void clear_external_function_hash ( void *  filehandle)

Definition at line 508 of file fmgr.c.

References hash_destroy(), and NULL.

Referenced by internal_unload_library().

509 {
510  if (CFuncHash)
512  CFuncHash = NULL;
513 }
void hash_destroy(HTAB *hashp)
Definition: dynahash.c:793
static HTAB * CFuncHash
Definition: fmgr.c:52
#define NULL
Definition: c.h:229
Datum DirectFunctionCall1Coll ( PGFunction  func,
Oid  collation,
Datum  arg1 
)

Definition at line 707 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

Referenced by Generic_Text_IC_like(), and libpqrcv_create_slot().

708 {
709  FunctionCallInfoData fcinfo;
710  Datum result;
711 
712  InitFunctionCallInfoData(fcinfo, NULL, 1, collation, NULL, NULL);
713 
714  fcinfo.arg[0] = arg1;
715  fcinfo.argnull[0] = false;
716 
717  result = (*func) (&fcinfo);
718 
719  /* Check for null result, since caller is clearly not expecting one */
720  if (fcinfo.isnull)
721  elog(ERROR, "function %p returned NULL", (void *) func);
722 
723  return result;
724 }
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum DirectFunctionCall2Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2 
)

Definition at line 727 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

Referenced by gbt_textcmp(), gbt_texteq(), gbt_textge(), gbt_textgt(), gbt_textle(), and gbt_textlt().

728 {
729  FunctionCallInfoData fcinfo;
730  Datum result;
731 
732  InitFunctionCallInfoData(fcinfo, NULL, 2, collation, NULL, NULL);
733 
734  fcinfo.arg[0] = arg1;
735  fcinfo.arg[1] = arg2;
736  fcinfo.argnull[0] = false;
737  fcinfo.argnull[1] = false;
738 
739  result = (*func) (&fcinfo);
740 
741  /* Check for null result, since caller is clearly not expecting one */
742  if (fcinfo.isnull)
743  elog(ERROR, "function %p returned NULL", (void *) func);
744 
745  return result;
746 }
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum DirectFunctionCall3Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3 
)

Definition at line 749 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

751 {
752  FunctionCallInfoData fcinfo;
753  Datum result;
754 
755  InitFunctionCallInfoData(fcinfo, NULL, 3, collation, NULL, NULL);
756 
757  fcinfo.arg[0] = arg1;
758  fcinfo.arg[1] = arg2;
759  fcinfo.arg[2] = arg3;
760  fcinfo.argnull[0] = false;
761  fcinfo.argnull[1] = false;
762  fcinfo.argnull[2] = false;
763 
764  result = (*func) (&fcinfo);
765 
766  /* Check for null result, since caller is clearly not expecting one */
767  if (fcinfo.isnull)
768  elog(ERROR, "function %p returned NULL", (void *) func);
769 
770  return result;
771 }
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum DirectFunctionCall4Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4 
)

Definition at line 774 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

Referenced by execute_extension_script().

776 {
777  FunctionCallInfoData fcinfo;
778  Datum result;
779 
780  InitFunctionCallInfoData(fcinfo, NULL, 4, collation, NULL, NULL);
781 
782  fcinfo.arg[0] = arg1;
783  fcinfo.arg[1] = arg2;
784  fcinfo.arg[2] = arg3;
785  fcinfo.arg[3] = arg4;
786  fcinfo.argnull[0] = false;
787  fcinfo.argnull[1] = false;
788  fcinfo.argnull[2] = false;
789  fcinfo.argnull[3] = false;
790 
791  result = (*func) (&fcinfo);
792 
793  /* Check for null result, since caller is clearly not expecting one */
794  if (fcinfo.isnull)
795  elog(ERROR, "function %p returned NULL", (void *) func);
796 
797  return result;
798 }
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum DirectFunctionCall5Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5 
)

Definition at line 801 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

803 {
804  FunctionCallInfoData fcinfo;
805  Datum result;
806 
807  InitFunctionCallInfoData(fcinfo, NULL, 5, collation, NULL, NULL);
808 
809  fcinfo.arg[0] = arg1;
810  fcinfo.arg[1] = arg2;
811  fcinfo.arg[2] = arg3;
812  fcinfo.arg[3] = arg4;
813  fcinfo.arg[4] = arg5;
814  fcinfo.argnull[0] = false;
815  fcinfo.argnull[1] = false;
816  fcinfo.argnull[2] = false;
817  fcinfo.argnull[3] = false;
818  fcinfo.argnull[4] = false;
819 
820  result = (*func) (&fcinfo);
821 
822  /* Check for null result, since caller is clearly not expecting one */
823  if (fcinfo.isnull)
824  elog(ERROR, "function %p returned NULL", (void *) func);
825 
826  return result;
827 }
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum DirectFunctionCall6Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6 
)

Definition at line 830 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

833 {
834  FunctionCallInfoData fcinfo;
835  Datum result;
836 
837  InitFunctionCallInfoData(fcinfo, NULL, 6, collation, NULL, NULL);
838 
839  fcinfo.arg[0] = arg1;
840  fcinfo.arg[1] = arg2;
841  fcinfo.arg[2] = arg3;
842  fcinfo.arg[3] = arg4;
843  fcinfo.arg[4] = arg5;
844  fcinfo.arg[5] = arg6;
845  fcinfo.argnull[0] = false;
846  fcinfo.argnull[1] = false;
847  fcinfo.argnull[2] = false;
848  fcinfo.argnull[3] = false;
849  fcinfo.argnull[4] = false;
850  fcinfo.argnull[5] = false;
851 
852  result = (*func) (&fcinfo);
853 
854  /* Check for null result, since caller is clearly not expecting one */
855  if (fcinfo.isnull)
856  elog(ERROR, "function %p returned NULL", (void *) func);
857 
858  return result;
859 }
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum DirectFunctionCall7Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7 
)

Definition at line 862 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

865 {
866  FunctionCallInfoData fcinfo;
867  Datum result;
868 
869  InitFunctionCallInfoData(fcinfo, NULL, 7, collation, NULL, NULL);
870 
871  fcinfo.arg[0] = arg1;
872  fcinfo.arg[1] = arg2;
873  fcinfo.arg[2] = arg3;
874  fcinfo.arg[3] = arg4;
875  fcinfo.arg[4] = arg5;
876  fcinfo.arg[5] = arg6;
877  fcinfo.arg[6] = arg7;
878  fcinfo.argnull[0] = false;
879  fcinfo.argnull[1] = false;
880  fcinfo.argnull[2] = false;
881  fcinfo.argnull[3] = false;
882  fcinfo.argnull[4] = false;
883  fcinfo.argnull[5] = false;
884  fcinfo.argnull[6] = false;
885 
886  result = (*func) (&fcinfo);
887 
888  /* Check for null result, since caller is clearly not expecting one */
889  if (fcinfo.isnull)
890  elog(ERROR, "function %p returned NULL", (void *) func);
891 
892  return result;
893 }
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum DirectFunctionCall8Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7,
Datum  arg8 
)

Definition at line 896 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

899 {
900  FunctionCallInfoData fcinfo;
901  Datum result;
902 
903  InitFunctionCallInfoData(fcinfo, NULL, 8, collation, NULL, NULL);
904 
905  fcinfo.arg[0] = arg1;
906  fcinfo.arg[1] = arg2;
907  fcinfo.arg[2] = arg3;
908  fcinfo.arg[3] = arg4;
909  fcinfo.arg[4] = arg5;
910  fcinfo.arg[5] = arg6;
911  fcinfo.arg[6] = arg7;
912  fcinfo.arg[7] = arg8;
913  fcinfo.argnull[0] = false;
914  fcinfo.argnull[1] = false;
915  fcinfo.argnull[2] = false;
916  fcinfo.argnull[3] = false;
917  fcinfo.argnull[4] = false;
918  fcinfo.argnull[5] = false;
919  fcinfo.argnull[6] = false;
920  fcinfo.argnull[7] = false;
921 
922  result = (*func) (&fcinfo);
923 
924  /* Check for null result, since caller is clearly not expecting one */
925  if (fcinfo.isnull)
926  elog(ERROR, "function %p returned NULL", (void *) func);
927 
928  return result;
929 }
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum DirectFunctionCall9Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7,
Datum  arg8,
Datum  arg9 
)

Definition at line 932 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

936 {
937  FunctionCallInfoData fcinfo;
938  Datum result;
939 
940  InitFunctionCallInfoData(fcinfo, NULL, 9, collation, NULL, NULL);
941 
942  fcinfo.arg[0] = arg1;
943  fcinfo.arg[1] = arg2;
944  fcinfo.arg[2] = arg3;
945  fcinfo.arg[3] = arg4;
946  fcinfo.arg[4] = arg5;
947  fcinfo.arg[5] = arg6;
948  fcinfo.arg[6] = arg7;
949  fcinfo.arg[7] = arg8;
950  fcinfo.arg[8] = arg9;
951  fcinfo.argnull[0] = false;
952  fcinfo.argnull[1] = false;
953  fcinfo.argnull[2] = false;
954  fcinfo.argnull[3] = false;
955  fcinfo.argnull[4] = false;
956  fcinfo.argnull[5] = false;
957  fcinfo.argnull[6] = false;
958  fcinfo.argnull[7] = false;
959  fcinfo.argnull[8] = false;
960 
961  result = (*func) (&fcinfo);
962 
963  /* Check for null result, since caller is clearly not expecting one */
964  if (fcinfo.isnull)
965  elog(ERROR, "function %p returned NULL", (void *) func);
966 
967  return result;
968 }
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
const Pg_finfo_record* fetch_finfo_record ( void *  filehandle,
const char *  funcname 
)

Definition at line 384 of file fmgr.c.

References Pg_finfo_record::api_version, elog, ereport, errcode(), errhint(), errmsg(), ERROR, lookup_external_function(), NULL, pfree(), and psprintf().

Referenced by fmgr_c_validator(), and fmgr_info_C_lang().

385 {
386  char *infofuncname;
387  PGFInfoFunction infofunc;
388  const Pg_finfo_record *inforec;
389 
390  infofuncname = psprintf("pg_finfo_%s", funcname);
391 
392  /* Try to look up the info function */
393  infofunc = (PGFInfoFunction) lookup_external_function(filehandle,
394  infofuncname);
395  if (infofunc == NULL)
396  {
397  ereport(ERROR,
398  (errcode(ERRCODE_UNDEFINED_FUNCTION),
399  errmsg("could not find function information for function \"%s\"",
400  funcname),
401  errhint("SQL-callable functions need an accompanying PG_FUNCTION_INFO_V1(funcname).")));
402  return NULL; /* silence compiler */
403  }
404 
405  /* Found, so call it */
406  inforec = (*infofunc) ();
407 
408  /* Validate result as best we can */
409  if (inforec == NULL)
410  elog(ERROR, "null result from info function \"%s\"", infofuncname);
411  switch (inforec->api_version)
412  {
413  case 1:
414  /* OK, no additional fields to validate */
415  break;
416  default:
417  ereport(ERROR,
418  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
419  errmsg("unrecognized API version %d reported by info function \"%s\"",
420  inforec->api_version, infofuncname)));
421  break;
422  }
423 
424  pfree(infofuncname);
425  return inforec;
426 }
PGFunction lookup_external_function(void *filehandle, const char *funcname)
Definition: dfmgr.c:162
int errhint(const char *fmt,...)
Definition: elog.c:987
const Pg_finfo_record *(* PGFInfoFunction)(void)
Definition: fmgr.h:359
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
int errcode(int sqlerrcode)
Definition: elog.c:575
void pfree(void *pointer)
Definition: mcxt.c:950
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define NULL
Definition: c.h:229
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219
int api_version
Definition: fmgr.h:354
Datum Float4GetDatum ( float4  X)

Definition at line 1803 of file fmgr.c.

References palloc(), and PointerGetDatum.

Referenced by AddEnumLabel(), EnumValuesCreate(), gbt_num_fetch(), getNextNearest(), InsertPgClassTuple(), leftmostvalue_float4(), ProcedureCreate(), set_limit(), and update_attstats().

1804 {
1805  float4 *retval = (float4 *) palloc(sizeof(float4));
1806 
1807  *retval = X;
1808  return PointerGetDatum(retval);
1809 }
#define PointerGetDatum(X)
Definition: postgres.h:562
float float4
Definition: c.h:380
void * palloc(Size size)
Definition: mcxt.c:849
Datum Float8GetDatum ( float8  X)

Definition at line 1815 of file fmgr.c.

References palloc(), and PointerGetDatum.

Referenced by assign_random_seed(), compute_range_stats(), float8_lerp(), gbt_num_fetch(), getNextNearest(), hash_metapage_info(), int8_to_char(), interval_avg(), leftmostvalue_float8(), normal_rand(), pgstathashindex(), pgstattuple_approx_internal(), and spg_kd_picksplit().

1816 {
1817  float8 *retval = (float8 *) palloc(sizeof(float8));
1818 
1819  *retval = X;
1820  return PointerGetDatum(retval);
1821 }
#define PointerGetDatum(X)
Definition: postgres.h:562
double float8
Definition: c.h:381
void * palloc(Size size)
Definition: mcxt.c:849
void fmgr_info ( Oid  functionId,
FmgrInfo finfo 
)

Definition at line 127 of file fmgr.c.

References CurrentMemoryContext, and fmgr_info_cxt_security().

Referenced by _bt_find_extreme_element(), _bt_sort_array_elements(), _sv_to_datum_finfo(), BeginCopyFrom(), brin_page_items(), build_pertrans_for_aggref(), call_pltcl_start_proc(), compute_distinct_stats(), CopyTo(), eqjoinsel_inner(), eqjoinsel_semi(), EventTriggerInvoke(), ExecCallTriggerFunc(), ExecHashTableCreate(), ExecInitAgg(), ExecInitExprRec(), ExecInitFunc(), ExecInitSubPlan(), ExecInitTableFuncScan(), execTuplesHashPrepare(), execTuplesMatchPrepare(), fetch_fp_info(), get_variable_range(), inet_mcv_join_sel(), initialize_peragg(), ltreeparentsel(), networkjoinsel_semi(), networksel(), OidFunctionCall0Coll(), OidFunctionCall1Coll(), OidFunctionCall2Coll(), OidFunctionCall3Coll(), OidFunctionCall4Coll(), OidFunctionCall5Coll(), OidFunctionCall6Coll(), OidFunctionCall7Coll(), OidFunctionCall8Coll(), OidFunctionCall9Coll(), OidInputFunctionCall(), OidOutputFunctionCall(), OidReceiveFunctionCall(), OidSendFunctionCall(), patternsel(), plperl_ref_from_pg_array(), postgresBeginForeignModify(), prefix_quals(), prefix_selectivity(), prepare_query_params(), printtup_prepare_info(), RelationBuildPartitionKey(), scalararraysel(), scalarineqsel(), ScanKeyEntryInitialize(), ScanKeyInit(), text_format(), TupleDescGetAttInMetadata(), and var_eq_const().

128 {
129  fmgr_info_cxt_security(functionId, finfo, CurrentMemoryContext, false);
130 }
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
static void fmgr_info_cxt_security(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt, bool ignore_security)
Definition: fmgr.c:147
static void fmgr_info_C_lang ( Oid  functionId,
FmgrInfo finfo,
HeapTuple  procedureTuple 
)
static

Definition at line 273 of file fmgr.c.

References Anum_pg_proc_probin, Anum_pg_proc_prosrc, Pg_finfo_record::api_version, elog, ERROR, fetch_finfo_record(), FmgrInfo::fn_addr, CFuncHashTabEntry::inforec, load_external_function(), lookup_C_func(), pfree(), PROCOID, record_C_func(), SysCacheGetAttr(), TextDatumGetCString, and CFuncHashTabEntry::user_fn.

Referenced by fmgr_info_cxt_security().

274 {
275  CFuncHashTabEntry *hashentry;
276  PGFunction user_fn;
277  const Pg_finfo_record *inforec;
278  bool isnull;
279 
280  /*
281  * See if we have the function address cached already
282  */
283  hashentry = lookup_C_func(procedureTuple);
284  if (hashentry)
285  {
286  user_fn = hashentry->user_fn;
287  inforec = hashentry->inforec;
288  }
289  else
290  {
291  Datum prosrcattr,
292  probinattr;
293  char *prosrcstring,
294  *probinstring;
295  void *libraryhandle;
296 
297  /*
298  * Get prosrc and probin strings (link symbol and library filename).
299  * While in general these columns might be null, that's not allowed
300  * for C-language functions.
301  */
302  prosrcattr = SysCacheGetAttr(PROCOID, procedureTuple,
303  Anum_pg_proc_prosrc, &isnull);
304  if (isnull)
305  elog(ERROR, "null prosrc for C function %u", functionId);
306  prosrcstring = TextDatumGetCString(prosrcattr);
307 
308  probinattr = SysCacheGetAttr(PROCOID, procedureTuple,
309  Anum_pg_proc_probin, &isnull);
310  if (isnull)
311  elog(ERROR, "null probin for C function %u", functionId);
312  probinstring = TextDatumGetCString(probinattr);
313 
314  /* Look up the function itself */
315  user_fn = load_external_function(probinstring, prosrcstring, true,
316  &libraryhandle);
317 
318  /* Get the function information record (real or default) */
319  inforec = fetch_finfo_record(libraryhandle, prosrcstring);
320 
321  /* Cache the addresses for later calls */
322  record_C_func(procedureTuple, user_fn, inforec);
323 
324  pfree(prosrcstring);
325  pfree(probinstring);
326  }
327 
328  switch (inforec->api_version)
329  {
330  case 1:
331  /* New style: call directly */
332  finfo->fn_addr = user_fn;
333  break;
334  default:
335  /* Shouldn't get here if fetch_finfo_record did its job */
336  elog(ERROR, "unrecognized function API version: %d",
337  inforec->api_version);
338  break;
339  }
340 }
PGFunction fn_addr
Definition: fmgr.h:58
Datum(* PGFunction)(FunctionCallInfo fcinfo)
Definition: fmgr.h:40
const Pg_finfo_record * inforec
Definition: fmgr.c:49
#define Anum_pg_proc_prosrc
Definition: pg_proc.h:115
#define Anum_pg_proc_probin
Definition: pg_proc.h:116
void pfree(void *pointer)
Definition: mcxt.c:950
#define ERROR
Definition: elog.h:43
PGFunction user_fn
Definition: fmgr.c:48
PGFunction load_external_function(const char *filename, const char *funcname, bool signalNotFound, void **filehandle)
Definition: dfmgr.c:94
#define TextDatumGetCString(d)
Definition: builtins.h:92
uintptr_t Datum
Definition: postgres.h:372
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1278
static void record_C_func(HeapTuple procedureTuple, PGFunction user_fn, const Pg_finfo_record *inforec)
Definition: fmgr.c:468
static CFuncHashTabEntry * lookup_C_func(HeapTuple procedureTuple)
Definition: fmgr.c:444
const Pg_finfo_record * fetch_finfo_record(void *filehandle, const char *funcname)
Definition: fmgr.c:384
#define elog
Definition: elog.h:219
int api_version
Definition: fmgr.h:354
void fmgr_info_copy ( FmgrInfo dstinfo,
FmgrInfo srcinfo,
MemoryContext  destcxt 
)

Definition at line 524 of file fmgr.c.

References FmgrInfo::fn_extra, FmgrInfo::fn_mcxt, and NULL.

Referenced by bringetbitmap(), gistrescan(), inclusion_get_procinfo(), initBloomState(), initGinState(), initGISTstate(), and ScanKeyEntryInitializeWithInfo().

526 {
527  memcpy(dstinfo, srcinfo, sizeof(FmgrInfo));
528  dstinfo->fn_mcxt = destcxt;
529  dstinfo->fn_extra = NULL;
530 }
Definition: fmgr.h:56
MemoryContext fn_mcxt
Definition: fmgr.h:65
#define NULL
Definition: c.h:229
void * fn_extra
Definition: fmgr.h:64
static void fmgr_info_cxt_security ( Oid  functionId,
FmgrInfo finfo,
MemoryContext  mcxt,
bool  ignore_security 
)
static

Definition at line 147 of file fmgr.c.

References Anum_pg_proc_proconfig, Anum_pg_proc_prosrc, ClanguageId, elog, ereport, errcode(), errmsg(), ERROR, fmgr_info_C_lang(), fmgr_info_other_lang(), fmgr_isbuiltin(), fmgr_lookupByName(), fmgr_security_definer(), fmgr_sql(), FmgrHookIsNeeded, FmgrInfo::fn_addr, FmgrInfo::fn_expr, FmgrInfo::fn_extra, FmgrInfo::fn_mcxt, FmgrInfo::fn_nargs, FmgrInfo::fn_oid, FmgrInfo::fn_retset, FmgrInfo::fn_stats, FmgrInfo::fn_strict, FmgrBuiltin::func, GETSTRUCT, heap_attisnull(), HeapTupleIsValid, INTERNALlanguageId, InvalidOid, FmgrBuiltin::nargs, NULL, ObjectIdGetDatum, pfree(), PROCOID, ReleaseSysCache(), FmgrBuiltin::retset, SearchSysCache1, SQLlanguageId, FmgrBuiltin::strict, SysCacheGetAttr(), TextDatumGetCString, TRACK_FUNC_ALL, TRACK_FUNC_OFF, and TRACK_FUNC_PL.

Referenced by fmgr_info(), fmgr_info_cxt(), fmgr_info_other_lang(), and fmgr_security_definer().

149 {
150  const FmgrBuiltin *fbp;
151  HeapTuple procedureTuple;
152  Form_pg_proc procedureStruct;
153  Datum prosrcdatum;
154  bool isnull;
155  char *prosrc;
156 
157  /*
158  * fn_oid *must* be filled in last. Some code assumes that if fn_oid is
159  * valid, the whole struct is valid. Some FmgrInfo struct's do survive
160  * elogs.
161  */
162  finfo->fn_oid = InvalidOid;
163  finfo->fn_extra = NULL;
164  finfo->fn_mcxt = mcxt;
165  finfo->fn_expr = NULL; /* caller may set this later */
166 
167  if ((fbp = fmgr_isbuiltin(functionId)) != NULL)
168  {
169  /*
170  * Fast path for builtin functions: don't bother consulting pg_proc
171  */
172  finfo->fn_nargs = fbp->nargs;
173  finfo->fn_strict = fbp->strict;
174  finfo->fn_retset = fbp->retset;
175  finfo->fn_stats = TRACK_FUNC_ALL; /* ie, never track */
176  finfo->fn_addr = fbp->func;
177  finfo->fn_oid = functionId;
178  return;
179  }
180 
181  /* Otherwise we need the pg_proc entry */
182  procedureTuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(functionId));
183  if (!HeapTupleIsValid(procedureTuple))
184  elog(ERROR, "cache lookup failed for function %u", functionId);
185  procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
186 
187  finfo->fn_nargs = procedureStruct->pronargs;
188  finfo->fn_strict = procedureStruct->proisstrict;
189  finfo->fn_retset = procedureStruct->proretset;
190 
191  /*
192  * If it has prosecdef set, non-null proconfig, or if a plugin wants to
193  * hook function entry/exit, use fmgr_security_definer call handler ---
194  * unless we are being called again by fmgr_security_definer or
195  * fmgr_info_other_lang.
196  *
197  * When using fmgr_security_definer, function stats tracking is always
198  * disabled at the outer level, and instead we set the flag properly in
199  * fmgr_security_definer's private flinfo and implement the tracking
200  * inside fmgr_security_definer. This loses the ability to charge the
201  * overhead of fmgr_security_definer to the function, but gains the
202  * ability to set the track_functions GUC as a local GUC parameter of an
203  * interesting function and have the right things happen.
204  */
205  if (!ignore_security &&
206  (procedureStruct->prosecdef ||
207  !heap_attisnull(procedureTuple, Anum_pg_proc_proconfig) ||
208  FmgrHookIsNeeded(functionId)))
209  {
211  finfo->fn_stats = TRACK_FUNC_ALL; /* ie, never track */
212  finfo->fn_oid = functionId;
213  ReleaseSysCache(procedureTuple);
214  return;
215  }
216 
217  switch (procedureStruct->prolang)
218  {
219  case INTERNALlanguageId:
220 
221  /*
222  * For an ordinary builtin function, we should never get here
223  * because the isbuiltin() search above will have succeeded.
224  * However, if the user has done a CREATE FUNCTION to create an
225  * alias for a builtin function, we can end up here. In that case
226  * we have to look up the function by name. The name of the
227  * internal function is stored in prosrc (it doesn't have to be
228  * the same as the name of the alias!)
229  */
230  prosrcdatum = SysCacheGetAttr(PROCOID, procedureTuple,
231  Anum_pg_proc_prosrc, &isnull);
232  if (isnull)
233  elog(ERROR, "null prosrc");
234  prosrc = TextDatumGetCString(prosrcdatum);
235  fbp = fmgr_lookupByName(prosrc);
236  if (fbp == NULL)
237  ereport(ERROR,
238  (errcode(ERRCODE_UNDEFINED_FUNCTION),
239  errmsg("internal function \"%s\" is not in internal lookup table",
240  prosrc)));
241  pfree(prosrc);
242  /* Should we check that nargs, strict, retset match the table? */
243  finfo->fn_addr = fbp->func;
244  /* note this policy is also assumed in fast path above */
245  finfo->fn_stats = TRACK_FUNC_ALL; /* ie, never track */
246  break;
247 
248  case ClanguageId:
249  fmgr_info_C_lang(functionId, finfo, procedureTuple);
250  finfo->fn_stats = TRACK_FUNC_PL; /* ie, track if ALL */
251  break;
252 
253  case SQLlanguageId:
254  finfo->fn_addr = fmgr_sql;
255  finfo->fn_stats = TRACK_FUNC_PL; /* ie, track if ALL */
256  break;
257 
258  default:
259  fmgr_info_other_lang(functionId, finfo, procedureTuple);
260  finfo->fn_stats = TRACK_FUNC_OFF; /* ie, track if not OFF */
261  break;
262  }
263 
264  finfo->fn_oid = functionId;
265  ReleaseSysCache(procedureTuple);
266 }
bool strict
Definition: fmgrtab.h:30
short fn_nargs
Definition: fmgr.h:60
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
MemoryContext fn_mcxt
Definition: fmgr.h:65
short nargs
Definition: fmgrtab.h:29
#define INTERNALlanguageId
Definition: pg_language.h:74
static Datum fmgr_security_definer(PG_FUNCTION_ARGS)
Definition: fmgr.c:574
PGFunction fn_addr
Definition: fmgr.h:58
static void fmgr_info_other_lang(Oid functionId, FmgrInfo *finfo, HeapTuple procedureTuple)
Definition: fmgr.c:347
#define Anum_pg_proc_prosrc
Definition: pg_proc.h:115
#define ClanguageId
Definition: pg_language.h:77
int errcode(int sqlerrcode)
Definition: elog.c:575
#define FmgrHookIsNeeded(fn_oid)
Definition: fmgr.h:728
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:152
#define Anum_pg_proc_proconfig
Definition: pg_proc.h:117
static void fmgr_info_C_lang(Oid functionId, FmgrInfo *finfo, HeapTuple procedureTuple)
Definition: fmgr.c:273
PGFunction func
Definition: fmgrtab.h:32
void pfree(void *pointer)
Definition: mcxt.c:950
bool fn_retset
Definition: fmgr.h:62
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
bool fn_strict
Definition: fmgr.h:61
#define SQLlanguageId
Definition: pg_language.h:80
bool heap_attisnull(HeapTuple tup, int attnum)
Definition: heaptuple.c:297
Datum fmgr_sql(PG_FUNCTION_ARGS)
Definition: functions.c:989
static const FmgrBuiltin * fmgr_lookupByName(const char *name)
Definition: fmgr.c:101
#define ereport(elevel, rest)
Definition: elog.h:122
#define TextDatumGetCString(d)
Definition: builtins.h:92
static const FmgrBuiltin * fmgr_isbuiltin(Oid id)
Definition: fmgr.c:71
uintptr_t Datum
Definition: postgres.h:372
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1278
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:83
#define InvalidOid
Definition: postgres_ext.h:36
Oid fn_oid
Definition: fmgr.h:59
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:229
fmNodePtr fn_expr
Definition: fmgr.h:66
void * fn_extra
Definition: fmgr.h:64
int errmsg(const char *fmt,...)
Definition: elog.c:797
unsigned char fn_stats
Definition: fmgr.h:63
#define elog
Definition: elog.h:219
bool retset
Definition: fmgrtab.h:31
static void fmgr_info_other_lang ( Oid  functionId,
FmgrInfo finfo,
HeapTuple  procedureTuple 
)
static

Definition at line 347 of file fmgr.c.

References CurrentMemoryContext, elog, ERROR, fmgr_info_cxt_security(), FmgrInfo::fn_addr, GETSTRUCT, HeapTupleIsValid, LANGOID, ObjectIdGetDatum, ReleaseSysCache(), and SearchSysCache1.

Referenced by fmgr_info_cxt_security().

348 {
349  Form_pg_proc procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
350  Oid language = procedureStruct->prolang;
351  HeapTuple languageTuple;
352  Form_pg_language languageStruct;
353  FmgrInfo plfinfo;
354 
355  languageTuple = SearchSysCache1(LANGOID, ObjectIdGetDatum(language));
356  if (!HeapTupleIsValid(languageTuple))
357  elog(ERROR, "cache lookup failed for language %u", language);
358  languageStruct = (Form_pg_language) GETSTRUCT(languageTuple);
359 
360  /*
361  * Look up the language's call handler function, ignoring any attributes
362  * that would normally cause insertion of fmgr_security_definer. We need
363  * to get back a bare pointer to the actual C-language function.
364  */
365  fmgr_info_cxt_security(languageStruct->lanplcallfoid, &plfinfo,
366  CurrentMemoryContext, true);
367  finfo->fn_addr = plfinfo.fn_addr;
368 
369  ReleaseSysCache(languageTuple);
370 }
Definition: fmgr.h:56
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
PGFunction fn_addr
Definition: fmgr.h:58
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:152
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:83
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
FormData_pg_language * Form_pg_language
Definition: pg_language.h:51
#define elog
Definition: elog.h:219
static void fmgr_info_cxt_security(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt, bool ignore_security)
Definition: fmgr.c:147
Oid fmgr_internal_function ( const char *  proname)

Definition at line 539 of file fmgr.c.

References fmgr_lookupByName(), FmgrBuiltin::foid, InvalidOid, and NULL.

Referenced by fmgr_internal_validator().

540 {
541  const FmgrBuiltin *fbp = fmgr_lookupByName(proname);
542 
543  if (fbp == NULL)
544  return InvalidOid;
545  return fbp->foid;
546 }
Oid foid
Definition: fmgrtab.h:27
static const FmgrBuiltin * fmgr_lookupByName(const char *name)
Definition: fmgr.c:101
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:229
static const FmgrBuiltin* fmgr_isbuiltin ( Oid  id)
static

Definition at line 71 of file fmgr.c.

References fmgr_builtins, fmgr_nbuiltins, FmgrBuiltin::foid, i, and NULL.

Referenced by fmgr_info_cxt_security().

72 {
73  int low = 0;
74  int high = fmgr_nbuiltins - 1;
75 
76  /*
77  * Loop invariant: low is the first index that could contain target entry,
78  * and high is the last index that could contain it.
79  */
80  while (low <= high)
81  {
82  int i = (high + low) / 2;
83  const FmgrBuiltin *ptr = &fmgr_builtins[i];
84 
85  if (id == ptr->foid)
86  return ptr;
87  else if (id > ptr->foid)
88  low = i + 1;
89  else
90  high = i - 1;
91  }
92  return NULL;
93 }
Oid foid
Definition: fmgrtab.h:27
const int fmgr_nbuiltins
const FmgrBuiltin fmgr_builtins[]
#define NULL
Definition: c.h:229
int i
static const FmgrBuiltin* fmgr_lookupByName ( const char *  name)
static

Definition at line 101 of file fmgr.c.

References fmgr_builtins, fmgr_nbuiltins, i, and NULL.

Referenced by fmgr_info_cxt_security(), and fmgr_internal_function().

102 {
103  int i;
104 
105  for (i = 0; i < fmgr_nbuiltins; i++)
106  {
107  if (strcmp(name, fmgr_builtins[i].funcName) == 0)
108  return fmgr_builtins + i;
109  }
110  return NULL;
111 }
const int fmgr_nbuiltins
const FmgrBuiltin fmgr_builtins[]
#define NULL
Definition: c.h:229
const char * name
Definition: encode.c:521
int i
static Datum fmgr_security_definer ( PG_FUNCTION_ARGS  )
static

Definition at line 574 of file fmgr.c.

References Anum_pg_proc_proconfig, fmgr_security_definer_cache::arg, AtEOXact_GUC(), DatumGetArrayTypePCopy, elog, ERROR, ExprMultipleResult, FHET_ABORT, FHET_END, FHET_START, fmgr_security_definer_cache::flinfo, fmgr_hook, fmgr_info_cxt_security(), FmgrInfo::fn_expr, FmgrInfo::fn_extra, FmgrInfo::fn_mcxt, FunctionCallInvoke, GETSTRUCT, GetUserIdAndSecContext(), GUC_ACTION_SAVE, HeapTupleIsValid, IsA, MemoryContextAllocZero(), MemoryContextSwitchTo(), NewGUCNestLevel(), NULL, ObjectIdGetDatum, OidIsValid, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, PGC_S_SESSION, PGC_SUSET, PGC_USERSET, pgstat_end_function_usage(), pgstat_init_function_usage(), ProcessGUCArray(), PROCOID, fmgr_security_definer_cache::proconfig, ReleaseSysCache(), result, SearchSysCache1, SECURITY_LOCAL_USERID_CHANGE, SetUserIdAndSecContext(), superuser(), SysCacheGetAttr(), and fmgr_security_definer_cache::userid.

Referenced by fmgr_info_cxt_security().

575 {
576  Datum result;
577  struct fmgr_security_definer_cache *volatile fcache;
578  FmgrInfo *save_flinfo;
579  Oid save_userid;
580  int save_sec_context;
581  volatile int save_nestlevel;
582  PgStat_FunctionCallUsage fcusage;
583 
584  if (!fcinfo->flinfo->fn_extra)
585  {
586  HeapTuple tuple;
587  Form_pg_proc procedureStruct;
588  Datum datum;
589  bool isnull;
590  MemoryContext oldcxt;
591 
592  fcache = MemoryContextAllocZero(fcinfo->flinfo->fn_mcxt,
593  sizeof(*fcache));
594 
595  fmgr_info_cxt_security(fcinfo->flinfo->fn_oid, &fcache->flinfo,
596  fcinfo->flinfo->fn_mcxt, true);
597  fcache->flinfo.fn_expr = fcinfo->flinfo->fn_expr;
598 
599  tuple = SearchSysCache1(PROCOID,
600  ObjectIdGetDatum(fcinfo->flinfo->fn_oid));
601  if (!HeapTupleIsValid(tuple))
602  elog(ERROR, "cache lookup failed for function %u",
603  fcinfo->flinfo->fn_oid);
604  procedureStruct = (Form_pg_proc) GETSTRUCT(tuple);
605 
606  if (procedureStruct->prosecdef)
607  fcache->userid = procedureStruct->proowner;
608 
610  &isnull);
611  if (!isnull)
612  {
613  oldcxt = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
614  fcache->proconfig = DatumGetArrayTypePCopy(datum);
615  MemoryContextSwitchTo(oldcxt);
616  }
617 
618  ReleaseSysCache(tuple);
619 
620  fcinfo->flinfo->fn_extra = fcache;
621  }
622  else
623  fcache = fcinfo->flinfo->fn_extra;
624 
625  /* GetUserIdAndSecContext is cheap enough that no harm in a wasted call */
626  GetUserIdAndSecContext(&save_userid, &save_sec_context);
627  if (fcache->proconfig) /* Need a new GUC nesting level */
628  save_nestlevel = NewGUCNestLevel();
629  else
630  save_nestlevel = 0; /* keep compiler quiet */
631 
632  if (OidIsValid(fcache->userid))
634  save_sec_context | SECURITY_LOCAL_USERID_CHANGE);
635 
636  if (fcache->proconfig)
637  {
638  ProcessGUCArray(fcache->proconfig,
642  }
643 
644  /* function manager hook */
645  if (fmgr_hook)
646  (*fmgr_hook) (FHET_START, &fcache->flinfo, &fcache->arg);
647 
648  /*
649  * We don't need to restore GUC or userid settings on error, because the
650  * ensuing xact or subxact abort will do that. The PG_TRY block is only
651  * needed to clean up the flinfo link.
652  */
653  save_flinfo = fcinfo->flinfo;
654 
655  PG_TRY();
656  {
657  fcinfo->flinfo = &fcache->flinfo;
658 
659  /* See notes in fmgr_info_cxt_security */
660  pgstat_init_function_usage(fcinfo, &fcusage);
661 
662  result = FunctionCallInvoke(fcinfo);
663 
664  /*
665  * We could be calling either a regular or a set-returning function,
666  * so we have to test to see what finalize flag to use.
667  */
668  pgstat_end_function_usage(&fcusage,
669  (fcinfo->resultinfo == NULL ||
670  !IsA(fcinfo->resultinfo, ReturnSetInfo) ||
671  ((ReturnSetInfo *) fcinfo->resultinfo)->isDone != ExprMultipleResult));
672  }
673  PG_CATCH();
674  {
675  fcinfo->flinfo = save_flinfo;
676  if (fmgr_hook)
677  (*fmgr_hook) (FHET_ABORT, &fcache->flinfo, &fcache->arg);
678  PG_RE_THROW();
679  }
680  PG_END_TRY();
681 
682  fcinfo->flinfo = save_flinfo;
683 
684  if (fcache->proconfig)
685  AtEOXact_GUC(true, save_nestlevel);
686  if (OidIsValid(fcache->userid))
687  SetUserIdAndSecContext(save_userid, save_sec_context);
688  if (fmgr_hook)
689  (*fmgr_hook) (FHET_END, &fcache->flinfo, &fcache->arg);
690 
691  return result;
692 }
Definition: fmgr.h:56
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
MemoryContext fn_mcxt
Definition: fmgr.h:65
void SetUserIdAndSecContext(Oid userid, int sec_context)
Definition: miscinit.c:395
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
bool superuser(void)
Definition: superuser.c:47
return result
Definition: formatting.c:1618
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:152
#define Anum_pg_proc_proconfig
Definition: pg_proc.h:117
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
Definition: guc.h:75
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
Definition: miscinit.c:388
void AtEOXact_GUC(bool isCommit, int nestLevel)
Definition: guc.c:5083
Definition: fmgr.h:716
ArrayType * proconfig
Definition: fmgr.c:559
uintptr_t Datum
Definition: postgres.h:372
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1278
#define DatumGetArrayTypePCopy(X)
Definition: array.h:243
PGDLLIMPORT fmgr_hook_type fmgr_hook
Definition: fmgr.c:37
#define SECURITY_LOCAL_USERID_CHANGE
Definition: miscadmin.h:291
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:83
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:742
void ProcessGUCArray(ArrayType *array, GucContext context, GucSource source, GucAction action)
Definition: guc.c:9416
#define PG_CATCH()
Definition: elog.h:293
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:229
fmNodePtr fn_expr
Definition: fmgr.h:66
#define PG_RE_THROW()
Definition: elog.h:314
void * fn_extra
Definition: fmgr.h:64
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
Definition: pgstat.c:1618
void pgstat_init_function_usage(FunctionCallInfoData *fcinfo, PgStat_FunctionCallUsage *fcu)
Definition: pgstat.c:1546
int NewGUCNestLevel(void)
Definition: guc.c:5069
#define elog
Definition: elog.h:219
#define PG_TRY()
Definition: elog.h:284
#define PG_END_TRY()
Definition: elog.h:300
static void fmgr_info_cxt_security(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt, bool ignore_security)
Definition: fmgr.c:147
Datum FunctionCall1Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1 
)

Definition at line 1027 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, FunctionCallInfoData::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

Referenced by _hash_datum2hashkey(), brin_inclusion_add_value(), element_hash(), gistdentryinit(), gistFetchAtt(), gistFormTuple(), and hash_range().

1028 {
1029  FunctionCallInfoData fcinfo;
1030  Datum result;
1031 
1032  InitFunctionCallInfoData(fcinfo, flinfo, 1, collation, NULL, NULL);
1033 
1034  fcinfo.arg[0] = arg1;
1035  fcinfo.argnull[0] = false;
1036 
1037  result = FunctionCallInvoke(&fcinfo);
1038 
1039  /* Check for null result, since caller is clearly not expecting one */
1040  if (fcinfo.isnull)
1041  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1042 
1043  return result;
1044 }
return result
Definition: formatting.c:1618
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum FunctionCall2Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2 
)

Definition at line 1047 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, FunctionCallInfoData::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

Referenced by _bt_check_rowcompare(), _bt_checkkeys(), _bt_compare(), _bt_compare_array_elements(), _bt_compare_scankey_args(), _bt_find_extreme_element(), _bt_isequal(), _bt_sort_array_elements(), _hash_checkqual(), array_position_common(), array_positions(), brin_inclusion_add_value(), brin_inclusion_consistent(), brin_inclusion_union(), brin_minmax_add_value(), brin_minmax_consistent(), brin_minmax_union(), call_subtype_diff(), cmpEntries(), compute_distinct_stats(), compute_range_stats(), doPickSplit(), element_compare(), eqjoinsel_inner(), eqjoinsel_semi(), genericPickSplit(), get_distance(), get_position(), get_variable_range(), ginCompareEntries(), gistMakeUnionItVec(), gistMakeUnionKey(), gistUserPicksplit(), histogram_selectivity(), ineq_histogram_selectivity(), make_greater_string(), mcv_selectivity(), partition_bound_cmp(), partition_rbound_cmp(), partition_rbound_datum_cmp(), qsort_partition_list_value_cmp(), range_cmp_bound_values(), range_cmp_bounds(), range_contains_elem_internal(), RelationBuildPartitionDesc(), spgdoinsert(), spgGetCache(), spgLeafTest(), spgWalk(), and var_eq_const().

1048 {
1049  FunctionCallInfoData fcinfo;
1050  Datum result;
1051 
1052  InitFunctionCallInfoData(fcinfo, flinfo, 2, collation, NULL, NULL);
1053 
1054  fcinfo.arg[0] = arg1;
1055  fcinfo.arg[1] = arg2;
1056  fcinfo.argnull[0] = false;
1057  fcinfo.argnull[1] = false;
1058 
1059  result = FunctionCallInvoke(&fcinfo);
1060 
1061  /* Check for null result, since caller is clearly not expecting one */
1062  if (fcinfo.isnull)
1063  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1064 
1065  return result;
1066 }
return result
Definition: formatting.c:1618
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum FunctionCall3Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3 
)

Definition at line 1069 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, FunctionCallInfoData::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

Referenced by bringetbitmap(), ginExtractEntries(), gistKeyIsEQ(), gistpenalty(), and union_tuples().

1071 {
1072  FunctionCallInfoData fcinfo;
1073  Datum result;
1074 
1075  InitFunctionCallInfoData(fcinfo, flinfo, 3, collation, NULL, NULL);
1076 
1077  fcinfo.arg[0] = arg1;
1078  fcinfo.arg[1] = arg2;
1079  fcinfo.arg[2] = arg3;
1080  fcinfo.argnull[0] = false;
1081  fcinfo.argnull[1] = false;
1082  fcinfo.argnull[2] = false;
1083 
1084  result = FunctionCallInvoke(&fcinfo);
1085 
1086  /* Check for null result, since caller is clearly not expecting one */
1087  if (fcinfo.isnull)
1088  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1089 
1090  return result;
1091 }
return result
Definition: formatting.c:1618
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum FunctionCall4Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4 
)

Definition at line 1094 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, FunctionCallInfoData::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

Referenced by brinbuildCallback(), brininsert(), collectMatchBitmap(), matchPartialInPendingList(), and scalararraysel().

1096 {
1097  FunctionCallInfoData fcinfo;
1098  Datum result;
1099 
1100  InitFunctionCallInfoData(fcinfo, flinfo, 4, collation, NULL, NULL);
1101 
1102  fcinfo.arg[0] = arg1;
1103  fcinfo.arg[1] = arg2;
1104  fcinfo.arg[2] = arg3;
1105  fcinfo.arg[3] = arg4;
1106  fcinfo.argnull[0] = false;
1107  fcinfo.argnull[1] = false;
1108  fcinfo.argnull[2] = false;
1109  fcinfo.argnull[3] = false;
1110 
1111  result = FunctionCallInvoke(&fcinfo);
1112 
1113  /* Check for null result, since caller is clearly not expecting one */
1114  if (fcinfo.isnull)
1115  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1116 
1117  return result;
1118 }
return result
Definition: formatting.c:1618
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum FunctionCall5Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5 
)

Definition at line 1121 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, FunctionCallInfoData::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

Referenced by gistindex_keytest(), and scalararraysel().

1123 {
1124  FunctionCallInfoData fcinfo;
1125  Datum result;
1126 
1127  InitFunctionCallInfoData(fcinfo, flinfo, 5, collation, NULL, NULL);
1128 
1129  fcinfo.arg[0] = arg1;
1130  fcinfo.arg[1] = arg2;
1131  fcinfo.arg[2] = arg3;
1132  fcinfo.arg[3] = arg4;
1133  fcinfo.arg[4] = arg5;
1134  fcinfo.argnull[0] = false;
1135  fcinfo.argnull[1] = false;
1136  fcinfo.argnull[2] = false;
1137  fcinfo.argnull[3] = false;
1138  fcinfo.argnull[4] = false;
1139 
1140  result = FunctionCallInvoke(&fcinfo);
1141 
1142  /* Check for null result, since caller is clearly not expecting one */
1143  if (fcinfo.isnull)
1144  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1145 
1146  return result;
1147 }
return result
Definition: formatting.c:1618
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum FunctionCall6Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6 
)

Definition at line 1150 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, FunctionCallInfoData::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

1153 {
1154  FunctionCallInfoData fcinfo;
1155  Datum result;
1156 
1157  InitFunctionCallInfoData(fcinfo, flinfo, 6, collation, NULL, NULL);
1158 
1159  fcinfo.arg[0] = arg1;
1160  fcinfo.arg[1] = arg2;
1161  fcinfo.arg[2] = arg3;
1162  fcinfo.arg[3] = arg4;
1163  fcinfo.arg[4] = arg5;
1164  fcinfo.arg[5] = arg6;
1165  fcinfo.argnull[0] = false;
1166  fcinfo.argnull[1] = false;
1167  fcinfo.argnull[2] = false;
1168  fcinfo.argnull[3] = false;
1169  fcinfo.argnull[4] = false;
1170  fcinfo.argnull[5] = false;
1171 
1172  result = FunctionCallInvoke(&fcinfo);
1173 
1174  /* Check for null result, since caller is clearly not expecting one */
1175  if (fcinfo.isnull)
1176  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1177 
1178  return result;
1179 }
return result
Definition: formatting.c:1618
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum FunctionCall7Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7 
)

Definition at line 1182 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, FunctionCallInfoData::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

Referenced by directTriConsistentFn(), ginNewScanKey(), and shimBoolConsistentFn().

1185 {
1186  FunctionCallInfoData fcinfo;
1187  Datum result;
1188 
1189  InitFunctionCallInfoData(fcinfo, flinfo, 7, collation, NULL, NULL);
1190 
1191  fcinfo.arg[0] = arg1;
1192  fcinfo.arg[1] = arg2;
1193  fcinfo.arg[2] = arg3;
1194  fcinfo.arg[3] = arg4;
1195  fcinfo.arg[4] = arg5;
1196  fcinfo.arg[5] = arg6;
1197  fcinfo.arg[6] = arg7;
1198  fcinfo.argnull[0] = false;
1199  fcinfo.argnull[1] = false;
1200  fcinfo.argnull[2] = false;
1201  fcinfo.argnull[3] = false;
1202  fcinfo.argnull[4] = false;
1203  fcinfo.argnull[5] = false;
1204  fcinfo.argnull[6] = false;
1205 
1206  result = FunctionCallInvoke(&fcinfo);
1207 
1208  /* Check for null result, since caller is clearly not expecting one */
1209  if (fcinfo.isnull)
1210  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1211 
1212  return result;
1213 }
return result
Definition: formatting.c:1618
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum FunctionCall8Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7,
Datum  arg8 
)

Definition at line 1216 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, FunctionCallInfoData::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

Referenced by directBoolConsistentFn().

1219 {
1220  FunctionCallInfoData fcinfo;
1221  Datum result;
1222 
1223  InitFunctionCallInfoData(fcinfo, flinfo, 8, collation, NULL, NULL);
1224 
1225  fcinfo.arg[0] = arg1;
1226  fcinfo.arg[1] = arg2;
1227  fcinfo.arg[2] = arg3;
1228  fcinfo.arg[3] = arg4;
1229  fcinfo.arg[4] = arg5;
1230  fcinfo.arg[5] = arg6;
1231  fcinfo.arg[6] = arg7;
1232  fcinfo.arg[7] = arg8;
1233  fcinfo.argnull[0] = false;
1234  fcinfo.argnull[1] = false;
1235  fcinfo.argnull[2] = false;
1236  fcinfo.argnull[3] = false;
1237  fcinfo.argnull[4] = false;
1238  fcinfo.argnull[5] = false;
1239  fcinfo.argnull[6] = false;
1240  fcinfo.argnull[7] = false;
1241 
1242  result = FunctionCallInvoke(&fcinfo);
1243 
1244  /* Check for null result, since caller is clearly not expecting one */
1245  if (fcinfo.isnull)
1246  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1247 
1248  return result;
1249 }
return result
Definition: formatting.c:1618
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum FunctionCall9Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7,
Datum  arg8,
Datum  arg9 
)

Definition at line 1252 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, FunctionCallInfoData::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

1256 {
1257  FunctionCallInfoData fcinfo;
1258  Datum result;
1259 
1260  InitFunctionCallInfoData(fcinfo, flinfo, 9, collation, NULL, NULL);
1261 
1262  fcinfo.arg[0] = arg1;
1263  fcinfo.arg[1] = arg2;
1264  fcinfo.arg[2] = arg3;
1265  fcinfo.arg[3] = arg4;
1266  fcinfo.arg[4] = arg5;
1267  fcinfo.arg[5] = arg6;
1268  fcinfo.arg[6] = arg7;
1269  fcinfo.arg[7] = arg8;
1270  fcinfo.arg[8] = arg9;
1271  fcinfo.argnull[0] = false;
1272  fcinfo.argnull[1] = false;
1273  fcinfo.argnull[2] = false;
1274  fcinfo.argnull[3] = false;
1275  fcinfo.argnull[4] = false;
1276  fcinfo.argnull[5] = false;
1277  fcinfo.argnull[6] = false;
1278  fcinfo.argnull[7] = false;
1279  fcinfo.argnull[8] = false;
1280 
1281  result = FunctionCallInvoke(&fcinfo);
1282 
1283  /* Check for null result, since caller is clearly not expecting one */
1284  if (fcinfo.isnull)
1285  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1286 
1287  return result;
1288 }
return result
Definition: formatting.c:1618
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
bool get_call_expr_arg_stable ( Node expr,
int  argnum 
)

Definition at line 1999 of file fmgr.c.

References arg, generate_unaccent_rules::args, IsA, list_length(), list_make1, list_nth(), NULL, and PARAM_EXTERN.

Referenced by get_fn_expr_arg_stable().

2000 {
2001  List *args;
2002  Node *arg;
2003 
2004  if (expr == NULL)
2005  return false;
2006 
2007  if (IsA(expr, FuncExpr))
2008  args = ((FuncExpr *) expr)->args;
2009  else if (IsA(expr, OpExpr))
2010  args = ((OpExpr *) expr)->args;
2011  else if (IsA(expr, DistinctExpr))
2012  args = ((DistinctExpr *) expr)->args;
2013  else if (IsA(expr, ScalarArrayOpExpr))
2014  args = ((ScalarArrayOpExpr *) expr)->args;
2015  else if (IsA(expr, ArrayCoerceExpr))
2016  args = list_make1(((ArrayCoerceExpr *) expr)->arg);
2017  else if (IsA(expr, NullIfExpr))
2018  args = ((NullIfExpr *) expr)->args;
2019  else if (IsA(expr, WindowFunc))
2020  args = ((WindowFunc *) expr)->args;
2021  else
2022  return false;
2023 
2024  if (argnum < 0 || argnum >= list_length(args))
2025  return false;
2026 
2027  arg = (Node *) list_nth(args, argnum);
2028 
2029  /*
2030  * Either a true Const or an external Param will have a value that doesn't
2031  * change during the execution of the query. In future we might want to
2032  * consider other cases too, e.g. now().
2033  */
2034  if (IsA(arg, Const))
2035  return true;
2036  if (IsA(arg, Param) &&
2037  ((Param *) arg)->paramkind == PARAM_EXTERN)
2038  return true;
2039 
2040  return false;
2041 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
Definition: nodes.h:509
#define list_make1(x1)
Definition: pg_list.h:139
void * list_nth(const List *list, int n)
Definition: list.c:410
#define NULL
Definition: c.h:229
static int list_length(const List *l)
Definition: pg_list.h:89
void * arg
Definition: pg_list.h:45
Oid get_call_expr_argtype ( Node expr,
int  argnum 
)

Definition at line 1928 of file fmgr.c.

References arg, generate_unaccent_rules::args, exprType(), get_base_element_type(), InvalidOid, IsA, list_length(), list_make1, list_nth(), and NULL.

Referenced by get_fn_expr_argtype(), prepare_sql_fn_parse_info(), resolve_polymorphic_argtypes(), and resolve_polymorphic_tupdesc().

1929 {
1930  List *args;
1931  Oid argtype;
1932 
1933  if (expr == NULL)
1934  return InvalidOid;
1935 
1936  if (IsA(expr, FuncExpr))
1937  args = ((FuncExpr *) expr)->args;
1938  else if (IsA(expr, OpExpr))
1939  args = ((OpExpr *) expr)->args;
1940  else if (IsA(expr, DistinctExpr))
1941  args = ((DistinctExpr *) expr)->args;
1942  else if (IsA(expr, ScalarArrayOpExpr))
1943  args = ((ScalarArrayOpExpr *) expr)->args;
1944  else if (IsA(expr, ArrayCoerceExpr))
1945  args = list_make1(((ArrayCoerceExpr *) expr)->arg);
1946  else if (IsA(expr, NullIfExpr))
1947  args = ((NullIfExpr *) expr)->args;
1948  else if (IsA(expr, WindowFunc))
1949  args = ((WindowFunc *) expr)->args;
1950  else
1951  return InvalidOid;
1952 
1953  if (argnum < 0 || argnum >= list_length(args))
1954  return InvalidOid;
1955 
1956  argtype = exprType((Node *) list_nth(args, argnum));
1957 
1958  /*
1959  * special hack for ScalarArrayOpExpr and ArrayCoerceExpr: what the
1960  * underlying function will actually get passed is the element type of the
1961  * array.
1962  */
1963  if (IsA(expr, ScalarArrayOpExpr) &&
1964  argnum == 1)
1965  argtype = get_base_element_type(argtype);
1966  else if (IsA(expr, ArrayCoerceExpr) &&
1967  argnum == 0)
1968  argtype = get_base_element_type(argtype);
1969 
1970  return argtype;
1971 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
Definition: nodes.h:509
unsigned int Oid
Definition: postgres_ext.h:31
#define list_make1(x1)
Definition: pg_list.h:139
void * list_nth(const List *list, int n)
Definition: list.c:410
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:229
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
static int list_length(const List *l)
Definition: pg_list.h:89
Oid get_base_element_type(Oid typid)
Definition: lsyscache.c:2557
void * arg
Definition: pg_list.h:45
bool get_fn_expr_arg_stable ( FmgrInfo flinfo,
int  argnum 
)

Definition at line 1980 of file fmgr.c.

References FmgrInfo::fn_expr, and get_call_expr_arg_stable().

Referenced by jsonb_build_array(), jsonb_build_object(), leadlag_common(), and window_nth_value().

1981 {
1982  /*
1983  * can't return anything useful if we have no FmgrInfo or if its fn_expr
1984  * node has not been initialized
1985  */
1986  if (!flinfo || !flinfo->fn_expr)
1987  return false;
1988 
1989  return get_call_expr_arg_stable(flinfo->fn_expr, argnum);
1990 }
bool get_call_expr_arg_stable(Node *expr, int argnum)
Definition: fmgr.c:1999
fmNodePtr fn_expr
Definition: fmgr.h:66
Oid get_fn_expr_rettype ( FmgrInfo flinfo)

Definition at line 1887 of file fmgr.c.

References exprType(), FmgrInfo::fn_expr, and InvalidOid.

Referenced by do_compile(), init_sql_fcache(), range_constructor2(), and range_constructor3().

1888 {
1889  Node *expr;
1890 
1891  /*
1892  * can't return anything useful if we have no FmgrInfo or if its fn_expr
1893  * node has not been initialized
1894  */
1895  if (!flinfo || !flinfo->fn_expr)
1896  return InvalidOid;
1897 
1898  expr = flinfo->fn_expr;
1899 
1900  return exprType(expr);
1901 }
Definition: nodes.h:509
#define InvalidOid
Definition: postgres_ext.h:36
fmNodePtr fn_expr
Definition: fmgr.h:66
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
bool get_fn_expr_variadic ( FmgrInfo flinfo)

Definition at line 2051 of file fmgr.c.

References FmgrInfo::fn_expr, and IsA.

Referenced by concat_internal(), count_nulls(), and text_format().

2052 {
2053  Node *expr;
2054 
2055  /*
2056  * can't return anything useful if we have no FmgrInfo or if its fn_expr
2057  * node has not been initialized
2058  */
2059  if (!flinfo || !flinfo->fn_expr)
2060  return false;
2061 
2062  expr = flinfo->fn_expr;
2063 
2064  if (IsA(expr, FuncExpr))
2065  return ((FuncExpr *) expr)->funcvariadic;
2066  else
2067  return false;
2068 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
Definition: nodes.h:509
fmNodePtr fn_expr
Definition: fmgr.h:66
Datum InputFunctionCall ( FmgrInfo flinfo,
char *  str,
Oid  typioparam,
int32  typmod 
)

Definition at line 1623 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, CStringGetDatum, elog, ERROR, FunctionCallInfoData::flinfo, FmgrInfo::fn_oid, FmgrInfo::fn_strict, FunctionCallInvoke, InitFunctionCallInfoData, Int32GetDatum, InvalidOid, FunctionCallInfoData::isnull, NULL, ObjectIdGetDatum, and result.

Referenced by BuildTupleFromCStrings(), domain_in(), hstore_populate_record(), make_tuple_from_result_row(), NextCopyFrom(), OidInputFunctionCall(), plperl_sv_to_datum(), pltcl_func_handler(), pltcl_returnnext(), pltcl_SPI_execute_plan(), PLy_cursor_plan(), PLy_exec_function(), PLy_modify_tuple(), PLy_spi_execute_plan(), PLyObject_ToDatum(), populate_scalar(), range_in(), ReadArrayStr(), record_in(), and XmlTableGetValue().

1624 {
1625  FunctionCallInfoData fcinfo;
1626  Datum result;
1627 
1628  if (str == NULL && flinfo->fn_strict)
1629  return (Datum) 0; /* just return null result */
1630 
1631  InitFunctionCallInfoData(fcinfo, flinfo, 3, InvalidOid, NULL, NULL);
1632 
1633  fcinfo.arg[0] = CStringGetDatum(str);
1634  fcinfo.arg[1] = ObjectIdGetDatum(typioparam);
1635  fcinfo.arg[2] = Int32GetDatum(typmod);
1636  fcinfo.argnull[0] = (str == NULL);
1637  fcinfo.argnull[1] = false;
1638  fcinfo.argnull[2] = false;
1639 
1640  result = FunctionCallInvoke(&fcinfo);
1641 
1642  /* Should get null result if and only if str is NULL */
1643  if (str == NULL)
1644  {
1645  if (!fcinfo.isnull)
1646  elog(ERROR, "input function %u returned non-NULL",
1647  fcinfo.flinfo->fn_oid);
1648  }
1649  else
1650  {
1651  if (fcinfo.isnull)
1652  elog(ERROR, "input function %u returned NULL",
1653  fcinfo.flinfo->fn_oid);
1654  }
1655 
1656  return result;
1657 }
return result
Definition: formatting.c:1618
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
bool fn_strict
Definition: fmgr.h:61
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
#define CStringGetDatum(X)
Definition: postgres.h:584
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
#define InvalidOid
Definition: postgres_ext.h:36
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define Int32GetDatum(X)
Definition: postgres.h:485
#define elog
Definition: elog.h:219
static CFuncHashTabEntry * lookup_C_func ( HeapTuple  procedureTuple)
static

Definition at line 444 of file fmgr.c.

References CFuncHashTabEntry::fn_tid, CFuncHashTabEntry::fn_xmin, HASH_FIND, hash_search(), HeapTupleGetOid, HeapTupleHeaderGetRawXmin, ItemPointerEquals(), NULL, HeapTupleData::t_data, and HeapTupleData::t_self.

Referenced by fmgr_info_C_lang().

445 {
446  Oid fn_oid = HeapTupleGetOid(procedureTuple);
447  CFuncHashTabEntry *entry;
448 
449  if (CFuncHash == NULL)
450  return NULL; /* no table yet */
451  entry = (CFuncHashTabEntry *)
453  &fn_oid,
454  HASH_FIND,
455  NULL);
456  if (entry == NULL)
457  return NULL; /* no such entry */
458  if (entry->fn_xmin == HeapTupleHeaderGetRawXmin(procedureTuple->t_data) &&
459  ItemPointerEquals(&entry->fn_tid, &procedureTuple->t_self))
460  return entry; /* OK */
461  return NULL; /* entry is out of date */
462 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:885
unsigned int Oid
Definition: postgres_ext.h:31
HeapTupleHeader t_data
Definition: htup.h:67
static HTAB * CFuncHash
Definition: fmgr.c:52
ItemPointerData t_self
Definition: htup.h:65
#define NULL
Definition: c.h:229
#define HeapTupleHeaderGetRawXmin(tup)
Definition: htup_details.h:302
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
Definition: itemptr.c:29
TransactionId fn_xmin
Definition: fmgr.c:46
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:695
ItemPointerData fn_tid
Definition: fmgr.c:47
Datum OidFunctionCall0Coll ( Oid  functionId,
Oid  collation 
)

Definition at line 1299 of file fmgr.c.

References elog, ERROR, fmgr_security_definer_cache::flinfo, fmgr_info(), FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

1300 {
1301  FmgrInfo flinfo;
1302  FunctionCallInfoData fcinfo;
1303  Datum result;
1304 
1305  fmgr_info(functionId, &flinfo);
1306 
1307  InitFunctionCallInfoData(fcinfo, &flinfo, 0, collation, NULL, NULL);
1308 
1309  result = FunctionCallInvoke(&fcinfo);
1310 
1311  /* Check for null result, since caller is clearly not expecting one */
1312  if (fcinfo.isnull)
1313  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1314 
1315  return result;
1316 }
Definition: fmgr.h:56
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:127
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum OidFunctionCall1Coll ( Oid  functionId,
Oid  collation,
Datum  arg1 
)

Definition at line 1319 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, fmgr_security_definer_cache::flinfo, fmgr_info(), FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

Referenced by _hash_datum2hashkey_type().

1320 {
1321  FmgrInfo flinfo;
1322  FunctionCallInfoData fcinfo;
1323  Datum result;
1324 
1325  fmgr_info(functionId, &flinfo);
1326 
1327  InitFunctionCallInfoData(fcinfo, &flinfo, 1, collation, NULL, NULL);
1328 
1329  fcinfo.arg[0] = arg1;
1330  fcinfo.argnull[0] = false;
1331 
1332  result = FunctionCallInvoke(&fcinfo);
1333 
1334  /* Check for null result, since caller is clearly not expecting one */
1335  if (fcinfo.isnull)
1336  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1337 
1338  return result;
1339 }
Definition: fmgr.h:56
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:127
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum OidFunctionCall2Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2 
)

Definition at line 1342 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, fmgr_security_definer_cache::flinfo, fmgr_info(), FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

Referenced by _bt_compare_scankey_args(), and index_recheck_constraint().

1343 {
1344  FmgrInfo flinfo;
1345  FunctionCallInfoData fcinfo;
1346  Datum result;
1347 
1348  fmgr_info(functionId, &flinfo);
1349 
1350  InitFunctionCallInfoData(fcinfo, &flinfo, 2, collation, NULL, NULL);
1351 
1352  fcinfo.arg[0] = arg1;
1353  fcinfo.arg[1] = arg2;
1354  fcinfo.argnull[0] = false;
1355  fcinfo.argnull[1] = false;
1356 
1357  result = FunctionCallInvoke(&fcinfo);
1358 
1359  /* Check for null result, since caller is clearly not expecting one */
1360  if (fcinfo.isnull)
1361  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1362 
1363  return result;
1364 }
Definition: fmgr.h:56
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:127
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum OidFunctionCall3Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3 
)

Definition at line 1367 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, fmgr_security_definer_cache::flinfo, fmgr_info(), FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

1369 {
1370  FmgrInfo flinfo;
1371  FunctionCallInfoData fcinfo;
1372  Datum result;
1373 
1374  fmgr_info(functionId, &flinfo);
1375 
1376  InitFunctionCallInfoData(fcinfo, &flinfo, 3, collation, NULL, NULL);
1377 
1378  fcinfo.arg[0] = arg1;
1379  fcinfo.arg[1] = arg2;
1380  fcinfo.arg[2] = arg3;
1381  fcinfo.argnull[0] = false;
1382  fcinfo.argnull[1] = false;
1383  fcinfo.argnull[2] = false;
1384 
1385  result = FunctionCallInvoke(&fcinfo);
1386 
1387  /* Check for null result, since caller is clearly not expecting one */
1388  if (fcinfo.isnull)
1389  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1390 
1391  return result;
1392 }
Definition: fmgr.h:56
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:127
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum OidFunctionCall4Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4 
)

Definition at line 1395 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, fmgr_security_definer_cache::flinfo, fmgr_info(), FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

Referenced by restriction_selectivity().

1397 {
1398  FmgrInfo flinfo;
1399  FunctionCallInfoData fcinfo;
1400  Datum result;
1401 
1402  fmgr_info(functionId, &flinfo);
1403 
1404  InitFunctionCallInfoData(fcinfo, &flinfo, 4, collation, NULL, NULL);
1405 
1406  fcinfo.arg[0] = arg1;
1407  fcinfo.arg[1] = arg2;
1408  fcinfo.arg[2] = arg3;
1409  fcinfo.arg[3] = arg4;
1410  fcinfo.argnull[0] = false;
1411  fcinfo.argnull[1] = false;
1412  fcinfo.argnull[2] = false;
1413  fcinfo.argnull[3] = false;
1414 
1415  result = FunctionCallInvoke(&fcinfo);
1416 
1417  /* Check for null result, since caller is clearly not expecting one */
1418  if (fcinfo.isnull)
1419  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1420 
1421  return result;
1422 }
Definition: fmgr.h:56
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:127
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum OidFunctionCall5Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5 
)

Definition at line 1425 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, fmgr_security_definer_cache::flinfo, fmgr_info(), FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

Referenced by join_selectivity().

1427 {
1428  FmgrInfo flinfo;
1429  FunctionCallInfoData fcinfo;
1430  Datum result;
1431 
1432  fmgr_info(functionId, &flinfo);
1433 
1434  InitFunctionCallInfoData(fcinfo, &flinfo, 5, collation, NULL, NULL);
1435 
1436  fcinfo.arg[0] = arg1;
1437  fcinfo.arg[1] = arg2;
1438  fcinfo.arg[2] = arg3;
1439  fcinfo.arg[3] = arg4;
1440  fcinfo.arg[4] = arg5;
1441  fcinfo.argnull[0] = false;
1442  fcinfo.argnull[1] = false;
1443  fcinfo.argnull[2] = false;
1444  fcinfo.argnull[3] = false;
1445  fcinfo.argnull[4] = false;
1446 
1447  result = FunctionCallInvoke(&fcinfo);
1448 
1449  /* Check for null result, since caller is clearly not expecting one */
1450  if (fcinfo.isnull)
1451  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1452 
1453  return result;
1454 }
Definition: fmgr.h:56
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:127
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum OidFunctionCall6Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6 
)

Definition at line 1457 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, fmgr_security_definer_cache::flinfo, fmgr_info(), FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

1460 {
1461  FmgrInfo flinfo;
1462  FunctionCallInfoData fcinfo;
1463  Datum result;
1464 
1465  fmgr_info(functionId, &flinfo);
1466 
1467  InitFunctionCallInfoData(fcinfo, &flinfo, 6, collation, NULL, NULL);
1468 
1469  fcinfo.arg[0] = arg1;
1470  fcinfo.arg[1] = arg2;
1471  fcinfo.arg[2] = arg3;
1472  fcinfo.arg[3] = arg4;
1473  fcinfo.arg[4] = arg5;
1474  fcinfo.arg[5] = arg6;
1475  fcinfo.argnull[0] = false;
1476  fcinfo.argnull[1] = false;
1477  fcinfo.argnull[2] = false;
1478  fcinfo.argnull[3] = false;
1479  fcinfo.argnull[4] = false;
1480  fcinfo.argnull[5] = false;
1481 
1482  result = FunctionCallInvoke(&fcinfo);
1483 
1484  /* Check for null result, since caller is clearly not expecting one */
1485  if (fcinfo.isnull)
1486  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1487 
1488  return result;
1489 }
Definition: fmgr.h:56
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:127
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum OidFunctionCall7Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7 
)

Definition at line 1492 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, fmgr_security_definer_cache::flinfo, fmgr_info(), FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

Referenced by gincost_pattern().

1495 {
1496  FmgrInfo flinfo;
1497  FunctionCallInfoData fcinfo;
1498  Datum result;
1499 
1500  fmgr_info(functionId, &flinfo);
1501 
1502  InitFunctionCallInfoData(fcinfo, &flinfo, 7, collation, NULL, NULL);
1503 
1504  fcinfo.arg[0] = arg1;
1505  fcinfo.arg[1] = arg2;
1506  fcinfo.arg[2] = arg3;
1507  fcinfo.arg[3] = arg4;
1508  fcinfo.arg[4] = arg5;
1509  fcinfo.arg[5] = arg6;
1510  fcinfo.arg[6] = arg7;
1511  fcinfo.argnull[0] = false;
1512  fcinfo.argnull[1] = false;
1513  fcinfo.argnull[2] = false;
1514  fcinfo.argnull[3] = false;
1515  fcinfo.argnull[4] = false;
1516  fcinfo.argnull[5] = false;
1517  fcinfo.argnull[6] = false;
1518 
1519  result = FunctionCallInvoke(&fcinfo);
1520 
1521  /* Check for null result, since caller is clearly not expecting one */
1522  if (fcinfo.isnull)
1523  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1524 
1525  return result;
1526 }
Definition: fmgr.h:56
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:127
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum OidFunctionCall8Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7,
Datum  arg8 
)

Definition at line 1529 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, fmgr_security_definer_cache::flinfo, fmgr_info(), FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

1532 {
1533  FmgrInfo flinfo;
1534  FunctionCallInfoData fcinfo;
1535  Datum result;
1536 
1537  fmgr_info(functionId, &flinfo);
1538 
1539  InitFunctionCallInfoData(fcinfo, &flinfo, 8, collation, NULL, NULL);
1540 
1541  fcinfo.arg[0] = arg1;
1542  fcinfo.arg[1] = arg2;
1543  fcinfo.arg[2] = arg3;
1544  fcinfo.arg[3] = arg4;
1545  fcinfo.arg[4] = arg5;
1546  fcinfo.arg[5] = arg6;
1547  fcinfo.arg[6] = arg7;
1548  fcinfo.arg[7] = arg8;
1549  fcinfo.argnull[0] = false;
1550  fcinfo.argnull[1] = false;
1551  fcinfo.argnull[2] = false;
1552  fcinfo.argnull[3] = false;
1553  fcinfo.argnull[4] = false;
1554  fcinfo.argnull[5] = false;
1555  fcinfo.argnull[6] = false;
1556  fcinfo.argnull[7] = false;
1557 
1558  result = FunctionCallInvoke(&fcinfo);
1559 
1560  /* Check for null result, since caller is clearly not expecting one */
1561  if (fcinfo.isnull)
1562  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1563 
1564  return result;
1565 }
Definition: fmgr.h:56
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:127
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum OidFunctionCall9Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7,
Datum  arg8,
Datum  arg9 
)

Definition at line 1568 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, fmgr_security_definer_cache::flinfo, fmgr_info(), FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, FunctionCallInfoData::isnull, NULL, and result.

1572 {
1573  FmgrInfo flinfo;
1574  FunctionCallInfoData fcinfo;
1575  Datum result;
1576 
1577  fmgr_info(functionId, &flinfo);
1578 
1579  InitFunctionCallInfoData(fcinfo, &flinfo, 9, collation, NULL, NULL);
1580 
1581  fcinfo.arg[0] = arg1;
1582  fcinfo.arg[1] = arg2;
1583  fcinfo.arg[2] = arg3;
1584  fcinfo.arg[3] = arg4;
1585  fcinfo.arg[4] = arg5;
1586  fcinfo.arg[5] = arg6;
1587  fcinfo.arg[6] = arg7;
1588  fcinfo.arg[7] = arg8;
1589  fcinfo.arg[8] = arg9;
1590  fcinfo.argnull[0] = false;
1591  fcinfo.argnull[1] = false;
1592  fcinfo.argnull[2] = false;
1593  fcinfo.argnull[3] = false;
1594  fcinfo.argnull[4] = false;
1595  fcinfo.argnull[5] = false;
1596  fcinfo.argnull[6] = false;
1597  fcinfo.argnull[7] = false;
1598  fcinfo.argnull[8] = false;
1599 
1600  result = FunctionCallInvoke(&fcinfo);
1601 
1602  /* Check for null result, since caller is clearly not expecting one */
1603  if (fcinfo.isnull)
1604  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1605 
1606  return result;
1607 }
Definition: fmgr.h:56
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:127
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219
Datum OidInputFunctionCall ( Oid  functionId,
char *  str,
Oid  typioparam,
int32  typmod 
)

Definition at line 1738 of file fmgr.c.

References fmgr_security_definer_cache::flinfo, fmgr_info(), and InputFunctionCall().

Referenced by DefineAggregate(), exec_bind_message(), get_typdefault(), GetAggInitVal(), InsertOneValue(), parse_fcall_arguments(), slot_modify_cstrings(), slot_store_cstrings(), and stringTypeDatum().

1739 {
1740  FmgrInfo flinfo;
1741 
1742  fmgr_info(functionId, &flinfo);
1743  return InputFunctionCall(&flinfo, str, typioparam, typmod);
1744 }
Definition: fmgr.h:56
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:127
Datum InputFunctionCall(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
Definition: fmgr.c:1623
Datum OidReceiveFunctionCall ( Oid  functionId,
StringInfo  buf,
Oid  typioparam,
int32  typmod 
)

Definition at line 1756 of file fmgr.c.

References fmgr_security_definer_cache::flinfo, fmgr_info(), and ReceiveFunctionCall().

Referenced by exec_bind_message(), parse_fcall_arguments(), and parse_fcall_arguments_20().

1758 {
1759  FmgrInfo flinfo;
1760 
1761  fmgr_info(functionId, &flinfo);
1762  return ReceiveFunctionCall(&flinfo, buf, typioparam, typmod);
1763 }
Definition: fmgr.h:56
Datum ReceiveFunctionCall(FmgrInfo *flinfo, StringInfo buf, Oid typioparam, int32 typmod)
Definition: fmgr.c:1681
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:127
bytea* OidSendFunctionCall ( Oid  functionId,
Datum  val 
)

Definition at line 1766 of file fmgr.c.

References fmgr_security_definer_cache::flinfo, fmgr_info(), and SendFunctionCall().

Referenced by SendFunctionResult().

1767 {
1768  FmgrInfo flinfo;
1769 
1770  fmgr_info(functionId, &flinfo);
1771  return SendFunctionCall(&flinfo, val);
1772 }
Definition: fmgr.h:56
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:127
bytea * SendFunctionCall(FmgrInfo *flinfo, Datum val)
Definition: fmgr.c:1728
long val
Definition: informix.c:689
struct varlena* pg_detoast_datum ( struct varlena datum)

Definition at line 1831 of file fmgr.c.

References heap_tuple_untoast_attr(), and VARATT_IS_EXTENDED.

1832 {
1833  if (VARATT_IS_EXTENDED(datum))
1834  return heap_tuple_untoast_attr(datum);
1835  else
1836  return datum;
1837 }
struct varlena * heap_tuple_untoast_attr(struct varlena *attr)
Definition: tuptoaster.c:172
#define VARATT_IS_EXTENDED(PTR)
Definition: postgres.h:326
struct varlena* pg_detoast_datum_copy ( struct varlena datum)

Definition at line 1840 of file fmgr.c.

References heap_tuple_untoast_attr(), palloc(), result, VARATT_IS_EXTENDED, and VARSIZE.

1841 {
1842  if (VARATT_IS_EXTENDED(datum))
1843  return heap_tuple_untoast_attr(datum);
1844  else
1845  {
1846  /* Make a modifiable copy of the varlena object */
1847  Size len = VARSIZE(datum);
1848  struct varlena *result = (struct varlena *) palloc(len);
1849 
1850  memcpy(result, datum, len);
1851  return result;
1852  }
1853 }
#define VARSIZE(PTR)
Definition: postgres.h:304
return result
Definition: formatting.c:1618
struct varlena * heap_tuple_untoast_attr(struct varlena *attr)
Definition: tuptoaster.c:172
size_t Size
Definition: c.h:356
#define VARATT_IS_EXTENDED(PTR)
Definition: postgres.h:326
void * palloc(Size size)
Definition: mcxt.c:849
Definition: c.h:439
struct varlena* pg_detoast_datum_packed ( struct varlena datum)

Definition at line 1863 of file fmgr.c.

References heap_tuple_untoast_attr(), VARATT_IS_COMPRESSED, and VARATT_IS_EXTERNAL.

Referenced by text_to_cstring(), and text_to_cstring_buffer().

1864 {
1865  if (VARATT_IS_COMPRESSED(datum) || VARATT_IS_EXTERNAL(datum))
1866  return heap_tuple_untoast_attr(datum);
1867  else
1868  return datum;
1869 }
#define VARATT_IS_COMPRESSED(PTR)
Definition: postgres.h:313
struct varlena * heap_tuple_untoast_attr(struct varlena *attr)
Definition: tuptoaster.c:172
#define VARATT_IS_EXTERNAL(PTR)
Definition: postgres.h:314
struct varlena* pg_detoast_datum_slice ( struct varlena datum,
int32  first,
int32  count 
)

Definition at line 1856 of file fmgr.c.

References heap_tuple_untoast_attr_slice().

1857 {
1858  /* Only get the specified portion from the toast rel */
1859  return heap_tuple_untoast_attr_slice(datum, first, count);
1860 }
struct varlena * heap_tuple_untoast_attr_slice(struct varlena *attr, int32 sliceoffset, int32 slicelength)
Definition: tuptoaster.c:258
Datum ReceiveFunctionCall ( FmgrInfo flinfo,
StringInfo  buf,
Oid  typioparam,
int32  typmod 
)

Definition at line 1681 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, FunctionCallInfoData::flinfo, FmgrInfo::fn_oid, FmgrInfo::fn_strict, FunctionCallInvoke, InitFunctionCallInfoData, Int32GetDatum, InvalidOid, FunctionCallInfoData::isnull, NULL, ObjectIdGetDatum, PointerGetDatum, and result.

Referenced by CopyReadBinaryAttribute(), domain_recv(), OidReceiveFunctionCall(), range_recv(), ReadArrayBinary(), and record_recv().

1683 {
1684  FunctionCallInfoData fcinfo;
1685  Datum result;
1686 
1687  if (buf == NULL && flinfo->fn_strict)
1688  return (Datum) 0; /* just return null result */
1689 
1690  InitFunctionCallInfoData(fcinfo, flinfo, 3, InvalidOid, NULL, NULL);
1691 
1692  fcinfo.arg[0] = PointerGetDatum(buf);
1693  fcinfo.arg[1] = ObjectIdGetDatum(typioparam);
1694  fcinfo.arg[2] = Int32GetDatum(typmod);
1695  fcinfo.argnull[0] = (buf == NULL);
1696  fcinfo.argnull[1] = false;
1697  fcinfo.argnull[2] = false;
1698 
1699  result = FunctionCallInvoke(&fcinfo);
1700 
1701  /* Should get null result if and only if buf is NULL */
1702  if (buf == NULL)
1703  {
1704  if (!fcinfo.isnull)
1705  elog(ERROR, "receive function %u returned non-NULL",
1706  fcinfo.flinfo->fn_oid);
1707  }
1708  else
1709  {
1710  if (fcinfo.isnull)
1711  elog(ERROR, "receive function %u returned NULL",
1712  fcinfo.flinfo->fn_oid);
1713  }
1714 
1715  return result;
1716 }
#define PointerGetDatum(X)
Definition: postgres.h:562
return result
Definition: formatting.c:1618
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
bool fn_strict
Definition: fmgr.h:61
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
#define InvalidOid
Definition: postgres_ext.h:36
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define Int32GetDatum(X)
Definition: postgres.h:485
#define elog
Definition: elog.h:219
static void record_C_func ( HeapTuple  procedureTuple,
PGFunction  user_fn,
const Pg_finfo_record inforec 
)
static

Definition at line 468 of file fmgr.c.

References HASHCTL::entrysize, CFuncHashTabEntry::fn_tid, CFuncHashTabEntry::fn_xmin, HASH_BLOBS, hash_create(), HASH_ELEM, HASH_ENTER, hash_search(), HeapTupleGetOid, HeapTupleHeaderGetRawXmin, CFuncHashTabEntry::inforec, HASHCTL::keysize, MemSet, NULL, HeapTupleData::t_data, HeapTupleData::t_self, and CFuncHashTabEntry::user_fn.

Referenced by fmgr_info_C_lang().

470 {
471  Oid fn_oid = HeapTupleGetOid(procedureTuple);
472  CFuncHashTabEntry *entry;
473  bool found;
474 
475  /* Create the hash table if it doesn't exist yet */
476  if (CFuncHash == NULL)
477  {
478  HASHCTL hash_ctl;
479 
480  MemSet(&hash_ctl, 0, sizeof(hash_ctl));
481  hash_ctl.keysize = sizeof(Oid);
482  hash_ctl.entrysize = sizeof(CFuncHashTabEntry);
483  CFuncHash = hash_create("CFuncHash",
484  100,
485  &hash_ctl,
487  }
488 
489  entry = (CFuncHashTabEntry *)
491  &fn_oid,
492  HASH_ENTER,
493  &found);
494  /* OID is already filled in */
495  entry->fn_xmin = HeapTupleHeaderGetRawXmin(procedureTuple->t_data);
496  entry->fn_tid = procedureTuple->t_self;
497  entry->user_fn = user_fn;
498  entry->inforec = inforec;
499 }
#define HASH_ELEM
Definition: hsearch.h:87
const Pg_finfo_record * inforec
Definition: fmgr.c:49
Size entrysize
Definition: hsearch.h:73
#define MemSet(start, val, len)
Definition: c.h:857
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:885
unsigned int Oid
Definition: postgres_ext.h:31
HeapTupleHeader t_data
Definition: htup.h:67
static HTAB * CFuncHash
Definition: fmgr.c:52
ItemPointerData t_self
Definition: htup.h:65
PGFunction user_fn
Definition: fmgr.c:48
#define HASH_BLOBS
Definition: hsearch.h:88
HTAB * hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
Definition: dynahash.c:301
Size keysize
Definition: hsearch.h:72
#define NULL
Definition: c.h:229
#define HeapTupleHeaderGetRawXmin(tup)
Definition: htup_details.h:302
TransactionId fn_xmin
Definition: fmgr.c:46
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:695
ItemPointerData fn_tid
Definition: fmgr.c:47
bytea* SendFunctionCall ( FmgrInfo flinfo,
Datum  val 
)

Definition at line 1728 of file fmgr.c.

References DatumGetByteaP, and FunctionCall1.

Referenced by array_send(), CopyOneRowTo(), OidSendFunctionCall(), printtup(), printtup_internal_20(), range_send(), and record_send().

1729 {
1730  return DatumGetByteaP(FunctionCall1(flinfo, val));
1731 }
#define DatumGetByteaP(X)
Definition: fmgr.h:295
#define FunctionCall1(flinfo, arg1)
Definition: fmgr.h:602
long val
Definition: informix.c:689

Variable Documentation

HTAB* CFuncHash = NULL
static

Definition at line 52 of file fmgr.c.

Definition at line 37 of file fmgr.c.

Referenced by fmgr_security_definer(), and sepgsql_init_client_label().

Definition at line 36 of file fmgr.c.

Referenced by sepgsql_init_client_label().