PostgreSQL Source Code  git master
fmgr.c File Reference
#include "postgres.h"
#include "access/detoast.h"
#include "catalog/pg_language.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_type.h"
#include "executor/functions.h"
#include "lib/stringinfo.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
#include "pgstat.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/fmgrtab.h"
#include "utils/guc.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
Include dependency graph for fmgr.c:

Go to the source code of this file.

Data Structures

struct  CFuncHashTabEntry
 
struct  fmgr_security_definer_cache
 

Functions

static void fmgr_info_cxt_security (Oid functionId, FmgrInfo *finfo, MemoryContext mcxt, bool ignore_security)
 
static void fmgr_info_C_lang (Oid functionId, FmgrInfo *finfo, HeapTuple procedureTuple)
 
static void fmgr_info_other_lang (Oid functionId, FmgrInfo *finfo, HeapTuple procedureTuple)
 
static CFuncHashTabEntrylookup_C_func (HeapTuple procedureTuple)
 
static void record_C_func (HeapTuple procedureTuple, PGFunction user_fn, const Pg_finfo_record *inforec)
 
Datum fmgr_security_definer (PG_FUNCTION_ARGS)
 
static const FmgrBuiltinfmgr_isbuiltin (Oid id)
 
static const FmgrBuiltinfmgr_lookupByName (const char *name)
 
void fmgr_info (Oid functionId, FmgrInfo *finfo)
 
void fmgr_info_cxt (Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
 
void fmgr_symbol (Oid functionId, char **mod, char **fn)
 
const Pg_finfo_recordfetch_finfo_record (void *filehandle, const char *funcname)
 
void clear_external_function_hash (void *filehandle)
 
void fmgr_info_copy (FmgrInfo *dstinfo, FmgrInfo *srcinfo, MemoryContext destcxt)
 
Oid fmgr_internal_function (const char *proname)
 
Datum DirectFunctionCall1Coll (PGFunction func, Oid collation, Datum arg1)
 
Datum DirectFunctionCall2Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2)
 
Datum DirectFunctionCall3Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3)
 
Datum DirectFunctionCall4Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4)
 
Datum DirectFunctionCall5Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5)
 
Datum DirectFunctionCall6Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6)
 
Datum DirectFunctionCall7Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7)
 
Datum DirectFunctionCall8Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8)
 
Datum DirectFunctionCall9Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8, Datum arg9)
 
Datum CallerFInfoFunctionCall1 (PGFunction func, FmgrInfo *flinfo, Oid collation, Datum arg1)
 
Datum CallerFInfoFunctionCall2 (PGFunction func, FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
 
Datum FunctionCall0Coll (FmgrInfo *flinfo, Oid collation)
 
Datum FunctionCall1Coll (FmgrInfo *flinfo, Oid collation, Datum arg1)
 
Datum FunctionCall2Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
 
Datum FunctionCall3Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3)
 
Datum FunctionCall4Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4)
 
Datum FunctionCall5Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5)
 
Datum FunctionCall6Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6)
 
Datum FunctionCall7Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7)
 
Datum FunctionCall8Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8)
 
Datum FunctionCall9Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8, Datum arg9)
 
Datum OidFunctionCall0Coll (Oid functionId, Oid collation)
 
Datum OidFunctionCall1Coll (Oid functionId, Oid collation, Datum arg1)
 
Datum OidFunctionCall2Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2)
 
Datum OidFunctionCall3Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3)
 
Datum OidFunctionCall4Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4)
 
Datum OidFunctionCall5Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5)
 
Datum OidFunctionCall6Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6)
 
Datum OidFunctionCall7Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7)
 
Datum OidFunctionCall8Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8)
 
Datum OidFunctionCall9Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8, Datum arg9)
 
