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

1049 {
1050  LOCAL_FCINFO(fcinfo, 1);
1051  Datum result;
1052 
1053  InitFunctionCallInfoData(*fcinfo, flinfo, 1, collation, NULL, NULL);
1054 
1055  fcinfo->args[0].value = arg1;
1056  fcinfo->args[0].isnull = false;
1057 
1058  result = (*func) (fcinfo);
1059 
1060  /* Check for null result, since caller is clearly not expecting one */
1061  if (fcinfo->isnull)
1062  elog(ERROR, "function %p returned NULL", (void *) func);
1063 
1064  return result;
1065 }
#define ERROR
Definition: elog.h:39
#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 1068 of file fmgr.c.

1069 {
1070  LOCAL_FCINFO(fcinfo, 2);
1071  Datum result;
1072 
1073  InitFunctionCallInfoData(*fcinfo, flinfo, 2, collation, NULL, NULL);
1074 
1075  fcinfo->args[0].value = arg1;
1076  fcinfo->args[0].isnull = false;
1077  fcinfo->args[1].value = arg2;
1078  fcinfo->args[1].isnull = false;
1079 
1080  result = (*func) (fcinfo);
1081 
1082  /* Check for null result, since caller is clearly not expecting one */
1083  if (fcinfo->isnull)
1084  elog(ERROR, "function %p returned NULL", (void *) func);
1085 
1086  return result;
1087 }

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

2129 {
2130  HeapTuple procTup;
2131  HeapTuple langTup;
2132  Form_pg_proc procStruct;
2133  Form_pg_language langStruct;
2134  AclResult aclresult;
2135 
2136  /*
2137  * Get the function's pg_proc entry. Throw a user-facing error for bad
2138  * OID, because validators can be called with user-specified OIDs.
2139  */
2140  procTup = SearchSysCache1(PROCOID, ObjectIdGetDatum(functionOid));
2141  if (!HeapTupleIsValid(procTup))
2142  ereport(ERROR,
2143  (errcode(ERRCODE_UNDEFINED_FUNCTION),
2144  errmsg("function with OID %u does not exist", functionOid)));
2145  procStruct = (Form_pg_proc) GETSTRUCT(procTup);
2146 
2147  /*
2148  * Fetch pg_language entry to know if this is the correct validation
2149  * function for that pg_proc entry.
2150  */
2151  langTup = SearchSysCache1(LANGOID, ObjectIdGetDatum(procStruct->prolang));
2152  if (!HeapTupleIsValid(langTup))
2153  elog(ERROR, "cache lookup failed for language %u", procStruct->prolang);
2154  langStruct = (Form_pg_language) GETSTRUCT(langTup);
2155 
2156  if (langStruct->lanvalidator != validatorOid)
2157  ereport(ERROR,
2158  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2159  errmsg("language validation function %u called for language %u instead of %u",
2160  validatorOid, procStruct->prolang,
2161  langStruct->lanvalidator)));
2162 
2163  /* first validate that we have permissions to use the language */
2164  aclresult = object_aclcheck(LanguageRelationId, procStruct->prolang, GetUserId(),
2165  ACL_USAGE);
2166  if (aclresult != ACLCHECK_OK)
2167  aclcheck_error(aclresult, OBJECT_LANGUAGE,
2168  NameStr(langStruct->lanname));
2169 
2170  /*
2171  * Check whether we are allowed to execute the function itself. If we can
2172  * execute it, there should be no possible side-effect of
2173  * compiling/validation that execution can't have.
2174  */
2175  aclresult = object_aclcheck(ProcedureRelationId, functionOid, GetUserId(), ACL_EXECUTE);
2176  if (aclresult != ACLCHECK_OK)
2177  aclcheck_error(aclresult, OBJECT_FUNCTION, NameStr(procStruct->proname));
2178 
2179  ReleaseSysCache(procTup);
2180  ReleaseSysCache(langTup);
2181 
2182  return true;
2183 }
AclResult
Definition: acl.h:181
@ ACLCHECK_OK
Definition: acl.h:182
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:2695
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
Definition: aclchk.c:3843
#define NameStr(name)
Definition: c.h:735
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#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:508
#define ACL_USAGE
Definition: parsenodes.h:84
@ OBJECT_LANGUAGE
Definition: parsenodes.h:2117
@ OBJECT_FUNCTION
Definition: parsenodes.h:2115
#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:868
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:820
@ PROCOID
Definition: syscache.h:79
@ LANGOID
Definition: syscache.h:68

References ACL_EXECUTE, ACL_USAGE, aclcheck_error(), ACLCHECK_OK, elog(), ereport, errcode(), errmsg(), ERROR, GETSTRUCT, GetUserId(), HeapTupleIsValid, LANGOID, NameStr, object_aclcheck(), OBJECT_FUNCTION, OBJECT_LANGUAGE, ObjectIdGetDatum(), PROCOID, 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 775 of file fmgr.c.

776 {
777  LOCAL_FCINFO(fcinfo, 1);
778  Datum result;
779 
780  InitFunctionCallInfoData(*fcinfo, NULL, 1, collation, NULL, NULL);
781 
782  fcinfo->args[0].value = arg1;
783  fcinfo->args[0].isnull = false;
784 
785  result = (*func) (fcinfo);
786 
787  /* Check for null result, since caller is clearly not expecting one */
788  if (fcinfo->isnull)
789  elog(ERROR, "function %p returned NULL", (void *) func);
790 
791  return result;
792 }

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

