Header And Logo

PostgreSQL
| The world's most advanced open source database.

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 "executor/spi.h"
#include "lib/stringinfo.h"
#include "miscadmin.h"
#include "nodes/nodeFuncs.h"
#include "pgstat.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 DirectFunctionCall1 (PGFunction func, Datum arg1)
Datum DirectFunctionCall2 (PGFunction func, Datum arg1, Datum arg2)
Datum DirectFunctionCall3 (PGFunction func, Datum arg1, Datum arg2, Datum arg3)
Datum DirectFunctionCall4 (PGFunction func, Datum arg1, Datum arg2, Datum arg3, Datum arg4)
Datum DirectFunctionCall5 (PGFunction func, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5)
Datum DirectFunctionCall6 (PGFunction func, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6)
Datum DirectFunctionCall7 (PGFunction func, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7)
Datum DirectFunctionCall8 (PGFunction func, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8)
Datum DirectFunctionCall9 (PGFunction func, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8, Datum arg9)
Datum FunctionCall1 (FmgrInfo *flinfo, Datum arg1)
Datum FunctionCall2 (FmgrInfo *flinfo, Datum arg1, Datum arg2)
Datum FunctionCall3 (FmgrInfo *flinfo, Datum arg1, Datum arg2, Datum arg3)
Datum FunctionCall4 (FmgrInfo *flinfo, Datum arg1, Datum arg2, Datum arg3, Datum arg4)
Datum FunctionCall5 (FmgrInfo *flinfo, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5)
Datum FunctionCall6 (FmgrInfo *flinfo, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6)
Datum FunctionCall7 (FmgrInfo *flinfo, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7)
Datum FunctionCall8 (FmgrInfo *flinfo, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8)
Datum FunctionCall9 (FmgrInfo *flinfo, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8, Datum arg9)
Datum OidFunctionCall1 (Oid functionId, Datum arg1)
Datum OidFunctionCall2 (Oid functionId, Datum arg1, Datum arg2)
Datum OidFunctionCall3 (Oid functionId, Datum arg1, Datum arg2, Datum arg3)
Datum OidFunctionCall4 (Oid functionId, Datum arg1, Datum arg2, Datum arg3, Datum arg4)
Datum OidFunctionCall5 (Oid functionId, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5)
Datum OidFunctionCall6 (Oid functionId, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6)
Datum OidFunctionCall7 (Oid functionId, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7)
Datum OidFunctionCall8 (Oid functionId, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8)
Datum OidFunctionCall9 (Oid functionId, 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)

Variables

static HTABCFuncHash = NULL


Typedef Documentation

typedef char*(* func_ptr)()

Definition at line 52 of file fmgr.c.


Function Documentation

void clear_external_function_hash ( void *  filehandle  ) 

Definition at line 558 of file fmgr.c.

References hash_destroy(), and NULL.

Referenced by internal_unload_library().

00559 {
00560     if (CFuncHash)
00561         hash_destroy(CFuncHash);
00562     CFuncHash = NULL;
00563 }

Datum DirectFunctionCall1 ( PGFunction  func,
Datum  arg1 
)

Definition at line 998 of file fmgr.c.

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

Referenced by assign_random_seed(), autoinc(), cash_numeric(), CatalogCacheComputeHashValue(), convert_function_name(), convert_numeric_to_scalar(), convert_timevalue_to_scalar(), CopyFrom(), CopyOneRowTo(), createdb(), CreateForeignDataWrapper(), CreateForeignServer(), CreateRole(), CreateTableSpace(), CreateTrigger(), current_schema(), current_schemas(), current_user(), defGetInt64(), do_numeric_accum(), do_numeric_avg_accum(), flatten_set_variable_args(), funny_dup17(), gbt_bpchar_compress(), gbt_bpchar_consistent(), gbt_numeric_penalty(), Generic_Text_IC_like(), getdatabaseencoding(), inet_client_port(), inet_server_port(), int2_accum(), int4_accum(), int4_to_char(), int8_accum(), int8_avg(), int8_avg_accum(), int8_sum(), int8_to_char(), interval_hash(), lo_manage(), ltree_addtext(), ltree_textadd(), make_greater_string(), nameiclike(), nameicnlike(), network_scan_first(), network_scan_last(), numeric_cash(), numeric_float4(), numeric_float8(), numeric_to_char(), numeric_to_double_no_overflow(), parsetinterval(), patternsel(), pg_client_encoding(), pg_convert_from(), pg_convert_to(), PG_encoding_to_char(), pg_stat_get_activity(), pg_stat_get_backend_client_addr(), pg_stat_get_backend_client_port(), pgrowlocks(), plperl_trigger_build_args(), plpgsql_exec_trigger(), pltcl_trigger_handler(), PLy_trigger_build_args(), PLyFloat_FromNumeric(), poly2path(), poly_center(), prefix_quals(), quote_ident_cstr(), quote_literal_cstr(), quote_nullable(), regclassin(), regconfigin(), regdictionaryin(), regoperatorin(), regoperin(), regprocedurein(), regprocin(), regtypein(), RelationBuildTriggers(), RenameRole(), session_user(), set_timetravel(), show_timezone(), special_uuid_value(), string_to_datum(), table_to_xml_internal(), text2ltree(), timestamp_izone(), timestamp_mi(), timestamptz_izone(), timetz_hash(), timetz_izone(), tintervalleneq(), tintervallenge(), tintervallengt(), tintervallenle(), tintervallenlt(), tintervallenne(), tintervalout(), ts_match_tq(), ts_match_tt(), tsa_headline_byname(), tsa_set_curcfg(), ttdummy(), uuid_generate_internal(), and uuid_generate_v35_internal().

00999 {
01000     FunctionCallInfoData fcinfo;
01001     Datum       result;
01002 
01003     InitFunctionCallInfoData(fcinfo, NULL, 1, NULL, NULL);
01004 
01005     fcinfo.arg[0] = arg1;
01006     fcinfo.argnull[0] = false;
01007 
01008     result = (*func) (&fcinfo);
01009 
01010     /* Check for null result, since caller is clearly not expecting one */
01011     if (fcinfo.isnull)
01012         elog(ERROR, "function %p returned NULL", (void *) func);
01013 
01014     return result;
01015 }

Datum DirectFunctionCall2 ( PGFunction  func,
Datum  arg1,
Datum  arg2 
)

Definition at line 1018 of file fmgr.c.

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

Referenced by _int_contained(), _int_different(), _lt_q_rregex(), _ltq_rregex(), _ltree_r_isparent(), _ltree_r_risparent(), _ltxtq_rexec(), array_iterator(), bitshiftleft(), bitshiftright(), box_div(), box_mul(), build_regexp_split_result(), cash_numeric(), chooseLR(), circle_div_pt(), circle_mul_pt(), close_lseg(), close_pb(), close_sb(), currtid_for_view(), date_mi_interval(), date_pl_interval(), decompile_conbin(), dist_pb(), dist_sb(), do_numeric_accum(), do_numeric_avg_accum(), g_cube_picksplit(), gbt_bitcmp(), gbt_biteq(), gbt_bitge(), gbt_bitgt(), gbt_bitle(), gbt_bitlt(), gbt_byteacmp(), gbt_byteaeq(), gbt_byteage(), gbt_byteagt(), gbt_byteale(), gbt_bytealt(), gbt_date_penalty(), gbt_dateeq(), gbt_datege(), gbt_dategt(), gbt_datekey_cmp(), gbt_datele(), gbt_datelt(), gbt_intveq(), gbt_intvge(), gbt_intvgt(), gbt_intvkey_cmp(), gbt_intvle(), gbt_intvlt(), gbt_macadeq(), gbt_macadge(), gbt_macadgt(), gbt_macadkey_cmp(), gbt_macadle(), gbt_macadlt(), gbt_numeric_cmp(), gbt_numeric_eq(), gbt_numeric_ge(), gbt_numeric_gt(), gbt_numeric_le(), gbt_numeric_lt(), gbt_numeric_penalty(), gbt_textcmp(), gbt_texteq(), gbt_textge(), gbt_textgt(), gbt_textle(), gbt_textlt(), gbt_time_penalty(), gbt_timeeq(), gbt_timege(), gbt_timegt(), gbt_timekey_cmp(), gbt_timele(), gbt_timelt(), gbt_tseq(), gbt_tsge(), gbt_tsgt(), gbt_tskey_cmp(), gbt_tsle(), gbt_tslt(), generate_series_timestamp(), generate_series_timestamptz(), gin_extract_hstore_query(), gin_numeric_cmp(), gist_box_leaf_consistent(), gist_box_penalty(), gist_box_picksplit(), gist_box_same(), gist_point_consistent(), hstore_contained(), hstore_eq(), hstore_ge(), hstore_gt(), hstore_le(), hstore_lt(), hstore_ne(), int8_avg(), int8_sum(), int8_to_char(), inter_sb(), interpt_pp(), interval_accum(), interval_avg(), intinterval(), line_distance(), line_interpt_internal(), line_intersect(), lt_q_regex(), lt_q_rregex(), ltq_rregex(), ltree_consistent(), ltxtq_rexec(), mul_d_interval(), network_scan_last(), numeric_avg(), numeric_cash(), numeric_to_char(), on_sb(), on_sl(), path_distance(), path_div_pt(), path_mul_pt(), plainto_tsquery(), poly_contain(), poly_contained(), rboolop(), regress_dist_ptpath(), regress_path_dist(), rtree_internal_consistent(), similarity_op(), text_isequal(), timestamp_mi_interval(), timestamptz_mi_interval(), tintervalct(), tintervalov(), tintervalsame(), to_tsquery(), to_tsvector(), ts_match_qv(), ts_match_tq(), ts_match_tt(), tsa_lexize_bycurrent(), tsa_lexize_byname(), tsa_plainto_tsquery_name(), tsa_to_tsquery_name(), tsa_to_tsvector_name(), and tsq_mcontained().

01019 {
01020     FunctionCallInfoData fcinfo;
01021     Datum       result;
01022 
01023     InitFunctionCallInfoData(fcinfo, NULL, 2, NULL, NULL);
01024 
01025     fcinfo.arg[0] = arg1;
01026     fcinfo.arg[1] = arg2;
01027     fcinfo.argnull[0] = false;
01028     fcinfo.argnull[1] = false;
01029 
01030     result = (*func) (&fcinfo);
01031 
01032     /* Check for null result, since caller is clearly not expecting one */
01033     if (fcinfo.isnull)
01034         elog(ERROR, "function %p returned NULL", (void *) func);
01035 
01036     return result;
01037 }

Datum DirectFunctionCall3 ( PGFunction  func,
Datum  arg1,
Datum  arg2,
Datum  arg3 
)

Definition at line 1040 of file fmgr.c.

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

Referenced by AlterRole(), assign_timezone(), build_regexp_matches_result(), build_regexp_split_result(), chooseLR(), CreateRole(), flatten_set_variable_args(), g_int_consistent(), ginqueryarrayextract(), leftmostvalue_bit(), leftmostvalue_inet(), leftmostvalue_varbit(), make_const(), moddatetime(), numeric_to_number(), pg_convert_from(), pg_convert_to(), readRecoveryCommandFile(), ssl_client_serial(), textregexsubstr(), ts_headline(), ts_headline_byid(), and tsa_headline_byname().

