PostgreSQL Source Code  git master
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)
 
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)
 
void fmgr_symbol (Oid functionId, char **mod, char **fn)
 
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

◆ CallerFInfoFunctionCall1()

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

Definition at line 1065 of file fmgr.c.

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

1066 {
1067  FunctionCallInfoData fcinfo;
1068  Datum result;
1069 
1070  InitFunctionCallInfoData(fcinfo, flinfo, 1, collation, NULL, NULL);
1071 
1072  fcinfo.arg[0] = arg1;
1073  fcinfo.argnull[0] = false;
1074 
1075  result = (*func) (&fcinfo);
1076 
1077  /* Check for null result, since caller is clearly not expecting one */
1078  if (fcinfo.isnull)
1079  elog(ERROR, "function %p returned NULL", (void *) func);
1080 
1081  return result;
1082 }
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ CallerFInfoFunctionCall2()

Datum CallerFInfoFunctionCall2 ( PGFunction  func,
FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2 
)

Definition at line 1085 of file fmgr.c.

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

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

1086 {
1087  FunctionCallInfoData fcinfo;
1088  Datum result;
1089 
1090  InitFunctionCallInfoData(fcinfo, flinfo, 2, collation, NULL, NULL);
1091 
1092  fcinfo.arg[0] = arg1;
1093  fcinfo.arg[1] = arg2;
1094  fcinfo.argnull[0] = false;
1095  fcinfo.argnull[1] = false;
1096 
1097  result = (*func) (&fcinfo);
1098 
1099  /* Check for null result, since caller is clearly not expecting one */
1100  if (fcinfo.isnull)
1101  elog(ERROR, "function %p returned NULL", (void *) func);
1102 
1103  return result;
1104 }
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ CheckFunctionValidatorAccess()

bool CheckFunctionValidatorAccess ( Oid  validatorOid,
Oid  functionOid 
)

Definition at line 2178 of file fmgr.c.

References ACL_EXECUTE, ACL_USAGE, aclcheck_error(), ACLCHECK_OK, elog, ereport, errcode(), errmsg(), ERROR, GETSTRUCT, GetUserId(), HeapTupleIsValid, LANGOID, NameStr, OBJECT_FUNCTION, OBJECT_LANGUAGE, 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().

2179 {
2180  HeapTuple procTup;
2181  HeapTuple langTup;
2182  Form_pg_proc procStruct;
2183  Form_pg_language langStruct;
2184  AclResult aclresult;
2185 
2186  /*
2187  * Get the function's pg_proc entry. Throw a user-facing error for bad
2188  * OID, because validators can be called with user-specified OIDs.
2189  */
2190  procTup = SearchSysCache1(PROCOID, ObjectIdGetDatum(functionOid));
2191  if (!HeapTupleIsValid(procTup))
2192  ereport(ERROR,
2193  (errcode(ERRCODE_UNDEFINED_FUNCTION),
2194  errmsg("function with OID %u does not exist", functionOid)));
2195  procStruct = (Form_pg_proc) GETSTRUCT(procTup);
2196 
2197  /*
2198  * Fetch pg_language entry to know if this is the correct validation
2199  * function for that pg_proc entry.
2200  */
2201  langTup = SearchSysCache1(LANGOID, ObjectIdGetDatum(procStruct->prolang));
2202  if (!HeapTupleIsValid(langTup))
2203  elog(ERROR, "cache lookup failed for language %u", procStruct->prolang);
2204  langStruct = (Form_pg_language) GETSTRUCT(langTup);
2205 
2206  if (langStruct->lanvalidator != validatorOid)
2207  ereport(ERROR,
2208  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2209  errmsg("language validation function %u called for language %u instead of %u",
2210  validatorOid, procStruct->prolang,
2211  langStruct->lanvalidator)));
2212 
2213  /* first validate that we have permissions to use the language */
2214  aclresult = pg_language_aclcheck(procStruct->prolang, GetUserId(),
2215  ACL_USAGE);
2216  if (aclresult != ACLCHECK_OK)
2217  aclcheck_error(aclresult, OBJECT_LANGUAGE,
2218  NameStr(langStruct->lanname));
2219 
2220  /*
2221  * Check whether we are allowed to execute the function itself. If we can
2222  * execute it, there should be no possible side-effect of
2223  * compiling/validation that execution can't have.
2224  */
2225  aclresult = pg_proc_aclcheck(functionOid, GetUserId(), ACL_EXECUTE);
2226  if (aclresult != ACLCHECK_OK)
2227  aclcheck_error(aclresult, OBJECT_FUNCTION, NameStr(procStruct->proname));
2228 
2229  ReleaseSysCache(procTup);
2230  ReleaseSysCache(langTup);
2231 
2232  return true;
2233 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:673
Oid GetUserId(void)
Definition: miscinit.c:379
int errcode(int sqlerrcode)
Definition: elog.c:575
AclResult pg_language_aclcheck(Oid lang_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4660
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3348
#define ObjectIdGetDatum(X)
Definition: postgres.h:490
#define ERROR
Definition: elog.h:43
#define ACL_USAGE
Definition: parsenodes.h:82
#define ereport(elevel, rest)
Definition: elog.h:122
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
AclResult
Definition: acl.h:178
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:132
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_language * Form_pg_language
Definition: pg_language.h:49
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define ACL_EXECUTE
Definition: parsenodes.h:81
AclResult pg_proc_aclcheck(Oid proc_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4648
#define NameStr(name)
Definition: c.h:576
#define elog
Definition: elog.h:219

◆ clear_external_function_hash()

void clear_external_function_hash ( void *  filehandle)

Definition at line 593 of file fmgr.c.

References hash_destroy().

Referenced by internal_unload_library().

594 {
595  if (CFuncHash)
597  CFuncHash = NULL;
598 }
void hash_destroy(HTAB *hashp)
Definition: dynahash.c:814
static HTAB * CFuncHash
Definition: fmgr.c:52

◆ DirectFunctionCall1Coll()

Datum DirectFunctionCall1Coll ( PGFunction  func,
Oid  collation,
Datum  arg1 
)

Definition at line 792 of file fmgr.c.

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

Referenced by Generic_Text_IC_like(), and libpqrcv_create_slot().

793 {
794  FunctionCallInfoData fcinfo;
795  Datum result;
796 
797  InitFunctionCallInfoData(fcinfo, NULL, 1, collation, NULL, NULL);
798 
799  fcinfo.arg[0] = arg1;
800  fcinfo.argnull[0] = false;
801 
802  result = (*func) (&fcinfo);
803 
804  /* Check for null result, since caller is clearly not expecting one */
805  if (fcinfo.isnull)
806  elog(ERROR, "function %p returned NULL", (void *) func);
807 
808  return result;
809 }
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ DirectFunctionCall2Coll()

Datum DirectFunctionCall2Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2 
)

Definition at line 812 of file fmgr.c.

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

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

813 {
814  FunctionCallInfoData fcinfo;
815  Datum result;
816 
817  InitFunctionCallInfoData(fcinfo, NULL, 2, collation, NULL, NULL);
818 
819  fcinfo.arg[0] = arg1;
820  fcinfo.arg[1] = arg2;
821  fcinfo.argnull[0] = false;
822  fcinfo.argnull[1] = false;
823 
824  result = (*func) (&fcinfo);
825 
826  /* Check for null result, since caller is clearly not expecting one */
827  if (fcinfo.isnull)
828  elog(ERROR, "function %p returned NULL", (void *) func);
829 
830  return result;
831 }
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ DirectFunctionCall3Coll()

Datum DirectFunctionCall3Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3 
)

Definition at line 834 of file fmgr.c.

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

836 {
837  FunctionCallInfoData fcinfo;
838  Datum result;
839 
840  InitFunctionCallInfoData(fcinfo, NULL, 3, collation, NULL, NULL);
841 
842  fcinfo.arg[0] = arg1;
843  fcinfo.arg[1] = arg2;
844  fcinfo.arg[2] = arg3;
845  fcinfo.argnull[0] = false;
846  fcinfo.argnull[1] = false;
847  fcinfo.argnull[2] = false;
848 
849  result = (*func) (&fcinfo);
850 
851  /* Check for null result, since caller is clearly not expecting one */
852  if (fcinfo.isnull)
853  elog(ERROR, "function %p returned NULL", (void *) func);
854 
855  return result;
856 }
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ DirectFunctionCall4Coll()

Datum DirectFunctionCall4Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4 
)

Definition at line 859 of file fmgr.c.

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

Referenced by execute_extension_script().

861 {
862  FunctionCallInfoData fcinfo;
863  Datum result;
864 
865  InitFunctionCallInfoData(fcinfo, NULL, 4, collation, NULL, NULL);
866 
867  fcinfo.arg[0] = arg1;
868  fcinfo.arg[1] = arg2;
869  fcinfo.arg[2] = arg3;
870  fcinfo.arg[3] = arg4;
871  fcinfo.argnull[0] = false;
872  fcinfo.argnull[1] = false;
873  fcinfo.argnull[2] = false;
874  fcinfo.argnull[3] = false;
875 
876  result = (*func) (&fcinfo);
877 
878  /* Check for null result, since caller is clearly not expecting one */
879  if (fcinfo.isnull)
880  elog(ERROR, "function %p returned NULL", (void *) func);
881 
882  return result;
883 }
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ DirectFunctionCall5Coll()

Datum DirectFunctionCall5Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5 
)

Definition at line 886 of file fmgr.c.

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

