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

1037 {
1038  LOCAL_FCINFO(fcinfo, 1);
1039  Datum result;
1040 
1041  InitFunctionCallInfoData(*fcinfo, flinfo, 1, collation, NULL, NULL);
1042 
1043  fcinfo->args[0].value = arg1;
1044  fcinfo->args[0].isnull = false;
1045 
1046  result = (*func) (fcinfo);
1047 
1048  /* Check for null result, since caller is clearly not expecting one */
1049  if (fcinfo->isnull)
1050  elog(ERROR, "function %p returned NULL", (void *) func);
1051 
1052  return result;
1053 }
#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 1056 of file fmgr.c.

1057 {
1058  LOCAL_FCINFO(fcinfo, 2);
1059  Datum result;
1060 
1061  InitFunctionCallInfoData(*fcinfo, flinfo, 2, collation, NULL, NULL);
1062 
1063  fcinfo->args[0].value = arg1;
1064  fcinfo->args[0].isnull = false;
1065  fcinfo->args[1].value = arg2;
1066  fcinfo->args[1].isnull = false;
1067 
1068  result = (*func) (fcinfo);
1069 
1070  /* Check for null result, since caller is clearly not expecting one */
1071  if (fcinfo->isnull)
1072  elog(ERROR, "function %p returned NULL", (void *) func);
1073 
1074  return result;
1075 }

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

2117 {
2118  HeapTuple procTup;
2119  HeapTuple langTup;
2120  Form_pg_proc procStruct;
2121  Form_pg_language langStruct;
2122  AclResult aclresult;
2123 
2124  /*
2125  * Get the function's pg_proc entry. Throw a user-facing error for bad
2126  * OID, because validators can be called with user-specified OIDs.
2127  */
2128  procTup = SearchSysCache1(PROCOID, ObjectIdGetDatum(functionOid));
2129  if (!HeapTupleIsValid(procTup))
2130  ereport(ERROR,
2131  (errcode(ERRCODE_UNDEFINED_FUNCTION),
2132  errmsg("function with OID %u does not exist", functionOid)));
2133  procStruct = (Form_pg_proc) GETSTRUCT(procTup);
2134 
2135  /*
2136  * Fetch pg_language entry to know if this is the correct validation
2137  * function for that pg_proc entry.
2138  */
2139  langTup = SearchSysCache1(LANGOID, ObjectIdGetDatum(procStruct->prolang));
2140  if (!HeapTupleIsValid(langTup))
2141  elog(ERROR, "cache lookup failed for language %u", procStruct->prolang);
2142  langStruct = (Form_pg_language) GETSTRUCT(langTup);
2143 
2144  if (langStruct->lanvalidator != validatorOid)
2145  ereport(ERROR,
2146  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2147  errmsg("language validation function %u called for language %u instead of %u",
2148  validatorOid, procStruct->prolang,
2149  langStruct->lanvalidator)));
2150 
2151  /* first validate that we have permissions to use the language */
2152  aclresult = object_aclcheck(LanguageRelationId, procStruct->prolang, GetUserId(),
2153  ACL_USAGE);
2154  if (aclresult != ACLCHECK_OK)
2155  aclcheck_error(aclresult, OBJECT_LANGUAGE,
2156  NameStr(langStruct->lanname));
2157 
2158  /*
2159  * Check whether we are allowed to execute the function itself. If we can
2160  * execute it, there should be no possible side-effect of
2161  * compiling/validation that execution can't have.
2162  */
2163  aclresult = object_aclcheck(ProcedureRelationId, functionOid, GetUserId(), ACL_EXECUTE);
2164  if (aclresult != ACLCHECK_OK)
2165  aclcheck_error(aclresult, OBJECT_FUNCTION, NameStr(procStruct->proname));
2166 
2167  ReleaseSysCache(procTup);
2168  ReleaseSysCache(langTup);
2169 
2170  return true;
2171 }
AclResult
Definition: acl.h:182
@ ACLCHECK_OK
Definition: acl.h:183
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:2673
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
Definition: aclchk.c:3775
#define NameStr(name)
Definition: c.h:730
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:510
#define ACL_USAGE
Definition: parsenodes.h:91
@ OBJECT_LANGUAGE
Definition: parsenodes.h:2103
@ OBJECT_FUNCTION
Definition: parsenodes.h:2101
#define ACL_EXECUTE
Definition: parsenodes.h:90
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:866
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:818
@ 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 763 of file fmgr.c.

