PostgreSQL Source Code  git master
fmgr.c File Reference
#include "postgres.h"
#include "access/detoast.h"
#include "catalog/pg_language.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_type.h"
#include "executor/functions.h"
#include "lib/stringinfo.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "nodes/miscnodes.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 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 FunctionCall0Coll (FmgrInfo *flinfo, Oid collation)
 
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)
 
bool InputFunctionCallSafe (FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod, fmNodePtr escontext, Datum *result)
 
bool DirectInputFunctionCallSafe (PGFunction func, char *str, Oid typioparam, int32 typmod, fmNodePtr escontext, Datum *result)
 
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 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)
 
void set_fn_opclass_options (FmgrInfo *flinfo, bytea *options)
 
bool has_fn_opclass_options (FmgrInfo *flinfo)
 
byteaget_fn_opclass_options (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.

1066 {
1067  LOCAL_FCINFO(fcinfo, 1);
1068  Datum result;
1069 
1070  InitFunctionCallInfoData(*fcinfo, flinfo, 1, collation, NULL, NULL);
1071 
1072  fcinfo->args[0].value = arg1;
1073  fcinfo->args[0].isnull = 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:39
#define elog(elevel,...)
Definition: elog.h:224
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
uintptr_t Datum
Definition: postgres.h:64

References elog, ERROR, fmgr_security_definer_cache::flinfo, InitFunctionCallInfoData, and LOCAL_FCINFO.

◆ CallerFInfoFunctionCall2()

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

Definition at line 1085 of file fmgr.c.

1086 {
1087  LOCAL_FCINFO(fcinfo, 2);
1088  Datum result;
1089 
1090  InitFunctionCallInfoData(*fcinfo, flinfo, 2, collation, NULL, NULL);
1091 
1092  fcinfo->args[0].value = arg1;
1093  fcinfo->args[0].isnull = false;
1094  fcinfo->args[1].value = arg2;
1095  fcinfo->args[1].isnull = 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 }

References elog, ERROR, fmgr_security_definer_cache::flinfo, InitFunctionCallInfoData, and LOCAL_FCINFO.

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

◆ CheckFunctionValidatorAccess()

bool CheckFunctionValidatorAccess ( Oid  validatorOid,
Oid  functionOid 
)

Definition at line 2145 of file fmgr.c.

2146 {
2147  HeapTuple procTup;
2148  HeapTuple langTup;
2149  Form_pg_proc procStruct;
2150  Form_pg_language langStruct;
2151  AclResult aclresult;
2152 
2153  /*
2154  * Get the function's pg_proc entry. Throw a user-facing error for bad
2155  * OID, because validators can be called with user-specified OIDs.
2156  */
2157  procTup = SearchSysCache1(PROCOID, ObjectIdGetDatum(functionOid));
2158  if (!HeapTupleIsValid(procTup))
2159  ereport(ERROR,
2160  (errcode(ERRCODE_UNDEFINED_FUNCTION),
2161  errmsg("function with OID %u does not exist", functionOid)));
2162  procStruct = (Form_pg_proc) GETSTRUCT(procTup);
2163 
2164  /*
2165  * Fetch pg_language entry to know if this is the correct validation
2166  * function for that pg_proc entry.
2167  */
2168  langTup = SearchSysCache1(LANGOID, ObjectIdGetDatum(procStruct->prolang));
2169  if (!HeapTupleIsValid(langTup))
2170  elog(ERROR, "cache lookup failed for language %u", procStruct->prolang);
2171  langStruct = (Form_pg_language) GETSTRUCT(langTup);
2172 
2173  if (langStruct->lanvalidator != validatorOid)
2174  ereport(ERROR,
2175  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2176  errmsg("language validation function %u called for language %u instead of %u",
2177  validatorOid, procStruct->prolang,
2178  langStruct->lanvalidator)));
2179 
2180  /* first validate that we have permissions to use the language */
2181  aclresult = object_aclcheck(LanguageRelationId, procStruct->prolang, GetUserId(),
2182  ACL_USAGE);
2183  if (aclresult != ACLCHECK_OK)
2184  aclcheck_error(aclresult, OBJECT_LANGUAGE,
2185  NameStr(langStruct->lanname));
2186 
2187  /*
2188  * Check whether we are allowed to execute the function itself. If we can
2189  * execute it, there should be no possible side-effect of
2190  * compiling/validation that execution can't have.
2191  */
2192  aclresult = object_aclcheck(ProcedureRelationId, functionOid, GetUserId(), ACL_EXECUTE);
2193  if (aclresult != ACLCHECK_OK)
2194  aclcheck_error(aclresult, OBJECT_FUNCTION, NameStr(procStruct->proname));
2195 
2196  ReleaseSysCache(procTup);
2197  ReleaseSysCache(langTup);
2198 
2199  return true;
2200 }
AclResult
Definition: acl.h:182
@ ACLCHECK_OK
Definition: acl.h:183
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:2688
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
Definition: aclchk.c:3876
#define NameStr(name)
Definition: c.h:733
int errcode(int sqlerrcode)
Definition: elog.c:859
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#define ereport(elevel,...)
Definition: elog.h:149
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
Oid GetUserId(void)
Definition: miscinit.c:514
#define ACL_USAGE
Definition: parsenodes.h:84
@ OBJECT_LANGUAGE
Definition: parsenodes.h:2130
@ OBJECT_FUNCTION
Definition: parsenodes.h:2128
#define ACL_EXECUTE
Definition: parsenodes.h:83
FormData_pg_language * Form_pg_language
Definition: pg_language.h:65
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:136
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:266
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:218

References ACL_EXECUTE, ACL_USAGE, aclcheck_error(), ACLCHECK_OK, elog, ereport, errcode(), errmsg(), ERROR, GETSTRUCT, GetUserId(), HeapTupleIsValid, NameStr, object_aclcheck(), OBJECT_FUNCTION, OBJECT_LANGUAGE, ObjectIdGetDatum(), ReleaseSysCache(), and SearchSysCache1().

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

◆ DirectFunctionCall1Coll()

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

Definition at line 792 of file fmgr.c.

793 {
794  LOCAL_FCINFO(fcinfo, 1);
795  Datum result;
796 
797  InitFunctionCallInfoData(*fcinfo, NULL, 1, collation, NULL, NULL);
798 
799  fcinfo->args[0].value = arg1;
800  fcinfo->args[0].isnull = 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 }

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by Generic_Text_IC_like(), libpqrcv_create_slot(), and texthashfast().

◆ DirectFunctionCall2Coll()

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

Definition at line 812 of file fmgr.c.

813 {
814  LOCAL_FCINFO(fcinfo, 2);
815  Datum result;
816 
817  InitFunctionCallInfoData(*fcinfo, NULL, 2, collation, NULL, NULL);
818 
819  fcinfo->args[0].value = arg1;
820  fcinfo->args[0].isnull = false;
821  fcinfo->args[1].value = arg2;
822  fcinfo->args[1].isnull = 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 }

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by gbt_bpcharcmp(), gbt_bpchareq(), gbt_bpcharge(), gbt_bpchargt(), gbt_bpcharle(), gbt_bpcharlt(), gbt_textcmp(), gbt_texteq(), gbt_textge(), gbt_textgt(), gbt_textle(), gbt_textlt(), spg_text_leaf_consistent(), text_isequal(), and texteqfast().

◆ DirectFunctionCall3Coll()

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

Definition at line 834 of file fmgr.c.

836 {
837  LOCAL_FCINFO(fcinfo, 3);
838  Datum result;
839 
840  InitFunctionCallInfoData(*fcinfo, NULL, 3, collation, NULL, NULL);
841 
842  fcinfo->args[0].value = arg1;
843  fcinfo->args[0].isnull = false;
844  fcinfo->args[1].value = arg2;
845  fcinfo->args[1].isnull = false;
846  fcinfo->args[2].value = arg3;
847  fcinfo->args[2].isnull = 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 }

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by execute_extension_script().

◆ DirectFunctionCall4Coll()

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

Definition at line 859 of file fmgr.c.

861 {
862  LOCAL_FCINFO(fcinfo, 4);
863  Datum result;
864 
865  InitFunctionCallInfoData(*fcinfo, NULL, 4, collation, NULL, NULL);
866 
867  fcinfo->args[0].value = arg1;
868  fcinfo->args[0].isnull = false;
869  fcinfo->args[1].value = arg2;
870  fcinfo->args[1].isnull = false;
871  fcinfo->args[2].value = arg3;
872  fcinfo->args[2].isnull = false;
873  fcinfo->args[3].value = arg4;
874  fcinfo->args[3].isnull = 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 }

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by execute_extension_script().

◆ 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.

888 {
889  LOCAL_FCINFO(fcinfo, 5);
890  Datum result;
891 
892  InitFunctionCallInfoData(*fcinfo, NULL, 5, collation, NULL, NULL);
893 
894  fcinfo->args[0].value = arg1;
895  fcinfo->args[0].isnull = false;
896  fcinfo->args[1].value = arg2;
897  fcinfo->args[1].isnull = false;
898  fcinfo->args[2].value = arg3;
899  fcinfo->args[2].isnull = false;
900  fcinfo->args[3].value = arg4;
901  fcinfo->args[3].isnull = false;
902  fcinfo->args[4].value = arg5;
903  fcinfo->args[4].isnull = 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 }

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by neqjoinsel().

◆ 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.

918 {
919  LOCAL_FCINFO(fcinfo, 6);
920  Datum result;
921 
922  InitFunctionCallInfoData(*fcinfo, NULL, 6, collation, NULL, NULL);
923 
924  fcinfo->args[0].value = arg1;
925  fcinfo->args[0].isnull = false;
926  fcinfo->args[1].value = arg2;
927  fcinfo->args[1].isnull = false;
928  fcinfo->args[2].value = arg3;
929  fcinfo->args[2].isnull = false;
930  fcinfo->args[3].value = arg4;
931  fcinfo->args[3].isnull = false;
932  fcinfo->args[4].value = arg5;
933  fcinfo->args[4].isnull = false;
934  fcinfo->args[5].value = arg6;
935  fcinfo->args[5].isnull = 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 }

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

◆ 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.

950 {
951  LOCAL_FCINFO(fcinfo, 7);
952  Datum result;
953 
954  InitFunctionCallInfoData(*fcinfo, NULL, 7, collation, NULL, NULL);
955 
956  fcinfo->args[0].value = arg1;
957  fcinfo->args[0].isnull = false;
958  fcinfo->args[1].value = arg2;
959  fcinfo->args[1].isnull = false;
960  fcinfo->args[2].value = arg3;
961  fcinfo->args[2].isnull = false;
962  fcinfo->args[3].value = arg4;
963  fcinfo->args[3].isnull = false;
964  fcinfo->args[4].value = arg5;
965  fcinfo->args[4].isnull = false;
966  fcinfo->args[5].value = arg6;
967  fcinfo->args[5].isnull = false;
968  fcinfo->args[6].value = arg7;
969  fcinfo->args[6].isnull = 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 }

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

◆ 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.

984 {
985  LOCAL_FCINFO(fcinfo, 8);
986  Datum result;
987 
988  InitFunctionCallInfoData(*fcinfo, NULL, 8, collation, NULL, NULL);
989 
990  fcinfo->args[0].value = arg1;
991  fcinfo->args[0].isnull = false;
992  fcinfo->args[1].value = arg2;
993  fcinfo->args[1].isnull = false;
994  fcinfo->args[2].value = arg3;
995  fcinfo->args[2].isnull = false;
996  fcinfo->args[3].value = arg4;
997  fcinfo->args[3].isnull = false;
998  fcinfo->args[4].value = arg5;
999  fcinfo->args[4].isnull = false;
1000  fcinfo->args[5].value = arg6;
1001  fcinfo->args[5].isnull = false;
1002  fcinfo->args[6].value = arg7;
1003  fcinfo->args[6].isnull = false;
1004  fcinfo->args[7].value = arg8;
1005  fcinfo->args[7].isnull = 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 }

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

◆ 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.

1021 {
1022  LOCAL_FCINFO(fcinfo, 9);
1023  Datum result;
1024 
1025  InitFunctionCallInfoData(*fcinfo, NULL, 9, collation, NULL, NULL);
1026 
1027  fcinfo->args[0].value = arg1;
1028  fcinfo->args[0].isnull = false;
1029  fcinfo->args[1].value = arg2;
1030  fcinfo->args[1].isnull = false;
1031  fcinfo->args[2].value = arg3;
1032  fcinfo->args[2].isnull = false;
1033  fcinfo->args[3].value = arg4;
1034  fcinfo->args[3].isnull = false;
1035  fcinfo->args[4].value = arg5;
1036  fcinfo->args[4].isnull = false;
1037  fcinfo->args[5].value = arg6;
1038  fcinfo->args[5].isnull = false;
1039  fcinfo->args[6].value = arg7;
1040  fcinfo->args[6].isnull = false;
1041  fcinfo->args[7].value = arg8;
1042  fcinfo->args[7].isnull = false;
1043  fcinfo->args[8].value = arg9;
1044  fcinfo->args[8].isnull = 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 }

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

◆ DirectInputFunctionCallSafe()

bool DirectInputFunctionCallSafe ( PGFunction  func,
char *  str,
Oid  typioparam,
int32  typmod,
fmNodePtr  escontext,
Datum result 
)

Definition at line 1640 of file fmgr.c.

1644 {
1645  LOCAL_FCINFO(fcinfo, 3);
1646 
1647  if (str == NULL)
1648  {
1649  *result = (Datum) 0; /* just return null result */
1650  return true;
1651  }
1652 
1653  InitFunctionCallInfoData(*fcinfo, NULL, 3, InvalidOid, escontext, NULL);
1654 
1655  fcinfo->args[0].value = CStringGetDatum(str);
1656  fcinfo->args[0].isnull = false;
1657  fcinfo->args[1].value = ObjectIdGetDatum(typioparam);
1658  fcinfo->args[1].isnull = false;
1659  fcinfo->args[2].value = Int32GetDatum(typmod);
1660  fcinfo->args[2].isnull = false;
1661 
1662  *result = (*func) (fcinfo);
1663 
1664  /* Result value is garbage, and could be null, if an error was reported */
1665  if (SOFT_ERROR_OCCURRED(escontext))
1666  return false;
1667 
1668  /* Otherwise, shouldn't get null result */
1669  if (fcinfo->isnull)
1670  elog(ERROR, "input function %p returned NULL", (void *) func);
1671 
1672  return true;
1673 }
#define SOFT_ERROR_OCCURRED(escontext)
Definition: miscnodes.h:52
static Datum CStringGetDatum(const char *X)
Definition: postgres.h:350
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:212
#define InvalidOid
Definition: postgres_ext.h:36

References CStringGetDatum(), elog, ERROR, InitFunctionCallInfoData, Int32GetDatum(), InvalidOid, LOCAL_FCINFO, ObjectIdGetDatum(), SOFT_ERROR_OCCURRED, and generate_unaccent_rules::str.

Referenced by executeItemOptUnwrapTarget(), jsonb_in_scalar(), parseNumericOid(), to_regclass(), to_regcollation(), to_regnamespace(), to_regoper(), to_regoperator(), to_regproc(), to_regprocedure(), to_regrole(), and to_regtype().

◆ fetch_finfo_record()

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

Definition at line 455 of file fmgr.c.

456 {
457  char *infofuncname;
458  PGFInfoFunction infofunc;
459  const Pg_finfo_record *inforec;
460 
461  infofuncname = psprintf("pg_finfo_%s", funcname);
462 
463  /* Try to look up the info function */
464  infofunc = (PGFInfoFunction) lookup_external_function(filehandle,
465  infofuncname);
466  if (infofunc == NULL)
467  {
468  ereport(ERROR,
469  (errcode(ERRCODE_UNDEFINED_FUNCTION),
470  errmsg("could not find function information for function \"%s\"",
471  funcname),
472  errhint("SQL-callable functions need an accompanying PG_FUNCTION_INFO_V1(funcname).")));
473  return NULL; /* silence compiler */
474  }
475 
476  /* Found, so call it */
477  inforec = (*infofunc) ();
478 
479  /* Validate result as best we can */
480  if (inforec == NULL)
481  elog(ERROR, "null result from info function \"%s\"", infofuncname);
482  switch (inforec->api_version)
483  {
484  case 1:
485  /* OK, no additional fields to validate */
486  break;
487  default:
488  ereport(ERROR,
489  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
490  errmsg("unrecognized API version %d reported by info function \"%s\"",
491  inforec->api_version, infofuncname)));
492  break;
493  }
494 
495  pfree(infofuncname);
496  return inforec;
497 }
void * lookup_external_function(void *filehandle, const char *funcname)
Definition: dfmgr.c:166
int errhint(const char *fmt,...)
Definition: elog.c:1319
const Pg_finfo_record *(* PGFInfoFunction)(void)
Definition: fmgr.h:401
#define funcname
Definition: indent_codes.h:69
void pfree(void *pointer)
Definition: mcxt.c:1508
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
int api_version
Definition: fmgr.h:396

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