796 {
797  LOCAL_FCINFO(fcinfo, 2);
798  Datum result;
799 
800  InitFunctionCallInfoData(*fcinfo, NULL, 2, collation, NULL, NULL);
801 
802  fcinfo->args[0].value = arg1;
803  fcinfo->args[0].isnull = false;
804  fcinfo->args[1].value = arg2;
805  fcinfo->args[1].isnull = false;
806 
807  result = (*func) (fcinfo);
808 
809  /* Check for null result, since caller is clearly not expecting one */
810  if (fcinfo->isnull)
811  elog(ERROR, "function %p returned NULL", (void *) func);
812 
813  return result;
814 }

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

819 {
820  LOCAL_FCINFO(fcinfo, 3);
821  Datum result;
822 
823  InitFunctionCallInfoData(*fcinfo, NULL, 3, collation, NULL, NULL);
824 
825  fcinfo->args[0].value = arg1;
826  fcinfo->args[0].isnull = false;
827  fcinfo->args[1].value = arg2;
828  fcinfo->args[1].isnull = false;
829  fcinfo->args[2].value = arg3;
830  fcinfo->args[2].isnull = false;
831 
832  result = (*func) (fcinfo);
833 
834  /* Check for null result, since caller is clearly not expecting one */
835  if (fcinfo->isnull)
836  elog(ERROR, "function %p returned NULL", (void *) func);
837 
838  return result;
839 }

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

844 {
845  LOCAL_FCINFO(fcinfo, 4);
846  Datum result;
847 
848  InitFunctionCallInfoData(*fcinfo, NULL, 4, collation, NULL, NULL);
849 
850  fcinfo->args[0].value = arg1;
851  fcinfo->args[0].isnull = false;
852  fcinfo->args[1].value = arg2;
853  fcinfo->args[1].isnull = false;
854  fcinfo->args[2].value = arg3;
855  fcinfo->args[2].isnull = false;
856  fcinfo->args[3].value = arg4;
857  fcinfo->args[3].isnull = false;
858 
859  result = (*func) (fcinfo);
860 
861  /* Check for null result, since caller is clearly not expecting one */
862  if (fcinfo->isnull)
863  elog(ERROR, "function %p returned NULL", (void *) func);
864 
865  return result;
866 }

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

871 {
872  LOCAL_FCINFO(fcinfo, 5);
873  Datum result;
874 
875  InitFunctionCallInfoData(*fcinfo, NULL, 5, collation, NULL, NULL);
876 
877  fcinfo->args[0].value = arg1;
878  fcinfo->args[0].isnull = false;
879  fcinfo->args[1].value = arg2;
880  fcinfo->args[1].isnull = false;
881  fcinfo->args[2].value = arg3;
882  fcinfo->args[2].isnull = false;
883  fcinfo->args[3].value = arg4;
884  fcinfo->args[3].isnull = false;
885  fcinfo->args[4].value = arg5;
886  fcinfo->args[4].isnull = false;
887 
888  result = (*func) (fcinfo);
889 
890  /* Check for null result, since caller is clearly not expecting one */
891  if (fcinfo->isnull)
892  elog(ERROR, "function %p returned NULL", (void *) func);
893 
894  return result;
895 }

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

901 {
902  LOCAL_FCINFO(fcinfo, 6);
903  Datum result;
904 
905  InitFunctionCallInfoData(*fcinfo, NULL, 6, collation, NULL, NULL);
906 
907  fcinfo->args[0].value = arg1;
908  fcinfo->args[0].isnull = false;
909  fcinfo->args[1].value = arg2;
910  fcinfo->args[1].isnull = false;
911  fcinfo->args[2].value = arg3;
912  fcinfo->args[2].isnull = false;
913  fcinfo->args[3].value = arg4;
914  fcinfo->args[3].isnull = false;
915  fcinfo->args[4].value = arg5;
916  fcinfo->args[4].isnull = false;
917  fcinfo->args[5].value = arg6;
918  fcinfo->args[5].isnull = false;
919 
920  result = (*func) (fcinfo);
921 
922  /* Check for null result, since caller is clearly not expecting one */
923  if (fcinfo->isnull)
924  elog(ERROR, "function %p returned NULL", (void *) func);
925 
926  return result;
927 }

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

933 {
934  LOCAL_FCINFO(fcinfo, 7);
935  Datum result;
936 
937  InitFunctionCallInfoData(*fcinfo, NULL, 7, collation, NULL, NULL);
938 
939  fcinfo->args[0].value = arg1;
940  fcinfo->args[0].isnull = false;
941  fcinfo->args[1].value = arg2;
942  fcinfo->args[1].isnull = false;
943  fcinfo->args[2].value = arg3;
944  fcinfo->args[2].isnull = false;
945  fcinfo->args[3].value = arg4;
946  fcinfo->args[3].isnull = false;
947  fcinfo->args[4].value = arg5;
948  fcinfo->args[4].isnull = false;
949  fcinfo->args[5].value = arg6;
950  fcinfo->args[5].isnull = false;
951  fcinfo->args[6].value = arg7;
952  fcinfo->args[6].isnull = false;
953 
954  result = (*func) (fcinfo);
955 
956  /* Check for null result, since caller is clearly not expecting one */
957  if (fcinfo->isnull)
958  elog(ERROR, "function %p returned NULL", (void *) func);
959 
960  return result;
961 }

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