01042 {
01043     FunctionCallInfoData fcinfo;
01044     Datum       result;
01045 
01046     InitFunctionCallInfoData(fcinfo, NULL, 3, NULL, NULL);
01047 
01048     fcinfo.arg[0] = arg1;
01049     fcinfo.arg[1] = arg2;
01050     fcinfo.arg[2] = arg3;
01051     fcinfo.argnull[0] = false;
01052     fcinfo.argnull[1] = false;
01053     fcinfo.argnull[2] = false;
01054 
01055     result = (*func) (&fcinfo);
01056 
01057     /* Check for null result, since caller is clearly not expecting one */
01058     if (fcinfo.isnull)
01059         elog(ERROR, "function %p returned NULL", (void *) func);
01060 
01061     return result;
01062 }

Datum DirectFunctionCall4 ( PGFunction  func,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4 
)

Definition at line 1065 of file fmgr.c.

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

Referenced by neqsel(), ts_headline_opt(), and tsa_headline_byname().

01067 {
01068     FunctionCallInfoData fcinfo;
01069     Datum       result;
01070 
01071     InitFunctionCallInfoData(fcinfo, NULL, 4, NULL, NULL);
01072 
01073     fcinfo.arg[0] = arg1;
01074     fcinfo.arg[1] = arg2;
01075     fcinfo.arg[2] = arg3;
01076     fcinfo.arg[3] = arg4;
01077     fcinfo.argnull[0] = false;
01078     fcinfo.argnull[1] = false;
01079     fcinfo.argnull[2] = false;
01080     fcinfo.argnull[3] = false;
01081 
01082     result = (*func) (&fcinfo);
01083 
01084     /* Check for null result, since caller is clearly not expecting one */
01085     if (fcinfo.isnull)
01086         elog(ERROR, "function %p returned NULL", (void *) func);
01087 
01088     return result;
01089 }

Datum DirectFunctionCall5 ( PGFunction  func,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5 
)

Definition at line 1092 of file fmgr.c.

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

Referenced by gist_point_consistent(), and neqjoinsel().

01094 {
01095     FunctionCallInfoData fcinfo;
01096     Datum       result;
01097 
01098     InitFunctionCallInfoData(fcinfo, NULL, 5, NULL, NULL);
01099 
01100     fcinfo.arg[0] = arg1;
01101     fcinfo.arg[1] = arg2;
01102     fcinfo.arg[2] = arg3;
01103     fcinfo.arg[3] = arg4;
01104     fcinfo.arg[4] = arg5;
01105     fcinfo.argnull[0] = false;
01106     fcinfo.argnull[1] = false;
01107     fcinfo.argnull[2] = false;
01108     fcinfo.argnull[3] = false;
01109     fcinfo.argnull[4] = false;
01110 
01111     result = (*func) (&fcinfo);
01112 
01113     /* Check for null result, since caller is clearly not expecting one */
01114     if (fcinfo.isnull)
01115         elog(ERROR, "function %p returned NULL", (void *) func);
01116 
01117     return result;
01118 }

Datum DirectFunctionCall6 ( PGFunction  func,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6 
)

Definition at line 1121 of file fmgr.c.

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

01124 {
01125     FunctionCallInfoData fcinfo;
01126     Datum       result;
01127 
01128     InitFunctionCallInfoData(fcinfo, NULL, 6, NULL, NULL);
01129 
01130     fcinfo.arg[0] = arg1;
01131     fcinfo.arg[1] = arg2;
01132     fcinfo.arg[2] = arg3;
01133     fcinfo.arg[3] = arg4;
01134     fcinfo.arg[4] = arg5;
01135     fcinfo.arg[5] = arg6;
01136     fcinfo.argnull[0] = false;
01137     fcinfo.argnull[1] = false;
01138     fcinfo.argnull[2] = false;
01139     fcinfo.argnull[3] = false;
01140     fcinfo.argnull[4] = false;
01141     fcinfo.argnull[5] = false;
01142 
01143     result = (*func) (&fcinfo);
01144 
01145     /* Check for null result, since caller is clearly not expecting one */
01146     if (fcinfo.isnull)
01147         elog(ERROR, "function %p returned NULL", (void *) func);
01148 
01149     return result;
01150 }

Datum DirectFunctionCall7 ( PGFunction  func,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7 
)

Definition at line 1153 of file fmgr.c.

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

01156 {
01157     FunctionCallInfoData fcinfo;
01158     Datum       result;
01159 
01160     InitFunctionCallInfoData(fcinfo, NULL, 7, NULL, NULL);
01161 
01162     fcinfo.arg[0] = arg1;
01163     fcinfo.arg[1] = arg2;
01164     fcinfo.arg[2] = arg3;
01165     fcinfo.arg[3] = arg4;
01166     fcinfo.arg[4] = arg5;
01167     fcinfo.arg[5] = arg6;
01168     fcinfo.arg[6] = arg7;
01169     fcinfo.argnull[0] = false;
01170     fcinfo.argnull[1] = false;
01171     fcinfo.argnull[2] = false;
01172     fcinfo.argnull[3] = false;
01173     fcinfo.argnull[4] = false;
01174     fcinfo.argnull[5] = false;
01175     fcinfo.argnull[6] = false;
01176 
01177     result = (*func) (&fcinfo);
01178 
01179     /* Check for null result, since caller is clearly not expecting one */
01180     if (fcinfo.isnull)
01181         elog(ERROR, "function %p returned NULL", (void *) func);
01182 
01183     return result;
01184 }

Datum DirectFunctionCall8 ( PGFunction  func,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7,
Datum  arg8 
)

Definition at line 1187 of file fmgr.c.

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

01190 {
01191     FunctionCallInfoData fcinfo;
01192     Datum       result;
01193 
01194     InitFunctionCallInfoData(fcinfo, NULL, 8, NULL, NULL);
01195 
01196     fcinfo.arg[0] = arg1;
01197     fcinfo.arg[1] = arg2;
01198     fcinfo.arg[2] = arg3;
01199     fcinfo.arg[3] = arg4;
01200     fcinfo.arg[4] = arg5;
01201     fcinfo.arg[5] = arg6;
01202     fcinfo.arg[6] = arg7;
01203     fcinfo.arg[7] = arg8;
01204     fcinfo.argnull[0] = false;
01205     fcinfo.argnull[1] = false;
01206     fcinfo.argnull[2] = false;
01207     fcinfo.argnull[3] = false;
01208     fcinfo.argnull[4] = false;
01209     fcinfo.argnull[5] = false;
01210     fcinfo.argnull[6] = false;
01211     fcinfo.argnull[7] = false;
01212 
01213     result = (*func) (&fcinfo);
01214 
01215     /* Check for null result, since caller is clearly not expecting one */
01216     if (fcinfo.isnull)
01217         elog(ERROR, "function %p returned NULL", (void *) func);
01218 
01219     return result;
01220 }

Datum DirectFunctionCall9 ( PGFunction  func,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7,
Datum  arg8,
Datum  arg9 
)

Definition at line 1223 of file fmgr.c.

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

01227 {
01228     FunctionCallInfoData fcinfo;
01229     Datum       result;
01230 
01231     InitFunctionCallInfoData(fcinfo, NULL, 9, NULL, NULL);
01232 
01233     fcinfo.arg[0] = arg1;
01234     fcinfo.arg[1] = arg2;
01235     fcinfo.arg[2] = arg3;
01236     fcinfo.arg[3] = arg4;
01237     fcinfo.arg[4] = arg5;
01238     fcinfo.arg[5] = arg6;
01239     fcinfo.arg[6] = arg7;
01240     fcinfo.arg[7] = arg8;
01241     fcinfo.arg[8] = arg9;
01242     fcinfo.argnull[0] = false;
01243     fcinfo.argnull[1] = false;
01244     fcinfo.argnull[2] = false;
01245     fcinfo.argnull[3] = false;
01246     fcinfo.argnull[4] = false;
01247     fcinfo.argnull[5] = false;
01248     fcinfo.argnull[6] = false;
01249     fcinfo.argnull[7] = false;
01250     fcinfo.argnull[8] = false;
01251 
01252     result = (*func) (&fcinfo);
01253 
01254     /* Check for null result, since caller is clearly not expecting one */
01255     if (fcinfo.isnull)
01256         elog(ERROR, "function %p returned NULL", (void *) func);
01257 
01258     return result;
01259 }

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

Definition at line 431 of file fmgr.c.

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

Referenced by fmgr_c_validator(), and fmgr_info_C_lang().

00432 {
00433     char       *infofuncname;
00434     PGFInfoFunction infofunc;
00435     const Pg_finfo_record *inforec;
00436     static Pg_finfo_record default_inforec = {0};
00437 
00438     /* Compute name of info func */
00439     infofuncname = (char *) palloc(strlen(funcname) + 10);
00440     strcpy(infofuncname, "pg_finfo_");
00441     strcat(infofuncname, funcname);
00442 
00443     /* Try to look up the info function */
00444     infofunc = (PGFInfoFunction) lookup_external_function(filehandle,
00445                                                           infofuncname);
00446     if (infofunc == NULL)
00447     {
00448         /* Not found --- assume version 0 */
00449         pfree(infofuncname);
00450         return &default_inforec;
00451     }
00452 
00453     /* Found, so call it */
00454     inforec = (*infofunc) ();
00455 
00456     /* Validate result as best we can */
00457     if (inforec == NULL)
00458         elog(ERROR, "null result from info function \"%s\"", infofuncname);
00459     switch (inforec->api_version)
00460     {
00461         case 0:
00462         case 1:
00463             /* OK, no additional fields to validate */
00464             break;
00465         default:
00466             ereport(ERROR,
00467                     (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
00468                      errmsg("unrecognized API version %d reported by info function \"%s\"",
00469                             inforec->api_version, infofuncname)));
00470             break;
00471     }
00472 
00473     pfree(infofuncname);
00474     return inforec;
00475 }

Datum Float4GetDatum ( float4  X  ) 

Definition at line 2118 of file fmgr.c.

References palloc, PointerGetDatum, SET_4_BYTES, and value.

Referenced by InsertPgClassTuple(), leftmostvalue_float4(), ProcedureCreate(), and update_attstats().

02119 {
02120 #ifdef USE_FLOAT4_BYVAL
02121     union
02122     {
02123         float4      value;
02124         int32       retval;
02125     }           myunion;
02126 
02127     myunion.value = X;
02128     return SET_4_BYTES(myunion.retval);
02129 #else
02130     float4     *retval = (float4 *) palloc(sizeof(float4));
02131 
02132     *retval = X;
02133     return PointerGetDatum(retval);
02134 #endif
02135 }

Datum Float8GetDatum ( float8  X  ) 

Definition at line 2154 of file fmgr.c.

References palloc, PointerGetDatum, and value.

Referenced by assign_random_seed(), int8_to_char(), interval_avg(), leftmostvalue_float8(), and normal_rand().

02155 {
02156 #ifdef USE_FLOAT8_BYVAL
02157     union
02158     {
02159         float8      value;
02160         int64       retval;
02161     }           myunion;
02162 
02163     myunion.value = X;
02164     return SET_8_BYTES(myunion.retval);
02165 #else
02166     float8     *retval = (float8 *) palloc(sizeof(float8));
02167 
02168     *retval = X;
02169     return PointerGetDatum(retval);
02170 #endif
02171 }

char* fmgr ( Oid  procedureId,
  ... 
)

Definition at line 2049 of file fmgr.c.

References FunctionCallInfoData::arg, DatumGetPointer, elog, ereport, errcode(), ERRCODE_TOO_MANY_ARGUMENTS, 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, and PointerGetDatum.