764 {
765  LOCAL_FCINFO(fcinfo, 1);
766  Datum result;
767 
768  InitFunctionCallInfoData(*fcinfo, NULL, 1, collation, NULL, NULL);
769 
770  fcinfo->args[0].value = arg1;
771  fcinfo->args[0].isnull = false;
772 
773  result = (*func) (fcinfo);
774 
775  /* Check for null result, since caller is clearly not expecting one */
776  if (fcinfo->isnull)
777  elog(ERROR, "function %p returned NULL", (void *) func);
778 
779  return result;
780 }

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

784 {
785  LOCAL_FCINFO(fcinfo, 2);
786  Datum result;
787 
788  InitFunctionCallInfoData(*fcinfo, NULL, 2, collation, NULL, NULL);
789 
790  fcinfo->args[0].value = arg1;
791  fcinfo->args[0].isnull = false;
792  fcinfo->args[1].value = arg2;
793  fcinfo->args[1].isnull = false;
794 
795  result = (*func) (fcinfo);
796 
797  /* Check for null result, since caller is clearly not expecting one */
798  if (fcinfo->isnull)
799  elog(ERROR, "function %p returned NULL", (void *) func);
800 
801  return result;
802 }

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

807 {
808  LOCAL_FCINFO(fcinfo, 3);
809  Datum result;
810 
811  InitFunctionCallInfoData(*fcinfo, NULL, 3, collation, NULL, NULL);
812 
813  fcinfo->args[0].value = arg1;
814  fcinfo->args[0].isnull = false;
815  fcinfo->args[1].value = arg2;
816  fcinfo->args[1].isnull = false;
817  fcinfo->args[2].value = arg3;
818  fcinfo->args[2].isnull = false;
819 
820  result = (*func) (fcinfo);
821 
822  /* Check for null result, since caller is clearly not expecting one */
823  if (fcinfo->isnull)
824  elog(ERROR, "function %p returned NULL", (void *) func);
825 
826  return result;
827 }

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

832 {
833  LOCAL_FCINFO(fcinfo, 4);
834  Datum result;
835 
836  InitFunctionCallInfoData(*fcinfo, NULL, 4, collation, NULL, NULL);
837 
838  fcinfo->args[0].value = arg1;
839  fcinfo->args[0].isnull = false;
840  fcinfo->args[1].value = arg2;
841  fcinfo->args[1].isnull = false;
842  fcinfo->args[2].value = arg3;
843  fcinfo->args[2].isnull = false;
844  fcinfo->args[3].value = arg4;
845  fcinfo->args[3].isnull = false;
846 
847  result = (*func) (fcinfo);
848 
849  /* Check for null result, since caller is clearly not expecting one */
850  if (fcinfo->isnull)
851  elog(ERROR, "function %p returned NULL", (void *) func);
852 
853  return result;
854 }

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

859 {
860  LOCAL_FCINFO(fcinfo, 5);
861  Datum result;
862 
863  InitFunctionCallInfoData(*fcinfo, NULL, 5, collation, NULL, NULL);
864 
865  fcinfo->args[0].value = arg1;
866  fcinfo->args[0].isnull = false;
867  fcinfo->args[1].value = arg2;
868  fcinfo->args[1].isnull = false;
869  fcinfo->args[2].value = arg3;
870  fcinfo->args[2].isnull = false;
871  fcinfo->args[3].value = arg4;
872  fcinfo->args[3].isnull = false;
873  fcinfo->args[4].value = arg5;
874  fcinfo->args[4].isnull = false;
875 
876  result = (*func) (fcinfo);
877 
878  /* Check for null result, since caller is clearly not expecting one */
879  if (fcinfo->isnull)
880  elog(ERROR, "function %p returned NULL", (void *) func);
881 
882  return result;
883 }

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

Referenced by neqjoinsel().

◆ DirectFunctionCall6Coll()

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

Definition at line 886 of file fmgr.c.

