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/hsearch.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)
 
varlenapg_detoast_datum (varlena *datum)
 
varlenapg_detoast_datum_copy (varlena *datum)
 
varlenapg_detoast_datum_slice (varlena *datum, int32 first, int32 count)
 
varlenapg_detoast_datum_packed (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 1067 of file fmgr.c.

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

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

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

2112{
2118
2119 /*
2120 * Get the function's pg_proc entry. Throw a user-facing error for bad
2121 * OID, because validators can be called with user-specified OIDs.
2122 */
2125 ereport(ERROR,
2127 errmsg("function with OID %u does not exist", functionOid)));
2129
2130 /*
2131 * Fetch pg_language entry to know if this is the correct validation
2132 * function for that pg_proc entry.
2133 */
2136 elog(ERROR, "cache lookup failed for language %u", procStruct->prolang);
2138
2139 if (langStruct->lanvalidator != validatorOid)
2140 ereport(ERROR,
2142 errmsg("language validation function %u called for language %u instead of %u",
2143 validatorOid, procStruct->prolang,
2144 langStruct->lanvalidator)));
2145
2146 /* first validate that we have permissions to use the language */
2148 ACL_USAGE);
2149 if (aclresult != ACLCHECK_OK)
2151 NameStr(langStruct->lanname));
2152
2153 /*
2154 * Check whether we are allowed to execute the function itself. If we can
2155 * execute it, there should be no possible side-effect of
2156 * compiling/validation that execution can't have.
2157 */
2159 if (aclresult != ACLCHECK_OK)
2161
2164
2165 return true;
2166}
AclResult
Definition acl.h:183
@ ACLCHECK_OK
Definition acl.h:184
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition aclchk.c:2672
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
Definition aclchk.c:3879
#define NameStr(name)
Definition c.h:837
int errcode(int sqlerrcode)
Definition elog.c:874
#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:470
static char * errmsg
#define ACL_USAGE
Definition parsenodes.h:84
@ OBJECT_LANGUAGE
@ OBJECT_FUNCTION
#define ACL_EXECUTE
Definition parsenodes.h:83
END_CATALOG_STRUCT typedef FormData_pg_language * Form_pg_language
Definition pg_language.h:69
END_CATALOG_STRUCT typedef FormData_pg_proc * Form_pg_proc
Definition pg_proc.h:140
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:265
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:221

References ACL_EXECUTE, ACL_USAGE, aclcheck_error(), ACLCHECK_OK, elog, ereport, errcode(), errmsg, ERROR, fb(), Form_pg_language, Form_pg_proc, 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 794 of file fmgr.c.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Referenced by executeItemOptUnwrapTarget(), jbv_to_infunc_datum(), jsonb_in_scalar(), numeric_float4(), numeric_float8(), 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 457 of file fmgr.c.

