PostgreSQL Source Code  git master
fmgr.c File Reference
#include "postgres.h"
#include "access/tuptoaster.h"
#include "catalog/pg_language.h"
#include "catalog/pg_proc.h"
#include "executor/functions.h"
#include "lib/stringinfo.h"
#include "miscadmin.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)
 
static 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)
 
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 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 Float4GetDatum (float4 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)
 
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 975 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

976 {
977  FunctionCallInfoData fcinfo;
978  Datum result;
979 
980  InitFunctionCallInfoData(fcinfo, flinfo, 1, collation, NULL, NULL);
981 
982  fcinfo.arg[0] = arg1;
983  fcinfo.argnull[0] = false;
984 
985  result = (*func) (&fcinfo);
986 
987  /* Check for null result, since caller is clearly not expecting one */
988  if (fcinfo.isnull)
989  elog(ERROR, "function %p returned NULL", (void *) func);
990 
991  return result;
992 }
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

◆ CallerFInfoFunctionCall2()

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

Definition at line 995 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

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

996 {
997  FunctionCallInfoData fcinfo;
998  Datum result;
999 
1000  InitFunctionCallInfoData(fcinfo, flinfo, 2, collation, NULL, NULL);
1001 
1002  fcinfo.arg[0] = arg1;
1003  fcinfo.arg[1] = arg2;
1004  fcinfo.argnull[0] = false;
1005  fcinfo.argnull[1] = false;
1006 
1007  result = (*func) (&fcinfo);
1008 
1009  /* Check for null result, since caller is clearly not expecting one */
1010  if (fcinfo.isnull)
1011  elog(ERROR, "function %p returned NULL", (void *) func);
1012 
1013  return result;
1014 }
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

◆ CheckFunctionValidatorAccess()

bool CheckFunctionValidatorAccess ( Oid  validatorOid,
Oid  functionOid 
)

Definition at line 2088 of file fmgr.c.

References ACL_EXECUTE, ACL_KIND_LANGUAGE, ACL_KIND_PROC, ACL_USAGE, aclcheck_error(), ACLCHECK_OK, elog, ereport, errcode(), errmsg(), ERROR, GETSTRUCT, GetUserId(), HeapTupleIsValid, LANGOID, NameStr, 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().

