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/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)
 
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 1050 of file fmgr.c.

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

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

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

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

2022 {
2023  HeapTuple procTup;
2024  HeapTuple langTup;
2025  Form_pg_proc procStruct;
2026  Form_pg_language langStruct;
2027  AclResult aclresult;
2028 
2029  /*
2030  * Get the function's pg_proc entry. Throw a user-facing error for bad
2031  * OID, because validators can be called with user-specified OIDs.
2032  */
2033  procTup = SearchSysCache1(PROCOID, ObjectIdGetDatum(functionOid));
2034  if (!HeapTupleIsValid(procTup))
2035  ereport(ERROR,
2036  (errcode(ERRCODE_UNDEFINED_FUNCTION),
2037  errmsg("function with OID %u does not exist", functionOid)));
2038  procStruct = (Form_pg_proc) GETSTRUCT(procTup);
2039 
2040  /*
2041  * Fetch pg_language entry to know if this is the correct validation
2042  * function for that pg_proc entry.
2043  */
2044  langTup = SearchSysCache1(LANGOID, ObjectIdGetDatum(procStruct->prolang));
2045  if (!HeapTupleIsValid(langTup))
2046  elog(ERROR, "cache lookup failed for language %u", procStruct->prolang);
2047  langStruct = (Form_pg_language) GETSTRUCT(langTup);
2048 
2049  if (langStruct->lanvalidator != validatorOid)
2050  ereport(ERROR,
2051  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2052  errmsg("language validation function %u called for language %u instead of %u",
2053  validatorOid, procStruct->prolang,
2054  langStruct->lanvalidator)));
2055 
2056  /* first validate that we have permissions to use the language */
2057  aclresult = pg_language_aclcheck(procStruct->prolang, GetUserId(),
2058  ACL_USAGE);
2059  if (aclresult != ACLCHECK_OK)
2060  aclcheck_error(aclresult, OBJECT_LANGUAGE,
2061  NameStr(langStruct->lanname));
2062 
2063  /*
2064  * Check whether we are allowed to execute the function itself. If we can
2065  * execute it, there should be no possible side-effect of
2066  * compiling/validation that execution can't have.
2067  */
2068  aclresult = pg_proc_aclcheck(functionOid, GetUserId(), ACL_EXECUTE);
2069  if (aclresult != ACLCHECK_OK)
2070  aclcheck_error(aclresult, OBJECT_FUNCTION, NameStr(procStruct->proname));
2071 
2072  ReleaseSysCache(procTup);
2073  ReleaseSysCache(langTup);
2074 
2075  return true;
2076 }
AclResult
Definition: acl.h:181
@ ACLCHECK_OK
Definition: acl.h:182
AclResult pg_language_aclcheck(Oid lang_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:5083
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3512
AclResult pg_proc_aclcheck(Oid proc_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:5071
#define NameStr(name)
Definition: c.h:692
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define ereport(elevel,...)
Definition: elog.h:143
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:649
Oid GetUserId(void)
Definition: miscinit.c:491
#define ACL_USAGE
Definition: parsenodes.h:90
@ OBJECT_LANGUAGE
Definition: parsenodes.h:2156
@ OBJECT_FUNCTION
Definition: parsenodes.h:2154
#define ACL_EXECUTE
Definition: parsenodes.h:89
FormData_pg_language * Form_pg_language
Definition: pg_language.h:65
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:136
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1221
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1173
@ 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_FUNCTION, OBJECT_LANGUAGE, ObjectIdGetDatum, pg_language_aclcheck(), pg_proc_aclcheck(), PROCOID, ReleaseSysCache(), and SearchSysCache1().

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

◆ DirectFunctionCall1Coll()

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

Definition at line 777 of file fmgr.c.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

References elog(), ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

◆ fetch_finfo_record()

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

Definition at line 469 of file fmgr.c.

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

Referenced by fmgr_c_validator(), and fmgr_info_C_lang().

◆ Float8GetDatum()

Datum Float8GetDatum ( float8  X)

◆ fmgr_info()

void fmgr_info ( Oid  functionId,
FmgrInfo finfo 
)

Definition at line 126 of file fmgr.c.

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

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(), 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 358 of file fmgr.c.

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

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

Referenced by fmgr_info_cxt_security().

◆ fmgr_info_copy()

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

Definition at line 594 of file fmgr.c.

596 {
597  memcpy(dstinfo, srcinfo, sizeof(FmgrInfo));
598  dstinfo->fn_mcxt = destcxt;
599  dstinfo->fn_extra = NULL;
600 }
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 146 of file fmgr.c.

148 {
149  const FmgrBuiltin *fbp;
150  HeapTuple procedureTuple;
151  Form_pg_proc procedureStruct;
152  Datum prosrcdatum;
153  bool isnull;
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 = SysCacheGetAttr(PROCOID, procedureTuple,
230  Anum_pg_proc_prosrc, &isnull);
231  if (isnull)
232  elog(ERROR, "null prosrc");
233  prosrc = TextDatumGetCString(prosrcdatum);
234  fbp = fmgr_lookupByName(prosrc);
235  if (fbp == NULL)
236  ereport(ERROR,
237  (errcode(ERRCODE_UNDEFINED_FUNCTION),
238  errmsg("internal function \"%s\" is not in internal lookup table",
239  prosrc)));
240  pfree(prosrc);
241  /* Should we check that nargs, strict, retset match the table? */
242  finfo->fn_addr = fbp->func;
243  /* note this policy is also assumed in fast path above */
244  finfo->fn_stats = TRACK_FUNC_ALL; /* ie, never track */
245  break;
246 
247  case ClanguageId:
248  fmgr_info_C_lang(functionId, finfo, procedureTuple);
249  finfo->fn_stats = TRACK_FUNC_PL; /* ie, track if ALL */
250  break;
251 
252  case SQLlanguageId:
253  finfo->fn_addr = fmgr_sql;
254  finfo->fn_stats = TRACK_FUNC_PL; /* ie, track if ALL */
255  break;
256 
257  default:
258  fmgr_info_other_lang(functionId, finfo, procedureTuple);
259  finfo->fn_stats = TRACK_FUNC_OFF; /* ie, track if not OFF */
260  break;
261  }
262 
263  finfo->fn_oid = functionId;
264  ReleaseSysCache(procedureTuple);
265 }
static void fmgr_info_C_lang(Oid functionId, FmgrInfo *finfo, HeapTuple procedureTuple)
Definition: fmgr.c:358
static void fmgr_info_other_lang(Oid functionId, FmgrInfo *finfo, HeapTuple procedureTuple)
Definition: fmgr.c:432
static const FmgrBuiltin * fmgr_isbuiltin(Oid id)
Definition: fmgr.c:75
static const FmgrBuiltin * fmgr_lookupByName(const char *name)
Definition: fmgr.c:100
Datum fmgr_security_definer(PG_FUNCTION_ARGS)
Definition: fmgr.c:644
#define FmgrHookIsNeeded(fn_oid)
Definition: fmgr.h:778
Datum fmgr_sql(PG_FUNCTION_ARGS)
Definition: functions.c:1019
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
Definition: heaptuple.c:359
@ TRACK_FUNC_PL
Definition: pgstat.h:63
@ TRACK_FUNC_ALL
Definition: pgstat.h:64
@ TRACK_FUNC_OFF
Definition: pgstat.h:62
#define InvalidOid
Definition: postgres_ext.h:36
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, SysCacheGetAttr(), TextDatumGetCString, TRACK_FUNC_ALL, TRACK_FUNC_OFF, and TRACK_FUNC_PL.

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

◆ fmgr_info_other_lang()

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

Definition at line 432 of file fmgr.c.

433 {
434  Form_pg_proc procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
435  Oid language = procedureStruct->prolang;
436  HeapTuple languageTuple;
437  Form_pg_language languageStruct;
438  FmgrInfo plfinfo;
439 
440  languageTuple = SearchSysCache1(LANGOID, ObjectIdGetDatum(language));
441  if (!HeapTupleIsValid(languageTuple))
442  elog(ERROR, "cache lookup failed for language %u", language);
443  languageStruct = (Form_pg_language) GETSTRUCT(languageTuple);
444 
445  /*
446  * Look up the language's call handler function, ignoring any attributes
447  * that would normally cause insertion of fmgr_security_definer. We need
448  * to get back a bare pointer to the actual C-language function.
449  */
450  fmgr_info_cxt_security(languageStruct->lanplcallfoid, &plfinfo,
451  CurrentMemoryContext, true);
452  finfo->fn_addr = plfinfo.fn_addr;
453 
454  ReleaseSysCache(languageTuple);
455 }
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 609 of file fmgr.c.

610 {
611  const FmgrBuiltin *fbp = fmgr_lookupByName(proname);
612 
613  if (fbp == NULL)
614  return InvalidOid;
615  return fbp->foid;
616 }
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 75 of file fmgr.c.

76 {
77  uint16 index;
78 
79  /* fast lookup only possible if original oid still assigned */
80  if (id > fmgr_last_builtin_oid)
81  return NULL;
82 
83  /*
84  * Lookup function data. If there's a miss in that range it's likely a
85  * nonexistent function, returning NULL here will trigger an ERROR later.
86  */
89  return NULL;
90 
91  return &fmgr_builtins[index];
92 }
unsigned short uint16
Definition: c.h:451
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:90

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

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

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

645 {
646  Datum result;
647  struct fmgr_security_definer_cache *volatile fcache;
648  FmgrInfo *save_flinfo;
649  Oid save_userid;
650  int save_sec_context;
651  volatile int save_nestlevel;
652  PgStat_FunctionCallUsage fcusage;
653 
654  if (!fcinfo->flinfo->fn_extra)
655  {
656  HeapTuple tuple;
657  Form_pg_proc procedureStruct;
658  Datum datum;
659  bool isnull;
660  MemoryContext oldcxt;
661 
662  fcache = MemoryContextAllocZero(fcinfo->flinfo->fn_mcxt,
663  sizeof(*fcache));
664 
665  fmgr_info_cxt_security(fcinfo->flinfo->fn_oid, &fcache->flinfo,
666  fcinfo->flinfo->fn_mcxt, true);
667  fcache->flinfo.fn_expr = fcinfo->flinfo->fn_expr;
668 
669  tuple = SearchSysCache1(PROCOID,
670  ObjectIdGetDatum(fcinfo->flinfo->fn_oid));
671  if (!HeapTupleIsValid(tuple))
672  elog(ERROR, "cache lookup failed for function %u",
673  fcinfo->flinfo->fn_oid);
674  procedureStruct = (Form_pg_proc) GETSTRUCT(tuple);
675 
676  if (procedureStruct->prosecdef)
677  fcache->userid = procedureStruct->proowner;
678 
679  datum = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_proconfig,
680  &isnull);
681  if (!isnull)
682  {
683  oldcxt = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
684  fcache->proconfig = DatumGetArrayTypePCopy(datum);
685  MemoryContextSwitchTo(oldcxt);
686  }
687 
688  ReleaseSysCache(tuple);
689 
690  fcinfo->flinfo->fn_extra = fcache;
691  }
692  else
693  fcache = fcinfo->flinfo->fn_extra;
694 
695  /* GetUserIdAndSecContext is cheap enough that no harm in a wasted call */
696  GetUserIdAndSecContext(&save_userid, &save_sec_context);
697  if (fcache->proconfig) /* Need a new GUC nesting level */
698  save_nestlevel = NewGUCNestLevel();
699  else
700  save_nestlevel = 0; /* keep compiler quiet */
701 
702  if (OidIsValid(fcache->userid))
704  save_sec_context | SECURITY_LOCAL_USERID_CHANGE);
705 
706  if (fcache->proconfig)
707  {
708  ProcessGUCArray(fcache->proconfig,
712  }
713 
714  /* function manager hook */
715  if (fmgr_hook)
716  (*fmgr_hook) (FHET_START, &fcache->flinfo, &fcache->arg);
717 
718  /*
719  * We don't need to restore GUC or userid settings on error, because the
720  * ensuing xact or subxact abort will do that. The PG_TRY block is only
721  * needed to clean up the flinfo link.
722  */
723  save_flinfo = fcinfo->flinfo;
724 
725  PG_TRY();
726  {
727  fcinfo->flinfo = &fcache->flinfo;
728 
729  /* See notes in fmgr_info_cxt_security */
730  pgstat_init_function_usage(fcinfo, &fcusage);
731 
732  result = FunctionCallInvoke(fcinfo);
733 
734  /*
735  * We could be calling either a regular or a set-returning function,
736  * so we have to test to see what finalize flag to use.
737  */
738  pgstat_end_function_usage(&fcusage,
739  (fcinfo->resultinfo == NULL ||
740  !IsA(fcinfo->resultinfo, ReturnSetInfo) ||
741  ((ReturnSetInfo *) fcinfo->resultinfo)->isDone != ExprMultipleResult));
742  }
743  PG_CATCH();
744  {
745  fcinfo->flinfo = save_flinfo;
746  if (fmgr_hook)
747  (*fmgr_hook) (FHET_ABORT, &fcache->flinfo, &fcache->arg);
748  PG_RE_THROW();
749  }
750  PG_END_TRY();
751 
752  fcinfo->flinfo = save_flinfo;
753 
754  if (fcache->proconfig)
755  AtEOXact_GUC(true, save_nestlevel);
756  if (OidIsValid(fcache->userid))
757  SetUserIdAndSecContext(save_userid, save_sec_context);
758  if (fmgr_hook)
759  (*fmgr_hook) (FHET_END, &fcache->flinfo, &fcache->arg);
760 
761  return result;
762 }
#define DatumGetArrayTypePCopy(X)
Definition: array.h:255
#define OidIsValid(objectId)
Definition: c.h:721
#define PG_RE_THROW()
Definition: elog.h:340
#define PG_END_TRY()
Definition: elog.h:324
#define PG_TRY()
Definition: elog.h:299
#define PG_CATCH()
Definition: elog.h:309
@ ExprMultipleResult
Definition: execnodes.h:281
PGDLLIMPORT fmgr_hook_type fmgr_hook
Definition: fmgr.c:39
@ FHET_END
Definition: fmgr.h:766
@ FHET_ABORT
Definition: fmgr.h:767
@ FHET_START
Definition: fmgr.h:765
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
int NewGUCNestLevel(void)
Definition: guc.c:6475
void ProcessGUCArray(ArrayType *array, GucContext context, GucSource source, GucAction action)
Definition: guc.c:11371
void AtEOXact_GUC(bool isCommit, int nestLevel)
Definition: guc.c:6489
@ GUC_ACTION_SAVE
Definition: guc.h:200
@ PGC_S_SESSION
Definition: guc.h:123
@ PGC_SUSET
Definition: guc.h:75
@ PGC_USERSET
Definition: guc.h:76
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:906
#define SECURITY_LOCAL_USERID_CHANGE
Definition: miscadmin.h:312
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
Definition: miscinit.c:602
void SetUserIdAndSecContext(Oid userid, int sec_context)
Definition: miscinit.c:609
#define IsA(nodeptr, _type_)
Definition: nodes.h:625
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
ArrayType * proconfig
Definition: fmgr.c:629
bool superuser(void)
Definition: superuser.c:46

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