888 {
889  FunctionCallInfoData fcinfo;
890  Datum result;
891 
892  InitFunctionCallInfoData(fcinfo, NULL, 5, collation, NULL, NULL);
893 
894  fcinfo.arg[0] = arg1;
895  fcinfo.arg[1] = arg2;
896  fcinfo.arg[2] = arg3;
897  fcinfo.arg[3] = arg4;
898  fcinfo.arg[4] = arg5;
899  fcinfo.argnull[0] = false;
900  fcinfo.argnull[1] = false;
901  fcinfo.argnull[2] = false;
902  fcinfo.argnull[3] = false;
903  fcinfo.argnull[4] = false;
904 
905  result = (*func) (&fcinfo);
906 
907  /* Check for null result, since caller is clearly not expecting one */
908  if (fcinfo.isnull)
909  elog(ERROR, "function %p returned NULL", (void *) func);
910 
911  return result;
912 }
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ DirectFunctionCall6Coll()

Datum DirectFunctionCall6Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6 
)

Definition at line 915 of file fmgr.c.

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

918 {
919  FunctionCallInfoData fcinfo;
920  Datum result;
921 
922  InitFunctionCallInfoData(fcinfo, NULL, 6, collation, NULL, NULL);
923 
924  fcinfo.arg[0] = arg1;
925  fcinfo.arg[1] = arg2;
926  fcinfo.arg[2] = arg3;
927  fcinfo.arg[3] = arg4;
928  fcinfo.arg[4] = arg5;
929  fcinfo.arg[5] = arg6;
930  fcinfo.argnull[0] = false;
931  fcinfo.argnull[1] = false;
932  fcinfo.argnull[2] = false;
933  fcinfo.argnull[3] = false;
934  fcinfo.argnull[4] = false;
935  fcinfo.argnull[5] = false;
936 
937  result = (*func) (&fcinfo);
938 
939  /* Check for null result, since caller is clearly not expecting one */
940  if (fcinfo.isnull)
941  elog(ERROR, "function %p returned NULL", (void *) func);
942 
943  return result;
944 }
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ DirectFunctionCall7Coll()

Datum DirectFunctionCall7Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7 
)

Definition at line 947 of file fmgr.c.

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

950 {
951  FunctionCallInfoData fcinfo;
952  Datum result;
953 
954  InitFunctionCallInfoData(fcinfo, NULL, 7, collation, NULL, NULL);
955 
956  fcinfo.arg[0] = arg1;
957  fcinfo.arg[1] = arg2;
958  fcinfo.arg[2] = arg3;
959  fcinfo.arg[3] = arg4;
960  fcinfo.arg[4] = arg5;
961  fcinfo.arg[5] = arg6;
962  fcinfo.arg[6] = arg7;
963  fcinfo.argnull[0] = false;
964  fcinfo.argnull[1] = false;
965  fcinfo.argnull[2] = false;
966  fcinfo.argnull[3] = false;
967  fcinfo.argnull[4] = false;
968  fcinfo.argnull[5] = false;
969  fcinfo.argnull[6] = false;
970 
971  result = (*func) (&fcinfo);
972 
973  /* Check for null result, since caller is clearly not expecting one */
974  if (fcinfo.isnull)
975  elog(ERROR, "function %p returned NULL", (void *) func);
976 
977  return result;
978 }
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ DirectFunctionCall8Coll()

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 981 of file fmgr.c.

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

984 {
985  FunctionCallInfoData fcinfo;
986  Datum result;
987 
988  InitFunctionCallInfoData(fcinfo, NULL, 8, collation, NULL, NULL);
989 
990  fcinfo.arg[0] = arg1;
991  fcinfo.arg[1] = arg2;
992  fcinfo.arg[2] = arg3;
993  fcinfo.arg[3] = arg4;
994  fcinfo.arg[4] = arg5;
995  fcinfo.arg[5] = arg6;
996  fcinfo.arg[6] = arg7;
997  fcinfo.arg[7] = arg8;
998  fcinfo.argnull[0] = false;
999  fcinfo.argnull[1] = false;
1000  fcinfo.argnull[2] = false;
1001  fcinfo.argnull[3] = false;
1002  fcinfo.argnull[4] = false;
1003  fcinfo.argnull[5] = false;
1004  fcinfo.argnull[6] = false;
1005  fcinfo.argnull[7] = false;
1006 
1007  result = (*func) (&fcinfo);
1008 
1009  /* Check for null result, since caller is clearly not expecting one */
1010  if (fcinfo.isnull)
1011  elog(ERROR, "function %p returned NULL", (void *) func);
1012 
1013  return result;
1014 }
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ DirectFunctionCall9Coll()

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 1017 of file fmgr.c.

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

1021 {
1022  FunctionCallInfoData fcinfo;
1023  Datum result;
1024 
1025  InitFunctionCallInfoData(fcinfo, NULL, 9, collation, NULL, NULL);
1026 
1027  fcinfo.arg[0] = arg1;
1028  fcinfo.arg[1] = arg2;
1029  fcinfo.arg[2] = arg3;
1030  fcinfo.arg[3] = arg4;
1031  fcinfo.arg[4] = arg5;
1032  fcinfo.arg[5] = arg6;
1033  fcinfo.arg[6] = arg7;
1034  fcinfo.arg[7] = arg8;
1035  fcinfo.arg[8] = arg9;
1036  fcinfo.argnull[0] = false;
1037  fcinfo.argnull[1] = false;
1038  fcinfo.argnull[2] = false;
1039  fcinfo.argnull[3] = false;
1040  fcinfo.argnull[4] = false;
1041  fcinfo.argnull[5] = false;
1042  fcinfo.argnull[6] = false;
1043  fcinfo.argnull[7] = false;
1044  fcinfo.argnull[8] = false;
1045 
1046  result = (*func) (&fcinfo);
1047 
1048  /* Check for null result, since caller is clearly not expecting one */
1049  if (fcinfo.isnull)
1050  elog(ERROR, "function %p returned NULL", (void *) func);
1051 
1052  return result;
1053 }
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ fetch_finfo_record()

const Pg_finfo_record* fetch_finfo_record ( void *  filehandle,
const char *  funcname 
)

Definition at line 469 of file fmgr.c.

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

Referenced by fmgr_c_validator(), and fmgr_info_C_lang().

470 {
471  char *infofuncname;
472  PGFInfoFunction infofunc;
473  const Pg_finfo_record *inforec;
474 
475  infofuncname = psprintf("pg_finfo_%s", funcname);
476 
477  /* Try to look up the info function */
478  infofunc = (PGFInfoFunction) lookup_external_function(filehandle,
479  infofuncname);
480  if (infofunc == NULL)
481  {
482  ereport(ERROR,
483  (errcode(ERRCODE_UNDEFINED_FUNCTION),
484  errmsg("could not find function information for function \"%s\"",
485  funcname),
486  errhint("SQL-callable functions need an accompanying PG_FUNCTION_INFO_V1(funcname).")));
487  return NULL; /* silence compiler */
488  }
489 
490  /* Found, so call it */
491  inforec = (*infofunc) ();
492 
493  /* Validate result as best we can */
494  if (inforec == NULL)
495  elog(ERROR, "null result from info function \"%s\"", infofuncname);
496  switch (inforec->api_version)
497  {
498  case 1:
499  /* OK, no additional fields to validate */
500  break;
501  default:
502  ereport(ERROR,
503  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
504  errmsg("unrecognized API version %d reported by info function \"%s\"",
505  inforec->api_version, infofuncname)));
506  break;
507  }
508 
509  pfree(infofuncname);
510  return inforec;
511 }
PGFunction lookup_external_function(void *filehandle, const char *funcname)
Definition: dfmgr.c:162
int errhint(const char *fmt,...)
Definition: elog.c:987
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
int errcode(int sqlerrcode)
Definition: elog.c:575
void pfree(void *pointer)
Definition: mcxt.c:1031
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
const Pg_finfo_record *(* PGFInfoFunction)(void)
Definition: fmgr.h:365
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219
int api_version
Definition: fmgr.h:360

◆ Float4GetDatum()

Datum Float4GetDatum ( float4  X)

Definition at line 1888 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().

1889 {
1890  float4 *retval = (float4 *) palloc(sizeof(float4));
1891 
1892  *retval = X;
1893  return PointerGetDatum(retval);
1894 }
#define PointerGetDatum(X)
Definition: postgres.h:539
float float4
Definition: c.h:457
void * palloc(Size size)
Definition: mcxt.c:924

◆ Float8GetDatum()

Datum Float8GetDatum ( float8  X)

Definition at line 1900 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(), spg_kd_picksplit(), SPI_sql_row_to_xmlelement(), and SV_to_JsonbValue().

1901 {
1902  float8 *retval = (float8 *) palloc(sizeof(float8));
1903 
1904  *retval = X;
1905  return PointerGetDatum(retval);
1906 }
#define PointerGetDatum(X)
Definition: postgres.h:539
double float8
Definition: c.h:458
void * palloc(Size size)
Definition: mcxt.c:924

◆ fmgr_info()

void fmgr_info ( Oid  functionId,
FmgrInfo finfo 
)

Definition at line 123 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(), create_foreign_modify(), eqjoinsel_inner(), eqjoinsel_semi(), EventTriggerInvoke(), ExecBuildGroupingEqual(), ExecCallTriggerFunc(), ExecHashTableCreate(), ExecInitAgg(), ExecInitExprRec(), ExecInitFunc(), ExecInitSubPlan(), ExecInitTableFuncScan(), ExecInitWindowAgg(), execTuplesHashPrepare(), ExecuteCallStmt(), 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(), perform_pruning_base_step(), plperl_ref_from_pg_array(), prefix_quals(), prefix_selectivity(), prepare_query_params(), printtup_prepare_info(), scalararraysel(), scalarineqsel(), ScanKeyEntryInitialize(), ScanKeyInit(), text_format(), TupleDescGetAttInMetadata(), and var_eq_const().

124 {
125  fmgr_info_cxt_security(functionId, finfo, CurrentMemoryContext, false);
126 }
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
static void fmgr_info_cxt_security(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt, bool ignore_security)
Definition: fmgr.c:143

◆ fmgr_info_C_lang()