Datum InputFunctionCall (FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
 
char * OutputFunctionCall (FmgrInfo *flinfo, Datum val)
 
Datum ReceiveFunctionCall (FmgrInfo *flinfo, StringInfo buf, Oid typioparam, int32 typmod)
 
byteaSendFunctionCall (FmgrInfo *flinfo, Datum val)
 
Datum OidInputFunctionCall (Oid functionId, char *str, Oid typioparam, int32 typmod)
 
char * OidOutputFunctionCall (Oid functionId, Datum val)
 
Datum OidReceiveFunctionCall (Oid functionId, StringInfo buf, Oid typioparam, int32 typmod)
 
byteaOidSendFunctionCall (Oid functionId, Datum val)
 
Datum Int64GetDatum (int64 X)
 
Datum Float8GetDatum (float8 X)
 
struct varlenapg_detoast_datum (struct varlena *datum)
 
struct varlenapg_detoast_datum_copy (struct varlena *datum)
 
struct varlenapg_detoast_datum_slice (struct varlena *datum, int32 first, int32 count)
 
struct varlenapg_detoast_datum_packed (struct varlena *datum)
 
Oid get_fn_expr_rettype (FmgrInfo *flinfo)
 
Oid get_fn_expr_argtype (FmgrInfo *flinfo, int argnum)
 
Oid get_call_expr_argtype (Node *expr, int argnum)
 
bool get_fn_expr_arg_stable (FmgrInfo *flinfo, int argnum)
 
bool get_call_expr_arg_stable (Node *expr, int argnum)
 
bool get_fn_expr_variadic (FmgrInfo *flinfo)
 
void set_fn_opclass_options (FmgrInfo *flinfo, bytea *options)
 
bool has_fn_opclass_options (FmgrInfo *flinfo)
 
byteaget_fn_opclass_options (FmgrInfo *flinfo)
 
bool CheckFunctionValidatorAccess (Oid validatorOid, Oid functionOid)
 

Variables

PGDLLIMPORT needs_fmgr_hook_type needs_fmgr_hook = NULL
 
PGDLLIMPORT fmgr_hook_type fmgr_hook = NULL
 
static HTABCFuncHash = NULL
 

Function Documentation

◆ CallerFInfoFunctionCall1()

Datum CallerFInfoFunctionCall1 ( PGFunction  func,
FmgrInfo flinfo,
Oid  collation,
Datum  arg1 
)

Definition at line 1064 of file fmgr.c.

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

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

◆ CallerFInfoFunctionCall2()

Datum CallerFInfoFunctionCall2 ( PGFunction  func,
FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2 
)

Definition at line 1084 of file fmgr.c.

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by gbt_enumge(), gbt_enumgt(), gbt_enumkey_cmp(), gbt_enumle(), gbt_enumlt(), gin_btree_compare_prefix(), and gin_enum_cmp().

1085 {
1086  LOCAL_FCINFO(fcinfo, 2);
1087  Datum result;
1088 
1089  InitFunctionCallInfoData(*fcinfo, flinfo, 2, collation, NULL, NULL);
1090 
1091  fcinfo->args[0].value = arg1;
1092  fcinfo->args[0].isnull = false;
1093  fcinfo->args[1].value = arg2;
1094  fcinfo->args[1].isnull = false;
1095 
1096  result = (*func) (fcinfo);
1097 
1098  /* Check for null result, since caller is clearly not expecting one */
1099  if (fcinfo->isnull)
1100  elog(ERROR, "function %p returned NULL", (void *) func);
1101 
1102  return result;
1103 }
#define ERROR
Definition: elog.h:46
uintptr_t Datum
Definition: postgres.h:411
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:232

◆ CheckFunctionValidatorAccess()

bool CheckFunctionValidatorAccess ( Oid  validatorOid,
Oid  functionOid 
)

Definition at line 2035 of file fmgr.c.

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

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

2036 {
2037  HeapTuple procTup;
2038  HeapTuple langTup;
2039  Form_pg_proc procStruct;
2040  Form_pg_language langStruct;
2041  AclResult aclresult;
2042 
2043  /*
2044  * Get the function's pg_proc entry. Throw a user-facing error for bad
2045  * OID, because validators can be called with user-specified OIDs.
2046  */
2047  procTup = SearchSysCache1(PROCOID, ObjectIdGetDatum(functionOid));
2048  if (!HeapTupleIsValid(procTup))
2049  ereport(ERROR,
2050  (errcode(ERRCODE_UNDEFINED_FUNCTION),
2051  errmsg("function with OID %u does not exist", functionOid)));
2052  procStruct = (Form_pg_proc) GETSTRUCT(procTup);
2053 
2054  /*
2055  * Fetch pg_language entry to know if this is the correct validation
2056  * function for that pg_proc entry.
2057  */
2058  langTup = SearchSysCache1(LANGOID, ObjectIdGetDatum(procStruct->prolang));
2059  if (!HeapTupleIsValid(langTup))
2060  elog(ERROR, "cache lookup failed for language %u", procStruct->prolang);
2061  langStruct = (Form_pg_language) GETSTRUCT(langTup);
2062 
2063  if (langStruct->lanvalidator != validatorOid)
2064  ereport(ERROR,
2065  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2066  errmsg("language validation function %u called for language %u instead of %u",
2067  validatorOid, procStruct->prolang,
2068  langStruct->lanvalidator)));
2069 
2070  /* first validate that we have permissions to use the language */
2071  aclresult = pg_language_aclcheck(procStruct->prolang, GetUserId(),
2072  ACL_USAGE);
2073  if (aclresult != ACLCHECK_OK)
2074  aclcheck_error(aclresult, OBJECT_LANGUAGE,
2075  NameStr(langStruct->lanname));
2076 
2077  /*
2078  * Check whether we are allowed to execute the function itself. If we can
2079  * execute it, there should be no possible side-effect of
2080  * compiling/validation that execution can't have.
2081  */
2082  aclresult = pg_proc_aclcheck(functionOid, GetUserId(), ACL_EXECUTE);
2083  if (aclresult != ACLCHECK_OK)
2084  aclcheck_error(aclresult, OBJECT_FUNCTION, NameStr(procStruct->proname));
2085 
2086  ReleaseSysCache(procTup);
2087  ReleaseSysCache(langTup);
2088 
2089  return true;
2090 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
Oid GetUserId(void)
Definition: miscinit.c:495
int errcode(int sqlerrcode)
Definition: elog.c:698
AclResult pg_language_aclcheck(Oid lang_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4730
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3308
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
#define ACL_USAGE
Definition: parsenodes.h:90
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1127
AclResult
Definition: acl.h:177
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:136
#define ereport(elevel,...)
Definition: elog.h:157
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_language * Form_pg_language
Definition: pg_language.h:65
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define ACL_EXECUTE
Definition: parsenodes.h:89
#define elog(elevel,...)
Definition: elog.h:232
AclResult pg_proc_aclcheck(Oid proc_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4718
#define NameStr(name)
Definition: c.h:681

◆ clear_external_function_hash()

void clear_external_function_hash ( void *  filehandle)

Definition at line 592 of file fmgr.c.

References hash_destroy().

Referenced by internal_unload_library().

593 {
594  if (CFuncHash)
596  CFuncHash = NULL;
597 }
void hash_destroy(HTAB *hashp)
Definition: dynahash.c:862
static HTAB * CFuncHash
Definition: fmgr.c:54

◆ DirectFunctionCall1Coll()

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

Definition at line 791 of file fmgr.c.

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by Generic_Text_IC_like(), libpqrcv_create_slot(), and texthashfast().

792 {
793  LOCAL_FCINFO(fcinfo, 1);
794  Datum result;
795 
796  InitFunctionCallInfoData(*fcinfo, NULL, 1, collation, NULL, NULL);
797 
798  fcinfo->args[0].value = arg1;
799  fcinfo->args[0].isnull = false;
800 
801  result = (*func) (fcinfo);
802 
803  /* Check for null result, since caller is clearly not expecting one */
804  if (fcinfo->isnull)
805  elog(ERROR, "function %p returned NULL", (void *) func);
806 
807  return result;
808 }
#define ERROR
Definition: elog.h:46
uintptr_t Datum
Definition: postgres.h:411
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:232

◆ DirectFunctionCall2Coll()

Datum DirectFunctionCall2Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2 
)

Definition at line 811 of file fmgr.c.

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by gbt_textcmp(), gbt_texteq(), gbt_textge(), gbt_textgt(), gbt_textle(), gbt_textlt(), spg_text_leaf_consistent(), text_isequal(), and texteqfast().

812 {
813  LOCAL_FCINFO(fcinfo, 2);
814  Datum result;
815 
816  InitFunctionCallInfoData(*fcinfo, NULL, 2, collation, NULL, NULL);
817 
818  fcinfo->args[0].value = arg1;
819  fcinfo->args[0].isnull = false;
820  fcinfo->args[1].value = arg2;
821  fcinfo->args[1].isnull = false;
822 
823  result = (*func) (fcinfo);
824 
825  /* Check for null result, since caller is clearly not expecting one */
826  if (fcinfo->isnull)
827  elog(ERROR, "function %p returned NULL", (void *) func);
828 
829  return result;
830 }
#define ERROR
Definition: elog.h:46
uintptr_t Datum
Definition: postgres.h:411
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:232

◆ DirectFunctionCall3Coll()

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

Definition at line 833 of file fmgr.c.

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by execute_extension_script().

835 {
836  LOCAL_FCINFO(fcinfo, 3);
837  Datum result;
838 
839  InitFunctionCallInfoData(*fcinfo, NULL, 3, collation, NULL, NULL);
840 
841  fcinfo->args[0].value = arg1;
842  fcinfo->args[0].isnull = false;
843  fcinfo->args[1].value = arg2;
844  fcinfo->args[1].isnull = false;
845  fcinfo->args[2].value = arg3;
846  fcinfo->args[2].isnull = false;
847 
848  result = (*func) (fcinfo);
849 
850  /* Check for null result, since caller is clearly not expecting one */
851  if (fcinfo->isnull)
852  elog(ERROR, "function %p returned NULL", (void *) func);
853 
854  return result;
855 }
#define ERROR
Definition: elog.h:46
uintptr_t Datum
Definition: postgres.h:411
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:232

◆ DirectFunctionCall4Coll()

Datum DirectFunctionCall4Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4 
)

Definition at line 858 of file fmgr.c.

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by execute_extension_script().

860 {
861  LOCAL_FCINFO(fcinfo, 4);
862  Datum result;
863 
864  InitFunctionCallInfoData(*fcinfo, NULL, 4, collation, NULL, NULL);
865 
866  fcinfo->args[0].value = arg1;
867  fcinfo->args[0].isnull = false;
868  fcinfo->args[1].value = arg2;
869  fcinfo->args[1].isnull = false;
870  fcinfo->args[2].value = arg3;
871  fcinfo->args[2].isnull = false;
872  fcinfo->args[3].value = arg4;
873  fcinfo->args[3].isnull = false;
874 
875  result = (*func) (fcinfo);
876 
877  /* Check for null result, since caller is clearly not expecting one */
878  if (fcinfo->isnull)
879  elog(ERROR, "function %p returned NULL", (void *) func);
880 
881  return result;
882 }
#define ERROR
Definition: elog.h:46
uintptr_t Datum
Definition: postgres.h:411
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:232

◆ DirectFunctionCall5Coll()

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

Definition at line 885 of file fmgr.c.

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by neqjoinsel().

887 {
888  LOCAL_FCINFO(fcinfo, 5);
889  Datum result;
890 
891  InitFunctionCallInfoData(*fcinfo, NULL, 5, collation, NULL, NULL);
892 
893  fcinfo->args[0].value = arg1;
894  fcinfo->args[0].isnull = false;
895  fcinfo->args[1].value = arg2;
896  fcinfo->args[1].isnull = false;
897  fcinfo->args[2].value = arg3;
898  fcinfo->args[2].isnull = false;
899  fcinfo->args[3].value = arg4;
900  fcinfo->args[3].isnull = false;
901  fcinfo->args[4].value = arg5;
902  fcinfo->args[4].isnull = false;
903 
904  result = (*func) (fcinfo);
905 
906  /* Check for null result, since caller is clearly not expecting one */
907  if (fcinfo->isnull)
908  elog(ERROR, "function %p returned NULL", (void *) func);
909 
910  return result;
911 }
#define ERROR
Definition: elog.h:46
uintptr_t Datum
Definition: postgres.h:411
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:232

◆ DirectFunctionCall6Coll()

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

Definition at line 914 of file fmgr.c.

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

917 {
918  LOCAL_FCINFO(fcinfo, 6);
919  Datum result;
920 
921  InitFunctionCallInfoData(*fcinfo, NULL, 6, collation, NULL, NULL);
922 
923  fcinfo->args[0].value = arg1;
924  fcinfo->args[0].isnull = false;
925  fcinfo->args[1].value = arg2;
926  fcinfo->args[1].isnull = false;
927  fcinfo->args[2].value = arg3;
928  fcinfo->args[2].isnull = false;
929  fcinfo->args[3].value = arg4;
930  fcinfo->args[3].isnull = false;
931  fcinfo->args[4].value = arg5;
932  fcinfo->args[4].isnull = false;
933  fcinfo->args[5].value = arg6;
934  fcinfo->args[5].isnull = false;
935 
936  result = (*func) (fcinfo);
937 
938  /* Check for null result, since caller is clearly not expecting one */
939  if (fcinfo->isnull)
940  elog(ERROR, "function %p returned NULL", (void *) func);
941 
942  return result;
943 }
#define ERROR
Definition: elog.h:46
uintptr_t Datum
Definition: postgres.h:411
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:232

◆ DirectFunctionCall7Coll()

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

Definition at line 946 of file fmgr.c.

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

949 {
950  LOCAL_FCINFO(fcinfo, 7);
951  Datum result;
952 
953  InitFunctionCallInfoData(*fcinfo, NULL, 7, collation, NULL, NULL);
954 
955  fcinfo->args[0].value = arg1;
956  fcinfo->args[0].isnull = false;
957  fcinfo->args[1].value = arg2;
958  fcinfo->args[1].isnull = false;
959  fcinfo->args[2].value = arg3;
960  fcinfo->args[2].isnull = false;
961  fcinfo->args[3].value = arg4;
962  fcinfo->args[3].isnull = false;
963  fcinfo->args[4].value = arg5;
964  fcinfo->args[4].isnull = false;
965  fcinfo->args[5].value = arg6;
966  fcinfo->args[5].isnull = false;
967  fcinfo->args[6].value = arg7;
968  fcinfo->args[6].isnull = false;
969 
970  result = (*func) (fcinfo);
971 
972  /* Check for null result, since caller is clearly not expecting one */
973  if (fcinfo->isnull)
974  elog(ERROR, "function %p returned NULL", (void *) func);
975 
976  return result;
977 }
#define ERROR
Definition: elog.h:46
uintptr_t Datum
Definition: postgres.h:411
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:232

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

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

983 {
984  LOCAL_FCINFO(fcinfo, 8);
985  Datum result;
986 
987  InitFunctionCallInfoData(*fcinfo, NULL, 8, collation, NULL, NULL);
988 
989  fcinfo->args[0].value = arg1;
990  fcinfo->args[0].isnull = false;
991  fcinfo->args[1].value = arg2;
992  fcinfo->args[1].isnull = false;
993  fcinfo->args[2].value = arg3;
994  fcinfo->args[2].isnull = false;
995  fcinfo->args[3].value = arg4;
996  fcinfo->args[3].isnull = false;
997  fcinfo->args[4].value = arg5;
998  fcinfo->args[4].isnull = false;
999  fcinfo->args[5].value = arg6;
1000  fcinfo->args[5].isnull = false;
1001  fcinfo->args[6].value = arg7;
1002  fcinfo->args[6].isnull = false;
1003  fcinfo->args[7].value = arg8;
1004  fcinfo->args[7].isnull = false;
1005 
1006  result = (*func) (fcinfo);
1007 
1008  /* Check for null result, since caller is clearly not expecting one */
1009  if (fcinfo->isnull)
1010  elog(ERROR, "function %p returned NULL", (void *) func);
1011 
1012  return result;
1013 }
#define ERROR
Definition: elog.h:46
uintptr_t Datum
Definition: postgres.h:411
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:232

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

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

1020 {
1021  LOCAL_FCINFO(fcinfo, 9);
1022  Datum result;
1023 
1024  InitFunctionCallInfoData(*fcinfo, NULL, 9, collation, NULL, NULL);
1025 
1026  fcinfo->args[0].value = arg1;
1027  fcinfo->args[0].isnull = false;
1028  fcinfo->args[1].value = arg2;
1029  fcinfo->args[1].isnull = false;
1030  fcinfo->args[2].value = arg3;
1031  fcinfo->args[2].isnull = false;
1032  fcinfo->args[3].value = arg4;
1033  fcinfo->args[3].isnull = false;
1034  fcinfo->args[4].value = arg5;
1035  fcinfo->args[4].isnull = false;
1036  fcinfo->args[5].value = arg6;
1037  fcinfo->args[5].isnull = false;
1038  fcinfo->args[6].value = arg7;
1039  fcinfo->args[6].isnull = false;
1040  fcinfo->args[7].value = arg8;
1041  fcinfo->args[7].isnull = false;
1042  fcinfo->args[8].value = arg9;
1043  fcinfo->args[8].isnull = false;
1044 
1045  result = (*func) (fcinfo);
1046 
1047  /* Check for null result, since caller is clearly not expecting one */
1048  if (fcinfo->isnull)
1049  elog(ERROR, "function %p returned NULL", (void *) func);
1050 
1051  return result;
1052 }
#define ERROR
Definition: elog.h:46
uintptr_t Datum
Definition: postgres.h:411
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:232

◆ fetch_finfo_record()

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

Definition at line 469 of file fmgr.c.

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

Referenced by fmgr_c_validator(), and fmgr_info_C_lang().

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

◆ Float8GetDatum()

◆ fmgr_info()

void fmgr_info ( Oid  functionId,
FmgrInfo finfo 
)

Definition at line 126 of file fmgr.c.

References CurrentMemoryContext, and fmgr_info_cxt_security().

Referenced by _bt_find_extreme_element(), _bt_sort_array_elements(), _sv_to_datum_finfo(), BeginCopyFrom(), brin_minmax_multi_summary_out(), brin_page_items(), build_pertrans_for_aggref(), call_pltcl_start_proc(), compute_distinct_stats(), create_foreign_modify(), DoCopyTo(), eqjoinsel_inner(), eqjoinsel_semi(), EventTriggerInvoke(), ExecBuildGroupingEqual(), ExecBuildParamSetEqual(), ExecCallTriggerFunc(), ExecHashTableCreate(), ExecInitAgg(), ExecInitExprRec(), ExecInitFunc(), ExecInitMemoize(), ExecInitSubPlan(), ExecInitTableFuncScan(), ExecInitWindowAgg(), execTuplesHashPrepare(), ExecuteCallStmt(), fetch_fp_info(), generic_restriction_selectivity(), get_stats_slot_range(), gincost_pattern(), hash_array(), inet_mcv_join_sel(), initialize_peragg(), match_pattern_prefix(), mcv_get_match_bitmap(), networkjoinsel_semi(), networksel(), OidFunctionCall0Coll(), OidFunctionCall1Coll(), OidFunctionCall2Coll(), OidFunctionCall3Coll(), OidFunctionCall4Coll(), OidFunctionCall5Coll(), OidFunctionCall6Coll(), OidFunctionCall7Coll(), OidFunctionCall8Coll(), OidFunctionCall9Coll(), OidInputFunctionCall(), OidOutputFunctionCall(), OidReceiveFunctionCall(), OidSendFunctionCall(), patternsel_common(), pg_get_catalog_foreign_keys(), pg_stats_ext_mcvlist_items(), plperl_ref_from_pg_array(), prefix_selectivity(), prepare_query_params(), printtup_prepare_info(), scalararraysel(), scalarineqsel(), ScanKeyEntryInitialize(), ScanKeyInit(), text_format(), TupleDescGetAttInMetadata(), and var_eq_const().

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

◆ fmgr_info_C_lang()

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

Definition at line 358 of file fmgr.c.

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

Referenced by fmgr_info_cxt_security().

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

◆ fmgr_info_copy()

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

Definition at line 608 of file fmgr.c.

References FmgrInfo::fn_extra, and FmgrInfo::fn_mcxt.

Referenced by bloom_get_procinfo(), bringetbitmap(), find_partition_scheme(), gistrescan(), inclusion_get_procinfo(), initBloomState(), initGinState(), initGISTstate(), minmax_multi_get_procinfo(), perform_pruning_base_step(), satisfies_hash_partition(), ScanKeyEntryInitializeWithInfo(), and spgbeginscan().

610 {
611  memcpy(dstinfo, srcinfo, sizeof(FmgrInfo));
612  dstinfo->fn_mcxt = destcxt;
613  dstinfo->fn_extra = NULL;
614 }
Definition: fmgr.h:56
MemoryContext fn_mcxt
Definition: fmgr.h:65
void * fn_extra
Definition: fmgr.h:64

◆ fmgr_info_cxt()

◆ fmgr_info_cxt_security()

static void fmgr_info_cxt_security ( Oid  functionId,
FmgrInfo finfo,
MemoryContext  mcxt,
bool  ignore_security 
)
static

Definition at line 146 of file fmgr.c.

References elog, ereport, errcode(), errmsg(), ERROR, fmgr_info_C_lang(), fmgr_info_other_lang(), fmgr_isbuiltin(), fmgr_lookupByName(), fmgr_security_definer(), fmgr_sql(), FmgrHookIsNeeded, FmgrInfo::fn_addr, FmgrInfo::fn_expr, FmgrInfo::fn_extra, FmgrInfo::fn_mcxt, FmgrInfo::fn_nargs, FmgrInfo::fn_oid, FmgrInfo::fn_retset, FmgrInfo::fn_stats, FmgrInfo::fn_strict, FmgrBuiltin::func, GETSTRUCT, heap_attisnull(), HeapTupleIsValid, InvalidOid, FmgrBuiltin::nargs, ObjectIdGetDatum, pfree(), PROCOID, ReleaseSysCache(), FmgrBuiltin::retset, SearchSysCache1(), FmgrBuiltin::strict, SysCacheGetAttr(), TextDatumGetCString, TRACK_FUNC_ALL, TRACK_FUNC_OFF, and TRACK_FUNC_PL.

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

148 {
149  const FmgrBuiltin *fbp;
150  HeapTuple procedureTuple;
151  Form_pg_proc procedureStruct;
152  Datum prosrcdatum;
153  bool isnull;
154  char *prosrc;
155 
156  /*
157  * fn_oid *must* be filled in last. Some code assumes that if fn_oid is
158  * valid, the whole struct is valid. Some FmgrInfo struct's do survive
159  * elogs.
160  */
161  finfo->fn_oid = InvalidOid;
162  finfo->fn_extra = NULL;
163  finfo->fn_mcxt = mcxt;
164  finfo->fn_expr = NULL; /* caller may set this later */
165 
166  if ((fbp = fmgr_isbuiltin(functionId)) != NULL)
167  {
168  /*
169  * Fast path for builtin functions: don't bother consulting pg_proc
170  */
171  finfo->fn_nargs = fbp->nargs;
172  finfo->fn_strict = fbp->strict;
173  finfo->fn_retset = fbp->retset;
174  finfo->fn_stats = TRACK_FUNC_ALL; /* ie, never track */
175  finfo->fn_addr = fbp->func;
176  finfo->fn_oid = functionId;
177  return;
178  }
179 
180  /* Otherwise we need the pg_proc entry */
181  procedureTuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(functionId));
182  if (!HeapTupleIsValid(procedureTuple))
183  elog(ERROR, "cache lookup failed for function %u", functionId);
184  procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
185 
186  finfo->fn_nargs = procedureStruct->pronargs;
187  finfo->fn_strict = procedureStruct->proisstrict;
188  finfo->fn_retset = procedureStruct->proretset;
189 
190  /*
191  * If it has prosecdef set, non-null proconfig, or if a plugin wants to
192  * hook function entry/exit, use fmgr_security_definer call handler ---
193  * unless we are being called again by fmgr_security_definer or
194  * fmgr_info_other_lang.
195  *
196  * When using fmgr_security_definer, function stats tracking is always
197  * disabled at the outer level, and instead we set the flag properly in
198  * fmgr_security_definer's private flinfo and implement the tracking
199  * inside fmgr_security_definer. This loses the ability to charge the
200  * overhead of fmgr_security_definer to the function, but gains the
201  * ability to set the track_functions GUC as a local GUC parameter of an
202  * interesting function and have the right things happen.
203  */
204  if (!ignore_security &&
205  (procedureStruct->prosecdef ||
206  !heap_attisnull(procedureTuple, Anum_pg_proc_proconfig, NULL) ||
207  FmgrHookIsNeeded(functionId)))
208  {
210  finfo->fn_stats = TRACK_FUNC_ALL; /* ie, never track */
211  finfo->fn_oid = functionId;
212  ReleaseSysCache(procedureTuple);
213  return;
214  }
215 
216  switch (procedureStruct->prolang)
217  {
218  case INTERNALlanguageId:
219 
220  /*
221  * For an ordinary builtin function, we should never get here
222  * because the fmgr_isbuiltin() search above will have succeeded.
223  * However, if the user has done a CREATE FUNCTION to create an
224  * alias for a builtin function, we can end up here. In that case
225  * we have to look up the function by name. The name of the
226  * internal function is stored in prosrc (it doesn't have to be
227  * the same as the name of the alias!)
228  */
229  prosrcdatum = SysCacheGetAttr(PROCOID, procedureTuple,
230  Anum_pg_proc_prosrc, &isnull);
231  if (isnull)
232  elog(ERROR, "null prosrc");
233  prosrc = TextDatumGetCString(prosrcdatum);
234  fbp = fmgr_lookupByName(prosrc);
235  if (fbp == NULL)
236  ereport(ERROR,
237  (errcode(ERRCODE_UNDEFINED_FUNCTION),
238  errmsg("internal function \"%s\" is not in internal lookup table",
239  prosrc)));
240  pfree(prosrc);
241  /* Should we check that nargs, strict, retset match the table? */
242  finfo->fn_addr = fbp->func;
243  /* note this policy is also assumed in fast path above */
244  finfo->fn_stats = TRACK_FUNC_ALL; /* ie, never track */
245  break;
246 
247  case ClanguageId:
248  fmgr_info_C_lang(functionId, finfo, procedureTuple);
249  finfo->fn_stats = TRACK_FUNC_PL; /* ie, track if ALL */
250  break;
251 
252  case SQLlanguageId:
253  finfo->fn_addr = fmgr_sql;
254  finfo->fn_stats = TRACK_FUNC_PL; /* ie, track if ALL */
255  break;
256 
257  default:
258  fmgr_info_other_lang(functionId, finfo, procedureTuple);
259  finfo->fn_stats = TRACK_FUNC_OFF; /* ie, track if not OFF */
260  break;
261  }
262 
263  finfo->fn_oid = functionId;
264  ReleaseSysCache(procedureTuple);
265 }
bool strict
Definition: fmgrtab.h:29
short fn_nargs
Definition: fmgr.h:60
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
MemoryContext fn_mcxt
Definition: fmgr.h:65
short nargs
Definition: fmgrtab.h:28
PGFunction fn_addr
Definition: fmgr.h:58
static void fmgr_info_other_lang(Oid functionId, FmgrInfo *finfo, HeapTuple procedureTuple)
Definition: fmgr.c:432
int errcode(int sqlerrcode)
Definition: elog.c:698
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
Definition: heaptuple.c:359
#define FmgrHookIsNeeded(fn_oid)
Definition: fmgr.h:774
static void fmgr_info_C_lang(Oid functionId, FmgrInfo *finfo, HeapTuple procedureTuple)
Definition: fmgr.c:358
PGFunction func
Definition: fmgrtab.h:32
void pfree(void *pointer)
Definition: mcxt.c:1169
bool fn_retset
Definition: fmgr.h:62
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
bool fn_strict
Definition: fmgr.h:61
Datum fmgr_sql(PG_FUNCTION_ARGS)
Definition: functions.c:1019
static const FmgrBuiltin * fmgr_lookupByName(const char *name)
Definition: fmgr.c:100
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1127
#define TextDatumGetCString(d)
Definition: builtins.h:87
static const FmgrBuiltin * fmgr_isbuiltin(Oid id)
Definition: fmgr.c:75
uintptr_t Datum
Definition: postgres.h:411
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1388
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:136
#define InvalidOid
Definition: postgres_ext.h:36
Oid fn_oid
Definition: fmgr.h:59
#define ereport(elevel,...)
Definition: elog.h:157
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
fmNodePtr fn_expr
Definition: fmgr.h:66
Datum fmgr_security_definer(PG_FUNCTION_ARGS)
Definition: fmgr.c:658
void * fn_extra
Definition: fmgr.h:64
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define elog(elevel,...)
Definition: elog.h:232
unsigned char fn_stats
Definition: fmgr.h:63
bool retset
Definition: fmgrtab.h:30