Referenced by fmgr_c_validator(), and fmgr_info_C_lang().

◆ Float8GetDatum()

◆ fmgr_info()

void fmgr_info ( Oid  functionId,
FmgrInfo finfo 
)

Definition at line 127 of file fmgr.c.

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

References CurrentMemoryContext, and fmgr_info_cxt_security().

Referenced by _bt_find_extreme_element(), _bt_sort_array_elements(), _sv_to_datum_finfo(), BeginCopyFrom(), brin_minmax_multi_summary_out(), brin_page_items(), build_pertrans_for_aggref(), call_pltcl_start_proc(), compute_distinct_stats(), create_foreign_modify(), DoCopyTo(), eqjoinsel_inner(), eqjoinsel_semi(), EventTriggerInvoke(), ExecBuildGroupingEqual(), ExecBuildParamSetEqual(), ExecCallTriggerFunc(), ExecEvalHashedScalarArrayOp(), ExecHashTableCreate(), ExecInitAgg(), ExecInitExprRec(), ExecInitFunc(), ExecInitMemoize(), ExecInitSubPlan(), ExecInitTableFuncScan(), ExecInitWindowAgg(), execTuplesHashPrepare(), ExecuteCallStmt(), fetch_fp_info(), generic_restriction_selectivity(), get_stats_slot_range(), gincost_pattern(), hash_array(), inet_mcv_join_sel(), initialize_peragg(), match_pattern_prefix(), mcv_get_match_bitmap(), networkjoinsel_semi(), networksel(), OidFunctionCall0Coll(), OidFunctionCall1Coll(), OidFunctionCall2Coll(), OidFunctionCall3Coll(), OidFunctionCall4Coll(), OidFunctionCall5Coll(), OidFunctionCall6Coll(), OidFunctionCall7Coll(), OidFunctionCall8Coll(), OidFunctionCall9Coll(), OidInputFunctionCall(), OidOutputFunctionCall(), OidReceiveFunctionCall(), OidSendFunctionCall(), patternsel_common(), pg_get_catalog_foreign_keys(), pg_stats_ext_mcvlist_items(), plperl_ref_from_pg_array(), prefix_selectivity(), prepare_query_params(), printtup_prepare_info(), scalararraysel(), scalarineqsel(), ScanKeyEntryInitialize(), ScanKeyInit(), text_format(), TupleDescGetAttInMetadata(), and var_eq_const().