02050 {
02051     FmgrInfo    flinfo;
02052     FunctionCallInfoData fcinfo;
02053     int         n_arguments;
02054     Datum       result;
02055 
02056     fmgr_info(procedureId, &flinfo);
02057 
02058     MemSet(&fcinfo, 0, sizeof(fcinfo));
02059     fcinfo.flinfo = &flinfo;
02060     fcinfo.nargs = flinfo.fn_nargs;
02061     n_arguments = fcinfo.nargs;
02062 
02063     if (n_arguments > 0)
02064     {
02065         va_list     pvar;
02066         int         i;
02067 
02068         if (n_arguments > FUNC_MAX_ARGS)
02069             ereport(ERROR,
02070                     (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
02071              errmsg("function %u has too many arguments (%d, maximum is %d)",
02072                     flinfo.fn_oid, n_arguments, FUNC_MAX_ARGS)));
02073         va_start(pvar, procedureId);
02074         for (i = 0; i < n_arguments; i++)
02075             fcinfo.arg[i] = PointerGetDatum(va_arg(pvar, char *));
02076         va_end(pvar);
02077     }
02078 
02079     result = FunctionCallInvoke(&fcinfo);
02080 
02081     /* Check for null result, since caller is clearly not expecting one */
02082     if (fcinfo.isnull)
02083         elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
02084 
02085     return DatumGetPointer(result);
02086 }

void fmgr_info ( Oid  functionId,
FmgrInfo finfo 
)

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

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

00299 {
00300     Form_pg_proc procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
00301     CFuncHashTabEntry *hashentry;
00302     PGFunction  user_fn;
00303     const Pg_finfo_record *inforec;
00304     Oldstyle_fnextra *fnextra;
00305     bool        isnull;
00306     int         i;
00307 
00308     /*
00309      * See if we have the function address cached already
00310      */
00311     hashentry = lookup_C_func(procedureTuple);
00312     if (hashentry)
00313     {
00314         user_fn = hashentry->user_fn;
00315         inforec = hashentry->inforec;
00316     }
00317     else
00318     {
00319         Datum       prosrcattr,
00320                     probinattr;
00321         char       *prosrcstring,
00322                    *probinstring;
00323         void       *libraryhandle;
00324 
00325         /*
00326          * Get prosrc and probin strings (link symbol and library filename).
00327          * While in general these columns might be null, that's not allowed
00328          * for C-language functions.
00329          */
00330         prosrcattr = SysCacheGetAttr(PROCOID, procedureTuple,
00331                                      Anum_pg_proc_prosrc, &isnull);
00332         if (isnull)
00333             elog(ERROR, "null prosrc for C function %u", functionId);
00334         prosrcstring = TextDatumGetCString(prosrcattr);
00335 
00336         probinattr = SysCacheGetAttr(PROCOID, procedureTuple,
00337                                      Anum_pg_proc_probin, &isnull);
00338         if (isnull)
00339             elog(ERROR, "null probin for C function %u", functionId);
00340         probinstring = TextDatumGetCString(probinattr);
00341 
00342         /* Look up the function itself */
00343         user_fn = load_external_function(probinstring, prosrcstring, true,
00344                                          &libraryhandle);
00345 
00346         /* Get the function information record (real or default) */
00347         inforec = fetch_finfo_record(libraryhandle, prosrcstring);
00348 
00349         /* Cache the addresses for later calls */
00350         record_C_func(procedureTuple, user_fn, inforec);
00351 
00352         pfree(prosrcstring);
00353         pfree(probinstring);
00354     }
00355 
00356     switch (inforec->api_version)
00357     {
00358         case 0:
00359             /* Old style: need to use a handler */
00360             finfo->fn_addr = fmgr_oldstyle;
00361             fnextra = (Oldstyle_fnextra *)
00362                 MemoryContextAllocZero(finfo->fn_mcxt,
00363                                        sizeof(Oldstyle_fnextra));
00364             finfo->fn_extra = (void *) fnextra;
00365             fnextra->func = (func_ptr) user_fn;
00366             for (i = 0; i < procedureStruct->pronargs; i++)
00367             {
00368                 fnextra->arg_toastable[i] =
00369                     TypeIsToastable(procedureStruct->proargtypes.values[i]);
00370             }
00371             break;
00372         case 1:
00373             /* New style: call directly */
00374             finfo->fn_addr = user_fn;
00375             break;
00376         default:
00377             /* Shouldn't get here if fetch_finfo_record did its job */
00378             elog(ERROR, "unrecognized function API version: %d",
00379                  inforec->api_version);
00380             break;
00381     }
00382 }

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

Definition at line 574 of file fmgr.c.

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

Referenced by initGinState(), initGISTstate(), and ScanKeyEntryInitializeWithInfo().

00576 {
00577     memcpy(dstinfo, srcinfo, sizeof(FmgrInfo));
00578     dstinfo->fn_mcxt = destcxt;
00579     if (dstinfo->fn_addr == fmgr_oldstyle)
00580     {
00581         /* For oldstyle functions we must copy fn_extra */
00582         Oldstyle_fnextra *fnextra;
00583 
00584         fnextra = (Oldstyle_fnextra *)
00585             MemoryContextAlloc(destcxt, sizeof(Oldstyle_fnextra));
00586         memcpy(fnextra, srcinfo->fn_extra, sizeof(Oldstyle_fnextra));
00587         dstinfo->fn_extra = (void *) fnextra;
00588     }
00589     else
00590         dstinfo->fn_extra = NULL;
00591 }

void fmgr_info_cxt ( Oid  functionId,
FmgrInfo finfo,
MemoryContext  mcxt 
)

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

Definition at line 174 of file fmgr.c.

References Anum_pg_proc_proconfig, Anum_pg_proc_prosrc, ClanguageId, elog, ereport, errcode(), ERRCODE_UNDEFINED_FUNCTION, errmsg(), ERROR, fmgr_info_C_lang(), fmgr_info_other_lang(), fmgr_isbuiltin(), fmgr_lookupByName(), fmgr_security_definer(), fmgr_sql(), 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_cxt(), and fmgr_security_definer().

00176 {
00177     const FmgrBuiltin *fbp;
00178     HeapTuple   procedureTuple;
00179     Form_pg_proc procedureStruct;
00180     Datum       prosrcdatum;
00181     bool        isnull;
00182     char       *prosrc;
00183 
00184     /*
00185      * fn_oid *must* be filled in last.  Some code assumes that if fn_oid is
00186      * valid, the whole struct is valid.  Some FmgrInfo struct's do survive
00187      * elogs.
00188      */
00189     finfo->fn_oid = InvalidOid;
00190     finfo->fn_extra = NULL;
00191     finfo->fn_mcxt = mcxt;
00192     finfo->fn_expr = NULL;      /* caller may set this later */
00193 
00194     if ((fbp = fmgr_isbuiltin(functionId)) != NULL)
00195     {
00196         /*
00197          * Fast path for builtin functions: don't bother consulting pg_proc
00198          */
00199         finfo->fn_nargs = fbp->nargs;
00200         finfo->fn_strict = fbp->strict;
00201         finfo->fn_retset = fbp->retset;
00202         finfo->fn_stats = TRACK_FUNC_ALL;       /* ie, never track */
00203         finfo->fn_addr = fbp->func;
00204         finfo->fn_oid = functionId;
00205         return;
00206     }
00207 
00208     /* Otherwise we need the pg_proc entry */
00209     procedureTuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(functionId));
00210     if (!HeapTupleIsValid(procedureTuple))
00211         elog(ERROR, "cache lookup failed for function %u", functionId);
00212     procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
00213 
00214     finfo->fn_nargs = procedureStruct->pronargs;
00215     finfo->fn_strict = procedureStruct->proisstrict;
00216     finfo->fn_retset = procedureStruct->proretset;
00217 
00218     /*
00219      * If it has prosecdef set, or non-null proconfig, use
00220      * fmgr_security_definer call handler --- unless we are being called again
00221      * by fmgr_security_definer.
00222      *
00223      * When using fmgr_security_definer, function stats tracking is always
00224      * disabled at the outer level, and instead we set the flag properly in
00225      * fmgr_security_definer's private flinfo and implement the tracking
00226      * inside fmgr_security_definer.  This loses the ability to charge the
00227      * overhead of fmgr_security_definer to the function, but gains the
00228      * ability to set the track_functions GUC as a local GUC parameter of an
00229      * interesting function and have the right things happen.
00230      */
00231     if (!ignore_security &&
00232         (procedureStruct->prosecdef ||
00233          !heap_attisnull(procedureTuple, Anum_pg_proc_proconfig)))
00234     {
00235         finfo->fn_addr = fmgr_security_definer;
00236         finfo->fn_stats = TRACK_FUNC_ALL;       /* ie, never track */
00237         finfo->fn_oid = functionId;
00238         ReleaseSysCache(procedureTuple);
00239         return;
00240     }
00241 
00242     switch (procedureStruct->prolang)
00243     {
00244         case INTERNALlanguageId:
00245 
00246             /*
00247              * For an ordinary builtin function, we should never get here
00248              * because the isbuiltin() search above will have succeeded.
00249              * However, if the user has done a CREATE FUNCTION to create an
00250              * alias for a builtin function, we can end up here.  In that case
00251              * we have to look up the function by name.  The name of the
00252              * internal function is stored in prosrc (it doesn't have to be
00253              * the same as the name of the alias!)
00254              */
00255             prosrcdatum = SysCacheGetAttr(PROCOID, procedureTuple,
00256                                           Anum_pg_proc_prosrc, &isnull);
00257             if (isnull)
00258                 elog(ERROR, "null prosrc");
00259             prosrc = TextDatumGetCString(prosrcdatum);
00260             fbp = fmgr_lookupByName(prosrc);
00261             if (fbp == NULL)
00262                 ereport(ERROR,
00263                         (errcode(ERRCODE_UNDEFINED_FUNCTION),
00264                          errmsg("internal function \"%s\" is not in internal lookup table",
00265                                 prosrc)));
00266             pfree(prosrc);
00267             /* Should we check that nargs, strict, retset match the table? */
00268             finfo->fn_addr = fbp->func;
00269             /* note this policy is also assumed in fast path above */
00270             finfo->fn_stats = TRACK_FUNC_ALL;   /* ie, never track */
00271             break;
00272 
00273         case ClanguageId:
00274             fmgr_info_C_lang(functionId, finfo, procedureTuple);
00275             finfo->fn_stats = TRACK_FUNC_PL;    /* ie, track if ALL */
00276             break;
00277 
00278         case SQLlanguageId:
00279             finfo->fn_addr = fmgr_sql;
00280             finfo->fn_stats = TRACK_FUNC_PL;    /* ie, track if ALL */
00281             break;
00282 
00283         default:
00284             fmgr_info_other_lang(functionId, finfo, procedureTuple);
00285             finfo->fn_stats = TRACK_FUNC_OFF;   /* ie, track if not OFF */
00286             break;
00287     }
00288 
00289     finfo->fn_oid = functionId;
00290     ReleaseSysCache(procedureTuple);
00291 }

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

Definition at line 389 of file fmgr.c.

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

Referenced by fmgr_info_cxt_security().