◆ fmgr_info_other_lang()

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

Definition at line 432 of file fmgr.c.

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

Referenced by fmgr_info_cxt_security().

433 {
434  Form_pg_proc procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
435  Oid language = procedureStruct->prolang;
436  HeapTuple languageTuple;
437  Form_pg_language languageStruct;
438  FmgrInfo plfinfo;
439 
440  languageTuple = SearchSysCache1(LANGOID, ObjectIdGetDatum(language));
441  if (!HeapTupleIsValid(languageTuple))
442  elog(ERROR, "cache lookup failed for language %u", language);
443  languageStruct = (Form_pg_language) GETSTRUCT(languageTuple);
444 
445  /*
446  * Look up the language's call handler function, ignoring any attributes
447  * that would normally cause insertion of fmgr_security_definer. We need
448  * to get back a bare pointer to the actual C-language function.
449  */
450  fmgr_info_cxt_security(languageStruct->lanplcallfoid, &plfinfo,
451  CurrentMemoryContext, true);
452  finfo->fn_addr = plfinfo.fn_addr;
453 
454  ReleaseSysCache(languageTuple);
455 }
Definition: fmgr.h:56
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
PGFunction fn_addr
Definition: fmgr.h:58
unsigned int Oid
Definition: postgres_ext.h:31
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
MemoryContext CurrentMemoryContext
Definition: mcxt.c:42
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1127
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:136
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_language * Form_pg_language
Definition: pg_language.h:65
#define elog(elevel,...)
Definition: elog.h:232
static void fmgr_info_cxt_security(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt, bool ignore_security)
Definition: fmgr.c:146