889 {
890  LOCAL_FCINFO(fcinfo, 6);
891  Datum result;
892 
893  InitFunctionCallInfoData(*fcinfo, NULL, 6, collation, NULL, NULL);
894 
895  fcinfo->args[0].value = arg1;
896  fcinfo->args[0].isnull = false;
897  fcinfo->args[1].value = arg2;
898  fcinfo->args[1].isnull = false;
899  fcinfo->args[2].value = arg3;
900  fcinfo->args[2].isnull = false;
901  fcinfo->args[3].value = arg4;
902  fcinfo->args[3].isnull = false;
903  fcinfo->args[4].value = arg5;
904  fcinfo->args[4].isnull = false;
905  fcinfo->args[5].value = arg6;
906  fcinfo->args[5].isnull = false;
907 
908  result = (*func) (fcinfo);
909 
910  /* Check for null result, since caller is clearly not expecting one */
911  if (fcinfo->isnull)
912  elog(ERROR, "function %p returned NULL", (void *) func);
913 
914  return result;
915 }

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

921 {
922  LOCAL_FCINFO(fcinfo, 7);
923  Datum result;
924 
925  InitFunctionCallInfoData(*fcinfo, NULL, 7, collation, NULL, NULL);
926 
927  fcinfo->args[0].value = arg1;
928  fcinfo->args[0].isnull = false;
929  fcinfo->args[1].value = arg2;
930  fcinfo->args[1].isnull = false;
931  fcinfo->args[2].value = arg3;
932  fcinfo->args[2].isnull = false;
933  fcinfo->args[3].value = arg4;
934  fcinfo->args[3].isnull = false;
935  fcinfo->args[4].value = arg5;
936  fcinfo->args[4].isnull = false;
937  fcinfo->args[5].value = arg6;
938  fcinfo->args[5].isnull = false;
939  fcinfo->args[6].value = arg7;
940  fcinfo->args[6].isnull = false;
941 
942  result = (*func) (fcinfo);
943 
944  /* Check for null result, since caller is clearly not expecting one */
945  if (fcinfo->isnull)
946  elog(ERROR, "function %p returned NULL", (void *) func);
947 
948  return result;
949 }

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

955 {
956  LOCAL_FCINFO(fcinfo, 8);
957  Datum result;
958 
959  InitFunctionCallInfoData(*fcinfo, NULL, 8, collation, NULL, NULL);
960 
961  fcinfo->args[0].value = arg1;
962  fcinfo->args[0].isnull = false;
963  fcinfo->args[1].value = arg2;
964  fcinfo->args[1].isnull = false;
965  fcinfo->args[2].value = arg3;
966  fcinfo->args[2].isnull = false;
967  fcinfo->args[3].value = arg4;
968  fcinfo->args[3].isnull = false;
969  fcinfo->args[4].value = arg5;
970  fcinfo->args[4].isnull = false;
971  fcinfo->args[5].value = arg6;
972  fcinfo->args[5].isnull = false;
973  fcinfo->args[6].value = arg7;
974  fcinfo->args[6].isnull = false;
975  fcinfo->args[7].value = arg8;
976  fcinfo->args[7].isnull = false;
977 
978  result = (*func) (fcinfo);
979 
980  /* Check for null result, since caller is clearly not expecting one */
981  if (fcinfo->isnull)
982  elog(ERROR, "function %p returned NULL", (void *) func);
983 
984  return result;
985 }

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

992 {
993  LOCAL_FCINFO(fcinfo, 9);
994  Datum result;
995 
996  InitFunctionCallInfoData(*fcinfo, NULL, 9, collation, NULL, NULL);
997 
998  fcinfo->args[0].value = arg1;
999  fcinfo->args[0].isnull = false;
1000  fcinfo->args[1].value = arg2;
1001  fcinfo->args[1].isnull = false;
1002  fcinfo->args[2].value = arg3;
1003  fcinfo->args[2].isnull = false;
1004  fcinfo->args[3].value = arg4;
1005  fcinfo->args[3].isnull = false;
1006  fcinfo->args[4].value = arg5;
1007  fcinfo->args[4].isnull = false;
1008  fcinfo->args[5].value = arg6;
1009  fcinfo->args[5].isnull = false;
1010  fcinfo->args[6].value = arg7;
1011  fcinfo->args[6].isnull = false;
1012  fcinfo->args[7].value = arg8;
1013  fcinfo->args[7].isnull = false;
1014  fcinfo->args[8].value = arg9;
1015  fcinfo->args[8].isnull = false;
1016 
1017  result = (*func) (fcinfo);
1018 
1019  /* Check for null result, since caller is clearly not expecting one */
1020  if (fcinfo->isnull)
1021  elog(ERROR, "function %p returned NULL", (void *) func);
1022 
1023  return result;
1024 }

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