◆ fmgr_info_C_lang()

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

Definition at line 349 of file fmgr.c.

350 {
351  CFuncHashTabEntry *hashentry;
352  PGFunction user_fn;
353  const Pg_finfo_record *inforec;
354 
355  /*
356  * See if we have the function address cached already
357  */
358  hashentry = lookup_C_func(procedureTuple);
359  if (hashentry)
360  {
361  user_fn = hashentry->user_fn;
362  inforec = hashentry->inforec;
363  }
364  else
365  {
366  Datum prosrcattr,
367  probinattr;
368  char *prosrcstring,
369  *probinstring;
370  void *libraryhandle;
371 
372  /*
373  * Get prosrc and probin strings (link symbol and library filename).
374  * While in general these columns might be null, that's not allowed
375  * for C-language functions.
376  */
377  prosrcattr = SysCacheGetAttrNotNull(PROCOID, procedureTuple,
378  Anum_pg_proc_prosrc);
379  prosrcstring = TextDatumGetCString(prosrcattr);
380 
381  probinattr = SysCacheGetAttrNotNull(PROCOID, procedureTuple,
382  Anum_pg_proc_probin);
383  probinstring = TextDatumGetCString(probinattr);
384 
385  /* Look up the function itself */
386  user_fn = load_external_function(probinstring, prosrcstring, true,
387  &libraryhandle);
388 
389  /* Get the function information record (real or default) */
390  inforec = fetch_finfo_record(libraryhandle, prosrcstring);
391 
392  /* Cache the addresses for later calls */
393  record_C_func(procedureTuple, user_fn, inforec);
394 
395  pfree(prosrcstring);
396  pfree(probinstring);
397  }
398 
399  switch (inforec->api_version)
400  {
401  case 1:
402  /* New style: call directly */
403  finfo->fn_addr = user_fn;
404  break;
405  default:
406  /* Shouldn't get here if fetch_finfo_record did its job */
407  elog(ERROR, "unrecognized function API version: %d",
408  inforec->api_version);
409  break;
410  }
411 }
#define TextDatumGetCString(d)
Definition: builtins.h:98
void * load_external_function(const char *filename, const char *funcname, bool signalNotFound, void **filehandle)
Definition: dfmgr.c:105
const Pg_finfo_record * fetch_finfo_record(void *filehandle, const char *funcname)
Definition: fmgr.c:455
static void record_C_func(HeapTuple procedureTuple, PGFunction user_fn, const Pg_finfo_record *inforec)
Definition: fmgr.c:539
static CFuncHashTabEntry * lookup_C_func(HeapTuple procedureTuple)
Definition: fmgr.c:515
Datum(* PGFunction)(FunctionCallInfo fcinfo)
Definition: fmgr.h:40
const Pg_finfo_record * inforec
Definition: fmgr.c:52
PGFunction user_fn
Definition: fmgr.c:51
PGFunction fn_addr
Definition: fmgr.h:58
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
Definition: syscache.c:510

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

Referenced by fmgr_info_cxt_security().

◆ fmgr_info_copy()

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

Definition at line 580 of file fmgr.c.

582 {
583  memcpy(dstinfo, srcinfo, sizeof(FmgrInfo));
584  dstinfo->fn_mcxt = destcxt;
585  dstinfo->fn_extra = NULL;
586 }
Definition: fmgr.h:57
void * fn_extra
Definition: fmgr.h:64
MemoryContext fn_mcxt
Definition: fmgr.h:65

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

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

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

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

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(), ReleaseSysCache(), FmgrBuiltin::retset, SearchSysCache1(), FmgrBuiltin::strict, SysCacheGetAttrNotNull(), 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().

◆ fmgr_info_other_lang()

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

Definition at line 418 of file fmgr.c.

419 {
420  Form_pg_proc procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
421  Oid language = procedureStruct->prolang;
422  HeapTuple languageTuple;
423  Form_pg_language languageStruct;
424  FmgrInfo plfinfo;
425 
426  languageTuple = SearchSysCache1(LANGOID, ObjectIdGetDatum(language));
427  if (!HeapTupleIsValid(languageTuple))
428  elog(ERROR, "cache lookup failed for language %u", language);
429  languageStruct = (Form_pg_language) GETSTRUCT(languageTuple);
430 
431  /*
432  * Look up the language's call handler function, ignoring any attributes
433  * that would normally cause insertion of fmgr_security_definer. We need
434  * to get back a bare pointer to the actual C-language function.
435  */
436  fmgr_info_cxt_security(languageStruct->lanplcallfoid, &plfinfo,
437  CurrentMemoryContext, true);
438  finfo->fn_addr = plfinfo.fn_addr;
439 
440  ReleaseSysCache(languageTuple);
441 }
unsigned int Oid
Definition: postgres_ext.h:31

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

Referenced by fmgr_info_cxt_security().

◆ fmgr_internal_function()

Oid fmgr_internal_function ( const char *  proname)

Definition at line 595 of file fmgr.c.

596 {
597  const FmgrBuiltin *fbp = fmgr_lookupByName(proname);
598 
599  if (fbp == NULL)
600  return InvalidOid;
601  return fbp->foid;
602 }
NameData proname
Definition: pg_proc.h:35
Oid foid
Definition: fmgrtab.h:27

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

Referenced by fmgr_internal_validator().

◆ fmgr_isbuiltin()

static const FmgrBuiltin* fmgr_isbuiltin ( Oid  id)
static

Definition at line 76 of file fmgr.c.

77 {
78  uint16 index;
79 
80  /* fast lookup only possible if original oid still assigned */
81  if (id > fmgr_last_builtin_oid)
82  return NULL;
83 
84  /*
85  * Lookup function data. If there's a miss in that range it's likely a
86  * nonexistent function, returning NULL here will trigger an ERROR later.
87  */
90  return NULL;
91 
92  return &fmgr_builtins[index];
93 }
unsigned short uint16
Definition: c.h:492
PGDLLIMPORT const Oid fmgr_last_builtin_oid
PGDLLIMPORT const FmgrBuiltin fmgr_builtins[]
#define InvalidOidBuiltinMapping
Definition: fmgrtab.h:46
PGDLLIMPORT const uint16 fmgr_builtin_oid_index[]
Definition: type.h:95

References fmgr_builtin_oid_index, fmgr_builtins, fmgr_last_builtin_oid, and InvalidOidBuiltinMapping.

Referenced by fmgr_info_cxt_security().

◆ fmgr_lookupByName()

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

Definition at line 101 of file fmgr.c.

102 {
103  int i;
104 
105  for (i = 0; i < fmgr_nbuiltins; i++)
106  {
107  if (strcmp(name, fmgr_builtins[i].funcName) == 0)
108  return fmgr_builtins + i;
109  }
110  return NULL;
111 }
PGDLLIMPORT const int fmgr_nbuiltins
int i
Definition: isn.c:73
const char * name

References fmgr_builtins, fmgr_nbuiltins, i, and name.

Referenced by fmgr_info_cxt_security(), and fmgr_internal_function().

◆ fmgr_security_definer()

Datum fmgr_security_definer ( PG_FUNCTION_ARGS  )

Definition at line 632 of file fmgr.c.