458{
459 char *infofuncname;
461 const Pg_finfo_record *inforec;
462
463 infofuncname = psprintf("pg_finfo_%s", funcname);
464
465 /* Try to look up the info function */
468 if (infofunc == NULL)
469 {
472 errmsg("could not find function information for function \"%s\"",
473 funcname),
474 errhint("SQL-callable functions need an accompanying PG_FUNCTION_INFO_V1(funcname).")));
475 return NULL; /* silence compiler */
476 }
477
478 /* Found, so call it */
479 inforec = (*infofunc) ();
480
481 /* Validate result as best we can */
482 if (inforec == NULL)
483 elog(ERROR, "null result from info function \"%s\"", infofuncname);
484 switch (inforec->api_version)
485 {
486 case 1:
487 /* OK, no additional fields to validate */
488 break;
489 default:
492 errmsg("unrecognized API version %d reported by info function \"%s\"",
493 inforec->api_version, infofuncname)));
494 break;
495 }
496
498 return inforec;
499}
void * lookup_external_function(void *filehandle, const char *funcname)
Definition dfmgr.c:171
int errhint(const char *fmt,...) pg_attribute_printf(1
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 129 of file fmgr.c.

130{
132}
static void fmgr_info_cxt_security(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt, bool ignore_security)
Definition fmgr.c:149
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(), import_expressions(), 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 351 of file fmgr.c.

352{
354 PGFunction user_fn;
355 const Pg_finfo_record *inforec;
356
357 /*
358 * See if we have the function address cached already
359 */
361 if (hashentry)
362 {
363 user_fn = hashentry->user_fn;
364 inforec = hashentry->inforec;
365 }
366 else
367 {
370 char *prosrcstring,
372 void *libraryhandle;
373
374 /*
375 * Get prosrc and probin strings (link symbol and library filename).
376 * While in general these columns might be null, that's not allowed
377 * for C-language functions.
378 */
382
386
387 /* Look up the function itself */
390
391 /* Get the function information record (real or default) */
393
394 /* Cache the addresses for later calls */
395 record_C_func(procedureTuple, user_fn, inforec);
396
399 }
400
401 switch (inforec->api_version)
402 {
403 case 1:
404 /* New style: call directly */
405 finfo->fn_addr = user_fn;
406 break;
407 default:
408 /* Shouldn't get here if fetch_finfo_record did its job */
409 elog(ERROR, "unrecognized function API version: %d",
410 inforec->api_version);
411 break;
412 }
413}
#define TextDatumGetCString(d)
Definition builtins.h:99
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:457
static void record_C_func(HeapTuple procedureTuple, PGFunction user_fn, const Pg_finfo_record *inforec)
Definition fmgr.c:541
static CFuncHashTabEntry * lookup_C_func(HeapTuple procedureTuple)
Definition fmgr.c:517
Datum(* PGFunction)(FunctionCallInfo fcinfo)
Definition fmgr.h:40
PGFunction fn_addr
Definition fmgr.h:58
Datum SysCacheGetAttrNotNull(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber)
Definition syscache.c:626

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

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

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

References CurrentMemoryContext, elog, ERROR, fb(), fmgr_info_cxt_security(), FmgrInfo::fn_addr, Form_pg_language, Form_pg_proc, 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 597 of file fmgr.c.

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

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

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

104{
105 int i;
106
107 for (i = 0; i < fmgr_nbuiltins; i++)
108 {
109 if (strcmp(name, fmgr_builtins[i].funcName) == 0)
110 return fmgr_builtins + i;
111 }
112 return NULL;
113}
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 634 of file fmgr.c.

635{
636 Datum result;
637 struct fmgr_security_definer_cache *volatile fcache;
639 Oid save_userid;
640 int save_sec_context;
641 ListCell *lc1,
642 *lc2,
643 *lc3;
644 int save_nestlevel;
646
647 if (!fcinfo->flinfo->fn_extra)
648 {
649 HeapTuple tuple;
651 Datum datum;
652 bool isnull;
654
655 fcache = MemoryContextAllocZero(fcinfo->flinfo->fn_mcxt,
656 sizeof(*fcache));
657
658 fmgr_info_cxt_security(fcinfo->flinfo->fn_oid, &fcache->flinfo,
659 fcinfo->flinfo->fn_mcxt, true);
660 fcache->flinfo.fn_expr = fcinfo->flinfo->fn_expr;
661
662 tuple = SearchSysCache1(PROCOID,
663 ObjectIdGetDatum(fcinfo->flinfo->fn_oid));
664 if (!HeapTupleIsValid(tuple))
665 elog(ERROR, "cache lookup failed for function %u",
666 fcinfo->flinfo->fn_oid);
668
669 if (procedureStruct->prosecdef)
670 fcache->userid = procedureStruct->proowner;
671
673 &isnull);
674 if (!isnull)
675 {
676 ArrayType *array;
677 ListCell *lc;
678
679 oldcxt = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
680 array = DatumGetArrayTypeP(datum);
681 TransformGUCArray(array, &fcache->configNames,
682 &fcache->configValues);
683
684 /* transform names to config handles to avoid lookup cost */
685 fcache->configHandles = NIL;
686 foreach(lc, fcache->configNames)
687 {
688 char *name = (char *) lfirst(lc);
689
690 fcache->configHandles = lappend(fcache->configHandles,
692 }
693
695 }
696
697 ReleaseSysCache(tuple);
698
699 fcinfo->flinfo->fn_extra = fcache;
700 }
701 else
702 fcache = fcinfo->flinfo->fn_extra;
703
704 /* GetUserIdAndSecContext is cheap enough that no harm in a wasted call */
705 GetUserIdAndSecContext(&save_userid, &save_sec_context);
706 if (fcache->configNames != NIL) /* Need a new GUC nesting level */
707 save_nestlevel = NewGUCNestLevel();
708 else
709 save_nestlevel = 0; /* keep compiler quiet */
710
711 if (OidIsValid(fcache->userid))
713 save_sec_context | SECURITY_LOCAL_USERID_CHANGE);
714
715 forthree(lc1, fcache->configNames,
716 lc2, fcache->configHandles,
717 lc3, fcache->configValues)
718 {
722 char *name = lfirst(lc1);
723 config_handle *handle = lfirst(lc2);
724 char *value = lfirst(lc3);
725
727 context, source, GetUserId(),
728 action, true, 0, false);
729 }
730
731 /* function manager hook */
732 if (fmgr_hook)
733 (*fmgr_hook) (FHET_START, &fcache->flinfo, &fcache->arg);
734
735 /*
736 * We don't need to restore GUC or userid settings on error, because the
737 * ensuing xact or subxact abort will do that. The PG_TRY block is only
738 * needed to clean up the flinfo link.
739 */
740 save_flinfo = fcinfo->flinfo;
741
742 PG_TRY();
743 {
744 fcinfo->flinfo = &fcache->flinfo;
745
746 /* See notes in fmgr_info_cxt_security */
748
749 result = FunctionCallInvoke(fcinfo);
750
751 /*
752 * We could be calling either a regular or a set-returning function,
753 * so we have to test to see what finalize flag to use.
754 */
756 (fcinfo->resultinfo == NULL ||
757 !IsA(fcinfo->resultinfo, ReturnSetInfo) ||
758 ((ReturnSetInfo *) fcinfo->resultinfo)->isDone != ExprMultipleResult));
759 }
760 PG_CATCH();
761 {
762 fcinfo->flinfo = save_flinfo;
763 if (fmgr_hook)
764 (*fmgr_hook) (FHET_ABORT, &fcache->flinfo, &fcache->arg);
765 PG_RE_THROW();
766 }
767 PG_END_TRY();
768
769 fcinfo->flinfo = save_flinfo;
770
771 if (fcache->configNames != NIL)
772 AtEOXact_GUC(true, save_nestlevel);
773 if (OidIsValid(fcache->userid))
774 SetUserIdAndSecContext(save_userid, save_sec_context);
775 if (fmgr_hook)
776 (*fmgr_hook) (FHET_END, &fcache->flinfo, &fcache->arg);
777
778 return result;
779}
#define DatumGetArrayTypeP(X)
Definition array.h:261
#define OidIsValid(objectId)
Definition c.h:860
#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:339
PGDLLIMPORT fmgr_hook_type fmgr_hook
Definition fmgr.c:42
@ 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:2142
config_handle * get_config_handle(const char *name)
Definition guc.c:4180
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:3311
void TransformGUCArray(ArrayType *array, List **names, List **values)
Definition guc.c:6273
void AtEOXact_GUC(bool isCommit, int nestLevel)
Definition guc.c:2169
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 @175 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:613
void SetUserIdAndSecContext(Oid userid, int sec_context)
Definition miscinit.c:620
#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:595
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:47
Datum SysCacheGetAttr(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition syscache.c:596

References AtEOXact_GUC(), DatumGetArrayTypeP, elog, ERROR, ExprMultipleResult, fb(), FHET_ABORT, FHET_END, FHET_START, fmgr_hook, fmgr_info_cxt_security(), Form_pg_proc, 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 283 of file fmgr.c.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

References fb(), fmgr_security_definer_cache::flinfo, 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 1854 of file fmgr.c.

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

References exprType(), fmgr_security_definer_cache::flinfo, 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 2010 of file fmgr.c.

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

References fmgr_security_definer_cache::flinfo, 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 2063 of file fmgr.c.

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

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

◆ has_fn_opclass_options()

bool has_fn_opclass_options ( FmgrInfo flinfo)

Definition at line 2047 of file fmgr.c.

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

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

◆ InputFunctionCall()

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

Definition at line 1532 of file fmgr.c.

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

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

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

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

518{
519 Oid fn_oid = ((Form_pg_proc) GETSTRUCT(procedureTuple))->oid;
520 CFuncHashTabEntry *entry;
521
522 if (CFuncHash == NULL)
523 return NULL; /* no table yet */
524 entry = (CFuncHashTabEntry *)
526 &fn_oid,
527 HASH_FIND,
528 NULL);
529 if (entry == NULL)
530 return NULL; /* no such entry */
531 if (entry->fn_xmin == HeapTupleHeaderGetRawXmin(procedureTuple->t_data) &&
532 ItemPointerEquals(&entry->fn_tid, &procedureTuple->t_self))
533 return entry; /* OK */
534 return NULL; /* entry is out of date */
535}
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition dynahash.c:952
static HTAB * CFuncHash
Definition fmgr.c:57
@ 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:51
ItemPointerData fn_tid
Definition fmgr.c:52

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