static void fmgr_info_C_lang ( Oid  functionId,
FmgrInfo finfo,
HeapTuple  procedureTuple 
)
static

Definition at line 358 of file fmgr.c.

References 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().

359 {
360  CFuncHashTabEntry *hashentry;
361  PGFunction user_fn;
362  const Pg_finfo_record *inforec;
363  bool isnull;
364 
365  /*
366  * See if we have the function address cached already
367  */
368  hashentry = lookup_C_func(procedureTuple);
369  if (hashentry)
370  {
371  user_fn = hashentry->user_fn;
372  inforec = hashentry->inforec;
373  }
374  else
375  {
376  Datum prosrcattr,
377  probinattr;
378  char *prosrcstring,
379  *probinstring;
380  void *libraryhandle;
381 
382  /*
383  * Get prosrc and probin strings (link symbol and library filename).
384  * While in general these columns might be null, that's not allowed
385  * for C-language functions.
386  */
387  prosrcattr = SysCacheGetAttr(PROCOID, procedureTuple,
388  Anum_pg_proc_prosrc, &isnull);
389  if (isnull)
390  elog(ERROR, "null prosrc for C function %u", functionId);
391  prosrcstring = TextDatumGetCString(prosrcattr);
392 
393  probinattr = SysCacheGetAttr(PROCOID, procedureTuple,
394  Anum_pg_proc_probin, &isnull);
395  if (isnull)
396  elog(ERROR, "null probin for C function %u", functionId);
397  probinstring = TextDatumGetCString(probinattr);
398 
399  /* Look up the function itself */
400  user_fn = load_external_function(probinstring, prosrcstring, true,
401  &libraryhandle);
402 
403  /* Get the function information record (real or default) */
404  inforec = fetch_finfo_record(libraryhandle, prosrcstring);
405 
406  /* Cache the addresses for later calls */
407  record_C_func(procedureTuple, user_fn, inforec);
408 
409  pfree(prosrcstring);
410  pfree(probinstring);
411  }
412 
413  switch (inforec->api_version)
414  {
415  case 1:
416  /* New style: call directly */
417  finfo->fn_addr = user_fn;
418  break;
419  default:
420  /* Shouldn't get here if fetch_finfo_record did its job */
421  elog(ERROR, "unrecognized function API version: %d",
422  inforec->api_version);
423  break;
424  }
425 }
Datum(* PGFunction)(FunctionCallInfo fcinfo)
Definition: fmgr.h:40
PGFunction fn_addr
Definition: fmgr.h:58
const Pg_finfo_record * inforec
Definition: fmgr.c:49
void pfree(void *pointer)
Definition: mcxt.c:1031
#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:96
uintptr_t Datum
Definition: postgres.h:365
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1368
static void record_C_func(HeapTuple procedureTuple, PGFunction user_fn, const Pg_finfo_record *inforec)
Definition: fmgr.c:553
static CFuncHashTabEntry * lookup_C_func(HeapTuple procedureTuple)
Definition: fmgr.c:529
const Pg_finfo_record * fetch_finfo_record(void *filehandle, const char *funcname)
Definition: fmgr.c:469
#define elog
Definition: elog.h:219
int api_version
Definition: fmgr.h:360

◆ fmgr_info_copy()

void fmgr_info_copy ( FmgrInfo dstinfo,
FmgrInfo srcinfo,
MemoryContext  destcxt 
)

Definition at line 609 of file fmgr.c.

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

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

611 {
612  memcpy(dstinfo, srcinfo, sizeof(FmgrInfo));
613  dstinfo->fn_mcxt = destcxt;
614  dstinfo->fn_extra = NULL;
615 }
Definition: fmgr.h:56
MemoryContext fn_mcxt
Definition: fmgr.h:65
void * fn_extra
Definition: fmgr.h:64

◆ fmgr_info_cxt()

◆ fmgr_info_cxt_security()

static void fmgr_info_cxt_security ( Oid  functionId,
FmgrInfo finfo,
MemoryContext  mcxt,
bool  ignore_security 
)
static

Definition at line 143 of file fmgr.c.

References 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, InvalidOid, FmgrBuiltin::nargs, ObjectIdGetDatum, pfree(), PROCOID, ReleaseSysCache(), FmgrBuiltin::retset, SearchSysCache1(), 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().

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

◆ fmgr_info_other_lang()

static void fmgr_info_other_lang ( Oid  functionId,
FmgrInfo finfo,
HeapTuple  procedureTuple 
)
static

Definition at line 432 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().

433 {
434  Form_pg_proc procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
435  Oid language = procedureStruct->prolang;
436  HeapTuple languageTuple;
437  Form_pg_language languageStruct;
438  FmgrInfo plfinfo;
439 
440  languageTuple = SearchSysCache1(LANGOID, ObjectIdGetDatum(language));
441  if (!HeapTupleIsValid(languageTuple))
442  elog(ERROR, "cache lookup failed for language %u", language);
443  languageStruct = (Form_pg_language) GETSTRUCT(languageTuple);
444 
445  /*
446  * Look up the language's call handler function, ignoring any attributes
447  * that would normally cause insertion of fmgr_security_definer. We need
448  * to get back a bare pointer to the actual C-language function.
449  */
450  fmgr_info_cxt_security(languageStruct->lanplcallfoid, &plfinfo,
451  CurrentMemoryContext, true);
452  finfo->fn_addr = plfinfo.fn_addr;
453 
454  ReleaseSysCache(languageTuple);
455 }
Definition: fmgr.h:56
#define GETSTRUCT(TUP)
Definition: htup_details.h:673
PGFunction fn_addr
Definition: fmgr.h:58
unsigned int Oid
Definition: postgres_ext.h:31
#define ObjectIdGetDatum(X)
Definition: postgres.h:490
#define ERROR
Definition: elog.h:43
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:132
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_language * Form_pg_language
Definition: pg_language.h:49
#define elog
Definition: elog.h:219
static void fmgr_info_cxt_security(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt, bool ignore_security)
Definition: fmgr.c:143

◆ fmgr_internal_function()

Oid fmgr_internal_function ( const char *  proname)

Definition at line 624 of file fmgr.c.

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

Referenced by fmgr_internal_validator().

625 {
626  const FmgrBuiltin *fbp = fmgr_lookupByName(proname);
627 
628  if (fbp == NULL)
629  return InvalidOid;
630  return fbp->foid;
631 }
Oid foid
Definition: fmgrtab.h:27
static const FmgrBuiltin * fmgr_lookupByName(const char *name)
Definition: fmgr.c:97
#define InvalidOid
Definition: postgres_ext.h:36

◆ fmgr_isbuiltin()

static const FmgrBuiltin* fmgr_isbuiltin ( Oid  id)
static

Definition at line 72 of file fmgr.c.

References FirstBootstrapObjectId, fmgr_builtin_oid_index, fmgr_builtins, and InvalidOidBuiltinMapping.

Referenced by fmgr_info_cxt_security().

73 {
74  uint16 index;
75 
76  /* fast lookup only possible if original oid still assigned */
77  if (id >= FirstBootstrapObjectId)
78  return NULL;
79 
80  /*
81  * Lookup function data. If there's a miss in that range it's likely a
82  * nonexistant function, returning NULL here will trigger an ERROR later.
83  */
84  index = fmgr_builtin_oid_index[id];
85  if (index == InvalidOidBuiltinMapping)
86  return NULL;
87 
88  return &fmgr_builtins[index];
89 }
const uint16 fmgr_builtin_oid_index[FirstBootstrapObjectId]
const FmgrBuiltin fmgr_builtins[]
#define InvalidOidBuiltinMapping
Definition: fmgrtab.h:43
Definition: type.h:89
unsigned short uint16
Definition: c.h:324
#define FirstBootstrapObjectId
Definition: transam.h:93

◆ fmgr_lookupByName()

static const FmgrBuiltin* fmgr_lookupByName ( const char *  name)
static

Definition at line 97 of file fmgr.c.

References fmgr_builtins, fmgr_nbuiltins, and i.

Referenced by fmgr_info_cxt_security(), and fmgr_internal_function().

98 {
99  int i;
100 
101  for (i = 0; i < fmgr_nbuiltins; i++)
102  {
103  if (strcmp(name, fmgr_builtins[i].funcName) == 0)
104  return fmgr_builtins + i;
105  }
106  return NULL;
107 }
const int fmgr_nbuiltins
const FmgrBuiltin fmgr_builtins[]
const char * name
Definition: encode.c:521
int i

◆ fmgr_security_definer()

Datum fmgr_security_definer ( PG_FUNCTION_ARGS  )

Definition at line 659 of file fmgr.c.

References 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(), 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(), SearchSysCache1(), SECURITY_LOCAL_USERID_CHANGE, SetUserIdAndSecContext(), superuser(), SysCacheGetAttr(), and fmgr_security_definer_cache::userid.

Referenced by fmgr_info_cxt_security().