◆ fmgr_internal_function()

Oid fmgr_internal_function ( const char *  proname)

Definition at line 623 of file fmgr.c.

References fmgr_lookupByName(), FmgrBuiltin::foid, and InvalidOid.

Referenced by fmgr_internal_validator().

624 {
625  const FmgrBuiltin *fbp = fmgr_lookupByName(proname);
626 
627  if (fbp == NULL)
628  return InvalidOid;
629  return fbp->foid;
630 }
NameData proname
Definition: pg_proc.h:35
Oid foid
Definition: fmgrtab.h:27
static const FmgrBuiltin * fmgr_lookupByName(const char *name)
Definition: fmgr.c:100
#define InvalidOid
Definition: postgres_ext.h:36

◆ fmgr_isbuiltin()

static const FmgrBuiltin* fmgr_isbuiltin ( Oid  id)
static

Definition at line 75 of file fmgr.c.

References fmgr_builtin_oid_index, fmgr_builtins, fmgr_last_builtin_oid, and InvalidOidBuiltinMapping.

Referenced by fmgr_info_cxt_security().

76 {
77  uint16 index;
78 
79  /* fast lookup only possible if original oid still assigned */
80  if (id > fmgr_last_builtin_oid)
81  return NULL;
82 
83  /*
84  * Lookup function data. If there's a miss in that range it's likely a
85  * nonexistent function, returning NULL here will trigger an ERROR later.
86  */
87  index = fmgr_builtin_oid_index[id];
88  if (index == InvalidOidBuiltinMapping)
89  return NULL;
90 
91  return &fmgr_builtins[index];
92 }
const FmgrBuiltin fmgr_builtins[]
#define InvalidOidBuiltinMapping
Definition: fmgrtab.h:45
Definition: type.h:89
const Oid fmgr_last_builtin_oid
unsigned short uint16
Definition: c.h:440
const uint16 fmgr_builtin_oid_index[]

◆ fmgr_lookupByName()

static const FmgrBuiltin* fmgr_lookupByName ( const char *  name)
static

Definition at line 100 of file fmgr.c.

References fmgr_builtins, fmgr_nbuiltins, and i.

Referenced by fmgr_info_cxt_security(), and fmgr_internal_function().

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

◆ fmgr_security_definer()

Datum fmgr_security_definer ( PG_FUNCTION_ARGS  )

Definition at line 658 of file fmgr.c.

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

Referenced by fmgr_info_cxt_security().

659 {
660  Datum result;
661  struct fmgr_security_definer_cache *volatile fcache;
662  FmgrInfo *save_flinfo;
663  Oid save_userid;
664  int save_sec_context;
665  volatile int save_nestlevel;
666  PgStat_FunctionCallUsage fcusage;
667 
668  if (!fcinfo->flinfo->fn_extra)
669  {
670  HeapTuple tuple;
671  Form_pg_proc procedureStruct;
672  Datum datum;
673  bool isnull;
674  MemoryContext oldcxt;
675 
676  fcache = MemoryContextAllocZero(fcinfo->flinfo->fn_mcxt,
677  sizeof(*fcache));
678 
679  fmgr_info_cxt_security(fcinfo->flinfo->fn_oid, &fcache->flinfo,
680  fcinfo->flinfo->fn_mcxt, true);
681  fcache->flinfo.fn_expr = fcinfo->flinfo->fn_expr;
682 
683  tuple = SearchSysCache1(PROCOID,
684  ObjectIdGetDatum(fcinfo->flinfo->fn_oid));
685  if (!HeapTupleIsValid(tuple))
686  elog(ERROR, "cache lookup failed for function %u",
687  fcinfo->flinfo->fn_oid);
688  procedureStruct = (Form_pg_proc) GETSTRUCT(tuple);
689 
690  if (procedureStruct->prosecdef)
691  fcache->userid = procedureStruct->proowner;
692 
693  datum = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_proconfig,
694  &isnull);
695  if (!isnull)
696  {
697  oldcxt = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
698  fcache->proconfig = DatumGetArrayTypePCopy(datum);
699  MemoryContextSwitchTo(oldcxt);
700  }
701 
702  ReleaseSysCache(tuple);
703 
704  fcinfo->flinfo->fn_extra = fcache;
705  }
706  else
707  fcache = fcinfo->flinfo->fn_extra;
708 
709  /* GetUserIdAndSecContext is cheap enough that no harm in a wasted call */
710  GetUserIdAndSecContext(&save_userid, &save_sec_context);
711  if (fcache->proconfig) /* Need a new GUC nesting level */
712  save_nestlevel = NewGUCNestLevel();
713  else
714  save_nestlevel = 0; /* keep compiler quiet */
715 
716  if (OidIsValid(fcache->userid))
718  save_sec_context | SECURITY_LOCAL_USERID_CHANGE);
719 
720  if (fcache->proconfig)
721  {
722  ProcessGUCArray(fcache->proconfig,
726  }
727 
728  /* function manager hook */
729  if (fmgr_hook)
730  (*fmgr_hook) (FHET_START, &fcache->flinfo, &fcache->arg);
731 
732  /*
733  * We don't need to restore GUC or userid settings on error, because the
734  * ensuing xact or subxact abort will do that. The PG_TRY block is only
735  * needed to clean up the flinfo link.
736  */
737  save_flinfo = fcinfo->flinfo;
738 
739  PG_TRY();
740  {
741  fcinfo->flinfo = &fcache->flinfo;
742 
743  /* See notes in fmgr_info_cxt_security */
744  pgstat_init_function_usage(fcinfo, &fcusage);
745 
746  result = FunctionCallInvoke(fcinfo);
747 
748  /*
749  * We could be calling either a regular or a set-returning function,
750  * so we have to test to see what finalize flag to use.
751  */
752  pgstat_end_function_usage(&fcusage,
753  (fcinfo->resultinfo == NULL ||
754  !IsA(fcinfo->resultinfo, ReturnSetInfo) ||
755  ((ReturnSetInfo *) fcinfo->resultinfo)->isDone != ExprMultipleResult));
756  }
757  PG_CATCH();
758  {
759  fcinfo->flinfo = save_flinfo;
760  if (fmgr_hook)
761  (*fmgr_hook) (FHET_ABORT, &fcache->flinfo, &fcache->arg);
762  PG_RE_THROW();
763  }
764  PG_END_TRY();
765 
766  fcinfo->flinfo = save_flinfo;
767 
768  if (fcache->proconfig)
769  AtEOXact_GUC(true, save_nestlevel);
770  if (OidIsValid(fcache->userid))
771  SetUserIdAndSecContext(save_userid, save_sec_context);
772  if (fmgr_hook)
773  (*fmgr_hook) (FHET_END, &fcache->flinfo, &fcache->arg);
774 
775  return result;
776 }
Definition: fmgr.h:56
#define IsA(nodeptr, _type_)
Definition: nodes.h:587
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
MemoryContext fn_mcxt
Definition: fmgr.h:65
void SetUserIdAndSecContext(Oid userid, int sec_context)
Definition: miscinit.c:607
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
bool superuser(void)
Definition: superuser.c:46
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:710
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
Definition: pgstat.c:1914
Definition: guc.h:75
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
Definition: miscinit.c:600
void AtEOXact_GUC(bool isCommit, int nestLevel)
Definition: guc.c:6242
Definition: fmgr.h:762
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1127
ArrayType * proconfig
Definition: fmgr.c:643
uintptr_t Datum
Definition: postgres.h:411
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1388
#define DatumGetArrayTypePCopy(X)
Definition: array.h:255
PGDLLIMPORT fmgr_hook_type fmgr_hook
Definition: fmgr.c:39
#define SECURITY_LOCAL_USERID_CHANGE
Definition: miscadmin.h:311
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:136
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:906
void ProcessGUCArray(ArrayType *array, GucContext context, GucSource source, GucAction action)
Definition: guc.c:11040
#define PG_CATCH()
Definition: elog.h:323
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
fmNodePtr fn_expr
Definition: fmgr.h:66
#define PG_RE_THROW()
Definition: elog.h:354
void * fn_extra
Definition: fmgr.h:64
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
Definition: pgstat.c:1987
int NewGUCNestLevel(void)
Definition: guc.c:6228
#define elog(elevel,...)
Definition: elog.h:232
#define PG_TRY()
Definition: elog.h:313
#define PG_END_TRY()
Definition: elog.h:338
static void fmgr_info_cxt_security(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt, bool ignore_security)
Definition: fmgr.c:146

◆ fmgr_symbol()

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

Definition at line 283 of file fmgr.c.

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

Referenced by llvm_function_reference().

284 {
285  HeapTuple procedureTuple;
286  Form_pg_proc procedureStruct;
287  bool isnull;
288  Datum prosrcattr;
289  Datum probinattr;
290 
291  procedureTuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(functionId));
292  if (!HeapTupleIsValid(procedureTuple))
293  elog(ERROR, "cache lookup failed for function %u", functionId);
294  procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
295 
296  if (procedureStruct->prosecdef ||
297  !heap_attisnull(procedureTuple, Anum_pg_proc_proconfig, NULL) ||
298  FmgrHookIsNeeded(functionId))
299  {
300  *mod = NULL; /* core binary */
301  *fn = pstrdup("fmgr_security_definer");
302  ReleaseSysCache(procedureTuple);
303  return;
304  }
305 
306  /* see fmgr_info_cxt_security for the individual cases */
307  switch (procedureStruct->prolang)
308  {
309  case INTERNALlanguageId:
310  prosrcattr = SysCacheGetAttr(PROCOID, procedureTuple,
311  Anum_pg_proc_prosrc, &isnull);
312  if (isnull)
313  elog(ERROR, "null prosrc");
314 
315  *mod = NULL; /* core binary */
316  *fn = TextDatumGetCString(prosrcattr);
317  break;
318 
319  case ClanguageId:
320  prosrcattr = SysCacheGetAttr(PROCOID, procedureTuple,
321  Anum_pg_proc_prosrc, &isnull);
322  if (isnull)
323  elog(ERROR, "null prosrc for C function %u", functionId);
324 
325  probinattr = SysCacheGetAttr(PROCOID, procedureTuple,
326  Anum_pg_proc_probin, &isnull);
327  if (isnull)
328  elog(ERROR, "null probin for C function %u", functionId);
329 
330  /*
331  * No need to check symbol presence / API version here, already
332  * checked in fmgr_info_cxt_security.
333  */
334  *mod = TextDatumGetCString(probinattr);
335  *fn = TextDatumGetCString(prosrcattr);
336  break;
337 
338  case SQLlanguageId:
339  *mod = NULL; /* core binary */
340  *fn = pstrdup("fmgr_sql");
341  break;
342 
343  default:
344  *mod = NULL;
345  *fn = NULL; /* unknown, pass pointer */
346  break;
347  }
348 
349  ReleaseSysCache(procedureTuple);
350 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
char * pstrdup(const char *in)
Definition: mcxt.c:1299
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
Definition: heaptuple.c:359
#define FmgrHookIsNeeded(fn_oid)
Definition: fmgr.h:774
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1127
#define TextDatumGetCString(d)
Definition: builtins.h:87
uintptr_t Datum
Definition: postgres.h:411
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1388
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:136
static void * fn(void *arg)
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define elog(elevel,...)
Definition: elog.h:232

