PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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  Oldstyle_fnextra
 
struct  CFuncHashTabEntry
 
struct  fmgr_security_definer_cache
 

Typedefs

typedef char *(* func_ptr )()
 

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_oldstyle (PG_FUNCTION_ARGS)
 
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, 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)
 
char * fmgr (Oid procedureId,...)
 
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
 

Typedef Documentation

typedef char*(* func_ptr)()

Definition at line 57 of file fmgr.c.

Function Documentation

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

Definition at line 1289 of file fmgr.c.

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

1290 {
1291  FunctionCallInfoData fcinfo;
1292  Datum result;
1293 
1294  InitFunctionCallInfoData(fcinfo, flinfo, 1, collation, NULL, NULL);
1295 
1296  fcinfo.arg[0] = arg1;
1297  fcinfo.argnull[0] = false;
1298 
1299  result = (*func) (&fcinfo);
1300 
1301  /* Check for null result, since caller is clearly not expecting one */
1302  if (fcinfo.isnull)
1303  elog(ERROR, "function %p returned NULL", (void *) func);
1304 
1305  return result;
1306 }
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
Datum CallerFInfoFunctionCall2 ( PGFunction  func,
FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2 
)

Definition at line 1309 of file fmgr.c.

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

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

1310 {
1311  FunctionCallInfoData fcinfo;
1312  Datum result;
1313 
1314  InitFunctionCallInfoData(fcinfo, flinfo, 2, collation, NULL, NULL);
1315 
1316  fcinfo.arg[0] = arg1;
1317  fcinfo.arg[1] = arg2;
1318  fcinfo.argnull[0] = false;
1319  fcinfo.argnull[1] = false;
1320 
1321  result = (*func) (&fcinfo);
1322 
1323  /* Check for null result, since caller is clearly not expecting one */
1324  if (fcinfo.isnull)
1325  elog(ERROR, "function %p returned NULL", (void *) func);
1326 
1327  return result;
1328 }
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
bool CheckFunctionValidatorAccess ( Oid  validatorOid,
Oid  functionOid 
)

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

2463 {
2464  HeapTuple procTup;
2465  HeapTuple langTup;
2466  Form_pg_proc procStruct;
2467  Form_pg_language langStruct;
2468  AclResult aclresult;
2469 
2470  /*
2471  * Get the function's pg_proc entry. Throw a user-facing error for bad
2472  * OID, because validators can be called with user-specified OIDs.
2473  */
2474  procTup = SearchSysCache1(PROCOID, ObjectIdGetDatum(functionOid));
2475  if (!HeapTupleIsValid(procTup))
2476  ereport(ERROR,
2477  (errcode(ERRCODE_UNDEFINED_FUNCTION),
2478  errmsg("function with OID %u does not exist", functionOid)));
2479  procStruct = (Form_pg_proc) GETSTRUCT(procTup);
2480 
2481  /*
2482  * Fetch pg_language entry to know if this is the correct validation
2483  * function for that pg_proc entry.
2484  */
2485  langTup = SearchSysCache1(LANGOID, ObjectIdGetDatum(procStruct->prolang));
2486  if (!HeapTupleIsValid(langTup))
2487  elog(ERROR, "cache lookup failed for language %u", procStruct->prolang);
2488  langStruct = (Form_pg_language) GETSTRUCT(langTup);
2489 
2490  if (langStruct->lanvalidator != validatorOid)
2491  ereport(ERROR,
2492  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2493  errmsg("language validation function %u called for language %u instead of %u",
2494  validatorOid, procStruct->prolang,
2495  langStruct->lanvalidator)));
2496 
2497  /* first validate that we have permissions to use the language */
2498  aclresult = pg_language_aclcheck(procStruct->prolang, GetUserId(),
2499  ACL_USAGE);
2500  if (aclresult != ACLCHECK_OK)
2501  aclcheck_error(aclresult, ACL_KIND_LANGUAGE,
2502  NameStr(langStruct->lanname));
2503 
2504  /*
2505  * Check whether we are allowed to execute the function itself. If we can
2506  * execute it, there should be no possible side-effect of
2507  * compiling/validation that execution can't have.
2508  */
2509  aclresult = pg_proc_aclcheck(functionOid, GetUserId(), ACL_EXECUTE);
2510  if (aclresult != ACLCHECK_OK)
2511  aclcheck_error(aclresult, ACL_KIND_PROC, NameStr(procStruct->proname));
2512 
2513  ReleaseSysCache(procTup);
2514  ReleaseSysCache(langTup);
2515 
2516  return true;
2517 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
Oid GetUserId(void)
Definition: miscinit.c:283
int errcode(int sqlerrcode)
Definition: elog.c:575
AclResult pg_language_aclcheck(Oid lang_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4432
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:150
#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:3377
#define ACL_USAGE
Definition: parsenodes.h:73
#define ereport(elevel, rest)
Definition: elog.h:122
AclResult
Definition: acl.h:170
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1093
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:72
AclResult pg_proc_aclcheck(Oid proc_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4420
#define NameStr(name)
Definition: c.h:499
#define elog
Definition: elog.h:219
void clear_external_function_hash ( void *  filehandle)

Definition at line 567 of file fmgr.c.

References hash_destroy(), and NULL.

Referenced by internal_unload_library().

568 {
569  if (CFuncHash)
571  CFuncHash = NULL;
572 }
void hash_destroy(HTAB *hashp)
Definition: dynahash.c:793
static HTAB * CFuncHash
Definition: fmgr.c:83
#define NULL
Definition: c.h:229
Datum DirectFunctionCall1Coll ( PGFunction  func,
Oid  collation,
Datum  arg1 
)

Definition at line 1016 of file fmgr.c.

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

Referenced by Generic_Text_IC_like(), and libpqrcv_create_slot().

1017 {
1018  FunctionCallInfoData fcinfo;
1019  Datum result;
1020 
1021  InitFunctionCallInfoData(fcinfo, NULL, 1, collation, NULL, NULL);
1022 
1023  fcinfo.arg[0] = arg1;
1024  fcinfo.argnull[0] = false;
1025 
1026  result = (*func) (&fcinfo);
1027 
1028  /* Check for null result, since caller is clearly not expecting one */
1029  if (fcinfo.isnull)
1030  elog(ERROR, "function %p returned NULL", (void *) func);
1031 
1032  return result;
1033 }
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
Datum DirectFunctionCall2Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2 
)

Definition at line 1036 of file fmgr.c.

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

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

1037 {
1038  FunctionCallInfoData fcinfo;
1039  Datum result;
1040 
1041  InitFunctionCallInfoData(fcinfo, NULL, 2, collation, NULL, NULL);
1042 
1043  fcinfo.arg[0] = arg1;
1044  fcinfo.arg[1] = arg2;
1045  fcinfo.argnull[0] = false;
1046  fcinfo.argnull[1] = false;
1047 
1048  result = (*func) (&fcinfo);
1049 
1050  /* Check for null result, since caller is clearly not expecting one */
1051  if (fcinfo.isnull)
1052  elog(ERROR, "function %p returned NULL", (void *) func);
1053 
1054  return result;
1055 }
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
Datum DirectFunctionCall3Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3 
)

Definition at line 1058 of file fmgr.c.

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

1060 {
1061  FunctionCallInfoData fcinfo;
1062  Datum result;
1063 
1064  InitFunctionCallInfoData(fcinfo, NULL, 3, collation, NULL, NULL);
1065 
1066  fcinfo.arg[0] = arg1;
1067  fcinfo.arg[1] = arg2;
1068  fcinfo.arg[2] = arg3;
1069  fcinfo.argnull[0] = false;
1070  fcinfo.argnull[1] = false;
1071  fcinfo.argnull[2] = false;
1072 
1073  result = (*func) (&fcinfo);
1074 
1075  /* Check for null result, since caller is clearly not expecting one */
1076  if (fcinfo.isnull)
1077  elog(ERROR, "function %p returned NULL", (void *) func);
1078 
1079  return result;
1080 }
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
Datum DirectFunctionCall4Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4 
)

Definition at line 1083 of file fmgr.c.

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

Referenced by execute_extension_script().

1085 {
1086  FunctionCallInfoData fcinfo;
1087  Datum result;
1088 
1089  InitFunctionCallInfoData(fcinfo, NULL, 4, collation, NULL, NULL);
1090 
1091  fcinfo.arg[0] = arg1;
1092  fcinfo.arg[1] = arg2;
1093  fcinfo.arg[2] = arg3;
1094  fcinfo.arg[3] = arg4;
1095  fcinfo.argnull[0] = false;
1096  fcinfo.argnull[1] = false;
1097  fcinfo.argnull[2] = false;
1098  fcinfo.argnull[3] = false;
1099 
1100  result = (*func) (&fcinfo);
1101 
1102  /* Check for null result, since caller is clearly not expecting one */
1103  if (fcinfo.isnull)
1104  elog(ERROR, "function %p returned NULL", (void *) func);
1105 
1106  return result;
1107 }
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
Datum DirectFunctionCall5Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5 
)

Definition at line 1110 of file fmgr.c.

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

1112 {
1113  FunctionCallInfoData fcinfo;
1114  Datum result;
1115 
1116  InitFunctionCallInfoData(fcinfo, NULL, 5, collation, NULL, NULL);
1117 
1118  fcinfo.arg[0] = arg1;
1119  fcinfo.arg[1] = arg2;
1120  fcinfo.arg[2] = arg3;
1121  fcinfo.arg[3] = arg4;
1122  fcinfo.arg[4] = arg5;
1123  fcinfo.argnull[0] = false;
1124  fcinfo.argnull[1] = false;
1125  fcinfo.argnull[2] = false;
1126  fcinfo.argnull[3] = false;
1127  fcinfo.argnull[4] = false;
1128 
1129  result = (*func) (&fcinfo);
1130 
1131  /* Check for null result, since caller is clearly not expecting one */
1132  if (fcinfo.isnull)
1133  elog(ERROR, "function %p returned NULL", (void *) func);
1134 
1135  return result;
1136 }
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
Datum DirectFunctionCall6Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6 
)

Definition at line 1139 of file fmgr.c.

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

1142 {
1143  FunctionCallInfoData fcinfo;
1144  Datum result;
1145 
1146  InitFunctionCallInfoData(fcinfo, NULL, 6, collation, NULL, NULL);
1147 
1148  fcinfo.arg[0] = arg1;
1149  fcinfo.arg[1] = arg2;
1150  fcinfo.arg[2] = arg3;
1151  fcinfo.arg[3] = arg4;
1152  fcinfo.arg[4] = arg5;
1153  fcinfo.arg[5] = arg6;
1154  fcinfo.argnull[0] = false;
1155  fcinfo.argnull[1] = false;
1156  fcinfo.argnull[2] = false;
1157  fcinfo.argnull[3] = false;
1158  fcinfo.argnull[4] = false;
1159  fcinfo.argnull[5] = false;
1160 
1161  result = (*func) (&fcinfo);
1162 
1163  /* Check for null result, since caller is clearly not expecting one */
1164  if (fcinfo.isnull)
1165  elog(ERROR, "function %p returned NULL", (void *) func);
1166 
1167  return result;
1168 }
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
Datum DirectFunctionCall7Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7 
)

Definition at line 1171 of file fmgr.c.

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

1174 {
1175  FunctionCallInfoData fcinfo;
1176  Datum result;
1177 
1178  InitFunctionCallInfoData(fcinfo, NULL, 7, collation, NULL, NULL);
1179 
1180  fcinfo.arg[0] = arg1;
1181  fcinfo.arg[1] = arg2;
1182  fcinfo.arg[2] = arg3;
1183  fcinfo.arg[3] = arg4;
1184  fcinfo.arg[4] = arg5;
1185  fcinfo.arg[5] = arg6;
1186  fcinfo.arg[6] = arg7;
1187  fcinfo.argnull[0] = false;
1188  fcinfo.argnull[1] = false;
1189  fcinfo.argnull[2] = false;
1190  fcinfo.argnull[3] = false;
1191  fcinfo.argnull[4] = false;
1192  fcinfo.argnull[5] = false;
1193  fcinfo.argnull[6] = false;
1194 
1195  result = (*func) (&fcinfo);
1196 
1197  /* Check for null result, since caller is clearly not expecting one */
1198  if (fcinfo.isnull)
1199  elog(ERROR, "function %p returned NULL", (void *) func);
1200 
1201  return result;
1202 }
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
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 1205 of file fmgr.c.

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