633 {
634  Datum result;
635  struct fmgr_security_definer_cache *volatile fcache;
636  FmgrInfo *save_flinfo;
637  Oid save_userid;
638  int save_sec_context;
639  ListCell *lc1,
640  *lc2,
641  *lc3;
642  volatile int save_nestlevel;
643  PgStat_FunctionCallUsage fcusage;
644 
645  if (!fcinfo->flinfo->fn_extra)
646  {
647  HeapTuple tuple;
648  Form_pg_proc procedureStruct;
649  Datum datum;
650  bool isnull;
651  MemoryContext oldcxt;
652 
653  fcache = MemoryContextAllocZero(fcinfo->flinfo->fn_mcxt,
654  sizeof(*fcache));
655 
656  fmgr_info_cxt_security(fcinfo->flinfo->fn_oid, &fcache->flinfo,
657  fcinfo->flinfo->fn_mcxt, true);
658  fcache->flinfo.fn_expr = fcinfo->flinfo->fn_expr;
659 
660  tuple = SearchSysCache1(PROCOID,
661  ObjectIdGetDatum(fcinfo->flinfo->fn_oid));
662  if (!HeapTupleIsValid(tuple))
663  elog(ERROR, "cache lookup failed for function %u",
664  fcinfo->flinfo->fn_oid);
665  procedureStruct = (Form_pg_proc) GETSTRUCT(tuple);
666 
667  if (procedureStruct->prosecdef)
668  fcache->userid = procedureStruct->proowner;
669 
670  datum = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_proconfig,
671  &isnull);
672  if (!isnull)
673  {
674  ArrayType *array;
675  ListCell *lc;
676 
677  oldcxt = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
678  array = DatumGetArrayTypeP(datum);
679  TransformGUCArray(array, &fcache->configNames,
680  &fcache->configValues);
681 
682  /* transform names to config handles to avoid lookup cost */
683  fcache->configHandles = NIL;
684  foreach(lc, fcache->configNames)
685  {
686  char *name = (char *) lfirst(lc);
687 
688  fcache->configHandles = lappend(fcache->configHandles,
690  }
691 
692  MemoryContextSwitchTo(oldcxt);
693  }
694 
695  ReleaseSysCache(tuple);
696 
697  fcinfo->flinfo->fn_extra = fcache;
698  }
699  else
700  fcache = fcinfo->flinfo->fn_extra;
701 
702  /* GetUserIdAndSecContext is cheap enough that no harm in a wasted call */
703  GetUserIdAndSecContext(&save_userid, &save_sec_context);
704  if (fcache->configNames != NIL) /* Need a new GUC nesting level */
705  save_nestlevel = NewGUCNestLevel();
706  else
707  save_nestlevel = 0; /* keep compiler quiet */
708 
709  if (OidIsValid(fcache->userid))
711  save_sec_context | SECURITY_LOCAL_USERID_CHANGE);
712 
713  forthree(lc1, fcache->configNames,
714  lc2, fcache->configHandles,
715  lc3, fcache->configValues)
716  {
717  GucContext context = superuser() ? PGC_SUSET : PGC_USERSET;
720  char *name = lfirst(lc1);
721  config_handle *handle = lfirst(lc2);
722  char *value = lfirst(lc3);
723 
724  (void) set_config_with_handle(name, handle, value,
725  context, source, GetUserId(),
726  action, true, 0, false);
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->configNames != NIL)
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 }
#define DatumGetArrayTypeP(X)
Definition: array.h:261
#define OidIsValid(objectId)
Definition: c.h:762
#define PG_RE_THROW()
Definition: elog.h:411
#define PG_TRY(...)
Definition: elog.h:370
#define PG_END_TRY(...)
Definition: elog.h:395
#define PG_CATCH(...)
Definition: elog.h:380
@ ExprMultipleResult
Definition: execnodes.h:304
PGDLLIMPORT fmgr_hook_type fmgr_hook
Definition: fmgr.c:40
@ FHET_END
Definition: fmgr.h:785
@ FHET_ABORT
Definition: fmgr.h:786
@ FHET_START
Definition: fmgr.h:784
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
int NewGUCNestLevel(void)
Definition: guc.c:2237
config_handle * get_config_handle(const char *name)
Definition: guc.c:4227
int set_config_with_handle(const char *name, config_handle *handle, const char *value, GucContext context, GucSource source, Oid srole, GucAction action, bool changeVal, int elevel, bool is_reload)
Definition: guc.c:3393
void TransformGUCArray(ArrayType *array, List **names, List **values)
Definition: guc.c:6343
void AtEOXact_GUC(bool isCommit, int nestLevel)
Definition: guc.c:2264
GucAction
Definition: guc.h:197
@ GUC_ACTION_SAVE
Definition: guc.h:201
GucSource
Definition: guc.h:108
@ PGC_S_SESSION
Definition: guc.h:122
GucContext
Definition: guc.h:68
@ PGC_SUSET
Definition: guc.h:74
@ PGC_USERSET
Definition: guc.h:75
static struct @150 value
List * lappend(List *list, void *datum)
Definition: list.c:339
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:1202
#define SECURITY_LOCAL_USERID_CHANGE
Definition: miscadmin.h:314
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
Definition: miscinit.c:635
void SetUserIdAndSecContext(Oid userid, int sec_context)
Definition: miscinit.c:642
#define IsA(nodeptr, _type_)
Definition: nodes.h:158
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
#define lfirst(lc)
Definition: pg_list.h:172
#define NIL
Definition: pg_list.h:68
#define forthree(cell1, list1, cell2, list2, cell3, list3)
Definition: pg_list.h:563
static rewind_source * source
Definition: pg_rewind.c:89
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
bool superuser(void)
Definition: superuser.c:46
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:479

References generate_unaccent_rules::action, fmgr_security_definer_cache::arg, AtEOXact_GUC(), fmgr_security_definer_cache::configHandles, fmgr_security_definer_cache::configNames, fmgr_security_definer_cache::configValues, DatumGetArrayTypeP, 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, forthree, FunctionCallInvoke, get_config_handle(), GETSTRUCT, GetUserId(), GetUserIdAndSecContext(), GUC_ACTION_SAVE, HeapTupleIsValid, IsA, lappend(), lfirst, MemoryContextAllocZero(), MemoryContextSwitchTo(), name, NewGUCNestLevel(), NIL, 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(), ReleaseSysCache(), SearchSysCache1(), SECURITY_LOCAL_USERID_CHANGE, set_config_with_handle(), SetUserIdAndSecContext(), source, superuser(), SysCacheGetAttr(), TransformGUCArray(), fmgr_security_definer_cache::userid, and value.

Referenced by fmgr_info_cxt_security().

◆ fmgr_symbol()

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

Definition at line 281 of file fmgr.c.

282 {
283  HeapTuple procedureTuple;
284  Form_pg_proc procedureStruct;
285  Datum prosrcattr;
286  Datum probinattr;
287 
288  procedureTuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(functionId));
289  if (!HeapTupleIsValid(procedureTuple))
290  elog(ERROR, "cache lookup failed for function %u", functionId);
291  procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
292 
293  if (procedureStruct->prosecdef ||
294  !heap_attisnull(procedureTuple, Anum_pg_proc_proconfig, NULL) ||
295  FmgrHookIsNeeded(functionId))
296  {
297  *mod = NULL; /* core binary */
298  *fn = pstrdup("fmgr_security_definer");
299  ReleaseSysCache(procedureTuple);
300  return;
301  }
302 
303  /* see fmgr_info_cxt_security for the individual cases */
304  switch (procedureStruct->prolang)
305  {
306  case INTERNALlanguageId:
307  prosrcattr = SysCacheGetAttrNotNull(PROCOID, procedureTuple,
308  Anum_pg_proc_prosrc);
309 
310  *mod = NULL; /* core binary */
311  *fn = TextDatumGetCString(prosrcattr);
312  break;
313 
314  case ClanguageId:
315  prosrcattr = SysCacheGetAttrNotNull(PROCOID, procedureTuple,
316  Anum_pg_proc_prosrc);
317 
318  probinattr = SysCacheGetAttrNotNull(PROCOID, procedureTuple,
319  Anum_pg_proc_probin);
320 
321  /*
322  * No need to check symbol presence / API version here, already
323  * checked in fmgr_info_cxt_security.
324  */
325  *mod = TextDatumGetCString(probinattr);
326  *fn = TextDatumGetCString(prosrcattr);
327  break;
328 
329  case SQLlanguageId:
330  *mod = NULL; /* core binary */
331  *fn = pstrdup("fmgr_sql");
332  break;
333 
334  default:
335  *mod = NULL;
336  *fn = NULL; /* unknown, pass pointer */
337  break;
338  }
339 
340  ReleaseSysCache(procedureTuple);
341 }
char * pstrdup(const char *in)
Definition: mcxt.c:1683
static void * fn(void *arg)
Definition: thread-alloc.c:119

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

Referenced by llvm_function_reference().

◆ FunctionCall0Coll()

Datum FunctionCall0Coll ( FmgrInfo flinfo,
Oid  collation 
)

Definition at line 1112 of file fmgr.c.

1113 {
1114  LOCAL_FCINFO(fcinfo, 0);
1115  Datum result;
1116 
1117  InitFunctionCallInfoData(*fcinfo, flinfo, 0, collation, NULL, NULL);
1118 
1119  result = FunctionCallInvoke(fcinfo);
1120 
1121  /* Check for null result, since caller is clearly not expecting one */
1122  if (fcinfo->isnull)
1123  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1124 
1125  return result;
1126 }

References elog, ERROR, fmgr_security_definer_cache::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by OidFunctionCall0Coll().

◆ FunctionCall1Coll()

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

Definition at line 1129 of file fmgr.c.

1130 {
1131  LOCAL_FCINFO(fcinfo, 1);
1132  Datum result;
1133 
1134  InitFunctionCallInfoData(*fcinfo, flinfo, 1, collation, NULL, NULL);
1135 
1136  fcinfo->args[0].value = arg1;
1137  fcinfo->args[0].isnull = false;
1138 
1139  result = FunctionCallInvoke(fcinfo);
1140 
1141  /* Check for null result, since caller is clearly not expecting one */
1142  if (fcinfo->isnull)
1143  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1144 
1145  return result;
1146 }

References elog, ERROR, fmgr_security_definer_cache::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by _hash_datum2hashkey(), brin_bloom_add_value(), brin_bloom_consistent(), brin_inclusion_add_value(), element_hash(), ExecHashBuildSkewHash(), ExecHashGetHashValue(), gistCompressValues(), gistdentryinit(), gistFetchAtt(), hash_multirange(), hash_range(), MemoizeHash_hash(), OidFunctionCall1Coll(), signValue(), spgdoinsert(), and TupleHashTableHash_internal().

◆ FunctionCall2Coll()

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

Definition at line 1149 of file fmgr.c.

1150 {
1151  LOCAL_FCINFO(fcinfo, 2);
1152  Datum result;
1153 
1154  InitFunctionCallInfoData(*fcinfo, flinfo, 2, collation, NULL, NULL);
1155 
1156  fcinfo->args[0].value = arg1;
1157  fcinfo->args[0].isnull = false;
1158  fcinfo->args[1].value = arg2;
1159  fcinfo->args[1].isnull = false;
1160 
1161  result = FunctionCallInvoke(fcinfo);
1162 
1163  /* Check for null result, since caller is clearly not expecting one */
1164  if (fcinfo->isnull)
1165  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1166 
1167  return result;
1168 }