967 {
968  LOCAL_FCINFO(fcinfo, 8);
969  Datum result;
970 
971  InitFunctionCallInfoData(*fcinfo, NULL, 8, collation, NULL, NULL);
972 
973  fcinfo->args[0].value = arg1;
974  fcinfo->args[0].isnull = false;
975  fcinfo->args[1].value = arg2;
976  fcinfo->args[1].isnull = false;
977  fcinfo->args[2].value = arg3;
978  fcinfo->args[2].isnull = false;
979  fcinfo->args[3].value = arg4;
980  fcinfo->args[3].isnull = false;
981  fcinfo->args[4].value = arg5;
982  fcinfo->args[4].isnull = false;
983  fcinfo->args[5].value = arg6;
984  fcinfo->args[5].isnull = false;
985  fcinfo->args[6].value = arg7;
986  fcinfo->args[6].isnull = false;
987  fcinfo->args[7].value = arg8;
988  fcinfo->args[7].isnull = false;
989 
990  result = (*func) (fcinfo);
991 
992  /* Check for null result, since caller is clearly not expecting one */
993  if (fcinfo->isnull)
994  elog(ERROR, "function %p returned NULL", (void *) func);
995 
996  return result;
997 }

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

1004 {
1005  LOCAL_FCINFO(fcinfo, 9);
1006  Datum result;
1007 
1008  InitFunctionCallInfoData(*fcinfo, NULL, 9, collation, NULL, NULL);
1009 
1010  fcinfo->args[0].value = arg1;
1011  fcinfo->args[0].isnull = false;
1012  fcinfo->args[1].value = arg2;
1013  fcinfo->args[1].isnull = false;
1014  fcinfo->args[2].value = arg3;
1015  fcinfo->args[2].isnull = false;
1016  fcinfo->args[3].value = arg4;
1017  fcinfo->args[3].isnull = false;
1018  fcinfo->args[4].value = arg5;
1019  fcinfo->args[4].isnull = false;
1020  fcinfo->args[5].value = arg6;
1021  fcinfo->args[5].isnull = false;
1022  fcinfo->args[6].value = arg7;
1023  fcinfo->args[6].isnull = false;
1024  fcinfo->args[7].value = arg8;
1025  fcinfo->args[7].isnull = false;
1026  fcinfo->args[8].value = arg9;
1027  fcinfo->args[8].isnull = false;
1028 
1029  result = (*func) (fcinfo);
1030 
1031  /* Check for null result, since caller is clearly not expecting one */
1032  if (fcinfo->isnull)
1033  elog(ERROR, "function %p returned NULL", (void *) func);
1034 
1035  return result;
1036 }

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

1627 {
1628  LOCAL_FCINFO(fcinfo, 3);
1629 
1630  if (str == NULL)
1631  {
1632  *result = (Datum) 0; /* just return null result */
1633  return true;
1634  }
1635 
1636  InitFunctionCallInfoData(*fcinfo, NULL, 3, InvalidOid, escontext, NULL);
1637 
1638  fcinfo->args[0].value = CStringGetDatum(str);
1639  fcinfo->args[0].isnull = false;
1640  fcinfo->args[1].value = ObjectIdGetDatum(typioparam);
1641  fcinfo->args[1].isnull = false;
1642  fcinfo->args[2].value = Int32GetDatum(typmod);
1643  fcinfo->args[2].isnull = false;
1644 
1645  *result = (*func) (fcinfo);
1646 
1647  /* Result value is garbage, and could be null, if an error was reported */
1648  if (SOFT_ERROR_OCCURRED(escontext))
1649  return false;
1650 
1651  /* Otherwise, shouldn't get null result */
1652  if (fcinfo->isnull)
1653  elog(ERROR, "input function %p returned NULL", (void *) func);
1654 
1655  return true;
1656 }
#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 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:1316
const Pg_finfo_record *(* PGFInfoFunction)(void)
Definition: fmgr.h:401
#define funcname
Definition: indent_codes.h:69
void pfree(void *pointer)
Definition: mcxt.c:1456
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:135

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:95
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:1112

References Pg_finfo_record::api_version, elog(), ERROR, fetch_finfo_record(), FmgrInfo::fn_addr, CFuncHashTabEntry::inforec, load_external_function(), lookup_C_func(), pfree(), PROCOID, record_C_func(), 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:631
#define FmgrHookIsNeeded(fn_oid)
Definition: fmgr.h:797
Datum fmgr_sql(PG_FUNCTION_ARGS)
Definition: functions.c:1027
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
Definition: heaptuple.c:456
@ 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(), PROCOID, 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, LANGOID, 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:494
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 631 of file fmgr.c.