1208 {
1209  FunctionCallInfoData fcinfo;
1210  Datum result;
1211 
1212  InitFunctionCallInfoData(fcinfo, NULL, 8, collation, NULL, NULL);
1213 
1214  fcinfo.arg[0] = arg1;
1215  fcinfo.arg[1] = arg2;
1216  fcinfo.arg[2] = arg3;
1217  fcinfo.arg[3] = arg4;
1218  fcinfo.arg[4] = arg5;
1219  fcinfo.arg[5] = arg6;
1220  fcinfo.arg[6] = arg7;
1221  fcinfo.arg[7] = arg8;
1222  fcinfo.argnull[0] = false;
1223  fcinfo.argnull[1] = false;
1224  fcinfo.argnull[2] = false;
1225  fcinfo.argnull[3] = false;
1226  fcinfo.argnull[4] = false;
1227  fcinfo.argnull[5] = false;
1228  fcinfo.argnull[6] = false;
1229  fcinfo.argnull[7] = false;
1230 
1231  result = (*func) (&fcinfo);
1232 
1233  /* Check for null result, since caller is clearly not expecting one */
1234  if (fcinfo.isnull)
1235  elog(ERROR, "function %p returned NULL", (void *) func);
1236 
1237  return result;
1238 }
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
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 1241 of file fmgr.c.

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

1245 {
1246  FunctionCallInfoData fcinfo;
1247  Datum result;
1248 
1249  InitFunctionCallInfoData(fcinfo, NULL, 9, collation, NULL, NULL);
1250 
1251  fcinfo.arg[0] = arg1;
1252  fcinfo.arg[1] = arg2;
1253  fcinfo.arg[2] = arg3;
1254  fcinfo.arg[3] = arg4;
1255  fcinfo.arg[4] = arg5;
1256  fcinfo.arg[5] = arg6;
1257  fcinfo.arg[6] = arg7;
1258  fcinfo.arg[7] = arg8;
1259  fcinfo.arg[8] = arg9;
1260  fcinfo.argnull[0] = false;
1261  fcinfo.argnull[1] = false;
1262  fcinfo.argnull[2] = false;
1263  fcinfo.argnull[3] = false;
1264  fcinfo.argnull[4] = false;
1265  fcinfo.argnull[5] = false;
1266  fcinfo.argnull[6] = false;
1267  fcinfo.argnull[7] = false;
1268  fcinfo.argnull[8] = false;
1269 
1270  result = (*func) (&fcinfo);
1271 
1272  /* Check for null result, since caller is clearly not expecting one */
1273  if (fcinfo.isnull)
1274  elog(ERROR, "function %p returned NULL", (void *) func);
1275 
1276  return result;
1277 }
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
const Pg_finfo_record* fetch_finfo_record ( void *  filehandle,
char *  funcname 
)

Definition at line 444 of file fmgr.c.

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

Referenced by fmgr_c_validator(), and fmgr_info_C_lang().

445 {
446  char *infofuncname;
447  PGFInfoFunction infofunc;
448  const Pg_finfo_record *inforec;
449  static Pg_finfo_record default_inforec = {0};
450 
451  infofuncname = psprintf("pg_finfo_%s", funcname);
452 
453  /* Try to look up the info function */
454  infofunc = (PGFInfoFunction) lookup_external_function(filehandle,
455  infofuncname);
456  if (infofunc == NULL)
457  {
458  /* Not found --- assume version 0 */
459  pfree(infofuncname);
460  return &default_inforec;
461  }
462 
463  /* Found, so call it */
464  inforec = (*infofunc) ();
465 
466  /* Validate result as best we can */
467  if (inforec == NULL)
468  elog(ERROR, "null result from info function \"%s\"", infofuncname);
469  switch (inforec->api_version)
470  {
471  case 0:
472  case 1:
473  /* OK, no additional fields to validate */
474  break;
475  default:
476  ereport(ERROR,
477  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
478  errmsg("unrecognized API version %d reported by info function \"%s\"",
479  inforec->api_version, infofuncname)));
480  break;
481  }
482 
483  pfree(infofuncname);
484  return inforec;
485 }
const Pg_finfo_record *(* PGFInfoFunction)(void)
Definition: fmgr.h:351
PGFunction lookup_external_function(void *filehandle, char *funcname)
Definition: dfmgr.c:158
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
int errcode(int sqlerrcode)
Definition: elog.c:575
void pfree(void *pointer)
Definition: mcxt.c:950
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define NULL
Definition: c.h:229
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219
int api_version
Definition: fmgr.h:346
Datum Float4GetDatum ( float4  X)

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

2165 {
2166  float4 *retval = (float4 *) palloc(sizeof(float4));
2167 
2168  *retval = X;
2169  return PointerGetDatum(retval);
2170 }
#define PointerGetDatum(X)
Definition: postgres.h:562
float float4
Definition: c.h:380
void * palloc(Size size)
Definition: mcxt.c:849
Datum Float8GetDatum ( float8  X)

Definition at line 2176 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(), and spg_kd_picksplit().

2177 {
2178  float8 *retval = (float8 *) palloc(sizeof(float8));
2179 
2180  *retval = X;
2181  return PointerGetDatum(retval);
2182 }
#define PointerGetDatum(X)
Definition: postgres.h:562
double float8
Definition: c.h:381
void * palloc(Size size)
Definition: mcxt.c:849
char* fmgr ( Oid  procedureId,
  ... 
)

Definition at line 2096 of file fmgr.c.

References FunctionCallInfoData::arg, DatumGetPointer, elog, ereport, errcode(), errmsg(), ERROR, FunctionCallInfoData::flinfo, fmgr_security_definer_cache::flinfo, fmgr_info(), FmgrInfo::fn_nargs, FmgrInfo::fn_oid, FUNC_MAX_ARGS, FunctionCallInvoke, i, FunctionCallInfoData::isnull, MemSet, FunctionCallInfoData::nargs, PointerGetDatum, and result.

2097 {
2098  FmgrInfo flinfo;
2099  FunctionCallInfoData fcinfo;
2100  int n_arguments;
2101  Datum result;
2102 
2103  fmgr_info(procedureId, &flinfo);
2104 
2105  MemSet(&fcinfo, 0, sizeof(fcinfo));
2106  fcinfo.flinfo = &flinfo;
2107  fcinfo.nargs = flinfo.fn_nargs;
2108  n_arguments = fcinfo.nargs;
2109 
2110  if (n_arguments > 0)
2111  {
2112  va_list pvar;
2113  int i;
2114 
2115  if (n_arguments > FUNC_MAX_ARGS)
2116  ereport(ERROR,
2117  (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
2118  errmsg("function %u has too many arguments (%d, maximum is %d)",
2119  flinfo.fn_oid, n_arguments, FUNC_MAX_ARGS)));
2120  va_start(pvar, procedureId);
2121  for (i = 0; i < n_arguments; i++)
2122  fcinfo.arg[i] = PointerGetDatum(va_arg(pvar, char *));
2123  va_end(pvar);
2124  }
2125 
2126  result = FunctionCallInvoke(&fcinfo);
2127 
2128  /* Check for null result, since caller is clearly not expecting one */
2129  if (fcinfo.isnull)
2130  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
2131 
2132  return DatumGetPointer(result);
2133 }
Definition: fmgr.h:53
short fn_nargs
Definition: fmgr.h:57
#define PointerGetDatum(X)
Definition: postgres.h:562
int errcode(int sqlerrcode)
Definition: elog.c:575
#define MemSet(start, val, len)
Definition: c.h:857
return result
Definition: formatting.c:1618
#define FUNC_MAX_ARGS
FmgrInfo * flinfo
Definition: fmgr.h:71
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:159
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:129
#define ereport(elevel, rest)
Definition: elog.h:122
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:56
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define DatumGetPointer(X)
Definition: postgres.h:555
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
#define elog
Definition: elog.h:219
void fmgr_info ( Oid  functionId,
FmgrInfo finfo 
)

Definition at line 159 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(), ExecInitExpr(), ExecInitSubPlan(), ExecInitTableFuncScan(), execTuplesHashPrepare(), execTuplesMatchPrepare(), fetch_fp_info(), fmgr(), 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().

160 {
161  fmgr_info_cxt_security(functionId, finfo, CurrentMemoryContext, false);
162 }
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
static void fmgr_info_cxt_security(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt, bool ignore_security)
Definition: fmgr.c:179
static void fmgr_info_C_lang ( Oid  functionId,
FmgrInfo finfo,
HeapTuple  procedureTuple 
)
static

Definition at line 305 of file fmgr.c.

References Anum_pg_proc_probin, Anum_pg_proc_prosrc, Pg_finfo_record::api_version, Oldstyle_fnextra::arg_toastable, elog, ERROR, fetch_finfo_record(), fmgr_oldstyle(), FmgrInfo::fn_addr, FmgrInfo::fn_extra, FmgrInfo::fn_mcxt, Oldstyle_fnextra::func, GETSTRUCT, i, CFuncHashTabEntry::inforec, load_external_function(), lookup_C_func(), MemoryContextAllocZero(), pfree(), PROCOID, record_C_func(), SysCacheGetAttr(), TextDatumGetCString, TypeIsToastable, and CFuncHashTabEntry::user_fn.

Referenced by fmgr_info_cxt_security().