1615 {
1616  LOCAL_FCINFO(fcinfo, 3);
1617 
1618  if (str == NULL)
1619  {
1620  *result = (Datum) 0; /* just return null result */
1621  return true;
1622  }
1623 
1624  InitFunctionCallInfoData(*fcinfo, NULL, 3, InvalidOid, escontext, NULL);
1625 
1626  fcinfo->args[0].value = CStringGetDatum(str);
1627  fcinfo->args[0].isnull = false;
1628  fcinfo->args[1].value = ObjectIdGetDatum(typioparam);
1629  fcinfo->args[1].isnull = false;
1630  fcinfo->args[2].value = Int32GetDatum(typmod);
1631  fcinfo->args[2].isnull = false;
1632 
1633  *result = (*func) (fcinfo);
1634 
1635  /* Result value is garbage, and could be null, if an error was reported */
1636  if (SOFT_ERROR_OCCURRED(escontext))
1637  return false;
1638 
1639  /* Otherwise, shouldn't get null result */
1640  if (fcinfo->isnull)
1641  elog(ERROR, "input function %p returned NULL", (void *) func);
1642 
1643  return true;
1644 }
#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:1110

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:630
#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:359
@ 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:489
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 }
const char * name
Definition: encode.c:571
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 630 of file fmgr.c.

