PostgreSQL Source Code git master
Loading...
Searching...
No Matches
fmgr.c File Reference
#include "postgres.h"
#include "access/detoast.h"
#include "access/htup_details.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, Node *escontext, Datum *result)
 
bool DirectInputFunctionCallSafe (PGFunction func, char *str, Oid typioparam, int32 typmod, Node *escontext, Datum *result)
 
charOutputFunctionCall (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)
 
charOidOutputFunctionCall (Oid functionId, Datum val)
 
Datum OidReceiveFunctionCall (Oid functionId, StringInfo buf, Oid typioparam, int32 typmod)
 
byteaOidSendFunctionCall (Oid functionId, Datum val)
 
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 1066 of file fmgr.c.

1067{
1068 LOCAL_FCINFO(fcinfo, 1);
1069 Datum result;
1070
1071 InitFunctionCallInfoData(*fcinfo, flinfo, 1, collation, NULL, NULL);
1072
1073 fcinfo->args[0].value = arg1;
1074 fcinfo->args[0].isnull = false;
1075
1076 result = (*func) (fcinfo);
1077
1078 /* Check for null result, since caller is clearly not expecting one */
1079 if (fcinfo->isnull)
1080 elog(ERROR, "function %p returned NULL", (void *) func);
1081
1082 return result;
1083}
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition fmgr.h:150
#define LOCAL_FCINFO(name, nargs)
Definition fmgr.h:110
uint64_t Datum
Definition postgres.h:70
static int fb(int x)

References elog, ERROR, fb(), 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 1086 of file fmgr.c.

1087{
1088 LOCAL_FCINFO(fcinfo, 2);
1089 Datum result;
1090
1091 InitFunctionCallInfoData(*fcinfo, flinfo, 2, collation, NULL, NULL);
1092
1093 fcinfo->args[0].value = arg1;
1094 fcinfo->args[0].isnull = false;
1095 fcinfo->args[1].value = arg2;
1096 fcinfo->args[1].isnull = false;
1097
1098 result = (*func) (fcinfo);
1099
1100 /* Check for null result, since caller is clearly not expecting one */
1101 if (fcinfo->isnull)
1102 elog(ERROR, "function %p returned NULL", (void *) func);
1103
1104 return result;
1105}

References elog, ERROR, fb(), fmgr_security_definer_cache::flinfo, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by gbt_enum_ssup_cmp(), 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 2110 of file fmgr.c.

2111{
2117
2118 /*
2119 * Get the function's pg_proc entry. Throw a user-facing error for bad
2120 * OID, because validators can be called with user-specified OIDs.
2121 */
2124 ereport(ERROR,
2126 errmsg("function with OID %u does not exist", functionOid)));
2128
2129 /*
2130 * Fetch pg_language entry to know if this is the correct validation
2131 * function for that pg_proc entry.
2132 */
2135 elog(ERROR, "cache lookup failed for language %u", procStruct->prolang);
2137
2138 if (langStruct->lanvalidator != validatorOid)
2139 ereport(ERROR,
2141 errmsg("language validation function %u called for language %u instead of %u",
2142 validatorOid, procStruct->prolang,
2143 langStruct->lanvalidator)));
2144
2145 /* first validate that we have permissions to use the language */
2147 ACL_USAGE);
2148 if (aclresult != ACLCHECK_OK)
2150 NameStr(langStruct->lanname));
2151
2152 /*
2153 * Check whether we are allowed to execute the function itself. If we can
2154 * execute it, there should be no possible side-effect of
2155 * compiling/validation that execution can't have.
2156 */
2158 if (aclresult != ACLCHECK_OK)
2160
2163
2164 return true;
2165}
AclResult
Definition acl.h:182
@ ACLCHECK_OK
Definition acl.h:183
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition aclchk.c:2654
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
Definition aclchk.c:3836
#define NameStr(name)
Definition c.h:765
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define ereport(elevel,...)
Definition elog.h:150
#define HeapTupleIsValid(tuple)
Definition htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
Oid GetUserId(void)
Definition miscinit.c:469
#define ACL_USAGE
Definition parsenodes.h:84
@ OBJECT_LANGUAGE
@ OBJECT_FUNCTION
#define ACL_EXECUTE
Definition parsenodes.h:83
FormData_pg_language * Form_pg_language
Definition pg_language.h:65
FormData_pg_proc * Form_pg_proc
Definition pg_proc.h:136
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:262
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:264
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition syscache.c:220

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

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