Referenced by fmgr_info_C_lang().

◆ OidFunctionCall0Coll()

Datum OidFunctionCall0Coll ( Oid  functionId,
Oid  collation 
)

Definition at line 1403 of file fmgr.c.

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

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

◆ OidFunctionCall1Coll()

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

Definition at line 1413 of file fmgr.c.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Referenced by DefineAggregate(), exec_bind_message(), get_typdefault(), GetAggInitVal(), GetAggInitVal(), GetAggInitVal(), InsertOneProargdefaultsValue(), 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 1773 of file fmgr.c.

1775{
1776 FmgrInfo flinfo;
1777
1778 fmgr_info(functionId, &flinfo);
1779 return ReceiveFunctionCall(&flinfo, buf, typioparam, typmod);
1780}
Datum ReceiveFunctionCall(FmgrInfo *flinfo, StringInfo buf, Oid typioparam, int32 typmod)
Definition fmgr.c:1698
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 1783 of file fmgr.c.

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

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

Referenced by logicalrep_write_tuple(), and SendFunctionResult().

◆ OutputFunctionCall()

◆ pg_detoast_datum()

varlena * pg_detoast_datum ( varlena datum)

Definition at line 1798 of file fmgr.c.

1799{
1800 if (VARATT_IS_EXTENDED(datum))
1801 return detoast_attr(datum);
1802 else
1803 return datum;
1804}
varlena * detoast_attr(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()

varlena * pg_detoast_datum_copy ( varlena datum)

Definition at line 1807 of file fmgr.c.

1808{
1809 if (VARATT_IS_EXTENDED(datum))
1810 return detoast_attr(datum);
1811 else
1812 {
1813 /* Make a modifiable copy of the varlena object */
1814 Size len = VARSIZE(datum);
1815 varlena *result = (varlena *) palloc(len);
1816
1817 memcpy(result, datum, len);
1818 return result;
1819 }
1820}
size_t Size
Definition c.h:691
void * palloc(Size size)
Definition mcxt.c:1387
const void size_t len
Definition c.h:778
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()

varlena * pg_detoast_datum_packed ( varlena datum)

Definition at line 1830 of file fmgr.c.

1831{
1832 if (VARATT_IS_COMPRESSED(datum) || VARATT_IS_EXTERNAL(datum))
1833 return detoast_attr(datum);
1834 else
1835 return datum;
1836}
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()

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

Definition at line 1823 of file fmgr.c.

1824{
1825 /* Only get the specified portion from the toast rel */
1826 return detoast_attr_slice(datum, first, count);
1827}
varlena * detoast_attr_slice(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 1698 of file fmgr.c.

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

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

543{
544 Oid fn_oid = ((Form_pg_proc) GETSTRUCT(procedureTuple))->oid;
545 CFuncHashTabEntry *entry;
546 bool found;
547
548 /* Create the hash table if it doesn't exist yet */
549 if (CFuncHash == NULL)
550 {
552
553 hash_ctl.keysize = sizeof(Oid);
554 hash_ctl.entrysize = sizeof(CFuncHashTabEntry);
555 CFuncHash = hash_create("CFuncHash",
556 100,
557 &hash_ctl,
559 }
560
561 entry = (CFuncHashTabEntry *)
563 &fn_oid,
565 &found);
566 /* OID is already filled in */
568 entry->fn_tid = procedureTuple->t_self;
569 entry->user_fn = user_fn;
570 entry->inforec = inforec;
571}
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:54
PGFunction user_fn
Definition fmgr.c:53
Size keysize
Definition hsearch.h:75

References CFuncHash, fb(), CFuncHashTabEntry::fn_tid, CFuncHashTabEntry::fn_xmin, Form_pg_proc, 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 2036 of file fmgr.c.

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

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

Referenced by gincost_pattern(), and index_getprocinfo().

Variable Documentation

◆ CFuncHash

HTAB* CFuncHash = NULL
static

Definition at line 57 of file fmgr.c.

Referenced by lookup_C_func(), and record_C_func().

◆ fmgr_hook

Definition at line 42 of file fmgr.c.

Referenced by fmgr_security_definer(), and sepgsql_init_client_label().

◆ needs_fmgr_hook

Definition at line 41 of file fmgr.c.

Referenced by sepgsql_init_client_label().