References elog, ERROR, fmgr_security_definer_cache::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by _bt_check_rowcompare(), _bt_checkkeys(), _bt_compare(), _bt_compare_array_elements(), _bt_compare_scankey_args(), _bt_find_extreme_element(), _bt_keep_natts(), _hash_checkqual(), array_position_common(), array_positions(), AssertCheckExpandedRanges(), AssertCheckRanges(), brin_inclusion_add_value(), brin_inclusion_consistent(), brin_inclusion_union(), brin_minmax_add_value(), brin_minmax_consistent(), brin_minmax_multi_consistent(), brin_minmax_union(), build_distances(), call_subtype_diff(), cmpEntries(), compare_expanded_ranges(), compare_values(), compute_distinct_stats(), compute_partition_hash_value(), compute_range_stats(), create_range_bounds(), doPickSplit(), element_compare(), ExecEvalPreOrderedDistinctSingle(), execTuplesUnequal(), genericPickSplit(), get_distance(), get_partition_for_tuple(), get_position(), get_stats_slot_range(), ginCompareEntries(), gistMakeUnionItVec(), gistMakeUnionKey(), gistUserPicksplit(), has_matching_range(), hash_multirange_extended(), hash_range_extended(), HeapKeyTest(), ineq_histogram_selectivity(), make_greater_string(), mcv_get_match_bitmap(), merge_list_bounds(), merge_overlapping_ranges(), mode_final(), multirange_elem_bsearch_comparison(), OidFunctionCall2Coll(), partition_list_bsearch(), partition_rbound_cmp(), partition_rbound_datum_cmp(), process_ordered_aggregate_single(), qsort_partition_list_value_cmp(), range_cmp_bound_values(), range_cmp_bounds(), range_contains_elem_internal(), range_contains_value(), ri_AttributesEqual(), satisfies_hash_partition(), spgdoinsert(), spgGetCache(), spgInnerTest(), spgLeafTest(), and tuples_equal().

◆ FunctionCall3Coll()

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

Definition at line 1171 of file fmgr.c.

1173 {
1174  LOCAL_FCINFO(fcinfo, 3);
1175  Datum result;
1176 
1177  InitFunctionCallInfoData(*fcinfo, flinfo, 3, collation, NULL, NULL);
1178 
1179  fcinfo->args[0].value = arg1;
1180  fcinfo->args[0].isnull = false;
1181  fcinfo->args[1].value = arg2;
1182  fcinfo->args[1].isnull = false;
1183  fcinfo->args[2].value = arg3;
1184  fcinfo->args[2].isnull = false;
1185 
1186  result = FunctionCallInvoke(fcinfo);
1187 
1188  /* Check for null result, since caller is clearly not expecting one */
1189  if (fcinfo->isnull)
1190  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1191 
1192  return result;
1193 }

References elog, ERROR, fmgr_security_definer_cache::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

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

◆ FunctionCall4Coll()

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

Definition at line 1196 of file fmgr.c.

1198 {
1199  LOCAL_FCINFO(fcinfo, 4);
1200  Datum result;
1201 
1202  InitFunctionCallInfoData(*fcinfo, flinfo, 4, collation, NULL, NULL);
1203 
1204  fcinfo->args[0].value = arg1;
1205  fcinfo->args[0].isnull = false;
1206  fcinfo->args[1].value = arg2;
1207  fcinfo->args[1].isnull = false;
1208  fcinfo->args[2].value = arg3;
1209  fcinfo->args[2].isnull = false;
1210  fcinfo->args[3].value = arg4;
1211  fcinfo->args[3].isnull = false;
1212 
1213  result = FunctionCallInvoke(fcinfo);
1214 
1215  /* Check for null result, since caller is clearly not expecting one */
1216  if (fcinfo->isnull)
1217  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1218 
1219  return result;
1220 }

References elog, ERROR, fmgr_security_definer_cache::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by add_values_to_range(), bringetbitmap(), collectMatchBitmap(), matchPartialInPendingList(), OidFunctionCall4Coll(), and scalararraysel().

◆ FunctionCall5Coll()

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

Definition at line 1223 of file fmgr.c.

1225 {
1226  LOCAL_FCINFO(fcinfo, 5);
1227  Datum result;
1228 
1229  InitFunctionCallInfoData(*fcinfo, flinfo, 5, collation, NULL, NULL);
1230 
1231  fcinfo->args[0].value = arg1;
1232  fcinfo->args[0].isnull = false;
1233  fcinfo->args[1].value = arg2;
1234  fcinfo->args[1].isnull = false;
1235  fcinfo->args[2].value = arg3;
1236  fcinfo->args[2].isnull = false;
1237  fcinfo->args[3].value = arg4;
1238  fcinfo->args[3].isnull = false;
1239  fcinfo->args[4].value = arg5;
1240  fcinfo->args[4].isnull = false;
1241 
1242  result = FunctionCallInvoke(fcinfo);
1243 
1244  /* Check for null result, since caller is clearly not expecting one */
1245  if (fcinfo->isnull)
1246  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1247 
1248  return result;
1249 }

References elog, ERROR, fmgr_security_definer_cache::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

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

◆ FunctionCall6Coll()

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

Definition at line 1252 of file fmgr.c.

1255 {
1256  LOCAL_FCINFO(fcinfo, 6);
1257  Datum result;
1258 
1259  InitFunctionCallInfoData(*fcinfo, flinfo, 6, collation, NULL, NULL);
1260 
1261  fcinfo->args[0].value = arg1;
1262  fcinfo->args[0].isnull = false;
1263  fcinfo->args[1].value = arg2;
1264  fcinfo->args[1].isnull = false;
1265  fcinfo->args[2].value = arg3;
1266  fcinfo->args[2].isnull = false;
1267  fcinfo->args[3].value = arg4;
1268  fcinfo->args[3].isnull = false;
1269  fcinfo->args[4].value = arg5;
1270  fcinfo->args[4].isnull = false;
1271  fcinfo->args[5].value = arg6;
1272  fcinfo->args[5].isnull = false;
1273 
1274  result = FunctionCallInvoke(fcinfo);
1275 
1276  /* Check for null result, since caller is clearly not expecting one */
1277  if (fcinfo->isnull)
1278  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1279 
1280  return result;
1281 }

References elog, ERROR, fmgr_security_definer_cache::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by OidFunctionCall6Coll().

◆ FunctionCall7Coll()

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

Definition at line 1284 of file fmgr.c.

1287 {
1288  LOCAL_FCINFO(fcinfo, 7);
1289  Datum result;
1290 
1291  InitFunctionCallInfoData(*fcinfo, flinfo, 7, collation, NULL, NULL);
1292 
1293  fcinfo->args[0].value = arg1;
1294  fcinfo->args[0].isnull = false;
1295  fcinfo->args[1].value = arg2;
1296  fcinfo->args[1].isnull = false;
1297  fcinfo->args[2].value = arg3;
1298  fcinfo->args[2].isnull = false;
1299  fcinfo->args[3].value = arg4;
1300  fcinfo->args[3].isnull = false;
1301  fcinfo->args[4].value = arg5;
1302  fcinfo->args[4].isnull = false;
1303  fcinfo->args[5].value = arg6;
1304  fcinfo->args[5].isnull = false;
1305  fcinfo->args[6].value = arg7;
1306  fcinfo->args[6].isnull = false;
1307 
1308  result = FunctionCallInvoke(fcinfo);
1309 
1310  /* Check for null result, since caller is clearly not expecting one */
1311  if (fcinfo->isnull)
1312  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1313 
1314  return result;
1315 }

References elog, ERROR, fmgr_security_definer_cache::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by directTriConsistentFn(), gincost_pattern(), OidFunctionCall7Coll(), and shimBoolConsistentFn().

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

1321 {
1322  LOCAL_FCINFO(fcinfo, 8);
1323  Datum result;
1324 
1325  InitFunctionCallInfoData(*fcinfo, flinfo, 8, collation, NULL, NULL);
1326 
1327  fcinfo->args[0].value = arg1;
1328  fcinfo->args[0].isnull = false;
1329  fcinfo->args[1].value = arg2;
1330  fcinfo->args[1].isnull = false;
1331  fcinfo->args[2].value = arg3;
1332  fcinfo->args[2].isnull = false;
1333  fcinfo->args[3].value = arg4;
1334  fcinfo->args[3].isnull = false;
1335  fcinfo->args[4].value = arg5;
1336  fcinfo->args[4].isnull = false;
1337  fcinfo->args[5].value = arg6;
1338  fcinfo->args[5].isnull = false;
1339  fcinfo->args[6].value = arg7;
1340  fcinfo->args[6].isnull = false;
1341  fcinfo->args[7].value = arg8;
1342  fcinfo->args[7].isnull = false;
1343 
1344  result = FunctionCallInvoke(fcinfo);
1345 
1346  /* Check for null result, since caller is clearly not expecting one */
1347  if (fcinfo->isnull)
1348  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1349 
1350  return result;
1351 }

References elog, ERROR, fmgr_security_definer_cache::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by directBoolConsistentFn(), and OidFunctionCall8Coll().

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

1358 {
1359  LOCAL_FCINFO(fcinfo, 9);
1360  Datum result;
1361 
1362  InitFunctionCallInfoData(*fcinfo, flinfo, 9, collation, NULL, NULL);
1363 
1364  fcinfo->args[0].value = arg1;
1365  fcinfo->args[0].isnull = false;
1366  fcinfo->args[1].value = arg2;
1367  fcinfo->args[1].isnull = false;
1368  fcinfo->args[2].value = arg3;
1369  fcinfo->args[2].isnull = false;
1370  fcinfo->args[3].value = arg4;
1371  fcinfo->args[3].isnull = false;
1372  fcinfo->args[4].value = arg5;
1373  fcinfo->args[4].isnull = false;
1374  fcinfo->args[5].value = arg6;
1375  fcinfo->args[5].isnull = false;
1376  fcinfo->args[6].value = arg7;
1377  fcinfo->args[6].isnull = false;
1378  fcinfo->args[7].value = arg8;
1379  fcinfo->args[7].isnull = false;
1380  fcinfo->args[8].value = arg9;
1381  fcinfo->args[8].isnull = false;
1382 
1383  result = FunctionCallInvoke(fcinfo);
1384 
1385  /* Check for null result, since caller is clearly not expecting one */
1386  if (fcinfo->isnull)
1387  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1388 
1389  return result;
1390 }