632 {
633  Datum result;
634  struct fmgr_security_definer_cache *volatile fcache;
635  FmgrInfo *save_flinfo;
636  Oid save_userid;
637  int save_sec_context;
638  ListCell *lc1;
639  ListCell *lc2;
640  volatile int save_nestlevel;
641  PgStat_FunctionCallUsage fcusage;
642 
643  if (!fcinfo->flinfo->fn_extra)
644  {
645  HeapTuple tuple;
646  Form_pg_proc procedureStruct;
647  Datum datum;
648  bool isnull;
649  MemoryContext oldcxt;
650 
651  fcache = MemoryContextAllocZero(fcinfo->flinfo->fn_mcxt,
652  sizeof(*fcache));
653 
654  fmgr_info_cxt_security(fcinfo->flinfo->fn_oid, &fcache->flinfo,
655  fcinfo->flinfo->fn_mcxt, true);
656  fcache->flinfo.fn_expr = fcinfo->flinfo->fn_expr;
657 
658  tuple = SearchSysCache1(PROCOID,
659  ObjectIdGetDatum(fcinfo->flinfo->fn_oid));
660  if (!HeapTupleIsValid(tuple))
661  elog(ERROR, "cache lookup failed for function %u",
662  fcinfo->flinfo->fn_oid);
663  procedureStruct = (Form_pg_proc) GETSTRUCT(tuple);
664 
665  if (procedureStruct->prosecdef)
666  fcache->userid = procedureStruct->proowner;
667 
668  datum = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_proconfig,
669  &isnull);
670  if (!isnull)
671  {
672  ArrayType *array;
673 
674  oldcxt = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
675  array = DatumGetArrayTypeP(datum);
676  TransformGUCArray(array, &fcache->configNames,
677  &fcache->configValues);
678  MemoryContextSwitchTo(oldcxt);
679  }
680 
681  ReleaseSysCache(tuple);
682 
683  fcinfo->flinfo->fn_extra = fcache;
684  }
685  else
686  fcache = fcinfo->flinfo->fn_extra;
687 
688  /* GetUserIdAndSecContext is cheap enough that no harm in a wasted call */
689  GetUserIdAndSecContext(&save_userid, &save_sec_context);
690  if (fcache->configNames != NIL) /* Need a new GUC nesting level */
691  save_nestlevel = NewGUCNestLevel();
692  else
693  save_nestlevel = 0; /* keep compiler quiet */
694 
695  if (OidIsValid(fcache->userid))
697  save_sec_context | SECURITY_LOCAL_USERID_CHANGE);
698 
699  forboth(lc1, fcache->configNames, lc2, fcache->configValues)
700  {
701  GucContext context = superuser() ? PGC_SUSET : PGC_USERSET;
704  char *name = lfirst(lc1);
705  char *value = lfirst(lc2);
706 
707  (void) set_config_option(name, value,
708  context, source,
709  action, true, 0, false);
710  }
711 
712  /* function manager hook */
713  if (fmgr_hook)
714  (*fmgr_hook) (FHET_START, &fcache->flinfo, &fcache->arg);
715 
716  /*
717  * We don't need to restore GUC or userid settings on error, because the
718  * ensuing xact or subxact abort will do that. The PG_TRY block is only
719  * needed to clean up the flinfo link.
720  */
721  save_flinfo = fcinfo->flinfo;
722 
723  PG_TRY();
724  {
725  fcinfo->flinfo = &fcache->flinfo;
726 
727  /* See notes in fmgr_info_cxt_security */
728  pgstat_init_function_usage(fcinfo, &fcusage);
729 
730  result = FunctionCallInvoke(fcinfo);
731 
732  /*
733  * We could be calling either a regular or a set-returning function,
734  * so we have to test to see what finalize flag to use.
735  */
736  pgstat_end_function_usage(&fcusage,
737  (fcinfo->resultinfo == NULL ||
738  !IsA(fcinfo->resultinfo, ReturnSetInfo) ||
739  ((ReturnSetInfo *) fcinfo->resultinfo)->isDone != ExprMultipleResult));
740  }
741  PG_CATCH();
742  {
743  fcinfo->flinfo = save_flinfo;
744  if (fmgr_hook)
745  (*fmgr_hook) (FHET_ABORT, &fcache->flinfo, &fcache->arg);
746  PG_RE_THROW();
747  }
748  PG_END_TRY();
749 
750  fcinfo->flinfo = save_flinfo;
751 
752  if (fcache->configNames != NIL)
753  AtEOXact_GUC(true, save_nestlevel);
754  if (OidIsValid(fcache->userid))
755  SetUserIdAndSecContext(save_userid, save_sec_context);
756  if (fmgr_hook)
757  (*fmgr_hook) (FHET_END, &fcache->flinfo, &fcache->arg);
758 
759  return result;
760 }
#define DatumGetArrayTypeP(X)
Definition: array.h:261
#define OidIsValid(objectId)
Definition: c.h:764
#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:297
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:2231
void TransformGUCArray(ArrayType *array, List **names, List **values)
Definition: guc.c:6274
void AtEOXact_GUC(bool isCommit, int nestLevel)
Definition: guc.c:2245
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
Definition: guc.c:3314
GucAction
Definition: guc.h:195
@ GUC_ACTION_SAVE
Definition: guc.h:199
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 @148 value
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:1064
#define SECURITY_LOCAL_USERID_CHANGE
Definition: miscadmin.h:315
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
Definition: miscinit.c:629
void SetUserIdAndSecContext(Oid userid, int sec_context)
Definition: miscinit.c:636
#define IsA(nodeptr, _type_)
Definition: nodes.h:179
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:138
#define lfirst(lc)
Definition: pg_list.h:172
#define NIL
Definition: pg_list.h:68
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:467
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:1081

References generate_unaccent_rules::action, fmgr_security_definer_cache::arg, AtEOXact_GUC(), 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, forboth, FunctionCallInvoke, GETSTRUCT, GetUserIdAndSecContext(), GUC_ACTION_SAVE, HeapTupleIsValid, IsA, 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(), PROCOID, ReleaseSysCache(), SearchSysCache1(), SECURITY_LOCAL_USERID_CHANGE, set_config_option(), 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:1644
static void * fn(void *arg)
Definition: thread-alloc.c:119

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

Referenced by llvm_function_reference().

◆ FunctionCall0Coll()

Datum FunctionCall0Coll ( FmgrInfo flinfo,
Oid  collation 
)

Definition at line 1095 of file fmgr.c.

1096 {
1097  LOCAL_FCINFO(fcinfo, 0);
1098  Datum result;
1099 
1100  InitFunctionCallInfoData(*fcinfo, flinfo, 0, collation, NULL, NULL);
1101 
1102  result = FunctionCallInvoke(fcinfo);
1103 
1104  /* Check for null result, since caller is clearly not expecting one */
1105  if (fcinfo->isnull)
1106  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1107 
1108  return result;
1109 }

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

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

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

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

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

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

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