00390 {
00391     Form_pg_proc procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
00392     Oid         language = procedureStruct->prolang;
00393     HeapTuple   languageTuple;
00394     Form_pg_language languageStruct;
00395     FmgrInfo    plfinfo;
00396 
00397     languageTuple = SearchSysCache1(LANGOID, ObjectIdGetDatum(language));
00398     if (!HeapTupleIsValid(languageTuple))
00399         elog(ERROR, "cache lookup failed for language %u", language);
00400     languageStruct = (Form_pg_language) GETSTRUCT(languageTuple);
00401 
00402     fmgr_info(languageStruct->lanplcallfoid, &plfinfo);
00403     finfo->fn_addr = plfinfo.fn_addr;
00404 
00405     /*
00406      * If lookup of the PL handler function produced nonnull fn_extra,
00407      * complain --- it must be an oldstyle function! We no longer support
00408      * oldstyle PL handlers.
00409      */
00410     if (plfinfo.fn_extra != NULL)
00411         elog(ERROR, "language %u has old-style handler", language);
00412 
00413     ReleaseSysCache(languageTuple);
00414 }

Oid fmgr_internal_function ( const char *  proname  ) 

Definition at line 600 of file fmgr.c.

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

Referenced by fmgr_internal_validator().

00601 {
00602     const FmgrBuiltin *fbp = fmgr_lookupByName(proname);
00603 
00604     if (fbp == NULL)
00605         return InvalidOid;
00606     return fbp->foid;
00607 }

static const FmgrBuiltin* fmgr_isbuiltin ( Oid  id  )  [static]

Definition at line 98 of file fmgr.c.

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

Referenced by fmgr_info_cxt_security().

00099 {
00100     int         low = 0;
00101     int         high = fmgr_nbuiltins - 1;
00102 
00103     /*
00104      * Loop invariant: low is the first index that could contain target entry,
00105      * and high is the last index that could contain it.
00106      */
00107     while (low <= high)
00108     {
00109         int         i = (high + low) / 2;
00110         const FmgrBuiltin *ptr = &fmgr_builtins[i];
00111 
00112         if (id == ptr->foid)
00113             return ptr;
00114         else if (id > ptr->foid)
00115             low = i + 1;
00116         else
00117             high = i - 1;
00118     }
00119     return NULL;
00120 }

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

Definition at line 128 of file fmgr.c.

References fmgr_builtins, fmgr_nbuiltins, i, and NULL.

Referenced by fmgr_info_cxt_security(), and fmgr_internal_function().

00129 {
00130     int         i;
00131 
00132     for (i = 0; i < fmgr_nbuiltins; i++)
00133     {
00134         if (strcmp(name, fmgr_builtins[i].funcName) == 0)
00135             return fmgr_builtins + i;
00136     }
00137     return NULL;
00138 }

static Datum fmgr_oldstyle ( PG_FUNCTION_ARGS   )  [static]

Definition at line 614 of file fmgr.c.

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

Referenced by fmgr_info_C_lang(), and fmgr_info_copy().

00615 {
00616     Oldstyle_fnextra *fnextra;
00617     int         n_arguments = fcinfo->nargs;
00618     int         i;
00619     bool        isnull;
00620     func_ptr    user_fn;
00621     char       *returnValue;
00622 
00623     if (fcinfo->flinfo == NULL || fcinfo->flinfo->fn_extra == NULL)
00624         elog(ERROR, "fmgr_oldstyle received NULL pointer");
00625     fnextra = (Oldstyle_fnextra *) fcinfo->flinfo->fn_extra;
00626 
00627     /*
00628      * Result is NULL if any argument is NULL, but we still call the function
00629      * (peculiar, but that's the way it worked before, and after all this is a
00630      * backwards-compatibility wrapper).  Note, however, that we'll never get
00631      * here with NULL arguments if the function is marked strict.
00632      *
00633      * We also need to detoast any TOAST-ed inputs, since it's unlikely that
00634      * an old-style function knows about TOASTing.
00635      */
00636     isnull = false;
00637     for (i = 0; i < n_arguments; i++)
00638     {
00639         if (PG_ARGISNULL(i))
00640             isnull = true;
00641         else if (fnextra->arg_toastable[i])
00642             fcinfo->arg[i] = PointerGetDatum(PG_DETOAST_DATUM(fcinfo->arg[i]));
00643     }
00644     fcinfo->isnull = isnull;
00645 
00646     user_fn = fnextra->func;
00647 
00648     switch (n_arguments)
00649     {
00650         case 0:
00651             returnValue = (char *) (*user_fn) ();
00652             break;
00653         case 1:
00654 
00655             /*
00656              * nullvalue() used to use isNull to check if arg is NULL; perhaps
00657              * there are other functions still out there that also rely on
00658              * this undocumented hack?
00659              */
00660             returnValue = (char *) (*user_fn) (fcinfo->arg[0],
00661                                                &fcinfo->isnull);
00662             break;
00663         case 2:
00664             returnValue = (char *) (*user_fn) (fcinfo->arg[0],
00665                                                fcinfo->arg[1]);
00666             break;
00667         case 3:
00668             returnValue = (char *) (*user_fn) (fcinfo->arg[0],
00669                                                fcinfo->arg[1],
00670                                                fcinfo->arg[2]);
00671             break;
00672         case 4:
00673             returnValue = (char *) (*user_fn) (fcinfo->arg[0],
00674                                                fcinfo->arg[1],
00675                                                fcinfo->arg[2],
00676                                                fcinfo->arg[3]);
00677             break;
00678         case 5:
00679             returnValue = (char *) (*user_fn) (fcinfo->arg[0],
00680                                                fcinfo->arg[1],
00681                                                fcinfo->arg[2],
00682                                                fcinfo->arg[3],
00683                                                fcinfo->arg[4]);
00684             break;
00685         case 6:
00686             returnValue = (char *) (*user_fn) (fcinfo->arg[0],
00687                                                fcinfo->arg[1],
00688                                                fcinfo->arg[2],
00689                                                fcinfo->arg[3],
00690                                                fcinfo->arg[4],
00691                                                fcinfo->arg[5]);
00692             break;
00693         case 7:
00694             returnValue = (char *) (*user_fn) (fcinfo->arg[0],
00695                                                fcinfo->arg[1],
00696                                                fcinfo->arg[2],
00697                                                fcinfo->arg[3],
00698                                                fcinfo->arg[4],
00699                                                fcinfo->arg[5],
00700                                                fcinfo->arg[6]);
00701             break;
00702         case 8:
00703             returnValue = (char *) (*user_fn) (fcinfo->arg[0],
00704                                                fcinfo->arg[1],
00705                                                fcinfo->arg[2],
00706                                                fcinfo->arg[3],
00707                                                fcinfo->arg[4],
00708                                                fcinfo->arg[5],
00709                                                fcinfo->arg[6],
00710                                                fcinfo->arg[7]);
00711             break;
00712         case 9:
00713             returnValue = (char *) (*user_fn) (fcinfo->arg[0],
00714                                                fcinfo->arg[1],
00715                                                fcinfo->arg[2],
00716                                                fcinfo->arg[3],
00717                                                fcinfo->arg[4],
00718                                                fcinfo->arg[5],
00719                                                fcinfo->arg[6],
00720                                                fcinfo->arg[7],
00721                                                fcinfo->arg[8]);
00722             break;
00723         case 10:
00724             returnValue = (char *) (*user_fn) (fcinfo->arg[0],
00725                                                fcinfo->arg[1],
00726                                                fcinfo->arg[2],
00727                                                fcinfo->arg[3],
00728                                                fcinfo->arg[4],
00729                                                fcinfo->arg[5],
00730                                                fcinfo->arg[6],
00731                                                fcinfo->arg[7],
00732                                                fcinfo->arg[8],
00733                                                fcinfo->arg[9]);
00734             break;
00735         case 11:
00736             returnValue = (char *) (*user_fn) (fcinfo->arg[0],
00737                                                fcinfo->arg[1],
00738                                                fcinfo->arg[2],
00739                                                fcinfo->arg[3],
00740                                                fcinfo->arg[4],
00741                                                fcinfo->arg[5],
00742                                                fcinfo->arg[6],
00743                                                fcinfo->arg[7],
00744                                                fcinfo->arg[8],
00745                                                fcinfo->arg[9],
00746                                                fcinfo->arg[10]);
00747             break;
00748         case 12:
00749             returnValue = (char *) (*user_fn) (fcinfo->arg[0],
00750                                                fcinfo->arg[1],
00751                                                fcinfo->arg[2],
00752                                                fcinfo->arg[3],
00753                                                fcinfo->arg[4],
00754                                                fcinfo->arg[5],
00755                                                fcinfo->arg[6],
00756                                                fcinfo->arg[7],
00757                                                fcinfo->arg[8],
00758                                                fcinfo->arg[9],
00759                                                fcinfo->arg[10],
00760                                                fcinfo->arg[11]);
00761             break;
00762         case 13:
00763             returnValue = (char *) (*user_fn) (fcinfo->arg[0],
00764                                                fcinfo->arg[1],
00765                                                fcinfo->arg[2],
00766                                                fcinfo->arg[3],
00767                                                fcinfo->arg[4],
00768                                                fcinfo->arg[5],
00769                                                fcinfo->arg[6],
00770                                                fcinfo->arg[7],
00771                                                fcinfo->arg[8],
00772                                                fcinfo->arg[9],
00773                                                fcinfo->arg[10],
00774                                                fcinfo->arg[11],
00775                                                fcinfo->arg[12]);
00776             break;
00777         case 14:
00778             returnValue = (char *) (*user_fn) (fcinfo->arg[0],
00779                                                fcinfo->arg[1],
00780                                                fcinfo->arg[2],
00781                                                fcinfo->arg[3],
00782                                                fcinfo->arg[4],
00783                                                fcinfo->arg[5],
00784                                                fcinfo->arg[6],
00785                                                fcinfo->arg[7],
00786                                                fcinfo->arg[8],
00787                                                fcinfo->arg[9],
00788                                                fcinfo->arg[10],
00789                                                fcinfo->arg[11],
00790                                                fcinfo->arg[12],
00791                                                fcinfo->arg[13]);
00792             break;
00793         case 15:
00794             returnValue = (char *) (*user_fn) (fcinfo->arg[0],
00795                                                fcinfo->arg[1],
00796                                                fcinfo->arg[2],
00797                                                fcinfo->arg[3],
00798                                                fcinfo->arg[4],
00799                                                fcinfo->arg[5],
00800                                                fcinfo->arg[6],
00801                                                fcinfo->arg[7],
00802                                                fcinfo->arg[8],
00803                                                fcinfo->arg[9],
00804                                                fcinfo->arg[10],
00805                                                fcinfo->arg[11],
00806                                                fcinfo->arg[12],
00807                                                fcinfo->arg[13],
00808                                                fcinfo->arg[14]);
00809             break;
00810         case 16:
00811             returnValue = (char *) (*user_fn) (fcinfo->arg[0],
00812                                                fcinfo->arg[1],
00813                                                fcinfo->arg[2],
00814                                                fcinfo->arg[3],
00815                                                fcinfo->arg[4],
00816                                                fcinfo->arg[5],
00817                                                fcinfo->arg[6],
00818                                                fcinfo->arg[7],
00819                                                fcinfo->arg[8],
00820                                                fcinfo->arg[9],
00821                                                fcinfo->arg[10],
00822                                                fcinfo->arg[11],
00823                                                fcinfo->arg[12],
00824                                                fcinfo->arg[13],
00825                                                fcinfo->arg[14],
00826                                                fcinfo->arg[15]);
00827             break;
00828         default:
00829 
00830             /*
00831              * Increasing FUNC_MAX_ARGS doesn't automatically add cases to the
00832              * above code, so mention the actual value in this error not
00833              * FUNC_MAX_ARGS.  You could add cases to the above if you needed
00834              * to support old-style functions with many arguments, but making
00835              * 'em be new-style is probably a better idea.
00836              */
00837             ereport(ERROR,
00838                     (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
00839              errmsg("function %u has too many arguments (%d, maximum is %d)",
00840                     fcinfo->flinfo->fn_oid, n_arguments, 16)));
00841             returnValue = NULL; /* keep compiler quiet */
00842             break;
00843     }
00844 
00845     return PointerGetDatum(returnValue);
00846 }