2089 {
2090  HeapTuple procTup;
2091  HeapTuple langTup;
2092  Form_pg_proc procStruct;
2093  Form_pg_language langStruct;
2094  AclResult aclresult;
2095 
2096  /*
2097  * Get the function's pg_proc entry. Throw a user-facing error for bad
2098  * OID, because validators can be called with user-specified OIDs.
2099  */
2100  procTup = SearchSysCache1(PROCOID, ObjectIdGetDatum(functionOid));
2101  if (!HeapTupleIsValid(procTup))
2102  ereport(ERROR,
2103  (errcode(ERRCODE_UNDEFINED_FUNCTION),
2104  errmsg("function with OID %u does not exist", functionOid)));
2105  procStruct = (Form_pg_proc) GETSTRUCT(procTup);
2106 
2107  /*
2108  * Fetch pg_language entry to know if this is the correct validation
2109  * function for that pg_proc entry.
2110  */
2111  langTup = SearchSysCache1(LANGOID, ObjectIdGetDatum(procStruct->prolang));
2112  if (!HeapTupleIsValid(langTup))
2113  elog(ERROR, "cache lookup failed for language %u", procStruct->prolang);
2114  langStruct = (Form_pg_language) GETSTRUCT(langTup);
2115 
2116  if (langStruct->lanvalidator != validatorOid)
2117  ereport(ERROR,
2118  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2119  errmsg("language validation function %u called for language %u instead of %u",
2120  validatorOid, procStruct->prolang,
2121  langStruct->lanvalidator)));
2122 
2123  /* first validate that we have permissions to use the language */
2124  aclresult = pg_language_aclcheck(procStruct->prolang, GetUserId(),
2125  ACL_USAGE);
2126  if (aclresult != ACLCHECK_OK)
2127  aclcheck_error(aclresult, ACL_KIND_LANGUAGE,
2128  NameStr(langStruct->lanname));
2129 
2130  /*
2131  * Check whether we are allowed to execute the function itself. If we can
2132  * execute it, there should be no possible side-effect of
2133  * compiling/validation that execution can't have.
2134  */
2135  aclresult = pg_proc_aclcheck(functionOid, GetUserId(), ACL_EXECUTE);
2136  if (aclresult != ACLCHECK_OK)
2137  aclcheck_error(aclresult, ACL_KIND_PROC, NameStr(procStruct->proname));
2138 
2139  ReleaseSysCache(procTup);
2140  ReleaseSysCache(langTup);
2141 
2142  return true;
2143 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:661
Oid GetUserId(void)
Definition: miscinit.c:284
int errcode(int sqlerrcode)
Definition: elog.c:575
AclResult pg_language_aclcheck(Oid lang_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4458
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
void aclcheck_error(AclResult aclerr, AclObjectKind objectkind, const char *objectname)
Definition: aclchk.c:3399
#define ACL_USAGE
Definition: parsenodes.h:80
#define ereport(elevel, rest)
Definition: elog.h:122
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
AclResult
Definition: acl.h:178
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:83
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
FormData_pg_language * Form_pg_language
Definition: pg_language.h:51
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define ACL_EXECUTE
Definition: parsenodes.h:79
AclResult pg_proc_aclcheck(Oid proc_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4446
#define NameStr(name)
Definition: c.h:547
#define elog
Definition: elog.h:219

◆ clear_external_function_hash()

void clear_external_function_hash ( void *  filehandle)

Definition at line 503 of file fmgr.c.

References hash_destroy().

Referenced by internal_unload_library().

504 {
505  if (CFuncHash)
507  CFuncHash = NULL;
508 }
void hash_destroy(HTAB *hashp)
Definition: dynahash.c:810
static HTAB * CFuncHash
Definition: fmgr.c:52

◆ DirectFunctionCall1Coll()

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

Definition at line 702 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

Referenced by Generic_Text_IC_like(), and libpqrcv_create_slot().

703 {
704  FunctionCallInfoData fcinfo;
705  Datum result;
706 
707  InitFunctionCallInfoData(fcinfo, NULL, 1, collation, NULL, NULL);
708 
709  fcinfo.arg[0] = arg1;
710  fcinfo.argnull[0] = false;
711 
712  result = (*func) (&fcinfo);
713 
714  /* Check for null result, since caller is clearly not expecting one */
715  if (fcinfo.isnull)
716  elog(ERROR, "function %p returned NULL", (void *) func);
717 
718  return result;
719 }
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

◆ DirectFunctionCall2Coll()

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

Definition at line 722 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

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

723 {
724  FunctionCallInfoData fcinfo;
725  Datum result;
726 
727  InitFunctionCallInfoData(fcinfo, NULL, 2, collation, NULL, NULL);
728 
729  fcinfo.arg[0] = arg1;
730  fcinfo.arg[1] = arg2;
731  fcinfo.argnull[0] = false;
732  fcinfo.argnull[1] = false;
733 
734  result = (*func) (&fcinfo);
735 
736  /* Check for null result, since caller is clearly not expecting one */
737  if (fcinfo.isnull)
738  elog(ERROR, "function %p returned NULL", (void *) func);
739 
740  return result;
741 }
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

◆ DirectFunctionCall3Coll()

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

Definition at line 744 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

746 {
747  FunctionCallInfoData fcinfo;
748  Datum result;
749 
750  InitFunctionCallInfoData(fcinfo, NULL, 3, collation, NULL, NULL);
751 
752  fcinfo.arg[0] = arg1;
753  fcinfo.arg[1] = arg2;
754  fcinfo.arg[2] = arg3;
755  fcinfo.argnull[0] = false;
756  fcinfo.argnull[1] = false;
757  fcinfo.argnull[2] = false;
758 
759  result = (*func) (&fcinfo);
760 
761  /* Check for null result, since caller is clearly not expecting one */
762  if (fcinfo.isnull)
763  elog(ERROR, "function %p returned NULL", (void *) func);
764 
765  return result;
766 }
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

◆ DirectFunctionCall4Coll()

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

Definition at line 769 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

Referenced by execute_extension_script().

771 {
772  FunctionCallInfoData fcinfo;
773  Datum result;
774 
775  InitFunctionCallInfoData(fcinfo, NULL, 4, collation, NULL, NULL);
776 
777  fcinfo.arg[0] = arg1;
778  fcinfo.arg[1] = arg2;
779  fcinfo.arg[2] = arg3;
780  fcinfo.arg[3] = arg4;
781  fcinfo.argnull[0] = false;
782  fcinfo.argnull[1] = false;
783  fcinfo.argnull[2] = false;
784  fcinfo.argnull[3] = false;
785 
786  result = (*func) (&fcinfo);
787 
788  /* Check for null result, since caller is clearly not expecting one */
789  if (fcinfo.isnull)
790  elog(ERROR, "function %p returned NULL", (void *) func);
791 
792  return result;
793 }
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

◆ DirectFunctionCall5Coll()

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

Definition at line 796 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

798 {
799  FunctionCallInfoData fcinfo;
800  Datum result;
801 
802  InitFunctionCallInfoData(fcinfo, NULL, 5, collation, NULL, NULL);
803 
804  fcinfo.arg[0] = arg1;
805  fcinfo.arg[1] = arg2;
806  fcinfo.arg[2] = arg3;
807  fcinfo.arg[3] = arg4;
808  fcinfo.arg[4] = arg5;
809  fcinfo.argnull[0] = false;
810  fcinfo.argnull[1] = false;
811  fcinfo.argnull[2] = false;
812  fcinfo.argnull[3] = false;
813  fcinfo.argnull[4] = false;
814 
815  result = (*func) (&fcinfo);
816 
817  /* Check for null result, since caller is clearly not expecting one */
818  if (fcinfo.isnull)
819  elog(ERROR, "function %p returned NULL", (void *) func);
820 
821  return result;
822 }
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

◆ DirectFunctionCall6Coll()

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

Definition at line 825 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

828 {
829  FunctionCallInfoData fcinfo;
830  Datum result;
831 
832  InitFunctionCallInfoData(fcinfo, NULL, 6, collation, NULL, NULL);
833 
834  fcinfo.arg[0] = arg1;
835  fcinfo.arg[1] = arg2;
836  fcinfo.arg[2] = arg3;
837  fcinfo.arg[3] = arg4;
838  fcinfo.arg[4] = arg5;
839  fcinfo.arg[5] = arg6;
840  fcinfo.argnull[0] = false;
841  fcinfo.argnull[1] = false;
842  fcinfo.argnull[2] = false;
843  fcinfo.argnull[3] = false;
844  fcinfo.argnull[4] = false;
845  fcinfo.argnull[5] = false;
846 
847  result = (*func) (&fcinfo);
848 
849  /* Check for null result, since caller is clearly not expecting one */
850  if (fcinfo.isnull)
851  elog(ERROR, "function %p returned NULL", (void *) func);
852 
853  return result;
854 }
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

◆ DirectFunctionCall7Coll()

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

Definition at line 857 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

860 {
861  FunctionCallInfoData fcinfo;
862  Datum result;
863 
864  InitFunctionCallInfoData(fcinfo, NULL, 7, collation, NULL, NULL);
865 
866  fcinfo.arg[0] = arg1;
867  fcinfo.arg[1] = arg2;
868  fcinfo.arg[2] = arg3;
869  fcinfo.arg[3] = arg4;
870  fcinfo.arg[4] = arg5;
871  fcinfo.arg[5] = arg6;
872  fcinfo.arg[6] = arg7;
873  fcinfo.argnull[0] = false;
874  fcinfo.argnull[1] = false;
875  fcinfo.argnull[2] = false;
876  fcinfo.argnull[3] = false;
877  fcinfo.argnull[4] = false;
878  fcinfo.argnull[5] = false;
879  fcinfo.argnull[6] = false;
880 
881  result = (*func) (&fcinfo);
882 
883  /* Check for null result, since caller is clearly not expecting one */
884  if (fcinfo.isnull)
885  elog(ERROR, "function %p returned NULL", (void *) func);
886 
887  return result;
888 }
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

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

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

894 {
895  FunctionCallInfoData fcinfo;
896  Datum result;
897 
898  InitFunctionCallInfoData(fcinfo, NULL, 8, collation, NULL, NULL);
899 
900  fcinfo.arg[0] = arg1;
901  fcinfo.arg[1] = arg2;
902  fcinfo.arg[2] = arg3;
903  fcinfo.arg[3] = arg4;
904  fcinfo.arg[4] = arg5;
905  fcinfo.arg[5] = arg6;
906  fcinfo.arg[6] = arg7;
907  fcinfo.arg[7] = arg8;
908  fcinfo.argnull[0] = false;
909  fcinfo.argnull[1] = false;
910  fcinfo.argnull[2] = false;
911  fcinfo.argnull[3] = false;
912  fcinfo.argnull[4] = false;
913  fcinfo.argnull[5] = false;
914  fcinfo.argnull[6] = false;
915  fcinfo.argnull[7] = false;
916 
917  result = (*func) (&fcinfo);
918 
919  /* Check for null result, since caller is clearly not expecting one */
920  if (fcinfo.isnull)
921  elog(ERROR, "function %p returned NULL", (void *) func);
922 
923  return result;
924 }
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

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

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

931 {
932  FunctionCallInfoData fcinfo;
933  Datum result;
934 
935  InitFunctionCallInfoData(fcinfo, NULL, 9, collation, NULL, NULL);
936 
937  fcinfo.arg[0] = arg1;
938  fcinfo.arg[1] = arg2;
939  fcinfo.arg[2] = arg3;
940  fcinfo.arg[3] = arg4;
941  fcinfo.arg[4] = arg5;
942  fcinfo.arg[5] = arg6;
943  fcinfo.arg[6] = arg7;
944  fcinfo.arg[7] = arg8;
945  fcinfo.arg[8] = arg9;
946  fcinfo.argnull[0] = false;
947  fcinfo.argnull[1] = false;
948  fcinfo.argnull[2] = false;
949  fcinfo.argnull[3] = false;
950  fcinfo.argnull[4] = false;
951  fcinfo.argnull[5] = false;
952  fcinfo.argnull[6] = false;
953  fcinfo.argnull[7] = false;
954  fcinfo.argnull[8] = false;
955 
956  result = (*func) (&fcinfo);
957 
958  /* Check for null result, since caller is clearly not expecting one */
959  if (fcinfo.isnull)
960  elog(ERROR, "function %p returned NULL", (void *) func);
961 
962  return result;
963 }
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

◆ fetch_finfo_record()

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

Definition at line 379 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().

380 {
381  char *infofuncname;
382  PGFInfoFunction infofunc;
383  const Pg_finfo_record *inforec;
384 
385  infofuncname = psprintf("pg_finfo_%s", funcname);
386 
387  /* Try to look up the info function */
388  infofunc = (PGFInfoFunction) lookup_external_function(filehandle,
389  infofuncname);
390  if (infofunc == NULL)
391  {
392  ereport(ERROR,
393  (errcode(ERRCODE_UNDEFINED_FUNCTION),
394  errmsg("could not find function information for function \"%s\"",
395  funcname),
396  errhint("SQL-callable functions need an accompanying PG_FUNCTION_INFO_V1(funcname).")));
397  return NULL; /* silence compiler */
398  }
399 
400  /* Found, so call it */
401  inforec = (*infofunc) ();
402 
403  /* Validate result as best we can */
404  if (inforec == NULL)
405  elog(ERROR, "null result from info function \"%s\"", infofuncname);
406  switch (inforec->api_version)
407  {
408  case 1:
409  /* OK, no additional fields to validate */
410  break;
411  default:
412  ereport(ERROR,
413  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
414  errmsg("unrecognized API version %d reported by info function \"%s\"",
415  inforec->api_version, infofuncname)));
416  break;
417  }
418 
419  pfree(infofuncname);
420  return inforec;
421 }
PGFunction lookup_external_function(void *filehandle, const char *funcname)
Definition: dfmgr.c:162
int errhint(const char *fmt,...)
Definition: elog.c:987
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
int errcode(int sqlerrcode)
Definition: elog.c:575
void pfree(void *pointer)
Definition: mcxt.c:949
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
const Pg_finfo_record *(* PGFInfoFunction)(void)
Definition: fmgr.h:360
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219
int api_version
Definition: fmgr.h:355

◆ Float4GetDatum()

Datum Float4GetDatum ( float4  X)

Definition at line 1798 of file fmgr.c.

References palloc(), and PointerGetDatum.

Referenced by AddEnumLabel(), EnumValuesCreate(), gbt_num_fetch(), getNextNearest(), InsertPgClassTuple(), leftmostvalue_float4(), ProcedureCreate(), set_limit(), and update_attstats().

1799 {
1800  float4 *retval = (float4 *) palloc(sizeof(float4));
1801 
1802  *retval = X;
1803  return PointerGetDatum(retval);
1804 }
#define PointerGetDatum(X)
Definition: postgres.h:562
float float4
Definition: c.h:428
void * palloc(Size size)
Definition: mcxt.c:848

◆ Float8GetDatum()

Datum Float8GetDatum ( float8  X)

Definition at line 1810 of file fmgr.c.

References palloc(), and PointerGetDatum.

Referenced by assign_random_seed(), compute_range_stats(), float8_lerp(), gbt_num_fetch(), getNextNearest(), hash_metapage_info(), int8_to_char(), interval_avg(), leftmostvalue_float8(), normal_rand(), pgstathashindex(), pgstattuple_approx_internal(), spg_kd_picksplit(), and SPI_sql_row_to_xmlelement().

1811 {
1812  float8 *retval = (float8 *) palloc(sizeof(float8));
1813 
1814  *retval = X;
1815  return PointerGetDatum(retval);
1816 }
#define PointerGetDatum(X)
Definition: postgres.h:562
double float8
Definition: c.h:429
void * palloc(Size size)
Definition: mcxt.c:848

◆ fmgr_info()

void fmgr_info ( Oid  functionId,
FmgrInfo finfo 
)

Definition at line 122 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_page_items(), build_pertrans_for_aggref(), call_pltcl_start_proc(), compute_distinct_stats(), CopyTo(), eqjoinsel_inner(), eqjoinsel_semi(), EventTriggerInvoke(), ExecCallTriggerFunc(), ExecHashTableCreate(), ExecInitAgg(), ExecInitExprRec(), ExecInitFunc(), ExecInitSubPlan(), ExecInitTableFuncScan(), execTuplesHashPrepare(), execTuplesMatchPrepare(), fetch_fp_info(), get_variable_range(), inet_mcv_join_sel(), initialize_peragg(), ltreeparentsel(), networkjoinsel_semi(), networksel(), OidFunctionCall0Coll(), OidFunctionCall1Coll(), OidFunctionCall2Coll(), OidFunctionCall3Coll(), OidFunctionCall4Coll(), OidFunctionCall5Coll(), OidFunctionCall6Coll(), OidFunctionCall7Coll(), OidFunctionCall8Coll(), OidFunctionCall9Coll(), OidInputFunctionCall(), OidOutputFunctionCall(), OidReceiveFunctionCall(), OidSendFunctionCall(), patternsel(), plperl_ref_from_pg_array(), postgresBeginForeignModify(), prefix_quals(), prefix_selectivity(), prepare_query_params(), printtup_prepare_info(), RelationBuildPartitionKey(), scalararraysel(), scalarineqsel(), ScanKeyEntryInitialize(), ScanKeyInit(), text_format(), TupleDescGetAttInMetadata(), and var_eq_const().

123 {
124  fmgr_info_cxt_security(functionId, finfo, CurrentMemoryContext, false);
125 }
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
static void fmgr_info_cxt_security(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt, bool ignore_security)
Definition: fmgr.c:142

◆ fmgr_info_C_lang()

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

Definition at line 268 of file fmgr.c.

References Anum_pg_proc_probin, Anum_pg_proc_prosrc, 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().

269 {
270  CFuncHashTabEntry *hashentry;
271  PGFunction user_fn;
272  const Pg_finfo_record *inforec;
273  bool isnull;
274 
275  /*
276  * See if we have the function address cached already
277  */
278  hashentry = lookup_C_func(procedureTuple);
279  if (hashentry)
280  {
281  user_fn = hashentry->user_fn;
282  inforec = hashentry->inforec;
283  }
284  else
285  {
286  Datum prosrcattr,
287  probinattr;
288  char *prosrcstring,
289  *probinstring;
290  void *libraryhandle;
291 
292  /*
293  * Get prosrc and probin strings (link symbol and library filename).
294  * While in general these columns might be null, that's not allowed
295  * for C-language functions.
296  */
297  prosrcattr = SysCacheGetAttr(PROCOID, procedureTuple,
298  Anum_pg_proc_prosrc, &isnull);
299  if (isnull)
300  elog(ERROR, "null prosrc for C function %u", functionId);
301  prosrcstring = TextDatumGetCString(prosrcattr);
302 
303  probinattr = SysCacheGetAttr(PROCOID, procedureTuple,
304  Anum_pg_proc_probin, &isnull);
305  if (isnull)
306  elog(ERROR, "null probin for C function %u", functionId);
307  probinstring = TextDatumGetCString(probinattr);
308 
309  /* Look up the function itself */
310  user_fn = load_external_function(probinstring, prosrcstring, true,
311  &libraryhandle);
312 
313  /* Get the function information record (real or default) */
314  inforec = fetch_finfo_record(libraryhandle, prosrcstring);
315 
316  /* Cache the addresses for later calls */
317  record_C_func(procedureTuple, user_fn, inforec);
318 
319  pfree(prosrcstring);
320  pfree(probinstring);
321  }
322 
323  switch (inforec->api_version)
324  {
325  case 1:
326  /* New style: call directly */
327  finfo->fn_addr = user_fn;
328  break;
329  default:
330  /* Shouldn't get here if fetch_finfo_record did its job */
331  elog(ERROR, "unrecognized function API version: %d",
332  inforec->api_version);
333  break;
334  }
335 }
Datum(* PGFunction)(FunctionCallInfo fcinfo)
Definition: fmgr.h:40
PGFunction fn_addr
Definition: fmgr.h:58
const Pg_finfo_record * inforec
Definition: fmgr.c:49
#define Anum_pg_proc_prosrc
Definition: pg_proc.h:115
#define Anum_pg_proc_probin
Definition: pg_proc.h:116
void pfree(void *pointer)
Definition: mcxt.c:949
#define ERROR
Definition: elog.h:43
PGFunction user_fn
Definition: fmgr.c:48
PGFunction load_external_function(const char *filename, const char *funcname, bool signalNotFound, void **filehandle)
Definition: dfmgr.c:94
#define TextDatumGetCString(d)
Definition: builtins.h:92
uintptr_t Datum
Definition: postgres.h:372
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1368
static void record_C_func(HeapTuple procedureTuple, PGFunction user_fn, const Pg_finfo_record *inforec)
Definition: fmgr.c:463
static CFuncHashTabEntry * lookup_C_func(HeapTuple procedureTuple)
Definition: fmgr.c:439
const Pg_finfo_record * fetch_finfo_record(void *filehandle, const char *funcname)
Definition: fmgr.c:379
#define elog
Definition: elog.h:219
int api_version
Definition: fmgr.h:355

◆ fmgr_info_copy()

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

Definition at line 519 of file fmgr.c.

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

Referenced by bringetbitmap(), gistrescan(), inclusion_get_procinfo(), initBloomState(), initGinState(), initGISTstate(), satisfies_hash_partition(), and ScanKeyEntryInitializeWithInfo().

521 {
522  memcpy(dstinfo, srcinfo, sizeof(FmgrInfo));
523  dstinfo->fn_mcxt = destcxt;
524  dstinfo->fn_extra = NULL;
525 }
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 142 of file fmgr.c.

References Anum_pg_proc_proconfig, Anum_pg_proc_prosrc, ClanguageId, 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, INTERNALlanguageId, InvalidOid, FmgrBuiltin::nargs, ObjectIdGetDatum, pfree(), PROCOID, ReleaseSysCache(), FmgrBuiltin::retset, SearchSysCache1(), SQLlanguageId, 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().

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

◆ fmgr_info_other_lang()

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

Definition at line 342 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().

343 {
344  Form_pg_proc procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
345  Oid language = procedureStruct->prolang;
346  HeapTuple languageTuple;
347  Form_pg_language languageStruct;
348  FmgrInfo plfinfo;
349 
350  languageTuple = SearchSysCache1(LANGOID, ObjectIdGetDatum(language));
351  if (!HeapTupleIsValid(languageTuple))
352  elog(ERROR, "cache lookup failed for language %u", language);
353  languageStruct = (Form_pg_language) GETSTRUCT(languageTuple);
354 
355  /*
356  * Look up the language's call handler function, ignoring any attributes
357  * that would normally cause insertion of fmgr_security_definer. We need
358  * to get back a bare pointer to the actual C-language function.
359  */
360  fmgr_info_cxt_security(languageStruct->lanplcallfoid, &plfinfo,
361  CurrentMemoryContext, true);
362  finfo->fn_addr = plfinfo.fn_addr;
363 
364  ReleaseSysCache(languageTuple);
365 }
Definition: fmgr.h:56
#define GETSTRUCT(TUP)
Definition: htup_details.h:661
PGFunction fn_addr
Definition: fmgr.h:58
unsigned int Oid
Definition: postgres_ext.h:31
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:83
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
FormData_pg_language * Form_pg_language
Definition: pg_language.h:51
#define elog
Definition: elog.h:219
static void fmgr_info_cxt_security(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt, bool ignore_security)
Definition: fmgr.c:142

◆ fmgr_internal_function()

Oid fmgr_internal_function ( const char *  proname)

Definition at line 534 of file fmgr.c.

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

Referenced by fmgr_internal_validator().

535 {
536  const FmgrBuiltin *fbp = fmgr_lookupByName(proname);
537 
538  if (fbp == NULL)
539  return InvalidOid;
540  return fbp->foid;
541 }
Oid foid
Definition: fmgrtab.h:27
static const FmgrBuiltin * fmgr_lookupByName(const char *name)
Definition: fmgr.c:96
#define InvalidOid
Definition: postgres_ext.h:36

◆ fmgr_isbuiltin()

static const FmgrBuiltin* fmgr_isbuiltin ( Oid  id)
static

Definition at line 71 of file fmgr.c.

References FirstBootstrapObjectId, fmgr_builtin_oid_index, fmgr_builtins, and InvalidOidBuiltinMapping.

Referenced by fmgr_info_cxt_security().

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

◆ fmgr_lookupByName()

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

Definition at line 96 of file fmgr.c.

References fmgr_builtins, fmgr_nbuiltins, and i.

Referenced by fmgr_info_cxt_security(), and fmgr_internal_function().

97 {
98  int i;
99 
100  for (i = 0; i < fmgr_nbuiltins; i++)
101  {
102  if (strcmp(name, fmgr_builtins[i].funcName) == 0)
103  return fmgr_builtins + i;
104  }
105  return NULL;
106 }
const int fmgr_nbuiltins
const FmgrBuiltin fmgr_builtins[]
const char * name
Definition: encode.c:521
int i

◆ fmgr_security_definer()

static Datum fmgr_security_definer ( PG_FUNCTION_ARGS  )
static

Definition at line 569 of file fmgr.c.

References Anum_pg_proc_proconfig, 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().

570 {
571  Datum result;
572  struct fmgr_security_definer_cache *volatile fcache;
573  FmgrInfo *save_flinfo;
574  Oid save_userid;
575  int save_sec_context;
576  volatile int save_nestlevel;
577  PgStat_FunctionCallUsage fcusage;
578 
579  if (!fcinfo->flinfo->fn_extra)
580  {
581  HeapTuple tuple;
582  Form_pg_proc procedureStruct;
583  Datum datum;
584  bool isnull;
585  MemoryContext oldcxt;
586 
587  fcache = MemoryContextAllocZero(fcinfo->flinfo->fn_mcxt,
588  sizeof(*fcache));
589 
590  fmgr_info_cxt_security(fcinfo->flinfo->fn_oid, &fcache->flinfo,
591  fcinfo->flinfo->fn_mcxt, true);
592  fcache->flinfo.fn_expr = fcinfo->flinfo->fn_expr;
593 
594  tuple = SearchSysCache1(PROCOID,
595  ObjectIdGetDatum(fcinfo->flinfo->fn_oid));
596  if (!HeapTupleIsValid(tuple))
597  elog(ERROR, "cache lookup failed for function %u",
598  fcinfo->flinfo->fn_oid);
599  procedureStruct = (Form_pg_proc) GETSTRUCT(tuple);
600 
601  if (procedureStruct->prosecdef)
602  fcache->userid = procedureStruct->proowner;
603 
605  &isnull);
606  if (!isnull)
607  {
608  oldcxt = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
609  fcache->proconfig = DatumGetArrayTypePCopy(datum);
610  MemoryContextSwitchTo(oldcxt);
611  }
612 
613  ReleaseSysCache(tuple);
614 
615  fcinfo->flinfo->fn_extra = fcache;
616  }
617  else
618  fcache = fcinfo->flinfo->fn_extra;
619 
620  /* GetUserIdAndSecContext is cheap enough that no harm in a wasted call */
621  GetUserIdAndSecContext(&save_userid, &save_sec_context);
622  if (fcache->proconfig) /* Need a new GUC nesting level */
623  save_nestlevel = NewGUCNestLevel();
624  else
625  save_nestlevel = 0; /* keep compiler quiet */
626 
627  if (OidIsValid(fcache->userid))
629  save_sec_context | SECURITY_LOCAL_USERID_CHANGE);
630 
631  if (fcache->proconfig)
632  {
633  ProcessGUCArray(fcache->proconfig,
637  }
638 
639  /* function manager hook */
640  if (fmgr_hook)
641  (*fmgr_hook) (FHET_START, &fcache->flinfo, &fcache->arg);
642 
643  /*
644  * We don't need to restore GUC or userid settings on error, because the
645  * ensuing xact or subxact abort will do that. The PG_TRY block is only
646  * needed to clean up the flinfo link.
647  */
648  save_flinfo = fcinfo->flinfo;
649 
650  PG_TRY();
651  {
652  fcinfo->flinfo = &fcache->flinfo;
653 
654  /* See notes in fmgr_info_cxt_security */
655  pgstat_init_function_usage(fcinfo, &fcusage);
656 
657  result = FunctionCallInvoke(fcinfo);
658 
659  /*
660  * We could be calling either a regular or a set-returning function,
661  * so we have to test to see what finalize flag to use.
662  */
663  pgstat_end_function_usage(&fcusage,
664  (fcinfo->resultinfo == NULL ||
665  !IsA(fcinfo->resultinfo, ReturnSetInfo) ||
666  ((ReturnSetInfo *) fcinfo->resultinfo)->isDone != ExprMultipleResult));
667  }
668  PG_CATCH();
669  {
670  fcinfo->flinfo = save_flinfo;
671  if (fmgr_hook)
672  (*fmgr_hook) (FHET_ABORT, &fcache->flinfo, &fcache->arg);
673  PG_RE_THROW();
674  }
675  PG_END_TRY();
676 
677  fcinfo->flinfo = save_flinfo;
678 
679  if (fcache->proconfig)
680  AtEOXact_GUC(true, save_nestlevel);
681  if (OidIsValid(fcache->userid))
682  SetUserIdAndSecContext(save_userid, save_sec_context);
683  if (fmgr_hook)
684  (*fmgr_hook) (FHET_END, &fcache->flinfo, &fcache->arg);
685 
686  return result;
687 }
Definition: fmgr.h:56
#define IsA(nodeptr, _type_)
Definition: nodes.h:561
#define GETSTRUCT(TUP)
Definition: htup_details.h:661
MemoryContext fn_mcxt
Definition: fmgr.h:65
void SetUserIdAndSecContext(Oid userid, int sec_context)
Definition: miscinit.c:396
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
bool superuser(void)
Definition: superuser.c:47
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:576
#define Anum_pg_proc_proconfig
Definition: pg_proc.h:117
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
Definition: guc.h:75
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
Definition: miscinit.c:389
void AtEOXact_GUC(bool isCommit, int nestLevel)
Definition: guc.c:5098
Definition: fmgr.h:718
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
ArrayType * proconfig
Definition: fmgr.c:554
uintptr_t Datum
Definition: postgres.h:372
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1368
#define DatumGetArrayTypePCopy(X)
Definition: array.h:247
PGDLLIMPORT fmgr_hook_type fmgr_hook
Definition: fmgr.c:37
#define SECURITY_LOCAL_USERID_CHANGE
Definition: miscadmin.h:293
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:83
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:741
void ProcessGUCArray(ArrayType *array, GucContext context, GucSource source, GucAction action)
Definition: guc.c:9426
#define PG_CATCH()
Definition: elog.h:293
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
fmNodePtr fn_expr
Definition: fmgr.h:66
#define PG_RE_THROW()
Definition: elog.h:314
void * fn_extra
Definition: fmgr.h:64
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
Definition: pgstat.c:1653
void pgstat_init_function_usage(FunctionCallInfoData *fcinfo, PgStat_FunctionCallUsage *fcu)
Definition: pgstat.c:1581
int NewGUCNestLevel(void)
Definition: guc.c:5084
#define elog
Definition: elog.h:219
#define PG_TRY()
Definition: elog.h:284
#define PG_END_TRY()
Definition: elog.h:300
static void fmgr_info_cxt_security(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt, bool ignore_security)
Definition: fmgr.c:142