1181 {
1182  LOCAL_FCINFO(fcinfo, 4);
1183  Datum result;
1184 
1185  InitFunctionCallInfoData(*fcinfo, flinfo, 4, collation, NULL, NULL);
1186 
1187  fcinfo->args[0].value = arg1;
1188  fcinfo->args[0].isnull = false;
1189  fcinfo->args[1].value = arg2;
1190  fcinfo->args[1].isnull = false;
1191  fcinfo->args[2].value = arg3;
1192  fcinfo->args[2].isnull = false;
1193  fcinfo->args[3].value = arg4;
1194  fcinfo->args[3].isnull = false;
1195 
1196  result = FunctionCallInvoke(fcinfo);
1197 
1198  /* Check for null result, since caller is clearly not expecting one */
1199  if (fcinfo->isnull)
1200  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1201 
1202  return result;
1203 }

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

1208 {
1209  LOCAL_FCINFO(fcinfo, 5);
1210  Datum result;
1211 
1212  InitFunctionCallInfoData(*fcinfo, flinfo, 5, collation, NULL, NULL);
1213 
1214  fcinfo->args[0].value = arg1;
1215  fcinfo->args[0].isnull = false;
1216  fcinfo->args[1].value = arg2;
1217  fcinfo->args[1].isnull = false;
1218  fcinfo->args[2].value = arg3;
1219  fcinfo->args[2].isnull = false;
1220  fcinfo->args[3].value = arg4;
1221  fcinfo->args[3].isnull = false;
1222  fcinfo->args[4].value = arg5;
1223  fcinfo->args[4].isnull = false;
1224 
1225  result = FunctionCallInvoke(fcinfo);
1226 
1227  /* Check for null result, since caller is clearly not expecting one */
1228  if (fcinfo->isnull)
1229  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1230 
1231  return result;
1232 }

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

1238 {
1239  LOCAL_FCINFO(fcinfo, 6);
1240  Datum result;
1241 
1242  InitFunctionCallInfoData(*fcinfo, flinfo, 6, collation, NULL, NULL);
1243 
1244  fcinfo->args[0].value = arg1;
1245  fcinfo->args[0].isnull = false;
1246  fcinfo->args[1].value = arg2;
1247  fcinfo->args[1].isnull = false;
1248  fcinfo->args[2].value = arg3;
1249  fcinfo->args[2].isnull = false;
1250  fcinfo->args[3].value = arg4;
1251  fcinfo->args[3].isnull = false;
1252  fcinfo->args[4].value = arg5;
1253  fcinfo->args[4].isnull = false;
1254  fcinfo->args[5].value = arg6;
1255  fcinfo->args[5].isnull = false;
1256 
1257  result = FunctionCallInvoke(fcinfo);
1258 
1259  /* Check for null result, since caller is clearly not expecting one */
1260  if (fcinfo->isnull)
1261  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1262 
1263  return result;
1264 }

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

1270 {
1271  LOCAL_FCINFO(fcinfo, 7);
1272  Datum result;
1273 
1274  InitFunctionCallInfoData(*fcinfo, flinfo, 7, collation, NULL, NULL);
1275 
1276  fcinfo->args[0].value = arg1;
1277  fcinfo->args[0].isnull = false;
1278  fcinfo->args[1].value = arg2;
1279  fcinfo->args[1].isnull = false;
1280  fcinfo->args[2].value = arg3;
1281  fcinfo->args[2].isnull = false;
1282  fcinfo->args[3].value = arg4;
1283  fcinfo->args[3].isnull = false;
1284  fcinfo->args[4].value = arg5;
1285  fcinfo->args[4].isnull = false;
1286  fcinfo->args[5].value = arg6;
1287  fcinfo->args[5].isnull = false;
1288  fcinfo->args[6].value = arg7;
1289  fcinfo->args[6].isnull = false;
1290 
1291  result = FunctionCallInvoke(fcinfo);
1292 
1293  /* Check for null result, since caller is clearly not expecting one */
1294  if (fcinfo->isnull)
1295  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1296 
1297  return result;
1298 }

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

1304 {
1305  LOCAL_FCINFO(fcinfo, 8);
1306  Datum result;
1307 
1308  InitFunctionCallInfoData(*fcinfo, flinfo, 8, collation, NULL, NULL);
1309 
1310  fcinfo->args[0].value = arg1;
1311  fcinfo->args[0].isnull = false;
1312  fcinfo->args[1].value = arg2;
1313  fcinfo->args[1].isnull = false;
1314  fcinfo->args[2].value = arg3;
1315  fcinfo->args[2].isnull = false;
1316  fcinfo->args[3].value = arg4;
1317  fcinfo->args[3].isnull = false;
1318  fcinfo->args[4].value = arg5;
1319  fcinfo->args[4].isnull = false;
1320  fcinfo->args[5].value = arg6;
1321  fcinfo->args[5].isnull = false;
1322  fcinfo->args[6].value = arg7;
1323  fcinfo->args[6].isnull = false;
1324  fcinfo->args[7].value = arg8;
1325  fcinfo->args[7].isnull = false;
1326 
1327  result = FunctionCallInvoke(fcinfo);
1328 
1329  /* Check for null result, since caller is clearly not expecting one */
1330  if (fcinfo->isnull)
1331  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1332 
1333  return result;
1334 }

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

1341 {
1342  LOCAL_FCINFO(fcinfo, 9);
1343  Datum result;
1344 
1345  InitFunctionCallInfoData(*fcinfo, flinfo, 9, collation, NULL, NULL);
1346 
1347  fcinfo->args[0].value = arg1;
1348  fcinfo->args[0].isnull = false;
1349  fcinfo->args[1].value = arg2;
1350  fcinfo->args[1].isnull = false;
1351  fcinfo->args[2].value = arg3;
1352  fcinfo->args[2].isnull = false;
1353  fcinfo->args[3].value = arg4;
1354  fcinfo->args[3].isnull = false;
1355  fcinfo->args[4].value = arg5;
1356  fcinfo->args[4].isnull = false;
1357  fcinfo->args[5].value = arg6;
1358  fcinfo->args[5].isnull = false;
1359  fcinfo->args[6].value = arg7;
1360  fcinfo->args[6].isnull = false;
1361  fcinfo->args[7].value = arg8;
1362  fcinfo->args[7].isnull = false;
1363  fcinfo->args[8].value = arg9;
1364  fcinfo->args[8].isnull = false;
1365 
1366  result = FunctionCallInvoke(fcinfo);
1367 
1368  /* Check for null result, since caller is clearly not expecting one */
1369  if (fcinfo->isnull)
1370  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1371 
1372  return result;
1373 }

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