306 {
307  Form_pg_proc procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
308  CFuncHashTabEntry *hashentry;
309  PGFunction user_fn;
310  const Pg_finfo_record *inforec;
311  Oldstyle_fnextra *fnextra;
312  bool isnull;
313  int i;
314 
315  /*
316  * See if we have the function address cached already
317  */
318  hashentry = lookup_C_func(procedureTuple);
319  if (hashentry)
320  {
321  user_fn = hashentry->user_fn;
322  inforec = hashentry->inforec;
323  }
324  else
325  {
326  Datum prosrcattr,
327  probinattr;
328  char *prosrcstring,
329  *probinstring;
330  void *libraryhandle;
331 
332  /*
333  * Get prosrc and probin strings (link symbol and library filename).
334  * While in general these columns might be null, that's not allowed
335  * for C-language functions.
336  */
337  prosrcattr = SysCacheGetAttr(PROCOID, procedureTuple,
338  Anum_pg_proc_prosrc, &isnull);
339  if (isnull)
340  elog(ERROR, "null prosrc for C function %u", functionId);
341  prosrcstring = TextDatumGetCString(prosrcattr);
342 
343  probinattr = SysCacheGetAttr(PROCOID, procedureTuple,
344  Anum_pg_proc_probin, &isnull);
345  if (isnull)
346  elog(ERROR, "null probin for C function %u", functionId);
347  probinstring = TextDatumGetCString(probinattr);
348 
349  /* Look up the function itself */
350  user_fn = load_external_function(probinstring, prosrcstring, true,
351  &libraryhandle);
352 
353  /* Get the function information record (real or default) */
354  inforec = fetch_finfo_record(libraryhandle, prosrcstring);
355 
356  /* Cache the addresses for later calls */
357  record_C_func(procedureTuple, user_fn, inforec);
358 
359  pfree(prosrcstring);
360  pfree(probinstring);
361  }
362 
363  switch (inforec->api_version)
364  {
365  case 0:
366  /* Old style: need to use a handler */
367  finfo->fn_addr = fmgr_oldstyle;
368  fnextra = (Oldstyle_fnextra *)
370  sizeof(Oldstyle_fnextra));
371  finfo->fn_extra = (void *) fnextra;
372  fnextra->func = (func_ptr) user_fn;
373  for (i = 0; i < procedureStruct->pronargs; i++)
374  {
375  fnextra->arg_toastable[i] =
376  TypeIsToastable(procedureStruct->proargtypes.values[i]);
377  }
378  break;
379  case 1:
380  /* New style: call directly */
381  finfo->fn_addr = user_fn;
382  break;
383  default:
384  /* Shouldn't get here if fetch_finfo_record did its job */
385  elog(ERROR, "unrecognized function API version: %d",
386  inforec->api_version);
387  break;
388  }
389 }
const Pg_finfo_record * fetch_finfo_record(void *filehandle, char *funcname)
Definition: fmgr.c:444
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
MemoryContext fn_mcxt
Definition: fmgr.h:62
char *(* func_ptr)()
Definition: fmgr.c:57
PGFunction fn_addr
Definition: fmgr.h:55
Datum(* PGFunction)(FunctionCallInfo fcinfo)
Definition: fmgr.h:40
const Pg_finfo_record * inforec
Definition: fmgr.c:80
#define Anum_pg_proc_prosrc
Definition: pg_proc.h:115
static Datum fmgr_oldstyle(PG_FUNCTION_ARGS)
Definition: fmgr.c:623
#define Anum_pg_proc_probin
Definition: pg_proc.h:116
void pfree(void *pointer)
Definition: mcxt.c:950
#define ERROR
Definition: elog.h:43
PGFunction user_fn
Definition: fmgr.c:79
PGFunction load_external_function(char *filename, 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:1255
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:83
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:742
static void record_C_func(HeapTuple procedureTuple, PGFunction user_fn, const Pg_finfo_record *inforec)
Definition: fmgr.c:527
func_ptr func
Definition: fmgr.c:65
static CFuncHashTabEntry * lookup_C_func(HeapTuple procedureTuple)
Definition: fmgr.c:503
void * fn_extra
Definition: fmgr.h:61
bool arg_toastable[FUNC_MAX_ARGS]
Definition: fmgr.c:66
int i
#define elog
Definition: elog.h:219
#define TypeIsToastable(typid)
Definition: lsyscache.h:167
int api_version
Definition: fmgr.h:346
void fmgr_info_copy ( FmgrInfo dstinfo,
FmgrInfo srcinfo,
MemoryContext  destcxt 
)

Definition at line 583 of file fmgr.c.

References fmgr_oldstyle(), FmgrInfo::fn_addr, FmgrInfo::fn_extra, FmgrInfo::fn_mcxt, MemoryContextAlloc(), and NULL.

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

585 {
586  memcpy(dstinfo, srcinfo, sizeof(FmgrInfo));
587  dstinfo->fn_mcxt = destcxt;
588  if (dstinfo->fn_addr == fmgr_oldstyle)
589  {
590  /* For oldstyle functions we must copy fn_extra */
591  Oldstyle_fnextra *fnextra;
592 
593  fnextra = (Oldstyle_fnextra *)
594  MemoryContextAlloc(destcxt, sizeof(Oldstyle_fnextra));
595  memcpy(fnextra, srcinfo->fn_extra, sizeof(Oldstyle_fnextra));
596  dstinfo->fn_extra = (void *) fnextra;
597  }
598  else
599  dstinfo->fn_extra = NULL;
600 }
Definition: fmgr.h:53
MemoryContext fn_mcxt
Definition: fmgr.h:62
PGFunction fn_addr
Definition: fmgr.h:55
static Datum fmgr_oldstyle(PG_FUNCTION_ARGS)
Definition: fmgr.c:623
#define NULL
Definition: c.h:229
void * fn_extra
Definition: fmgr.h:61
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:707
static void fmgr_info_cxt_security ( Oid  functionId,
FmgrInfo finfo,
MemoryContext  mcxt,
bool  ignore_security 
)
static

Definition at line 179 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, NULL, 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().

181 {
182  const FmgrBuiltin *fbp;
183  HeapTuple procedureTuple;
184  Form_pg_proc procedureStruct;
185  Datum prosrcdatum;
186  bool isnull;
187  char *prosrc;
188 
189  /*
190  * fn_oid *must* be filled in last. Some code assumes that if fn_oid is
191  * valid, the whole struct is valid. Some FmgrInfo struct's do survive
192  * elogs.
193  */
194  finfo->fn_oid = InvalidOid;
195  finfo->fn_extra = NULL;
196  finfo->fn_mcxt = mcxt;
197  finfo->fn_expr = NULL; /* caller may set this later */
198 
199  if ((fbp = fmgr_isbuiltin(functionId)) != NULL)
200  {
201  /*
202  * Fast path for builtin functions: don't bother consulting pg_proc
203  */
204  finfo->fn_nargs = fbp->nargs;
205  finfo->fn_strict = fbp->strict;
206  finfo->fn_retset = fbp->retset;
207  finfo->fn_stats = TRACK_FUNC_ALL; /* ie, never track */
208  finfo->fn_addr = fbp->func;
209  finfo->fn_oid = functionId;
210  return;
211  }
212 
213  /* Otherwise we need the pg_proc entry */
214  procedureTuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(functionId));
215  if (!HeapTupleIsValid(procedureTuple))
216  elog(ERROR, "cache lookup failed for function %u", functionId);
217  procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
218 
219  finfo->fn_nargs = procedureStruct->pronargs;
220  finfo->fn_strict = procedureStruct->proisstrict;
221  finfo->fn_retset = procedureStruct->proretset;
222 
223  /*
224  * If it has prosecdef set, non-null proconfig, or if a plugin wants to
225  * hook function entry/exit, use fmgr_security_definer call handler ---
226  * unless we are being called again by fmgr_security_definer or
227  * fmgr_info_other_lang.
228  *
229  * When using fmgr_security_definer, function stats tracking is always
230  * disabled at the outer level, and instead we set the flag properly in
231  * fmgr_security_definer's private flinfo and implement the tracking
232  * inside fmgr_security_definer. This loses the ability to charge the
233  * overhead of fmgr_security_definer to the function, but gains the
234  * ability to set the track_functions GUC as a local GUC parameter of an
235  * interesting function and have the right things happen.
236  */
237  if (!ignore_security &&
238  (procedureStruct->prosecdef ||
239  !heap_attisnull(procedureTuple, Anum_pg_proc_proconfig) ||
240  FmgrHookIsNeeded(functionId)))
241  {
243  finfo->fn_stats = TRACK_FUNC_ALL; /* ie, never track */
244  finfo->fn_oid = functionId;
245  ReleaseSysCache(procedureTuple);
246  return;
247  }
248 
249  switch (procedureStruct->prolang)
250  {
251  case INTERNALlanguageId:
252 
253  /*
254  * For an ordinary builtin function, we should never get here
255  * because the isbuiltin() search above will have succeeded.
256  * However, if the user has done a CREATE FUNCTION to create an
257  * alias for a builtin function, we can end up here. In that case
258  * we have to look up the function by name. The name of the
259  * internal function is stored in prosrc (it doesn't have to be
260  * the same as the name of the alias!)
261  */
262  prosrcdatum = SysCacheGetAttr(PROCOID, procedureTuple,
263  Anum_pg_proc_prosrc, &isnull);
264  if (isnull)
265  elog(ERROR, "null prosrc");
266  prosrc = TextDatumGetCString(prosrcdatum);
267  fbp = fmgr_lookupByName(prosrc);
268  if (fbp == NULL)
269  ereport(ERROR,
270  (errcode(ERRCODE_UNDEFINED_FUNCTION),
271  errmsg("internal function \"%s\" is not in internal lookup table",
272  prosrc)));
273  pfree(prosrc);
274  /* Should we check that nargs, strict, retset match the table? */
275  finfo->fn_addr = fbp->func;
276  /* note this policy is also assumed in fast path above */
277  finfo->fn_stats = TRACK_FUNC_ALL; /* ie, never track */
278  break;
279 
280  case ClanguageId:
281  fmgr_info_C_lang(functionId, finfo, procedureTuple);
282  finfo->fn_stats = TRACK_FUNC_PL; /* ie, track if ALL */
283  break;
284 
285  case SQLlanguageId:
286  finfo->fn_addr = fmgr_sql;
287  finfo->fn_stats = TRACK_FUNC_PL; /* ie, track if ALL */
288  break;
289 
290  default:
291  fmgr_info_other_lang(functionId, finfo, procedureTuple);
292  finfo->fn_stats = TRACK_FUNC_OFF; /* ie, track if not OFF */
293  break;
294  }
295 
296  finfo->fn_oid = functionId;
297  ReleaseSysCache(procedureTuple);
298 }
bool strict
Definition: fmgrtab.h:30
short fn_nargs
Definition: fmgr.h:57
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
MemoryContext fn_mcxt
Definition: fmgr.h:62
short nargs
Definition: fmgrtab.h:29
#define INTERNALlanguageId
Definition: pg_language.h:74
static Datum fmgr_security_definer(PG_FUNCTION_ARGS)
Definition: fmgr.c:883
PGFunction fn_addr
Definition: fmgr.h:55
static void fmgr_info_other_lang(Oid functionId, FmgrInfo *finfo, HeapTuple procedureTuple)
Definition: fmgr.c:396
#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:720
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:150
#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:305
PGFunction func
Definition: fmgrtab.h:32
void pfree(void *pointer)
Definition: mcxt.c:950
bool fn_retset
Definition: fmgr.h:59
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
bool fn_strict
Definition: fmgr.h:58
#define SQLlanguageId
Definition: pg_language.h:80
bool heap_attisnull(HeapTuple tup, int attnum)
Definition: heaptuple.c:297
Datum fmgr_sql(PG_FUNCTION_ARGS)
Definition: functions.c:985
static const FmgrBuiltin * fmgr_lookupByName(const char *name)
Definition: fmgr.c:133
#define ereport(elevel, rest)
Definition: elog.h:122
#define TextDatumGetCString(d)
Definition: builtins.h:92
static const FmgrBuiltin * fmgr_isbuiltin(Oid id)
Definition: fmgr.c:103
uintptr_t Datum
Definition: postgres.h:372
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1093
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1255
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:83
#define InvalidOid
Definition: postgres_ext.h:36
Oid fn_oid
Definition: fmgr.h:56
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:229
fmNodePtr fn_expr
Definition: fmgr.h:63
void * fn_extra
Definition: fmgr.h:61
int errmsg(const char *fmt,...)
Definition: elog.c:797
unsigned char fn_stats
Definition: fmgr.h:60
#define elog
Definition: elog.h:219
bool retset
Definition: fmgrtab.h:31
static void fmgr_info_other_lang ( Oid  functionId,
FmgrInfo finfo,
HeapTuple  procedureTuple 
)
static

Definition at line 396 of file fmgr.c.

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

Referenced by fmgr_info_cxt_security().

397 {
398  Form_pg_proc procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
399  Oid language = procedureStruct->prolang;
400  HeapTuple languageTuple;
401  Form_pg_language languageStruct;
402  FmgrInfo plfinfo;
403 
404  languageTuple = SearchSysCache1(LANGOID, ObjectIdGetDatum(language));
405  if (!HeapTupleIsValid(languageTuple))
406  elog(ERROR, "cache lookup failed for language %u", language);
407  languageStruct = (Form_pg_language) GETSTRUCT(languageTuple);
408 
409  /*
410  * Look up the language's call handler function, ignoring any attributes
411  * that would normally cause insertion of fmgr_security_definer. We need
412  * to get back a bare pointer to the actual C-language function.
413  */
414  fmgr_info_cxt_security(languageStruct->lanplcallfoid, &plfinfo,
415  CurrentMemoryContext, true);
416  finfo->fn_addr = plfinfo.fn_addr;
417 
418  /*
419  * If lookup of the PL handler function produced nonnull fn_extra,
420  * complain --- it must be an oldstyle function! We no longer support
421  * oldstyle PL handlers.
422  */
423  if (plfinfo.fn_extra != NULL)
424  elog(ERROR, "language %u has old-style handler", language);
425 
426  ReleaseSysCache(languageTuple);
427 }
Definition: fmgr.h:53
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
PGFunction fn_addr
Definition: fmgr.h:55
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:150
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1093
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:83
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:229
void * fn_extra
Definition: fmgr.h:61
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:179
Oid fmgr_internal_function ( const char *  proname)