◆ FunctionCall1Coll()

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

Definition at line 1022 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, FunctionCallInfoData::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

Referenced by _hash_datum2hashkey(), brin_inclusion_add_value(), element_hash(), gistdentryinit(), gistFetchAtt(), gistFormTuple(), and hash_range().

1023 {
1024  FunctionCallInfoData fcinfo;
1025  Datum result;
1026 
1027  InitFunctionCallInfoData(fcinfo, flinfo, 1, collation, NULL, NULL);
1028 
1029  fcinfo.arg[0] = arg1;
1030  fcinfo.argnull[0] = false;
1031 
1032  result = FunctionCallInvoke(&fcinfo);
1033 
1034  /* Check for null result, since caller is clearly not expecting one */
1035  if (fcinfo.isnull)
1036  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1037 
1038  return result;
1039 }
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

◆ FunctionCall2Coll()

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

Definition at line 1042 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, FunctionCallInfoData::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

Referenced by _bt_check_rowcompare(), _bt_checkkeys(), _bt_compare(), _bt_compare_array_elements(), _bt_compare_scankey_args(), _bt_find_extreme_element(), _bt_isequal(), _bt_sort_array_elements(), _hash_checkqual(), array_position_common(), array_positions(), brin_inclusion_add_value(), brin_inclusion_consistent(), brin_inclusion_union(), brin_minmax_add_value(), brin_minmax_consistent(), brin_minmax_union(), call_subtype_diff(), cmpEntries(), compute_distinct_stats(), compute_range_stats(), doPickSplit(), element_compare(), eqjoinsel_inner(), eqjoinsel_semi(), genericPickSplit(), get_distance(), get_position(), get_variable_range(), ginCompareEntries(), gistMakeUnionItVec(), gistMakeUnionKey(), gistUserPicksplit(), hash_range_extended(), histogram_selectivity(), ineq_histogram_selectivity(), make_greater_string(), mcv_selectivity(), partition_bound_cmp(), partition_rbound_cmp(), partition_rbound_datum_cmp(), qsort_partition_list_value_cmp(), range_cmp_bound_values(), range_cmp_bounds(), range_contains_elem_internal(), RelationBuildPartitionDesc(), spgdoinsert(), spgGetCache(), spgLeafTest(), spgWalk(), and var_eq_const().