Referenced by fmgr_info_cxt_security().

◆ fmgr_symbol()

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

Definition at line 283 of file fmgr.c.

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

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

Referenced by llvm_function_reference().

◆ FunctionCall0Coll()

Datum FunctionCall0Coll ( FmgrInfo flinfo,
Oid  collation 
)

Definition at line 1097 of file fmgr.c.

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

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

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

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

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

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(), execTuplesUnequal(), genericPickSplit(), get_distance(), get_position(), get_stats_slot_range(), ginCompareEntries(), gistMakeUnionItVec(), gistMakeUnionKey(), gistUserPicksplit(), has_matching_range(), hash_multirange_extended(), hash_range_extended(), 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 1156 of file fmgr.c.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1871 {
1872  List *args;
1873  Node *arg;
1874 
1875  if (expr == NULL)
1876  return false;
1877 
1878  if (IsA(expr, FuncExpr))
1879  args = ((FuncExpr *) expr)->args;
1880  else if (IsA(expr, OpExpr))
1881  args = ((OpExpr *) expr)->args;
1882  else if (IsA(expr, DistinctExpr))
1883  args = ((DistinctExpr *) expr)->args;
1884  else if (IsA(expr, ScalarArrayOpExpr))
1885  args = ((ScalarArrayOpExpr *) expr)->args;
1886  else if (IsA(expr, NullIfExpr))
1887  args = ((NullIfExpr *) expr)->args;
1888  else if (IsA(expr, WindowFunc))
1889  args = ((WindowFunc *) expr)->args;
1890  else
1891  return false;
1892 
1893  if (argnum < 0 || argnum >= list_length(args))
1894  return false;
1895 
1896  arg = (Node *) list_nth(args, argnum);
1897 
1898  /*
1899  * Either a true Const or an external Param will have a value that doesn't
1900  * change during the execution of the query. In future we might want to
1901  * consider other cases too, e.g. now().
1902  */
1903  if (IsA(arg, Const))
1904  return true;
1905  if (IsA(arg, Param) &&
1906  ((Param *) arg)->paramkind == PARAM_EXTERN)
1907  return true;
1908 
1909  return false;
1910 }
void * arg
static int list_length(const List *l)
Definition: pg_list.h:150
static void * list_nth(const List *list, int n)
Definition: pg_list.h:297
@ PARAM_EXTERN
Definition: primnodes.h:299
Definition: pg_list.h:52
Definition: nodes.h:575

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