◆ DirectFunctionCall1Coll()

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

Definition at line 793 of file fmgr.c.

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

References elog, ERROR, fb(), 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 813 of file fmgr.c.

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

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

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

◆ DirectFunctionCall3Coll()

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

Definition at line 835 of file fmgr.c.

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

References elog, ERROR, fb(), 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 860 of file fmgr.c.

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

References elog, ERROR, fb(), 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 887 of file fmgr.c.

889{
890 LOCAL_FCINFO(fcinfo, 5);
891 Datum result;
892
893 InitFunctionCallInfoData(*fcinfo, NULL, 5, 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
906 result = (*func) (fcinfo);
907
908 /* Check for null result, since caller is clearly not expecting one */
909 if (fcinfo->isnull)
910 elog(ERROR, "function %p returned NULL", (void *) func);
911
912 return result;
913}

References elog, ERROR, fb(), 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 916 of file fmgr.c.

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

References elog, ERROR, fb(), 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 948 of file fmgr.c.

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

References elog, ERROR, fb(), 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 982 of file fmgr.c.

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

References elog, ERROR, fb(), 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 1018 of file fmgr.c.

1022{
1023 LOCAL_FCINFO(fcinfo, 9);
1024 Datum result;
1025
1026 InitFunctionCallInfoData(*fcinfo, NULL, 9, collation, NULL, NULL);
1027
1028 fcinfo->args[0].value = arg1;
1029 fcinfo->args[0].isnull = false;
1030 fcinfo->args[1].value = arg2;
1031 fcinfo->args[1].isnull = false;
1032 fcinfo->args[2].value = arg3;
1033 fcinfo->args[2].isnull = false;
1034 fcinfo->args[3].value = arg4;
1035 fcinfo->args[3].isnull = false;
1036 fcinfo->args[4].value = arg5;
1037 fcinfo->args[4].isnull = false;
1038 fcinfo->args[5].value = arg6;
1039 fcinfo->args[5].isnull = false;
1040 fcinfo->args[6].value = arg7;
1041 fcinfo->args[6].isnull = false;
1042 fcinfo->args[7].value = arg8;
1043 fcinfo->args[7].isnull = false;
1044 fcinfo->args[8].value = arg9;
1045 fcinfo->args[8].isnull = false;
1046
1047 result = (*func) (fcinfo);
1048
1049 /* Check for null result, since caller is clearly not expecting one */
1050 if (fcinfo->isnull)
1051 elog(ERROR, "function %p returned NULL", (void *) func);
1052
1053 return result;
1054}

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

◆ DirectInputFunctionCallSafe()

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

Definition at line 1640 of file fmgr.c.

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

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

Referenced by executeItemOptUnwrapTarget(), jsonb_in_scalar(), parseNumericOid(), to_regclass(), to_regcollation(), to_regdatabase(), 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 456 of file fmgr.c.

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

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

Referenced by fmgr_c_validator(), and fmgr_info_C_lang().

◆ fmgr_info()

void fmgr_info ( Oid  functionId,
FmgrInfo finfo 
)

Definition at line 128 of file fmgr.c.

129{
131}
static void fmgr_info_cxt_security(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt, bool ignore_security)
Definition fmgr.c:148
MemoryContext CurrentMemoryContext
Definition mcxt.c:160

References CurrentMemoryContext, fb(), and fmgr_info_cxt_security().

Referenced by _bt_find_extreme_element(), _bt_saoparray_shrink(), _bt_skiparray_strat_decrement(), _bt_skiparray_strat_increment(), _sv_to_datum_finfo(), attribute_statistics_update(), brin_minmax_multi_summary_out(), brin_page_items(), build_pertrans_for_aggref(), call_pltcl_start_proc(), CompareOpclassOptions(), compute_distinct_stats(), CopyFromBinaryInFunc(), CopyFromTextLikeInFunc(), CopyToBinaryOutFunc(), CopyToTextLikeOutFunc(), create_foreign_modify(), eqjoinsel(), eqjoinsel_find_matches(), EventTriggerInvoke(), ExecBuildGroupingEqual(), ExecBuildHash32Expr(), ExecBuildParamSetEqual(), ExecCallTriggerFunc(), ExecEvalHashedScalarArrayOp(), ExecInitAgg(), ExecInitExprRec(), ExecInitFunc(), ExecInitHashJoin(), ExecInitJsonExpr(), 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(), serialize_prepare_info(), statext_mcv_import(), 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 350 of file fmgr.c.

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

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

Referenced by fmgr_info_cxt_security().

◆ fmgr_info_copy()

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

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

420{
422 Oid language = procedureStruct->prolang;
426
429 elog(ERROR, "cache lookup failed for language %u", language);
431
432 /*
433 * Look up the language's call handler function, ignoring any attributes
434 * that would normally cause insertion of fmgr_security_definer. We need
435 * to get back a bare pointer to the actual C-language function.
436 */
439 finfo->fn_addr = plfinfo.fn_addr;
440
442}
unsigned int Oid

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

Referenced by fmgr_info_cxt_security().

◆ fmgr_internal_function()

Oid fmgr_internal_function ( const char proname)

Definition at line 596 of file fmgr.c.

597{
599
600 if (fbp == NULL)
601 return InvalidOid;
602 return fbp->foid;
603}
NameData proname
Definition pg_proc.h:35

References fb(), fmgr_lookupByName(), InvalidOid, and proname.

Referenced by fmgr_internal_validator().

◆ fmgr_isbuiltin()

static const FmgrBuiltin * fmgr_isbuiltin ( Oid  id)
static

Definition at line 77 of file fmgr.c.

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

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

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

References fb(), 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  )
extern