660 {
661  Datum result;
662  struct fmgr_security_definer_cache *volatile fcache;
663  FmgrInfo *save_flinfo;
664  Oid save_userid;
665  int save_sec_context;
666  volatile int save_nestlevel;
667  PgStat_FunctionCallUsage fcusage;
668 
669  if (!fcinfo->flinfo->fn_extra)
670  {
671  HeapTuple tuple;
672  Form_pg_proc procedureStruct;
673  Datum datum;
674  bool isnull;
675  MemoryContext oldcxt;
676 
677  fcache = MemoryContextAllocZero(fcinfo->flinfo->fn_mcxt,
678  sizeof(*fcache));
679 
680  fmgr_info_cxt_security(fcinfo->flinfo->fn_oid, &fcache->flinfo,
681  fcinfo->flinfo->fn_mcxt, true);
682  fcache->flinfo.fn_expr = fcinfo->flinfo->fn_expr;
683 
684  tuple = SearchSysCache1(PROCOID,
685  ObjectIdGetDatum(fcinfo->flinfo->fn_oid));
686  if (!HeapTupleIsValid(tuple))
687  elog(ERROR, "cache lookup failed for function %u",
688  fcinfo->flinfo->fn_oid);
689  procedureStruct = (Form_pg_proc) GETSTRUCT(tuple);
690 
691  if (procedureStruct->prosecdef)
692  fcache->userid = procedureStruct->proowner;
693 
694  datum = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_proconfig,
695  &isnull);
696  if (!isnull)
697  {
698  oldcxt = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
699  fcache->proconfig = DatumGetArrayTypePCopy(datum);
700  MemoryContextSwitchTo(oldcxt);
701  }
702 
703  ReleaseSysCache(tuple);
704 
705  fcinfo->flinfo->fn_extra = fcache;
706  }
707  else
708  fcache = fcinfo->flinfo->fn_extra;
709 
710  /* GetUserIdAndSecContext is cheap enough that no harm in a wasted call */
711  GetUserIdAndSecContext(&save_userid, &save_sec_context);
712  if (fcache->proconfig) /* Need a new GUC nesting level */
713  save_nestlevel = NewGUCNestLevel();
714  else
715  save_nestlevel = 0; /* keep compiler quiet */
716 
717  if (OidIsValid(fcache->userid))
719  save_sec_context | SECURITY_LOCAL_USERID_CHANGE);
720 
721  if (fcache->proconfig)
722  {
723  ProcessGUCArray(fcache->proconfig,
727  }
728 
729  /* function manager hook */
730  if (fmgr_hook)
731  (*fmgr_hook) (FHET_START, &fcache->flinfo, &fcache->arg);
732 
733  /*
734  * We don't need to restore GUC or userid settings on error, because the
735  * ensuing xact or subxact abort will do that. The PG_TRY block is only
736  * needed to clean up the flinfo link.
737  */
738  save_flinfo = fcinfo->flinfo;
739 
740  PG_TRY();
741  {
742  fcinfo->flinfo = &fcache->flinfo;
743 
744  /* See notes in fmgr_info_cxt_security */
745  pgstat_init_function_usage(fcinfo, &fcusage);
746 
747  result = FunctionCallInvoke(fcinfo);
748 
749  /*
750  * We could be calling either a regular or a set-returning function,
751  * so we have to test to see what finalize flag to use.
752  */
753  pgstat_end_function_usage(&fcusage,
754  (fcinfo->resultinfo == NULL ||
755  !IsA(fcinfo->resultinfo, ReturnSetInfo) ||
756  ((ReturnSetInfo *) fcinfo->resultinfo)->isDone != ExprMultipleResult));
757  }
758  PG_CATCH();
759  {
760  fcinfo->flinfo = save_flinfo;
761  if (fmgr_hook)
762  (*fmgr_hook) (FHET_ABORT, &fcache->flinfo, &fcache->arg);
763  PG_RE_THROW();
764  }
765  PG_END_TRY();
766 
767  fcinfo->flinfo = save_flinfo;
768 
769  if (fcache->proconfig)
770  AtEOXact_GUC(true, save_nestlevel);
771  if (OidIsValid(fcache->userid))
772  SetUserIdAndSecContext(save_userid, save_sec_context);
773  if (fmgr_hook)
774  (*fmgr_hook) (FHET_END, &fcache->flinfo, &fcache->arg);
775 
776  return result;
777 }
Definition: fmgr.h:56
#define IsA(nodeptr, _type_)
Definition: nodes.h:568
#define GETSTRUCT(TUP)
Definition: htup_details.h:673
MemoryContext fn_mcxt
Definition: fmgr.h:65
void SetUserIdAndSecContext(Oid userid, int sec_context)
Definition: miscinit.c:491
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
bool superuser(void)
Definition: superuser.c:47
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:605
#define ObjectIdGetDatum(X)
Definition: postgres.h:490
#define ERROR
Definition: elog.h:43
Definition: guc.h:75
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:142
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
Definition: miscinit.c:484
void AtEOXact_GUC(bool isCommit, int nestLevel)
Definition: guc.c:5310
Definition: fmgr.h:723
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
ArrayType * proconfig
Definition: fmgr.c:644
uintptr_t Datum
Definition: postgres.h:365
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1368
#define DatumGetArrayTypePCopy(X)
Definition: array.h:247
PGDLLIMPORT fmgr_hook_type fmgr_hook
Definition: fmgr.c:37
#define SECURITY_LOCAL_USERID_CHANGE
Definition: miscadmin.h:297
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:132
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:814
void ProcessGUCArray(ArrayType *array, GucContext context, GucSource source, GucAction action)
Definition: guc.c:9671
#define PG_CATCH()
Definition: elog.h:293
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
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:1653
void pgstat_init_function_usage(FunctionCallInfoData *fcinfo, PgStat_FunctionCallUsage *fcu)
Definition: pgstat.c:1581
int NewGUCNestLevel(void)
Definition: guc.c:5296
#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:143

◆ fmgr_symbol()

void fmgr_symbol ( Oid  functionId,
char **  mod,
char **  fn 
)

Definition at line 280 of file fmgr.c.

References elog, ERROR, FmgrHookIsNeeded, GETSTRUCT, heap_attisnull(), HeapTupleIsValid, ObjectIdGetDatum, PROCOID, pstrdup(), ReleaseSysCache(), SearchSysCache1(), SysCacheGetAttr(), and TextDatumGetCString.

Referenced by llvm_function_reference().

281 {
282  HeapTuple procedureTuple;
283  Form_pg_proc procedureStruct;
284  bool isnull;
285  Datum prosrcattr;
286  Datum probinattr;
287 
288  /* Otherwise we need the pg_proc entry */
289  procedureTuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(functionId));
290  if (!HeapTupleIsValid(procedureTuple))
291  elog(ERROR, "cache lookup failed for function %u", functionId);
292  procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
293 
294  /*
295  */
296  if (procedureStruct->prosecdef ||
297  !heap_attisnull(procedureTuple, Anum_pg_proc_proconfig, NULL) ||
298  FmgrHookIsNeeded(functionId))
299  {
300  *mod = NULL; /* core binary */
301  *fn = pstrdup("fmgr_security_definer");
302  ReleaseSysCache(procedureTuple);
303  return;
304  }
305 
306  /* see fmgr_info_cxt_security for the individual cases */
307  switch (procedureStruct->prolang)
308  {
309  case INTERNALlanguageId:
310  prosrcattr = SysCacheGetAttr(PROCOID, procedureTuple,
311  Anum_pg_proc_prosrc, &isnull);
312  if (isnull)
313  elog(ERROR, "null prosrc");
314 
315  *mod = NULL; /* core binary */
316  *fn = TextDatumGetCString(prosrcattr);
317  break;
318 
319  case ClanguageId:
320  prosrcattr = SysCacheGetAttr(PROCOID, procedureTuple,
321  Anum_pg_proc_prosrc, &isnull);
322  if (isnull)
323  elog(ERROR, "null prosrc for C function %u", functionId);
324 
325  probinattr = SysCacheGetAttr(PROCOID, procedureTuple,
326  Anum_pg_proc_probin, &isnull);
327  if (isnull)
328  elog(ERROR, "null probin for C function %u", functionId);
329 
330  /*
331  * No need to check symbol presence / API version here, already
332  * checked in fmgr_info_cxt_security.
333  */
334  *mod = TextDatumGetCString(probinattr);
335  *fn = TextDatumGetCString(prosrcattr);
336  break;
337 
338  case SQLlanguageId:
339  *mod = NULL; /* core binary */
340  *fn = pstrdup("fmgr_sql");
341  break;
342 
343  default:
344  *mod = NULL;
345  *fn = NULL; /* unknown, pass pointer */
346  break;
347  }
348 
349  ReleaseSysCache(procedureTuple);
350 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:673
char * pstrdup(const char *in)
Definition: mcxt.c:1161
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
Definition: heaptuple.c:397
#define FmgrHookIsNeeded(fn_oid)
Definition: fmgr.h:735
#define ObjectIdGetDatum(X)
Definition: postgres.h:490
#define ERROR
Definition: elog.h:43
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
#define TextDatumGetCString(d)
Definition: builtins.h:96
uintptr_t Datum
Definition: postgres.h:365
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1368
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:132
static void * fn(void *arg)
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define elog
Definition: elog.h:219

◆ FunctionCall1Coll()

Datum FunctionCall1Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1 
)

Definition at line 1112 of file fmgr.c.

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

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

1113 {
1114  FunctionCallInfoData fcinfo;
1115  Datum result;
1116 
1117  InitFunctionCallInfoData(fcinfo, flinfo, 1, collation, NULL, NULL);
1118 
1119  fcinfo.arg[0] = arg1;
1120  fcinfo.argnull[0] = false;
1121 
1122  result = FunctionCallInvoke(&fcinfo);
1123 
1124  /* Check for null result, since caller is clearly not expecting one */
1125  if (fcinfo.isnull)
1126  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1127 
1128  return result;
1129 }
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:142
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ FunctionCall2Coll()

Datum FunctionCall2Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2 
)

Definition at line 1132 of file fmgr.c.

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

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(), hash_range_extended(), histogram_selectivity(), ineq_histogram_selectivity(), make_greater_string(), mcv_selectivity(), partition_list_bsearch(), 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().

1133 {
1134  FunctionCallInfoData fcinfo;
1135  Datum result;
1136 
1137  InitFunctionCallInfoData(fcinfo, flinfo, 2, collation, NULL, NULL);
1138 
1139  fcinfo.arg[0] = arg1;
1140  fcinfo.arg[1] = arg2;
1141  fcinfo.argnull[0] = false;
1142  fcinfo.argnull[1] = false;
1143 
1144  result = FunctionCallInvoke(&fcinfo);
1145 
1146  /* Check for null result, since caller is clearly not expecting one */
1147  if (fcinfo.isnull)
1148  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1149 
1150  return result;
1151 }
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:142
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ FunctionCall3Coll()