1806 {
1807  List *args;
1808  Oid argtype;
1809 
1810  if (expr == NULL)
1811  return InvalidOid;
1812 
1813  if (IsA(expr, FuncExpr))
1814  args = ((FuncExpr *) expr)->args;
1815  else if (IsA(expr, OpExpr))
1816  args = ((OpExpr *) expr)->args;
1817  else if (IsA(expr, DistinctExpr))
1818  args = ((DistinctExpr *) expr)->args;
1819  else if (IsA(expr, ScalarArrayOpExpr))
1820  args = ((ScalarArrayOpExpr *) expr)->args;
1821  else if (IsA(expr, NullIfExpr))
1822  args = ((NullIfExpr *) expr)->args;
1823  else if (IsA(expr, WindowFunc))
1824  args = ((WindowFunc *) expr)->args;
1825  else
1826  return InvalidOid;
1827 
1828  if (argnum < 0 || argnum >= list_length(args))
1829  return InvalidOid;
1830 
1831  argtype = exprType((Node *) list_nth(args, argnum));
1832 
1833  /*
1834  * special hack for ScalarArrayOpExpr: what the underlying function will
1835  * actually get passed is the element type of the array.
1836  */
1837  if (IsA(expr, ScalarArrayOpExpr) &&
1838  argnum == 1)
1839  argtype = get_base_element_type(argtype);
1840 
1841  return argtype;
1842 }
Oid get_base_element_type(Oid typid)
Definition: lsyscache.c:2789
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41

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

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