static Datum fmgr_security_definer ( PG_FUNCTION_ARGS   )  [static]

Definition at line 873 of file fmgr.c.

References Anum_pg_proc_proconfig, AtEOXact_GUC(), DatumGetArrayTypePCopy, elog, ERROR, ExprMultipleResult, fmgr_security_definer_cache::flinfo, 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(), SearchSysCache1, SECURITY_LOCAL_USERID_CHANGE, SetUserIdAndSecContext(), superuser(), SysCacheGetAttr(), and fmgr_security_definer_cache::userid.

Referenced by fmgr_info_cxt_security().

00874 {
00875     Datum       result;
00876     struct fmgr_security_definer_cache *volatile fcache;
00877     FmgrInfo   *save_flinfo;
00878     Oid         save_userid;
00879     int         save_sec_context;
00880     volatile int save_nestlevel;
00881     PgStat_FunctionCallUsage fcusage;
00882 
00883     if (!fcinfo->flinfo->fn_extra)
00884     {
00885         HeapTuple   tuple;
00886         Form_pg_proc procedureStruct;
00887         Datum       datum;
00888         bool        isnull;
00889         MemoryContext oldcxt;
00890 
00891         fcache = MemoryContextAllocZero(fcinfo->flinfo->fn_mcxt,
00892                                         sizeof(*fcache));
00893 
00894         fmgr_info_cxt_security(fcinfo->flinfo->fn_oid, &fcache->flinfo,
00895                                fcinfo->flinfo->fn_mcxt, true);
00896         fcache->flinfo.fn_expr = fcinfo->flinfo->fn_expr;
00897 
00898         tuple = SearchSysCache1(PROCOID,
00899                                 ObjectIdGetDatum(fcinfo->flinfo->fn_oid));
00900         if (!HeapTupleIsValid(tuple))
00901             elog(ERROR, "cache lookup failed for function %u",
00902                  fcinfo->flinfo->fn_oid);
00903         procedureStruct = (Form_pg_proc) GETSTRUCT(tuple);
00904 
00905         if (procedureStruct->prosecdef)
00906             fcache->userid = procedureStruct->proowner;
00907 
00908         datum = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_proconfig,
00909                                 &isnull);
00910         if (!isnull)
00911         {
00912             oldcxt = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
00913             fcache->proconfig = DatumGetArrayTypePCopy(datum);
00914             MemoryContextSwitchTo(oldcxt);
00915         }
00916 
00917         ReleaseSysCache(tuple);
00918 
00919         fcinfo->flinfo->fn_extra = fcache;
00920     }
00921     else
00922         fcache = fcinfo->flinfo->fn_extra;
00923 
00924     /* GetUserIdAndSecContext is cheap enough that no harm in a wasted call */
00925     GetUserIdAndSecContext(&save_userid, &save_sec_context);
00926     if (fcache->proconfig)      /* Need a new GUC nesting level */
00927         save_nestlevel = NewGUCNestLevel();
00928     else
00929         save_nestlevel = 0;     /* keep compiler quiet */
00930 
00931     if (OidIsValid(fcache->userid))
00932         SetUserIdAndSecContext(fcache->userid,
00933                             save_sec_context | SECURITY_LOCAL_USERID_CHANGE);
00934 
00935     if (fcache->proconfig)
00936     {
00937         ProcessGUCArray(fcache->proconfig,
00938                         (superuser() ? PGC_SUSET : PGC_USERSET),
00939                         PGC_S_SESSION,
00940                         GUC_ACTION_SAVE);
00941     }
00942 
00943     /*
00944      * We don't need to restore GUC or userid settings on error, because the
00945      * ensuing xact or subxact abort will do that.  The PG_TRY block is only
00946      * needed to clean up the flinfo link.
00947      */
00948     save_flinfo = fcinfo->flinfo;
00949 
00950     PG_TRY();
00951     {
00952         fcinfo->flinfo = &fcache->flinfo;
00953 
00954         /* See notes in fmgr_info_cxt_security */
00955         pgstat_init_function_usage(fcinfo, &fcusage);
00956 
00957         result = FunctionCallInvoke(fcinfo);
00958 
00959         /*
00960          * We could be calling either a regular or a set-returning function,
00961          * so we have to test to see what finalize flag to use.
00962          */
00963         pgstat_end_function_usage(&fcusage,
00964                                   (fcinfo->resultinfo == NULL ||
00965                                    !IsA(fcinfo->resultinfo, ReturnSetInfo) ||
00966                                    ((ReturnSetInfo *) fcinfo->resultinfo)->isDone != ExprMultipleResult));
00967     }
00968     PG_CATCH();
00969     {
00970         fcinfo->flinfo = save_flinfo;
00971         PG_RE_THROW();
00972     }
00973     PG_END_TRY();
00974 
00975     fcinfo->flinfo = save_flinfo;
00976 
00977     if (fcache->proconfig)
00978         AtEOXact_GUC(true, save_nestlevel);
00979     if (OidIsValid(fcache->userid))
00980         SetUserIdAndSecContext(save_userid, save_sec_context);
00981 
00982     return result;
00983 }

Datum FunctionCall1 ( FmgrInfo flinfo,
Datum  arg1 
)

Definition at line 1268 of file fmgr.c.

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

Referenced by _hash_datum2hashkey(), ExecHashBuildSkewHash(), ExecHashGetHashValue(), gistcentryinit(), gistdentryinit(), hlparsetext(), index_endscan(), index_markpos(), index_restrpos(), OutputFunctionCall(), parsetext(), prs_setup_firstcall(), SendFunctionCall(), and TupleHashTableHash().

01269 {
01270     FunctionCallInfoData fcinfo;
01271     Datum       result;
01272 
01273     InitFunctionCallInfoData(fcinfo, flinfo, 1, NULL, NULL);
01274 
01275     fcinfo.arg[0] = arg1;
01276     fcinfo.argnull[0] = false;
01277 
01278     result = FunctionCallInvoke(&fcinfo);
01279 
01280     /* Check for null result, since caller is clearly not expecting one */
01281     if (fcinfo.isnull)
01282         elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
01283 
01284     return result;
01285 }

Datum FunctionCall2 ( FmgrInfo flinfo,
Datum  arg1,
Datum  arg2 
)

Definition at line 1288 of file fmgr.c.

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

Referenced by _bt_check_rowcompare(), _bt_checkkeys(), _bt_compare(), _bt_compare_scankey_args(), _bt_isequal(), _bt_load(), _hash_checkqual(), cmpEntries(), compareEntries(), compute_minimal_stats(), eqjoinsel_inner(), eqjoinsel_semi(), execTuplesMatch(), execTuplesUnequal(), extractEntriesS(), genericPickSplit(), get_variable_range(), gistMakeUnionItVec(), gistMakeUnionKey(), gistUserPicksplit(), histogram_selectivity(), hlparsetext(), index_getbitmap(), index_getnext(), index_rescan(), index_vacuum_cleanup(), ineq_histogram_selectivity(), make_greater_string(), mcv_selectivity(), parsetext(), process_ordered_aggregate_single(), prs_setup_firstcall(), ri_AttributesEqual(), and var_eq_const().

01289 {
01290     /*
01291      * XXX if you change this routine, see also the inlined version in
01292      * utils/sort/tuplesort.c!
01293      */
01294     FunctionCallInfoData fcinfo;
01295     Datum       result;
01296 
01297     InitFunctionCallInfoData(fcinfo, flinfo, 2, NULL, NULL);
01298 
01299     fcinfo.arg[0] = arg1;
01300     fcinfo.arg[1] = arg2;
01301     fcinfo.argnull[0] = false;
01302     fcinfo.argnull[1] = false;
01303 
01304     result = FunctionCallInvoke(&fcinfo);
01305 
01306     /* Check for null result, since caller is clearly not expecting one */
01307     if (fcinfo.isnull)
01308         elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
01309 
01310     return result;
01311 }

Datum FunctionCall3 ( FmgrInfo flinfo,
Datum  arg1,
Datum  arg2,
Datum  arg3 
)

Definition at line 1314 of file fmgr.c.

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

Referenced by gistKeyIsEQ(), gistpenalty(), hlparsetext(), index_beginscan_internal(), parsetext(), prs_setup_firstcall(), ri_AttributesEqual(), and ts_headline_byid_opt().

01316 {
01317     FunctionCallInfoData fcinfo;
01318     Datum       result;
01319 
01320     InitFunctionCallInfoData(fcinfo, flinfo, 3, NULL, NULL);
01321 
01322     fcinfo.arg[0] = arg1;
01323     fcinfo.arg[1] = arg2;
01324     fcinfo.arg[2] = arg3;
01325     fcinfo.argnull[0] = false;
01326     fcinfo.argnull[1] = false;
01327     fcinfo.argnull[2] = false;
01328 
01329     result = FunctionCallInvoke(&fcinfo);
01330 
01331     /* Check for null result, since caller is clearly not expecting one */
01332     if (fcinfo.isnull)
01333         elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
01334 
01335     return result;
01336 }

Datum FunctionCall4 ( FmgrInfo flinfo,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4 
)

Definition at line 1339 of file fmgr.c.

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

Referenced by compileTheLexeme(), compileTheSubstitute(), computePartialMatchList(), index_bulk_delete(), LexizeExec(), matchPartialInPendingList(), scalararraysel(), thesaurus_lexize(), ts_lexize(), and unaccent_dict().

01341 {
01342     FunctionCallInfoData fcinfo;
01343     Datum       result;
01344 
01345     InitFunctionCallInfoData(fcinfo, flinfo, 4, NULL, NULL);
01346 
01347     fcinfo.arg[0] = arg1;
01348     fcinfo.arg[1] = arg2;
01349     fcinfo.arg[2] = arg3;
01350     fcinfo.arg[3] = arg4;
01351     fcinfo.argnull[0] = false;
01352     fcinfo.argnull[1] = false;
01353     fcinfo.argnull[2] = false;
01354     fcinfo.argnull[3] = false;
01355 
01356     result = FunctionCallInvoke(&fcinfo);
01357 
01358     /* Check for null result, since caller is clearly not expecting one */
01359     if (fcinfo.isnull)
01360         elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
01361 
01362     return result;
01363 }

Datum FunctionCall5 ( FmgrInfo flinfo,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5 
)

Definition at line 1366 of file fmgr.c.

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

Referenced by gistindex_keytest(), newScanKey(), perform_default_encoding_conversion(), and scalararraysel().