Definition at line 633 of file fmgr.c.

634{
635 Datum result;
636 struct fmgr_security_definer_cache *volatile fcache;
638 Oid save_userid;
639 int save_sec_context;
640 ListCell *lc1,
641 *lc2,
642 *lc3;
643 int save_nestlevel;
645
646 if (!fcinfo->flinfo->fn_extra)
647 {
648 HeapTuple tuple;
650 Datum datum;
651 bool isnull;
653
654 fcache = MemoryContextAllocZero(fcinfo->flinfo->fn_mcxt,
655 sizeof(*fcache));
656
657 fmgr_info_cxt_security(fcinfo->flinfo->fn_oid, &fcache->flinfo,
658 fcinfo->flinfo->fn_mcxt, true);
659 fcache->flinfo.fn_expr = fcinfo->flinfo->fn_expr;
660
661 tuple = SearchSysCache1(PROCOID,
662 ObjectIdGetDatum(fcinfo->flinfo->fn_oid));
663 if (!HeapTupleIsValid(tuple))
664 elog(ERROR, "cache lookup failed for function %u",
665 fcinfo->flinfo->fn_oid);
667
668 if (procedureStruct->prosecdef)
669 fcache->userid = procedureStruct->proowner;
670
672 &isnull);
673 if (!isnull)
674 {
675 ArrayType *array;
676 ListCell *lc;
677
678 oldcxt = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
679 array = DatumGetArrayTypeP(datum);
680 TransformGUCArray(array, &fcache->configNames,
681 &fcache->configValues);
682
683 /* transform names to config handles to avoid lookup cost */
684 fcache->configHandles = NIL;
685 foreach(lc, fcache->configNames)
686 {
687 char *name = (char *) lfirst(lc);
688
689 fcache->configHandles = lappend(fcache->configHandles,
691 }
692
694 }
695
696 ReleaseSysCache(tuple);
697
698 fcinfo->flinfo->fn_extra = fcache;
699 }
700 else
701 fcache = fcinfo->flinfo->fn_extra;
702
703 /* GetUserIdAndSecContext is cheap enough that no harm in a wasted call */
704 GetUserIdAndSecContext(&save_userid, &save_sec_context);
705 if (fcache->configNames != NIL) /* Need a new GUC nesting level */
706 save_nestlevel = NewGUCNestLevel();
707 else
708 save_nestlevel = 0; /* keep compiler quiet */
709
710 if (OidIsValid(fcache->userid))
712 save_sec_context | SECURITY_LOCAL_USERID_CHANGE);
713
714 forthree(lc1, fcache->configNames,
715 lc2, fcache->configHandles,
716 lc3, fcache->configValues)
717 {
721 char *name = lfirst(lc1);
722 config_handle *handle = lfirst(lc2);
723 char *value = lfirst(lc3);
724
726 context, source, GetUserId(),
727 action, true, 0, false);
728 }
729
730 /* function manager hook */
731 if (fmgr_hook)
732 (*fmgr_hook) (FHET_START, &fcache->flinfo, &fcache->arg);
733
734 /*
735 * We don't need to restore GUC or userid settings on error, because the
736 * ensuing xact or subxact abort will do that. The PG_TRY block is only
737 * needed to clean up the flinfo link.
738 */
739 save_flinfo = fcinfo->flinfo;
740
741 PG_TRY();
742 {
743 fcinfo->flinfo = &fcache->flinfo;
744
745 /* See notes in fmgr_info_cxt_security */
747
748 result = FunctionCallInvoke(fcinfo);
749
750 /*
751 * We could be calling either a regular or a set-returning function,
752 * so we have to test to see what finalize flag to use.
753 */
755 (fcinfo->resultinfo == NULL ||
756 !IsA(fcinfo->resultinfo, ReturnSetInfo) ||
757 ((ReturnSetInfo *) fcinfo->resultinfo)->isDone != ExprMultipleResult));
758 }
759 PG_CATCH();
760 {
761 fcinfo->flinfo = save_flinfo;
762 if (fmgr_hook)
763 (*fmgr_hook) (FHET_ABORT, &fcache->flinfo, &fcache->arg);
764 PG_RE_THROW();
765 }
766 PG_END_TRY();
767
768 fcinfo->flinfo = save_flinfo;
769
770 if (fcache->configNames != NIL)
771 AtEOXact_GUC(true, save_nestlevel);
772 if (OidIsValid(fcache->userid))
773 SetUserIdAndSecContext(save_userid, save_sec_context);
774 if (fmgr_hook)
775 (*fmgr_hook) (FHET_END, &fcache->flinfo, &fcache->arg);
776
777 return result;
778}
#define DatumGetArrayTypeP(X)
Definition array.h:261
#define OidIsValid(objectId)
Definition c.h:788
#define PG_RE_THROW()
Definition elog.h:405
#define PG_TRY(...)
Definition elog.h:372
#define PG_END_TRY(...)
Definition elog.h:397
#define PG_CATCH(...)
Definition elog.h:382
@ ExprMultipleResult
Definition execnodes.h:330
PGDLLIMPORT fmgr_hook_type fmgr_hook
Definition fmgr.c:41
@ FHET_END
Definition fmgr.h:838
@ FHET_ABORT
Definition fmgr.h:839
@ FHET_START
Definition fmgr.h:837
#define FunctionCallInvoke(fcinfo)
Definition fmgr.h:172
int NewGUCNestLevel(void)
Definition guc.c:2110
config_handle * get_config_handle(const char *name)
Definition guc.c:4148
int set_config_with_handle(const char *name, config_handle *handle, const char *value, GucContext context, GucSource source, Oid srole, GucAction action, bool changeVal, int elevel, bool is_reload)
Definition guc.c:3279
void TransformGUCArray(ArrayType *array, List **names, List **values)
Definition guc.c:6241
void AtEOXact_GUC(bool isCommit, int nestLevel)
Definition guc.c:2137
GucAction
Definition guc.h:201
@ GUC_ACTION_SAVE
Definition guc.h:205
GucSource
Definition guc.h:112
@ PGC_S_SESSION
Definition guc.h:126
GucContext
Definition guc.h:72
@ PGC_SUSET
Definition guc.h:78
@ PGC_USERSET
Definition guc.h:79
static struct @172 value
List * lappend(List *list, void *datum)
Definition list.c:339
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition mcxt.c:1266
#define SECURITY_LOCAL_USERID_CHANGE
Definition miscadmin.h:318
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
Definition miscinit.c:612
void SetUserIdAndSecContext(Oid userid, int sec_context)
Definition miscinit.c:619
#define IsA(nodeptr, _type_)
Definition nodes.h:164
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124
#define lfirst(lc)
Definition pg_list.h:172
#define NIL
Definition pg_list.h:68
#define forthree(cell1, list1, cell2, list2, cell3, list3)
Definition pg_list.h:563
static rewind_source * source
Definition pg_rewind.c:89
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
bool superuser(void)
Definition superuser.c:46
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition syscache.c:595