◆ get_fn_expr_arg_stable()

bool get_fn_expr_arg_stable ( FmgrInfo flinfo,
int  argnum 
)

Definition at line 1851 of file fmgr.c.

1852 {
1853  /*
1854  * can't return anything useful if we have no FmgrInfo or if its fn_expr
1855  * node has not been initialized
1856  */
1857  if (!flinfo || !flinfo->fn_expr)
1858  return false;
1859 
1860  return get_call_expr_arg_stable(flinfo->fn_expr, argnum);
1861 }
bool get_call_expr_arg_stable(Node *expr, int argnum)
Definition: fmgr.c:1870

References FmgrInfo::fn_expr, and get_call_expr_arg_stable().

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

◆ get_fn_expr_argtype()

◆ get_fn_expr_rettype()

Oid get_fn_expr_rettype ( FmgrInfo flinfo)

Definition at line 1764 of file fmgr.c.

1765 {
1766  Node *expr;
1767 
1768  /*
1769  * can't return anything useful if we have no FmgrInfo or if its fn_expr
1770  * node has not been initialized
1771  */
1772  if (!flinfo || !flinfo->fn_expr)
1773  return InvalidOid;
1774 
1775  expr = flinfo->fn_expr;
1776 
1777  return exprType(expr);
1778 }

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