1043 {
1044  FunctionCallInfoData fcinfo;
1045  Datum result;
1046 
1047  InitFunctionCallInfoData(fcinfo, flinfo, 2, collation, NULL, NULL);
1048 
1049  fcinfo.arg[0] = arg1;
1050  fcinfo.arg[1] = arg2;
1051  fcinfo.argnull[0] = false;
1052  fcinfo.argnull[1] = false;
1053 
1054  result = FunctionCallInvoke(&fcinfo);
1055 
1056  /* Check for null result, since caller is clearly not expecting one */
1057  if (fcinfo.isnull)
1058  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1059 
1060  return result;
1061 }
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

◆ FunctionCall3Coll()

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

Definition at line 1064 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, FunctionCallInfoData::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

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

1066 {
1067  FunctionCallInfoData fcinfo;
1068  Datum result;
1069 
1070  InitFunctionCallInfoData(fcinfo, flinfo, 3, collation, NULL, NULL);
1071 
1072  fcinfo.arg[0] = arg1;
1073  fcinfo.arg[1] = arg2;
1074  fcinfo.arg[2] = arg3;
1075  fcinfo.argnull[0] = false;
1076  fcinfo.argnull[1] = false;
1077  fcinfo.argnull[2] = false;
1078 
1079  result = FunctionCallInvoke(&fcinfo);
1080 
1081  /* Check for null result, since caller is clearly not expecting one */
1082  if (fcinfo.isnull)
1083  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1084 
1085  return result;
1086 }
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

◆ FunctionCall4Coll()

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

Definition at line 1089 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, FunctionCallInfoData::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

Referenced by brinbuildCallback(), brininsert(), collectMatchBitmap(), matchPartialInPendingList(), and scalararraysel().