631 {
632  Datum result;
633  struct fmgr_security_definer_cache *volatile fcache;
634  FmgrInfo *save_flinfo;
635  Oid save_userid;
636  int save_sec_context;
637  volatile int save_nestlevel;
638  PgStat_FunctionCallUsage fcusage;
639 
640  if (!fcinfo->flinfo->fn_extra)
641  {
642  HeapTuple tuple;
643  Form_pg_proc procedureStruct;
644  Datum datum;
645  bool isnull;
646  MemoryContext oldcxt;
647 
648  fcache = MemoryContextAllocZero(fcinfo->flinfo->fn_mcxt,
649  sizeof(*fcache));
650 
651  fmgr_info_cxt_security(fcinfo->flinfo->fn_oid, &fcache->flinfo,
652  fcinfo->flinfo->fn_mcxt, true);
653  fcache->flinfo.fn_expr = fcinfo->flinfo->fn_expr;
654 
655  tuple = SearchSysCache1(PROCOID,
656  ObjectIdGetDatum(fcinfo->flinfo->fn_oid));
657  if (!HeapTupleIsValid(tuple))
658  elog(ERROR, "cache lookup failed for function %u",
659  fcinfo->flinfo->fn_oid);
660  procedureStruct = (Form_pg_proc) GETSTRUCT(tuple);
661 
662  if (procedureStruct->prosecdef)
663  fcache->userid = procedureStruct->proowner;
664 
665  datum = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_proconfig,
666  &isnull);
667  if (!isnull)
668  {
669  oldcxt = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
670  fcache->proconfig = DatumGetArrayTypePCopy(datum);
671  MemoryContextSwitchTo(oldcxt);
672  }
673 
674  ReleaseSysCache(tuple);
675 
676  fcinfo->flinfo->fn_extra = fcache;
677  }
678  else
679  fcache = fcinfo->flinfo->fn_extra;
680 
681  /* GetUserIdAndSecContext is cheap enough that no harm in a wasted call */
682  GetUserIdAndSecContext(&save_userid, &save_sec_context);
683  if (fcache->proconfig) /* Need a new GUC nesting level */
684  save_nestlevel = NewGUCNestLevel();
685  else
686  save_nestlevel = 0; /* keep compiler quiet */
687 
688  if (OidIsValid(fcache->userid))
690  save_sec_context | SECURITY_LOCAL_USERID_CHANGE);
691 
692  if (fcache->proconfig)
693  {
694  ProcessGUCArray(fcache->proconfig,
698  }
699 
700  /* function manager hook */
701  if (fmgr_hook)
702  (*fmgr_hook) (FHET_START, &fcache->flinfo, &fcache->arg);
703 
704  /*
705  * We don't need to restore GUC or userid settings on error, because the
706  * ensuing xact or subxact abort will do that. The PG_TRY block is only
707  * needed to clean up the flinfo link.
708  */
709  save_flinfo = fcinfo->flinfo;
710 
711  PG_TRY();
712  {
713  fcinfo->flinfo = &fcache->flinfo;
714 
715  /* See notes in fmgr_info_cxt_security */
716  pgstat_init_function_usage(fcinfo, &fcusage);
717 
718  result = FunctionCallInvoke(fcinfo);
719 
720  /*
721  * We could be calling either a regular or a set-returning function,
722  * so we have to test to see what finalize flag to use.
723  */
724  pgstat_end_function_usage(&fcusage,
725  (fcinfo->resultinfo == NULL ||
726  !IsA(fcinfo->resultinfo, ReturnSetInfo) ||
727  ((ReturnSetInfo *) fcinfo->resultinfo)->isDone != ExprMultipleResult));
728  }
729  PG_CATCH();
730  {
731  fcinfo->flinfo = save_flinfo;
732  if (fmgr_hook)
733  (*fmgr_hook) (FHET_ABORT, &fcache->flinfo, &fcache->arg);
734  PG_RE_THROW();
735  }
736  PG_END_TRY();
737 
738  fcinfo->flinfo = save_flinfo;
739 
740  if (fcache->proconfig)
741  AtEOXact_GUC(true, save_nestlevel);
742  if (OidIsValid(fcache->userid))
743  SetUserIdAndSecContext(save_userid, save_sec_context);
744  if (fmgr_hook)
745  (*fmgr_hook) (FHET_END, &fcache->flinfo, &fcache->arg);
746 
747  return result;
748 }
#define DatumGetArrayTypePCopy(X)
Definition: array.h:255
#define OidIsValid(objectId)
Definition: c.h:759
#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:298
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:2201
void ProcessGUCArray(ArrayType *array, GucContext context, GucSource source, GucAction action)
Definition: guc.c:6224
void AtEOXact_GUC(bool isCommit, int nestLevel)
Definition: guc.c:2215
@ GUC_ACTION_SAVE
Definition: guc.h:199
@ PGC_S_SESSION
Definition: guc.h:122
@ PGC_SUSET
Definition: guc.h:74
@ PGC_USERSET
Definition: guc.h:75
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:1064
#define SECURITY_LOCAL_USERID_CHANGE
Definition: miscadmin.h:313
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
Definition: miscinit.c:631
void SetUserIdAndSecContext(Oid userid, int sec_context)
Definition: miscinit.c:638
#define IsA(nodeptr, _type_)
Definition: nodes.h:179
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:138
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:615
bool superuser(void)
Definition: superuser.c:46
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1079

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

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

1084 {
1085  LOCAL_FCINFO(fcinfo, 0);
1086  Datum result;
1087 
1088  InitFunctionCallInfoData(*fcinfo, flinfo, 0, collation, NULL, NULL);
1089 
1090  result = FunctionCallInvoke(fcinfo);
1091 
1092  /* Check for null result, since caller is clearly not expecting one */
1093  if (fcinfo->isnull)
1094  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1095 
1096  return result;
1097 }

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

1101 {
1102  LOCAL_FCINFO(fcinfo, 1);
1103  Datum result;
1104 
1105  InitFunctionCallInfoData(*fcinfo, flinfo, 1, collation, NULL, NULL);
1106 
1107  fcinfo->args[0].value = arg1;
1108  fcinfo->args[0].isnull = false;
1109 
1110  result = FunctionCallInvoke(fcinfo);
1111 
1112  /* Check for null result, since caller is clearly not expecting one */
1113  if (fcinfo->isnull)
1114  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1115 
1116  return result;
1117 }

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