1978 {
1979  List *args;
1980  Node *arg;
1981 
1982  if (expr == NULL)
1983  return false;
1984 
1985  if (IsA(expr, FuncExpr))
1986  args = ((FuncExpr *) expr)->args;
1987  else if (IsA(expr, OpExpr))
1988  args = ((OpExpr *) expr)->args;
1989  else if (IsA(expr, DistinctExpr))
1990  args = ((DistinctExpr *) expr)->args;
1991  else if (IsA(expr, ScalarArrayOpExpr))
1992  args = ((ScalarArrayOpExpr *) expr)->args;
1993  else if (IsA(expr, NullIfExpr))
1994  args = ((NullIfExpr *) expr)->args;
1995  else if (IsA(expr, WindowFunc))
1996  args = ((WindowFunc *) expr)->args;
1997  else
1998  return false;
1999 
2000  if (argnum < 0 || argnum >= list_length(args))
2001  return false;
2002 
2003  arg = (Node *) list_nth(args, argnum);
2004 
2005  /*
2006  * Either a true Const or an external Param will have a value that doesn't
2007  * change during the execution of the query. In future we might want to
2008  * consider other cases too, e.g. now().
2009  */
2010  if (IsA(arg, Const))
2011  return true;
2012  if (IsA(arg, Param) &&
2013  ((Param *) arg)->paramkind == PARAM_EXTERN)
2014  return true;
2015 
2016  return false;
2017 }
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 1912 of file fmgr.c.

1913 {
1914  List *args;
1915  Oid argtype;
1916 
1917  if (expr == NULL)
1918  return InvalidOid;
1919 
1920  if (IsA(expr, FuncExpr))
1921  args = ((FuncExpr *) expr)->args;
1922  else if (IsA(expr, OpExpr))
1923  args = ((OpExpr *) expr)->args;
1924  else if (IsA(expr, DistinctExpr))
1925  args = ((DistinctExpr *) expr)->args;
1926  else if (IsA(expr, ScalarArrayOpExpr))
1927  args = ((ScalarArrayOpExpr *) expr)->args;
1928  else if (IsA(expr, NullIfExpr))
1929  args = ((NullIfExpr *) expr)->args;
1930  else if (IsA(expr, WindowFunc))
1931  args = ((WindowFunc *) expr)->args;
1932  else
1933  return InvalidOid;
1934 
1935  if (argnum < 0 || argnum >= list_length(args))
1936  return InvalidOid;
1937 
1938  argtype = exprType((Node *) list_nth(args, argnum));
1939 
1940  /*
1941  * special hack for ScalarArrayOpExpr: what the underlying function will
1942  * actually get passed is the element type of the array.
1943  */
1944  if (IsA(expr, ScalarArrayOpExpr) &&
1945  argnum == 1)
1946  argtype = get_base_element_type(argtype);
1947 
1948  return argtype;
1949 }
Oid get_base_element_type(Oid typid)
Definition: lsyscache.c:2814
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:43

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

1959 {
1960  /*
1961  * can't return anything useful if we have no FmgrInfo or if its fn_expr
1962  * node has not been initialized
1963  */
1964  if (!flinfo || !flinfo->fn_expr)
1965  return false;
1966 
1967  return get_call_expr_arg_stable(flinfo->fn_expr, argnum);
1968 }
bool get_call_expr_arg_stable(Node *expr, int argnum)
Definition: fmgr.c:1977

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

1872 {
1873  Node *expr;
1874 
1875  /*
1876  * can't return anything useful if we have no FmgrInfo or if its fn_expr
1877  * node has not been initialized
1878  */
1879  if (!flinfo || !flinfo->fn_expr)
1880  return InvalidOid;
1881 
1882  expr = flinfo->fn_expr;
1883 
1884  return exprType(expr);
1885 }

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

2028 {
2029  Node *expr;
2030 
2031  /*
2032  * can't return anything useful if we have no FmgrInfo or if its fn_expr
2033  * node has not been initialized
2034  */
2035  if (!flinfo || !flinfo->fn_expr)
2036  return false;
2037 
2038  expr = flinfo->fn_expr;
2039 
2040  if (IsA(expr, FuncExpr))
2041  return ((FuncExpr *) expr)->funcvariadic;
2042  else
2043  return false;
2044 }

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

2081 {
2082  if (flinfo && flinfo->fn_expr && IsA(flinfo->fn_expr, Const))
2083  {
2084  Const *expr = (Const *) flinfo->fn_expr;
2085 
2086  if (expr->consttype == BYTEAOID)
2087  return expr->constisnull ? NULL : DatumGetByteaP(expr->constvalue);
2088  }
2089 
2090  ereport(ERROR,
2091  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2092  errmsg("operator class options info is absent in function call context")));
2093 
2094  return NULL;
2095 }
#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 2064 of file fmgr.c.

2065 {
2066  if (flinfo && flinfo->fn_expr && IsA(flinfo->fn_expr, Const))
2067  {
2068  Const *expr = (Const *) flinfo->fn_expr;
2069 
2070  if (expr->consttype == BYTEAOID)
2071  return !expr->constisnull;
2072  }
2073  return false;
2074 }

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