Definition at line 609 of file fmgr.c.

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

Referenced by fmgr_internal_validator().

610 {
611  const FmgrBuiltin *fbp = fmgr_lookupByName(proname);
612 
613  if (fbp == NULL)
614  return InvalidOid;
615  return fbp->foid;
616 }
Oid foid
Definition: fmgrtab.h:27
static const FmgrBuiltin * fmgr_lookupByName(const char *name)
Definition: fmgr.c:133
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:229
static const FmgrBuiltin* fmgr_isbuiltin ( Oid  id)
static

Definition at line 103 of file fmgr.c.

References fmgr_builtins, fmgr_nbuiltins, FmgrBuiltin::foid, i, and NULL.

Referenced by fmgr_info_cxt_security().

104 {
105  int low = 0;
106  int high = fmgr_nbuiltins - 1;
107 
108  /*
109  * Loop invariant: low is the first index that could contain target entry,
110  * and high is the last index that could contain it.
111  */
112  while (low <= high)
113  {
114  int i = (high + low) / 2;
115  const FmgrBuiltin *ptr = &fmgr_builtins[i];
116 
117  if (id == ptr->foid)
118  return ptr;
119  else if (id > ptr->foid)
120  low = i + 1;
121  else
122  high = i - 1;
123  }
124  return NULL;
125 }
Oid foid
Definition: fmgrtab.h:27
const int fmgr_nbuiltins
const FmgrBuiltin fmgr_builtins[]
#define NULL
Definition: c.h:229
int i
static const FmgrBuiltin* fmgr_lookupByName ( const char *  name)
static

Definition at line 133 of file fmgr.c.

References fmgr_builtins, fmgr_nbuiltins, i, and NULL.

Referenced by fmgr_info_cxt_security(), and fmgr_internal_function().

134 {
135  int i;
136 
137  for (i = 0; i < fmgr_nbuiltins; i++)
138  {
139  if (strcmp(name, fmgr_builtins[i].funcName) == 0)
140  return fmgr_builtins + i;
141  }
142  return NULL;
143 }
const int fmgr_nbuiltins
const FmgrBuiltin fmgr_builtins[]
#define NULL
Definition: c.h:229
const char * name
Definition: encode.c:521
int i
static Datum fmgr_oldstyle ( PG_FUNCTION_ARGS  )
static

Definition at line 623 of file fmgr.c.

References Oldstyle_fnextra::arg_toastable, elog, ereport, errcode(), errmsg(), ERROR, Oldstyle_fnextra::func, i, NULL, PG_ARGISNULL, PG_DETOAST_DATUM, and PointerGetDatum.

Referenced by fmgr_info_C_lang(), and fmgr_info_copy().

624 {
625  Oldstyle_fnextra *fnextra;
626  int n_arguments = fcinfo->nargs;
627  int i;
628  bool isnull;
629  func_ptr user_fn;
630  char *returnValue;
631 
632  if (fcinfo->flinfo == NULL || fcinfo->flinfo->fn_extra == NULL)
633  elog(ERROR, "fmgr_oldstyle received NULL pointer");
634  fnextra = (Oldstyle_fnextra *) fcinfo->flinfo->fn_extra;
635 
636  /*
637  * Result is NULL if any argument is NULL, but we still call the function
638  * (peculiar, but that's the way it worked before, and after all this is a
639  * backwards-compatibility wrapper). Note, however, that we'll never get
640  * here with NULL arguments if the function is marked strict.
641  *
642  * We also need to detoast any TOAST-ed inputs, since it's unlikely that
643  * an old-style function knows about TOASTing.
644  */
645  isnull = false;
646  for (i = 0; i < n_arguments; i++)
647  {
648  if (PG_ARGISNULL(i))
649  isnull = true;
650  else if (fnextra->arg_toastable[i])
651  fcinfo->arg[i] = PointerGetDatum(PG_DETOAST_DATUM(fcinfo->arg[i]));
652  }
653  fcinfo->isnull = isnull;
654 
655  user_fn = fnextra->func;
656 
657  switch (n_arguments)
658  {
659  case 0:
660  returnValue = (char *) (*user_fn) ();
661  break;
662  case 1:
663 
664  /*
665  * nullvalue() used to use isNull to check if arg is NULL; perhaps
666  * there are other functions still out there that also rely on
667  * this undocumented hack?
668  */
669  returnValue = (char *) (*user_fn) (fcinfo->arg[0],
670  &fcinfo->isnull);
671  break;
672  case 2:
673  returnValue = (char *) (*user_fn) (fcinfo->arg[0],
674  fcinfo->arg[1]);
675  break;
676  case 3:
677  returnValue = (char *) (*user_fn) (fcinfo->arg[0],
678  fcinfo->arg[1],
679  fcinfo->arg[2]);
680  break;
681  case 4:
682  returnValue = (char *) (*user_fn) (fcinfo->arg[0],
683  fcinfo->arg[1],
684  fcinfo->arg[2],
685  fcinfo->arg[3]);
686  break;
687  case 5:
688  returnValue = (char *) (*user_fn) (fcinfo->arg[0],
689  fcinfo->arg[1],
690  fcinfo->arg[2],
691  fcinfo->arg[3],
692  fcinfo->arg[4]);
693  break;
694  case 6:
695  returnValue = (char *) (*user_fn) (fcinfo->arg[0],
696  fcinfo->arg[1],
697  fcinfo->arg[2],
698  fcinfo->arg[3],
699  fcinfo->arg[4],
700  fcinfo->arg[5]);
701  break;
702  case 7:
703  returnValue = (char *) (*user_fn) (fcinfo->arg[0],
704  fcinfo->arg[1],
705  fcinfo->arg[2],
706  fcinfo->arg[3],
707  fcinfo->arg[4],
708  fcinfo->arg[5],
709  fcinfo->arg[6]);
710  break;
711  case 8:
712  returnValue = (char *) (*user_fn) (fcinfo->arg[0],
713  fcinfo->arg[1],
714  fcinfo->arg[2],
715  fcinfo->arg[3],
716  fcinfo->arg[4],
717  fcinfo->arg[5],
718  fcinfo->arg[6],
719  fcinfo->arg[7]);
720  break;
721  case 9:
722  returnValue = (char *) (*user_fn) (fcinfo->arg[0],
723  fcinfo->arg[1],
724  fcinfo->arg[2],
725  fcinfo->arg[3],
726  fcinfo->arg[4],
727  fcinfo->arg[5],
728  fcinfo->arg[6],
729  fcinfo->arg[7],
730  fcinfo->arg[8]);
731  break;
732  case 10:
733  returnValue = (char *) (*user_fn) (fcinfo->arg[0],
734  fcinfo->arg[1],
735  fcinfo->arg[2],
736  fcinfo->arg[3],
737  fcinfo->arg[4],
738  fcinfo->arg[5],
739  fcinfo->arg[6],
740  fcinfo->arg[7],
741  fcinfo->arg[8],
742  fcinfo->arg[9]);
743  break;
744  case 11:
745  returnValue = (char *) (*user_fn) (fcinfo->arg[0],
746  fcinfo->arg[1],
747  fcinfo->arg[2],
748  fcinfo->arg[3],
749  fcinfo->arg[4],
750  fcinfo->arg[5],
751  fcinfo->arg[6],
752  fcinfo->arg[7],
753  fcinfo->arg[8],
754  fcinfo->arg[9],
755  fcinfo->arg[10]);
756  break;
757  case 12:
758  returnValue = (char *) (*user_fn) (fcinfo->arg[0],
759  fcinfo->arg[1],
760  fcinfo->arg[2],
761  fcinfo->arg[3],
762  fcinfo->arg[4],
763  fcinfo->arg[5],
764  fcinfo->arg[6],
765  fcinfo->arg[7],
766  fcinfo->arg[8],
767  fcinfo->arg[9],
768  fcinfo->arg[10],
769  fcinfo->arg[11]);
770  break;
771  case 13:
772  returnValue = (char *) (*user_fn) (fcinfo->arg[0],
773  fcinfo->arg[1],
774  fcinfo->arg[2],
775  fcinfo->arg[3],
776  fcinfo->arg[4],
777  fcinfo->arg[5],
778  fcinfo->arg[6],
779  fcinfo->arg[7],
780  fcinfo->arg[8],
781  fcinfo->arg[9],
782  fcinfo->arg[10],
783  fcinfo->arg[11],
784  fcinfo->arg[12]);
785  break;
786  case 14:
787  returnValue = (char *) (*user_fn) (fcinfo->arg[0],
788  fcinfo->arg[1],
789  fcinfo->arg[2],
790  fcinfo->arg[3],
791  fcinfo->arg[4],
792  fcinfo->arg[5],
793  fcinfo->arg[6],
794  fcinfo->arg[7],
795  fcinfo->arg[8],
796  fcinfo->arg[9],
797  fcinfo->arg[10],
798  fcinfo->arg[11],
799  fcinfo->arg[12],
800  fcinfo->arg[13]);
801  break;
802  case 15:
803  returnValue = (char *) (*user_fn) (fcinfo->arg[0],
804  fcinfo->arg[1],
805  fcinfo->arg[2],
806  fcinfo->arg[3],
807  fcinfo->arg[4],
808  fcinfo->arg[5],
809  fcinfo->arg[6],
810  fcinfo->arg[7],
811  fcinfo->arg[8],
812  fcinfo->arg[9],
813  fcinfo->arg[10],
814  fcinfo->arg[11],
815  fcinfo->arg[12],
816  fcinfo->arg[13],
817  fcinfo->arg[14]);
818  break;
819  case 16:
820  returnValue = (char *) (*user_fn) (fcinfo->arg[0],
821  fcinfo->arg[1],
822  fcinfo->arg[2],
823  fcinfo->arg[3],
824  fcinfo->arg[4],
825  fcinfo->arg[5],
826  fcinfo->arg[6],
827  fcinfo->arg[7],
828  fcinfo->arg[8],
829  fcinfo->arg[9],
830  fcinfo->arg[10],
831  fcinfo->arg[11],
832  fcinfo->arg[12],
833  fcinfo->arg[13],
834  fcinfo->arg[14],
835  fcinfo->arg[15]);
836  break;
837  default:
838 
839  /*
840  * Increasing FUNC_MAX_ARGS doesn't automatically add cases to the
841  * above code, so mention the actual value in this error not
842  * FUNC_MAX_ARGS. You could add cases to the above if you needed
843  * to support old-style functions with many arguments, but making
844  * 'em be new-style is probably a better idea.
845  */
846  ereport(ERROR,
847  (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
848  errmsg("function %u has too many arguments (%d, maximum is %d)",
849  fcinfo->flinfo->fn_oid, n_arguments, 16)));
850  returnValue = NULL; /* keep compiler quiet */
851  break;
852  }
853 
854  return PointerGetDatum(returnValue);
855 }
char *(* func_ptr)()
Definition: fmgr.c:57
#define PointerGetDatum(X)
Definition: postgres.h:562
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_ARGISNULL(n)
Definition: fmgr.h:166
#define NULL
Definition: c.h:229
func_ptr func
Definition: fmgr.c:65
bool arg_toastable[FUNC_MAX_ARGS]
Definition: fmgr.c:66
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
#define PG_DETOAST_DATUM(datum)
Definition: fmgr.h:197
#define elog
Definition: elog.h:219
static Datum fmgr_security_definer ( PG_FUNCTION_ARGS  )
static