1921 {
1922  Node *expr;
1923 
1924  /*
1925  * can't return anything useful if we have no FmgrInfo or if its fn_expr
1926  * node has not been initialized
1927  */
1928  if (!flinfo || !flinfo->fn_expr)
1929  return false;
1930 
1931  expr = flinfo->fn_expr;
1932 
1933  if (IsA(expr, FuncExpr))
1934  return ((FuncExpr *) expr)->funcvariadic;
1935  else
1936  return false;
1937 }

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

1974 {
1975  if (flinfo && flinfo->fn_expr && IsA(flinfo->fn_expr, Const))
1976  {
1977  Const *expr = (Const *) flinfo->fn_expr;
1978 
1979  if (expr->consttype == BYTEAOID)
1980  return expr->constisnull ? NULL : DatumGetByteaP(expr->constvalue);
1981  }
1982 
1983  ereport(ERROR,
1984  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1985  errmsg("operator class options info is absent in function call context")));
1986 
1987  return NULL;
1988 }
#define DatumGetByteaP(X)
Definition: fmgr.h:331
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
Oid consttype
Definition: primnodes.h:256
Datum constvalue
Definition: primnodes.h:260
bool constisnull
Definition: primnodes.h:261

References Const::constisnull, Const::consttype, Const::constvalue, 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 1957 of file fmgr.c.