1091 {
1092  FunctionCallInfoData fcinfo;
1093  Datum result;
1094 
1095  InitFunctionCallInfoData(fcinfo, flinfo, 4, collation, NULL, NULL);
1096 
1097  fcinfo.arg[0] = arg1;
1098  fcinfo.arg[1] = arg2;
1099  fcinfo.arg[2] = arg3;
1100  fcinfo.arg[3] = arg4;
1101  fcinfo.argnull[0] = false;
1102  fcinfo.argnull[1] = false;
1103  fcinfo.argnull[2] = false;
1104  fcinfo.argnull[3] = false;
1105 
1106  result = FunctionCallInvoke(&fcinfo);
1107 
1108  /* Check for null result, since caller is clearly not expecting one */
1109  if (fcinfo.isnull)
1110  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1111 
1112  return result;
1113 }
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

◆ FunctionCall5Coll()

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

Definition at line 1116 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, FunctionCallInfoData::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

Referenced by gistindex_keytest(), and scalararraysel().

1118 {
1119  FunctionCallInfoData fcinfo;
1120  Datum result;
1121 
1122  InitFunctionCallInfoData(fcinfo, flinfo, 5, collation, NULL, NULL);
1123 
1124  fcinfo.arg[0] = arg1;
1125  fcinfo.arg[1] = arg2;
1126  fcinfo.arg[2] = arg3;
1127  fcinfo.arg[3] = arg4;
1128  fcinfo.arg[4] = arg5;
1129  fcinfo.argnull[0] = false;
1130  fcinfo.argnull[1] = false;
1131  fcinfo.argnull[2] = false;
1132  fcinfo.argnull[3] = false;
1133  fcinfo.argnull[4] = false;
1134 
1135  result = FunctionCallInvoke(&fcinfo);
1136 
1137  /* Check for null result, since caller is clearly not expecting one */
1138  if (fcinfo.isnull)
1139  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1140 
1141  return result;
1142 }
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

◆ FunctionCall6Coll()

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

Definition at line 1145 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, FunctionCallInfoData::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

1148 {
1149  FunctionCallInfoData fcinfo;
1150  Datum result;
1151 
1152  InitFunctionCallInfoData(fcinfo, flinfo, 6, collation, NULL, NULL);
1153 
1154  fcinfo.arg[0] = arg1;
1155  fcinfo.arg[1] = arg2;
1156  fcinfo.arg[2] = arg3;
1157  fcinfo.arg[3] = arg4;
1158  fcinfo.arg[4] = arg5;
1159  fcinfo.arg[5] = arg6;
1160  fcinfo.argnull[0] = false;
1161  fcinfo.argnull[1] = false;
1162  fcinfo.argnull[2] = false;
1163  fcinfo.argnull[3] = false;
1164  fcinfo.argnull[4] = false;
1165  fcinfo.argnull[5] = false;
1166 
1167  result = FunctionCallInvoke(&fcinfo);
1168 
1169  /* Check for null result, since caller is clearly not expecting one */
1170  if (fcinfo.isnull)
1171  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1172 
1173  return result;
1174 }
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

◆ FunctionCall7Coll()

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

Definition at line 1177 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, FunctionCallInfoData::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

Referenced by directTriConsistentFn(), ginNewScanKey(), and shimBoolConsistentFn().

1180 {
1181  FunctionCallInfoData fcinfo;
1182  Datum result;
1183 
1184  InitFunctionCallInfoData(fcinfo, flinfo, 7, collation, NULL, NULL);
1185 
1186  fcinfo.arg[0] = arg1;
1187  fcinfo.arg[1] = arg2;
1188  fcinfo.arg[2] = arg3;
1189  fcinfo.arg[3] = arg4;
1190  fcinfo.arg[4] = arg5;
1191  fcinfo.arg[5] = arg6;
1192  fcinfo.arg[6] = arg7;
1193  fcinfo.argnull[0] = false;
1194  fcinfo.argnull[1] = false;
1195  fcinfo.argnull[2] = false;
1196  fcinfo.argnull[3] = false;
1197  fcinfo.argnull[4] = false;
1198  fcinfo.argnull[5] = false;
1199  fcinfo.argnull[6] = false;
1200 
1201  result = FunctionCallInvoke(&fcinfo);
1202 
1203  /* Check for null result, since caller is clearly not expecting one */
1204  if (fcinfo.isnull)
1205  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1206 
1207  return result;
1208 }
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

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

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, FunctionCallInfoData::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

Referenced by directBoolConsistentFn().

1214 {
1215  FunctionCallInfoData fcinfo;
1216  Datum result;
1217 
1218  InitFunctionCallInfoData(fcinfo, flinfo, 8, collation, NULL, NULL);
1219 
1220  fcinfo.arg[0] = arg1;
1221  fcinfo.arg[1] = arg2;
1222  fcinfo.arg[2] = arg3;
1223  fcinfo.arg[3] = arg4;
1224  fcinfo.arg[4] = arg5;
1225  fcinfo.arg[5] = arg6;
1226  fcinfo.arg[6] = arg7;
1227  fcinfo.arg[7] = arg8;
1228  fcinfo.argnull[0] = false;
1229  fcinfo.argnull[1] = false;
1230  fcinfo.argnull[2] = false;
1231  fcinfo.argnull[3] = false;
1232  fcinfo.argnull[4] = false;
1233  fcinfo.argnull[5] = false;
1234  fcinfo.argnull[6] = false;
1235  fcinfo.argnull[7] = false;
1236 
1237  result = FunctionCallInvoke(&fcinfo);
1238 
1239  /* Check for null result, since caller is clearly not expecting one */
1240  if (fcinfo.isnull)
1241  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1242 
1243  return result;
1244 }
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

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

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, FunctionCallInfoData::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

1251 {
1252  FunctionCallInfoData fcinfo;
1253  Datum result;
1254 
1255  InitFunctionCallInfoData(fcinfo, flinfo, 9, collation, NULL, NULL);
1256 
1257  fcinfo.arg[0] = arg1;
1258  fcinfo.arg[1] = arg2;
1259  fcinfo.arg[2] = arg3;
1260  fcinfo.arg[3] = arg4;
1261  fcinfo.arg[4] = arg5;
1262  fcinfo.arg[5] = arg6;
1263  fcinfo.arg[6] = arg7;
1264  fcinfo.arg[7] = arg8;
1265  fcinfo.arg[8] = arg9;
1266  fcinfo.argnull[0] = false;
1267  fcinfo.argnull[1] = false;
1268  fcinfo.argnull[2] = false;
1269  fcinfo.argnull[3] = false;
1270  fcinfo.argnull[4] = false;
1271  fcinfo.argnull[5] = false;
1272  fcinfo.argnull[6] = false;
1273  fcinfo.argnull[7] = false;
1274  fcinfo.argnull[8] = false;
1275 
1276  result = FunctionCallInvoke(&fcinfo);
1277 
1278  /* Check for null result, since caller is clearly not expecting one */
1279  if (fcinfo.isnull)
1280  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1281 
1282  return result;
1283 }
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

◆ get_call_expr_arg_stable()

bool get_call_expr_arg_stable ( Node expr,
int  argnum 
)

Definition at line 1988 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().