References elog, ERROR, fmgr_security_definer_cache::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by OidFunctionCall9Coll().

◆ get_call_expr_arg_stable()

bool get_call_expr_arg_stable ( Node expr,
int  argnum 
)

Definition at line 1994 of file fmgr.c.

1995 {
1996  List *args;
1997  Node *arg;
1998 
1999  if (expr == NULL)
2000  return false;
2001 
2002  if (IsA(expr, FuncExpr))
2003  args = ((FuncExpr *) expr)->args;
2004  else if (IsA(expr, OpExpr))
2005  args = ((OpExpr *) expr)->args;
2006  else if (IsA(expr, DistinctExpr))
2007  args = ((DistinctExpr *) expr)->args;
2008  else if (IsA(expr, ScalarArrayOpExpr))
2009  args = ((ScalarArrayOpExpr *) expr)->args;
2010  else if (IsA(expr, NullIfExpr))
2011  args = ((NullIfExpr *) expr)->args;
2012  else if (IsA(expr, WindowFunc))
2013  args = ((WindowFunc *) expr)->args;
2014  else
2015  return false;
2016 
2017  if (argnum < 0 || argnum >= list_length(args))
2018  return false;
2019 
2020  arg = (Node *) list_nth(args, argnum);
2021 
2022  /*
2023  * Either a true Const or an external Param will have a value that doesn't
2024  * change during the execution of the query. In future we might want to
2025  * consider other cases too, e.g. now().
2026  */
2027  if (IsA(arg, Const))
2028  return true;
2029  if (IsA(arg, Param) &&
2030  ((Param *) arg)->paramkind == PARAM_EXTERN)
2031  return true;
2032 
2033  return false;
2034 }
void * arg
static int list_length(const List *l)
Definition: pg_list.h:152
static void * list_nth(const List *list, int n)
Definition: pg_list.h:299
@ PARAM_EXTERN
Definition: primnodes.h:353
Definition: pg_list.h:54
Definition: nodes.h:129

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

Referenced by get_fn_expr_arg_stable().

◆ get_call_expr_argtype()

Oid get_call_expr_argtype ( Node expr,
int  argnum 
)

Definition at line 1929 of file fmgr.c.

1930 {
1931  List *args;
1932  Oid argtype;
1933 
1934  if (expr == NULL)
1935  return InvalidOid;
1936 
1937  if (IsA(expr, FuncExpr))
1938  args = ((FuncExpr *) expr)->args;
1939  else if (IsA(expr, OpExpr))
1940  args = ((OpExpr *) expr)->args;
1941  else if (IsA(expr, DistinctExpr))
1942  args = ((DistinctExpr *) expr)->args;
1943  else if (IsA(expr, ScalarArrayOpExpr))
1944  args = ((ScalarArrayOpExpr *) expr)->args;
1945  else if (IsA(expr, NullIfExpr))
1946  args = ((NullIfExpr *) expr)->args;
1947  else if (IsA(expr, WindowFunc))
1948  args = ((WindowFunc *) expr)->args;
1949  else
1950  return InvalidOid;
1951 
1952  if (argnum < 0 || argnum >= list_length(args))
1953  return InvalidOid;
1954 
1955  argtype = exprType((Node *) list_nth(args, argnum));
1956 
1957  /*
1958  * special hack for ScalarArrayOpExpr: what the underlying function will
1959  * actually get passed is the element type of the array.
1960  */
1961  if (IsA(expr, ScalarArrayOpExpr) &&
1962  argnum == 1)
1963  argtype = get_base_element_type(argtype);
1964 
1965  return argtype;
1966 }
Oid get_base_element_type(Oid typid)
Definition: lsyscache.c:2788
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42

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

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

◆ get_fn_expr_arg_stable()

bool get_fn_expr_arg_stable ( FmgrInfo flinfo,
int  argnum 
)

Definition at line 1975 of file fmgr.c.

1976 {
1977  /*
1978  * can't return anything useful if we have no FmgrInfo or if its fn_expr
1979  * node has not been initialized
1980  */
1981  if (!flinfo || !flinfo->fn_expr)
1982  return false;
1983 
1984  return get_call_expr_arg_stable(flinfo->fn_expr, argnum);
1985 }
bool get_call_expr_arg_stable(Node *expr, int argnum)
Definition: fmgr.c:1994

References FmgrInfo::fn_expr, and get_call_expr_arg_stable().

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

◆ get_fn_expr_argtype()

◆ get_fn_expr_rettype()

Oid get_fn_expr_rettype ( FmgrInfo flinfo)

Definition at line 1888 of file fmgr.c.

1889 {
1890  Node *expr;
1891 
1892  /*
1893  * can't return anything useful if we have no FmgrInfo or if its fn_expr
1894  * node has not been initialized
1895  */
1896  if (!flinfo || !flinfo->fn_expr)
1897  return InvalidOid;
1898 
1899  expr = flinfo->fn_expr;
1900 
1901  return exprType(expr);
1902 }

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

Referenced by do_compile(), multirange_constructor0(), multirange_constructor1(), multirange_constructor2(), range_agg_finalfn(), range_constructor2(), and range_constructor3().

◆ get_fn_expr_variadic()

bool get_fn_expr_variadic ( FmgrInfo flinfo)

Definition at line 2044 of file fmgr.c.

2045 {
2046  Node *expr;
2047 
2048  /*
2049  * can't return anything useful if we have no FmgrInfo or if its fn_expr
2050  * node has not been initialized
2051  */
2052  if (!flinfo || !flinfo->fn_expr)
2053  return false;
2054 
2055  expr = flinfo->fn_expr;
2056 
2057  if (IsA(expr, FuncExpr))
2058  return ((FuncExpr *) expr)->funcvariadic;
2059  else
2060  return false;
2061 }

References FmgrInfo::fn_expr, and IsA.

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

◆ get_fn_opclass_options()

bytea* get_fn_opclass_options ( FmgrInfo flinfo)

Definition at line 2097 of file fmgr.c.

2098 {
2099  if (flinfo && flinfo->fn_expr && IsA(flinfo->fn_expr, Const))
2100  {
2101  Const *expr = (Const *) flinfo->fn_expr;
2102 
2103  if (expr->consttype == BYTEAOID)
2104  return expr->constisnull ? NULL : DatumGetByteaP(expr->constvalue);
2105  }
2106 
2107  ereport(ERROR,
2108  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2109  errmsg("operator class options info is absent in function call context")));
2110 
2111  return NULL;
2112 }
#define DatumGetByteaP(X)
Definition: fmgr.h:331
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
Oid consttype
Definition: primnodes.h:298

References Const::consttype, DatumGetByteaP, ereport, errcode(), errmsg(), ERROR, FmgrInfo::fn_expr, if(), and IsA.

◆ has_fn_opclass_options()

bool has_fn_opclass_options ( FmgrInfo flinfo)

Definition at line 2081 of file fmgr.c.

2082 {
2083  if (flinfo && flinfo->fn_expr && IsA(flinfo->fn_expr, Const))
2084  {
2085  Const *expr = (Const *) flinfo->fn_expr;
2086 
2087  if (expr->consttype == BYTEAOID)
2088  return !expr->constisnull;
2089  }
2090  return false;
2091 }

References Const::consttype, FmgrInfo::fn_expr, if(), and IsA.

◆ InputFunctionCall()

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

Definition at line 1530 of file fmgr.c.

1531 {
1532  LOCAL_FCINFO(fcinfo, 3);
1533  Datum result;
1534 
1535  if (str == NULL && flinfo->fn_strict)
1536  return (Datum) 0; /* just return null result */
1537 
1538  InitFunctionCallInfoData(*fcinfo, flinfo, 3, InvalidOid, NULL, NULL);
1539 
1540  fcinfo->args[0].value = CStringGetDatum(str);
1541  fcinfo->args[0].isnull = false;
1542  fcinfo->args[1].value = ObjectIdGetDatum(typioparam);
1543  fcinfo->args[1].isnull = false;
1544  fcinfo->args[2].value = Int32GetDatum(typmod);
1545  fcinfo->args[2].isnull = false;
1546 
1547  result = FunctionCallInvoke(fcinfo);
1548 
1549  /* Should get null result if and only if str is NULL */
1550  if (str == NULL)
1551  {
1552  if (!fcinfo->isnull)
1553  elog(ERROR, "input function %u returned non-NULL",
1554  flinfo->fn_oid);
1555  }
1556  else
1557  {
1558  if (fcinfo->isnull)
1559  elog(ERROR, "input function %u returned NULL",
1560  flinfo->fn_oid);
1561  }
1562 
1563  return result;
1564 }

References CStringGetDatum(), elog, ERROR, fmgr_security_definer_cache::flinfo, FmgrInfo::fn_oid, FmgrInfo::fn_strict, FunctionCallInvoke, InitFunctionCallInfoData, Int32GetDatum(), InvalidOid, LOCAL_FCINFO, ObjectIdGetDatum(), and generate_unaccent_rules::str.