1958 {
1959  if (flinfo && flinfo->fn_expr && IsA(flinfo->fn_expr, Const))
1960  {
1961  Const *expr = (Const *) flinfo->fn_expr;
1962 
1963  if (expr->consttype == BYTEAOID)
1964  return !expr->constisnull;
1965  }
1966  return false;
1967 }

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

◆ InputFunctionCall()

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

Definition at line 1515 of file fmgr.c.

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

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(), domain_in(), ExecEvalJsonExprCoercion(), hstore_populate_record(), make_tuple_from_result_row(), multirange_in(), NextCopyFrom(), OidInputFunctionCall(), plperl_sv_to_datum(), plsample_func_handler(), pltcl_func_handler(), pltcl_returnnext(), pltcl_SPI_execute_plan(), PLyObject_ToScalar(), PLyUnicode_ToComposite(), populate_scalar(), range_in(), ReadArrayStr(), record_in(), and XmlTableGetValue().

◆ Int64GetDatum()

Datum Int64GetDatum ( int64  X)

Definition at line 1683 of file fmgr.c.

1684 {
1685  int64 *retval = (int64 *) palloc(sizeof(int64));
1686 
1687  *retval = X;
1688  return PointerGetDatum(retval);
1689 }

References palloc(), and PointerGetDatum.