1121 {
1122  LOCAL_FCINFO(fcinfo, 2);
1123  Datum result;
1124 
1125  InitFunctionCallInfoData(*fcinfo, flinfo, 2, collation, NULL, NULL);
1126 
1127  fcinfo->args[0].value = arg1;
1128  fcinfo->args[0].isnull = false;
1129  fcinfo->args[1].value = arg2;
1130  fcinfo->args[1].isnull = false;
1131 
1132  result = FunctionCallInvoke(fcinfo);
1133 
1134  /* Check for null result, since caller is clearly not expecting one */
1135  if (fcinfo->isnull)
1136  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1137 
1138  return result;
1139 }

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

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

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

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

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

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

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

Referenced by 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 1223 of file fmgr.c.

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

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

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

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

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

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

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

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

1966 {
1967  List *args;
1968  Node *arg;
1969 
1970  if (expr == NULL)
1971  return false;
1972 
1973  if (IsA(expr, FuncExpr))
1974  args = ((FuncExpr *) expr)->args;
1975  else if (IsA(expr, OpExpr))
1976  args = ((OpExpr *) expr)->args;
1977  else if (IsA(expr, DistinctExpr))
1978  args = ((DistinctExpr *) expr)->args;
1979  else if (IsA(expr, ScalarArrayOpExpr))
1980  args = ((ScalarArrayOpExpr *) expr)->args;
1981  else if (IsA(expr, NullIfExpr))
1982  args = ((NullIfExpr *) expr)->args;
1983  else if (IsA(expr, WindowFunc))
1984  args = ((WindowFunc *) expr)->args;
1985  else
1986  return false;
1987 
1988  if (argnum < 0 || argnum >= list_length(args))
1989  return false;
1990 
1991  arg = (Node *) list_nth(args, argnum);
1992 
1993  /*
1994  * Either a true Const or an external Param will have a value that doesn't
1995  * change during the execution of the query. In future we might want to
1996  * consider other cases too, e.g. now().
1997  */
1998  if (IsA(arg, Const))
1999  return true;
2000  if (IsA(arg, Param) &&
2001  ((Param *) arg)->paramkind == PARAM_EXTERN)
2002  return true;
2003 
2004  return false;
2005 }
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:345
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 1900 of file fmgr.c.

1901 {
1902  List *args;
1903  Oid argtype;
1904 
1905  if (expr == NULL)
1906  return InvalidOid;
1907 
1908  if (IsA(expr, FuncExpr))
1909  args = ((FuncExpr *) expr)->args;
1910  else if (IsA(expr, OpExpr))
1911  args = ((OpExpr *) expr)->args;
1912  else if (IsA(expr, DistinctExpr))
1913  args = ((DistinctExpr *) expr)->args;
1914  else if (IsA(expr, ScalarArrayOpExpr))
1915  args = ((ScalarArrayOpExpr *) expr)->args;
1916  else if (IsA(expr, NullIfExpr))
1917  args = ((NullIfExpr *) expr)->args;
1918  else if (IsA(expr, WindowFunc))
1919  args = ((WindowFunc *) expr)->args;
1920  else
1921  return InvalidOid;
1922 
1923  if (argnum < 0 || argnum >= list_length(args))
1924  return InvalidOid;
1925 
1926  argtype = exprType((Node *) list_nth(args, argnum));
1927 
1928  /*
1929  * special hack for ScalarArrayOpExpr: what the underlying function will
1930  * actually get passed is the element type of the array.
1931  */
1932  if (IsA(expr, ScalarArrayOpExpr) &&
1933  argnum == 1)
1934  argtype = get_base_element_type(argtype);
1935 
1936  return argtype;
1937 }
Oid get_base_element_type(Oid typid)
Definition: lsyscache.c:2790
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 1946 of file fmgr.c.

1947 {
1948  /*
1949  * can't return anything useful if we have no FmgrInfo or if its fn_expr
1950  * node has not been initialized
1951  */
1952  if (!flinfo || !flinfo->fn_expr)
1953  return false;
1954 
1955  return get_call_expr_arg_stable(flinfo->fn_expr, argnum);
1956 }
bool get_call_expr_arg_stable(Node *expr, int argnum)
Definition: fmgr.c:1965

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