Datum FunctionCall3Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3 
)

Definition at line 1154 of file fmgr.c.

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

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

1156 {
1157  FunctionCallInfoData fcinfo;
1158  Datum result;
1159 
1160  InitFunctionCallInfoData(fcinfo, flinfo, 3, collation, NULL, NULL);
1161 
1162  fcinfo.arg[0] = arg1;
1163  fcinfo.arg[1] = arg2;
1164  fcinfo.arg[2] = arg3;
1165  fcinfo.argnull[0] = false;
1166  fcinfo.argnull[1] = false;
1167  fcinfo.argnull[2] = false;
1168 
1169  result = FunctionCallInvoke(&fcinfo);
1170 
1171  /* Check for null result, since caller is clearly not expecting one */
1172  if (fcinfo.isnull)
1173  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1174 
1175  return result;
1176 }
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:142
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ FunctionCall4Coll()

Datum FunctionCall4Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4 
)

Definition at line 1179 of file fmgr.c.

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

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

1181 {
1182  FunctionCallInfoData fcinfo;
1183  Datum result;
1184 
1185  InitFunctionCallInfoData(fcinfo, flinfo, 4, collation, NULL, NULL);
1186 
1187  fcinfo.arg[0] = arg1;
1188  fcinfo.arg[1] = arg2;
1189  fcinfo.arg[2] = arg3;
1190  fcinfo.arg[3] = arg4;
1191  fcinfo.argnull[0] = false;
1192  fcinfo.argnull[1] = false;
1193  fcinfo.argnull[2] = false;
1194  fcinfo.argnull[3] = false;
1195 
1196  result = FunctionCallInvoke(&fcinfo);
1197 
1198  /* Check for null result, since caller is clearly not expecting one */
1199  if (fcinfo.isnull)
1200  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1201 
1202  return result;
1203 }
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:142
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ FunctionCall5Coll()

Datum FunctionCall5Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5 
)

Definition at line 1206 of file fmgr.c.

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

Referenced by gistindex_keytest(), scalararraysel(), update_frameheadpos(), and update_frametailpos().

1208 {
1209  FunctionCallInfoData fcinfo;
1210  Datum result;
1211 
1212  InitFunctionCallInfoData(fcinfo, flinfo, 5, collation, NULL, NULL);
1213 
1214  fcinfo.arg[0] = arg1;
1215  fcinfo.arg[1] = arg2;
1216  fcinfo.arg[2] = arg3;
1217  fcinfo.arg[3] = arg4;
1218  fcinfo.arg[4] = arg5;
1219  fcinfo.argnull[0] = false;
1220  fcinfo.argnull[1] = false;
1221  fcinfo.argnull[2] = false;
1222  fcinfo.argnull[3] = false;
1223  fcinfo.argnull[4] = false;
1224 
1225  result = FunctionCallInvoke(&fcinfo);
1226 
1227  /* Check for null result, since caller is clearly not expecting one */
1228  if (fcinfo.isnull)
1229  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1230 
1231  return result;
1232 }
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:142
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ FunctionCall6Coll()

Datum FunctionCall6Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6 
)

Definition at line 1235 of file fmgr.c.

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

1238 {
1239  FunctionCallInfoData fcinfo;
1240  Datum result;
1241 
1242  InitFunctionCallInfoData(fcinfo, flinfo, 6, collation, NULL, NULL);
1243 
1244  fcinfo.arg[0] = arg1;
1245  fcinfo.arg[1] = arg2;
1246  fcinfo.arg[2] = arg3;
1247  fcinfo.arg[3] = arg4;
1248  fcinfo.arg[4] = arg5;
1249  fcinfo.arg[5] = arg6;
1250  fcinfo.argnull[0] = false;
1251  fcinfo.argnull[1] = false;
1252  fcinfo.argnull[2] = false;
1253  fcinfo.argnull[3] = false;
1254  fcinfo.argnull[4] = false;
1255  fcinfo.argnull[5] = false;
1256 
1257  result = FunctionCallInvoke(&fcinfo);
1258 
1259  /* Check for null result, since caller is clearly not expecting one */
1260  if (fcinfo.isnull)
1261  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1262 
1263  return result;
1264 }
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:142
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ FunctionCall7Coll()

Datum FunctionCall7Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7 
)

Definition at line 1267 of file fmgr.c.

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

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

1270 {
1271  FunctionCallInfoData fcinfo;
1272  Datum result;
1273 
1274  InitFunctionCallInfoData(fcinfo, flinfo, 7, collation, NULL, NULL);
1275 
1276  fcinfo.arg[0] = arg1;
1277  fcinfo.arg[1] = arg2;
1278  fcinfo.arg[2] = arg3;
1279  fcinfo.arg[3] = arg4;
1280  fcinfo.arg[4] = arg5;
1281  fcinfo.arg[5] = arg6;
1282  fcinfo.arg[6] = arg7;
1283  fcinfo.argnull[0] = false;
1284  fcinfo.argnull[1] = false;
1285  fcinfo.argnull[2] = false;
1286  fcinfo.argnull[3] = false;
1287  fcinfo.argnull[4] = false;
1288  fcinfo.argnull[5] = false;
1289  fcinfo.argnull[6] = false;
1290 
1291  result = FunctionCallInvoke(&fcinfo);
1292 
1293  /* Check for null result, since caller is clearly not expecting one */
1294  if (fcinfo.isnull)
1295  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1296 
1297  return result;
1298 }
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:142
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ FunctionCall8Coll()

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 1301 of file fmgr.c.

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

Referenced by directBoolConsistentFn().

1304 {
1305  FunctionCallInfoData fcinfo;
1306  Datum result;
1307 
1308  InitFunctionCallInfoData(fcinfo, flinfo, 8, collation, NULL, NULL);
1309 
1310  fcinfo.arg[0] = arg1;
1311  fcinfo.arg[1] = arg2;
1312  fcinfo.arg[2] = arg3;
1313  fcinfo.arg[3] = arg4;
1314  fcinfo.arg[4] = arg5;
1315  fcinfo.arg[5] = arg6;
1316  fcinfo.arg[6] = arg7;
1317  fcinfo.arg[7] = arg8;
1318  fcinfo.argnull[0] = false;
1319  fcinfo.argnull[1] = false;
1320  fcinfo.argnull[2] = false;
1321  fcinfo.argnull[3] = false;
1322  fcinfo.argnull[4] = false;
1323  fcinfo.argnull[5] = false;
1324  fcinfo.argnull[6] = false;
1325  fcinfo.argnull[7] = false;
1326 
1327  result = FunctionCallInvoke(&fcinfo);
1328 
1329  /* Check for null result, since caller is clearly not expecting one */
1330  if (fcinfo.isnull)
1331  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1332 
1333  return result;
1334 }
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:142
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ FunctionCall9Coll()

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 1337 of file fmgr.c.

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

1341 {
1342  FunctionCallInfoData fcinfo;
1343  Datum result;
1344 
1345  InitFunctionCallInfoData(fcinfo, flinfo, 9, collation, NULL, NULL);
1346 
1347  fcinfo.arg[0] = arg1;
1348  fcinfo.arg[1] = arg2;
1349  fcinfo.arg[2] = arg3;
1350  fcinfo.arg[3] = arg4;
1351  fcinfo.arg[4] = arg5;
1352  fcinfo.arg[5] = arg6;
1353  fcinfo.arg[6] = arg7;
1354  fcinfo.arg[7] = arg8;
1355  fcinfo.arg[8] = arg9;
1356  fcinfo.argnull[0] = false;
1357  fcinfo.argnull[1] = false;
1358  fcinfo.argnull[2] = false;
1359  fcinfo.argnull[3] = false;
1360  fcinfo.argnull[4] = false;
1361  fcinfo.argnull[5] = false;
1362  fcinfo.argnull[6] = false;
1363  fcinfo.argnull[7] = false;
1364  fcinfo.argnull[8] = false;
1365 
1366  result = FunctionCallInvoke(&fcinfo);
1367 
1368  /* Check for null result, since caller is clearly not expecting one */
1369  if (fcinfo.isnull)
1370  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1371 
1372  return result;
1373 }
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:142
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ get_call_expr_arg_stable()

bool get_call_expr_arg_stable ( Node expr,
int  argnum 
)

Definition at line 2078 of file fmgr.c.

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

Referenced by get_fn_expr_arg_stable().