Referenced by brin_metapage_info(), brin_page_items(), brin_summarize_new_values(), build_minmax_path(), DefineSequence(), delay_execution_planner(), ExecEvalNextValueExpr(), FillXLogStatsRow(), gbt_num_fetch(), generate_series_step_int8(), 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(), 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_stat_file(), pg_stat_get_archiver(), 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(), StartReplication(), and validate_index_callback().

◆ lookup_C_func()

static CFuncHashTabEntry * lookup_C_func ( HeapTuple  procedureTuple)
static

Definition at line 529 of file fmgr.c.

530 {
531  Oid fn_oid = ((Form_pg_proc) GETSTRUCT(procedureTuple))->oid;
532  CFuncHashTabEntry *entry;
533 
534  if (CFuncHash == NULL)
535  return NULL; /* no table yet */
536  entry = (CFuncHashTabEntry *)
538  &fn_oid,
539  HASH_FIND,
540  NULL);
541  if (entry == NULL)
542  return NULL; /* no such entry */
543  if (entry->fn_xmin == HeapTupleHeaderGetRawXmin(procedureTuple->t_data) &&
544  ItemPointerEquals(&entry->fn_tid, &procedureTuple->t_self))
545  return entry; /* OK */
546  return NULL; /* entry is out of date */
547 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
static HTAB * CFuncHash
Definition: fmgr.c:54
@ HASH_FIND
Definition: hsearch.h:113
#define HeapTupleHeaderGetRawXmin(tup)
Definition: htup_details.h:303
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
Definition: itemptr.c:29
TransactionId fn_xmin
Definition: fmgr.c:48
ItemPointerData fn_tid
Definition: fmgr.c:49
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 1386 of file fmgr.c.

1387 {
1388  FmgrInfo flinfo;
1389 
1390  fmgr_info(functionId, &flinfo);
1391 
1392  return FunctionCall0Coll(&flinfo, collation);
1393 }
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126
Datum FunctionCall0Coll(FmgrInfo *flinfo, Oid collation)
Definition: fmgr.c:1097

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

◆ OidFunctionCall1Coll()

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

Definition at line 1396 of file fmgr.c.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

◆ OidInputFunctionCall()

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

Definition at line 1630 of file fmgr.c.