Definition at line 883 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(), NULL, 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(), result, SearchSysCache1, SECURITY_LOCAL_USERID_CHANGE, SetUserIdAndSecContext(), superuser(), SysCacheGetAttr(), and fmgr_security_definer_cache::userid.

Referenced by fmgr_info_cxt_security().

884 {
885  Datum result;
886  struct fmgr_security_definer_cache *volatile fcache;
887  FmgrInfo *save_flinfo;
888  Oid save_userid;
889  int save_sec_context;
890  volatile int save_nestlevel;
891  PgStat_FunctionCallUsage fcusage;
892 
893  if (!fcinfo->flinfo->fn_extra)
894  {
895  HeapTuple tuple;
896  Form_pg_proc procedureStruct;
897  Datum datum;
898  bool isnull;
899  MemoryContext oldcxt;
900 
901  fcache = MemoryContextAllocZero(fcinfo->flinfo->fn_mcxt,
902  sizeof(*fcache));
903 
904  fmgr_info_cxt_security(fcinfo->flinfo->fn_oid, &fcache->flinfo,
905  fcinfo->flinfo->fn_mcxt, true);
906  fcache->flinfo.fn_expr = fcinfo->flinfo->fn_expr;
907 
908  tuple = SearchSysCache1(PROCOID,
909  ObjectIdGetDatum(fcinfo->flinfo->fn_oid));
910  if (!HeapTupleIsValid(tuple))
911  elog(ERROR, "cache lookup failed for function %u",
912  fcinfo->flinfo->fn_oid);
913  procedureStruct = (Form_pg_proc) GETSTRUCT(tuple);
914 
915  if (procedureStruct->prosecdef)
916  fcache->userid = procedureStruct->proowner;
917 
919  &isnull);
920  if (!isnull)
921  {
922  oldcxt = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
923  fcache->proconfig = DatumGetArrayTypePCopy(datum);
924  MemoryContextSwitchTo(oldcxt);
925  }
926 
927  ReleaseSysCache(tuple);
928 
929  fcinfo->flinfo->fn_extra = fcache;
930  }
931  else
932  fcache = fcinfo->flinfo->fn_extra;
933 
934  /* GetUserIdAndSecContext is cheap enough that no harm in a wasted call */
935  GetUserIdAndSecContext(&save_userid, &save_sec_context);
936  if (fcache->proconfig) /* Need a new GUC nesting level */
937  save_nestlevel = NewGUCNestLevel();
938  else
939  save_nestlevel = 0; /* keep compiler quiet */
940 
941  if (OidIsValid(fcache->userid))
943  save_sec_context | SECURITY_LOCAL_USERID_CHANGE);
944 
945  if (fcache->proconfig)
946  {
947  ProcessGUCArray(fcache->proconfig,
951  }
952 
953  /* function manager hook */
954  if (fmgr_hook)
955  (*fmgr_hook) (FHET_START, &fcache->flinfo, &fcache->arg);
956 
957  /*
958  * We don't need to restore GUC or userid settings on error, because the
959  * ensuing xact or subxact abort will do that. The PG_TRY block is only
960  * needed to clean up the flinfo link.
961  */
962  save_flinfo = fcinfo->flinfo;
963 
964  PG_TRY();
965  {
966  fcinfo->flinfo = &fcache->flinfo;
967 
968  /* See notes in fmgr_info_cxt_security */
969  pgstat_init_function_usage(fcinfo, &fcusage);
970 
971  result = FunctionCallInvoke(fcinfo);
972 
973  /*
974  * We could be calling either a regular or a set-returning function,
975  * so we have to test to see what finalize flag to use.
976  */
977  pgstat_end_function_usage(&fcusage,
978  (fcinfo->resultinfo == NULL ||
979  !IsA(fcinfo->resultinfo, ReturnSetInfo) ||
980  ((ReturnSetInfo *) fcinfo->resultinfo)->isDone != ExprMultipleResult));
981  }
982  PG_CATCH();
983  {
984  fcinfo->flinfo = save_flinfo;
985  if (fmgr_hook)
986  (*fmgr_hook) (FHET_ABORT, &fcache->flinfo, &fcache->arg);
987  PG_RE_THROW();
988  }
989  PG_END_TRY();
990 
991  fcinfo->flinfo = save_flinfo;
992 
993  if (fcache->proconfig)
994  AtEOXact_GUC(true, save_nestlevel);
995  if (OidIsValid(fcache->userid))
996  SetUserIdAndSecContext(save_userid, save_sec_context);
997  if (fmgr_hook)
998  (*fmgr_hook) (FHET_END, &fcache->flinfo, &fcache->arg);
999 
1000  return result;
1001 }
Definition: fmgr.h:53
#define IsA(nodeptr, _type_)
Definition: nodes.h:571
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
MemoryContext fn_mcxt
Definition: fmgr.h:62
void SetUserIdAndSecContext(Oid userid, int sec_context)
Definition: miscinit.c:395
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
bool superuser(void)
Definition: superuser.c:47
return result
Definition: formatting.c:1618
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:150
#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:129
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
Definition: miscinit.c:388
void AtEOXact_GUC(bool isCommit, int nestLevel)
Definition: guc.c:5058
Definition: fmgr.h:708
ArrayType * proconfig
Definition: fmgr.c:868
uintptr_t Datum
Definition: postgres.h:372
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1093
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1255
#define DatumGetArrayTypePCopy(X)
Definition: array.h:243
PGDLLIMPORT fmgr_hook_type fmgr_hook
Definition: fmgr.c:37
#define SECURITY_LOCAL_USERID_CHANGE
Definition: miscadmin.h:291
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:83
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:742
void ProcessGUCArray(ArrayType *array, GucContext context, GucSource source, GucAction action)
Definition: guc.c:9387
#define PG_CATCH()
Definition: elog.h:293
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:229
fmNodePtr fn_expr
Definition: fmgr.h:63
#define PG_RE_THROW()
Definition: elog.h:314
void * fn_extra
Definition: fmgr.h:61
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
Definition: pgstat.c:1578
void pgstat_init_function_usage(FunctionCallInfoData *fcinfo, PgStat_FunctionCallUsage *fcu)
Definition: pgstat.c:1506
int NewGUCNestLevel(void)
Definition: guc.c:5044
#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:179
Datum FunctionCall1Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1 
)

Definition at line 1336 of file fmgr.c.

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

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

1337 {
1338  FunctionCallInfoData fcinfo;
1339  Datum result;
1340 
1341  InitFunctionCallInfoData(fcinfo, flinfo, 1, collation, NULL, NULL);
1342 
1343  fcinfo.arg[0] = arg1;
1344  fcinfo.argnull[0] = false;
1345 
1346  result = FunctionCallInvoke(&fcinfo);
1347 
1348  /* Check for null result, since caller is clearly not expecting one */
1349  if (fcinfo.isnull)
1350  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1351 
1352  return result;
1353 }
return result
Definition: formatting.c:1618
FmgrInfo * flinfo
Definition: fmgr.h:71
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:129
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:56
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
Datum FunctionCall2Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2 
)

Definition at line 1356 of file fmgr.c.

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

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

1357 {
1358  FunctionCallInfoData fcinfo;
1359  Datum result;
1360 
1361  InitFunctionCallInfoData(fcinfo, flinfo, 2, collation, NULL, NULL);
1362 
1363  fcinfo.arg[0] = arg1;
1364  fcinfo.arg[1] = arg2;
1365  fcinfo.argnull[0] = false;
1366  fcinfo.argnull[1] = false;
1367 
1368  result = FunctionCallInvoke(&fcinfo);
1369 
1370  /* Check for null result, since caller is clearly not expecting one */
1371  if (fcinfo.isnull)
1372  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1373 
1374  return result;
1375 }
return result
Definition: formatting.c:1618
FmgrInfo * flinfo
Definition: fmgr.h:71
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:129
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:56
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
Datum FunctionCall3Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3 
)

Definition at line 1378 of file fmgr.c.

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

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

1380 {
1381  FunctionCallInfoData fcinfo;
1382  Datum result;
1383 
1384  InitFunctionCallInfoData(fcinfo, flinfo, 3, collation, NULL, NULL);
1385 
1386  fcinfo.arg[0] = arg1;
1387  fcinfo.arg[1] = arg2;
1388  fcinfo.arg[2] = arg3;
1389  fcinfo.argnull[0] = false;
1390  fcinfo.argnull[1] = false;
1391  fcinfo.argnull[2] = false;
1392 
1393  result = FunctionCallInvoke(&fcinfo);
1394 
1395  /* Check for null result, since caller is clearly not expecting one */
1396  if (fcinfo.isnull)
1397  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1398 
1399  return result;
1400 }
return result
Definition: formatting.c:1618
FmgrInfo * flinfo
Definition: fmgr.h:71
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:129
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:56
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
Datum FunctionCall4Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4 
)

Definition at line 1403 of file fmgr.c.

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

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

1405 {
1406  FunctionCallInfoData fcinfo;
1407  Datum result;
1408 
1409  InitFunctionCallInfoData(fcinfo, flinfo, 4, collation, NULL, NULL);
1410 
1411  fcinfo.arg[0] = arg1;
1412  fcinfo.arg[1] = arg2;
1413  fcinfo.arg[2] = arg3;
1414  fcinfo.arg[3] = arg4;
1415  fcinfo.argnull[0] = false;
1416  fcinfo.argnull[1] = false;
1417  fcinfo.argnull[2] = false;
1418  fcinfo.argnull[3] = false;
1419 
1420  result = FunctionCallInvoke(&fcinfo);
1421 
1422  /* Check for null result, since caller is clearly not expecting one */
1423  if (fcinfo.isnull)
1424  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1425 
1426  return result;
1427 }
return result
Definition: formatting.c:1618
FmgrInfo * flinfo
Definition: fmgr.h:71
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:129
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:56
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
Datum FunctionCall5Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5 
)

Definition at line 1430 of file fmgr.c.

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

Referenced by gistindex_keytest(), and scalararraysel().

1432 {
1433  FunctionCallInfoData fcinfo;
1434  Datum result;
1435 
1436  InitFunctionCallInfoData(fcinfo, flinfo, 5, collation, NULL, NULL);
1437 
1438  fcinfo.arg[0] = arg1;
1439  fcinfo.arg[1] = arg2;
1440  fcinfo.arg[2] = arg3;
1441  fcinfo.arg[3] = arg4;
1442  fcinfo.arg[4] = arg5;
1443  fcinfo.argnull[0] = false;
1444  fcinfo.argnull[1] = false;
1445  fcinfo.argnull[2] = false;
1446  fcinfo.argnull[3] = false;
1447  fcinfo.argnull[4] = false;
1448 
1449  result = FunctionCallInvoke(&fcinfo);
1450 
1451  /* Check for null result, since caller is clearly not expecting one */
1452  if (fcinfo.isnull)
1453  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1454 
1455  return result;
1456 }
return result
Definition: formatting.c:1618
FmgrInfo * flinfo
Definition: fmgr.h:71
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:129
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:56
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
Datum FunctionCall6Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6 
)

Definition at line 1459 of file fmgr.c.

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

1462 {
1463  FunctionCallInfoData fcinfo;
1464  Datum result;
1465 
1466  InitFunctionCallInfoData(fcinfo, flinfo, 6, collation, NULL, NULL);
1467 
1468  fcinfo.arg[0] = arg1;
1469  fcinfo.arg[1] = arg2;
1470  fcinfo.arg[2] = arg3;
1471  fcinfo.arg[3] = arg4;
1472  fcinfo.arg[4] = arg5;
1473  fcinfo.arg[5] = arg6;
1474  fcinfo.argnull[0] = false;
1475  fcinfo.argnull[1] = false;
1476  fcinfo.argnull[2] = false;
1477  fcinfo.argnull[3] = false;
1478  fcinfo.argnull[4] = false;
1479  fcinfo.argnull[5] = false;
1480 
1481  result = FunctionCallInvoke(&fcinfo);
1482 
1483  /* Check for null result, since caller is clearly not expecting one */
1484  if (fcinfo.isnull)
1485  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1486 
1487  return result;
1488 }
return result
Definition: formatting.c:1618
FmgrInfo * flinfo
Definition: fmgr.h:71
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:129
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:56
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
Datum FunctionCall7Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7 
)