◆ FunctionCall0Coll()

Datum FunctionCall0Coll ( FmgrInfo flinfo,
Oid  collation 
)

Definition at line 1111 of file fmgr.c.

References elog, ERROR, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by OidFunctionCall0Coll().

1112 {
1113  LOCAL_FCINFO(fcinfo, 0);
1114  Datum result;
1115 
1116  InitFunctionCallInfoData(*fcinfo, flinfo, 0, collation, NULL, NULL);
1117 
1118  result = FunctionCallInvoke(fcinfo);
1119 
1120  /* Check for null result, since caller is clearly not expecting one */
1121  if (fcinfo->isnull)
1122  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1123 
1124  return result;
1125 }
#define ERROR
Definition: elog.h:46
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
uintptr_t Datum
Definition: postgres.h:411
Oid fn_oid
Definition: fmgr.h:59
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:232

◆ FunctionCall1Coll()

Datum FunctionCall1Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1 
)

Definition at line 1128 of file fmgr.c.

References elog, ERROR, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by _hash_datum2hashkey(), brin_bloom_add_value(), brin_bloom_consistent(), brin_inclusion_add_value(), element_hash(), ExecHashBuildSkewHash(), ExecHashGetHashValue(), gistCompressValues(), gistdentryinit(), gistFetchAtt(), hash_multirange(), hash_range(), MemoizeHash_hash(), OidFunctionCall1Coll(), signValue(), spgdoinsert(), and TupleHashTableHash_internal().

1129 {
1130  LOCAL_FCINFO(fcinfo, 1);
1131  Datum result;
1132 
1133  InitFunctionCallInfoData(*fcinfo, flinfo, 1, collation, NULL, NULL);
1134 
1135  fcinfo->args[0].value = arg1;
1136  fcinfo->args[0].isnull = false;
1137 
1138  result = FunctionCallInvoke(fcinfo);
1139 
1140  /* Check for null result, since caller is clearly not expecting one */
1141  if (fcinfo->isnull)
1142  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1143 
1144  return result;
1145 }
#define ERROR
Definition: elog.h:46
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
uintptr_t Datum
Definition: postgres.h:411
Oid fn_oid
Definition: fmgr.h:59
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:232

◆ FunctionCall2Coll()

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

Definition at line 1148 of file fmgr.c.

References elog, ERROR, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by _bt_check_rowcompare(), _bt_checkkeys(), _bt_compare(), _bt_compare_array_elements(), _bt_compare_scankey_args(), _bt_find_extreme_element(), _bt_keep_natts(), _hash_checkqual(), array_position_common(), array_positions(), AssertCheckExpandedRanges(), AssertCheckRanges(), brin_inclusion_add_value(), brin_inclusion_consistent(), brin_inclusion_union(), brin_minmax_add_value(), brin_minmax_consistent(), brin_minmax_multi_consistent(), brin_minmax_union(), build_distances(), call_subtype_diff(), cmpEntries(), compare_expanded_ranges(), compare_values(), compute_distinct_stats(), compute_partition_hash_value(), compute_range_stats(), create_range_bounds(), doPickSplit(), element_compare(), execTuplesUnequal(), genericPickSplit(), get_distance(), get_position(), get_stats_slot_range(), ginCompareEntries(), gistMakeUnionItVec(), gistMakeUnionKey(), gistUserPicksplit(), has_matching_range(), hash_multirange_extended(), hash_range_extended(), ineq_histogram_selectivity(), make_greater_string(), mcv_get_match_bitmap(), merge_list_bounds(), merge_overlapping_ranges(), mode_final(), multirange_elem_bsearch_comparison(), OidFunctionCall2Coll(), partition_list_bsearch(), partition_rbound_cmp(), partition_rbound_datum_cmp(), process_ordered_aggregate_single(), qsort_partition_list_value_cmp(), range_cmp_bound_values(), range_cmp_bounds(), range_contains_elem_internal(), range_contains_value(), ri_AttributesEqual(), satisfies_hash_partition(), spgdoinsert(), spgGetCache(), spgInnerTest(), spgLeafTest(), and tuples_equal().

1149 {
1150  LOCAL_FCINFO(fcinfo, 2);
1151  Datum result;
1152 
1153  InitFunctionCallInfoData(*fcinfo, flinfo, 2, collation, NULL, NULL);
1154 
1155  fcinfo->args[0].value = arg1;
1156  fcinfo->args[0].isnull = false;
1157  fcinfo->args[1].value = arg2;
1158  fcinfo->args[1].isnull = false;
1159 
1160  result = FunctionCallInvoke(fcinfo);
1161 
1162  /* Check for null result, since caller is clearly not expecting one */
1163  if (fcinfo->isnull)
1164  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1165 
1166  return result;
1167 }
#define ERROR
Definition: elog.h:46
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
uintptr_t Datum
Definition: postgres.h:411
Oid fn_oid
Definition: fmgr.h:59
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:232

◆ FunctionCall3Coll()

Datum FunctionCall3Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3 
)

Definition at line 1170 of file fmgr.c.

References elog, ERROR, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by bringetbitmap(), ginExtractEntries(), gistKeyIsEQ(), gistpenalty(), OidFunctionCall3Coll(), and union_tuples().

1172 {
1173  LOCAL_FCINFO(fcinfo, 3);
1174  Datum result;
1175 
1176  InitFunctionCallInfoData(*fcinfo, flinfo, 3, collation, NULL, NULL);
1177 
1178  fcinfo->args[0].value = arg1;
1179  fcinfo->args[0].isnull = false;
1180  fcinfo->args[1].value = arg2;
1181  fcinfo->args[1].isnull = false;
1182  fcinfo->args[2].value = arg3;
1183  fcinfo->args[2].isnull = false;
1184 
1185  result = FunctionCallInvoke(fcinfo);
1186 
1187  /* Check for null result, since caller is clearly not expecting one */
1188  if (fcinfo->isnull)
1189  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1190 
1191  return result;
1192 }
#define ERROR
Definition: elog.h:46
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
uintptr_t Datum
Definition: postgres.h:411
Oid fn_oid
Definition: fmgr.h:59
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:232

◆ FunctionCall4Coll()

Datum FunctionCall4Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4 
)

Definition at line 1195 of file fmgr.c.

References elog, ERROR, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by add_values_to_range(), bringetbitmap(), collectMatchBitmap(), matchPartialInPendingList(), OidFunctionCall4Coll(), and scalararraysel().

1197 {
1198  LOCAL_FCINFO(fcinfo, 4);
1199  Datum result;
1200 
1201  InitFunctionCallInfoData(*fcinfo, flinfo, 4, collation, NULL, NULL);
1202 
1203  fcinfo->args[0].value = arg1;
1204  fcinfo->args[0].isnull = false;
1205  fcinfo->args[1].value = arg2;
1206  fcinfo->args[1].isnull = false;
1207  fcinfo->args[2].value = arg3;
1208  fcinfo->args[2].isnull = false;
1209  fcinfo->args[3].value = arg4;
1210  fcinfo->args[3].isnull = false;
1211 
1212  result = FunctionCallInvoke(fcinfo);
1213 
1214  /* Check for null result, since caller is clearly not expecting one */
1215  if (fcinfo->isnull)
1216  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1217 
1218  return result;
1219 }
#define ERROR
Definition: elog.h:46
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
uintptr_t Datum
Definition: postgres.h:411
Oid fn_oid
Definition: fmgr.h:59
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:232

◆ FunctionCall5Coll()

Datum FunctionCall5Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5 
)

Definition at line 1222 of file fmgr.c.

References elog, ERROR, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by gistindex_keytest(), OidFunctionCall5Coll(), scalararraysel(), update_frameheadpos(), and update_frametailpos().

1224 {
1225  LOCAL_FCINFO(fcinfo, 5);
1226  Datum result;
1227 
1228  InitFunctionCallInfoData(*fcinfo, flinfo, 5, collation, NULL, NULL);
1229 
1230  fcinfo->args[0].value = arg1;
1231  fcinfo->args[0].isnull = false;
1232  fcinfo->args[1].value = arg2;
1233  fcinfo->args[1].isnull = false;
1234  fcinfo->args[2].value = arg3;
1235  fcinfo->args[2].isnull = false;
1236  fcinfo->args[3].value = arg4;
1237  fcinfo->args[3].isnull = false;
1238  fcinfo->args[4].value = arg5;
1239  fcinfo->args[4].isnull = false;
1240 
1241  result = FunctionCallInvoke(fcinfo);
1242 
1243  /* Check for null result, since caller is clearly not expecting one */
1244  if (fcinfo->isnull)
1245  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1246 
1247  return result;
1248 }
#define ERROR
Definition: elog.h:46
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
uintptr_t Datum
Definition: postgres.h:411
Oid fn_oid
Definition: fmgr.h:59
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:232

◆ FunctionCall6Coll()

Datum FunctionCall6Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6 
)

Definition at line 1251 of file fmgr.c.

References elog, ERROR, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by OidFunctionCall6Coll().

1254 {
1255  LOCAL_FCINFO(fcinfo, 6);
1256  Datum result;
1257 
1258  InitFunctionCallInfoData(*fcinfo, flinfo, 6, collation, NULL, NULL);
1259 
1260  fcinfo->args[0].value = arg1;
1261  fcinfo->args[0].isnull = false;
1262  fcinfo->args[1].value = arg2;
1263  fcinfo->args[1].isnull = false;
1264  fcinfo->args[2].value = arg3;
1265  fcinfo->args[2].isnull = false;
1266  fcinfo->args[3].value = arg4;
1267  fcinfo->args[3].isnull = false;
1268  fcinfo->args[4].value = arg5;
1269  fcinfo->args[4].isnull = false;
1270  fcinfo->args[5].value = arg6;
1271  fcinfo->args[5].isnull = false;
1272 
1273  result = FunctionCallInvoke(fcinfo);
1274 
1275  /* Check for null result, since caller is clearly not expecting one */
1276  if (fcinfo->isnull)
1277  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1278 
1279  return result;
1280 }
#define ERROR
Definition: elog.h:46
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
uintptr_t Datum
Definition: postgres.h:411
Oid fn_oid
Definition: fmgr.h:59
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:232

◆ FunctionCall7Coll()

Datum FunctionCall7Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7 
)

Definition at line 1283 of file fmgr.c.

References elog, ERROR, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by directTriConsistentFn(), gincost_pattern(), OidFunctionCall7Coll(), and shimBoolConsistentFn().