1860 {
1861  Node *expr;
1862 
1863  /*
1864  * can't return anything useful if we have no FmgrInfo or if its fn_expr
1865  * node has not been initialized
1866  */
1867  if (!flinfo || !flinfo->fn_expr)
1868  return InvalidOid;
1869 
1870  expr = flinfo->fn_expr;
1871 
1872  return exprType(expr);
1873 }

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

2016 {
2017  Node *expr;
2018 
2019  /*
2020  * can't return anything useful if we have no FmgrInfo or if its fn_expr
2021  * node has not been initialized
2022  */
2023  if (!flinfo || !flinfo->fn_expr)
2024  return false;
2025 
2026  expr = flinfo->fn_expr;
2027 
2028  if (IsA(expr, FuncExpr))
2029  return ((FuncExpr *) expr)->funcvariadic;
2030  else
2031  return false;
2032 }

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

2069 {
2070  if (flinfo && flinfo->fn_expr && IsA(flinfo->fn_expr, Const))
2071  {
2072  Const *expr = (Const *) flinfo->fn_expr;
2073 
2074  if (expr->consttype == BYTEAOID)
2075  return expr->constisnull ? NULL : DatumGetByteaP(expr->constvalue);
2076  }
2077 
2078  ereport(ERROR,
2079  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2080  errmsg("operator class options info is absent in function call context")));
2081 
2082  return NULL;
2083 }
#define DatumGetByteaP(X)
Definition: fmgr.h:331
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
Oid consttype
Definition: primnodes.h:290

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

2053 {
2054  if (flinfo && flinfo->fn_expr && IsA(flinfo->fn_expr, Const))
2055  {
2056  Const *expr = (Const *) flinfo->fn_expr;
2057 
2058  if (expr->consttype == BYTEAOID)
2059  return !expr->constisnull;
2060  }
2061  return false;
2062 }

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

◆ InputFunctionCall()

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

Definition at line 1501 of file fmgr.c.

1502 {
1503  LOCAL_FCINFO(fcinfo, 3);
1504  Datum result;
1505 
1506  if (str == NULL && flinfo->fn_strict)
1507  return (Datum) 0; /* just return null result */
1508 
1509  InitFunctionCallInfoData(*fcinfo, flinfo, 3, InvalidOid, NULL, NULL);
1510 
1511  fcinfo->args[0].value = CStringGetDatum(str);
1512  fcinfo->args[0].isnull = false;
1513  fcinfo->args[1].value = ObjectIdGetDatum(typioparam);
1514  fcinfo->args[1].isnull = false;
1515  fcinfo->args[2].value = Int32GetDatum(typmod);
1516  fcinfo->args[2].isnull = false;
1517 
1518  result = FunctionCallInvoke(fcinfo);
1519 
1520  /* Should get null result if and only if str is NULL */
1521  if (str == NULL)
1522  {
1523  if (!fcinfo->isnull)
1524  elog(ERROR, "input function %u returned non-NULL",
1525  flinfo->fn_oid);
1526  }
1527  else
1528  {
1529  if (fcinfo->isnull)
1530  elog(ERROR, "input function %u returned NULL",
1531  flinfo->fn_oid);
1532  }
1533 
1534  return result;
1535 }

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

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

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

1779 {
1780  int64 *retval = (int64 *) palloc(sizeof(int64));
1781 
1782  *retval = X;
1783  return PointerGetDatum(retval);
1784 }

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

1373 {
1374  FmgrInfo flinfo;
1375 
1376  fmgr_info(functionId, &flinfo);
1377 
1378  return FunctionCall0Coll(&flinfo, collation);
1379 }
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:127
Datum FunctionCall0Coll(FmgrInfo *flinfo, Oid collation)
Definition: fmgr.c:1083

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

◆ OidFunctionCall1Coll()

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

Definition at line 1382 of file fmgr.c.

1383 {
1384  FmgrInfo flinfo;
1385 
1386  fmgr_info(functionId, &flinfo);
1387 
1388  return FunctionCall1Coll(&flinfo, collation, arg1);
1389 }
Datum FunctionCall1Coll(FmgrInfo *flinfo, Oid collation, Datum arg1)
Definition: fmgr.c:1100

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