Definition at line 1491 of file fmgr.c.

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

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

1494 {
1495  FunctionCallInfoData fcinfo;
1496  Datum result;
1497 
1498  InitFunctionCallInfoData(fcinfo, flinfo, 7, collation, NULL, NULL);
1499 
1500  fcinfo.arg[0] = arg1;
1501  fcinfo.arg[1] = arg2;
1502  fcinfo.arg[2] = arg3;
1503  fcinfo.arg[3] = arg4;
1504  fcinfo.arg[4] = arg5;
1505  fcinfo.arg[5] = arg6;
1506  fcinfo.arg[6] = arg7;
1507  fcinfo.argnull[0] = false;
1508  fcinfo.argnull[1] = false;
1509  fcinfo.argnull[2] = false;
1510  fcinfo.argnull[3] = false;
1511  fcinfo.argnull[4] = false;
1512  fcinfo.argnull[5] = false;
1513  fcinfo.argnull[6] = false;
1514 
1515  result = FunctionCallInvoke(&fcinfo);
1516 
1517  /* Check for null result, since caller is clearly not expecting one */
1518  if (fcinfo.isnull)
1519  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1520 
1521  return result;
1522 }
return result
Definition: formatting.c:1618
FmgrInfo * flinfo
Definition: fmgr.h:71
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:129
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:56
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
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 1525 of file fmgr.c.

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

Referenced by directBoolConsistentFn().

1528 {
1529  FunctionCallInfoData fcinfo;
1530  Datum result;
1531 
1532  InitFunctionCallInfoData(fcinfo, flinfo, 8, collation, NULL, NULL);
1533 
1534  fcinfo.arg[0] = arg1;
1535  fcinfo.arg[1] = arg2;
1536  fcinfo.arg[2] = arg3;
1537  fcinfo.arg[3] = arg4;
1538  fcinfo.arg[4] = arg5;
1539  fcinfo.arg[5] = arg6;
1540  fcinfo.arg[6] = arg7;
1541  fcinfo.arg[7] = arg8;
1542  fcinfo.argnull[0] = false;
1543  fcinfo.argnull[1] = false;
1544  fcinfo.argnull[2] = false;
1545  fcinfo.argnull[3] = false;
1546  fcinfo.argnull[4] = false;
1547  fcinfo.argnull[5] = false;
1548  fcinfo.argnull[6] = false;
1549  fcinfo.argnull[7] = false;
1550 
1551  result = FunctionCallInvoke(&fcinfo);
1552 
1553  /* Check for null result, since caller is clearly not expecting one */
1554  if (fcinfo.isnull)
1555  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1556 
1557  return result;
1558 }
return result
Definition: formatting.c:1618
FmgrInfo * flinfo
Definition: fmgr.h:71
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:129
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:56
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
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 1561 of file fmgr.c.

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

1565 {
1566  FunctionCallInfoData fcinfo;
1567  Datum result;
1568 
1569  InitFunctionCallInfoData(fcinfo, flinfo, 9, collation, NULL, NULL);
1570 
1571  fcinfo.arg[0] = arg1;
1572  fcinfo.arg[1] = arg2;
1573  fcinfo.arg[2] = arg3;
1574  fcinfo.arg[3] = arg4;
1575  fcinfo.arg[4] = arg5;
1576  fcinfo.arg[5] = arg6;
1577  fcinfo.arg[6] = arg7;
1578  fcinfo.arg[7] = arg8;
1579  fcinfo.arg[8] = arg9;
1580  fcinfo.argnull[0] = false;
1581  fcinfo.argnull[1] = false;
1582  fcinfo.argnull[2] = false;
1583  fcinfo.argnull[3] = false;
1584  fcinfo.argnull[4] = false;
1585  fcinfo.argnull[5] = false;
1586  fcinfo.argnull[6] = false;
1587  fcinfo.argnull[7] = false;
1588  fcinfo.argnull[8] = false;
1589 
1590  result = FunctionCallInvoke(&fcinfo);
1591 
1592  /* Check for null result, since caller is clearly not expecting one */
1593  if (fcinfo.isnull)
1594  elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
1595 
1596  return result;
1597 }
return result
Definition: formatting.c:1618
FmgrInfo * flinfo
Definition: fmgr.h:71
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:129
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:56
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
bool get_call_expr_arg_stable ( Node expr,
int  argnum 
)

Definition at line 2360 of file fmgr.c.

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

Referenced by get_fn_expr_arg_stable().

2361 {
2362  List *args;
2363  Node *arg;
2364 
2365  if (expr == NULL)
2366  return false;
2367 
2368  if (IsA(expr, FuncExpr))
2369  args = ((FuncExpr *) expr)->args;
2370  else if (IsA(expr, OpExpr))
2371  args = ((OpExpr *) expr)->args;
2372  else if (IsA(expr, DistinctExpr))
2373  args = ((DistinctExpr *) expr)->args;
2374  else if (IsA(expr, ScalarArrayOpExpr))
2375  args = ((ScalarArrayOpExpr *) expr)->args;
2376  else if (IsA(expr, ArrayCoerceExpr))
2377  args = list_make1(((ArrayCoerceExpr *) expr)->arg);
2378  else if (IsA(expr, NullIfExpr))
2379  args = ((NullIfExpr *) expr)->args;
2380  else if (IsA(expr, WindowFunc))
2381  args = ((WindowFunc *) expr)->args;
2382  else
2383  return false;
2384 
2385  if (argnum < 0 || argnum >= list_length(args))
2386  return false;
2387 
2388  arg = (Node *) list_nth(args, argnum);
2389 
2390  /*
2391  * Either a true Const or an external Param will have a value that doesn't
2392  * change during the execution of the query. In future we might want to
2393  * consider other cases too, e.g. now().
2394  */
2395  if (IsA(arg, Const))
2396  return true;
2397  if (IsA(arg, Param) &&
2398  ((Param *) arg)->paramkind == PARAM_EXTERN)
2399  return true;
2400 
2401  return false;
2402 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:571
Definition: nodes.h:520
#define list_make1(x1)
Definition: pg_list.h:133
void * list_nth(const List *list, int n)
Definition: list.c:410
#define NULL
Definition: c.h:229
static int list_length(const List *l)
Definition: pg_list.h:89
void * arg
Definition: pg_list.h:45
Oid get_call_expr_argtype ( Node expr,
int  argnum 
)

Definition at line 2289 of file fmgr.c.

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

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

2290 {
2291  List *args;
2292  Oid argtype;
2293 
2294  if (expr == NULL)
2295  return InvalidOid;
2296 
2297  if (IsA(expr, FuncExpr))
2298  args = ((FuncExpr *) expr)->args;
2299  else if (IsA(expr, OpExpr))
2300  args = ((OpExpr *) expr)->args;
2301  else if (IsA(expr, DistinctExpr))
2302  args = ((DistinctExpr *) expr)->args;
2303  else if (IsA(expr, ScalarArrayOpExpr))
2304  args = ((ScalarArrayOpExpr *) expr)->args;
2305  else if (IsA(expr, ArrayCoerceExpr))
2306  args = list_make1(((ArrayCoerceExpr *) expr)->arg);
2307  else if (IsA(expr, NullIfExpr))
2308  args = ((NullIfExpr *) expr)->args;
2309  else if (IsA(expr, WindowFunc))
2310  args = ((WindowFunc *) expr)->args;
2311  else
2312  return InvalidOid;
2313 
2314  if (argnum < 0 || argnum >= list_length(args))
2315  return InvalidOid;
2316 
2317  argtype = exprType((Node *) list_nth(args, argnum));
2318 
2319  /*
2320  * special hack for ScalarArrayOpExpr and ArrayCoerceExpr: what the
2321  * underlying function will actually get passed is the element type of the
2322  * array.
2323  */
2324  if (IsA(expr, ScalarArrayOpExpr) &&
2325  argnum == 1)
2326  argtype = get_base_element_type(argtype);
2327  else if (IsA(expr, ArrayCoerceExpr) &&
2328  argnum == 0)
2329  argtype = get_base_element_type(argtype);
2330 
2331  return argtype;
2332 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:571
Definition: nodes.h:520
unsigned int Oid
Definition: postgres_ext.h:31
#define list_make1(x1)
Definition: pg_list.h:133
void * list_nth(const List *list, int n)
Definition: list.c:410
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:229
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:2525
void * arg
Definition: pg_list.h:45
bool get_fn_expr_arg_stable ( FmgrInfo flinfo,
int  argnum 
)

Definition at line 2341 of file fmgr.c.

References FmgrInfo::fn_expr, and get_call_expr_arg_stable().

Referenced by jsonb_build_array(), jsonb_build_object(), leadlag_common(), and window_nth_value().

2342 {
2343  /*
2344  * can't return anything useful if we have no FmgrInfo or if its fn_expr
2345  * node has not been initialized
2346  */
2347  if (!flinfo || !flinfo->fn_expr)
2348  return false;
2349 
2350  return get_call_expr_arg_stable(flinfo->fn_expr, argnum);
2351 }
bool get_call_expr_arg_stable(Node *expr, int argnum)
Definition: fmgr.c:2360
fmNodePtr fn_expr
Definition: fmgr.h:63
Oid get_fn_expr_rettype ( FmgrInfo flinfo)

Definition at line 2248 of file fmgr.c.

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

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

2249 {
2250  Node *expr;
2251 
2252  /*
2253  * can't return anything useful if we have no FmgrInfo or if its fn_expr
2254  * node has not been initialized
2255  */
2256  if (!flinfo || !flinfo->fn_expr)
2257  return InvalidOid;
2258 
2259  expr = flinfo->fn_expr;
2260 
2261  return exprType(expr);
2262 }
Definition: nodes.h:520
#define InvalidOid
Definition: postgres_ext.h:36
fmNodePtr fn_expr
Definition: fmgr.h:63
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
bool get_fn_expr_variadic ( FmgrInfo flinfo)

Definition at line 2412 of file fmgr.c.

References FmgrInfo::fn_expr, and IsA.

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

2413 {
2414  Node *expr;
2415 
2416  /*
2417  * can't return anything useful if we have no FmgrInfo or if its fn_expr
2418  * node has not been initialized
2419  */
2420  if (!flinfo || !flinfo->fn_expr)
2421  return false;
2422 
2423  expr = flinfo->fn_expr;
2424 
2425  if (IsA(expr, FuncExpr))
2426  return ((FuncExpr *) expr)->funcvariadic;
2427  else
2428  return false;
2429 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:571
Definition: nodes.h:520
fmNodePtr fn_expr
Definition: fmgr.h:63
Datum InputFunctionCall ( FmgrInfo flinfo,
char *  str,
Oid  typioparam,
int32  typmod 
)

Definition at line 1932 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, NULL, ObjectIdGetDatum, and result.

Referenced by BuildTupleFromCStrings(), domain_in(), ExecEvalCoerceViaIO(), hstore_populate_record(), make_row_from_rec_and_jsonb(), make_tuple_from_result_row(), NextCopyFrom(), OidInputFunctionCall(), plperl_sv_to_datum(), pltcl_func_handler(), pltcl_returnnext(), pltcl_SPI_execute_plan(), PLy_cursor_plan(), PLy_exec_function(), PLy_modify_tuple(), PLy_spi_execute_plan(), PLyObject_ToDatum(), populate_record_worker(), populate_recordset_object_end(), range_in(), ReadArrayStr(), record_in(), and XmlTableGetValue().

1933 {
1934  FunctionCallInfoData fcinfo;
1935  Datum result;
1936 
1937  if (str == NULL && flinfo->fn_strict)
1938  return (Datum) 0; /* just return null result */
1939 
1940  InitFunctionCallInfoData(fcinfo, flinfo, 3, InvalidOid, NULL, NULL);
1941 
1942  fcinfo.arg[0] = CStringGetDatum(str);
1943  fcinfo.arg[1] = ObjectIdGetDatum(typioparam);
1944  fcinfo.arg[2] = Int32GetDatum(typmod);
1945  fcinfo.argnull[0] = (str == NULL);
1946  fcinfo.argnull[1] = false;
1947  fcinfo.argnull[2] = false;
1948 
1949  result = FunctionCallInvoke(&fcinfo);
1950 
1951  /* Should get null result if and only if str is NULL */
1952  if (str == NULL)
1953  {
1954  if (!fcinfo.isnull)
1955  elog(ERROR, "input function %u returned non-NULL",
1956  fcinfo.flinfo->fn_oid);
1957  }
1958  else
1959  {
1960  if (fcinfo.isnull)
1961  elog(ERROR, "input function %u returned NULL",
1962  fcinfo.flinfo->fn_oid);
1963  }
1964 
1965  return result;
1966 }
return result
Definition: formatting.c:1618
FmgrInfo * flinfo
Definition: fmgr.h:71
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
bool fn_strict
Definition: fmgr.h:58
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:129
#define CStringGetDatum(X)
Definition: postgres.h:584
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
#define InvalidOid
Definition: postgres_ext.h:36
Oid fn_oid
Definition: fmgr.h:56
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define Int32GetDatum(X)
Definition: postgres.h:485
#define elog
Definition: elog.h:219
static CFuncHashTabEntry * lookup_C_func ( HeapTuple  procedureTuple)
static

Definition at line 503 of file fmgr.c.

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

Referenced by fmgr_info_C_lang().

504 {
505  Oid fn_oid = HeapTupleGetOid(procedureTuple);
506  CFuncHashTabEntry *entry;
507 
508  if (CFuncHash == NULL)
509  return NULL; /* no table yet */
510  entry = (CFuncHashTabEntry *)
512  &fn_oid,
513  HASH_FIND,
514  NULL);
515  if (entry == NULL)
516  return NULL; /* no such entry */
517  if (entry->fn_xmin == HeapTupleHeaderGetRawXmin(procedureTuple->t_data) &&
518  ItemPointerEquals(&entry->fn_tid, &procedureTuple->t_self))
519  return entry; /* OK */
520  return NULL; /* entry is out of date */
521 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:885
unsigned int Oid
Definition: postgres_ext.h:31
HeapTupleHeader t_data
Definition: htup.h:67
static HTAB * CFuncHash
Definition: fmgr.c:83
ItemPointerData t_self
Definition: htup.h:65
#define NULL
Definition: c.h:229
#define HeapTupleHeaderGetRawXmin(tup)
Definition: htup_details.h:302
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
Definition: itemptr.c:29
TransactionId fn_xmin
Definition: fmgr.c:77
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:695
ItemPointerData fn_tid
Definition: fmgr.c:78
Datum OidFunctionCall0Coll ( Oid  functionId,
Oid  collation 
)

Definition at line 1608 of file fmgr.c.

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

1609 {
1610  FmgrInfo flinfo;
1611  FunctionCallInfoData fcinfo;
1612  Datum result;
1613 
1614  fmgr_info(functionId, &flinfo);
1615 
1616  InitFunctionCallInfoData(fcinfo, &flinfo, 0, collation, NULL, NULL);
1617 
1618  result = FunctionCallInvoke(&fcinfo);
1619 
1620  /* Check for null result, since caller is clearly not expecting one */
1621  if (fcinfo.isnull)
1622  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1623 
1624  return result;
1625 }
Definition: fmgr.h:53
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:159
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:129
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:56
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
Datum OidFunctionCall1Coll ( Oid  functionId,
Oid  collation,
Datum  arg1 
)

Definition at line 1628 of file fmgr.c.

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

Referenced by _hash_datum2hashkey_type().

1629 {
1630  FmgrInfo flinfo;
1631  FunctionCallInfoData fcinfo;
1632  Datum result;
1633 
1634  fmgr_info(functionId, &flinfo);
1635 
1636  InitFunctionCallInfoData(fcinfo, &flinfo, 1, collation, NULL, NULL);
1637 
1638  fcinfo.arg[0] = arg1;
1639  fcinfo.argnull[0] = false;
1640 
1641  result = FunctionCallInvoke(&fcinfo);
1642 
1643  /* Check for null result, since caller is clearly not expecting one */
1644  if (fcinfo.isnull)
1645  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1646 
1647  return result;
1648 }
Definition: fmgr.h:53
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:159
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:129
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:56
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
Datum OidFunctionCall2Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2 
)

Definition at line 1651 of file fmgr.c.

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

Referenced by _bt_compare_scankey_args(), and index_recheck_constraint().

1652 {
1653  FmgrInfo flinfo;
1654  FunctionCallInfoData fcinfo;
1655  Datum result;
1656 
1657  fmgr_info(functionId, &flinfo);
1658 
1659  InitFunctionCallInfoData(fcinfo, &flinfo, 2, collation, NULL, NULL);
1660 
1661  fcinfo.arg[0] = arg1;
1662  fcinfo.arg[1] = arg2;
1663  fcinfo.argnull[0] = false;
1664  fcinfo.argnull[1] = false;
1665 
1666  result = FunctionCallInvoke(&fcinfo);
1667 
1668  /* Check for null result, since caller is clearly not expecting one */
1669  if (fcinfo.isnull)
1670  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1671 
1672  return result;
1673 }
Definition: fmgr.h:53
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:159
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:129
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:56
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
Datum OidFunctionCall3Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3 
)

Definition at line 1676 of file fmgr.c.

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

1678 {
1679  FmgrInfo flinfo;
1680  FunctionCallInfoData fcinfo;
1681  Datum result;
1682 
1683  fmgr_info(functionId, &flinfo);
1684 
1685  InitFunctionCallInfoData(fcinfo, &flinfo, 3, collation, NULL, NULL);
1686 
1687  fcinfo.arg[0] = arg1;
1688  fcinfo.arg[1] = arg2;
1689  fcinfo.arg[2] = arg3;
1690  fcinfo.argnull[0] = false;
1691  fcinfo.argnull[1] = false;
1692  fcinfo.argnull[2] = false;
1693 
1694  result = FunctionCallInvoke(&fcinfo);
1695 
1696  /* Check for null result, since caller is clearly not expecting one */
1697  if (fcinfo.isnull)
1698  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1699 
1700  return result;
1701 }
Definition: fmgr.h:53
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:159
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:129
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:56
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
Datum OidFunctionCall4Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4 
)