1286 {
1287  LOCAL_FCINFO(fcinfo, 7);
1288  Datum result;
1289 
1290  InitFunctionCallInfoData(*fcinfo, flinfo, 7, collation, NULL, NULL);
1291 
1292  fcinfo->args[0].value = arg1;
1293  fcinfo->args[0].isnull = false;
1294  fcinfo->args[1].value = arg2;
1295  fcinfo->args[1].isnull = false;
1296  fcinfo->args[2].value = arg3;
1297  fcinfo->args[2].isnull = false;
1298  fcinfo->args[3].value = arg4;
1299  fcinfo->args[3].isnull = false;
1300  fcinfo->args[4].value = arg5;
1301  fcinfo->args[4].isnull = false;
1302  fcinfo->args[5].value = arg6;
1303  fcinfo->args[5].isnull = false;
1304  fcinfo->args[6].value = arg7;
1305  fcinfo->args[6].isnull = false;
1306 
1307  result = FunctionCallInvoke(fcinfo);
1308 
1309  /* Check for null result, since caller is clearly not expecting one */
1310  if (fcinfo->isnull)
1311  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1312 
1313  return result;
1314 }
#define ERROR
Definition: elog.h:46
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
uintptr_t Datum
Definition: postgres.h:411
Oid fn_oid
Definition: fmgr.h:59
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:232

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

References elog, ERROR, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by directBoolConsistentFn(), and OidFunctionCall8Coll().

1320 {
1321  LOCAL_FCINFO(fcinfo, 8);
1322  Datum result;
1323 
1324  InitFunctionCallInfoData(*fcinfo, flinfo, 8, collation, NULL, NULL);
1325 
1326  fcinfo->args[0].value = arg1;
1327  fcinfo->args[0].isnull = false;
1328  fcinfo->args[1].value = arg2;
1329  fcinfo->args[1].isnull = false;
1330  fcinfo->args[2].value = arg3;
1331  fcinfo->args[2].isnull = false;
1332  fcinfo->args[3].value = arg4;
1333  fcinfo->args[3].isnull = false;
1334  fcinfo->args[4].value = arg5;
1335  fcinfo->args[4].isnull = false;
1336  fcinfo->args[5].value = arg6;
1337  fcinfo->args[5].isnull = false;
1338  fcinfo->args[6].value = arg7;
1339  fcinfo->args[6].isnull = false;
1340  fcinfo->args[7].value = arg8;
1341  fcinfo->args[7].isnull = false;
1342 
1343  result = FunctionCallInvoke(fcinfo);
1344 
1345  /* Check for null result, since caller is clearly not expecting one */
1346  if (fcinfo->isnull)
1347  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1348 
1349  return result;
1350 }
#define ERROR
Definition: elog.h:46
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
uintptr_t Datum
Definition: postgres.h:411
Oid fn_oid
Definition: fmgr.h:59
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:232

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

References elog, ERROR, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by OidFunctionCall9Coll().

1357 {
1358  LOCAL_FCINFO(fcinfo, 9);
1359  Datum result;
1360 
1361  InitFunctionCallInfoData(*fcinfo, flinfo, 9, collation, NULL, NULL);
1362 
1363  fcinfo->args[0].value = arg1;
1364  fcinfo->args[0].isnull = false;
1365  fcinfo->args[1].value = arg2;
1366  fcinfo->args[1].isnull = false;
1367  fcinfo->args[2].value = arg3;
1368  fcinfo->args[2].isnull = false;
1369  fcinfo->args[3].value = arg4;
1370  fcinfo->args[3].isnull = false;
1371  fcinfo->args[4].value = arg5;
1372  fcinfo->args[4].isnull = false;
1373  fcinfo->args[5].value = arg6;
1374  fcinfo->args[5].isnull = false;
1375  fcinfo->args[6].value = arg7;
1376  fcinfo->args[6].isnull = false;
1377  fcinfo->args[7].value = arg8;
1378  fcinfo->args[7].isnull = false;
1379  fcinfo->args[8].value = arg9;
1380  fcinfo->args[8].isnull = false;
1381 
1382  result = FunctionCallInvoke(fcinfo);
1383 
1384  /* Check for null result, since caller is clearly not expecting one */
1385  if (fcinfo->isnull)
1386  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1387 
1388  return result;
1389 }
#define ERROR
Definition: elog.h:46
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
uintptr_t Datum
Definition: postgres.h:411
Oid fn_oid
Definition: fmgr.h:59
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:232

◆ get_call_expr_arg_stable()

bool get_call_expr_arg_stable ( Node expr,
int  argnum 
)

Definition at line 1884 of file fmgr.c.

References fmgr_security_definer_cache::arg, generate_unaccent_rules::args, IsA, list_length(), list_nth(), and PARAM_EXTERN.

Referenced by get_fn_expr_arg_stable().