2079 {
2080  List *args;
2081  Node *arg;
2082 
2083  if (expr == NULL)
2084  return false;
2085 
2086  if (IsA(expr, FuncExpr))
2087  args = ((FuncExpr *) expr)->args;
2088  else if (IsA(expr, OpExpr))
2089  args = ((OpExpr *) expr)->args;
2090  else if (IsA(expr, DistinctExpr))
2091  args = ((DistinctExpr *) expr)->args;
2092  else if (IsA(expr, ScalarArrayOpExpr))
2093  args = ((ScalarArrayOpExpr *) expr)->args;
2094  else if (IsA(expr, NullIfExpr))
2095  args = ((NullIfExpr *) expr)->args;
2096  else if (IsA(expr, WindowFunc))
2097  args = ((WindowFunc *) expr)->args;
2098  else
2099  return false;
2100 
2101  if (argnum < 0 || argnum >= list_length(args))
2102  return false;
2103 
2104  arg = (Node *) list_nth(args, argnum);
2105 
2106  /*
2107  * Either a true Const or an external Param will have a value that doesn't
2108  * change during the execution of the query. In future we might want to
2109  * consider other cases too, e.g. now().
2110  */
2111  if (IsA(arg, Const))
2112  return true;
2113  if (IsA(arg, Param) &&
2114  ((Param *) arg)->paramkind == PARAM_EXTERN)
2115  return true;
2116 
2117  return false;
2118 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:568
Definition: nodes.h:517
void * list_nth(const List *list, int n)
Definition: list.c:410
static int list_length(const List *l)
Definition: pg_list.h:89
void * arg
Definition: pg_list.h:45

◆ get_call_expr_argtype()

Oid get_call_expr_argtype ( Node expr,
int  argnum 
)

Definition at line 2013 of file fmgr.c.

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

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

2014 {
2015  List *args;
2016  Oid argtype;
2017 
2018  if (expr == NULL)
2019  return InvalidOid;
2020 
2021  if (IsA(expr, FuncExpr))
2022  args = ((FuncExpr *) expr)->args;
2023  else if (IsA(expr, OpExpr))
2024  args = ((OpExpr *) expr)->args;
2025  else if (IsA(expr, DistinctExpr))
2026  args = ((DistinctExpr *) expr)->args;
2027  else if (IsA(expr, ScalarArrayOpExpr))
2028  args = ((ScalarArrayOpExpr *) expr)->args;
2029  else if (IsA(expr, NullIfExpr))
2030  args = ((NullIfExpr *) expr)->args;
2031  else if (IsA(expr, WindowFunc))
2032  args = ((WindowFunc *) expr)->args;
2033  else
2034  return InvalidOid;
2035 
2036  if (argnum < 0 || argnum >= list_length(args))
2037  return InvalidOid;
2038 
2039  argtype = exprType((Node *) list_nth(args, argnum));
2040 
2041  /*
2042  * special hack for ScalarArrayOpExpr: what the underlying function will
2043  * actually get passed is the element type of the array.
2044  */
2045  if (IsA(expr, ScalarArrayOpExpr) &&
2046  argnum == 1)
2047  argtype = get_base_element_type(argtype);
2048 
2049  return argtype;
2050 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:568
Definition: nodes.h:517
unsigned int Oid
Definition: postgres_ext.h:31
void * list_nth(const List *list, int n)
Definition: list.c:410
#define InvalidOid
Definition: postgres_ext.h:36
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:2575
Definition: pg_list.h:45

◆ get_fn_expr_arg_stable()

bool get_fn_expr_arg_stable ( FmgrInfo flinfo,
int  argnum 
)

Definition at line 2059 of file fmgr.c.

References FmgrInfo::fn_expr, and get_call_expr_arg_stable().

Referenced by extract_variadic_args(), leadlag_common(), and window_nth_value().

2060 {
2061  /*
2062  * can't return anything useful if we have no FmgrInfo or if its fn_expr
2063  * node has not been initialized
2064  */
2065  if (!flinfo || !flinfo->fn_expr)
2066  return false;
2067 
2068  return get_call_expr_arg_stable(flinfo->fn_expr, argnum);
2069 }
bool get_call_expr_arg_stable(Node *expr, int argnum)
Definition: fmgr.c:2078
fmNodePtr fn_expr
Definition: fmgr.h:66

◆ get_fn_expr_argtype()

◆ get_fn_expr_rettype()

Oid get_fn_expr_rettype ( FmgrInfo flinfo)

Definition at line 1972 of file fmgr.c.

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

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

1973 {
1974  Node *expr;
1975 
1976  /*
1977  * can't return anything useful if we have no FmgrInfo or if its fn_expr
1978  * node has not been initialized
1979  */
1980  if (!flinfo || !flinfo->fn_expr)
1981  return InvalidOid;
1982 
1983  expr = flinfo->fn_expr;
1984 
1985  return exprType(expr);
1986 }
Definition: nodes.h:517
#define InvalidOid
Definition: postgres_ext.h:36
fmNodePtr fn_expr
Definition: fmgr.h:66
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42

◆ get_fn_expr_variadic()

bool get_fn_expr_variadic ( FmgrInfo flinfo)

Definition at line 2128 of file fmgr.c.

References FmgrInfo::fn_expr, and IsA.

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

2129 {
2130  Node *expr;
2131 
2132  /*
2133  * can't return anything useful if we have no FmgrInfo or if its fn_expr
2134  * node has not been initialized
2135  */
2136  if (!flinfo || !flinfo->fn_expr)
2137  return false;
2138 
2139  expr = flinfo->fn_expr;
2140 
2141  if (IsA(expr, FuncExpr))
2142  return ((FuncExpr *) expr)->funcvariadic;
2143  else
2144  return false;
2145 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:568
Definition: nodes.h:517
fmNodePtr fn_expr
Definition: fmgr.h:66

◆ InputFunctionCall()

Datum InputFunctionCall ( FmgrInfo flinfo,
char *  str,
Oid  typioparam,
int32  typmod 
)

Definition at line 1708 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, and ObjectIdGetDatum.

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(), PLyObject_ToScalar(), PLyString_ToComposite(), populate_scalar(), range_in(), ReadArrayStr(), record_in(), and XmlTableGetValue().

1709 {
1710  FunctionCallInfoData fcinfo;
1711  Datum result;
1712 
1713  if (str == NULL && flinfo->fn_strict)
1714  return (Datum) 0; /* just return null result */
1715 
1716  InitFunctionCallInfoData(fcinfo, flinfo, 3, InvalidOid, NULL, NULL);
1717 
1718  fcinfo.arg[0] = CStringGetDatum(str);
1719  fcinfo.arg[1] = ObjectIdGetDatum(typioparam);
1720  fcinfo.arg[2] = Int32GetDatum(typmod);
1721  fcinfo.argnull[0] = (str == NULL);
1722  fcinfo.argnull[1] = false;
1723  fcinfo.argnull[2] = false;
1724 
1725  result = FunctionCallInvoke(&fcinfo);
1726 
1727  /* Should get null result if and only if str is NULL */
1728  if (str == NULL)
1729  {
1730  if (!fcinfo.isnull)
1731  elog(ERROR, "input function %u returned non-NULL",
1732  fcinfo.flinfo->fn_oid);
1733  }
1734  else
1735  {
1736  if (fcinfo.isnull)
1737  elog(ERROR, "input function %u returned NULL",
1738  fcinfo.flinfo->fn_oid);
1739  }
1740 
1741  return result;
1742 }
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ObjectIdGetDatum(X)
Definition: postgres.h:490
#define ERROR
Definition: elog.h:43
bool fn_strict
Definition: fmgr.h:61
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:142
#define CStringGetDatum(X)
Definition: postgres.h:561
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
#define InvalidOid
Definition: postgres_ext.h:36
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define Int32GetDatum(X)
Definition: postgres.h:462
#define elog
Definition: elog.h:219

◆ Int64GetDatum()

◆ lookup_C_func()

static CFuncHashTabEntry * lookup_C_func ( HeapTuple  procedureTuple)
static

Definition at line 529 of file fmgr.c.

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

Referenced by fmgr_info_C_lang().

530 {
531  Oid fn_oid = HeapTupleGetOid(procedureTuple);
532  CFuncHashTabEntry *entry;
533 
534  if (CFuncHash == NULL)
535  return NULL; /* no table yet */
536  entry = (CFuncHashTabEntry *)
538  &fn_oid,
539  HASH_FIND,
540  NULL);
541  if (entry == NULL)
542  return NULL; /* no such entry */
543  if (entry->fn_xmin == HeapTupleHeaderGetRawXmin(procedureTuple->t_data) &&
544  ItemPointerEquals(&entry->fn_tid, &procedureTuple->t_self))
545  return entry; /* OK */
546  return NULL; /* entry is out of date */
547 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:906
unsigned int Oid
Definition: postgres_ext.h:31
HeapTupleHeader t_data
Definition: htup.h:68
static HTAB * CFuncHash
Definition: fmgr.c:52
ItemPointerData t_self
Definition: htup.h:65
#define HeapTupleHeaderGetRawXmin(tup)
Definition: htup_details.h:313
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
Definition: itemptr.c:29
TransactionId fn_xmin
Definition: fmgr.c:46
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:712
ItemPointerData fn_tid
Definition: fmgr.c:47

◆ OidFunctionCall0Coll()

Datum OidFunctionCall0Coll ( Oid  functionId,
Oid  collation 
)

Definition at line 1384 of file fmgr.c.

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

1385 {
1386  FmgrInfo flinfo;
1387  FunctionCallInfoData fcinfo;
1388  Datum result;
1389 
1390  fmgr_info(functionId, &flinfo);
1391 
1392  InitFunctionCallInfoData(fcinfo, &flinfo, 0, collation, NULL, NULL);
1393 
1394  result = FunctionCallInvoke(&fcinfo);
1395 
1396  /* Check for null result, since caller is clearly not expecting one */
1397  if (fcinfo.isnull)
1398  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1399 
1400  return result;
1401 }
Definition: fmgr.h:56
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:123
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:142
uintptr_t Datum
Definition: postgres.h:365
Oid fn_oid
Definition: fmgr.h:59
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ OidFunctionCall1Coll()

Datum OidFunctionCall1Coll ( Oid  functionId,
Oid  collation,
Datum  arg1 
)

Definition at line 1404 of file fmgr.c.

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

Referenced by _hash_datum2hashkey_type().

1405 {
1406  FmgrInfo flinfo;
1407  FunctionCallInfoData fcinfo;
1408  Datum result;
1409 
1410  fmgr_info(functionId, &flinfo);
1411 
1412  InitFunctionCallInfoData(fcinfo, &flinfo, 1, collation, NULL, NULL);
1413 
1414  fcinfo.arg[0] = arg1;
1415  fcinfo.argnull[0] = false;
1416 
1417  result = FunctionCallInvoke(&fcinfo);
1418 
1419  /* Check for null result, since caller is clearly not expecting one */
1420  if (fcinfo.isnull)
1421  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1422 
1423  return result;
1424 }
Definition: fmgr.h:56
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:123
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:142
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ OidFunctionCall2Coll()

Datum OidFunctionCall2Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2 
)

Definition at line 1427 of file fmgr.c.

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

Referenced by _bt_compare_scankey_args(), and index_recheck_constraint().

1428 {
1429  FmgrInfo flinfo;
1430  FunctionCallInfoData fcinfo;
1431  Datum result;
1432 
1433  fmgr_info(functionId, &flinfo);
1434 
1435  InitFunctionCallInfoData(fcinfo, &flinfo, 2, collation, NULL, NULL);
1436 
1437  fcinfo.arg[0] = arg1;
1438  fcinfo.arg[1] = arg2;
1439  fcinfo.argnull[0] = false;
1440  fcinfo.argnull[1] = false;
1441 
1442  result = FunctionCallInvoke(&fcinfo);
1443 
1444  /* Check for null result, since caller is clearly not expecting one */
1445  if (fcinfo.isnull)
1446  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1447 
1448  return result;
1449 }
Definition: fmgr.h:56
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:123
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:142
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ OidFunctionCall3Coll()

Datum OidFunctionCall3Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3 
)

Definition at line 1452 of file fmgr.c.

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

1454 {
1455  FmgrInfo flinfo;
1456  FunctionCallInfoData fcinfo;
1457  Datum result;
1458 
1459  fmgr_info(functionId, &flinfo);
1460 
1461  InitFunctionCallInfoData(fcinfo, &flinfo, 3, collation, NULL, NULL);
1462 
1463  fcinfo.arg[0] = arg1;
1464  fcinfo.arg[1] = arg2;
1465  fcinfo.arg[2] = arg3;
1466  fcinfo.argnull[0] = false;
1467  fcinfo.argnull[1] = false;
1468  fcinfo.argnull[2] = false;
1469 
1470  result = FunctionCallInvoke(&fcinfo);
1471 
1472  /* Check for null result, since caller is clearly not expecting one */
1473  if (fcinfo.isnull)
1474  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1475 
1476  return result;
1477 }
Definition: fmgr.h:56
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:123
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:142
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ OidFunctionCall4Coll()

Datum OidFunctionCall4Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4 
)