01368 {
01369     FunctionCallInfoData fcinfo;
01370     Datum       result;
01371 
01372     InitFunctionCallInfoData(fcinfo, flinfo, 5, NULL, NULL);
01373 
01374     fcinfo.arg[0] = arg1;
01375     fcinfo.arg[1] = arg2;
01376     fcinfo.arg[2] = arg3;
01377     fcinfo.arg[3] = arg4;
01378     fcinfo.arg[4] = arg5;
01379     fcinfo.argnull[0] = false;
01380     fcinfo.argnull[1] = false;
01381     fcinfo.argnull[2] = false;
01382     fcinfo.argnull[3] = false;
01383     fcinfo.argnull[4] = false;
01384 
01385     result = FunctionCallInvoke(&fcinfo);
01386 
01387     /* Check for null result, since caller is clearly not expecting one */
01388     if (fcinfo.isnull)
01389         elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
01390 
01391     return result;
01392 }

Datum FunctionCall6 ( FmgrInfo flinfo,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6 
)

Definition at line 1395 of file fmgr.c.

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

Referenced by callConsistentFn(), and index_insert().

01398 {
01399     FunctionCallInfoData fcinfo;
01400     Datum       result;
01401 
01402     InitFunctionCallInfoData(fcinfo, flinfo, 6, NULL, NULL);
01403 
01404     fcinfo.arg[0] = arg1;
01405     fcinfo.arg[1] = arg2;
01406     fcinfo.arg[2] = arg3;
01407     fcinfo.arg[3] = arg4;
01408     fcinfo.arg[4] = arg5;
01409     fcinfo.arg[5] = arg6;
01410     fcinfo.argnull[0] = false;
01411     fcinfo.argnull[1] = false;
01412     fcinfo.argnull[2] = false;
01413     fcinfo.argnull[3] = false;
01414     fcinfo.argnull[4] = false;
01415     fcinfo.argnull[5] = false;
01416 
01417     result = FunctionCallInvoke(&fcinfo);
01418 
01419     /* Check for null result, since caller is clearly not expecting one */
01420     if (fcinfo.isnull)
01421         elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
01422 
01423     return result;
01424 }

Datum FunctionCall7 ( FmgrInfo flinfo,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7 
)

Definition at line 1427 of file fmgr.c.

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

01430 {
01431     FunctionCallInfoData fcinfo;
01432     Datum       result;
01433 
01434     InitFunctionCallInfoData(fcinfo, flinfo, 7, NULL, NULL);
01435 
01436     fcinfo.arg[0] = arg1;
01437     fcinfo.arg[1] = arg2;
01438     fcinfo.arg[2] = arg3;
01439     fcinfo.arg[3] = arg4;
01440     fcinfo.arg[4] = arg5;
01441     fcinfo.arg[5] = arg6;
01442     fcinfo.arg[6] = arg7;
01443     fcinfo.argnull[0] = false;
01444     fcinfo.argnull[1] = false;
01445     fcinfo.argnull[2] = false;
01446     fcinfo.argnull[3] = false;
01447     fcinfo.argnull[4] = false;
01448     fcinfo.argnull[5] = false;
01449     fcinfo.argnull[6] = false;
01450 
01451     result = FunctionCallInvoke(&fcinfo);
01452 
01453     /* Check for null result, since caller is clearly not expecting one */
01454     if (fcinfo.isnull)
01455         elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
01456 
01457     return result;
01458 }

Datum FunctionCall8 ( FmgrInfo flinfo,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7,
Datum  arg8 
)

Definition at line 1461 of file fmgr.c.

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

01464 {
01465     FunctionCallInfoData fcinfo;
01466     Datum       result;
01467 
01468     InitFunctionCallInfoData(fcinfo, flinfo, 8, NULL, NULL);
01469 
01470     fcinfo.arg[0] = arg1;
01471     fcinfo.arg[1] = arg2;
01472     fcinfo.arg[2] = arg3;
01473     fcinfo.arg[3] = arg4;
01474     fcinfo.arg[4] = arg5;
01475     fcinfo.arg[5] = arg6;
01476     fcinfo.arg[6] = arg7;
01477     fcinfo.arg[7] = arg8;
01478     fcinfo.argnull[0] = false;
01479     fcinfo.argnull[1] = false;
01480     fcinfo.argnull[2] = false;
01481     fcinfo.argnull[3] = false;
01482     fcinfo.argnull[4] = false;
01483     fcinfo.argnull[5] = false;
01484     fcinfo.argnull[6] = false;
01485     fcinfo.argnull[7] = false;
01486 
01487     result = FunctionCallInvoke(&fcinfo);
01488 
01489     /* Check for null result, since caller is clearly not expecting one */
01490     if (fcinfo.isnull)
01491         elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
01492 
01493     return result;
01494 }

Datum FunctionCall9 ( FmgrInfo flinfo,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7,
Datum  arg8,
Datum  arg9 
)

Definition at line 1497 of file fmgr.c.

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

01501 {
01502     FunctionCallInfoData fcinfo;
01503     Datum       result;
01504 
01505     InitFunctionCallInfoData(fcinfo, flinfo, 9, NULL, NULL);
01506 
01507     fcinfo.arg[0] = arg1;
01508     fcinfo.arg[1] = arg2;
01509     fcinfo.arg[2] = arg3;
01510     fcinfo.arg[3] = arg4;
01511     fcinfo.arg[4] = arg5;
01512     fcinfo.arg[5] = arg6;
01513     fcinfo.arg[6] = arg7;
01514     fcinfo.arg[7] = arg8;
01515     fcinfo.arg[8] = arg9;
01516     fcinfo.argnull[0] = false;
01517     fcinfo.argnull[1] = false;
01518     fcinfo.argnull[2] = false;
01519     fcinfo.argnull[3] = false;
01520     fcinfo.argnull[4] = false;
01521     fcinfo.argnull[5] = false;
01522     fcinfo.argnull[6] = false;
01523     fcinfo.argnull[7] = false;
01524     fcinfo.argnull[8] = false;
01525 
01526     result = FunctionCallInvoke(&fcinfo);
01527 
01528     /* Check for null result, since caller is clearly not expecting one */
01529     if (fcinfo.isnull)
01530         elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
01531 
01532     return result;
01533 }

bool get_call_expr_arg_stable ( Node expr,
int  argnum 
)

Definition at line 2363 of file fmgr.c.

References IsA, list_length(), list_make1, list_nth(), NULL, and PARAM_EXTERN.

Referenced by get_fn_expr_arg_stable().

02364 {
02365     List       *args;
02366     Node       *arg;
02367 
02368     if (expr == NULL)
02369         return false;
02370 
02371     if (IsA(expr, FuncExpr))
02372         args = ((FuncExpr *) expr)->args;
02373     else if (IsA(expr, OpExpr))
02374         args = ((OpExpr *) expr)->args;
02375     else if (IsA(expr, DistinctExpr))
02376         args = ((DistinctExpr *) expr)->args;
02377     else if (IsA(expr, ScalarArrayOpExpr))
02378         args = ((ScalarArrayOpExpr *) expr)->args;
02379     else if (IsA(expr, ArrayCoerceExpr))
02380         args = list_make1(((ArrayCoerceExpr *) expr)->arg);
02381     else if (IsA(expr, NullIfExpr))
02382         args = ((NullIfExpr *) expr)->args;
02383     else if (IsA(expr, WindowFunc))
02384         args = ((WindowFunc *) expr)->args;
02385     else
02386         return false;
02387 
02388     if (argnum < 0 || argnum >= list_length(args))
02389         return false;
02390 
02391     arg = (Node *) list_nth(args, argnum);
02392 
02393     /*
02394      * Either a true Const or an external Param will have a value that doesn't
02395      * change during the execution of the query.  In future we might want to
02396      * consider other cases too, e.g. now().
02397      */
02398     if (IsA(arg, Const))
02399         return true;
02400     if (IsA(arg, Param) &&
02401         ((Param *) arg)->paramkind == PARAM_EXTERN)
02402         return true;
02403 
02404     return false;
02405 }

Oid get_call_expr_argtype ( Node expr,
int  argnum 
)

Definition at line 2292 of file fmgr.c.

References exprType(), get_element_type(), InvalidOid, IsA, list_length(), list_make1, list_nth(), and NULL.

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

02293 {
02294     List       *args;
02295     Oid         argtype;
02296 
02297     if (expr == NULL)
02298         return InvalidOid;
02299 
02300     if (IsA(expr, FuncExpr))
02301         args = ((FuncExpr *) expr)->args;
02302     else if (IsA(expr, OpExpr))
02303         args = ((OpExpr *) expr)->args;
02304     else if (IsA(expr, DistinctExpr))
02305         args = ((DistinctExpr *) expr)->args;
02306     else if (IsA(expr, ScalarArrayOpExpr))
02307         args = ((ScalarArrayOpExpr *) expr)->args;
02308     else if (IsA(expr, ArrayCoerceExpr))
02309         args = list_make1(((ArrayCoerceExpr *) expr)->arg);
02310     else if (IsA(expr, NullIfExpr))
02311         args = ((NullIfExpr *) expr)->args;
02312     else if (IsA(expr, WindowFunc))
02313         args = ((WindowFunc *) expr)->args;
02314     else
02315         return InvalidOid;
02316 
02317     if (argnum < 0 || argnum >= list_length(args))
02318         return InvalidOid;
02319 
02320     argtype = exprType((Node *) list_nth(args, argnum));
02321 
02322     /*
02323      * special hack for ScalarArrayOpExpr and ArrayCoerceExpr: what the
02324      * underlying function will actually get passed is the element type of the
02325      * array.
02326      */
02327     if (IsA(expr, ScalarArrayOpExpr) &&
02328         argnum == 1)
02329         argtype = get_element_type(argtype);
02330     else if (IsA(expr, ArrayCoerceExpr) &&
02331              argnum == 0)
02332         argtype = get_element_type(argtype);
02333 
02334     return argtype;
02335 }

bool get_fn_expr_arg_stable ( FmgrInfo flinfo,
int  argnum 
)

Definition at line 2344 of file fmgr.c.

References FmgrInfo::fn_expr, and get_call_expr_arg_stable().

Referenced by leadlag_common(), and window_nth_value().

02345 {
02346     /*
02347      * can't return anything useful if we have no FmgrInfo or if its fn_expr
02348      * node has not been initialized
02349      */
02350     if (!flinfo || !flinfo->fn_expr)
02351         return false;
02352 
02353     return get_call_expr_arg_stable(flinfo->fn_expr, argnum);
02354 }

Oid get_fn_expr_argtype ( FmgrInfo flinfo,
int  argnum 
)

Definition at line 2273 of file fmgr.c.

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

Referenced by array_agg_transfn(), array_fill(), array_fill_with_lower_bounds(), array_push(), concat_internal(), dblink_close(), dblink_exec(), dblink_fetch(), dblink_open(), dblink_record_internal(), enum_first(), enum_last(), enum_range_all(), enum_range_bounds(), hstore_from_record(), hstore_populate_record(), init_sql_fcache(), pg_column_size(), and pg_typeof().

02274 {
02275     /*
02276      * can't return anything useful if we have no FmgrInfo or if its fn_expr
02277      * node has not been initialized
02278      */
02279     if (!flinfo || !flinfo->fn_expr)
02280         return InvalidOid;
02281 
02282     return get_call_expr_argtype(flinfo->fn_expr, argnum);
02283 }

Oid get_fn_expr_rettype ( FmgrInfo flinfo  ) 

Definition at line 2251 of file fmgr.c.

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

Referenced by do_compile(), and init_sql_fcache().

02252 {
02253     Node       *expr;
02254 
02255     /*
02256      * can't return anything useful if we have no FmgrInfo or if its fn_expr
02257      * node has not been initialized
02258      */
02259     if (!flinfo || !flinfo->fn_expr)
02260         return InvalidOid;
02261 
02262     expr = flinfo->fn_expr;
02263 
02264     return exprType(expr);
02265 }

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