◆ InputFunctionCall()

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

Definition at line 1513 of file fmgr.c.

1514 {
1515  LOCAL_FCINFO(fcinfo, 3);
1516  Datum result;
1517 
1518  if (str == NULL && flinfo->fn_strict)
1519  return (Datum) 0; /* just return null result */
1520 
1521  InitFunctionCallInfoData(*fcinfo, flinfo, 3, InvalidOid, NULL, NULL);
1522 
1523  fcinfo->args[0].value = CStringGetDatum(str);
1524  fcinfo->args[0].isnull = false;
1525  fcinfo->args[1].value = ObjectIdGetDatum(typioparam);
1526  fcinfo->args[1].isnull = false;
1527  fcinfo->args[2].value = Int32GetDatum(typmod);
1528  fcinfo->args[2].isnull = false;
1529 
1530  result = FunctionCallInvoke(fcinfo);
1531 
1532  /* Should get null result if and only if str is NULL */
1533  if (str == NULL)
1534  {
1535  if (!fcinfo->isnull)
1536  elog(ERROR, "input function %u returned non-NULL",
1537  flinfo->fn_oid);
1538  }
1539  else
1540  {
1541  if (fcinfo->isnull)
1542  elog(ERROR, "input function %u returned NULL",
1543  flinfo->fn_oid);
1544  }
1545 
1546  return result;
1547 }

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(), NextCopyFrom(), OidInputFunctionCall(), plperl_sv_to_datum(), plsample_func_handler(), pltcl_func_handler(), pltcl_returnnext(), pltcl_SPI_execute_plan(), PLyObject_ToScalar(), PLyUnicode_ToComposite(), populate_scalar(), and XmlTableGetValue().

◆ InputFunctionCallSafe()

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

Definition at line 1568 of file fmgr.c.

1572 {
1573  LOCAL_FCINFO(fcinfo, 3);
1574 
1575  if (str == NULL && flinfo->fn_strict)
1576  {
1577  *result = (Datum) 0; /* just return null result */
1578  return true;
1579  }
1580 
1581  InitFunctionCallInfoData(*fcinfo, flinfo, 3, InvalidOid, escontext, NULL);
1582 
1583  fcinfo->args[0].value = CStringGetDatum(str);
1584  fcinfo->args[0].isnull = false;
1585  fcinfo->args[1].value = ObjectIdGetDatum(typioparam);
1586  fcinfo->args[1].isnull = false;
1587  fcinfo->args[2].value = Int32GetDatum(typmod);
1588  fcinfo->args[2].isnull = false;
1589 
1590  *result = FunctionCallInvoke(fcinfo);
1591 
1592  /* Result value is garbage, and could be null, if an error was reported */
1593  if (SOFT_ERROR_OCCURRED(escontext))
1594  return false;
1595 
1596  /* Otherwise, should get null result if and only if str is NULL */
1597  if (str == NULL)
1598  {
1599  if (!fcinfo->isnull)
1600  elog(ERROR, "input function %u returned non-NULL",
1601  flinfo->fn_oid);
1602  }
1603  else
1604  {
1605  if (fcinfo->isnull)
1606  elog(ERROR, "input function %u returned NULL",
1607  flinfo->fn_oid);
1608  }
1609 
1610  return true;
1611 }

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(), pg_input_is_valid_common(), range_in(), ReadArrayStr(), and record_in().

◆ Int64GetDatum()

Datum Int64GetDatum ( int64  X)

Definition at line 1790 of file fmgr.c.

1791 {
1792  int64 *retval = (int64 *) palloc(sizeof(int64));
1793 
1794  *retval = X;
1795  return PointerGetDatum(retval);
1796 }

References palloc(), and PointerGetDatum().

Referenced by brin_metapage_info(), brin_page_items(), brin_summarize_new_values(), build_minmax_path(), CashGetDatum(), create_final_distinct_paths(), DefineSequence(), delay_execution_planner(), ExecEvalNextValueExpr(), 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_buffercache_pages(), pg_control_system(), pg_get_replication_slots(), pg_get_shmem_allocations(), 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(), 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:953
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 1384 of file fmgr.c.

1385 {
1386  FmgrInfo flinfo;
1387 
1388  fmgr_info(functionId, &flinfo);
1389 
1390  return FunctionCall0Coll(&flinfo, collation);
1391 }
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:127
Datum FunctionCall0Coll(FmgrInfo *flinfo, Oid collation)
Definition: fmgr.c:1095

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

◆ OidFunctionCall1Coll()

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

Definition at line 1394 of file fmgr.c.

1395 {
1396  FmgrInfo flinfo;
1397 
1398  fmgr_info(functionId, &flinfo);
1399 
1400  return FunctionCall1Coll(&flinfo, collation, arg1);
1401 }
Datum FunctionCall1Coll(FmgrInfo *flinfo, Oid collation, Datum arg1)
Definition: fmgr.c:1112

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

Referenced by _bt_allequalimage(), and _hash_datum2hashkey_type().

◆ OidFunctionCall2Coll()

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

Definition at line 1404 of file fmgr.c.

1405 {
1406  FmgrInfo flinfo;
1407 
1408  fmgr_info(functionId, &flinfo);
1409 
1410  return FunctionCall2Coll(&flinfo, collation, arg1, arg2);
1411 }
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:1132

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

1416 {
1417  FmgrInfo flinfo;
1418 
1419  fmgr_info(functionId, &flinfo);
1420 
1421  return FunctionCall3Coll(&flinfo, collation, arg1, arg2, arg3);
1422 }
Datum FunctionCall3Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3)
Definition: fmgr.c:1154

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