Definition at line 1704 of file fmgr.c.

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

Referenced by restriction_selectivity().

1706 {
1707  FmgrInfo flinfo;
1708  FunctionCallInfoData fcinfo;
1709  Datum result;
1710 
1711  fmgr_info(functionId, &flinfo);
1712 
1713  InitFunctionCallInfoData(fcinfo, &flinfo, 4, collation, NULL, NULL);
1714 
1715  fcinfo.arg[0] = arg1;
1716  fcinfo.arg[1] = arg2;
1717  fcinfo.arg[2] = arg3;
1718  fcinfo.arg[3] = arg4;
1719  fcinfo.argnull[0] = false;
1720  fcinfo.argnull[1] = false;
1721  fcinfo.argnull[2] = false;
1722  fcinfo.argnull[3] = false;
1723 
1724  result = FunctionCallInvoke(&fcinfo);
1725 
1726  /* Check for null result, since caller is clearly not expecting one */
1727  if (fcinfo.isnull)
1728  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1729 
1730  return result;
1731 }
Definition: fmgr.h:53
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:159
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:129
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:56
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
Datum OidFunctionCall5Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5 
)

Definition at line 1734 of file fmgr.c.

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

Referenced by join_selectivity().

1736 {
1737  FmgrInfo flinfo;
1738  FunctionCallInfoData fcinfo;
1739  Datum result;
1740 
1741  fmgr_info(functionId, &flinfo);
1742 
1743  InitFunctionCallInfoData(fcinfo, &flinfo, 5, collation, NULL, NULL);
1744 
1745  fcinfo.arg[0] = arg1;
1746  fcinfo.arg[1] = arg2;
1747  fcinfo.arg[2] = arg3;
1748  fcinfo.arg[3] = arg4;
1749  fcinfo.arg[4] = arg5;
1750  fcinfo.argnull[0] = false;
1751  fcinfo.argnull[1] = false;
1752  fcinfo.argnull[2] = false;
1753  fcinfo.argnull[3] = false;
1754  fcinfo.argnull[4] = false;
1755 
1756  result = FunctionCallInvoke(&fcinfo);
1757 
1758  /* Check for null result, since caller is clearly not expecting one */
1759  if (fcinfo.isnull)
1760  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1761 
1762  return result;
1763 }
Definition: fmgr.h:53
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:159
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:129
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:56
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
Datum OidFunctionCall6Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6 
)

Definition at line 1766 of file fmgr.c.

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

1769 {
1770  FmgrInfo flinfo;
1771  FunctionCallInfoData fcinfo;
1772  Datum result;
1773 
1774  fmgr_info(functionId, &flinfo);
1775 
1776  InitFunctionCallInfoData(fcinfo, &flinfo, 6, collation, NULL, NULL);
1777 
1778  fcinfo.arg[0] = arg1;
1779  fcinfo.arg[1] = arg2;
1780  fcinfo.arg[2] = arg3;
1781  fcinfo.arg[3] = arg4;
1782  fcinfo.arg[4] = arg5;
1783  fcinfo.arg[5] = arg6;
1784  fcinfo.argnull[0] = false;
1785  fcinfo.argnull[1] = false;
1786  fcinfo.argnull[2] = false;
1787  fcinfo.argnull[3] = false;
1788  fcinfo.argnull[4] = false;
1789  fcinfo.argnull[5] = false;
1790 
1791  result = FunctionCallInvoke(&fcinfo);
1792 
1793  /* Check for null result, since caller is clearly not expecting one */
1794  if (fcinfo.isnull)
1795  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1796 
1797  return result;
1798 }
Definition: fmgr.h:53
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:159
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:129
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:56
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
Datum OidFunctionCall7Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7 
)

Definition at line 1801 of file fmgr.c.

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

Referenced by gincost_pattern().

1804 {
1805  FmgrInfo flinfo;
1806  FunctionCallInfoData fcinfo;
1807  Datum result;
1808 
1809  fmgr_info(functionId, &flinfo);
1810 
1811  InitFunctionCallInfoData(fcinfo, &flinfo, 7, collation, NULL, NULL);
1812 
1813  fcinfo.arg[0] = arg1;
1814  fcinfo.arg[1] = arg2;
1815  fcinfo.arg[2] = arg3;
1816  fcinfo.arg[3] = arg4;
1817  fcinfo.arg[4] = arg5;
1818  fcinfo.arg[5] = arg6;
1819  fcinfo.arg[6] = arg7;
1820  fcinfo.argnull[0] = false;
1821  fcinfo.argnull[1] = false;
1822  fcinfo.argnull[2] = false;
1823  fcinfo.argnull[3] = false;
1824  fcinfo.argnull[4] = false;
1825  fcinfo.argnull[5] = false;
1826  fcinfo.argnull[6] = false;
1827 
1828  result = FunctionCallInvoke(&fcinfo);
1829 
1830  /* Check for null result, since caller is clearly not expecting one */
1831  if (fcinfo.isnull)
1832  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1833 
1834  return result;
1835 }
Definition: fmgr.h:53
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:159
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:129
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:56
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
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 1838 of file fmgr.c.

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