Referenced by BuildTupleFromCStrings(), hstore_populate_record(), make_tuple_from_result_row(), OidInputFunctionCall(), plperl_sv_to_datum(), plsample_func_handler(), pltcl_func_handler(), pltcl_returnnext(), pltcl_SPI_execute_plan(), PLyObject_ToScalar(), PLyUnicode_ToComposite(), and XmlTableGetValue().

◆ InputFunctionCallSafe()

bool InputFunctionCallSafe ( FmgrInfo flinfo,
char *  str,
Oid  typioparam,
int32  typmod,
fmNodePtr  escontext,
Datum result 
)

Definition at line 1585 of file fmgr.c.

1589 {
1590  LOCAL_FCINFO(fcinfo, 3);
1591 
1592  if (str == NULL && flinfo->fn_strict)
1593  {
1594  *result = (Datum) 0; /* just return null result */
1595  return true;
1596  }
1597 
1598  InitFunctionCallInfoData(*fcinfo, flinfo, 3, InvalidOid, escontext, NULL);
1599 
1600  fcinfo->args[0].value = CStringGetDatum(str);
1601  fcinfo->args[0].isnull = false;
1602  fcinfo->args[1].value = ObjectIdGetDatum(typioparam);
1603  fcinfo->args[1].isnull = false;
1604  fcinfo->args[2].value = Int32GetDatum(typmod);
1605  fcinfo->args[2].isnull = false;
1606 
1607  *result = FunctionCallInvoke(fcinfo);
1608 
1609  /* Result value is garbage, and could be null, if an error was reported */
1610  if (SOFT_ERROR_OCCURRED(escontext))
1611  return false;
1612 
1613  /* Otherwise, should get null result if and only if str is NULL */
1614  if (str == NULL)
1615  {
1616  if (!fcinfo->isnull)
1617  elog(ERROR, "input function %u returned non-NULL",
1618  flinfo->fn_oid);
1619  }
1620  else
1621  {
1622  if (fcinfo->isnull)
1623  elog(ERROR, "input function %u returned NULL",
1624  flinfo->fn_oid);
1625  }
1626 
1627  return true;
1628 }

References CStringGetDatum(), elog, ERROR, fmgr_security_definer_cache::flinfo, FmgrInfo::fn_oid, FmgrInfo::fn_strict, FunctionCallInvoke, InitFunctionCallInfoData, Int32GetDatum(), InvalidOid, LOCAL_FCINFO, ObjectIdGetDatum(), SOFT_ERROR_OCCURRED, and generate_unaccent_rules::str.

Referenced by domain_in(), multirange_in(), NextCopyFrom(), pg_input_is_valid_common(), populate_scalar(), range_in(), ReadArrayStr(), and record_in().

◆ Int64GetDatum()

Datum Int64GetDatum ( int64  X)

Definition at line 1807 of file fmgr.c.

1808 {
1809  int64 *retval = (int64 *) palloc(sizeof(int64));
1810 
1811  *retval = X;
1812  return PointerGetDatum(retval);
1813 }

References palloc(), and PointerGetDatum().

Referenced by brin_metapage_info(), brin_page_items(), brin_summarize_new_values(), build_minmax_path(), CashGetDatum(), create_final_distinct_paths(), create_partial_distinct_paths(), DefineSequence(), delay_execution_planner(), ExecEvalNextValueExpr(), executeItemOptUnwrapTarget(), FillXLogStatsRow(), gbt_num_fetch(), generate_series_step_int8(), GetWALBlockInfo(), gin_metapage_info(), gin_page_opaque_info(), gist_page_opaque_info(), hash_array_extended(), hash_bitmap_info(), hash_metapage_info(), hash_page_items(), hash_page_stats(), hash_record_extended(), IdentifySystem(), int4_cash(), int8_cash(), int8_to_char(), int8range_canonical(), leftmostvalue_int8(), leftmostvalue_money(), LSNGetDatum(), make_const(), perform_work_item(), pg_available_wal_summaries(), pg_buffercache_pages(), pg_control_system(), pg_get_replication_slots(), pg_get_shmem_allocations(), pg_get_wal_summarizer_state(), pg_ls_dir_files(), pg_sequence_parameters(), pg_split_walfile_name(), pg_stat_file(), pg_stat_get_archiver(), pg_stat_get_io(), pg_stat_get_progress_info(), pg_stat_get_recovery_prefetch(), pg_stat_get_replication_slot(), pg_stat_get_slru(), pg_stat_get_subscription_stats(), pg_stat_get_wal(), pg_stat_statements_info(), pg_visibility_map_rel(), pg_visibility_map_summary(), pg_visibility_rel(), pg_wal_summary_contents(), pgstatginindex_internal(), pgstathashindex(), pgstattuple_approx_internal(), PutMemoryContextsStatsTupleStore(), ReadReplicationSlot(), report_corruption_internal(), rewriteSearchAndCycle(), SendTablespaceList(), SendXlogRecPtrResult(), StartReplication(), TimeADTGetDatum(), TimestampGetDatum(), TimestampTzGetDatum(), TSQuerySignGetDatum(), UInt64GetDatum(), and validate_index_callback().

◆ lookup_C_func()

static CFuncHashTabEntry * lookup_C_func ( HeapTuple  procedureTuple)
static

Definition at line 515 of file fmgr.c.

516 {
517  Oid fn_oid = ((Form_pg_proc) GETSTRUCT(procedureTuple))->oid;
518  CFuncHashTabEntry *entry;
519 
520  if (CFuncHash == NULL)
521  return NULL; /* no table yet */
522  entry = (CFuncHashTabEntry *)
524  &fn_oid,
525  HASH_FIND,
526  NULL);
527  if (entry == NULL)
528  return NULL; /* no such entry */
529  if (entry->fn_xmin == HeapTupleHeaderGetRawXmin(procedureTuple->t_data) &&
530  ItemPointerEquals(&entry->fn_tid, &procedureTuple->t_self))
531  return entry; /* OK */
532  return NULL; /* entry is out of date */
533 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:955
static HTAB * CFuncHash
Definition: fmgr.c:55
@ HASH_FIND
Definition: hsearch.h:113
#define HeapTupleHeaderGetRawXmin(tup)
Definition: htup_details.h:304
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
Definition: itemptr.c:35
TransactionId fn_xmin
Definition: fmgr.c:49
ItemPointerData fn_tid
Definition: fmgr.c:50
ItemPointerData t_self
Definition: htup.h:65
HeapTupleHeader t_data
Definition: htup.h:68

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

Referenced by fmgr_info_C_lang().

◆ OidFunctionCall0Coll()

Datum OidFunctionCall0Coll ( Oid  functionId,
Oid  collation 
)

Definition at line 1401 of file fmgr.c.

1402 {
1403  FmgrInfo flinfo;
1404 
1405  fmgr_info(functionId, &flinfo);
1406 
1407  return FunctionCall0Coll(&flinfo, collation);
1408 }
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:127
Datum FunctionCall0Coll(FmgrInfo *flinfo, Oid collation)
Definition: fmgr.c:1112

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

◆ OidFunctionCall1Coll()

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

Definition at line 1411 of file fmgr.c.

1412 {
1413  FmgrInfo flinfo;
1414 
1415  fmgr_info(functionId, &flinfo);
1416 
1417  return FunctionCall1Coll(&flinfo, collation, arg1);
1418 }
Datum FunctionCall1Coll(FmgrInfo *flinfo, Oid collation, Datum arg1)
Definition: fmgr.c:1129

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

Referenced by _bt_allequalimage(), _hash_datum2hashkey_type(), and GistTranslateStratnum().

◆ OidFunctionCall2Coll()

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

Definition at line 1421 of file fmgr.c.

1422 {
1423  FmgrInfo flinfo;
1424 
1425  fmgr_info(functionId, &flinfo);
1426 
1427  return FunctionCall2Coll(&flinfo, collation, arg1, arg2);
1428 }
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:1149

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

Referenced by _bt_compare_scankey_args(), and index_recheck_constraint().

◆ OidFunctionCall3Coll()

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

Definition at line 1431 of file fmgr.c.

1433 {
1434  FmgrInfo flinfo;
1435 
1436  fmgr_info(functionId, &flinfo);
1437 
1438  return FunctionCall3Coll(&flinfo, collation, arg1, arg2, arg3);
1439 }
Datum FunctionCall3Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3)
Definition: fmgr.c:1171

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

◆ OidFunctionCall4Coll()

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

Definition at line 1442 of file fmgr.c.

1444 {
1445  FmgrInfo flinfo;
1446 
1447  fmgr_info(functionId, &flinfo);
1448 
1449  return FunctionCall4Coll(&flinfo, collation, arg1, arg2, arg3, arg4);
1450 }
Datum FunctionCall4Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4)
Definition: fmgr.c:1196

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

Referenced by restriction_selectivity().

◆ OidFunctionCall5Coll()

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

Definition at line 1453 of file fmgr.c.

1455 {
1456  FmgrInfo flinfo;
1457 
1458  fmgr_info(functionId, &flinfo);
1459 
1460  return FunctionCall5Coll(&flinfo, collation, arg1, arg2, arg3, arg4, arg5);
1461 }
Datum FunctionCall5Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5)
Definition: fmgr.c:1223

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

Referenced by join_selectivity().

◆ OidFunctionCall6Coll()

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

Definition at line 1464 of file fmgr.c.

1467 {
1468  FmgrInfo flinfo;
1469 
1470  fmgr_info(functionId, &flinfo);
1471 
1472  return FunctionCall6Coll(&flinfo, collation, arg1, arg2, arg3, arg4, arg5,
1473  arg6);
1474 }
Datum FunctionCall6Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6)
Definition: fmgr.c:1252

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

◆ OidFunctionCall7Coll()

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