1885 {
1886  List *args;
1887  Node *arg;
1888 
1889  if (expr == NULL)
1890  return false;
1891 
1892  if (IsA(expr, FuncExpr))
1893  args = ((FuncExpr *) expr)->args;
1894  else if (IsA(expr, OpExpr))
1895  args = ((OpExpr *) expr)->args;
1896  else if (IsA(expr, DistinctExpr))
1897  args = ((DistinctExpr *) expr)->args;
1898  else if (IsA(expr, ScalarArrayOpExpr))
1899  args = ((ScalarArrayOpExpr *) expr)->args;
1900  else if (IsA(expr, NullIfExpr))
1901  args = ((NullIfExpr *) expr)->args;
1902  else if (IsA(expr, WindowFunc))
1903  args = ((WindowFunc *) expr)->args;
1904  else
1905  return false;
1906 
1907  if (argnum < 0 || argnum >= list_length(args))
1908  return false;
1909 
1910  arg = (Node *) list_nth(args, argnum);
1911 
1912  /*
1913  * Either a true Const or an external Param will have a value that doesn't
1914  * change during the execution of the query. In future we might want to
1915  * consider other cases too, e.g. now().
1916  */
1917  if (IsA(arg, Const))
1918  return true;
1919  if (IsA(arg, Param) &&
1920  ((Param *) arg)->paramkind == PARAM_EXTERN)
1921  return true;
1922 
1923  return false;
1924 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:587
Definition: nodes.h:536
static void * list_nth(const List *list, int n)
Definition: pg_list.h:278
static int list_length(const List *l)
Definition: pg_list.h:149
void * arg
Definition: pg_list.h:50

◆ get_call_expr_argtype()

Oid get_call_expr_argtype ( Node expr,
int  argnum 
)

Definition at line 1819 of file fmgr.c.

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

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

1820 {
1821  List *args;
1822  Oid argtype;
1823 
1824  if (expr == NULL)
1825  return InvalidOid;
1826 
1827  if (IsA(expr, FuncExpr))
1828  args = ((FuncExpr *) expr)->args;
1829  else if (IsA(expr, OpExpr))
1830  args = ((OpExpr *) expr)->args;
1831  else if (IsA(expr, DistinctExpr))
1832  args = ((DistinctExpr *) expr)->args;
1833  else if (IsA(expr, ScalarArrayOpExpr))
1834  args = ((ScalarArrayOpExpr *) expr)->args;
1835  else if (IsA(expr, NullIfExpr))
1836  args = ((NullIfExpr *) expr)->args;
1837  else if (IsA(expr, WindowFunc))
1838  args = ((WindowFunc *) expr)->args;
1839  else
1840  return InvalidOid;
1841 
1842  if (argnum < 0 || argnum >= list_length(args))
1843  return InvalidOid;
1844 
1845  argtype = exprType((Node *) list_nth(args, argnum));
1846 
1847  /*
1848  * special hack for ScalarArrayOpExpr: what the underlying function will
1849  * actually get passed is the element type of the array.
1850  */
1851  if (IsA(expr, ScalarArrayOpExpr) &&
1852  argnum == 1)
1853  argtype = get_base_element_type(argtype);
1854 
1855  return argtype;
1856 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:587
Definition: nodes.h:536
unsigned int Oid
Definition: postgres_ext.h:31
static void * list_nth(const List *list, int n)
Definition: pg_list.h:278
#define InvalidOid
Definition: postgres_ext.h:36
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
static int list_length(const List *l)
Definition: pg_list.h:149
Oid get_base_element_type(Oid typid)
Definition: lsyscache.c:2779
Definition: pg_list.h:50

◆ get_fn_expr_arg_stable()

bool get_fn_expr_arg_stable ( FmgrInfo flinfo,
int  argnum 
)

Definition at line 1865 of file fmgr.c.

References FmgrInfo::fn_expr, and get_call_expr_arg_stable().

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

1866 {
1867  /*
1868  * can't return anything useful if we have no FmgrInfo or if its fn_expr
1869  * node has not been initialized
1870  */
1871  if (!flinfo || !flinfo->fn_expr)
1872  return false;
1873 
1874  return get_call_expr_arg_stable(flinfo->fn_expr, argnum);
1875 }
bool get_call_expr_arg_stable(Node *expr, int argnum)
Definition: fmgr.c:1884
fmNodePtr fn_expr
Definition: fmgr.h:66

◆ get_fn_expr_argtype()

◆ get_fn_expr_rettype()

Oid get_fn_expr_rettype ( FmgrInfo flinfo)

Definition at line 1778 of file fmgr.c.

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

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

1779 {
1780  Node *expr;
1781 
1782  /*
1783  * can't return anything useful if we have no FmgrInfo or if its fn_expr
1784  * node has not been initialized
1785  */
1786  if (!flinfo || !flinfo->fn_expr)
1787  return InvalidOid;
1788 
1789  expr = flinfo->fn_expr;
1790 
1791  return exprType(expr);
1792 }
Definition: nodes.h:536
#define InvalidOid
Definition: postgres_ext.h:36
fmNodePtr fn_expr
Definition: fmgr.h:66
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41

◆ get_fn_expr_variadic()

bool get_fn_expr_variadic ( FmgrInfo flinfo)

Definition at line 1934 of file fmgr.c.

References FmgrInfo::fn_expr, and IsA.

Referenced by concat_internal(), count_nulls(), extract_variadic_args(), satisfies_hash_partition(), and text_format().

1935 {
1936  Node *expr;
1937 
1938  /*
1939  * can't return anything useful if we have no FmgrInfo or if its fn_expr
1940  * node has not been initialized
1941  */
1942  if (!flinfo || !flinfo->fn_expr)
1943  return false;
1944 
1945  expr = flinfo->fn_expr;
1946 
1947  if (IsA(expr, FuncExpr))
1948  return ((FuncExpr *) expr)->funcvariadic;
1949  else
1950  return false;
1951 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:587
Definition: nodes.h:536
fmNodePtr fn_expr
Definition: fmgr.h:66

◆ get_fn_opclass_options()

bytea* get_fn_opclass_options ( FmgrInfo flinfo)

Definition at line 1987 of file fmgr.c.

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

1988 {
1989  if (flinfo && flinfo->fn_expr && IsA(flinfo->fn_expr, Const))
1990  {
1991  Const *expr = (Const *) flinfo->fn_expr;
1992 
1993  if (expr->consttype == BYTEAOID)
1994  return expr->constisnull ? NULL : DatumGetByteaP(expr->constvalue);
1995  }
1996 
1997  ereport(ERROR,
1998  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1999  errmsg("operator class options info is absent in function call context")));
2000 
2001  return NULL;
2002 }
Datum constvalue
Definition: primnodes.h:219
#define IsA(nodeptr, _type_)
Definition: nodes.h:587
int errcode(int sqlerrcode)
Definition: elog.c:698
Oid consttype
Definition: primnodes.h:215
#define ERROR
Definition: elog.h:46
#define DatumGetByteaP(X)
Definition: fmgr.h:331
#define ereport(elevel,...)
Definition: elog.h:157
fmNodePtr fn_expr
Definition: fmgr.h:66
int errmsg(const char *fmt,...)
Definition: elog.c:909
bool constisnull
Definition: primnodes.h:220

◆ has_fn_opclass_options()

bool has_fn_opclass_options ( FmgrInfo flinfo)

Definition at line 1971 of file fmgr.c.

References Const::constisnull, Const::consttype, FmgrInfo::fn_expr, and IsA.

1972 {
1973  if (flinfo && flinfo->fn_expr && IsA(flinfo->fn_expr, Const))
1974  {
1975  Const *expr = (Const *) flinfo->fn_expr;
1976 
1977  if (expr->consttype == BYTEAOID)
1978  return !expr->constisnull;
1979  }
1980  return false;
1981 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:587
Oid consttype
Definition: primnodes.h:215
fmNodePtr fn_expr
Definition: fmgr.h:66
bool constisnull
Definition: primnodes.h:220

◆ InputFunctionCall()

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

Definition at line 1529 of file fmgr.c.

References CStringGetDatum, elog, ERROR, FmgrInfo::fn_oid, FmgrInfo::fn_strict, FunctionCallInvoke, InitFunctionCallInfoData, Int32GetDatum, InvalidOid, LOCAL_FCINFO, and ObjectIdGetDatum.

Referenced by BuildTupleFromCStrings(), domain_in(), hstore_populate_record(), make_tuple_from_result_row(), multirange_in(), NextCopyFrom(), OidInputFunctionCall(), plperl_sv_to_datum(), plsample_func_handler(), pltcl_func_handler(), pltcl_returnnext(), pltcl_SPI_execute_plan(), PLyObject_ToScalar(), PLyString_ToComposite(), populate_scalar(), range_in(), ReadArrayStr(), record_in(), and XmlTableGetValue().

1530 {
1531  LOCAL_FCINFO(fcinfo, 3);
1532  Datum result;
1533 
1534  if (str == NULL && flinfo->fn_strict)
1535  return (Datum) 0; /* just return null result */
1536 
1537  InitFunctionCallInfoData(*fcinfo, flinfo, 3, InvalidOid, NULL, NULL);
1538 
1539  fcinfo->args[0].value = CStringGetDatum(str);
1540  fcinfo->args[0].isnull = false;
1541  fcinfo->args[1].value = ObjectIdGetDatum(typioparam);
1542  fcinfo->args[1].isnull = false;
1543  fcinfo->args[2].value = Int32GetDatum(typmod);
1544  fcinfo->args[2].isnull = false;
1545 
1546  result = FunctionCallInvoke(fcinfo);
1547 
1548  /* Should get null result if and only if str is NULL */
1549  if (str == NULL)
1550  {
1551  if (!fcinfo->isnull)
1552  elog(ERROR, "input function %u returned non-NULL",
1553  flinfo->fn_oid);
1554  }
1555  else
1556  {
1557  if (fcinfo->isnull)
1558  elog(ERROR, "input function %u returned NULL",
1559  flinfo->fn_oid);
1560  }
1561 
1562  return result;
1563 }
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
bool fn_strict
Definition: fmgr.h:61
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
#define CStringGetDatum(X)
Definition: postgres.h:622
uintptr_t Datum
Definition: postgres.h:411
#define InvalidOid
Definition: postgres_ext.h:36
Oid fn_oid
Definition: fmgr.h:59
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define Int32GetDatum(X)
Definition: postgres.h:523
#define elog(elevel,...)
Definition: elog.h:232

◆ Int64GetDatum()

Datum Int64GetDatum ( int64  X)

Definition at line 1697 of file fmgr.c.

References palloc(), and PointerGetDatum.

Referenced by brin_metapage_info(), brin_page_items(), brin_summarize_new_values(), build_minmax_path(), DefineSequence(), delay_execution_planner(), ExecEvalNextValueExpr(), gbt_num_fetch(), generate_series_step_int8(), gin_metapage_info(), gin_page_opaque_info(), gist_page_opaque_info(), hash_array_extended(), hash_bitmap_info(), hash_metapage_info(), hash_page_items(), hash_page_stats(), hash_record_extended(), int4_cash(), int8_cash(), int8_to_char(), int8range_canonical(), leftmostvalue_int8(), leftmostvalue_money(), make_const(), perform_work_item(), pg_buffercache_pages(), pg_control_system(), pg_get_replication_slots(), pg_get_shmem_allocations(), pg_ls_dir_files(), pg_sequence_parameters(), pg_stat_file(), pg_stat_get_archiver(), pg_stat_get_progress_info(), pg_stat_get_replication_slot(), pg_stat_get_slru(), pg_stat_get_wal(), pg_stat_statements_info(), pg_visibility_map_rel(), pg_visibility_map_summary(), pg_visibility_rel(), pgstatginindex_internal(), pgstathashindex(), pgstattuple_approx_internal(), PutMemoryContextsStatsTupleStore(), report_corruption_internal(), rewriteSearchAndCycle(), StartReplication(), and validate_index_callback().

1698 {
1699  int64 *retval = (int64 *) palloc(sizeof(int64));
1700 
1701  *retval = X;
1702  return PointerGetDatum(retval);
1703 }
#define PointerGetDatum(X)
Definition: postgres.h:600
void * palloc(Size size)
Definition: mcxt.c:1062

◆ lookup_C_func()

static CFuncHashTabEntry * lookup_C_func ( HeapTuple  procedureTuple)
static

Definition at line 529 of file fmgr.c.

References CFuncHashTabEntry::fn_tid, CFuncHashTabEntry::fn_xmin, GETSTRUCT, HASH_FIND, hash_search(), HeapTupleHeaderGetRawXmin, ItemPointerEquals(), HeapTupleData::t_data, and HeapTupleData::t_self.

Referenced by fmgr_info_C_lang().

530 {
531  Oid fn_oid = ((Form_pg_proc) GETSTRUCT(procedureTuple))->oid;
532  CFuncHashTabEntry *entry;
533 
534  if (CFuncHash == NULL)
535  return NULL; /* no table yet */
536  entry = (CFuncHashTabEntry *)
538  &fn_oid,
539  HASH_FIND,
540  NULL);
541  if (entry == NULL)
542  return NULL; /* no such entry */
543  if (entry->fn_xmin == HeapTupleHeaderGetRawXmin(procedureTuple->t_data) &&
544  ItemPointerEquals(&entry->fn_tid, &procedureTuple->t_self))
545  return entry; /* OK */
546  return NULL; /* entry is out of date */
547 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
unsigned int Oid
Definition: postgres_ext.h:31
HeapTupleHeader t_data
Definition: htup.h:68
static HTAB * CFuncHash
Definition: fmgr.c:54
ItemPointerData t_self
Definition: htup.h:65
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:136
#define HeapTupleHeaderGetRawXmin(tup)
Definition: htup_details.h:308
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
Definition: itemptr.c:29
TransactionId fn_xmin
Definition: fmgr.c:48
ItemPointerData fn_tid
Definition: fmgr.c:49

◆ OidFunctionCall0Coll()

Datum OidFunctionCall0Coll ( Oid  functionId,
Oid  collation 
)

Definition at line 1400 of file fmgr.c.

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

1401 {
1402  FmgrInfo flinfo;
1403 
1404  fmgr_info(functionId, &flinfo);
1405 
1406  return FunctionCall0Coll(&flinfo, collation);
1407 }
Definition: fmgr.h:56
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126
Datum FunctionCall0Coll(FmgrInfo *flinfo, Oid collation)
Definition: fmgr.c:1111

◆ OidFunctionCall1Coll()

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

Definition at line 1410 of file fmgr.c.

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

Referenced by _bt_allequalimage(), and _hash_datum2hashkey_type().

1411 {
1412  FmgrInfo flinfo;
1413 
1414  fmgr_info(functionId, &flinfo);
1415 
1416  return FunctionCall1Coll(&flinfo, collation, arg1);
1417 }
Definition: fmgr.h:56
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126
Datum FunctionCall1Coll(FmgrInfo *flinfo, Oid collation, Datum arg1)
Definition: fmgr.c:1128

◆ OidFunctionCall2Coll()

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

Definition at line 1420 of file fmgr.c.

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

Referenced by _bt_compare_scankey_args(), and index_recheck_constraint().

1421 {
1422  FmgrInfo flinfo;
1423 
1424  fmgr_info(functionId, &flinfo);
1425 
1426  return FunctionCall2Coll(&flinfo, collation, arg1, arg2);
1427 }
Definition: fmgr.h:56
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:1148
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126

◆ OidFunctionCall3Coll()

Datum OidFunctionCall3Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3 
)

Definition at line 1430 of file fmgr.c.

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

1432 {
1433  FmgrInfo flinfo;
1434 
1435  fmgr_info(functionId, &flinfo);
1436 
1437  return FunctionCall3Coll(&flinfo, collation, arg1, arg2, arg3);
1438 }
Definition: fmgr.h:56
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126
Datum FunctionCall3Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3)
Definition: fmgr.c:1170

◆ OidFunctionCall4Coll()

Datum OidFunctionCall4Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4 
)

Definition at line 1441 of file fmgr.c.

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

Referenced by restriction_selectivity().

1443 {
1444  FmgrInfo flinfo;
1445 
1446  fmgr_info(functionId, &flinfo);
1447 
1448  return FunctionCall4Coll(&flinfo, collation, arg1, arg2, arg3, arg4);
1449 }
Definition: fmgr.h:56
Datum FunctionCall4Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4)
Definition: fmgr.c:1195
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126

◆ OidFunctionCall5Coll()

Datum OidFunctionCall5Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5 
)

Definition at line 1452 of file fmgr.c.

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

Referenced by join_selectivity().

1454 {
1455  FmgrInfo flinfo;
1456 
1457  fmgr_info(functionId, &flinfo);
1458 
1459  return FunctionCall5Coll(&flinfo, collation, arg1, arg2, arg3, arg4, arg5);
1460 }
Definition: fmgr.h:56
Datum FunctionCall5Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5)
Definition: fmgr.c:1222
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126

◆ OidFunctionCall6Coll()

Datum OidFunctionCall6Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6 
)

Definition at line 1463 of file fmgr.c.

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

1466 {
1467  FmgrInfo flinfo;
1468 
1469  fmgr_info(functionId, &flinfo);
1470 
1471  return FunctionCall6Coll(&flinfo, collation, arg1, arg2, arg3, arg4, arg5,
1472  arg6);
1473 }
Definition: fmgr.h:56
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126
Datum FunctionCall6Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6)
Definition: fmgr.c:1251

◆ OidFunctionCall7Coll()

Datum OidFunctionCall7Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7 
)

Definition at line 1476 of file fmgr.c.

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

1479 {
1480  FmgrInfo flinfo;
1481 
1482  fmgr_info(functionId, &flinfo);
1483 
1484  return FunctionCall7Coll(&flinfo, collation, arg1, arg2, arg3, arg4, arg5,
1485  arg6, arg7);
1486 }
Definition: fmgr.h:56
Datum FunctionCall7Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7)
Definition: fmgr.c:1283
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126

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

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