1631 {
1632  FmgrInfo flinfo;
1633 
1634  fmgr_info(functionId, &flinfo);
1635  return InputFunctionCall(&flinfo, str, typioparam, typmod);
1636 }
Datum InputFunctionCall(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
Definition: fmgr.c:1515

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

1650 {
1651  FmgrInfo flinfo;
1652 
1653  fmgr_info(functionId, &flinfo);
1654  return ReceiveFunctionCall(&flinfo, buf, typioparam, typmod);
1655 }
Datum ReceiveFunctionCall(FmgrInfo *flinfo, StringInfo buf, Oid typioparam, int32 typmod)
Definition: fmgr.c:1573
static char * buf
Definition: pg_test_fsync.c:67

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

1659 {
1660  FmgrInfo flinfo;
1661 
1662  fmgr_info(functionId, &flinfo);
1663  return SendFunctionCall(&flinfo, val);
1664 }
bytea * SendFunctionCall(FmgrInfo *flinfo, Datum val)
Definition: fmgr.c:1620

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

1709 {
1710  if (VARATT_IS_EXTENDED(datum))
1711  return detoast_attr(datum);
1712  else
1713  return datum;
1714 }
struct varlena * detoast_attr(struct varlena *attr)
Definition: detoast.c:116
#define VARATT_IS_EXTENDED(PTR)
Definition: postgres.h:340

References detoast_attr(), and VARATT_IS_EXTENDED.

◆ pg_detoast_datum_copy()

struct varlena* pg_detoast_datum_copy ( struct varlena datum)

Definition at line 1717 of file fmgr.c.

1718 {
1719  if (VARATT_IS_EXTENDED(datum))
1720  return detoast_attr(datum);
1721  else
1722  {
1723  /* Make a modifiable copy of the varlena object */
1724  Size len = VARSIZE(datum);
1725  struct varlena *result = (struct varlena *) palloc(len);
1726 
1727  memcpy(result, datum, len);
1728  return result;
1729  }
1730 }
size_t Size
Definition: c.h:551
const void size_t len
#define VARSIZE(PTR)
Definition: postgres.h:316
Definition: c.h:633

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

◆ pg_detoast_datum_packed()

struct varlena* pg_detoast_datum_packed ( struct varlena datum)

Definition at line 1740 of file fmgr.c.

1741 {
1742  if (VARATT_IS_COMPRESSED(datum) || VARATT_IS_EXTERNAL(datum))
1743  return detoast_attr(datum);
1744  else
1745  return datum;
1746 }
#define VARATT_IS_COMPRESSED(PTR)
Definition: postgres.h:325
#define VARATT_IS_EXTERNAL(PTR)
Definition: postgres.h:326

References detoast_attr(), VARATT_IS_COMPRESSED, and VARATT_IS_EXTERNAL.

Referenced by text_to_cstring(), and text_to_cstring_buffer().

◆ pg_detoast_datum_slice()

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

Definition at line 1733 of file fmgr.c.

1734 {
1735  /* Only get the specified portion from the toast rel */
1736  return detoast_attr_slice(datum, first, count);
1737 }
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 1573 of file fmgr.c.

1575 {
1576  LOCAL_FCINFO(fcinfo, 3);
1577  Datum result;
1578 
1579  if (buf == NULL && flinfo->fn_strict)
1580  return (Datum) 0; /* just return null result */
1581 
1582  InitFunctionCallInfoData(*fcinfo, flinfo, 3, InvalidOid, NULL, NULL);
1583 
1584  fcinfo->args[0].value = PointerGetDatum(buf);
1585  fcinfo->args[0].isnull = false;
1586  fcinfo->args[1].value = ObjectIdGetDatum(typioparam);
1587  fcinfo->args[1].isnull = false;
1588  fcinfo->args[2].value = Int32GetDatum(typmod);
1589  fcinfo->args[2].isnull = false;
1590 
1591  result = FunctionCallInvoke(fcinfo);
1592 
1593  /* Should get null result if and only if buf is NULL */
1594  if (buf == NULL)
1595  {
1596  if (!fcinfo->isnull)
1597  elog(ERROR, "receive function %u returned non-NULL",
1598  flinfo->fn_oid);
1599  }
1600  else
1601  {
1602  if (fcinfo->isnull)
1603  elog(ERROR, "receive function %u returned NULL",
1604  flinfo->fn_oid);
1605  }
1606 
1607  return result;
1608 }

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

555 {
556  Oid fn_oid = ((Form_pg_proc) GETSTRUCT(procedureTuple))->oid;
557  CFuncHashTabEntry *entry;
558  bool found;
559 
560  /* Create the hash table if it doesn't exist yet */
561  if (CFuncHash == NULL)
562  {
563  HASHCTL hash_ctl;
564 
565  hash_ctl.keysize = sizeof(Oid);
566  hash_ctl.entrysize = sizeof(CFuncHashTabEntry);
567  CFuncHash = hash_create("CFuncHash",
568  100,
569  &hash_ctl,
571  }
572 
573  entry = (CFuncHashTabEntry *)
575  &fn_oid,
576  HASH_ENTER,
577  &found);
578  /* OID is already filled in */
579  entry->fn_xmin = HeapTupleHeaderGetRawXmin(procedureTuple->t_data);
580  entry->fn_tid = procedureTuple->t_self;
581  entry->user_fn = user_fn;
582  entry->inforec = inforec;
583 }
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:349
@ 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 1946 of file fmgr.c.

1947 {
1948  flinfo->fn_expr = (Node *) makeConst(BYTEAOID, -1, InvalidOid, -1,
1950  options == NULL, false);
1951 }
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
Definition: makefuncs.c:300

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 54 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 39 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 38 of file fmgr.c.

Referenced by sepgsql_init_client_label().