Definition at line 1480 of file fmgr.c.

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

Referenced by restriction_selectivity().

1482 {
1483  FmgrInfo flinfo;
1484  FunctionCallInfoData fcinfo;
1485  Datum result;
1486 
1487  fmgr_info(functionId, &flinfo);
1488 
1489  InitFunctionCallInfoData(fcinfo, &flinfo, 4, collation, NULL, NULL);
1490 
1491  fcinfo.arg[0] = arg1;
1492  fcinfo.arg[1] = arg2;
1493  fcinfo.arg[2] = arg3;
1494  fcinfo.arg[3] = arg4;
1495  fcinfo.argnull[0] = false;
1496  fcinfo.argnull[1] = false;
1497  fcinfo.argnull[2] = false;
1498  fcinfo.argnull[3] = false;
1499 
1500  result = FunctionCallInvoke(&fcinfo);
1501 
1502  /* Check for null result, since caller is clearly not expecting one */
1503  if (fcinfo.isnull)
1504  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1505 
1506  return result;
1507 }
Definition: fmgr.h:56
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:123
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:142
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ OidFunctionCall5Coll()

Datum OidFunctionCall5Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5 
)

Definition at line 1510 of file fmgr.c.

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

Referenced by join_selectivity().

1512 {
1513  FmgrInfo flinfo;
1514  FunctionCallInfoData fcinfo;
1515  Datum result;
1516 
1517  fmgr_info(functionId, &flinfo);
1518 
1519  InitFunctionCallInfoData(fcinfo, &flinfo, 5, collation, NULL, NULL);
1520 
1521  fcinfo.arg[0] = arg1;
1522  fcinfo.arg[1] = arg2;
1523  fcinfo.arg[2] = arg3;
1524  fcinfo.arg[3] = arg4;
1525  fcinfo.arg[4] = arg5;
1526  fcinfo.argnull[0] = false;
1527  fcinfo.argnull[1] = false;
1528  fcinfo.argnull[2] = false;
1529  fcinfo.argnull[3] = false;
1530  fcinfo.argnull[4] = false;
1531 
1532  result = FunctionCallInvoke(&fcinfo);
1533 
1534  /* Check for null result, since caller is clearly not expecting one */
1535  if (fcinfo.isnull)
1536  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1537 
1538  return result;
1539 }
Definition: fmgr.h:56
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:123
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:142
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ OidFunctionCall6Coll()

Datum OidFunctionCall6Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6 
)

Definition at line 1542 of file fmgr.c.

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

1545 {
1546  FmgrInfo flinfo;
1547  FunctionCallInfoData fcinfo;
1548  Datum result;
1549 
1550  fmgr_info(functionId, &flinfo);
1551 
1552  InitFunctionCallInfoData(fcinfo, &flinfo, 6, collation, NULL, NULL);
1553 
1554  fcinfo.arg[0] = arg1;
1555  fcinfo.arg[1] = arg2;
1556  fcinfo.arg[2] = arg3;
1557  fcinfo.arg[3] = arg4;
1558  fcinfo.arg[4] = arg5;
1559  fcinfo.arg[5] = arg6;
1560  fcinfo.argnull[0] = false;
1561  fcinfo.argnull[1] = false;
1562  fcinfo.argnull[2] = false;
1563  fcinfo.argnull[3] = false;
1564  fcinfo.argnull[4] = false;
1565  fcinfo.argnull[5] = false;
1566 
1567  result = FunctionCallInvoke(&fcinfo);
1568 
1569  /* Check for null result, since caller is clearly not expecting one */
1570  if (fcinfo.isnull)
1571  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1572 
1573  return result;
1574 }
Definition: fmgr.h:56
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:123
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:142
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ OidFunctionCall7Coll()

Datum OidFunctionCall7Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7 
)

Definition at line 1577 of file fmgr.c.

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

Referenced by gincost_pattern().

1580 {
1581  FmgrInfo flinfo;
1582  FunctionCallInfoData fcinfo;
1583  Datum result;
1584 
1585  fmgr_info(functionId, &flinfo);
1586 
1587  InitFunctionCallInfoData(fcinfo, &flinfo, 7, collation, NULL, NULL);
1588 
1589  fcinfo.arg[0] = arg1;
1590  fcinfo.arg[1] = arg2;
1591  fcinfo.arg[2] = arg3;
1592  fcinfo.arg[3] = arg4;
1593  fcinfo.arg[4] = arg5;
1594  fcinfo.arg[5] = arg6;
1595  fcinfo.arg[6] = arg7;
1596  fcinfo.argnull[0] = false;
1597  fcinfo.argnull[1] = false;
1598  fcinfo.argnull[2] = false;
1599  fcinfo.argnull[3] = false;
1600  fcinfo.argnull[4] = false;
1601  fcinfo.argnull[5] = false;
1602  fcinfo.argnull[6] = false;
1603 
1604  result = FunctionCallInvoke(&fcinfo);
1605 
1606  /* Check for null result, since caller is clearly not expecting one */
1607  if (fcinfo.isnull)
1608  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1609 
1610  return result;
1611 }
Definition: fmgr.h:56
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:123
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:142
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ OidFunctionCall8Coll()

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 1614 of file fmgr.c.

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

1617 {
1618  FmgrInfo flinfo;
1619  FunctionCallInfoData fcinfo;
1620  Datum result;
1621 
1622  fmgr_info(functionId, &flinfo);
1623 
1624  InitFunctionCallInfoData(fcinfo, &flinfo, 8, collation, NULL, NULL);
1625 
1626  fcinfo.arg[0] = arg1;
1627  fcinfo.arg[1] = arg2;
1628  fcinfo.arg[2] = arg3;
1629  fcinfo.arg[3] = arg4;
1630  fcinfo.arg[4] = arg5;
1631  fcinfo.arg[5] = arg6;
1632  fcinfo.arg[6] = arg7;
1633  fcinfo.arg[7] = arg8;
1634  fcinfo.argnull[0] = false;
1635  fcinfo.argnull[1] = false;
1636  fcinfo.argnull[2] = false;
1637  fcinfo.argnull[3] = false;
1638  fcinfo.argnull[4] = false;
1639  fcinfo.argnull[5] = false;
1640  fcinfo.argnull[6] = false;
1641  fcinfo.argnull[7] = false;
1642 
1643  result = FunctionCallInvoke(&fcinfo);
1644 
1645  /* Check for null result, since caller is clearly not expecting one */
1646  if (fcinfo.isnull)
1647  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1648 
1649  return result;
1650 }
Definition: fmgr.h:56
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:123
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:142
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ OidFunctionCall9Coll()

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 1653 of file fmgr.c.

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

1657 {
1658  FmgrInfo flinfo;
1659  FunctionCallInfoData fcinfo;
1660  Datum result;
1661 
1662  fmgr_info(functionId, &flinfo);
1663 
1664  InitFunctionCallInfoData(fcinfo, &flinfo, 9, collation, NULL, NULL);
1665 
1666  fcinfo.arg[0] = arg1;
1667  fcinfo.arg[1] = arg2;
1668  fcinfo.arg[2] = arg3;
1669  fcinfo.arg[3] = arg4;
1670  fcinfo.arg[4] = arg5;
1671  fcinfo.arg[5] = arg6;
1672  fcinfo.arg[6] = arg7;
1673  fcinfo.arg[7] = arg8;
1674  fcinfo.arg[8] = arg9;
1675  fcinfo.argnull[0] = false;
1676  fcinfo.argnull[1] = false;
1677  fcinfo.argnull[2] = false;
1678  fcinfo.argnull[3] = false;
1679  fcinfo.argnull[4] = false;
1680  fcinfo.argnull[5] = false;
1681  fcinfo.argnull[6] = false;
1682  fcinfo.argnull[7] = false;
1683  fcinfo.argnull[8] = false;
1684 
1685  result = FunctionCallInvoke(&fcinfo);
1686 
1687  /* Check for null result, since caller is clearly not expecting one */
1688  if (fcinfo.isnull)
1689  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1690 
1691  return result;
1692 }
Definition: fmgr.h:56
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:123
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:142
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define elog
Definition: elog.h:219