1989 {
1990  List *args;
1991  Node *arg;
1992 
1993  if (expr == NULL)
1994  return false;
1995 
1996  if (IsA(expr, FuncExpr))
1997  args = ((FuncExpr *) expr)->args;
1998  else if (IsA(expr, OpExpr))
1999  args = ((OpExpr *) expr)->args;
2000  else if (IsA(expr, DistinctExpr))
2001  args = ((DistinctExpr *) expr)->args;
2002  else if (IsA(expr, ScalarArrayOpExpr))
2003  args = ((ScalarArrayOpExpr *) expr)->args;
2004  else if (IsA(expr, NullIfExpr))
2005  args = ((NullIfExpr *) expr)->args;
2006  else if (IsA(expr, WindowFunc))
2007  args = ((WindowFunc *) expr)->args;
2008  else
2009  return false;
2010 
2011  if (argnum < 0 || argnum >= list_length(args))
2012  return false;
2013 
2014  arg = (Node *) list_nth(args, argnum);
2015 
2016  /*
2017  * Either a true Const or an external Param will have a value that doesn't
2018  * change during the execution of the query. In future we might want to
2019  * consider other cases too, e.g. now().
2020  */
2021  if (IsA(arg, Const))
2022  return true;
2023  if (IsA(arg, Param) &&
2024  ((Param *) arg)->paramkind == PARAM_EXTERN)
2025  return true;
2026 
2027  return false;
2028 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:561
Definition: nodes.h:510
void * list_nth(const List *list, int n)
Definition: list.c:410
static int list_length(const List *l)
Definition: pg_list.h:89
void * arg
Definition: pg_list.h:45

◆ get_call_expr_argtype()

Oid get_call_expr_argtype ( Node expr,
int  argnum 
)

Definition at line 1923 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().

1924 {
1925  List *args;
1926  Oid argtype;
1927 
1928  if (expr == NULL)
1929  return InvalidOid;
1930 
1931  if (IsA(expr, FuncExpr))
1932  args = ((FuncExpr *) expr)->args;
1933  else if (IsA(expr, OpExpr))
1934  args = ((OpExpr *) expr)->args;
1935  else if (IsA(expr, DistinctExpr))
1936  args = ((DistinctExpr *) expr)->args;
1937  else if (IsA(expr, ScalarArrayOpExpr))
1938  args = ((ScalarArrayOpExpr *) expr)->args;
1939  else if (IsA(expr, NullIfExpr))
1940  args = ((NullIfExpr *) expr)->args;
1941  else if (IsA(expr, WindowFunc))
1942  args = ((WindowFunc *) expr)->args;
1943  else
1944  return InvalidOid;
1945 
1946  if (argnum < 0 || argnum >= list_length(args))
1947  return InvalidOid;
1948 
1949  argtype = exprType((Node *) list_nth(args, argnum));
1950 
1951  /*
1952  * special hack for ScalarArrayOpExpr: what the underlying function will
1953  * actually get passed is the element type of the array.
1954  */
1955  if (IsA(expr, ScalarArrayOpExpr) &&
1956  argnum == 1)
1957  argtype = get_base_element_type(argtype);
1958 
1959  return argtype;
1960 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:561
Definition: nodes.h:510
unsigned int Oid
Definition: postgres_ext.h:31
void * list_nth(const List *list, int n)
Definition: list.c:410
#define InvalidOid
Definition: postgres_ext.h:36
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
static int list_length(const List *l)
Definition: pg_list.h:89
Oid get_base_element_type(Oid typid)
Definition: lsyscache.c:2571
Definition: pg_list.h:45

◆ get_fn_expr_arg_stable()

bool get_fn_expr_arg_stable ( FmgrInfo flinfo,
int  argnum 
)

Definition at line 1969 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().

1970 {
1971  /*
1972  * can't return anything useful if we have no FmgrInfo or if its fn_expr
1973  * node has not been initialized
1974  */
1975  if (!flinfo || !flinfo->fn_expr)
1976  return false;
1977 
1978  return get_call_expr_arg_stable(flinfo->fn_expr, argnum);
1979 }
bool get_call_expr_arg_stable(Node *expr, int argnum)
Definition: fmgr.c:1988
fmNodePtr fn_expr
Definition: fmgr.h:66

◆ get_fn_expr_argtype()

Oid get_fn_expr_argtype ( FmgrInfo flinfo,
int  argnum 
)

◆ get_fn_expr_rettype()

Oid get_fn_expr_rettype ( FmgrInfo flinfo)

Definition at line 1882 of file fmgr.c.

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

Referenced by do_compile(), init_sql_fcache(), range_constructor2(), and range_constructor3().

1883 {
1884  Node *expr;
1885 
1886  /*
1887  * can't return anything useful if we have no FmgrInfo or if its fn_expr
1888  * node has not been initialized
1889  */
1890  if (!flinfo || !flinfo->fn_expr)
1891  return InvalidOid;
1892 
1893  expr = flinfo->fn_expr;
1894 
1895  return exprType(expr);
1896 }
Definition: nodes.h:510
#define InvalidOid
Definition: postgres_ext.h:36
fmNodePtr fn_expr
Definition: fmgr.h:66
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42

◆ get_fn_expr_variadic()

bool get_fn_expr_variadic ( FmgrInfo flinfo)

Definition at line 2038 of file fmgr.c.

References FmgrInfo::fn_expr, and IsA.

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

2039 {
2040  Node *expr;
2041 
2042  /*
2043  * can't return anything useful if we have no FmgrInfo or if its fn_expr
2044  * node has not been initialized
2045  */
2046  if (!flinfo || !flinfo->fn_expr)
2047  return false;
2048 
2049  expr = flinfo->fn_expr;
2050 
2051  if (IsA(expr, FuncExpr))
2052  return ((FuncExpr *) expr)->funcvariadic;
2053  else
2054  return false;
2055 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:561
Definition: nodes.h:510
fmNodePtr fn_expr
Definition: fmgr.h:66

◆ InputFunctionCall()

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

Definition at line 1618 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, CStringGetDatum, elog, ERROR, FunctionCallInfoData::flinfo, FmgrInfo::fn_oid, FmgrInfo::fn_strict, FunctionCallInvoke, InitFunctionCallInfoData, Int32GetDatum, InvalidOid, FunctionCallInfoData::isnull, and ObjectIdGetDatum.

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

1619 {
1620  FunctionCallInfoData fcinfo;
1621  Datum result;
1622 
1623  if (str == NULL && flinfo->fn_strict)
1624  return (Datum) 0; /* just return null result */
1625 
1626  InitFunctionCallInfoData(fcinfo, flinfo, 3, InvalidOid, NULL, NULL);
1627 
1628  fcinfo.arg[0] = CStringGetDatum(str);
1629  fcinfo.arg[1] = ObjectIdGetDatum(typioparam);
1630  fcinfo.arg[2] = Int32GetDatum(typmod);
1631  fcinfo.argnull[0] = (str == NULL);
1632  fcinfo.argnull[1] = false;
1633  fcinfo.argnull[2] = false;
1634 
1635  result = FunctionCallInvoke(&fcinfo);
1636 
1637  /* Should get null result if and only if str is NULL */
1638  if (str == NULL)
1639  {
1640  if (!fcinfo.isnull)
1641  elog(ERROR, "input function %u returned non-NULL",
1642  fcinfo.flinfo->fn_oid);
1643  }
1644  else
1645  {
1646  if (fcinfo.isnull)
1647  elog(ERROR, "input function %u returned NULL",
1648  fcinfo.flinfo->fn_oid);
1649  }
1650 
1651  return result;
1652 }
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
bool fn_strict
Definition: fmgr.h:61
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
#define CStringGetDatum(X)
Definition: postgres.h:584
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
#define InvalidOid
Definition: postgres_ext.h:36
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define Int32GetDatum(X)
Definition: postgres.h:485
#define elog
Definition: elog.h:219

◆ Int64GetDatum()

◆ lookup_C_func()

static CFuncHashTabEntry * lookup_C_func ( HeapTuple  procedureTuple)
static

Definition at line 439 of file fmgr.c.

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

Referenced by fmgr_info_C_lang().

440 {
441  Oid fn_oid = HeapTupleGetOid(procedureTuple);
442  CFuncHashTabEntry *entry;
443 
444  if (CFuncHash == NULL)
445  return NULL; /* no table yet */
446  entry = (CFuncHashTabEntry *)
448  &fn_oid,
449  HASH_FIND,
450  NULL);
451  if (entry == NULL)
452  return NULL; /* no such entry */
453  if (entry->fn_xmin == HeapTupleHeaderGetRawXmin(procedureTuple->t_data) &&
454  ItemPointerEquals(&entry->fn_tid, &procedureTuple->t_self))
455  return entry; /* OK */
456  return NULL; /* entry is out of date */
457 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:902
unsigned int Oid
Definition: postgres_ext.h:31
HeapTupleHeader t_data
Definition: htup.h:67
static HTAB * CFuncHash
Definition: fmgr.c:52
ItemPointerData t_self
Definition: htup.h:65
#define HeapTupleHeaderGetRawXmin(tup)
Definition: htup_details.h:307
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
Definition: itemptr.c:29
TransactionId fn_xmin
Definition: fmgr.c:46
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:700
ItemPointerData fn_tid
Definition: fmgr.c:47

◆ OidFunctionCall0Coll()

Datum OidFunctionCall0Coll ( Oid  functionId,
Oid  collation 
)

Definition at line 1294 of file fmgr.c.

References elog, ERROR, fmgr_security_definer_cache::flinfo, fmgr_info(), FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

1295 {
1296  FmgrInfo flinfo;
1297  FunctionCallInfoData fcinfo;
1298  Datum result;
1299 
1300  fmgr_info(functionId, &flinfo);
1301 
1302  InitFunctionCallInfoData(fcinfo, &flinfo, 0, collation, NULL, NULL);
1303 
1304  result = FunctionCallInvoke(&fcinfo);
1305 
1306  /* Check for null result, since caller is clearly not expecting one */
1307  if (fcinfo.isnull)
1308  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1309 
1310  return result;
1311 }
Definition: fmgr.h:56
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:122
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

◆ OidFunctionCall1Coll()

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

Definition at line 1314 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, fmgr_security_definer_cache::flinfo, fmgr_info(), FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

Referenced by _hash_datum2hashkey_type().

1315 {
1316  FmgrInfo flinfo;
1317  FunctionCallInfoData fcinfo;
1318  Datum result;
1319 
1320  fmgr_info(functionId, &flinfo);
1321 
1322  InitFunctionCallInfoData(fcinfo, &flinfo, 1, collation, NULL, NULL);
1323 
1324  fcinfo.arg[0] = arg1;
1325  fcinfo.argnull[0] = false;
1326 
1327  result = FunctionCallInvoke(&fcinfo);
1328 
1329  /* Check for null result, since caller is clearly not expecting one */
1330  if (fcinfo.isnull)
1331  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1332 
1333  return result;
1334 }
Definition: fmgr.h:56
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:122
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

◆ OidFunctionCall2Coll()

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

Definition at line 1337 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, fmgr_security_definer_cache::flinfo, fmgr_info(), FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

Referenced by _bt_compare_scankey_args(), and index_recheck_constraint().

1338 {
1339  FmgrInfo flinfo;
1340  FunctionCallInfoData fcinfo;
1341  Datum result;
1342 
1343  fmgr_info(functionId, &flinfo);
1344 
1345  InitFunctionCallInfoData(fcinfo, &flinfo, 2, collation, NULL, NULL);
1346 
1347  fcinfo.arg[0] = arg1;
1348  fcinfo.arg[1] = arg2;
1349  fcinfo.argnull[0] = false;
1350  fcinfo.argnull[1] = false;
1351 
1352  result = FunctionCallInvoke(&fcinfo);
1353 
1354  /* Check for null result, since caller is clearly not expecting one */
1355  if (fcinfo.isnull)
1356  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1357 
1358  return result;
1359 }
Definition: fmgr.h:56
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:122
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

◆ OidFunctionCall3Coll()

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

Definition at line 1362 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, fmgr_security_definer_cache::flinfo, fmgr_info(), FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

1364 {
1365  FmgrInfo flinfo;
1366  FunctionCallInfoData fcinfo;
1367  Datum result;
1368 
1369  fmgr_info(functionId, &flinfo);
1370 
1371  InitFunctionCallInfoData(fcinfo, &flinfo, 3, collation, NULL, NULL);
1372 
1373  fcinfo.arg[0] = arg1;
1374  fcinfo.arg[1] = arg2;
1375  fcinfo.arg[2] = arg3;
1376  fcinfo.argnull[0] = false;
1377  fcinfo.argnull[1] = false;
1378  fcinfo.argnull[2] = false;
1379 
1380  result = FunctionCallInvoke(&fcinfo);
1381 
1382  /* Check for null result, since caller is clearly not expecting one */
1383  if (fcinfo.isnull)
1384  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1385 
1386  return result;
1387 }
Definition: fmgr.h:56
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:122
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

◆ OidFunctionCall4Coll()

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

Definition at line 1390 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, fmgr_security_definer_cache::flinfo, fmgr_info(), FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

Referenced by restriction_selectivity().

1392 {
1393  FmgrInfo flinfo;
1394  FunctionCallInfoData fcinfo;
1395  Datum result;
1396 
1397  fmgr_info(functionId, &flinfo);
1398 
1399  InitFunctionCallInfoData(fcinfo, &flinfo, 4, collation, NULL, NULL);
1400 
1401  fcinfo.arg[0] = arg1;
1402  fcinfo.arg[1] = arg2;
1403  fcinfo.arg[2] = arg3;
1404  fcinfo.arg[3] = arg4;
1405  fcinfo.argnull[0] = false;
1406  fcinfo.argnull[1] = false;
1407  fcinfo.argnull[2] = false;
1408  fcinfo.argnull[3] = false;
1409 
1410  result = FunctionCallInvoke(&fcinfo);
1411 
1412  /* Check for null result, since caller is clearly not expecting one */
1413  if (fcinfo.isnull)
1414  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1415 
1416  return result;
1417 }
Definition: fmgr.h:56
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:122
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

◆ OidFunctionCall5Coll()

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

Definition at line 1420 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, fmgr_security_definer_cache::flinfo, fmgr_info(), FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

Referenced by join_selectivity().

1422 {
1423  FmgrInfo flinfo;
1424  FunctionCallInfoData fcinfo;
1425  Datum result;
1426 
1427  fmgr_info(functionId, &flinfo);
1428 
1429  InitFunctionCallInfoData(fcinfo, &flinfo, 5, collation, NULL, NULL);
1430 
1431  fcinfo.arg[0] = arg1;
1432  fcinfo.arg[1] = arg2;
1433  fcinfo.arg[2] = arg3;
1434  fcinfo.arg[3] = arg4;
1435  fcinfo.arg[4] = arg5;
1436  fcinfo.argnull[0] = false;
1437  fcinfo.argnull[1] = false;
1438  fcinfo.argnull[2] = false;
1439  fcinfo.argnull[3] = false;
1440  fcinfo.argnull[4] = false;
1441 
1442  result = FunctionCallInvoke(&fcinfo);
1443 
1444  /* Check for null result, since caller is clearly not expecting one */
1445  if (fcinfo.isnull)
1446  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1447 
1448  return result;
1449 }
Definition: fmgr.h:56
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:122
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

◆ OidFunctionCall6Coll()

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

Definition at line 1452 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, fmgr_security_definer_cache::flinfo, fmgr_info(), FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

1455 {
1456  FmgrInfo flinfo;
1457  FunctionCallInfoData fcinfo;
1458  Datum result;
1459 
1460  fmgr_info(functionId, &flinfo);
1461 
1462  InitFunctionCallInfoData(fcinfo, &flinfo, 6, collation, NULL, NULL);
1463 
1464  fcinfo.arg[0] = arg1;
1465  fcinfo.arg[1] = arg2;
1466  fcinfo.arg[2] = arg3;
1467  fcinfo.arg[3] = arg4;
1468  fcinfo.arg[4] = arg5;
1469  fcinfo.arg[5] = arg6;
1470  fcinfo.argnull[0] = false;
1471  fcinfo.argnull[1] = false;
1472  fcinfo.argnull[2] = false;
1473  fcinfo.argnull[3] = false;
1474  fcinfo.argnull[4] = false;
1475  fcinfo.argnull[5] = false;
1476 
1477  result = FunctionCallInvoke(&fcinfo);
1478 
1479  /* Check for null result, since caller is clearly not expecting one */
1480  if (fcinfo.isnull)
1481  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1482 
1483  return result;
1484 }
Definition: fmgr.h:56
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:122
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

◆ OidFunctionCall7Coll()

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

Definition at line 1487 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, fmgr_security_definer_cache::flinfo, fmgr_info(), FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

Referenced by gincost_pattern().

1490 {
1491  FmgrInfo flinfo;
1492  FunctionCallInfoData fcinfo;
1493  Datum result;
1494 
1495  fmgr_info(functionId, &flinfo);
1496 
1497  InitFunctionCallInfoData(fcinfo, &flinfo, 7, collation, NULL, NULL);
1498 
1499  fcinfo.arg[0] = arg1;
1500  fcinfo.arg[1] = arg2;
1501  fcinfo.arg[2] = arg3;
1502  fcinfo.arg[3] = arg4;
1503  fcinfo.arg[4] = arg5;
1504  fcinfo.arg[5] = arg6;
1505  fcinfo.arg[6] = arg7;
1506  fcinfo.argnull[0] = false;
1507  fcinfo.argnull[1] = false;
1508  fcinfo.argnull[2] = false;
1509  fcinfo.argnull[3] = false;
1510  fcinfo.argnull[4] = false;
1511  fcinfo.argnull[5] = false;
1512  fcinfo.argnull[6] = false;
1513 
1514  result = FunctionCallInvoke(&fcinfo);
1515 
1516  /* Check for null result, since caller is clearly not expecting one */
1517  if (fcinfo.isnull)
1518  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1519 
1520  return result;
1521 }
Definition: fmgr.h:56
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:122
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

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

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, fmgr_security_definer_cache::flinfo, fmgr_info(), FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

1527 {
1528  FmgrInfo flinfo;
1529  FunctionCallInfoData fcinfo;
1530  Datum result;
1531 
1532  fmgr_info(functionId, &flinfo);
1533 
1534  InitFunctionCallInfoData(fcinfo, &flinfo, 8, collation, NULL, NULL);
1535 
1536  fcinfo.arg[0] = arg1;
1537  fcinfo.arg[1] = arg2;
1538  fcinfo.arg[2] = arg3;
1539  fcinfo.arg[3] = arg4;
1540  fcinfo.arg[4] = arg5;
1541  fcinfo.arg[5] = arg6;
1542  fcinfo.arg[6] = arg7;
1543  fcinfo.arg[7] = arg8;
1544  fcinfo.argnull[0] = false;
1545  fcinfo.argnull[1] = false;
1546  fcinfo.argnull[2] = false;
1547  fcinfo.argnull[3] = false;
1548  fcinfo.argnull[4] = false;
1549  fcinfo.argnull[5] = false;
1550  fcinfo.argnull[6] = false;
1551  fcinfo.argnull[7] = false;
1552 
1553  result = FunctionCallInvoke(&fcinfo);
1554 
1555  /* Check for null result, since caller is clearly not expecting one */
1556  if (fcinfo.isnull)
1557  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1558 
1559  return result;
1560 }
Definition: fmgr.h:56
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:122
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

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

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, fmgr_security_definer_cache::flinfo, fmgr_info(), FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and FunctionCallInfoData::isnull.

1567 {
1568  FmgrInfo flinfo;
1569  FunctionCallInfoData fcinfo;
1570  Datum result;
1571 
1572  fmgr_info(functionId, &flinfo);
1573 
1574  InitFunctionCallInfoData(fcinfo, &flinfo, 9, collation, NULL, NULL);
1575 
1576  fcinfo.arg[0] = arg1;
1577  fcinfo.arg[1] = arg2;
1578  fcinfo.arg[2] = arg3;
1579  fcinfo.arg[3] = arg4;
1580  fcinfo.arg[4] = arg5;
1581  fcinfo.arg[5] = arg6;
1582  fcinfo.arg[6] = arg7;
1583  fcinfo.arg[7] = arg8;
1584  fcinfo.arg[8] = arg9;
1585  fcinfo.argnull[0] = false;
1586  fcinfo.argnull[1] = false;
1587  fcinfo.argnull[2] = false;
1588  fcinfo.argnull[3] = false;
1589  fcinfo.argnull[4] = false;
1590  fcinfo.argnull[5] = false;
1591  fcinfo.argnull[6] = false;
1592  fcinfo.argnull[7] = false;
1593  fcinfo.argnull[8] = false;
1594 
1595  result = FunctionCallInvoke(&fcinfo);
1596 
1597  /* Check for null result, since caller is clearly not expecting one */
1598  if (fcinfo.isnull)
1599  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1600 
1601  return result;
1602 }
Definition: fmgr.h:56
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:122
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define elog
Definition: elog.h:219

◆ OidInputFunctionCall()

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

Definition at line 1733 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_cstrings(), slot_store_cstrings(), and stringTypeDatum().

1734 {
1735  FmgrInfo flinfo;
1736 
1737  fmgr_info(functionId, &flinfo);
1738  return InputFunctionCall(&flinfo, str, typioparam, typmod);
1739 }
Definition: fmgr.h:56
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:122
Datum InputFunctionCall(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
Definition: fmgr.c:1618

◆ OidOutputFunctionCall()

◆ OidReceiveFunctionCall()

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

Definition at line 1751 of file fmgr.c.

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

Referenced by exec_bind_message(), parse_fcall_arguments(), and parse_fcall_arguments_20().

1753 {
1754  FmgrInfo flinfo;
1755 
1756  fmgr_info(functionId, &flinfo);
1757  return ReceiveFunctionCall(&flinfo, buf, typioparam, typmod);
1758 }
Definition: fmgr.h:56
Datum ReceiveFunctionCall(FmgrInfo *flinfo, StringInfo buf, Oid typioparam, int32 typmod)
Definition: fmgr.c:1676
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:122

◆ OidSendFunctionCall()

bytea* OidSendFunctionCall ( Oid  functionId,
Datum  val 
)

Definition at line 1761 of file fmgr.c.

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

Referenced by SendFunctionResult().

1762 {
1763  FmgrInfo flinfo;
1764 
1765  fmgr_info(functionId, &flinfo);
1766  return SendFunctionCall(&flinfo, val);
1767 }
Definition: fmgr.h:56
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:122
bytea * SendFunctionCall(FmgrInfo *flinfo, Datum val)
Definition: fmgr.c:1723
long val
Definition: informix.c:689

◆ OutputFunctionCall()

◆ pg_detoast_datum()

struct varlena* pg_detoast_datum ( struct varlena datum)

Definition at line 1826 of file fmgr.c.

References heap_tuple_untoast_attr(), and VARATT_IS_EXTENDED.

1827 {
1828  if (VARATT_IS_EXTENDED(datum))
1829  return heap_tuple_untoast_attr(datum);
1830  else
1831  return datum;
1832 }
struct varlena * heap_tuple_untoast_attr(struct varlena *attr)
Definition: tuptoaster.c:172
#define VARATT_IS_EXTENDED(PTR)
Definition: postgres.h:326

◆ pg_detoast_datum_copy()

struct varlena* pg_detoast_datum_copy ( struct varlena datum)

Definition at line 1835 of file fmgr.c.

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

1836 {
1837  if (VARATT_IS_EXTENDED(datum))
1838  return heap_tuple_untoast_attr(datum);
1839  else
1840  {
1841  /* Make a modifiable copy of the varlena object */
1842  Size len = VARSIZE(datum);
1843  struct varlena *result = (struct varlena *) palloc(len);
1844 
1845  memcpy(result, datum, len);
1846  return result;
1847  }
1848 }
#define VARSIZE(PTR)
Definition: postgres.h:304
struct varlena * heap_tuple_untoast_attr(struct varlena *attr)
Definition: tuptoaster.c:172
size_t Size
Definition: c.h:404
#define VARATT_IS_EXTENDED(PTR)
Definition: postgres.h:326
void * palloc(Size size)
Definition: mcxt.c:848
Definition: c.h:487

◆ pg_detoast_datum_packed()

struct varlena* pg_detoast_datum_packed ( struct varlena datum)

Definition at line 1858 of file fmgr.c.

References heap_tuple_untoast_attr(), VARATT_IS_COMPRESSED, and VARATT_IS_EXTERNAL.

Referenced by text_to_cstring(), and text_to_cstring_buffer().

1859 {
1860  if (VARATT_IS_COMPRESSED(datum) || VARATT_IS_EXTERNAL(datum))
1861  return heap_tuple_untoast_attr(datum);
1862  else
1863  return datum;
1864 }
#define VARATT_IS_COMPRESSED(PTR)
Definition: postgres.h:313
struct varlena * heap_tuple_untoast_attr(struct varlena *attr)
Definition: tuptoaster.c:172
#define VARATT_IS_EXTERNAL(PTR)
Definition: postgres.h:314

◆ pg_detoast_datum_slice()

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

Definition at line 1851 of file fmgr.c.

References heap_tuple_untoast_attr_slice().

1852 {
1853  /* Only get the specified portion from the toast rel */
1854  return heap_tuple_untoast_attr_slice(datum, first, count);
1855 }
struct varlena * heap_tuple_untoast_attr_slice(struct varlena *attr, int32 sliceoffset, int32 slicelength)
Definition: tuptoaster.c:258

◆ ReceiveFunctionCall()

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

Definition at line 1676 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, FunctionCallInfoData::flinfo, FmgrInfo::fn_oid, FmgrInfo::fn_strict, FunctionCallInvoke, InitFunctionCallInfoData, Int32GetDatum, InvalidOid, FunctionCallInfoData::isnull, ObjectIdGetDatum, and PointerGetDatum.

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

1678 {
1679  FunctionCallInfoData fcinfo;
1680  Datum result;
1681 
1682  if (buf == NULL && flinfo->fn_strict)
1683  return (Datum) 0; /* just return null result */
1684 
1685  InitFunctionCallInfoData(fcinfo, flinfo, 3, InvalidOid, NULL, NULL);
1686 
1687  fcinfo.arg[0] = PointerGetDatum(buf);
1688  fcinfo.arg[1] = ObjectIdGetDatum(typioparam);
1689  fcinfo.arg[2] = Int32GetDatum(typmod);
1690  fcinfo.argnull[0] = (buf == NULL);
1691  fcinfo.argnull[1] = false;
1692  fcinfo.argnull[2] = false;
1693 
1694  result = FunctionCallInvoke(&fcinfo);
1695 
1696  /* Should get null result if and only if buf is NULL */
1697  if (buf == NULL)
1698  {
1699  if (!fcinfo.isnull)
1700  elog(ERROR, "receive function %u returned non-NULL",
1701  fcinfo.flinfo->fn_oid);
1702  }
1703  else
1704  {
1705  if (fcinfo.isnull)
1706  elog(ERROR, "receive function %u returned NULL",
1707  fcinfo.flinfo->fn_oid);
1708  }
1709 
1710  return result;
1711 }
#define PointerGetDatum(X)
Definition: postgres.h:562
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
bool fn_strict
Definition: fmgr.h:61
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:137
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
uintptr_t Datum
Definition: postgres.h:372
#define InvalidOid
Definition: postgres_ext.h:36
Oid fn_oid
Definition: fmgr.h:59
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define Int32GetDatum(X)
Definition: postgres.h:485
#define elog
Definition: elog.h:219

◆ record_C_func()

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

Definition at line 463 of file fmgr.c.

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

Referenced by fmgr_info_C_lang().

465 {
466  Oid fn_oid = HeapTupleGetOid(procedureTuple);
467  CFuncHashTabEntry *entry;
468  bool found;
469 
470  /* Create the hash table if it doesn't exist yet */
471  if (CFuncHash == NULL)
472  {
473  HASHCTL hash_ctl;
474 
475  MemSet(&hash_ctl, 0, sizeof(hash_ctl));
476  hash_ctl.keysize = sizeof(Oid);
477  hash_ctl.entrysize = sizeof(CFuncHashTabEntry);
478  CFuncHash = hash_create("CFuncHash",
479  100,
480  &hash_ctl,
482  }
483 
484  entry = (CFuncHashTabEntry *)
486  &fn_oid,
487  HASH_ENTER,
488  &found);
489  /* OID is already filled in */
490  entry->fn_xmin = HeapTupleHeaderGetRawXmin(procedureTuple->t_data);
491  entry->fn_tid = procedureTuple->t_self;
492  entry->user_fn = user_fn;
493  entry->inforec = inforec;
494 }
#define HASH_ELEM
Definition: hsearch.h:87
const Pg_finfo_record * inforec
Definition: fmgr.c:49
Size entrysize
Definition: hsearch.h:73
#define MemSet(start, val, len)
Definition: c.h:853
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:902
unsigned int Oid
Definition: postgres_ext.h:31
HeapTupleHeader t_data
Definition: htup.h:67
static HTAB * CFuncHash
Definition: fmgr.c:52
ItemPointerData t_self
Definition: htup.h:65
PGFunction user_fn
Definition: fmgr.c:48
#define HASH_BLOBS
Definition: hsearch.h:88
HTAB * hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
Definition: dynahash.c:316
Size keysize
Definition: hsearch.h:72
#define HeapTupleHeaderGetRawXmin(tup)
Definition: htup_details.h:307
TransactionId fn_xmin
Definition: fmgr.c:46
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:700
ItemPointerData fn_tid
Definition: fmgr.c:47

◆ SendFunctionCall()

bytea* SendFunctionCall ( FmgrInfo flinfo,
Datum  val 
)

Definition at line 1723 of file fmgr.c.

References DatumGetByteaP, and FunctionCall1.

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

1724 {
1725  return DatumGetByteaP(FunctionCall1(flinfo, val));
1726 }
#define DatumGetByteaP(X)
Definition: fmgr.h:295
#define FunctionCall1(flinfo, arg1)
Definition: fmgr.h:603
long val
Definition: informix.c:689

Variable Documentation

◆ CFuncHash

HTAB* CFuncHash = NULL
static

Definition at line 52 of file fmgr.c.

◆ fmgr_hook

PGDLLIMPORT fmgr_hook_type fmgr_hook = NULL

Definition at line 37 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 36 of file fmgr.c.

Referenced by sepgsql_init_client_label().