Definition at line 1854 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, CStringGetDatum, elog, ERROR, FunctionCallInfoData::flinfo, FmgrInfo::fn_oid, FmgrInfo::fn_strict, FunctionCallInvoke, InitFunctionCallInfoData, Int32GetDatum, FunctionCallInfoData::isnull, NULL, ObjectIdGetDatum, SPI_pop_conditional(), and SPI_push_conditional().

Referenced by BuildTupleFromCStrings(), CopyFrom(), domain_in(), exec_cast_value(), ExecEvalCoerceViaIO(), hstore_populate_record(), OidInputFunctionCall(), plperl_func_handler(), plperl_modify_tuple(), plperl_return_next(), plperl_spi_exec_prepared(), plperl_spi_query_prepared(), pltcl_func_handler(), pltcl_SPI_execute_plan(), pltcl_trigger_handler(), PLy_function_handler(), PLy_modify_tuple(), PLy_spi_execute_plan(), PLyObject_ToDatum(), ReadArrayStr(), and record_in().

01855 {
01856     FunctionCallInfoData fcinfo;
01857     Datum       result;
01858     bool        pushed;
01859 
01860     if (str == NULL && flinfo->fn_strict)
01861         return (Datum) 0;       /* just return null result */
01862 
01863     pushed = SPI_push_conditional();
01864 
01865     InitFunctionCallInfoData(fcinfo, flinfo, 3, NULL, NULL);
01866 
01867     fcinfo.arg[0] = CStringGetDatum(str);
01868     fcinfo.arg[1] = ObjectIdGetDatum(typioparam);
01869     fcinfo.arg[2] = Int32GetDatum(typmod);
01870     fcinfo.argnull[0] = (str == NULL);
01871     fcinfo.argnull[1] = false;
01872     fcinfo.argnull[2] = false;
01873 
01874     result = FunctionCallInvoke(&fcinfo);
01875 
01876     /* Should get null result if and only if str is NULL */
01877     if (str == NULL)
01878     {
01879         if (!fcinfo.isnull)
01880             elog(ERROR, "input function %u returned non-NULL",
01881                  fcinfo.flinfo->fn_oid);
01882     }
01883     else
01884     {
01885         if (fcinfo.isnull)
01886             elog(ERROR, "input function %u returned NULL",
01887                  fcinfo.flinfo->fn_oid);
01888     }
01889 
01890     SPI_pop_conditional(pushed);
01891 
01892     return result;
01893 }

Datum Int64GetDatum ( int64  X  ) 

Definition at line 2108 of file fmgr.c.

References palloc, and PointerGetDatum.

Referenced by cash_numeric(), DefineSequence(), generate_series_step_int8(), int8_to_char(), leftmostvalue_int8(), leftmostvalue_money(), make_agg_subplan(), make_const(), numeric_cash(), pg_buffercache_pages(), pg_stat_file(), and txid_snapshot_xip().

02109 {
02110     int64      *retval = (int64 *) palloc(sizeof(int64));
02111 
02112     *retval = X;
02113     return PointerGetDatum(retval);
02114 }

static CFuncHashTabEntry * lookup_C_func ( HeapTuple  procedureTuple  )  [static]

Definition at line 493 of file fmgr.c.

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

Referenced by fmgr_info_C_lang().

00494 {
00495     Oid         fn_oid = HeapTupleGetOid(procedureTuple);
00496     CFuncHashTabEntry *entry;
00497 
00498     if (CFuncHash == NULL)
00499         return NULL;            /* no table yet */
00500     entry = (CFuncHashTabEntry *)
00501         hash_search(CFuncHash,
00502                     &fn_oid,
00503                     HASH_FIND,
00504                     NULL);
00505     if (entry == NULL)
00506         return NULL;            /* no such entry */
00507     if (entry->fn_xmin == HeapTupleHeaderGetXmin(procedureTuple->t_data) &&
00508         ItemPointerEquals(&entry->fn_tid, &procedureTuple->t_self))
00509         return entry;           /* OK */
00510     return NULL;                /* entry is out of date */
00511 }

Datum OidFunctionCall1 ( Oid  functionId,
Datum  arg1 
)

Definition at line 1544 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, and NULL.

Referenced by _hash_datum2hashkey_type(), examine_attribute(), ExecuteDoStmt(), getTokenTypes(), lookup_ts_dictionary_cache(), printTypmod(), ProcedureCreate(), tt_setup_firstcall(), typenameTypeMod(), and verify_dictoptions().

01545 {
01546     FmgrInfo    flinfo;
01547     FunctionCallInfoData fcinfo;
01548     Datum       result;
01549 
01550     fmgr_info(functionId, &flinfo);
01551 
01552     InitFunctionCallInfoData(fcinfo, &flinfo, 1, NULL, NULL);
01553 
01554     fcinfo.arg[0] = arg1;
01555     fcinfo.argnull[0] = false;
01556 
01557     result = FunctionCallInvoke(&fcinfo);
01558 
01559     /* Check for null result, since caller is clearly not expecting one */
01560     if (fcinfo.isnull)
01561         elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
01562 
01563     return result;
01564 }

Datum OidFunctionCall2 ( Oid  functionId,
Datum  arg1,
Datum  arg2 
)

Definition at line 1567 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, and NULL.

Referenced by _bt_compare_scankey_args(), flatten_reloptions(), index_recheck_constraint(), and transformGenericOptions().

01568 {
01569     FmgrInfo    flinfo;
01570     FunctionCallInfoData fcinfo;
01571     Datum       result;
01572 
01573     fmgr_info(functionId, &flinfo);
01574 
01575     InitFunctionCallInfoData(fcinfo, &flinfo, 2, NULL, NULL);
01576 
01577     fcinfo.arg[0] = arg1;
01578     fcinfo.arg[1] = arg2;
01579     fcinfo.argnull[0] = false;
01580     fcinfo.argnull[1] = false;
01581 
01582     result = FunctionCallInvoke(&fcinfo);
01583 
01584     /* Check for null result, since caller is clearly not expecting one */
01585     if (fcinfo.isnull)
01586         elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
01587 
01588     return result;
01589 }

Datum OidFunctionCall3 ( Oid  functionId,
Datum  arg1,
Datum  arg2,
Datum  arg3 
)

Definition at line 1592 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, and NULL.

Referenced by index_build().

01594 {
01595     FmgrInfo    flinfo;
01596     FunctionCallInfoData fcinfo;
01597     Datum       result;
01598 
01599     fmgr_info(functionId, &flinfo);
01600 
01601     InitFunctionCallInfoData(fcinfo, &flinfo, 3, NULL, NULL);
01602 
01603     fcinfo.arg[0] = arg1;
01604     fcinfo.arg[1] = arg2;
01605     fcinfo.arg[2] = arg3;
01606     fcinfo.argnull[0] = false;
01607     fcinfo.argnull[1] = false;
01608     fcinfo.argnull[2] = false;
01609 
01610     result = FunctionCallInvoke(&fcinfo);
01611 
01612     /* Check for null result, since caller is clearly not expecting one */
01613     if (fcinfo.isnull)
01614         elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
01615 
01616     return result;
01617 }

Datum OidFunctionCall4 ( Oid  functionId,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4 
)

Definition at line 1620 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, and NULL.

Referenced by restriction_selectivity().

01622 {
01623     FmgrInfo    flinfo;
01624     FunctionCallInfoData fcinfo;
01625     Datum       result;
01626 
01627     fmgr_info(functionId, &flinfo);
01628 
01629     InitFunctionCallInfoData(fcinfo, &flinfo, 4, NULL, NULL);
01630 
01631     fcinfo.arg[0] = arg1;
01632     fcinfo.arg[1] = arg2;
01633     fcinfo.arg[2] = arg3;
01634     fcinfo.arg[3] = arg4;
01635     fcinfo.argnull[0] = false;
01636     fcinfo.argnull[1] = false;
01637     fcinfo.argnull[2] = false;
01638     fcinfo.argnull[3] = false;
01639 
01640     result = FunctionCallInvoke(&fcinfo);
01641 
01642     /* Check for null result, since caller is clearly not expecting one */
01643     if (fcinfo.isnull)
01644         elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
01645 
01646     return result;
01647 }

Datum OidFunctionCall5 ( Oid  functionId,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5 
)

Definition at line 1650 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, and NULL.

Referenced by CreateConversionCommand(), join_selectivity(), and pg_do_encoding_conversion().

01652 {
01653     FmgrInfo    flinfo;
01654     FunctionCallInfoData fcinfo;
01655     Datum       result;
01656 
01657     fmgr_info(functionId, &flinfo);
01658 
01659     InitFunctionCallInfoData(fcinfo, &flinfo, 5, NULL, NULL);
01660 
01661     fcinfo.arg[0] = arg1;
01662     fcinfo.arg[1] = arg2;
01663     fcinfo.arg[2] = arg3;
01664     fcinfo.arg[3] = arg4;
01665     fcinfo.arg[4] = arg5;
01666     fcinfo.argnull[0] = false;
01667     fcinfo.argnull[1] = false;
01668     fcinfo.argnull[2] = false;
01669     fcinfo.argnull[3] = false;
01670     fcinfo.argnull[4] = false;
01671 
01672     result = FunctionCallInvoke(&fcinfo);
01673 
01674     /* Check for null result, since caller is clearly not expecting one */
01675     if (fcinfo.isnull)
01676         elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
01677 
01678     return result;
01679 }

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

Definition at line 1682 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, and NULL.

01685 {
01686     FmgrInfo    flinfo;
01687     FunctionCallInfoData fcinfo;
01688     Datum       result;
01689 
01690     fmgr_info(functionId, &flinfo);
01691 
01692     InitFunctionCallInfoData(fcinfo, &flinfo, 6, NULL, NULL);
01693 
01694     fcinfo.arg[0] = arg1;
01695     fcinfo.arg[1] = arg2;
01696     fcinfo.arg[2] = arg3;
01697     fcinfo.arg[3] = arg4;
01698     fcinfo.arg[4] = arg5;
01699     fcinfo.arg[5] = arg6;
01700     fcinfo.argnull[0] = false;
01701     fcinfo.argnull[1] = false;
01702     fcinfo.argnull[2] = false;
01703     fcinfo.argnull[3] = false;
01704     fcinfo.argnull[4] = false;
01705     fcinfo.argnull[5] = false;
01706 
01707     result = FunctionCallInvoke(&fcinfo);
01708 
01709     /* Check for null result, since caller is clearly not expecting one */
01710     if (fcinfo.isnull)
01711         elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
01712 
01713     return result;
01714 }

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

Definition at line 1717 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, and NULL.

01720 {
01721     FmgrInfo    flinfo;
01722     FunctionCallInfoData fcinfo;
01723     Datum       result;
01724 
01725     fmgr_info(functionId, &flinfo);
01726 
01727     InitFunctionCallInfoData(fcinfo, &flinfo, 7, NULL, NULL);
01728 
01729     fcinfo.arg[0] = arg1;
01730     fcinfo.arg[1] = arg2;
01731     fcinfo.arg[2] = arg3;
01732     fcinfo.arg[3] = arg4;
01733     fcinfo.arg[4] = arg5;
01734     fcinfo.arg[5] = arg6;
01735     fcinfo.arg[6] = arg7;
01736     fcinfo.argnull[0] = false;
01737     fcinfo.argnull[1] = false;
01738     fcinfo.argnull[2] = false;
01739     fcinfo.argnull[3] = false;
01740     fcinfo.argnull[4] = false;
01741     fcinfo.argnull[5] = false;
01742     fcinfo.argnull[6] = false;
01743 
01744     result = FunctionCallInvoke(&fcinfo);
01745 
01746     /* Check for null result, since caller is clearly not expecting one */
01747     if (fcinfo.isnull)
01748         elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
01749 
01750     return result;
01751 }