◆ OidInputFunctionCall()

Datum OidInputFunctionCall ( Oid  functionId,
char *  str,
Oid  typioparam,
int32  typmod 
)

Definition at line 1823 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().

1824 {
1825  FmgrInfo flinfo;
1826 
1827  fmgr_info(functionId, &flinfo);
1828  return InputFunctionCall(&flinfo, str, typioparam, typmod);
1829 }
Definition: fmgr.h:56
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:123
Datum InputFunctionCall(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
Definition: fmgr.c:1708

◆ OidOutputFunctionCall()

◆ OidReceiveFunctionCall()

Datum OidReceiveFunctionCall ( Oid  functionId,
StringInfo  buf,
Oid  typioparam,
int32  typmod 
)

Definition at line 1841 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().

1843 {
1844  FmgrInfo flinfo;
1845 
1846  fmgr_info(functionId, &flinfo);
1847  return ReceiveFunctionCall(&flinfo, buf, typioparam, typmod);
1848 }
Definition: fmgr.h:56
Datum ReceiveFunctionCall(FmgrInfo *flinfo, StringInfo buf, Oid typioparam, int32 typmod)
Definition: fmgr.c:1766
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:123

◆ OidSendFunctionCall()

bytea* OidSendFunctionCall ( Oid  functionId,
Datum  val 
)

Definition at line 1851 of file fmgr.c.

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

Referenced by SendFunctionResult().

1852 {
1853  FmgrInfo flinfo;
1854 
1855  fmgr_info(functionId, &flinfo);
1856  return SendFunctionCall(&flinfo, val);
1857 }
Definition: fmgr.h:56
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:123
bytea * SendFunctionCall(FmgrInfo *flinfo, Datum val)
Definition: fmgr.c:1813
long val
Definition: informix.c:689

◆ OutputFunctionCall()

◆ pg_detoast_datum()

struct varlena* pg_detoast_datum ( struct varlena datum)

Definition at line 1916 of file fmgr.c.

References heap_tuple_untoast_attr(), and VARATT_IS_EXTENDED.

1917 {
1918  if (VARATT_IS_EXTENDED(datum))
1919  return heap_tuple_untoast_attr(datum);
1920  else
1921  return datum;
1922 }
struct varlena * heap_tuple_untoast_attr(struct varlena *attr)
Definition: tuptoaster.c:172
#define VARATT_IS_EXTENDED(PTR)
Definition: postgres.h:325

◆ pg_detoast_datum_copy()

struct varlena* pg_detoast_datum_copy ( struct varlena datum)

Definition at line 1925 of file fmgr.c.

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

1926 {
1927  if (VARATT_IS_EXTENDED(datum))
1928  return heap_tuple_untoast_attr(datum);
1929  else
1930  {
1931  /* Make a modifiable copy of the varlena object */
1932  Size len = VARSIZE(datum);
1933  struct varlena *result = (struct varlena *) palloc(len);
1934 
1935  memcpy(result, datum, len);
1936  return result;
1937  }
1938 }
#define VARSIZE(PTR)
Definition: postgres.h:303
struct varlena * heap_tuple_untoast_attr(struct varlena *attr)
Definition: tuptoaster.c:172
size_t Size
Definition: c.h:433
#define VARATT_IS_EXTENDED(PTR)
Definition: postgres.h:325
void * palloc(Size size)
Definition: mcxt.c:924
Definition: c.h:516

◆ pg_detoast_datum_packed()

struct varlena* pg_detoast_datum_packed ( struct varlena datum)

Definition at line 1948 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().

1949 {
1950  if (VARATT_IS_COMPRESSED(datum) || VARATT_IS_EXTERNAL(datum))
1951  return heap_tuple_untoast_attr(datum);
1952  else
1953  return datum;
1954 }
#define VARATT_IS_COMPRESSED(PTR)
Definition: postgres.h:312
struct varlena * heap_tuple_untoast_attr(struct varlena *attr)
Definition: tuptoaster.c:172
#define VARATT_IS_EXTERNAL(PTR)
Definition: postgres.h:313

◆ pg_detoast_datum_slice()

struct varlena* pg_detoast_datum_slice ( struct varlena datum,
int32  first,
int32  count 
)

Definition at line 1941 of file fmgr.c.

References heap_tuple_untoast_attr_slice().

1942 {
1943  /* Only get the specified portion from the toast rel */
1944  return heap_tuple_untoast_attr_slice(datum, first, count);
1945 }
struct varlena * heap_tuple_untoast_attr_slice(struct varlena *attr, int32 sliceoffset, int32 slicelength)
Definition: tuptoaster.c:258

◆ ReceiveFunctionCall()

Datum ReceiveFunctionCall ( FmgrInfo flinfo,
StringInfo  buf,
Oid  typioparam,
int32  typmod 
)

Definition at line 1766 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, ObjectIdGetDatum, and PointerGetDatum.

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

1768 {
1769  FunctionCallInfoData fcinfo;
1770  Datum result;
1771 
1772  if (buf == NULL && flinfo->fn_strict)
1773  return (Datum) 0; /* just return null result */
1774 
1775  InitFunctionCallInfoData(fcinfo, flinfo, 3, InvalidOid, NULL, NULL);
1776 
1777  fcinfo.arg[0] = PointerGetDatum(buf);
1778  fcinfo.arg[1] = ObjectIdGetDatum(typioparam);
1779  fcinfo.arg[2] = Int32GetDatum(typmod);
1780  fcinfo.argnull[0] = (buf == NULL);
1781  fcinfo.argnull[1] = false;
1782  fcinfo.argnull[2] = false;
1783 
1784  result = FunctionCallInvoke(&fcinfo);
1785 
1786  /* Should get null result if and only if buf is NULL */
1787  if (buf == NULL)
1788  {
1789  if (!fcinfo.isnull)
1790  elog(ERROR, "receive function %u returned non-NULL",
1791  fcinfo.flinfo->fn_oid);
1792  }
1793  else
1794  {
1795  if (fcinfo.isnull)
1796  elog(ERROR, "receive function %u returned NULL",
1797  fcinfo.flinfo->fn_oid);
1798  }
1799 
1800  return result;
1801 }
#define PointerGetDatum(X)
Definition: postgres.h:539
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ObjectIdGetDatum(X)
Definition: postgres.h:490
#define ERROR
Definition: elog.h:43
bool fn_strict
Definition: fmgr.h:61
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:142
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:89
uintptr_t Datum
Definition: postgres.h:365
#define InvalidOid
Definition: postgres_ext.h:36
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:87
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:125
#define Int32GetDatum(X)
Definition: postgres.h:462
#define elog
Definition: elog.h:219

◆ record_C_func()

static void record_C_func ( HeapTuple  procedureTuple,
PGFunction  user_fn,
const Pg_finfo_record inforec 
)
static

Definition at line 553 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, HeapTupleData::t_data, HeapTupleData::t_self, and CFuncHashTabEntry::user_fn.

Referenced by fmgr_info_C_lang().

555 {
556  Oid fn_oid = HeapTupleGetOid(procedureTuple);
557  CFuncHashTabEntry *entry;
558  bool found;
559 
560  /* Create the hash table if it doesn't exist yet */
561  if (CFuncHash == NULL)
562  {
563  HASHCTL hash_ctl;
564 
565  MemSet(&hash_ctl, 0, sizeof(hash_ctl));
566  hash_ctl.keysize = sizeof(Oid);
567  hash_ctl.entrysize = sizeof(CFuncHashTabEntry);
568  CFuncHash = hash_create("CFuncHash",
569  100,
570  &hash_ctl,
572  }
573 
574  entry = (CFuncHashTabEntry *)
576  &fn_oid,
577  HASH_ENTER,
578  &found);
579  /* OID is already filled in */
580  entry->fn_xmin = HeapTupleHeaderGetRawXmin(procedureTuple->t_data);
581  entry->fn_tid = procedureTuple->t_self;
582  entry->user_fn = user_fn;
583  entry->inforec = inforec;
584 }
#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:908
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:906
unsigned int Oid
Definition: postgres_ext.h:31
HeapTupleHeader t_data
Definition: htup.h:68
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:316
Size keysize
Definition: hsearch.h:72
#define HeapTupleHeaderGetRawXmin(tup)
Definition: htup_details.h:313
TransactionId fn_xmin
Definition: fmgr.c:46
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:712
ItemPointerData fn_tid
Definition: fmgr.c:47

◆ SendFunctionCall()

bytea* SendFunctionCall ( FmgrInfo flinfo,
Datum  val 
)

Definition at line 1813 of file fmgr.c.

References DatumGetByteaP, and FunctionCall1.

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

1814 {
1815  return DatumGetByteaP(FunctionCall1(flinfo, val));
1816 }
#define DatumGetByteaP(X)
Definition: fmgr.h:300
#define FunctionCall1(flinfo, arg1)
Definition: fmgr.h:608
long val
Definition: informix.c:689

Variable Documentation

◆ CFuncHash

HTAB* CFuncHash = NULL
static

Definition at line 52 of file fmgr.c.

◆ fmgr_hook

PGDLLIMPORT fmgr_hook_type fmgr_hook = NULL

Definition at line 37 of file fmgr.c.

Referenced by fmgr_security_definer(), and sepgsql_init_client_label().

◆ needs_fmgr_hook

PGDLLIMPORT needs_fmgr_hook_type needs_fmgr_hook = NULL

Definition at line 36 of file fmgr.c.

Referenced by sepgsql_init_client_label().