Header And Logo

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

Data Structures | Typedefs | Functions | Variables

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 DirectFunctionCall1Coll (PGFunction func, Oid collation, Datum arg1)
Datum DirectFunctionCall2Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2)
Datum DirectFunctionCall3Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3)
Datum DirectFunctionCall4Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4)
Datum DirectFunctionCall5Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5)
Datum DirectFunctionCall6Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6)
Datum DirectFunctionCall7Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7)
Datum DirectFunctionCall8Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8)
Datum DirectFunctionCall9Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8, Datum arg9)
Datum FunctionCall1Coll (FmgrInfo *flinfo, Oid collation, Datum arg1)
Datum FunctionCall2Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Datum FunctionCall3Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3)
Datum FunctionCall4Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4)
Datum FunctionCall5Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5)
Datum FunctionCall6Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6)
Datum FunctionCall7Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7)
Datum FunctionCall8Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8)
Datum FunctionCall9Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8, Datum arg9)
Datum OidFunctionCall0Coll (Oid functionId, Oid collation)
Datum OidFunctionCall1Coll (Oid functionId, Oid collation, Datum arg1)
Datum OidFunctionCall2Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2)
Datum OidFunctionCall3Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3)
Datum OidFunctionCall4Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4)
Datum OidFunctionCall5Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5)
Datum OidFunctionCall6Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6)
Datum OidFunctionCall7Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7)
Datum OidFunctionCall8Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8)
Datum OidFunctionCall9Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8, Datum arg9)
Datum InputFunctionCall (FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
char * OutputFunctionCall (FmgrInfo *flinfo, Datum val)
Datum ReceiveFunctionCall (FmgrInfo *flinfo, StringInfo buf, Oid typioparam, int32 typmod)
byteaSendFunctionCall (FmgrInfo *flinfo, Datum val)
Datum OidInputFunctionCall (Oid functionId, char *str, Oid typioparam, int32 typmod)
char * OidOutputFunctionCall (Oid functionId, Datum val)
Datum OidReceiveFunctionCall (Oid functionId, StringInfo buf, Oid typioparam, int32 typmod)
byteaOidSendFunctionCall (Oid functionId, Datum val)
char * fmgr (Oid procedureId,...)
Datum Int64GetDatum (int64 X)
Datum Float4GetDatum (float4 X)
Datum Float8GetDatum (float8 X)
struct varlenapg_detoast_datum (struct varlena *datum)
struct varlenapg_detoast_datum_copy (struct varlena *datum)
struct varlenapg_detoast_datum_slice (struct varlena *datum, int32 first, int32 count)
struct varlenapg_detoast_datum_packed (struct varlena *datum)
Oid get_fn_expr_rettype (FmgrInfo *flinfo)
Oid get_fn_expr_argtype (FmgrInfo *flinfo, int argnum)
Oid get_call_expr_argtype (Node *expr, int argnum)
bool get_fn_expr_arg_stable (FmgrInfo *flinfo, int argnum)
bool get_call_expr_arg_stable (Node *expr, int argnum)
bool get_fn_expr_variadic (FmgrInfo *flinfo)

Variables

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

Typedef Documentation

typedef char*(* func_ptr)()

Definition at line 57 of file fmgr.c.


Function Documentation

void clear_external_function_hash ( void *  filehandle  ) 

Definition at line 571 of file fmgr.c.

References hash_destroy().

Referenced by internal_unload_library().

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

Definition at line 1020 of file fmgr.c.

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

Referenced by Generic_Text_IC_like().

{
    FunctionCallInfoData fcinfo;
    Datum       result;

    InitFunctionCallInfoData(fcinfo, NULL, 1, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.argnull[0] = false;

    result = (*func) (&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %p returned NULL", (void *) func);

    return result;
}

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

Definition at line 1040 of file fmgr.c.

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

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

{
    FunctionCallInfoData fcinfo;
    Datum       result;

    InitFunctionCallInfoData(fcinfo, NULL, 2, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.arg[1] = arg2;
    fcinfo.argnull[0] = false;
    fcinfo.argnull[1] = false;

    result = (*func) (&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %p returned NULL", (void *) func);

    return result;
}

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

Definition at line 1062 of file fmgr.c.

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

{
    FunctionCallInfoData fcinfo;
    Datum       result;

    InitFunctionCallInfoData(fcinfo, NULL, 3, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.arg[1] = arg2;
    fcinfo.arg[2] = arg3;
    fcinfo.argnull[0] = false;
    fcinfo.argnull[1] = false;
    fcinfo.argnull[2] = false;

    result = (*func) (&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %p returned NULL", (void *) func);

    return result;
}

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

Definition at line 1087 of file fmgr.c.

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

Referenced by execute_extension_script().

{
    FunctionCallInfoData fcinfo;
    Datum       result;

    InitFunctionCallInfoData(fcinfo, NULL, 4, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.arg[1] = arg2;
    fcinfo.arg[2] = arg3;
    fcinfo.arg[3] = arg4;
    fcinfo.argnull[0] = false;
    fcinfo.argnull[1] = false;
    fcinfo.argnull[2] = false;
    fcinfo.argnull[3] = false;

    result = (*func) (&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %p returned NULL", (void *) func);

    return result;
}

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

Definition at line 1114 of file fmgr.c.

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

{
    FunctionCallInfoData fcinfo;
    Datum       result;

    InitFunctionCallInfoData(fcinfo, NULL, 5, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.arg[1] = arg2;
    fcinfo.arg[2] = arg3;
    fcinfo.arg[3] = arg4;
    fcinfo.arg[4] = arg5;
    fcinfo.argnull[0] = false;
    fcinfo.argnull[1] = false;
    fcinfo.argnull[2] = false;
    fcinfo.argnull[3] = false;
    fcinfo.argnull[4] = false;

    result = (*func) (&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %p returned NULL", (void *) func);

    return result;
}

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

Definition at line 1143 of file fmgr.c.

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

{
    FunctionCallInfoData fcinfo;
    Datum       result;

    InitFunctionCallInfoData(fcinfo, NULL, 6, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.arg[1] = arg2;
    fcinfo.arg[2] = arg3;
    fcinfo.arg[3] = arg4;
    fcinfo.arg[4] = arg5;
    fcinfo.arg[5] = arg6;
    fcinfo.argnull[0] = false;
    fcinfo.argnull[1] = false;
    fcinfo.argnull[2] = false;
    fcinfo.argnull[3] = false;
    fcinfo.argnull[4] = false;
    fcinfo.argnull[5] = false;

    result = (*func) (&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %p returned NULL", (void *) func);

    return result;
}

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

Definition at line 1175 of file fmgr.c.

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

{
    FunctionCallInfoData fcinfo;
    Datum       result;

    InitFunctionCallInfoData(fcinfo, NULL, 7, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.arg[1] = arg2;
    fcinfo.arg[2] = arg3;
    fcinfo.arg[3] = arg4;
    fcinfo.arg[4] = arg5;
    fcinfo.arg[5] = arg6;
    fcinfo.arg[6] = arg7;
    fcinfo.argnull[0] = false;
    fcinfo.argnull[1] = false;
    fcinfo.argnull[2] = false;
    fcinfo.argnull[3] = false;
    fcinfo.argnull[4] = false;
    fcinfo.argnull[5] = false;
    fcinfo.argnull[6] = false;

    result = (*func) (&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %p returned NULL", (void *) func);

    return result;
}

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

Definition at line 1209 of file fmgr.c.

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

{
    FunctionCallInfoData fcinfo;
    Datum       result;

    InitFunctionCallInfoData(fcinfo, NULL, 8, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.arg[1] = arg2;
    fcinfo.arg[2] = arg3;
    fcinfo.arg[3] = arg4;
    fcinfo.arg[4] = arg5;
    fcinfo.arg[5] = arg6;
    fcinfo.arg[6] = arg7;
    fcinfo.arg[7] = arg8;
    fcinfo.argnull[0] = false;
    fcinfo.argnull[1] = false;
    fcinfo.argnull[2] = false;
    fcinfo.argnull[3] = false;
    fcinfo.argnull[4] = false;
    fcinfo.argnull[5] = false;
    fcinfo.argnull[6] = false;
    fcinfo.argnull[7] = false;

    result = (*func) (&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %p returned NULL", (void *) func);

    return result;
}

Datum DirectFunctionCall9Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7,
Datum  arg8,
Datum  arg9 
)

Definition at line 1245 of file fmgr.c.

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

{
    FunctionCallInfoData fcinfo;
    Datum       result;

    InitFunctionCallInfoData(fcinfo, NULL, 9, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.arg[1] = arg2;
    fcinfo.arg[2] = arg3;
    fcinfo.arg[3] = arg4;
    fcinfo.arg[4] = arg5;
    fcinfo.arg[5] = arg6;
    fcinfo.arg[6] = arg7;
    fcinfo.arg[7] = arg8;
    fcinfo.arg[8] = arg9;
    fcinfo.argnull[0] = false;
    fcinfo.argnull[1] = false;
    fcinfo.argnull[2] = false;
    fcinfo.argnull[3] = false;
    fcinfo.argnull[4] = false;
    fcinfo.argnull[5] = false;
    fcinfo.argnull[6] = false;
    fcinfo.argnull[7] = false;
    fcinfo.argnull[8] = false;

    result = (*func) (&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %p returned NULL", (void *) func);

    return result;
}

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

Definition at line 444 of file fmgr.c.

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

Referenced by fmgr_c_validator(), and fmgr_info_C_lang().

{
    char       *infofuncname;
    PGFInfoFunction infofunc;
    const Pg_finfo_record *inforec;
    static Pg_finfo_record default_inforec = {0};

    /* Compute name of info func */
    infofuncname = (char *) palloc(strlen(funcname) + 10);
    strcpy(infofuncname, "pg_finfo_");
    strcat(infofuncname, funcname);

    /* Try to look up the info function */
    infofunc = (PGFInfoFunction) lookup_external_function(filehandle,
                                                          infofuncname);
    if (infofunc == NULL)
    {
        /* Not found --- assume version 0 */
        pfree(infofuncname);
        return &default_inforec;
    }

    /* Found, so call it */
    inforec = (*infofunc) ();

    /* Validate result as best we can */
    if (inforec == NULL)
        elog(ERROR, "null result from info function \"%s\"", infofuncname);
    switch (inforec->api_version)
    {
        case 0:
        case 1:
            /* OK, no additional fields to validate */
            break;
        default:
            ereport(ERROR,
                    (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                     errmsg("unrecognized API version %d reported by info function \"%s\"",
                            inforec->api_version, infofuncname)));
            break;
    }

    pfree(infofuncname);
    return inforec;
}

Datum Float4GetDatum ( float4  X  ) 

Definition at line 2160 of file fmgr.c.

References palloc(), PointerGetDatum, SET_4_BYTES, and value.

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

{
#ifdef USE_FLOAT4_BYVAL
    union
    {
        float4      value;
        int32       retval;
    }           myunion;

    myunion.value = X;
    return SET_4_BYTES(myunion.retval);
#else
    float4     *retval = (float4 *) palloc(sizeof(float4));

    *retval = X;
    return PointerGetDatum(retval);
#endif
}

Datum Float8GetDatum ( float8  X  ) 

Definition at line 2196 of file fmgr.c.

References palloc(), PointerGetDatum, and value.

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

{
#ifdef USE_FLOAT8_BYVAL
    union
    {
        float8      value;
        int64       retval;
    }           myunion;

    myunion.value = X;
    return SET_8_BYTES(myunion.retval);
#else
    float8     *retval = (float8 *) palloc(sizeof(float8));

    *retval = X;
    return PointerGetDatum(retval);
#endif
}

char* fmgr ( Oid  procedureId,
  ... 
)

Definition at line 2091 of file fmgr.c.

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

{
    FmgrInfo    flinfo;
    FunctionCallInfoData fcinfo;
    int         n_arguments;
    Datum       result;

    fmgr_info(procedureId, &flinfo);

    MemSet(&fcinfo, 0, sizeof(fcinfo));
    fcinfo.flinfo = &flinfo;
    fcinfo.nargs = flinfo.fn_nargs;
    n_arguments = fcinfo.nargs;

    if (n_arguments > 0)
    {
        va_list     pvar;
        int         i;

        if (n_arguments > FUNC_MAX_ARGS)
            ereport(ERROR,
                    (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
             errmsg("function %u has too many arguments (%d, maximum is %d)",
                    flinfo.fn_oid, n_arguments, FUNC_MAX_ARGS)));
        va_start(pvar, procedureId);
        for (i = 0; i < n_arguments; i++)
            fcinfo.arg[i] = PointerGetDatum(va_arg(pvar, char *));
        va_end(pvar);
    }

    result = FunctionCallInvoke(&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %u returned NULL", flinfo.fn_oid);

    return DatumGetPointer(result);
}

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

Definition at line 305 of file fmgr.c.

References Anum_pg_proc_probin, Anum_pg_proc_prosrc, Pg_finfo_record::api_version, Oldstyle_fnextra::arg_toastable, elog, ERROR, fetch_finfo_record(), 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().

{
    Form_pg_proc procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
    CFuncHashTabEntry *hashentry;
    PGFunction  user_fn;
    const Pg_finfo_record *inforec;
    Oldstyle_fnextra *fnextra;
    bool        isnull;
    int         i;

    /*
     * See if we have the function address cached already
     */
    hashentry = lookup_C_func(procedureTuple);
    if (hashentry)
    {
        user_fn = hashentry->user_fn;
        inforec = hashentry->inforec;
    }
    else
    {
        Datum       prosrcattr,
                    probinattr;
        char       *prosrcstring,
                   *probinstring;
        void       *libraryhandle;

        /*
         * Get prosrc and probin strings (link symbol and library filename).
         * While in general these columns might be null, that's not allowed
         * for C-language functions.
         */
        prosrcattr = SysCacheGetAttr(PROCOID, procedureTuple,
                                     Anum_pg_proc_prosrc, &isnull);
        if (isnull)
            elog(ERROR, "null prosrc for C function %u", functionId);
        prosrcstring = TextDatumGetCString(prosrcattr);

        probinattr = SysCacheGetAttr(PROCOID, procedureTuple,
                                     Anum_pg_proc_probin, &isnull);
        if (isnull)
            elog(ERROR, "null probin for C function %u", functionId);
        probinstring = TextDatumGetCString(probinattr);

        /* Look up the function itself */
        user_fn = load_external_function(probinstring, prosrcstring, true,
                                         &libraryhandle);

        /* Get the function information record (real or default) */
        inforec = fetch_finfo_record(libraryhandle, prosrcstring);

        /* Cache the addresses for later calls */
        record_C_func(procedureTuple, user_fn, inforec);

        pfree(prosrcstring);
        pfree(probinstring);
    }

    switch (inforec->api_version)
    {
        case 0:
            /* Old style: need to use a handler */
            finfo->fn_addr = fmgr_oldstyle;
            fnextra = (Oldstyle_fnextra *)
                MemoryContextAllocZero(finfo->fn_mcxt,
                                       sizeof(Oldstyle_fnextra));
            finfo->fn_extra = (void *) fnextra;
            fnextra->func = (func_ptr) user_fn;
            for (i = 0; i < procedureStruct->pronargs; i++)
            {
                fnextra->arg_toastable[i] =
                    TypeIsToastable(procedureStruct->proargtypes.values[i]);
            }
            break;
        case 1:
            /* New style: call directly */
            finfo->fn_addr = user_fn;
            break;
        default:
            /* Shouldn't get here if fetch_finfo_record did its job */
            elog(ERROR, "unrecognized function API version: %d",
                 inforec->api_version);
            break;
    }
}

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

Definition at line 587 of file fmgr.c.

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

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

{
    memcpy(dstinfo, srcinfo, sizeof(FmgrInfo));
    dstinfo->fn_mcxt = destcxt;
    if (dstinfo->fn_addr == fmgr_oldstyle)
    {
        /* For oldstyle functions we must copy fn_extra */
        Oldstyle_fnextra *fnextra;

        fnextra = (Oldstyle_fnextra *)
            MemoryContextAlloc(destcxt, sizeof(Oldstyle_fnextra));
        memcpy(fnextra, srcinfo->fn_extra, sizeof(Oldstyle_fnextra));
        dstinfo->fn_extra = (void *) fnextra;
    }
    else
        dstinfo->fn_extra = NULL;
}

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

References Anum_pg_proc_proconfig, Anum_pg_proc_prosrc, ClanguageId, elog, ereport, errcode(), errmsg(), ERROR, fmgr_info_C_lang(), fmgr_info_other_lang(), fmgr_isbuiltin(), fmgr_lookupByName(), FmgrHookIsNeeded, FmgrInfo::fn_addr, FmgrInfo::fn_expr, FmgrInfo::fn_extra, FmgrInfo::fn_mcxt, FmgrInfo::fn_nargs, FmgrInfo::fn_oid, FmgrInfo::fn_retset, FmgrInfo::fn_stats, FmgrInfo::fn_strict, FmgrBuiltin::func, GETSTRUCT, heap_attisnull(), HeapTupleIsValid, INTERNALlanguageId, FmgrBuiltin::nargs, NULL, ObjectIdGetDatum, pfree(), PROCOID, ReleaseSysCache(), FmgrBuiltin::retset, SearchSysCache1, SQLlanguageId, FmgrBuiltin::strict, SysCacheGetAttr(), and TextDatumGetCString.

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

{
    const FmgrBuiltin *fbp;
    HeapTuple   procedureTuple;
    Form_pg_proc procedureStruct;
    Datum       prosrcdatum;
    bool        isnull;
    char       *prosrc;

    /*
     * fn_oid *must* be filled in last.  Some code assumes that if fn_oid is
     * valid, the whole struct is valid.  Some FmgrInfo struct's do survive
     * elogs.
     */
    finfo->fn_oid = InvalidOid;
    finfo->fn_extra = NULL;
    finfo->fn_mcxt = mcxt;
    finfo->fn_expr = NULL;      /* caller may set this later */

    if ((fbp = fmgr_isbuiltin(functionId)) != NULL)
    {
        /*
         * Fast path for builtin functions: don't bother consulting pg_proc
         */
        finfo->fn_nargs = fbp->nargs;
        finfo->fn_strict = fbp->strict;
        finfo->fn_retset = fbp->retset;
        finfo->fn_stats = TRACK_FUNC_ALL;       /* ie, never track */
        finfo->fn_addr = fbp->func;
        finfo->fn_oid = functionId;
        return;
    }

    /* Otherwise we need the pg_proc entry */
    procedureTuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(functionId));
    if (!HeapTupleIsValid(procedureTuple))
        elog(ERROR, "cache lookup failed for function %u", functionId);
    procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);

    finfo->fn_nargs = procedureStruct->pronargs;
    finfo->fn_strict = procedureStruct->proisstrict;
    finfo->fn_retset = procedureStruct->proretset;

    /*
     * If it has prosecdef set, non-null proconfig, or if a plugin wants to
     * hook function entry/exit, use fmgr_security_definer call handler ---
     * unless we are being called again by fmgr_security_definer or
     * fmgr_info_other_lang.
     *
     * When using fmgr_security_definer, function stats tracking is always
     * disabled at the outer level, and instead we set the flag properly in
     * fmgr_security_definer's private flinfo and implement the tracking
     * inside fmgr_security_definer.  This loses the ability to charge the
     * overhead of fmgr_security_definer to the function, but gains the
     * ability to set the track_functions GUC as a local GUC parameter of an
     * interesting function and have the right things happen.
     */
    if (!ignore_security &&
        (procedureStruct->prosecdef ||
         !heap_attisnull(procedureTuple, Anum_pg_proc_proconfig) ||
         FmgrHookIsNeeded(functionId)))
    {
        finfo->fn_addr = fmgr_security_definer;
        finfo->fn_stats = TRACK_FUNC_ALL;       /* ie, never track */
        finfo->fn_oid = functionId;
        ReleaseSysCache(procedureTuple);
        return;
    }

    switch (procedureStruct->prolang)
    {
        case INTERNALlanguageId:

            /*
             * For an ordinary builtin function, we should never get here
             * because the isbuiltin() search above will have succeeded.
             * However, if the user has done a CREATE FUNCTION to create an
             * alias for a builtin function, we can end up here.  In that case
             * we have to look up the function by name.  The name of the
             * internal function is stored in prosrc (it doesn't have to be
             * the same as the name of the alias!)
             */
            prosrcdatum = SysCacheGetAttr(PROCOID, procedureTuple,
                                          Anum_pg_proc_prosrc, &isnull);
            if (isnull)
                elog(ERROR, "null prosrc");
            prosrc = TextDatumGetCString(prosrcdatum);
            fbp = fmgr_lookupByName(prosrc);
            if (fbp == NULL)
                ereport(ERROR,
                        (errcode(ERRCODE_UNDEFINED_FUNCTION),
                         errmsg("internal function \"%s\" is not in internal lookup table",
                                prosrc)));
            pfree(prosrc);
            /* Should we check that nargs, strict, retset match the table? */
            finfo->fn_addr = fbp->func;
            /* note this policy is also assumed in fast path above */
            finfo->fn_stats = TRACK_FUNC_ALL;   /* ie, never track */
            break;

        case ClanguageId:
            fmgr_info_C_lang(functionId, finfo, procedureTuple);
            finfo->fn_stats = TRACK_FUNC_PL;    /* ie, track if ALL */
            break;

        case SQLlanguageId:
            finfo->fn_addr = fmgr_sql;
            finfo->fn_stats = TRACK_FUNC_PL;    /* ie, track if ALL */
            break;

        default:
            fmgr_info_other_lang(functionId, finfo, procedureTuple);
            finfo->fn_stats = TRACK_FUNC_OFF;   /* ie, track if not OFF */
            break;
    }

    finfo->fn_oid = functionId;
    ReleaseSysCache(procedureTuple);
}

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

Definition at line 396 of file fmgr.c.

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

Referenced by fmgr_info_cxt_security().

{
    Form_pg_proc procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
    Oid         language = procedureStruct->prolang;
    HeapTuple   languageTuple;
    Form_pg_language languageStruct;
    FmgrInfo    plfinfo;

    languageTuple = SearchSysCache1(LANGOID, ObjectIdGetDatum(language));
    if (!HeapTupleIsValid(languageTuple))
        elog(ERROR, "cache lookup failed for language %u", language);
    languageStruct = (Form_pg_language) GETSTRUCT(languageTuple);

    /*
     * Look up the language's call handler function, ignoring any attributes
     * that would normally cause insertion of fmgr_security_definer.  We need
     * to get back a bare pointer to the actual C-language function.
     */
    fmgr_info_cxt_security(languageStruct->lanplcallfoid, &plfinfo,
                           CurrentMemoryContext, true);
    finfo->fn_addr = plfinfo.fn_addr;

    /*
     * If lookup of the PL handler function produced nonnull fn_extra,
     * complain --- it must be an oldstyle function! We no longer support
     * oldstyle PL handlers.
     */
    if (plfinfo.fn_extra != NULL)
        elog(ERROR, "language %u has old-style handler", language);

    ReleaseSysCache(languageTuple);
}

Oid fmgr_internal_function ( const char *  proname  ) 

Definition at line 613 of file fmgr.c.

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

Referenced by fmgr_internal_validator().

{
    const FmgrBuiltin *fbp = fmgr_lookupByName(proname);

    if (fbp == NULL)
        return InvalidOid;
    return fbp->foid;
}

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

Definition at line 103 of file fmgr.c.

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

Referenced by fmgr_info_cxt_security().

{
    int         low = 0;
    int         high = fmgr_nbuiltins - 1;

    /*
     * Loop invariant: low is the first index that could contain target entry,
     * and high is the last index that could contain it.
     */
    while (low <= high)
    {
        int         i = (high + low) / 2;
        const FmgrBuiltin *ptr = &fmgr_builtins[i];

        if (id == ptr->foid)
            return ptr;
        else if (id > ptr->foid)
            low = i + 1;
        else
            high = i - 1;
    }
    return NULL;
}

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

Definition at line 133 of file fmgr.c.

References fmgr_builtins, fmgr_nbuiltins, and i.

Referenced by fmgr_info_cxt_security(), and fmgr_internal_function().

{
    int         i;

    for (i = 0; i < fmgr_nbuiltins; i++)
    {
        if (strcmp(name, fmgr_builtins[i].funcName) == 0)
            return fmgr_builtins + i;
    }
    return NULL;
}

static Datum fmgr_oldstyle ( PG_FUNCTION_ARGS   )  [static]

Definition at line 627 of file fmgr.c.

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

Referenced by fmgr_info_copy().

{
    Oldstyle_fnextra *fnextra;
    int         n_arguments = fcinfo->nargs;
    int         i;
    bool        isnull;
    func_ptr    user_fn;
    char       *returnValue;

    if (fcinfo->flinfo == NULL || fcinfo->flinfo->fn_extra == NULL)
        elog(ERROR, "fmgr_oldstyle received NULL pointer");
    fnextra = (Oldstyle_fnextra *) fcinfo->flinfo->fn_extra;

    /*
     * Result is NULL if any argument is NULL, but we still call the function
     * (peculiar, but that's the way it worked before, and after all this is a
     * backwards-compatibility wrapper).  Note, however, that we'll never get
     * here with NULL arguments if the function is marked strict.
     *
     * We also need to detoast any TOAST-ed inputs, since it's unlikely that
     * an old-style function knows about TOASTing.
     */
    isnull = false;
    for (i = 0; i < n_arguments; i++)
    {
        if (PG_ARGISNULL(i))
            isnull = true;
        else if (fnextra->arg_toastable[i])
            fcinfo->arg[i] = PointerGetDatum(PG_DETOAST_DATUM(fcinfo->arg[i]));
    }
    fcinfo->isnull = isnull;

    user_fn = fnextra->func;

    switch (n_arguments)
    {
        case 0:
            returnValue = (char *) (*user_fn) ();
            break;
        case 1:

            /*
             * nullvalue() used to use isNull to check if arg is NULL; perhaps
             * there are other functions still out there that also rely on
             * this undocumented hack?
             */
            returnValue = (char *) (*user_fn) (fcinfo->arg[0],
                                               &fcinfo->isnull);
            break;
        case 2:
            returnValue = (char *) (*user_fn) (fcinfo->arg[0],
                                               fcinfo->arg[1]);
            break;
        case 3:
            returnValue = (char *) (*user_fn) (fcinfo->arg[0],
                                               fcinfo->arg[1],
                                               fcinfo->arg[2]);
            break;
        case 4:
            returnValue = (char *) (*user_fn) (fcinfo->arg[0],
                                               fcinfo->arg[1],
                                               fcinfo->arg[2],
                                               fcinfo->arg[3]);
            break;
        case 5:
            returnValue = (char *) (*user_fn) (fcinfo->arg[0],
                                               fcinfo->arg[1],
                                               fcinfo->arg[2],
                                               fcinfo->arg[3],
                                               fcinfo->arg[4]);
            break;
        case 6:
            returnValue = (char *) (*user_fn) (fcinfo->arg[0],
                                               fcinfo->arg[1],
                                               fcinfo->arg[2],
                                               fcinfo->arg[3],
                                               fcinfo->arg[4],
                                               fcinfo->arg[5]);
            break;
        case 7:
            returnValue = (char *) (*user_fn) (fcinfo->arg[0],
                                               fcinfo->arg[1],
                                               fcinfo->arg[2],
                                               fcinfo->arg[3],
                                               fcinfo->arg[4],
                                               fcinfo->arg[5],
                                               fcinfo->arg[6]);
            break;
        case 8:
            returnValue = (char *) (*user_fn) (fcinfo->arg[0],
                                               fcinfo->arg[1],
                                               fcinfo->arg[2],
                                               fcinfo->arg[3],
                                               fcinfo->arg[4],
                                               fcinfo->arg[5],
                                               fcinfo->arg[6],
                                               fcinfo->arg[7]);
            break;
        case 9:
            returnValue = (char *) (*user_fn) (fcinfo->arg[0],
                                               fcinfo->arg[1],
                                               fcinfo->arg[2],
                                               fcinfo->arg[3],
                                               fcinfo->arg[4],
                                               fcinfo->arg[5],
                                               fcinfo->arg[6],
                                               fcinfo->arg[7],
                                               fcinfo->arg[8]);
            break;
        case 10:
            returnValue = (char *) (*user_fn) (fcinfo->arg[0],
                                               fcinfo->arg[1],
                                               fcinfo->arg[2],
                                               fcinfo->arg[3],
                                               fcinfo->arg[4],
                                               fcinfo->arg[5],
                                               fcinfo->arg[6],
                                               fcinfo->arg[7],
                                               fcinfo->arg[8],
                                               fcinfo->arg[9]);
            break;
        case 11:
            returnValue = (char *) (*user_fn) (fcinfo->arg[0],
                                               fcinfo->arg[1],
                                               fcinfo->arg[2],
                                               fcinfo->arg[3],
                                               fcinfo->arg[4],
                                               fcinfo->arg[5],
                                               fcinfo->arg[6],
                                               fcinfo->arg[7],
                                               fcinfo->arg[8],
                                               fcinfo->arg[9],
                                               fcinfo->arg[10]);
            break;
        case 12:
            returnValue = (char *) (*user_fn) (fcinfo->arg[0],
                                               fcinfo->arg[1],
                                               fcinfo->arg[2],
                                               fcinfo->arg[3],
                                               fcinfo->arg[4],
                                               fcinfo->arg[5],
                                               fcinfo->arg[6],
                                               fcinfo->arg[7],
                                               fcinfo->arg[8],
                                               fcinfo->arg[9],
                                               fcinfo->arg[10],
                                               fcinfo->arg[11]);
            break;
        case 13:
            returnValue = (char *) (*user_fn) (fcinfo->arg[0],
                                               fcinfo->arg[1],
                                               fcinfo->arg[2],
                                               fcinfo->arg[3],
                                               fcinfo->arg[4],
                                               fcinfo->arg[5],
                                               fcinfo->arg[6],
                                               fcinfo->arg[7],
                                               fcinfo->arg[8],
                                               fcinfo->arg[9],
                                               fcinfo->arg[10],
                                               fcinfo->arg[11],
                                               fcinfo->arg[12]);
            break;
        case 14:
            returnValue = (char *) (*user_fn) (fcinfo->arg[0],
                                               fcinfo->arg[1],
                                               fcinfo->arg[2],
                                               fcinfo->arg[3],
                                               fcinfo->arg[4],
                                               fcinfo->arg[5],
                                               fcinfo->arg[6],
                                               fcinfo->arg[7],
                                               fcinfo->arg[8],
                                               fcinfo->arg[9],
                                               fcinfo->arg[10],
                                               fcinfo->arg[11],
                                               fcinfo->arg[12],
                                               fcinfo->arg[13]);
            break;
        case 15:
            returnValue = (char *) (*user_fn) (fcinfo->arg[0],
                                               fcinfo->arg[1],
                                               fcinfo->arg[2],
                                               fcinfo->arg[3],
                                               fcinfo->arg[4],
                                               fcinfo->arg[5],
                                               fcinfo->arg[6],
                                               fcinfo->arg[7],
                                               fcinfo->arg[8],
                                               fcinfo->arg[9],
                                               fcinfo->arg[10],
                                               fcinfo->arg[11],
                                               fcinfo->arg[12],
                                               fcinfo->arg[13],
                                               fcinfo->arg[14]);
            break;
        case 16:
            returnValue = (char *) (*user_fn) (fcinfo->arg[0],
                                               fcinfo->arg[1],
                                               fcinfo->arg[2],
                                               fcinfo->arg[3],
                                               fcinfo->arg[4],
                                               fcinfo->arg[5],
                                               fcinfo->arg[6],
                                               fcinfo->arg[7],
                                               fcinfo->arg[8],
                                               fcinfo->arg[9],
                                               fcinfo->arg[10],
                                               fcinfo->arg[11],
                                               fcinfo->arg[12],
                                               fcinfo->arg[13],
                                               fcinfo->arg[14],
                                               fcinfo->arg[15]);
            break;
        default:

            /*
             * Increasing FUNC_MAX_ARGS doesn't automatically add cases to the
             * above code, so mention the actual value in this error not
             * FUNC_MAX_ARGS.  You could add cases to the above if you needed
             * to support old-style functions with many arguments, but making
             * 'em be new-style is probably a better idea.
             */
            ereport(ERROR,
                    (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
             errmsg("function %u has too many arguments (%d, maximum is %d)",
                    fcinfo->flinfo->fn_oid, n_arguments, 16)));
            returnValue = NULL; /* keep compiler quiet */
            break;
    }

    return PointerGetDatum(returnValue);
}

static Datum fmgr_security_definer ( PG_FUNCTION_ARGS   )  [static]

Definition at line 887 of file fmgr.c.

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

{
    Datum       result;
    struct fmgr_security_definer_cache *volatile fcache;
    FmgrInfo   *save_flinfo;
    Oid         save_userid;
    int         save_sec_context;
    volatile int save_nestlevel;
    PgStat_FunctionCallUsage fcusage;

    if (!fcinfo->flinfo->fn_extra)
    {
        HeapTuple   tuple;
        Form_pg_proc procedureStruct;
        Datum       datum;
        bool        isnull;
        MemoryContext oldcxt;

        fcache = MemoryContextAllocZero(fcinfo->flinfo->fn_mcxt,
                                        sizeof(*fcache));

        fmgr_info_cxt_security(fcinfo->flinfo->fn_oid, &fcache->flinfo,
                               fcinfo->flinfo->fn_mcxt, true);
        fcache->flinfo.fn_expr = fcinfo->flinfo->fn_expr;

        tuple = SearchSysCache1(PROCOID,
                                ObjectIdGetDatum(fcinfo->flinfo->fn_oid));
        if (!HeapTupleIsValid(tuple))
            elog(ERROR, "cache lookup failed for function %u",
                 fcinfo->flinfo->fn_oid);
        procedureStruct = (Form_pg_proc) GETSTRUCT(tuple);

        if (procedureStruct->prosecdef)
            fcache->userid = procedureStruct->proowner;

        datum = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_proconfig,
                                &isnull);
        if (!isnull)
        {
            oldcxt = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
            fcache->proconfig = DatumGetArrayTypePCopy(datum);
            MemoryContextSwitchTo(oldcxt);
        }

        ReleaseSysCache(tuple);

        fcinfo->flinfo->fn_extra = fcache;
    }
    else
        fcache = fcinfo->flinfo->fn_extra;

    /* GetUserIdAndSecContext is cheap enough that no harm in a wasted call */
    GetUserIdAndSecContext(&save_userid, &save_sec_context);
    if (fcache->proconfig)      /* Need a new GUC nesting level */
        save_nestlevel = NewGUCNestLevel();
    else
        save_nestlevel = 0;     /* keep compiler quiet */

    if (OidIsValid(fcache->userid))
        SetUserIdAndSecContext(fcache->userid,
                            save_sec_context | SECURITY_LOCAL_USERID_CHANGE);

    if (fcache->proconfig)
    {
        ProcessGUCArray(fcache->proconfig,
                        (superuser() ? PGC_SUSET : PGC_USERSET),
                        PGC_S_SESSION,
                        GUC_ACTION_SAVE);
    }

    /* function manager hook */
    if (fmgr_hook)
        (*fmgr_hook) (FHET_START, &fcache->flinfo, &fcache->arg);

    /*
     * We don't need to restore GUC or userid settings on error, because the
     * ensuing xact or subxact abort will do that.  The PG_TRY block is only
     * needed to clean up the flinfo link.
     */
    save_flinfo = fcinfo->flinfo;

    PG_TRY();
    {
        fcinfo->flinfo = &fcache->flinfo;

        /* See notes in fmgr_info_cxt_security */
        pgstat_init_function_usage(fcinfo, &fcusage);

        result = FunctionCallInvoke(fcinfo);

        /*
         * We could be calling either a regular or a set-returning function,
         * so we have to test to see what finalize flag to use.
         */
        pgstat_end_function_usage(&fcusage,
                                  (fcinfo->resultinfo == NULL ||
                                   !IsA(fcinfo->resultinfo, ReturnSetInfo) ||
                                   ((ReturnSetInfo *) fcinfo->resultinfo)->isDone != ExprMultipleResult));
    }
    PG_CATCH();
    {
        fcinfo->flinfo = save_flinfo;
        if (fmgr_hook)
            (*fmgr_hook) (FHET_ABORT, &fcache->flinfo, &fcache->arg);
        PG_RE_THROW();
    }
    PG_END_TRY();

    fcinfo->flinfo = save_flinfo;

    if (fcache->proconfig)
        AtEOXact_GUC(true, save_nestlevel);
    if (OidIsValid(fcache->userid))
        SetUserIdAndSecContext(save_userid, save_sec_context);
    if (fmgr_hook)
        (*fmgr_hook) (FHET_END, &fcache->flinfo, &fcache->arg);

    return result;
}

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

Definition at line 1290 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(), element_hash(), gistcentryinit(), gistdentryinit(), and hash_range().

{
    FunctionCallInfoData fcinfo;
    Datum       result;

    InitFunctionCallInfoData(fcinfo, flinfo, 1, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.argnull[0] = false;

    result = FunctionCallInvoke(&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);

    return result;
}

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

Definition at line 1310 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_array_elements(), _bt_compare_scankey_args(), _bt_find_extreme_element(), _bt_isequal(), _bt_load(), _bt_sort_array_elements(), _hash_checkqual(), call_subtype_diff(), cmpEntries(), compute_minimal_stats(), compute_range_stats(), doPickSplit(), element_compare(), eqjoinsel_inner(), eqjoinsel_semi(), genericPickSplit(), get_distance(), get_position(), get_variable_range(), ginCompareEntries(), gistMakeUnionItVec(), gistMakeUnionKey(), gistUserPicksplit(), histogram_selectivity(), ineq_histogram_selectivity(), make_greater_string(), mcv_selectivity(), range_cmp_bound_values(), range_cmp_bounds(), range_contains_elem_internal(), spgdoinsert(), spgGetCache(), spgLeafTest(), spgWalk(), and var_eq_const().

{
    /*
     * XXX if you change this routine, see also the inlined version in
     * utils/sort/tuplesort.c!
     */
    FunctionCallInfoData fcinfo;
    Datum       result;

    InitFunctionCallInfoData(fcinfo, flinfo, 2, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.arg[1] = arg2;
    fcinfo.argnull[0] = false;
    fcinfo.argnull[1] = false;

    result = FunctionCallInvoke(&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);

    return result;
}

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

Definition at line 1336 of file fmgr.c.

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

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

{
    FunctionCallInfoData fcinfo;
    Datum       result;

    InitFunctionCallInfoData(fcinfo, flinfo, 3, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.arg[1] = arg2;
    fcinfo.arg[2] = arg3;
    fcinfo.argnull[0] = false;
    fcinfo.argnull[1] = false;
    fcinfo.argnull[2] = false;

    result = FunctionCallInvoke(&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);

    return result;
}

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

Definition at line 1361 of file fmgr.c.

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

Referenced by collectMatchBitmap(), gistindex_keytest(), matchPartialInPendingList(), and scalararraysel().

{
    FunctionCallInfoData fcinfo;
    Datum       result;

    InitFunctionCallInfoData(fcinfo, flinfo, 4, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.arg[1] = arg2;
    fcinfo.arg[2] = arg3;
    fcinfo.arg[3] = arg4;
    fcinfo.argnull[0] = false;
    fcinfo.argnull[1] = false;
    fcinfo.argnull[2] = false;
    fcinfo.argnull[3] = false;

    result = FunctionCallInvoke(&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);

    return result;
}

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

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

{
    FunctionCallInfoData fcinfo;
    Datum       result;

    InitFunctionCallInfoData(fcinfo, flinfo, 5, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.arg[1] = arg2;
    fcinfo.arg[2] = arg3;
    fcinfo.arg[3] = arg4;
    fcinfo.arg[4] = arg5;
    fcinfo.argnull[0] = false;
    fcinfo.argnull[1] = false;
    fcinfo.argnull[2] = false;
    fcinfo.argnull[3] = false;
    fcinfo.argnull[4] = false;

    result = FunctionCallInvoke(&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);

    return result;
}

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

Definition at line 1417 of file fmgr.c.

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

{
    FunctionCallInfoData fcinfo;
    Datum       result;

    InitFunctionCallInfoData(fcinfo, flinfo, 6, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.arg[1] = arg2;
    fcinfo.arg[2] = arg3;
    fcinfo.arg[3] = arg4;
    fcinfo.arg[4] = arg5;
    fcinfo.arg[5] = arg6;
    fcinfo.argnull[0] = false;
    fcinfo.argnull[1] = false;
    fcinfo.argnull[2] = false;
    fcinfo.argnull[3] = false;
    fcinfo.argnull[4] = false;
    fcinfo.argnull[5] = false;

    result = FunctionCallInvoke(&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);

    return result;
}

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

Definition at line 1449 of file fmgr.c.

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

Referenced by ginNewScanKey().

{
    FunctionCallInfoData fcinfo;
    Datum       result;

    InitFunctionCallInfoData(fcinfo, flinfo, 7, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.arg[1] = arg2;
    fcinfo.arg[2] = arg3;
    fcinfo.arg[3] = arg4;
    fcinfo.arg[4] = arg5;
    fcinfo.arg[5] = arg6;
    fcinfo.arg[6] = arg7;
    fcinfo.argnull[0] = false;
    fcinfo.argnull[1] = false;
    fcinfo.argnull[2] = false;
    fcinfo.argnull[3] = false;
    fcinfo.argnull[4] = false;
    fcinfo.argnull[5] = false;
    fcinfo.argnull[6] = false;

    result = FunctionCallInvoke(&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);

    return result;
}

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

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

{
    FunctionCallInfoData fcinfo;
    Datum       result;

    InitFunctionCallInfoData(fcinfo, flinfo, 8, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.arg[1] = arg2;
    fcinfo.arg[2] = arg3;
    fcinfo.arg[3] = arg4;
    fcinfo.arg[4] = arg5;
    fcinfo.arg[5] = arg6;
    fcinfo.arg[6] = arg7;
    fcinfo.arg[7] = arg8;
    fcinfo.argnull[0] = false;
    fcinfo.argnull[1] = false;
    fcinfo.argnull[2] = false;
    fcinfo.argnull[3] = false;
    fcinfo.argnull[4] = false;
    fcinfo.argnull[5] = false;
    fcinfo.argnull[6] = false;
    fcinfo.argnull[7] = false;

    result = FunctionCallInvoke(&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);

    return result;
}

Datum FunctionCall9Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7,
Datum  arg8,
Datum  arg9 
)

Definition at line 1519 of file fmgr.c.

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

{
    FunctionCallInfoData fcinfo;
    Datum       result;

    InitFunctionCallInfoData(fcinfo, flinfo, 9, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.arg[1] = arg2;
    fcinfo.arg[2] = arg3;
    fcinfo.arg[3] = arg4;
    fcinfo.arg[4] = arg5;
    fcinfo.arg[5] = arg6;
    fcinfo.arg[6] = arg7;
    fcinfo.arg[7] = arg8;
    fcinfo.arg[8] = arg9;
    fcinfo.argnull[0] = false;
    fcinfo.argnull[1] = false;
    fcinfo.argnull[2] = false;
    fcinfo.argnull[3] = false;
    fcinfo.argnull[4] = false;
    fcinfo.argnull[5] = false;
    fcinfo.argnull[6] = false;
    fcinfo.argnull[7] = false;
    fcinfo.argnull[8] = false;

    result = FunctionCallInvoke(&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);

    return result;
}

bool get_call_expr_arg_stable ( Node expr,
int  argnum 
)

Definition at line 2406 of file fmgr.c.

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

Referenced by get_fn_expr_arg_stable().

{
    List       *args;
    Node       *arg;

    if (expr == NULL)
        return false;

    if (IsA(expr, FuncExpr))
        args = ((FuncExpr *) expr)->args;
    else if (IsA(expr, OpExpr))
        args = ((OpExpr *) expr)->args;
    else if (IsA(expr, DistinctExpr))
        args = ((DistinctExpr *) expr)->args;
    else if (IsA(expr, ScalarArrayOpExpr))
        args = ((ScalarArrayOpExpr *) expr)->args;
    else if (IsA(expr, ArrayCoerceExpr))
        args = list_make1(((ArrayCoerceExpr *) expr)->arg);
    else if (IsA(expr, NullIfExpr))
        args = ((NullIfExpr *) expr)->args;
    else if (IsA(expr, WindowFunc))
        args = ((WindowFunc *) expr)->args;
    else
        return false;

    if (argnum < 0 || argnum >= list_length(args))
        return false;

    arg = (Node *) list_nth(args, argnum);

    /*
     * Either a true Const or an external Param will have a value that doesn't
     * change during the execution of the query.  In future we might want to
     * consider other cases too, e.g. now().
     */
    if (IsA(arg, Const))
        return true;
    if (IsA(arg, Param) &&
        ((Param *) arg)->paramkind == PARAM_EXTERN)
        return true;

    return false;
}

Oid get_call_expr_argtype ( Node expr,
int  argnum 
)

Definition at line 2335 of file fmgr.c.

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

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

{
    List       *args;
    Oid         argtype;

    if (expr == NULL)
        return InvalidOid;

    if (IsA(expr, FuncExpr))
        args = ((FuncExpr *) expr)->args;
    else if (IsA(expr, OpExpr))
        args = ((OpExpr *) expr)->args;
    else if (IsA(expr, DistinctExpr))
        args = ((DistinctExpr *) expr)->args;
    else if (IsA(expr, ScalarArrayOpExpr))
        args = ((ScalarArrayOpExpr *) expr)->args;
    else if (IsA(expr, ArrayCoerceExpr))
        args = list_make1(((ArrayCoerceExpr *) expr)->arg);
    else if (IsA(expr, NullIfExpr))
        args = ((NullIfExpr *) expr)->args;
    else if (IsA(expr, WindowFunc))
        args = ((WindowFunc *) expr)->args;
    else
        return InvalidOid;

    if (argnum < 0 || argnum >= list_length(args))
        return InvalidOid;

    argtype = exprType((Node *) list_nth(args, argnum));

    /*
     * special hack for ScalarArrayOpExpr and ArrayCoerceExpr: what the
     * underlying function will actually get passed is the element type of the
     * array.
     */
    if (IsA(expr, ScalarArrayOpExpr) &&
        argnum == 1)
        argtype = get_base_element_type(argtype);
    else if (IsA(expr, ArrayCoerceExpr) &&
             argnum == 0)
        argtype = get_base_element_type(argtype);

    return argtype;
}

bool get_fn_expr_arg_stable ( FmgrInfo flinfo,
int  argnum 
)

Definition at line 2387 of file fmgr.c.

References FmgrInfo::fn_expr, and get_call_expr_arg_stable().

Referenced by leadlag_common(), and window_nth_value().

{
    /*
     * can't return anything useful if we have no FmgrInfo or if its fn_expr
     * node has not been initialized
     */
    if (!flinfo || !flinfo->fn_expr)
        return false;

    return get_call_expr_arg_stable(flinfo->fn_expr, argnum);
}

Oid get_fn_expr_argtype ( FmgrInfo flinfo,
int  argnum 
)
Oid get_fn_expr_rettype ( FmgrInfo flinfo  ) 

Definition at line 2294 of file fmgr.c.

References exprType(), and FmgrInfo::fn_expr.

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

{
    Node       *expr;

    /*
     * can't return anything useful if we have no FmgrInfo or if its fn_expr
     * node has not been initialized
     */
    if (!flinfo || !flinfo->fn_expr)
        return InvalidOid;

    expr = flinfo->fn_expr;

    return exprType(expr);
}

bool get_fn_expr_variadic ( FmgrInfo flinfo  ) 

Definition at line 2456 of file fmgr.c.

References FmgrInfo::fn_expr, and IsA.

Referenced by concat_internal(), and text_format().

{
    Node       *expr;

    /*
     * can't return anything useful if we have no FmgrInfo or if its fn_expr
     * node has not been initialized
     */
    if (!flinfo || !flinfo->fn_expr)
        return false;

    expr = flinfo->fn_expr;

    if (IsA(expr, FuncExpr))
        return ((FuncExpr *) expr)->funcvariadic;
    else
        return false;
}

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

Definition at line 1896 of file fmgr.c.

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

Referenced by BuildTupleFromCStrings(), domain_in(), exec_cast_value(), ExecEvalCoerceViaIO(), hstore_populate_record(), json_populate_record(), make_tuple_from_result_row(), NextCopyFrom(), OidInputFunctionCall(), plperl_sv_to_datum(), pltcl_func_handler(), pltcl_SPI_execute_plan(), pltcl_trigger_handler(), PLy_cursor_plan(), PLy_exec_function(), PLy_modify_tuple(), PLy_spi_execute_plan(), PLyObject_ToDatum(), populate_recordset_object_end(), range_in(), ReadArrayStr(), and record_in().

{
    FunctionCallInfoData fcinfo;
    Datum       result;
    bool        pushed;

    if (str == NULL && flinfo->fn_strict)
        return (Datum) 0;       /* just return null result */

    pushed = SPI_push_conditional();

    InitFunctionCallInfoData(fcinfo, flinfo, 3, InvalidOid, NULL, NULL);

    fcinfo.arg[0] = CStringGetDatum(str);
    fcinfo.arg[1] = ObjectIdGetDatum(typioparam);
    fcinfo.arg[2] = Int32GetDatum(typmod);
    fcinfo.argnull[0] = (str == NULL);
    fcinfo.argnull[1] = false;
    fcinfo.argnull[2] = false;

    result = FunctionCallInvoke(&fcinfo);

    /* Should get null result if and only if str is NULL */
    if (str == NULL)
    {
        if (!fcinfo.isnull)
            elog(ERROR, "input function %u returned non-NULL",
                 fcinfo.flinfo->fn_oid);
    }
    else
    {
        if (fcinfo.isnull)
            elog(ERROR, "input function %u returned NULL",
                 fcinfo.flinfo->fn_oid);
    }

    SPI_pop_conditional(pushed);

    return result;
}

Datum Int64GetDatum ( int64  X  ) 
static CFuncHashTabEntry * lookup_C_func ( HeapTuple  procedureTuple  )  [static]

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

{
    Oid         fn_oid = HeapTupleGetOid(procedureTuple);
    CFuncHashTabEntry *entry;

    if (CFuncHash == NULL)
        return NULL;            /* no table yet */
    entry = (CFuncHashTabEntry *)
        hash_search(CFuncHash,
                    &fn_oid,
                    HASH_FIND,
                    NULL);
    if (entry == NULL)
        return NULL;            /* no such entry */
    if (entry->fn_xmin == HeapTupleHeaderGetXmin(procedureTuple->t_data) &&
        ItemPointerEquals(&entry->fn_tid, &procedureTuple->t_self))
        return entry;           /* OK */
    return NULL;                /* entry is out of date */
}

Datum OidFunctionCall0Coll ( Oid  functionId,
Oid  collation 
)

Definition at line 1566 of file fmgr.c.

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

{
    FmgrInfo    flinfo;
    FunctionCallInfoData fcinfo;
    Datum       result;

    fmgr_info(functionId, &flinfo);

    InitFunctionCallInfoData(fcinfo, &flinfo, 0, collation, NULL, NULL);

    result = FunctionCallInvoke(&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %u returned NULL", flinfo.fn_oid);

    return result;
}

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

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

{
    FmgrInfo    flinfo;
    FunctionCallInfoData fcinfo;
    Datum       result;

    fmgr_info(functionId, &flinfo);

    InitFunctionCallInfoData(fcinfo, &flinfo, 1, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.argnull[0] = false;

    result = FunctionCallInvoke(&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %u returned NULL", flinfo.fn_oid);

    return result;
}

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

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

{
    FmgrInfo    flinfo;
    FunctionCallInfoData fcinfo;
    Datum       result;

    fmgr_info(functionId, &flinfo);

    InitFunctionCallInfoData(fcinfo, &flinfo, 2, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.arg[1] = arg2;
    fcinfo.argnull[0] = false;
    fcinfo.argnull[1] = false;

    result = FunctionCallInvoke(&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %u returned NULL", flinfo.fn_oid);

    return result;
}

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

Definition at line 1634 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.

{
    FmgrInfo    flinfo;
    FunctionCallInfoData fcinfo;
    Datum       result;

    fmgr_info(functionId, &flinfo);

    InitFunctionCallInfoData(fcinfo, &flinfo, 3, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.arg[1] = arg2;
    fcinfo.arg[2] = arg3;
    fcinfo.argnull[0] = false;
    fcinfo.argnull[1] = false;
    fcinfo.argnull[2] = false;

    result = FunctionCallInvoke(&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %u returned NULL", flinfo.fn_oid);

    return result;
}

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

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

{
    FmgrInfo    flinfo;
    FunctionCallInfoData fcinfo;
    Datum       result;

    fmgr_info(functionId, &flinfo);

    InitFunctionCallInfoData(fcinfo, &flinfo, 4, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.arg[1] = arg2;
    fcinfo.arg[2] = arg3;
    fcinfo.arg[3] = arg4;
    fcinfo.argnull[0] = false;
    fcinfo.argnull[1] = false;
    fcinfo.argnull[2] = false;
    fcinfo.argnull[3] = false;

    result = FunctionCallInvoke(&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %u returned NULL", flinfo.fn_oid);

    return result;
}

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

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

{
    FmgrInfo    flinfo;
    FunctionCallInfoData fcinfo;
    Datum       result;

    fmgr_info(functionId, &flinfo);

    InitFunctionCallInfoData(fcinfo, &flinfo, 5, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.arg[1] = arg2;
    fcinfo.arg[2] = arg3;
    fcinfo.arg[3] = arg4;
    fcinfo.arg[4] = arg5;
    fcinfo.argnull[0] = false;
    fcinfo.argnull[1] = false;
    fcinfo.argnull[2] = false;
    fcinfo.argnull[3] = false;
    fcinfo.argnull[4] = false;

    result = FunctionCallInvoke(&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %u returned NULL", flinfo.fn_oid);

    return result;
}

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

Definition at line 1724 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.

{
    FmgrInfo    flinfo;
    FunctionCallInfoData fcinfo;
    Datum       result;

    fmgr_info(functionId, &flinfo);

    InitFunctionCallInfoData(fcinfo, &flinfo, 6, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.arg[1] = arg2;
    fcinfo.arg[2] = arg3;
    fcinfo.arg[3] = arg4;
    fcinfo.arg[4] = arg5;
    fcinfo.arg[5] = arg6;
    fcinfo.argnull[0] = false;
    fcinfo.argnull[1] = false;
    fcinfo.argnull[2] = false;
    fcinfo.argnull[3] = false;
    fcinfo.argnull[4] = false;
    fcinfo.argnull[5] = false;

    result = FunctionCallInvoke(&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %u returned NULL", flinfo.fn_oid);

    return result;
}

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

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

{
    FmgrInfo    flinfo;
    FunctionCallInfoData fcinfo;
    Datum       result;

    fmgr_info(functionId, &flinfo);

    InitFunctionCallInfoData(fcinfo, &flinfo, 7, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.arg[1] = arg2;
    fcinfo.arg[2] = arg3;
    fcinfo.arg[3] = arg4;
    fcinfo.arg[4] = arg5;
    fcinfo.arg[5] = arg6;
    fcinfo.arg[6] = arg7;
    fcinfo.argnull[0] = false;
    fcinfo.argnull[1] = false;
    fcinfo.argnull[2] = false;
    fcinfo.argnull[3] = false;
    fcinfo.argnull[4] = false;
    fcinfo.argnull[5] = false;
    fcinfo.argnull[6] = false;

    result = FunctionCallInvoke(&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %u returned NULL", flinfo.fn_oid);

    return result;
}

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

Definition at line 1796 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.

{
    FmgrInfo    flinfo;
    FunctionCallInfoData fcinfo;
    Datum       result;

    fmgr_info(functionId, &flinfo);

    InitFunctionCallInfoData(fcinfo, &flinfo, 8, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.arg[1] = arg2;
    fcinfo.arg[2] = arg3;
    fcinfo.arg[3] = arg4;
    fcinfo.arg[4] = arg5;
    fcinfo.arg[5] = arg6;
    fcinfo.arg[6] = arg7;
    fcinfo.arg[7] = arg8;
    fcinfo.argnull[0] = false;
    fcinfo.argnull[1] = false;
    fcinfo.argnull[2] = false;
    fcinfo.argnull[3] = false;
    fcinfo.argnull[4] = false;
    fcinfo.argnull[5] = false;
    fcinfo.argnull[6] = false;
    fcinfo.argnull[7] = false;

    result = FunctionCallInvoke(&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %u returned NULL", flinfo.fn_oid);

    return result;
}

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

Definition at line 1835 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.

{
    FmgrInfo    flinfo;
    FunctionCallInfoData fcinfo;
    Datum       result;

    fmgr_info(functionId, &flinfo);

    InitFunctionCallInfoData(fcinfo, &flinfo, 9, collation, NULL, NULL);

    fcinfo.arg[0] = arg1;
    fcinfo.arg[1] = arg2;
    fcinfo.arg[2] = arg3;
    fcinfo.arg[3] = arg4;
    fcinfo.arg[4] = arg5;
    fcinfo.arg[5] = arg6;
    fcinfo.arg[6] = arg7;
    fcinfo.arg[7] = arg8;
    fcinfo.arg[8] = arg9;
    fcinfo.argnull[0] = false;
    fcinfo.argnull[1] = false;
    fcinfo.argnull[2] = false;
    fcinfo.argnull[3] = false;
    fcinfo.argnull[4] = false;
    fcinfo.argnull[5] = false;
    fcinfo.argnull[6] = false;
    fcinfo.argnull[7] = false;
    fcinfo.argnull[8] = false;

    result = FunctionCallInvoke(&fcinfo);

    /* Check for null result, since caller is clearly not expecting one */
    if (fcinfo.isnull)
        elog(ERROR, "function %u returned NULL", flinfo.fn_oid);

    return result;
}

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 
)

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

{
    FmgrInfo    flinfo;

    fmgr_info(functionId, &flinfo);
    return ReceiveFunctionCall(&flinfo, buf, typioparam, typmod);
}

bytea* OidSendFunctionCall ( Oid  functionId,
Datum  val 
)

Definition at line 2070 of file fmgr.c.

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

Referenced by SendFunctionResult().

{
    FmgrInfo    flinfo;

    fmgr_info(functionId, &flinfo);
    return SendFunctionCall(&flinfo, val);
}

char* OutputFunctionCall ( FmgrInfo flinfo,
Datum  val 
)
struct varlena* pg_detoast_datum ( struct varlena datum  )  [read]

Definition at line 2238 of file fmgr.c.

References heap_tuple_untoast_attr(), and VARATT_IS_EXTENDED.

{
    if (VARATT_IS_EXTENDED(datum))
        return heap_tuple_untoast_attr(datum);
    else
        return datum;
}

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

Definition at line 2247 of file fmgr.c.

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

{
    if (VARATT_IS_EXTENDED(datum))
        return heap_tuple_untoast_attr(datum);
    else
    {
        /* Make a modifiable copy of the varlena object */
        Size        len = VARSIZE(datum);
        struct varlena *result = (struct varlena *) palloc(len);

        memcpy(result, datum, len);
        return result;
    }
}

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

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

{
    if (VARATT_IS_COMPRESSED(datum) || VARATT_IS_EXTERNAL(datum))
        return heap_tuple_untoast_attr(datum);
    else
        return datum;
}

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

Definition at line 2263 of file fmgr.c.

References heap_tuple_untoast_attr_slice().

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

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

Definition at line 1970 of file fmgr.c.

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

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

{
    FunctionCallInfoData fcinfo;
    Datum       result;
    bool        pushed;

    if (buf == NULL && flinfo->fn_strict)
        return (Datum) 0;       /* just return null result */

    pushed = SPI_push_conditional();

    InitFunctionCallInfoData(fcinfo, flinfo, 3, InvalidOid, NULL, NULL);

    fcinfo.arg[0] = PointerGetDatum(buf);
    fcinfo.arg[1] = ObjectIdGetDatum(typioparam);
    fcinfo.arg[2] = Int32GetDatum(typmod);
    fcinfo.argnull[0] = (buf == NULL);
    fcinfo.argnull[1] = false;
    fcinfo.argnull[2] = false;

    result = FunctionCallInvoke(&fcinfo);

    /* Should get null result if and only if buf is NULL */
    if (buf == NULL)
    {
        if (!fcinfo.isnull)
            elog(ERROR, "receive function %u returned non-NULL",
                 fcinfo.flinfo->fn_oid);
    }
    else
    {
        if (fcinfo.isnull)
            elog(ERROR, "receive function %u returned NULL",
                 fcinfo.flinfo->fn_oid);
    }

    SPI_pop_conditional(pushed);

    return result;
}

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

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

Referenced by fmgr_info_C_lang().

{
    Oid         fn_oid = HeapTupleGetOid(procedureTuple);
    CFuncHashTabEntry *entry;
    bool        found;

    /* Create the hash table if it doesn't exist yet */
    if (CFuncHash == NULL)
    {
        HASHCTL     hash_ctl;

        MemSet(&hash_ctl, 0, sizeof(hash_ctl));
        hash_ctl.keysize = sizeof(Oid);
        hash_ctl.entrysize = sizeof(CFuncHashTabEntry);
        hash_ctl.hash = oid_hash;
        CFuncHash = hash_create("CFuncHash",
                                100,
                                &hash_ctl,
                                HASH_ELEM | HASH_FUNCTION);
    }

    entry = (CFuncHashTabEntry *)
        hash_search(CFuncHash,
                    &fn_oid,
                    HASH_ENTER,
                    &found);
    /* OID is already filled in */
    entry->fn_xmin = HeapTupleHeaderGetXmin(procedureTuple->t_data);
    entry->fn_tid = procedureTuple->t_self;
    entry->user_fn = user_fn;
    entry->inforec = inforec;
}

bytea* SendFunctionCall ( FmgrInfo flinfo,
Datum  val 
)

Definition at line 2023 of file fmgr.c.

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

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

{
    bytea      *result;
    bool        pushed;

    pushed = SPI_push_conditional();

    result = DatumGetByteaP(FunctionCall1(flinfo, val));

    SPI_pop_conditional(pushed);

    return result;
}


Variable Documentation

HTAB* CFuncHash = NULL [static]

Definition at line 83 of file fmgr.c.

PGDLLIMPORT fmgr_hook_type fmgr_hook = NULL

Definition at line 37 of file fmgr.c.

Referenced by fmgr_security_definer(), and sepgsql_init_client_label().

Definition at line 36 of file fmgr.c.

Referenced by sepgsql_init_client_label().