Definition at line 1477 of file fmgr.c.

1480 {
1481  FmgrInfo flinfo;
1482 
1483  fmgr_info(functionId, &flinfo);
1484 
1485  return FunctionCall7Coll(&flinfo, collation, arg1, arg2, arg3, arg4, arg5,
1486  arg6, arg7);
1487 }
Datum FunctionCall7Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7)
Definition: fmgr.c:1284

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

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

1493 {
1494  FmgrInfo flinfo;
1495 
1496  fmgr_info(functionId, &flinfo);
1497 
1498  return FunctionCall8Coll(&flinfo, collation, arg1, arg2, arg3, arg4, arg5,
1499  arg6, arg7, arg8);
1500 }
Datum FunctionCall8Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8)
Definition: fmgr.c:1318

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

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

1507 {
1508  FmgrInfo flinfo;
1509 
1510  fmgr_info(functionId, &flinfo);
1511 
1512  return FunctionCall9Coll(&flinfo, collation, arg1, arg2, arg3, arg4, arg5,
1513  arg6, arg7, arg8, arg9);
1514 }
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: fmgr.c:1354

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

◆ OidInputFunctionCall()

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

Definition at line 1754 of file fmgr.c.

1755 {
1756  FmgrInfo flinfo;
1757 
1758  fmgr_info(functionId, &flinfo);
1759  return InputFunctionCall(&flinfo, str, typioparam, typmod);
1760 }
Datum InputFunctionCall(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
Definition: fmgr.c:1530

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

Referenced by DefineAggregate(), exec_bind_message(), get_typdefault(), GetAggInitVal(), InsertOneValue(), parse_fcall_arguments(), slot_modify_data(), slot_store_data(), and stringTypeDatum().

◆ OidOutputFunctionCall()

◆ OidReceiveFunctionCall()

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

Definition at line 1772 of file fmgr.c.

1774 {
1775  FmgrInfo flinfo;
1776 
1777  fmgr_info(functionId, &flinfo);
1778  return ReceiveFunctionCall(&flinfo, buf, typioparam, typmod);
1779 }
Datum ReceiveFunctionCall(FmgrInfo *flinfo, StringInfo buf, Oid typioparam, int32 typmod)
Definition: fmgr.c:1697
static char * buf
Definition: pg_test_fsync.c:73

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

Referenced by exec_bind_message(), parse_fcall_arguments(), slot_modify_data(), and slot_store_data().

◆ OidSendFunctionCall()

bytea* OidSendFunctionCall ( Oid  functionId,
Datum  val 
)

Definition at line 1782 of file fmgr.c.

1783 {
1784  FmgrInfo flinfo;
1785 
1786  fmgr_info(functionId, &flinfo);
1787  return SendFunctionCall(&flinfo, val);
1788 }
bytea * SendFunctionCall(FmgrInfo *flinfo, Datum val)
Definition: fmgr.c:1744

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

Referenced by logicalrep_write_tuple(), and SendFunctionResult().

◆ OutputFunctionCall()

◆ pg_detoast_datum()

struct varlena* pg_detoast_datum ( struct varlena datum)

Definition at line 1832 of file fmgr.c.

1833 {
1834  if (VARATT_IS_EXTENDED(datum))
1835  return detoast_attr(datum);
1836  else
1837  return datum;
1838 }
struct varlena * detoast_attr(struct varlena *attr)
Definition: detoast.c:116
#define VARATT_IS_EXTENDED(PTR)
Definition: varatt.h:303

References detoast_attr(), and VARATT_IS_EXTENDED.

◆ pg_detoast_datum_copy()

struct varlena* pg_detoast_datum_copy ( struct varlena datum)

Definition at line 1841 of file fmgr.c.

1842 {
1843  if (VARATT_IS_EXTENDED(datum))
1844  return detoast_attr(datum);
1845  else
1846  {
1847  /* Make a modifiable copy of the varlena object */
1848  Size len = VARSIZE(datum);
1849  struct varlena *result = (struct varlena *) palloc(len);
1850 
1851  memcpy(result, datum, len);
1852  return result;
1853  }
1854 }
size_t Size
Definition: c.h:592
const void size_t len
Definition: c.h:674
#define VARSIZE(PTR)
Definition: varatt.h:279

References detoast_attr(), len, palloc(), VARATT_IS_EXTENDED, and VARSIZE.

Referenced by tuple_data_split_internal().

◆ pg_detoast_datum_packed()

struct varlena* pg_detoast_datum_packed ( struct varlena datum)

Definition at line 1864 of file fmgr.c.

1865 {
1866  if (VARATT_IS_COMPRESSED(datum) || VARATT_IS_EXTERNAL(datum))
1867  return detoast_attr(datum);
1868  else
1869  return datum;
1870 }
#define VARATT_IS_COMPRESSED(PTR)
Definition: varatt.h:288
#define VARATT_IS_EXTERNAL(PTR)
Definition: varatt.h:289

References detoast_attr(), VARATT_IS_COMPRESSED, and VARATT_IS_EXTERNAL.

Referenced by makeJsonLexContext(), text_to_cstring(), text_to_cstring_buffer(), and transform_jsonb_string_values().

◆ pg_detoast_datum_slice()

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

Definition at line 1857 of file fmgr.c.

1858 {
1859  /* Only get the specified portion from the toast rel */
1860  return detoast_attr_slice(datum, first, count);
1861 }
struct varlena * detoast_attr_slice(struct varlena *attr, int32 sliceoffset, int32 slicelength)
Definition: detoast.c:205

References detoast_attr_slice().

◆ ReceiveFunctionCall()

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

Definition at line 1697 of file fmgr.c.

1699 {
1700  LOCAL_FCINFO(fcinfo, 3);
1701  Datum result;
1702 
1703  if (buf == NULL && flinfo->fn_strict)
1704  return (Datum) 0; /* just return null result */
1705 
1706  InitFunctionCallInfoData(*fcinfo, flinfo, 3, InvalidOid, NULL, NULL);
1707 
1708  fcinfo->args[0].value = PointerGetDatum(buf);
1709  fcinfo->args[0].isnull = false;
1710  fcinfo->args[1].value = ObjectIdGetDatum(typioparam);
1711  fcinfo->args[1].isnull = false;
1712  fcinfo->args[2].value = Int32GetDatum(typmod);
1713  fcinfo->args[2].isnull = false;
1714 
1715  result = FunctionCallInvoke(fcinfo);
1716 
1717  /* Should get null result if and only if buf is NULL */
1718  if (buf == NULL)
1719  {
1720  if (!fcinfo->isnull)
1721  elog(ERROR, "receive function %u returned non-NULL",
1722  flinfo->fn_oid);
1723  }
1724  else
1725  {
1726  if (fcinfo->isnull)
1727  elog(ERROR, "receive function %u returned NULL",
1728  flinfo->fn_oid);
1729  }
1730 
1731  return result;
1732 }

References buf, elog, ERROR, fmgr_security_definer_cache::flinfo, FmgrInfo::fn_oid, FmgrInfo::fn_strict, FunctionCallInvoke, InitFunctionCallInfoData, Int32GetDatum(), InvalidOid, LOCAL_FCINFO, ObjectIdGetDatum(), and PointerGetDatum().

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

◆ record_C_func()

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

Definition at line 539 of file fmgr.c.

541 {
542  Oid fn_oid = ((Form_pg_proc) GETSTRUCT(procedureTuple))->oid;
543  CFuncHashTabEntry *entry;
544  bool found;
545 
546  /* Create the hash table if it doesn't exist yet */
547  if (CFuncHash == NULL)
548  {
549  HASHCTL hash_ctl;
550 
551  hash_ctl.keysize = sizeof(Oid);
552  hash_ctl.entrysize = sizeof(CFuncHashTabEntry);
553  CFuncHash = hash_create("CFuncHash",
554  100,
555  &hash_ctl,
557  }
558 
559  entry = (CFuncHashTabEntry *)
561  &fn_oid,
562  HASH_ENTER,
563  &found);
564  /* OID is already filled in */
565  entry->fn_xmin = HeapTupleHeaderGetRawXmin(procedureTuple->t_data);
566  entry->fn_tid = procedureTuple->t_self;
567  entry->user_fn = user_fn;
568  entry->inforec = inforec;
569 }
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:352
@ HASH_ENTER
Definition: hsearch.h:114
#define HASH_ELEM
Definition: hsearch.h:95
#define HASH_BLOBS
Definition: hsearch.h:97
Size keysize
Definition: hsearch.h:75
Size entrysize
Definition: hsearch.h:76

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

Referenced by fmgr_info_C_lang().

◆ SendFunctionCall()

bytea* SendFunctionCall ( FmgrInfo flinfo,
Datum  val 
)

◆ set_fn_opclass_options()

void set_fn_opclass_options ( FmgrInfo flinfo,
bytea options 
)

Definition at line 2070 of file fmgr.c.

2071 {
2072  flinfo->fn_expr = (Node *) makeConst(BYTEAOID, -1, InvalidOid, -1,
2074  options == NULL, false);
2075 }
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
Definition: makefuncs.c:301

References FmgrInfo::fn_expr, InvalidOid, makeConst(), and PointerGetDatum().

Referenced by gincost_pattern(), and index_getprocinfo().

Variable Documentation

◆ CFuncHash

HTAB* CFuncHash = NULL
static

Definition at line 55 of file fmgr.c.

Referenced by lookup_C_func(), and record_C_func().

◆ fmgr_hook

PGDLLIMPORT fmgr_hook_type fmgr_hook = NULL

Definition at line 40 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 39 of file fmgr.c.

Referenced by sepgsql_init_client_label().