1492 {
1493  FmgrInfo flinfo;
1494 
1495  fmgr_info(functionId, &flinfo);
1496 
1497  return FunctionCall8Coll(&flinfo, collation, arg1, arg2, arg3, arg4, arg5,
1498  arg6, arg7, arg8);
1499 }
Definition: fmgr.h:56
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:1317
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126

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

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

1506 {
1507  FmgrInfo flinfo;
1508 
1509  fmgr_info(functionId, &flinfo);
1510 
1511  return FunctionCall9Coll(&flinfo, collation, arg1, arg2, arg3, arg4, arg5,
1512  arg6, arg7, arg8, arg9);
1513 }
Definition: fmgr.h:56
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:1353
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126

◆ OidInputFunctionCall()

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

Definition at line 1644 of file fmgr.c.

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

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

1645 {
1646  FmgrInfo flinfo;
1647 
1648  fmgr_info(functionId, &flinfo);
1649  return InputFunctionCall(&flinfo, str, typioparam, typmod);
1650 }
Definition: fmgr.h:56
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126
Datum InputFunctionCall(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
Definition: fmgr.c:1529

◆ OidOutputFunctionCall()

◆ OidReceiveFunctionCall()

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

Definition at line 1662 of file fmgr.c.

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

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

1664 {
1665  FmgrInfo flinfo;
1666 
1667  fmgr_info(functionId, &flinfo);
1668  return ReceiveFunctionCall(&flinfo, buf, typioparam, typmod);
1669 }
Definition: fmgr.h:56
Datum ReceiveFunctionCall(FmgrInfo *flinfo, StringInfo buf, Oid typioparam, int32 typmod)
Definition: fmgr.c:1587
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126

◆ OidSendFunctionCall()

bytea* OidSendFunctionCall ( Oid  functionId,
Datum  val 
)

Definition at line 1672 of file fmgr.c.

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

Referenced by logicalrep_write_tuple(), and SendFunctionResult().

1673 {
1674  FmgrInfo flinfo;
1675 
1676  fmgr_info(functionId, &flinfo);
1677  return SendFunctionCall(&flinfo, val);
1678 }
Definition: fmgr.h:56
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126
bytea * SendFunctionCall(FmgrInfo *flinfo, Datum val)
Definition: fmgr.c:1634
long val
Definition: informix.c:664

◆ OutputFunctionCall()

◆ pg_detoast_datum()

struct varlena* pg_detoast_datum ( struct varlena datum)

Definition at line 1722 of file fmgr.c.

References detoast_attr(), and VARATT_IS_EXTENDED.

1723 {
1724  if (VARATT_IS_EXTENDED(datum))
1725  return detoast_attr(datum);
1726  else
1727  return datum;
1728 }
struct varlena * detoast_attr(struct varlena *attr)
Definition: detoast.c:116
#define VARATT_IS_EXTENDED(PTR)
Definition: postgres.h:340

◆ pg_detoast_datum_copy()

struct varlena* pg_detoast_datum_copy ( struct varlena datum)

Definition at line 1731 of file fmgr.c.

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

1732 {
1733  if (VARATT_IS_EXTENDED(datum))
1734  return detoast_attr(datum);
1735  else
1736  {
1737  /* Make a modifiable copy of the varlena object */
1738  Size len = VARSIZE(datum);
1739  struct varlena *result = (struct varlena *) palloc(len);
1740 
1741  memcpy(result, datum, len);
1742  return result;
1743  }
1744 }
#define VARSIZE(PTR)
Definition: postgres.h:316
struct varlena * detoast_attr(struct varlena *attr)
Definition: detoast.c:116
size_t Size
Definition: c.h:540
#define VARATT_IS_EXTENDED(PTR)
Definition: postgres.h:340
void * palloc(Size size)
Definition: mcxt.c:1062
Definition: c.h:621

◆ pg_detoast_datum_packed()

struct varlena* pg_detoast_datum_packed ( struct varlena datum)

Definition at line 1754 of file fmgr.c.

References detoast_attr(), VARATT_IS_COMPRESSED, and VARATT_IS_EXTERNAL.

Referenced by text_to_cstring(), and text_to_cstring_buffer().

1755 {
1756  if (VARATT_IS_COMPRESSED(datum) || VARATT_IS_EXTERNAL(datum))
1757  return detoast_attr(datum);
1758  else
1759  return datum;
1760 }
#define VARATT_IS_COMPRESSED(PTR)
Definition: postgres.h:325
#define VARATT_IS_EXTERNAL(PTR)
Definition: postgres.h:326
struct varlena * detoast_attr(struct varlena *attr)
Definition: detoast.c:116

◆ pg_detoast_datum_slice()

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

Definition at line 1747 of file fmgr.c.

References detoast_attr_slice().

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

◆ ReceiveFunctionCall()

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

Definition at line 1587 of file fmgr.c.

References elog, ERROR, FmgrInfo::fn_oid, FmgrInfo::fn_strict, FunctionCallInvoke, InitFunctionCallInfoData, Int32GetDatum, InvalidOid, LOCAL_FCINFO, ObjectIdGetDatum, and PointerGetDatum.

Referenced by CopyReadBinaryAttribute(), domain_recv(), multirange_recv(), OidReceiveFunctionCall(), range_recv(), ReadArrayBinary(), and record_recv().

1589 {
1590  LOCAL_FCINFO(fcinfo, 3);
1591  Datum result;
1592 
1593  if (buf == NULL && flinfo->fn_strict)
1594  return (Datum) 0; /* just return null result */
1595 
1596  InitFunctionCallInfoData(*fcinfo, flinfo, 3, InvalidOid, NULL, NULL);
1597 
1598  fcinfo->args[0].value = PointerGetDatum(buf);
1599  fcinfo->args[0].isnull = false;
1600  fcinfo->args[1].value = ObjectIdGetDatum(typioparam);
1601  fcinfo->args[1].isnull = false;
1602  fcinfo->args[2].value = Int32GetDatum(typmod);
1603  fcinfo->args[2].isnull = false;
1604 
1605  result = FunctionCallInvoke(fcinfo);
1606 
1607  /* Should get null result if and only if buf is NULL */
1608  if (buf == NULL)
1609  {
1610  if (!fcinfo->isnull)
1611  elog(ERROR, "receive function %u returned non-NULL",
1612  flinfo->fn_oid);
1613  }
1614  else
1615  {
1616  if (fcinfo->isnull)
1617  elog(ERROR, "receive function %u returned NULL",
1618  flinfo->fn_oid);
1619  }
1620 
1621  return result;
1622 }
#define PointerGetDatum(X)
Definition: postgres.h:600
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
bool fn_strict
Definition: fmgr.h:61
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
uintptr_t Datum
Definition: postgres.h:411
#define InvalidOid
Definition: postgres_ext.h:36
Oid fn_oid
Definition: fmgr.h:59
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define Int32GetDatum(X)
Definition: postgres.h:523
#define elog(elevel,...)
Definition: elog.h:232

◆ record_C_func()

static void record_C_func ( HeapTuple  procedureTuple,
PGFunction  user_fn,
const Pg_finfo_record inforec 
)
static

Definition at line 553 of file fmgr.c.

References HASHCTL::entrysize, CFuncHashTabEntry::fn_tid, CFuncHashTabEntry::fn_xmin, GETSTRUCT, HASH_BLOBS, hash_create(), HASH_ELEM, HASH_ENTER, hash_search(), HeapTupleHeaderGetRawXmin, CFuncHashTabEntry::inforec, HASHCTL::keysize, HeapTupleData::t_data, HeapTupleData::t_self, and CFuncHashTabEntry::user_fn.

Referenced by fmgr_info_C_lang().

555 {
556  Oid fn_oid = ((Form_pg_proc) GETSTRUCT(procedureTuple))->oid;
557  CFuncHashTabEntry *entry;
558  bool found;
559 
560  /* Create the hash table if it doesn't exist yet */
561  if (CFuncHash == NULL)
562  {
563  HASHCTL hash_ctl;
564 
565  hash_ctl.keysize = sizeof(Oid);
566  hash_ctl.entrysize = sizeof(CFuncHashTabEntry);
567  CFuncHash = hash_create("CFuncHash",
568  100,
569  &hash_ctl,
571  }
572 
573  entry = (CFuncHashTabEntry *)
575  &fn_oid,
576  HASH_ENTER,
577  &found);
578  /* OID is already filled in */
579  entry->fn_xmin = HeapTupleHeaderGetRawXmin(procedureTuple->t_data);
580  entry->fn_tid = procedureTuple->t_self;
581  entry->user_fn = user_fn;
582  entry->inforec = inforec;
583 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
#define HASH_ELEM
Definition: hsearch.h:95
const Pg_finfo_record * inforec
Definition: fmgr.c:51
Size entrysize
Definition: hsearch.h:76
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
unsigned int Oid
Definition: postgres_ext.h:31
HeapTupleHeader t_data
Definition: htup.h:68
static HTAB * CFuncHash
Definition: fmgr.c:54
ItemPointerData t_self
Definition: htup.h:65
PGFunction user_fn
Definition: fmgr.c:50
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:349
#define HASH_BLOBS
Definition: hsearch.h:97
Size keysize
Definition: hsearch.h:75
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:136
#define HeapTupleHeaderGetRawXmin(tup)
Definition: htup_details.h:308
TransactionId fn_xmin
Definition: fmgr.c:48
ItemPointerData fn_tid
Definition: fmgr.c:49

◆ SendFunctionCall()

bytea* SendFunctionCall ( FmgrInfo flinfo,
Datum  val 
)

Definition at line 1634 of file fmgr.c.

References DatumGetByteaP, and FunctionCall1.

Referenced by array_send(), CopyOneRowTo(), multirange_send(), OidSendFunctionCall(), printtup(), range_send(), and record_send().

1635 {
1636  return DatumGetByteaP(FunctionCall1(flinfo, val));
1637 }
#define DatumGetByteaP(X)
Definition: fmgr.h:331
#define FunctionCall1(flinfo, arg1)
Definition: fmgr.h:644
long val
Definition: informix.c:664

◆ set_fn_opclass_options()

void set_fn_opclass_options ( FmgrInfo flinfo,
bytea options 
)

Definition at line 1960 of file fmgr.c.

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

Referenced by gincost_pattern(), and index_getprocinfo().

1961 {
1962  flinfo->fn_expr = (Node *) makeConst(BYTEAOID, -1, InvalidOid, -1,
1963  PointerGetDatum(options),
1964  options == NULL, false);
1965 }
#define PointerGetDatum(X)
Definition: postgres.h:600
Definition: nodes.h:536
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
Definition: makefuncs.c:299
#define InvalidOid
Definition: postgres_ext.h:36
fmNodePtr fn_expr
Definition: fmgr.h:66

Variable Documentation

◆ CFuncHash

HTAB* CFuncHash = NULL
static

Definition at line 54 of file fmgr.c.

◆ fmgr_hook

PGDLLIMPORT fmgr_hook_type fmgr_hook = NULL

Definition at line 39 of file fmgr.c.

Referenced by fmgr_security_definer(), and sepgsql_init_client_label().

◆ needs_fmgr_hook

PGDLLIMPORT needs_fmgr_hook_type needs_fmgr_hook = NULL

Definition at line 38 of file fmgr.c.

Referenced by sepgsql_init_client_label().