1841 {
1842  FmgrInfo flinfo;
1843  FunctionCallInfoData fcinfo;
1844  Datum result;
1845 
1846  fmgr_info(functionId, &flinfo);
1847 
1848  InitFunctionCallInfoData(fcinfo, &flinfo, 8, collation, NULL, NULL);
1849 
1850  fcinfo.arg[0] = arg1;
1851  fcinfo.arg[1] = arg2;
1852  fcinfo.arg[2] = arg3;
1853  fcinfo.arg[3] = arg4;
1854  fcinfo.arg[4] = arg5;
1855  fcinfo.arg[5] = arg6;
1856  fcinfo.arg[6] = arg7;
1857  fcinfo.arg[7] = arg8;
1858  fcinfo.argnull[0] = false;
1859  fcinfo.argnull[1] = false;
1860  fcinfo.argnull[2] = false;
1861  fcinfo.argnull[3] = false;
1862  fcinfo.argnull[4] = false;
1863  fcinfo.argnull[5] = false;
1864  fcinfo.argnull[6] = false;
1865  fcinfo.argnull[7] = false;
1866 
1867  result = FunctionCallInvoke(&fcinfo);
1868 
1869  /* Check for null result, since caller is clearly not expecting one */
1870  if (fcinfo.isnull)
1871  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1872 
1873  return result;
1874 }
Definition: fmgr.h:53
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:159
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:129
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:56
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
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 1877 of file fmgr.c.

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

1881 {
1882  FmgrInfo flinfo;
1883  FunctionCallInfoData fcinfo;
1884  Datum result;
1885 
1886  fmgr_info(functionId, &flinfo);
1887 
1888  InitFunctionCallInfoData(fcinfo, &flinfo, 9, collation, NULL, NULL);
1889 
1890  fcinfo.arg[0] = arg1;
1891  fcinfo.arg[1] = arg2;
1892  fcinfo.arg[2] = arg3;
1893  fcinfo.arg[3] = arg4;
1894  fcinfo.arg[4] = arg5;
1895  fcinfo.arg[5] = arg6;
1896  fcinfo.arg[6] = arg7;
1897  fcinfo.arg[7] = arg8;
1898  fcinfo.arg[8] = arg9;
1899  fcinfo.argnull[0] = false;
1900  fcinfo.argnull[1] = false;
1901  fcinfo.argnull[2] = false;
1902  fcinfo.argnull[3] = false;
1903  fcinfo.argnull[4] = false;
1904  fcinfo.argnull[5] = false;
1905  fcinfo.argnull[6] = false;
1906  fcinfo.argnull[7] = false;
1907  fcinfo.argnull[8] = false;
1908 
1909  result = FunctionCallInvoke(&fcinfo);
1910 
1911  /* Check for null result, since caller is clearly not expecting one */
1912  if (fcinfo.isnull)
1913  elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
1914 
1915  return result;
1916 }
Definition: fmgr.h:53
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:159
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:129
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
Oid fn_oid
Definition: fmgr.h:56
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define elog
Definition: elog.h:219
Datum OidInputFunctionCall ( Oid  functionId,
char *  str,
Oid  typioparam,
int32  typmod 
)

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

2048 {
2049  FmgrInfo flinfo;
2050 
2051  fmgr_info(functionId, &flinfo);
2052  return InputFunctionCall(&flinfo, str, typioparam, typmod);
2053 }
Definition: fmgr.h:53
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:159
Datum InputFunctionCall(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
Definition: fmgr.c:1932
Datum OidReceiveFunctionCall ( Oid  functionId,
StringInfo  buf,
Oid  typioparam,
int32  typmod 
)

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

2067 {
2068  FmgrInfo flinfo;
2069 
2070  fmgr_info(functionId, &flinfo);
2071  return ReceiveFunctionCall(&flinfo, buf, typioparam, typmod);
2072 }
Definition: fmgr.h:53
Datum ReceiveFunctionCall(FmgrInfo *flinfo, StringInfo buf, Oid typioparam, int32 typmod)
Definition: fmgr.c:1990
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:159
bytea* OidSendFunctionCall ( Oid  functionId,
Datum  val 
)

Definition at line 2075 of file fmgr.c.

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

Referenced by SendFunctionResult().

2076 {
2077  FmgrInfo flinfo;
2078 
2079  fmgr_info(functionId, &flinfo);
2080  return SendFunctionCall(&flinfo, val);
2081 }
Definition: fmgr.h:53
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:159
bytea * SendFunctionCall(FmgrInfo *flinfo, Datum val)
Definition: fmgr.c:2037
long val
Definition: informix.c:689
struct varlena* pg_detoast_datum ( struct varlena datum)

Definition at line 2192 of file fmgr.c.

References heap_tuple_untoast_attr(), and VARATT_IS_EXTENDED.

2193 {
2194  if (VARATT_IS_EXTENDED(datum))
2195  return heap_tuple_untoast_attr(datum);
2196  else
2197  return datum;
2198 }
struct varlena * heap_tuple_untoast_attr(struct varlena *attr)
Definition: tuptoaster.c:172
#define VARATT_IS_EXTENDED(PTR)
Definition: postgres.h:326
struct varlena* pg_detoast_datum_copy ( struct varlena datum)

Definition at line 2201 of file fmgr.c.

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

2202 {
2203  if (VARATT_IS_EXTENDED(datum))
2204  return heap_tuple_untoast_attr(datum);
2205  else
2206  {
2207  /* Make a modifiable copy of the varlena object */
2208  Size len = VARSIZE(datum);
2209  struct varlena *result = (struct varlena *) palloc(len);
2210 
2211  memcpy(result, datum, len);
2212  return result;
2213  }
2214 }
#define VARSIZE(PTR)
Definition: postgres.h:304
return result
Definition: formatting.c:1618
struct varlena * heap_tuple_untoast_attr(struct varlena *attr)
Definition: tuptoaster.c:172
size_t Size
Definition: c.h:356
#define VARATT_IS_EXTENDED(PTR)
Definition: postgres.h:326
void * palloc(Size size)
Definition: mcxt.c:849
Definition: c.h:439
struct varlena* pg_detoast_datum_packed ( struct varlena datum)

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

2225 {
2226  if (VARATT_IS_COMPRESSED(datum) || VARATT_IS_EXTERNAL(datum))
2227  return heap_tuple_untoast_attr(datum);
2228  else
2229  return datum;
2230 }
#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
struct varlena* pg_detoast_datum_slice ( struct varlena datum,
int32  first,
int32  count 
)

Definition at line 2217 of file fmgr.c.

References heap_tuple_untoast_attr_slice().

2218 {
2219  /* Only get the specified portion from the toast rel */
2220  return heap_tuple_untoast_attr_slice(datum, first, count);
2221 }
struct varlena * heap_tuple_untoast_attr_slice(struct varlena *attr, int32 sliceoffset, int32 slicelength)
Definition: tuptoaster.c:258
Datum ReceiveFunctionCall ( FmgrInfo flinfo,
StringInfo  buf,
Oid  typioparam,
int32  typmod 
)

Definition at line 1990 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, NULL, ObjectIdGetDatum, PointerGetDatum, and result.

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

1992 {
1993  FunctionCallInfoData fcinfo;
1994  Datum result;
1995 
1996  if (buf == NULL && flinfo->fn_strict)
1997  return (Datum) 0; /* just return null result */
1998 
1999  InitFunctionCallInfoData(fcinfo, flinfo, 3, InvalidOid, NULL, NULL);
2000 
2001  fcinfo.arg[0] = PointerGetDatum(buf);
2002  fcinfo.arg[1] = ObjectIdGetDatum(typioparam);
2003  fcinfo.arg[2] = Int32GetDatum(typmod);
2004  fcinfo.argnull[0] = (buf == NULL);
2005  fcinfo.argnull[1] = false;
2006  fcinfo.argnull[2] = false;
2007 
2008  result = FunctionCallInvoke(&fcinfo);
2009 
2010  /* Should get null result if and only if buf is NULL */
2011  if (buf == NULL)
2012  {
2013  if (!fcinfo.isnull)
2014  elog(ERROR, "receive function %u returned non-NULL",
2015  fcinfo.flinfo->fn_oid);
2016  }
2017  else
2018  {
2019  if (fcinfo.isnull)
2020  elog(ERROR, "receive function %u returned NULL",
2021  fcinfo.flinfo->fn_oid);
2022  }
2023 
2024  return result;
2025 }
#define PointerGetDatum(X)
Definition: postgres.h:562
return result
Definition: formatting.c:1618
FmgrInfo * flinfo
Definition: fmgr.h:71
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
bool fn_strict
Definition: fmgr.h:58
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:129
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:78
uintptr_t Datum
Definition: postgres.h:372
#define InvalidOid
Definition: postgres_ext.h:36
Oid fn_oid
Definition: fmgr.h:56
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:77
#define NULL
Definition: c.h:229
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:112
#define Int32GetDatum(X)
Definition: postgres.h:485
#define elog
Definition: elog.h:219
static void record_C_func ( HeapTuple  procedureTuple,
PGFunction  user_fn,
const Pg_finfo_record inforec 
)
static

Definition at line 527 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, NULL, HeapTupleData::t_data, HeapTupleData::t_self, and CFuncHashTabEntry::user_fn.

Referenced by fmgr_info_C_lang().

529 {
530  Oid fn_oid = HeapTupleGetOid(procedureTuple);
531  CFuncHashTabEntry *entry;
532  bool found;
533 
534  /* Create the hash table if it doesn't exist yet */
535  if (CFuncHash == NULL)
536  {
537  HASHCTL hash_ctl;
538 
539  MemSet(&hash_ctl, 0, sizeof(hash_ctl));
540  hash_ctl.keysize = sizeof(Oid);
541  hash_ctl.entrysize = sizeof(CFuncHashTabEntry);
542  CFuncHash = hash_create("CFuncHash",
543  100,
544  &hash_ctl,
546  }
547 
548  entry = (CFuncHashTabEntry *)
550  &fn_oid,
551  HASH_ENTER,
552  &found);
553  /* OID is already filled in */
554  entry->fn_xmin = HeapTupleHeaderGetRawXmin(procedureTuple->t_data);
555  entry->fn_tid = procedureTuple->t_self;
556  entry->user_fn = user_fn;
557  entry->inforec = inforec;
558 }
#define HASH_ELEM
Definition: hsearch.h:87
const Pg_finfo_record * inforec
Definition: fmgr.c:80
Size entrysize
Definition: hsearch.h:73
#define MemSet(start, val, len)
Definition: c.h:857
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:885
unsigned int Oid
Definition: postgres_ext.h:31
HeapTupleHeader t_data
Definition: htup.h:67
static HTAB * CFuncHash
Definition: fmgr.c:83
ItemPointerData t_self
Definition: htup.h:65
PGFunction user_fn
Definition: fmgr.c:79
#define HASH_BLOBS
Definition: hsearch.h:88
HTAB * hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
Definition: dynahash.c:301
Size keysize
Definition: hsearch.h:72
#define NULL
Definition: c.h:229
#define HeapTupleHeaderGetRawXmin(tup)
Definition: htup_details.h:302
TransactionId fn_xmin
Definition: fmgr.c:77
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:695
ItemPointerData fn_tid
Definition: fmgr.c:78
bytea* SendFunctionCall ( FmgrInfo flinfo,
Datum  val 
)

Definition at line 2037 of file fmgr.c.

References DatumGetByteaP, and FunctionCall1.

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

2038 {
2039  return DatumGetByteaP(FunctionCall1(flinfo, val));
2040 }
#define DatumGetByteaP(X)
Definition: fmgr.h:287
#define FunctionCall1(flinfo, arg1)
Definition: fmgr.h:594
long val
Definition: informix.c:689

Variable Documentation

HTAB* CFuncHash = NULL
static

Definition at line 83 of file fmgr.c.

Definition at line 37 of file fmgr.c.

Referenced by fmgr_security_definer(), and sepgsql_init_client_label().

Definition at line 36 of file fmgr.c.

Referenced by sepgsql_init_client_label().