1427 {
1428  FmgrInfo flinfo;
1429 
1430  fmgr_info(functionId, &flinfo);
1431 
1432  return FunctionCall4Coll(&flinfo, collation, arg1, arg2, arg3, arg4);
1433 }
Datum FunctionCall4Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4)
Definition: fmgr.c:1179

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

1438 {
1439  FmgrInfo flinfo;
1440 
1441  fmgr_info(functionId, &flinfo);
1442 
1443  return FunctionCall5Coll(&flinfo, collation, arg1, arg2, arg3, arg4, arg5);
1444 }
Datum FunctionCall5Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5)
Definition: fmgr.c:1206

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

1450 {
1451  FmgrInfo flinfo;
1452 
1453  fmgr_info(functionId, &flinfo);
1454 
1455  return FunctionCall6Coll(&flinfo, collation, arg1, arg2, arg3, arg4, arg5,
1456  arg6);
1457 }
Datum FunctionCall6Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6)
Definition: fmgr.c:1235

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

1463 {
1464  FmgrInfo flinfo;
1465 
1466  fmgr_info(functionId, &flinfo);
1467 
1468  return FunctionCall7Coll(&flinfo, collation, arg1, arg2, arg3, arg4, arg5,
1469  arg6, arg7);
1470 }
Datum FunctionCall7Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7)
Definition: fmgr.c:1267

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

1476 {
1477  FmgrInfo flinfo;
1478 
1479  fmgr_info(functionId, &flinfo);
1480 
1481  return FunctionCall8Coll(&flinfo, collation, arg1, arg2, arg3, arg4, arg5,
1482  arg6, arg7, arg8);
1483 }
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:1301

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

1490 {
1491  FmgrInfo flinfo;
1492 
1493  fmgr_info(functionId, &flinfo);
1494 
1495  return FunctionCall9Coll(&flinfo, collation, arg1, arg2, arg3, arg4, arg5,
1496  arg6, arg7, arg8, arg9);
1497 }
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:1337

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

◆ OidInputFunctionCall()

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

Definition at line 1737 of file fmgr.c.

1738 {
1739  FmgrInfo flinfo;
1740 
1741  fmgr_info(functionId, &flinfo);
1742  return InputFunctionCall(&flinfo, str, typioparam, typmod);
1743 }
Datum InputFunctionCall(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
Definition: fmgr.c:1513

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

1757 {
1758  FmgrInfo flinfo;
1759 
1760  fmgr_info(functionId, &flinfo);
1761  return ReceiveFunctionCall(&flinfo, buf, typioparam, typmod);
1762 }
Datum ReceiveFunctionCall(FmgrInfo *flinfo, StringInfo buf, Oid typioparam, int32 typmod)
Definition: fmgr.c:1680
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 1765 of file fmgr.c.

1766 {
1767  FmgrInfo flinfo;
1768 
1769  fmgr_info(functionId, &flinfo);
1770  return SendFunctionCall(&flinfo, val);
1771 }
bytea * SendFunctionCall(FmgrInfo *flinfo, Datum val)
Definition: fmgr.c:1727

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

1816 {
1817  if (VARATT_IS_EXTENDED(datum))
1818  return detoast_attr(datum);
1819  else
1820  return datum;
1821 }
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 1824 of file fmgr.c.

1825 {
1826  if (VARATT_IS_EXTENDED(datum))
1827  return detoast_attr(datum);
1828  else
1829  {
1830  /* Make a modifiable copy of the varlena object */
1831  Size len = VARSIZE(datum);
1832  struct varlena *result = (struct varlena *) palloc(len);
1833 
1834  memcpy(result, datum, len);
1835  return result;
1836  }
1837 }
size_t Size
Definition: c.h:594
const void size_t len
Definition: c.h:676
#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 1847 of file fmgr.c.

1848 {
1849  if (VARATT_IS_COMPRESSED(datum) || VARATT_IS_EXTERNAL(datum))
1850  return detoast_attr(datum);
1851  else
1852  return datum;
1853 }
#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 1840 of file fmgr.c.

1841 {
1842  /* Only get the specified portion from the toast rel */
1843  return detoast_attr_slice(datum, first, count);
1844 }
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 1680 of file fmgr.c.

1682 {
1683  LOCAL_FCINFO(fcinfo, 3);
1684  Datum result;
1685 
1686  if (buf == NULL && flinfo->fn_strict)
1687  return (Datum) 0; /* just return null result */
1688 
1689  InitFunctionCallInfoData(*fcinfo, flinfo, 3, InvalidOid, NULL, NULL);
1690 
1691  fcinfo->args[0].value = PointerGetDatum(buf);
1692  fcinfo->args[0].isnull = false;
1693  fcinfo->args[1].value = ObjectIdGetDatum(typioparam);
1694  fcinfo->args[1].isnull = false;
1695  fcinfo->args[2].value = Int32GetDatum(typmod);
1696  fcinfo->args[2].isnull = false;
1697 
1698  result = FunctionCallInvoke(fcinfo);
1699 
1700  /* Should get null result if and only if buf is NULL */
1701  if (buf == NULL)
1702  {
1703  if (!fcinfo->isnull)
1704  elog(ERROR, "receive function %u returned non-NULL",
1705  flinfo->fn_oid);
1706  }
1707  else
1708  {
1709  if (fcinfo->isnull)
1710  elog(ERROR, "receive function %u returned NULL",
1711  flinfo->fn_oid);
1712  }
1713 
1714  return result;
1715 }

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:350
@ 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 2053 of file fmgr.c.

2054 {
2055  flinfo->fn_expr = (Node *) makeConst(BYTEAOID, -1, InvalidOid, -1,
2057  options == NULL, false);
2058 }
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
Definition: makefuncs.c:302

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