Datum OidFunctionCall8 ( Oid  functionId,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7,
Datum  arg8 
)

Definition at line 1754 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, and NULL.

Referenced by cost_index().

01757 {
01758     FmgrInfo    flinfo;
01759     FunctionCallInfoData fcinfo;
01760     Datum       result;
01761 
01762     fmgr_info(functionId, &flinfo);
01763 
01764     InitFunctionCallInfoData(fcinfo, &flinfo, 8, NULL, NULL);
01765 
01766     fcinfo.arg[0] = arg1;
01767     fcinfo.arg[1] = arg2;
01768     fcinfo.arg[2] = arg3;
01769     fcinfo.arg[3] = arg4;
01770     fcinfo.arg[4] = arg5;
01771     fcinfo.arg[5] = arg6;
01772     fcinfo.arg[6] = arg7;
01773     fcinfo.arg[7] = arg8;
01774     fcinfo.argnull[0] = false;
01775     fcinfo.argnull[1] = false;
01776     fcinfo.argnull[2] = false;
01777     fcinfo.argnull[3] = false;
01778     fcinfo.argnull[4] = false;
01779     fcinfo.argnull[5] = false;
01780     fcinfo.argnull[6] = false;
01781     fcinfo.argnull[7] = false;
01782 
01783     result = FunctionCallInvoke(&fcinfo);
01784 
01785     /* Check for null result, since caller is clearly not expecting one */
01786     if (fcinfo.isnull)
01787         elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
01788 
01789     return result;
01790 }

Datum OidFunctionCall9 ( Oid  functionId,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7,
Datum  arg8,
Datum  arg9 
)

Definition at line 1793 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, and NULL.

01797 {
01798     FmgrInfo    flinfo;
01799     FunctionCallInfoData fcinfo;
01800     Datum       result;
01801 
01802     fmgr_info(functionId, &flinfo);
01803 
01804     InitFunctionCallInfoData(fcinfo, &flinfo, 9, NULL, NULL);
01805 
01806     fcinfo.arg[0] = arg1;
01807     fcinfo.arg[1] = arg2;
01808     fcinfo.arg[2] = arg3;
01809     fcinfo.arg[3] = arg4;
01810     fcinfo.arg[4] = arg5;
01811     fcinfo.arg[5] = arg6;
01812     fcinfo.arg[6] = arg7;
01813     fcinfo.arg[7] = arg8;
01814     fcinfo.arg[8] = arg9;
01815     fcinfo.argnull[0] = false;
01816     fcinfo.argnull[1] = false;
01817     fcinfo.argnull[2] = false;
01818     fcinfo.argnull[3] = false;
01819     fcinfo.argnull[4] = false;
01820     fcinfo.argnull[5] = false;
01821     fcinfo.argnull[6] = false;
01822     fcinfo.argnull[7] = false;
01823     fcinfo.argnull[8] = false;
01824 
01825     result = FunctionCallInvoke(&fcinfo);
01826 
01827     /* Check for null result, since caller is clearly not expecting one */
01828     if (fcinfo.isnull)
01829         elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
01830 
01831     return result;
01832 }

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

Definition at line 2000 of file fmgr.c.

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

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

02001 {
02002     FmgrInfo    flinfo;
02003 
02004     fmgr_info(functionId, &flinfo);
02005     return InputFunctionCall(&flinfo, str, typioparam, typmod);
02006 }

char* OidOutputFunctionCall ( Oid  functionId,
Datum  val 
)

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

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

02020 {
02021     FmgrInfo    flinfo;
02022 
02023     fmgr_info(functionId, &flinfo);
02024     return ReceiveFunctionCall(&flinfo, buf, typioparam, typmod);
02025 }

bytea* OidSendFunctionCall ( Oid  functionId,
Datum  val 
)

Definition at line 2028 of file fmgr.c.

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

Referenced by SendFunctionResult().

02029 {
02030     FmgrInfo    flinfo;
02031 
02032     fmgr_info(functionId, &flinfo);
02033     return SendFunctionCall(&flinfo, val);
02034 }

char* OutputFunctionCall ( FmgrInfo flinfo,
Datum  val 
)

Definition at line 1904 of file fmgr.c.

References DatumGetCString, FunctionCall1(), SPI_pop_conditional(), and SPI_push_conditional().

Referenced by array_out(), array_to_text_internal(), CopyOneRowTo(), ExecEvalCoerceViaIO(), hstore_from_record(), OidOutputFunctionCall(), plperl_call_perl_func(), pltcl_func_handler(), PLyString_FromDatum(), printtup(), printtup_20(), and record_out().

01905 {
01906     char       *result;
01907     bool        pushed;
01908 
01909     pushed = SPI_push_conditional();
01910 
01911     result = DatumGetCString(FunctionCall1(flinfo, val));
01912 
01913     SPI_pop_conditional(pushed);
01914 
01915     return result;
01916 }

struct varlena* pg_detoast_datum ( struct varlena datum  )  [read]

Definition at line 2196 of file fmgr.c.

References heap_tuple_untoast_attr(), and VARATT_IS_EXTENDED.

02197 {
02198     if (VARATT_IS_EXTENDED(datum))
02199         return heap_tuple_untoast_attr(datum);
02200     else
02201         return datum;
02202 }

struct varlena* pg_detoast_datum_copy ( struct varlena datum  )  [read]

Definition at line 2205 of file fmgr.c.

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

02206 {
02207     if (VARATT_IS_EXTENDED(datum))
02208         return heap_tuple_untoast_attr(datum);
02209     else
02210     {
02211         /* Make a modifiable copy of the varlena object */
02212         Size        len = VARSIZE(datum);
02213         struct varlena *result = (struct varlena *) palloc(len);
02214 
02215         memcpy(result, datum, len);
02216         return result;
02217     }
02218 }

struct varlena* pg_detoast_datum_packed ( struct varlena datum  )  [read]

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

02229 {
02230     if (VARATT_IS_COMPRESSED(datum) || VARATT_IS_EXTERNAL(datum))
02231         return heap_tuple_untoast_attr(datum);
02232     else
02233         return datum;
02234 }

struct varlena* pg_detoast_datum_slice ( struct varlena datum,
int32  first,
int32  count 
) [read]

Definition at line 2221 of file fmgr.c.

References heap_tuple_untoast_attr_slice().

02222 {
02223     /* Only get the specified portion from the toast rel */
02224     return heap_tuple_untoast_attr_slice(datum, first, count);
02225 }

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

Definition at line 1928 of file fmgr.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, elog, ERROR, FunctionCallInfoData::flinfo, FmgrInfo::fn_oid, FmgrInfo::fn_strict, FunctionCallInvoke, InitFunctionCallInfoData, Int32GetDatum, FunctionCallInfoData::isnull, NULL, ObjectIdGetDatum, PointerGetDatum, SPI_pop_conditional(), and SPI_push_conditional().

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

01930 {
01931     FunctionCallInfoData fcinfo;
01932     Datum       result;
01933     bool        pushed;
01934 
01935     if (buf == NULL && flinfo->fn_strict)
01936         return (Datum) 0;       /* just return null result */
01937 
01938     pushed = SPI_push_conditional();
01939 
01940     InitFunctionCallInfoData(fcinfo, flinfo, 3, NULL, NULL);
01941 
01942     fcinfo.arg[0] = PointerGetDatum(buf);
01943     fcinfo.arg[1] = ObjectIdGetDatum(typioparam);
01944     fcinfo.arg[2] = Int32GetDatum(typmod);
01945     fcinfo.argnull[0] = (buf == NULL);
01946     fcinfo.argnull[1] = false;
01947     fcinfo.argnull[2] = false;
01948 
01949     result = FunctionCallInvoke(&fcinfo);
01950 
01951     /* Should get null result if and only if buf is NULL */
01952     if (buf == NULL)
01953     {
01954         if (!fcinfo.isnull)
01955             elog(ERROR, "receive function %u returned non-NULL",
01956                  fcinfo.flinfo->fn_oid);
01957     }
01958     else
01959     {
01960         if (fcinfo.isnull)
01961             elog(ERROR, "receive function %u returned NULL",
01962                  fcinfo.flinfo->fn_oid);
01963     }
01964 
01965     SPI_pop_conditional(pushed);
01966 
01967     return result;
01968 }

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

Definition at line 517 of file fmgr.c.

References HASHCTL::entrysize, CFuncHashTabEntry::fn_tid, CFuncHashTabEntry::fn_xmin, HASHCTL::hash, hash_create(), HASH_ELEM, HASH_ENTER, HASH_FUNCTION, hash_search(), HeapTupleGetOid, HeapTupleHeaderGetXmin, CFuncHashTabEntry::inforec, HASHCTL::keysize, MemSet, NULL, oid_hash(), HeapTupleData::t_data, HeapTupleData::t_self, and CFuncHashTabEntry::user_fn.

Referenced by fmgr_info_C_lang().

00519 {
00520     Oid         fn_oid = HeapTupleGetOid(procedureTuple);
00521     CFuncHashTabEntry *entry;
00522     bool        found;
00523 
00524     /* Create the hash table if it doesn't exist yet */
00525     if (CFuncHash == NULL)
00526     {
00527         HASHCTL     hash_ctl;
00528 
00529         MemSet(&hash_ctl, 0, sizeof(hash_ctl));
00530         hash_ctl.keysize = sizeof(Oid);
00531         hash_ctl.entrysize = sizeof(CFuncHashTabEntry);
00532         hash_ctl.hash = oid_hash;
00533         CFuncHash = hash_create("CFuncHash",
00534                                 100,
00535                                 &hash_ctl,
00536                                 HASH_ELEM | HASH_FUNCTION);
00537     }
00538 
00539     entry = (CFuncHashTabEntry *)
00540         hash_search(CFuncHash,
00541                     &fn_oid,
00542                     HASH_ENTER,
00543                     &found);
00544     /* OID is already filled in */
00545     entry->fn_xmin = HeapTupleHeaderGetXmin(procedureTuple->t_data);
00546     entry->fn_tid = procedureTuple->t_self;
00547     entry->user_fn = user_fn;
00548     entry->inforec = inforec;
00549 }

bytea* SendFunctionCall ( FmgrInfo flinfo,
Datum  val 
)

Definition at line 1981 of file fmgr.c.

References DatumGetByteaP, FunctionCall1(), SPI_pop_conditional(), and SPI_push_conditional().

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

01982 {
01983     bytea      *result;
01984     bool        pushed;
01985 
01986     pushed = SPI_push_conditional();
01987 
01988     result = DatumGetByteaP(FunctionCall1(flinfo, val));
01989 
01990     SPI_pop_conditional(pushed);
01991 
01992     return result;
01993 }


Variable Documentation

HTAB* CFuncHash = NULL [static]

Definition at line 78 of file fmgr.c.


Generated on Thu Sep 2 03:11:10 2010 for PostgreSQL Source Code by  doxygen 1.5.8