1393 {
1394  FmgrInfo flinfo;
1395 
1396  fmgr_info(functionId, &flinfo);
1397 
1398  return FunctionCall2Coll(&flinfo, collation, arg1, arg2);
1399 }
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:1120

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

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

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

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

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

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

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

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

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

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

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

1464 {
1465  FmgrInfo flinfo;
1466 
1467  fmgr_info(functionId, &flinfo);
1468 
1469  return FunctionCall8Coll(&flinfo, collation, arg1, arg2, arg3, arg4, arg5,
1470  arg6, arg7, arg8);
1471 }
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:1289

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

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

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

◆ OidInputFunctionCall()

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

Definition at line 1725 of file fmgr.c.

1726 {
1727  FmgrInfo flinfo;
1728 
1729  fmgr_info(functionId, &flinfo);
1730  return InputFunctionCall(&flinfo, str, typioparam, typmod);
1731 }
Datum InputFunctionCall(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
Definition: fmgr.c:1501

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

1745 {
1746  FmgrInfo flinfo;
1747 
1748  fmgr_info(functionId, &flinfo);
1749  return ReceiveFunctionCall(&flinfo, buf, typioparam, typmod);
1750 }
Datum ReceiveFunctionCall(FmgrInfo *flinfo, StringInfo buf, Oid typioparam, int32 typmod)
Definition: fmgr.c:1668
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 1753 of file fmgr.c.

1754 {
1755  FmgrInfo flinfo;
1756 
1757  fmgr_info(functionId, &flinfo);
1758  return SendFunctionCall(&flinfo, val);
1759 }
bytea * SendFunctionCall(FmgrInfo *flinfo, Datum val)
Definition: fmgr.c:1715

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

1804 {
1805  if (VARATT_IS_EXTENDED(datum))
1806  return detoast_attr(datum);
1807  else
1808  return datum;
1809 }
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 1812 of file fmgr.c.

1813 {
1814  if (VARATT_IS_EXTENDED(datum))
1815  return detoast_attr(datum);
1816  else
1817  {
1818  /* Make a modifiable copy of the varlena object */
1819  Size len = VARSIZE(datum);
1820  struct varlena *result = (struct varlena *) palloc(len);
1821 
1822  memcpy(result, datum, len);
1823  return result;
1824  }
1825 }
size_t Size
Definition: c.h:589
const void size_t len
Definition: c.h:671
#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 1835 of file fmgr.c.

1836 {
1837  if (VARATT_IS_COMPRESSED(datum) || VARATT_IS_EXTERNAL(datum))
1838  return detoast_attr(datum);
1839  else
1840  return datum;
1841 }
#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 1828 of file fmgr.c.

1829 {
1830  /* Only get the specified portion from the toast rel */
1831  return detoast_attr_slice(datum, first, count);
1832 }
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 1668 of file fmgr.c.

1670 {
1671  LOCAL_FCINFO(fcinfo, 3);
1672  Datum result;
1673 
1674  if (buf == NULL && flinfo->fn_strict)
1675  return (Datum) 0; /* just return null result */
1676 
1677  InitFunctionCallInfoData(*fcinfo, flinfo, 3, InvalidOid, NULL, NULL);
1678 
1679  fcinfo->args[0].value = PointerGetDatum(buf);
1680  fcinfo->args[0].isnull = false;
1681  fcinfo->args[1].value = ObjectIdGetDatum(typioparam);
1682  fcinfo->args[1].isnull = false;
1683  fcinfo->args[2].value = Int32GetDatum(typmod);
1684  fcinfo->args[2].isnull = false;
1685 
1686  result = FunctionCallInvoke(fcinfo);
1687 
1688  /* Should get null result if and only if buf is NULL */
1689  if (buf == NULL)
1690  {
1691  if (!fcinfo->isnull)
1692  elog(ERROR, "receive function %u returned non-NULL",
1693  flinfo->fn_oid);
1694  }
1695  else
1696  {
1697  if (fcinfo->isnull)
1698  elog(ERROR, "receive function %u returned NULL",
1699  flinfo->fn_oid);
1700  }
1701 
1702  return result;
1703 }

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

2042 {
2043  flinfo->fn_expr = (Node *) makeConst(BYTEAOID, -1, InvalidOid, -1,
2045  options == NULL, false);
2046 }
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().