References AtEOXact_GUC(), DatumGetArrayTypeP, elog, ERROR, ExprMultipleResult, fb(), FHET_ABORT, FHET_END, FHET_START, fmgr_hook, fmgr_info_cxt_security(), forthree, FunctionCallInvoke, get_config_handle(), GETSTRUCT(), GetUserId(), GetUserIdAndSecContext(), GUC_ACTION_SAVE, HeapTupleIsValid, IsA, lappend(), lfirst, MemoryContextAllocZero(), MemoryContextSwitchTo(), name, NewGUCNestLevel(), NIL, ObjectIdGetDatum(), OidIsValid, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, PGC_S_SESSION, PGC_SUSET, PGC_USERSET, pgstat_end_function_usage(), pgstat_init_function_usage(), ReleaseSysCache(), SearchSysCache1(), SECURITY_LOCAL_USERID_CHANGE, set_config_with_handle(), SetUserIdAndSecContext(), source, superuser(), SysCacheGetAttr(), TransformGUCArray(), and value.

Referenced by fmgr_info_cxt_security().

◆ fmgr_symbol()

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

Definition at line 282 of file fmgr.c.

283{
288
291 elog(ERROR, "cache lookup failed for function %u", functionId);
293
294 if (procedureStruct->prosecdef ||
297 {
298 *mod = NULL; /* core binary */
299 *fn = pstrdup("fmgr_security_definer");
301 return;
302 }
303
304 /* see fmgr_info_cxt_security for the individual cases */
305 switch (procedureStruct->prolang)
306 {
310
311 *mod = NULL; /* core binary */
313 break;
314
315 case ClanguageId:
318
321
322 /*
323 * No need to check symbol presence / API version here, already
324 * checked in fmgr_info_cxt_security.
325 */
328 break;
329
330 case SQLlanguageId:
331 *mod = NULL; /* core binary */
332 *fn = pstrdup("fmgr_sql");
333 break;
334
335 default:
336 *mod = NULL;
337 *fn = NULL; /* unknown, pass pointer */
338 break;
339 }
340
342}
char * pstrdup(const char *in)
Definition mcxt.c:1781
static void * fn(void *arg)

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

Referenced by llvm_function_reference().

◆ FunctionCall0Coll()

Datum FunctionCall0Coll ( FmgrInfo flinfo,
Oid  collation 
)

Definition at line 1113 of file fmgr.c.

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

References elog, ERROR, fb(), 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 1130 of file fmgr.c.

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

References elog, ERROR, fb(), 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(), gistCompressValues(), gistdentryinit(), gistFetchAtt(), hash_multirange(), hash_range(), MemoizeHash_hash(), OidFunctionCall1Coll(), signValue(), and spgdoinsert().

◆ FunctionCall2Coll()

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

Definition at line 1150 of file fmgr.c.

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

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

Referenced by _bt_array_decrement(), _bt_array_increment(), _bt_binsrch_skiparray_skey(), _bt_check_compare(), _bt_check_rowcompare(), _bt_compare(), _bt_compare_array_elements(), _bt_compare_array_skey(), _bt_compare_scankey_args(), _bt_find_extreme_element(), _bt_keep_natts(), _bt_set_startikey(), _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(), CompareOpclassOptions(), compute_distinct_stats(), compute_partition_hash_value(), compute_range_stats(), create_range_bounds(), doPickSplit(), element_compare(), element_compare(), ExecEvalPreOrderedDistinctSingle(), execTuplesUnequal(), find_value_in_new_partitions_list(), genericPickSplit(), get_distance(), get_distance(), get_partition_for_tuple(), get_position(), 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(), partitions_listdatum_intersection(), process_ordered_aggregate_single(), qsort_partition_list_value_cmp(), range_cmp_bound_values(), range_cmp_bounds(), range_contains_elem_internal(), range_contains_value(), ri_CompareWithCast(), 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 1172 of file fmgr.c.

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

References elog, ERROR, fb(), 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 1197 of file fmgr.c.

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

References elog, ERROR, fb(), 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 1224 of file fmgr.c.

1226{
1227 LOCAL_FCINFO(fcinfo, 5);
1228 Datum result;
1229
1230 InitFunctionCallInfoData(*fcinfo, flinfo, 5, 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
1243 result = FunctionCallInvoke(fcinfo);
1244
1245 /* Check for null result, since caller is clearly not expecting one */
1246 if (fcinfo->isnull)
1247 elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1248
1249 return result;
1250}

References elog, ERROR, fb(), 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 1253 of file fmgr.c.

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

References elog, ERROR, fb(), 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 1285 of file fmgr.c.

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

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

Referenced by directTriConsistentFn(), gincost_pattern(), ginNewScanKey(), 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 1319 of file fmgr.c.

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

References elog, ERROR, fb(), 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 1355 of file fmgr.c.

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

References elog, ERROR, fb(), 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 1959 of file fmgr.c.

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

References arg, fb(), 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 1894 of file fmgr.c.

1895{
1896 List *args;
1897 Oid argtype;
1898
1899 if (expr == NULL)
1900 return InvalidOid;
1901
1902 if (IsA(expr, FuncExpr))
1903 args = ((FuncExpr *) expr)->args;
1904 else if (IsA(expr, OpExpr))
1905 args = ((OpExpr *) expr)->args;
1906 else if (IsA(expr, DistinctExpr))
1907 args = ((DistinctExpr *) expr)->args;
1908 else if (IsA(expr, ScalarArrayOpExpr))
1909 args = ((ScalarArrayOpExpr *) expr)->args;
1910 else if (IsA(expr, NullIfExpr))
1911 args = ((NullIfExpr *) expr)->args;
1912 else if (IsA(expr, WindowFunc))
1913 args = ((WindowFunc *) expr)->args;
1914 else
1915 return InvalidOid;
1916
1918 return InvalidOid;
1919
1920 argtype = exprType((Node *) list_nth(args, argnum));
1921
1922 /*
1923 * special hack for ScalarArrayOpExpr: what the underlying function will
1924 * actually get passed is the element type of the array.
1925 */
1926 if (IsA(expr, ScalarArrayOpExpr) &&
1927 argnum == 1)
1928 argtype = get_base_element_type(argtype);
1929
1930 return argtype;
1931}
Oid get_base_element_type(Oid typid)
Definition lsyscache.c:2982
Oid exprType(const Node *expr)
Definition nodeFuncs.c:42

References exprType(), fb(), get_base_element_type(), InvalidOid, IsA, list_length(), and list_nth().

Referenced by cfunc_resolve_polymorphic_argtypes(), 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 1940 of file fmgr.c.

1941{
1942 /*
1943 * can't return anything useful if we have no FmgrInfo or if its fn_expr
1944 * node has not been initialized
1945 */
1946 if (!flinfo || !flinfo->fn_expr)
1947 return false;
1948
1949 return get_call_expr_arg_stable(flinfo->fn_expr, argnum);
1950}
bool get_call_expr_arg_stable(Node *expr, int argnum)
Definition fmgr.c:1959

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

1854{
1855 Node *expr;
1856
1857 /*
1858 * can't return anything useful if we have no FmgrInfo or if its fn_expr
1859 * node has not been initialized
1860 */
1861 if (!flinfo || !flinfo->fn_expr)
1862 return InvalidOid;
1863
1864 expr = flinfo->fn_expr;
1865
1866 return exprType(expr);
1867}

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

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

◆ get_fn_expr_variadic()

bool get_fn_expr_variadic ( FmgrInfo flinfo)

Definition at line 2009 of file fmgr.c.

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

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

2063{
2064 if (flinfo && flinfo->fn_expr && IsA(flinfo->fn_expr, Const))
2065 {
2066 Const *expr = (Const *) flinfo->fn_expr;
2067
2068 if (expr->consttype == BYTEAOID)
2069 return expr->constisnull ? NULL : DatumGetByteaP(expr->constvalue);
2070 }
2071
2072 ereport(ERROR,
2074 errmsg("operator class options info is absent in function call context")));
2075
2076 return NULL;
2077}
#define DatumGetByteaP(X)
Definition fmgr.h:332

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

◆ has_fn_opclass_options()

bool has_fn_opclass_options ( FmgrInfo flinfo)

Definition at line 2046 of file fmgr.c.

2047{
2048 if (flinfo && flinfo->fn_expr && IsA(flinfo->fn_expr, Const))
2049 {
2050 Const *expr = (Const *) flinfo->fn_expr;
2051
2052 if (expr->consttype == BYTEAOID)
2053 return !expr->constisnull;
2054 }
2055 return false;
2056}

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

◆ InputFunctionCall()

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

Definition at line 1531 of file fmgr.c.

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

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

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

◆ InputFunctionCallSafe()

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

Definition at line 1585 of file fmgr.c.

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

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

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

◆ lookup_C_func()

static CFuncHashTabEntry * lookup_C_func ( HeapTuple  procedureTuple)
static

Definition at line 516 of file fmgr.c.

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

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

Referenced by fmgr_info_C_lang().

◆ OidFunctionCall0Coll()

Datum OidFunctionCall0Coll ( Oid  functionId,
Oid  collation 
)

Definition at line 1402 of file fmgr.c.

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

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

◆ OidFunctionCall1Coll()

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

Definition at line 1412 of file fmgr.c.

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

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

Referenced by _bt_allequalimage(), _hash_datum2hashkey_type(), create_grouping_expr_infos(), gisttranslatecmptype(), and init_grouping_targets().

◆ OidFunctionCall2Coll()

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

Definition at line 1422 of file fmgr.c.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

◆ OidInputFunctionCall()

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

Definition at line 1754 of file fmgr.c.

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

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

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

◆ OidOutputFunctionCall()

◆ OidReceiveFunctionCall()

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

Definition at line 1772 of file fmgr.c.

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

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

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

◆ OidSendFunctionCall()

bytea * OidSendFunctionCall ( Oid  functionId,
Datum  val 
)

Definition at line 1782 of file fmgr.c.

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

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

1798{
1799 if (VARATT_IS_EXTENDED(datum))
1800 return detoast_attr(datum);
1801 else
1802 return datum;
1803}
struct varlena * detoast_attr(struct varlena *attr)
Definition detoast.c:116
static bool VARATT_IS_EXTENDED(const void *PTR)
Definition varatt.h:410

References detoast_attr(), and VARATT_IS_EXTENDED().

◆ pg_detoast_datum_copy()

struct varlena * pg_detoast_datum_copy ( struct varlena datum)

Definition at line 1806 of file fmgr.c.

1807{
1808 if (VARATT_IS_EXTENDED(datum))
1809 return detoast_attr(datum);
1810 else
1811 {
1812 /* Make a modifiable copy of the varlena object */
1813 Size len = VARSIZE(datum);
1814 struct varlena *result = (struct varlena *) palloc(len);
1815
1816 memcpy(result, datum, len);
1817 return result;
1818 }
1819}
size_t Size
Definition c.h:619
void * palloc(Size size)
Definition mcxt.c:1387
const void size_t len
Definition c.h:706
static Size VARSIZE(const void *PTR)
Definition varatt.h:298

References detoast_attr(), fb(), 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 1829 of file fmgr.c.

1830{
1831 if (VARATT_IS_COMPRESSED(datum) || VARATT_IS_EXTERNAL(datum))
1832 return detoast_attr(datum);
1833 else
1834 return datum;
1835}
static bool VARATT_IS_EXTERNAL(const void *PTR)
Definition varatt.h:354
static bool VARATT_IS_COMPRESSED(const void *PTR)
Definition varatt.h:347

References detoast_attr(), VARATT_IS_COMPRESSED(), and VARATT_IS_EXTERNAL().

Referenced by escape_json_text(), 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 1822 of file fmgr.c.

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

References detoast_attr_slice().

◆ ReceiveFunctionCall()

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

Definition at line 1697 of file fmgr.c.

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

References buf, elog, ERROR, fb(), 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 540 of file fmgr.c.

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

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

Referenced by fmgr_info_C_lang().

◆ SendFunctionCall()

◆ set_fn_opclass_options()

void set_fn_opclass_options ( FmgrInfo flinfo,
bytea options 
)

Definition at line 2035 of file fmgr.c.

2036{
2037 flinfo->fn_expr = (Node *) makeConst(BYTEAOID, -1, InvalidOid, -1,
2039 options == NULL, false);
2040}
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
Definition makefuncs.c:350

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

Referenced by gincost_pattern(), and index_getprocinfo().

Variable Documentation

◆ CFuncHash

HTAB* CFuncHash = NULL
static

Definition at line 56 of file fmgr.c.

Referenced by lookup_C_func(), and record_C_func().

◆ fmgr_hook

Definition at line 41 of file fmgr.c.

Referenced by fmgr_security_definer(), and sepgsql_init_client_label().

◆ needs_fmgr_hook

Definition at line 40 of file fmgr.c.

Referenced by sepgsql_init_client_label().