36 #include "utils/fmgroids.h"
47 #define TEXTDOMAIN PG_TEXTDOMAIN("plperl")
54 #include "perlchunks.h"
56 #include "plperl_opmask.h"
131 #define increment_prodesc_refcount(prodesc) \
132 ((prodesc)->refcount++)
133 #define decrement_prodesc_refcount(prodesc) \
135 if (--((prodesc)->refcount) <= 0) \
136 free_plperl_function(prodesc); \
261 bool is_event_trigger);
276 int *ndims,
int *dims,
int cur_depth,
299 static char *setlocale_perl(
int category,
char *
locale);
343 sv = HeSVKEY_force(he);
389 static bool inited =
false;
404 gettext_noop(
"If true, trusted and untrusted Perl code will be compiled in strict mode."),
418 gettext_noop(
"Perl initialization code to execute when a Perl interpreter is initialized."),
440 gettext_noop(
"Perl initialization code to execute once when plperl is first used."),
448 gettext_noop(
"Perl initialization code to execute once when plperlu is first used."),
460 memset(&hash_ctl, 0,
sizeof(hash_ctl));
463 plperl_interp_hash =
hash_create(
"PL/Perl interpreters",
468 memset(&hash_ctl, 0,
sizeof(hash_ctl));
471 plperl_proc_hash =
hash_create(
"PL/Perl procedures",
559 PerlInterpreter *interp =
NULL;
567 interp_desc =
hash_search(plperl_interp_hash, &user_id,
582 memset(&hash_ctl, 0,
sizeof(hash_ctl));
633 plperl_active_interp =
NULL;
644 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
645 errmsg(
"cannot allocate multiple Perl interpreters on this platform")));
658 newXS(
"PostgreSQL::InServer::SPI::bootstrap",
661 eval_pv(
"PostgreSQL::InServer::SPI::bootstrap()",
FALSE);
664 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
666 errcontext(
"while executing PostgreSQL::InServer::SPI::bootstrap")));
669 interp_desc->
interp = interp;
672 plperl_active_interp = interp_desc;
684 if (interp_desc && plperl_active_interp != interp_desc)
687 PERL_SET_CONTEXT(interp_desc->
interp);
690 plperl_active_interp = interp_desc;
702 static PerlInterpreter *
705 PerlInterpreter *plperl;
707 static char *embedding[3 + 2] = {
708 "",
"-e", PLC_PERLBOOT
741 loc = setlocale(LC_COLLATE,
NULL);
743 loc = setlocale(LC_CTYPE,
NULL);
745 loc = setlocale(LC_MONETARY,
NULL);
747 loc = setlocale(LC_NUMERIC,
NULL);
749 loc = setlocale(LC_TIME,
NULL);
752 #define PLPERL_RESTORE_LOCALE(name, saved) \
754 if (saved != NULL) { setlocale_perl(name, saved); pfree(saved); } \
760 embedding[nargs++] =
"-e";
773 #if defined(PERL_SYS_INIT3) && !defined(MYMALLOC)
775 static int perl_sys_init_done;
778 if (!perl_sys_init_done)
780 char *dummy_env[1] = {
NULL};
782 PERL_SYS_INIT3(&nargs, (
char ***) &embedding, (
char ***) &dummy_env);
795 perl_sys_init_done = 1;
802 plperl = perl_alloc();
804 elog(
ERROR,
"could not allocate Perl interpreter");
806 PERL_SET_CONTEXT(plperl);
807 perl_construct(plperl);
810 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
825 #ifdef PLPERL_ENABLE_OPMASK_EARLY
837 nargs, embedding,
NULL) != 0)
839 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
841 errcontext(
"while parsing Perl initialization")));
843 if (perl_run(plperl) != 0)
845 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
847 errcontext(
"while running Perl initialization")));
849 #ifdef PLPERL_RESTORE_LOCALE
850 PLPERL_RESTORE_LOCALE(LC_COLLATE, save_collate);
851 PLPERL_RESTORE_LOCALE(LC_CTYPE, save_ctype);
852 PLPERL_RESTORE_LOCALE(LC_MONETARY, save_monetary);
853 PLPERL_RESTORE_LOCALE(LC_NUMERIC, save_numeric);
854 PLPERL_RESTORE_LOCALE(LC_TIME, save_time);
879 name = SvPV(sv, len);
880 if (!(name && len > 0 && *name))
883 svp = hv_fetch(GvHVn(PL_incgv), name, len, 0);
887 DIE(
aTHX_ "Unable to load %s into plperl", name);
909 if (interp && *interp)
923 if (PL_exit_flags & PERL_EXIT_DESTRUCT_END)
930 if (PL_endav && !PL_minus_c)
931 call_list(PL_scopestack_ix, PL_endav);
959 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
968 eval_pv(
"my $a=chr(0x100); return $a =~ /\\xa9/i",
FALSE);
971 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
990 stash = gv_stashpv(
"DynaLoader", GV_ADDWARN);
992 while ((sv = hv_iternextsv(stash, &key, &klen)))
996 SvREFCNT_dec(GvCV(sv));
1002 ++PL_sub_generation;
1003 hv_clear(PL_stashcache);
1014 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
1016 errcontext(
"while executing plperl.on_plperl_init")));
1035 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
1037 errcontext(
"while executing plperl.on_plperlu_init")));
1049 int len = strlen(res);
1051 while (len > 0 && isspace((
unsigned char) res[len - 1]))
1069 memset(nulls,
true,
sizeof(
bool) * td->
natts);
1071 hv_iterinit(perlhash);
1072 while ((he = hv_iternext(perlhash)))
1074 SV *
val = HeVAL(he);
1078 if (attn <= 0 || td->attrs[attn - 1]->attisdropped)
1080 (
errcode(ERRCODE_UNDEFINED_COLUMN),
1081 errmsg(
"Perl hash contains nonexistent column \"%s\"",
1085 td->
attrs[attn - 1]->atttypid,
1086 td->
attrs[attn - 1]->atttypmod,
1094 hv_iterinit(perlhash);
1118 if (SvOK(sv) && SvROK(sv))
1120 if (SvTYPE(SvRV(sv)) == SVt_PVAV)
1122 else if (sv_isa(sv,
"PostgreSQL::InServer::ARRAY"))
1124 HV *hv = (HV *) SvRV(sv);
1127 if (*sav && SvOK(*sav) && SvROK(*sav) &&
1128 SvTYPE(SvRV(*sav)) == SVt_PVAV)
1131 elog(
ERROR,
"could not get array reference from PostgreSQL::InServer::ARRAY object");
1142 int *ndims,
int *dims,
int cur_depth,
1147 int len = av_len(av) + 1;
1149 for (i = 0; i < len; i++)
1152 SV **svp = av_fetch(av, i,
FALSE);
1160 AV *nav = (AV *) SvRV(sav);
1163 if (cur_depth + 1 >
MAXDIM)
1165 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1166 errmsg(
"number of array dimensions (%d) exceeds the maximum allowed (%d)",
1167 cur_depth + 1,
MAXDIM)));
1170 if (i == 0 && *ndims == cur_depth)
1172 dims[*ndims] = av_len(nav) + 1;
1175 else if (av_len(nav) + 1 != dims[cur_depth])
1177 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1178 errmsg(
"multidimensional arrays must have array expressions with matching dimensions")));
1182 ndims, dims, cur_depth + 1,
1183 arraytypid, elemtypid, typmod,
1192 if (*ndims != cur_depth)
1194 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1195 errmsg(
"multidimensional arrays must have array expressions with matching dimensions")));
1229 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1230 errmsg(
"cannot convert Perl array to non-array type %s",
1237 memset(dims, 0,
sizeof(dims));
1238 dims[0] = av_len((AV *) SvRV(src)) + 1;
1242 typid, elemtypid, typmod,
1243 &finfo, typioparam);
1249 for (i = 0; i < ndims; i++)
1264 &typinput, typioparam);
1299 if (!sv || !SvOK(sv) || typid ==
VOIDOID)
1323 else if (SvTYPE(SvRV(sv)) == SVt_PVHV)
1331 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1332 errmsg(
"cannot convert Perl hash to non-composite type %s",
1339 if (fcinfo ==
NULL ||
1342 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1343 errmsg(
"function returning record called in context "
1344 "that cannot accept type record")));
1357 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1358 errmsg(
"PL/Perl function must return reference to hash or array")));
1394 (
errcode(ERRCODE_UNDEFINED_OBJECT),
1395 errmsg(
"lookup failed for type %s", fqtypename)));
1406 &typoutput, &typisvarlena);
1427 Oid transform_funcid;
1439 &typlen, &typbyval, &typalign,
1440 &typdelim, &typioparam, &typoutputfunc);
1459 info->
nelems[0] = nitems;
1460 for (i = 1; i < info->
ndims; i++)
1466 (void) hv_store(hv,
"array", 5, av, 0);
1467 (void) hv_store(hv,
"typeoid", 7, newSViv(typid), 0);
1470 gv_stashpv(
"PostgreSQL::InServer::ARRAY", 0));
1488 if (nest >= info->
ndims - 1)
1492 for (i = first; i < last; i += info->
nelems[nest + 1])
1497 av_push(result, ref);
1510 AV *result = newAV();
1512 for (i = first; i < last; i++)
1520 av_push(result, newSV(0));
1535 av_push(result,
cstr2sv(val));
1631 when =
"INSTEAD OF";
1639 level =
"STATEMENT";
1686 (
errcode(ERRCODE_UNDEFINED_COLUMN),
1687 errmsg(
"$_TD->{new} does not exist")));
1688 if (!SvOK(*svp) || !SvROK(*svp) || SvTYPE(SvRV(*svp)) != SVt_PVHV)
1690 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1691 errmsg(
"$_TD->{new} is not a hash reference")));
1692 hvNew = (HV *) SvRV(*svp);
1700 while ((he = hv_iternext(hvNew)))
1704 SV *
val = HeVAL(he);
1707 if (attn <= 0 || tupdesc->attrs[attn - 1]->attisdropped)
1709 (
errcode(ERRCODE_UNDEFINED_COLUMN),
1710 errmsg(
"Perl hash contains nonexistent column \"%s\"",
1714 tupdesc->
attrs[attn - 1]->atttypid,
1715 tupdesc->
attrs[attn - 1]->atttypmod,
1721 modnulls[slotsused] = isnull ?
'n' :
' ';
1722 modattrs[slotsused] = attn;
1730 modattrs, modvalues, modnulls);
1737 elog(
ERROR,
"SPI_modifytuple failed: %s",
1764 MemSet(&this_call_data, 0,
sizeof(this_call_data));
1765 this_call_data.
fcinfo = fcinfo;
1769 current_call_data = &this_call_data;
1784 current_call_data = save_call_data;
1792 current_call_data = save_call_data;
1815 MemSet(&this_call_data, 0,
sizeof(this_call_data));
1828 MemSet(&fake_fcinfo, 0,
sizeof(fake_fcinfo));
1829 MemSet(&flinfo, 0,
sizeof(flinfo));
1830 MemSet(&desc, 0,
sizeof(desc));
1831 fake_fcinfo.
flinfo = &flinfo;
1835 desc.
proname =
"inline_code_block";
1849 this_call_data.
fcinfo = &fake_fcinfo;
1850 this_call_data.
prodesc = &desc;
1857 current_call_data = &this_call_data;
1860 elog(
ERROR,
"could not connect to SPI manager");
1867 elog(
ERROR,
"could not create internal procedure for anonymous code block");
1871 SvREFCNT_dec(perlret);
1880 current_call_data = save_call_data;
1889 current_call_data = save_call_data;
1915 bool is_trigger =
false;
1916 bool is_event_trigger =
false;
1925 elog(
ERROR,
"cache lookup failed for function %u", funcoid);
1936 (proc->prorettype ==
OPAQUEOID && proc->pronargs == 0))
1939 is_event_trigger =
true;
1940 else if (proc->prorettype !=
RECORDOID &&
1943 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1944 errmsg(
"PL/Perl functions cannot return type %s",
1950 &argtypes, &argnames, &argmodes);
1951 for (i = 0; i < numargs; i++)
1956 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1957 errmsg(
"PL/Perl functions cannot accept type %s",
2017 HV *pragma_hv = newHV();
2021 sprintf(subname,
"%s__%u", prodesc->
proname, fn_oid);
2030 PUSHs(sv_2mortal(
cstr2sv(subname)));
2039 PUSHs(sv_2mortal(
cstr2sv(s)));
2047 count = perl_call_pv(
"PostgreSQL::InServer::mkfunc",
2048 G_SCALAR | G_EVAL | G_KEEPERR);
2053 SV *sub_rv = (SV *) POPs;
2055 if (sub_rv && SvROK(sub_rv) && SvTYPE(SvRV(sub_rv)) == SVt_PVCV)
2067 (
errcode(ERRCODE_SYNTAX_ERROR),
2072 (
errcode(ERRCODE_SYNTAX_ERROR),
2073 errmsg(
"didn't get a CODE reference from compiling function \"%s\"",
2089 char *file = __FILE__;
2092 newXS(
"PostgreSQL::InServer::Util::bootstrap",
2112 EXTEND(sp, desc->
nargs);
2117 for (i = 0; i < desc->
nargs; i++)
2125 PUSHs(sv_2mortal(sv));
2146 PUSHs(sv_2mortal(sv));
2152 count = perl_call_sv(desc->
reference, G_SCALAR | G_EVAL);
2162 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
2163 errmsg(
"didn't get a return item from function")));
2174 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
2178 retval = newSVsv(POPs);
2202 TDsv =
get_sv(
"main::_TD", 0);
2205 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
2206 errmsg(
"couldn't fetch $_TD")));
2212 EXTEND(sp, tg_trigger->
tgnargs);
2214 for (i = 0; i < tg_trigger->
tgnargs; i++)
2219 count = perl_call_sv(desc->
reference, G_SCALAR | G_EVAL);
2229 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
2230 errmsg(
"didn't get a return item from trigger function")));
2241 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
2245 retval = newSVsv(POPs);
2268 TDsv =
get_sv(
"main::_TD", 0);
2271 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
2272 errmsg(
"couldn't fetch $_TD")));
2281 count = perl_call_sv(desc->
reference, G_SCALAR | G_EVAL);
2291 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
2292 errmsg(
"didn't get a return item from trigger function")));
2303 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
2307 retval = newSVsv(POPs);
2327 elog(
ERROR,
"could not connect to SPI manager");
2330 current_call_data->
prodesc = prodesc;
2348 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2349 errmsg(
"set-valued function called in context that "
2350 "cannot accept a set")));
2381 AV *rav = (AV *) SvRV(sav);
2383 while ((svp = av_fetch(rav, i,
FALSE)) !=
NULL)
2389 else if (SvOK(perlret))
2392 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2393 errmsg(
"set-returning PL/Perl function must return "
2394 "reference to array or use return_next")));
2422 SvREFCNT_dec(perlret);
2440 elog(
ERROR,
"could not connect to SPI manager");
2444 current_call_data->
prodesc = prodesc;
2457 hvTD = (HV *) SvRV(svTD);
2468 if (perlret ==
NULL || !SvOK(perlret))
2506 (
errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
2507 errmsg(
"ignoring modified row in DELETE trigger")));
2514 (
errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
2515 errmsg(
"result of PL/Perl trigger function must be undef, "
2516 "\"SKIP\", or \"MODIFY\"")));
2528 SvREFCNT_dec(perlret);
2543 elog(
ERROR,
"could not connect to SPI manager");
2547 current_call_data->
prodesc = prodesc;
2576 if (proc_ptr && proc_ptr->
proc_ptr)
2639 elog(
ERROR,
"cache lookup failed for function %u", fn_oid);
2645 plperl_error_context.
arg =
NameStr(procStruct->proname);
2653 proc_ptr =
hash_search(plperl_proc_hash, &proc_key,
2662 proc_ptr =
hash_search(plperl_proc_hash, &proc_key,
2676 if (prodesc ==
NULL)
2682 Datum protrftypes_datum;
2691 if (prodesc ==
NULL)
2693 (
errcode(ERRCODE_OUT_OF_MEMORY),
2694 errmsg(
"out of memory")));
2703 (
errcode(ERRCODE_OUT_OF_MEMORY),
2704 errmsg(
"out of memory")));
2731 elog(
ERROR,
"cache lookup failed for language %u",
2732 procStruct->prolang);
2743 if (!is_trigger && !is_event_trigger)
2751 elog(
ERROR,
"cache lookup failed for type %u",
2752 procStruct->prorettype);
2759 if (procStruct->prorettype ==
VOIDOID ||
2762 else if (procStruct->prorettype ==
TRIGGEROID ||
2767 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2768 errmsg(
"trigger functions can only be called "
2775 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2776 errmsg(
"PL/Perl functions cannot return type %s",
2781 prodesc->
result_oid = procStruct->prorettype;
2787 (typeStruct->typlen == -1 && typeStruct->typelem);
2799 if (!is_trigger && !is_event_trigger)
2801 prodesc->
nargs = procStruct->pronargs;
2802 for (i = 0; i < prodesc->
nargs; i++)
2809 elog(
ERROR,
"cache lookup failed for type %u",
2810 procStruct->proargtypes.values[i]);
2816 procStruct->proargtypes.values[i] !=
RECORDOID)
2820 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2821 errmsg(
"PL/Perl functions cannot accept type %s",
2826 procStruct->proargtypes.values[i] ==
RECORDOID)
2836 if (typeStruct->typelem != 0 && typeStruct->typlen == -1)
2872 elog(
ERROR,
"could not create PL/Perl internal procedure");
2880 proc_ptr =
hash_search(plperl_proc_hash, &proc_key,
2933 hv_ksplit(hv, tupdesc->
natts);
2935 for (i = 0; i < tupdesc->
natts; i++)
2943 if (tupdesc->
attrs[i]->attisdropped)
2981 &typoutput, &typisvarlena);
3002 croak(
"SPI functions can not be used in END blocks");
3093 newSViv(processed));
3095 if (status > 0 && tuptable)
3102 av_extend(rows, processed);
3103 for (i = 0; i < processed; i++)
3137 prodesc = current_call_data->
prodesc;
3138 fcinfo = current_call_data->
fcinfo;
3143 (
errcode(ERRCODE_SYNTAX_ERROR),
3144 errmsg(
"cannot use return_next in a non-SETOF function")));
3181 if (!current_call_data->
tmp_cxt)
3185 "PL/Perl return_next temporary cxt",
3197 if (!(SvOK(sv) && SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVHV))
3199 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3200 errmsg(
"SETOF-composite-returning PL/Perl function "
3201 "must call return_next with reference to hash")));
3265 elog(
ERROR,
"SPI_cursor_open() failed:%s",
3440 "PL/Perl spi_prepare query",
3448 qdesc->
nargs = argc;
3459 "PL/Perl spi_prepare workspace",
3470 for (i = 0; i < argc; i++)
3609 if (hash_entry ==
NULL)
3610 elog(
ERROR,
"spi_exec_prepared: Invalid prepared query passed");
3614 elog(
ERROR,
"spi_exec_prepared: plperl query_hash value vanished");
3616 if (qdesc->
nargs != argc)
3617 elog(
ERROR,
"spi_exec_prepared: expected %d argument(s), %d passed",
3618 qdesc->
nargs, argc);
3627 if (sv && *sv && SvIOK(*sv))
3635 nulls = (
char *)
palloc(argc);
3644 for (i = 0; i < argc; i++)
3655 nulls[
i] = isnull ?
'n' :
' ';
3745 if (hash_entry ==
NULL)
3746 elog(
ERROR,
"spi_query_prepared: Invalid prepared query passed");
3750 elog(
ERROR,
"spi_query_prepared: plperl query_hash value vanished");
3752 if (qdesc->
nargs != argc)
3753 elog(
ERROR,
"spi_query_prepared: expected %d argument(s), %d passed",
3754 qdesc->
nargs, argc);
3761 nulls = (
char *)
palloc(argc);
3770 for (i = 0; i < argc; i++)
3781 nulls[
i] = isnull ?
'n' :
' ';
3795 elog(
ERROR,
"SPI_cursor_open() failed:%s",
3854 if (hash_entry ==
NULL)
3855 elog(
ERROR,
"spi_freeplan: Invalid prepared query passed");
3859 elog(
ERROR,
"spi_freeplan: plperl query_hash value vanished");
3893 hlen = -(int) strlen(hkey);
3894 ret = hv_store(hv, hkey, hlen, val, 0);
3916 hlen = -(int) strlen(hkey);
3917 ret = hv_fetch(hv, hkey, hlen, 0);
3931 char *procname = (
char *) arg;
3934 errcontext(
"PL/Perl function \"%s\"", procname);
3943 char *procname = (
char *) arg;
3946 errcontext(
"compilation of PL/Perl function \"%s\"", procname);
3965 setlocale_perl(
int category,
char *
locale)
3967 char *RETVAL = setlocale(category, locale);
3971 #ifdef USE_LOCALE_CTYPE
3972 if (category == LC_CTYPE
3974 || category == LC_ALL
3981 if (category == LC_ALL)
3982 newctype = setlocale(LC_CTYPE,
NULL);
3986 new_ctype(newctype);
3989 #ifdef USE_LOCALE_COLLATE
3990 if (category == LC_COLLATE
3992 || category == LC_ALL
3999 if (category == LC_ALL)
4000 newcoll = setlocale(LC_COLLATE,
NULL);
4004 new_collate(newcoll);
4008 #ifdef USE_LOCALE_NUMERIC
4009 if (category == LC_NUMERIC
4011 || category == LC_ALL
4018 if (category == LC_ALL)
4019 newnum = setlocale(LC_NUMERIC,
NULL);
4023 new_numeric(newnum);
int SPI_fnumber(TupleDesc tupdesc, const char *fname)
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, Datum *values, bool *isnull)
Datum makeMdArrayResult(ArrayBuildState *astate, int ndims, int *dims, int *lbs, MemoryContext rcontext, bool release)
static SV * plperl_ref_from_pg_array(Datum arg, Oid typid)
EXTERN_C void boot_PostgreSQL__InServer__SPI(pTHX_ CV *cv)
bool arg_is_rowtype[FUNC_MAX_ARGS]
Oid get_transform_fromsql(Oid typid, Oid langid, List *trftypes)
static char plperl_opmask[MAXO]
static PerlInterpreter * plperl_init_interp(void)
static bool validate_plperl_function(plperl_proc_ptr *proc_ptr, HeapTuple procTup)
#define CALLED_AS_EVENT_TRIGGER(fcinfo)
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
static Datum plperl_func_handler(PG_FUNCTION_ARGS)
#define IsA(nodeptr, _type_)
void MemoryContextDelete(MemoryContext context)
static HTAB * plperl_proc_hash
#define decrement_prodesc_refcount(prodesc)
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
struct plperl_call_data plperl_call_data
static SV * get_perl_array_ref(SV *sv)
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
static char * hek2cstr(HE *he)
static Datum plperl_sv_to_datum(SV *sv, Oid typid, int32 typmod, FunctionCallInfo fcinfo, FmgrInfo *finfo, Oid typioparam, bool *isnull)
static Datum plperl_array_to_datum(SV *src, Oid typid, int32 typmod)
static char * plperl_on_init
static void plperl_init_shared_libs(pTHX)
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
static bool plperl_ending
ArrayBuildState * initArrayResult(Oid element_type, MemoryContext rcontext, bool subcontext)
static void select_perl_context(bool trusted)
EXTERN_C void boot_DynaLoader(pTHX_ CV *cv)
SV * plperl_spi_query(char *query)
static HeapTuple plperl_modify_tuple(HV *hvTD, TriggerData *tdata, HeapTuple otup)
#define TYPTYPE_COMPOSITE
void on_proc_exit(pg_on_exit_callback function, Datum arg)
ErrorData * CopyErrorData(void)
Oid get_element_type(Oid typid)
struct plperl_proc_desc plperl_proc_desc
#define PointerGetDatum(X)
ResourceOwner CurrentResourceOwner
char * pstrdup(const char *in)
SPIPlanPtr SPI_prepare(const char *src, int nargs, Oid *argtypes)
void ReleaseCurrentSubTransaction(void)
static void set_interp_require(bool trusted)
struct plperl_interp_desc plperl_interp_desc
Form_pg_attribute * attrs
int get_func_arg_info(HeapTuple procTup, Oid **p_argtypes, char ***p_argnames, char **p_argmodes)
static HV * plperl_spi_execute_fetch_result(SPITupleTable *, int, int)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
#define Anum_pg_proc_prosrc
Oid get_func_signature(Oid funcid, Oid **argtypes, int *nargs)
FmgrInfo arg_out_func[FUNC_MAX_ARGS]
SV * plperl_spi_fetchrow(char *cursor)
SPITupleTable * SPI_tuptable
int errcode(int sqlerrcode)
static SV ** hv_fetch_string(HV *hv, const char *key)
char get_typtype(Oid typid)
#define MemSet(start, val, len)
static SV * plperl_hash_from_datum(Datum attr)
#define Anum_pg_proc_protrftypes
void plperl_spi_cursor_close(char *cursor)
static plperl_interp_desc * plperl_active_interp
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define PG_GETARG_POINTER(n)
void MemoryContextReset(MemoryContext context)
Portal SPI_cursor_open(const char *name, SPIPlanPtr plan, Datum *Values, const char *Nulls, bool read_only)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
#define DirectFunctionCall1(func, arg1)
int pg_strcasecmp(const char *s1, const char *s2)
struct plperl_query_desc plperl_query_desc
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
FormData_pg_type * Form_pg_type
bool check_function_bodies
static SV ** hv_store_string(HV *hv, const char *key, SV *val)
#define TRIGGER_FIRED_AFTER(event)
Datum oidout(PG_FUNCTION_ARGS)
struct ErrorContextCallback * previous
#define OidIsValid(objectId)
#define DatumGetHeapTupleHeader(X)
SV * plperl_spi_prepare(char *query, int argc, SV **argv)
void FlushErrorState(void)
#define TRIGGER_FIRED_FOR_STATEMENT(event)
#define ALLOCSET_DEFAULT_MINSIZE
#define SearchSysCache1(cacheId, key1)
static void plperl_event_trigger_handler(PG_FUNCTION_ARGS)
#define ALLOCSET_SMALL_MINSIZE
char * pg_server_to_any(const char *s, int len, int encoding)
#define PERL_UNUSED_VAR(x)
static SV * split_array(plperl_array_info *info, int first, int last, int nest)
char * OutputFunctionCall(FmgrInfo *flinfo, Datum val)
Portal SPI_cursor_find(const char *name)
static void plperl_call_perl_event_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo, SV *td)
ErrorContextCallback * error_context_stack
#define HeapTupleHeaderGetTypMod(tup)
void plperl_spi_freeplan(char *query)
List * oid_array_to_list(Datum datum)
static void plperl_untrusted_init(void)
static Datum plperl_trigger_handler(PG_FUNCTION_ARGS)
void pfree(void *pointer)
static SV * make_array_ref(plperl_array_info *info, int first, int last)
#define TRIGGER_FIRED_BY_TRUNCATE(event)
#define ObjectIdGetDatum(X)
plperl_proc_desc * proc_ptr
#define DatumGetCString(X)
bool CheckFunctionValidatorAccess(Oid validatorOid, Oid functionOid)
void fmgr_info(Oid functionId, FmgrInfo *finfo)
void EmitWarningsOnPlaceholders(const char *className)
int SPI_execute_plan(SPIPlanPtr plan, Datum *Values, const char *Nulls, bool read_only, long tcount)
#define OidFunctionCall1(functionId, arg1)
const char * SPI_result_code_string(int code)
void tuplestore_puttuple(Tuplestorestate *state, HeapTuple tuple)
static plperl_proc_desc * compile_plperl_function(Oid fn_oid, bool is_trigger, bool is_event_trigger)
char query_name[NAMEDATALEN]
static OP *(* pp_require_orig)(pTHX)
int SPI_keepplan(SPIPlanPtr plan)
Datum plperl_call_handler(PG_FUNCTION_ARGS)
static void plperl_trusted_init(void)
void RollbackAndReleaseCurrentSubTransaction(void)
void check_stack_depth(void)
static void plperl_fini(int code, Datum arg)
#define CStringGetDatum(X)
static void activate_interpreter(plperl_interp_desc *interp_desc)
static Datum plperl_hash_to_datum(SV *src, TupleDesc td)
bool argnull[FUNC_MAX_ARGS]
MemoryContext CurrentMemoryContext
TupleDesc lookup_rowtype_tupdesc_noerror(Oid type_id, int32 typmod, bool noError)
bool type_is_rowtype(Oid typid)
static void plperl_exec_callback(void *arg)
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
HeapTuple SPI_modifytuple(Relation rel, HeapTuple tuple, int natts, int *attnum, Datum *Values, const char *Nulls)
#define increment_prodesc_refcount(prodesc)
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
#define ereport(elevel, rest)
MemoryContext TopMemoryContext
static void perm_fmgr_info(Oid functionId, FmgrInfo *finfo)
char * plperl_sv_to_literal(SV *sv, char *fqtypename)
#define PROVOLATILE_VOLATILE
static SV * plperl_hash_from_tuple(HeapTuple tuple, TupleDesc tupdesc)
#define ALLOCSET_SMALL_INITSIZE
#define heap_getattr(tup, attnum, tupleDesc, isnull)
void SPI_freetuptable(SPITupleTable *tuptable)
#define TRIGGER_FIRED_BY_DELETE(event)
Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes)
#define TextDatumGetCString(d)
Datum regtypein(PG_FUNCTION_ARGS)
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
void * palloc0(Size size)
void DefineCustomStringVariable(const char *name, const char *short_desc, const char *long_desc, char **valueAddr, const char *bootValue, GucContext context, int flags, GucStringCheckHook check_hook, GucStringAssignHook assign_hook, GucShowHook show_hook)
HTAB * hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
SV * plperl_spi_query_prepared(char *query, int argc, SV **argv)
void ReleaseSysCache(HeapTuple tuple)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
static void free_plperl_function(plperl_proc_desc *prodesc)
#define HeapTupleHeaderGetTypeId(tup)
Tuplestorestate * tuple_store
static void plperl_destroy_interp(PerlInterpreter **)
FormData_pg_proc * Form_pg_proc
static SV * cstr2sv(const char *str)
void parseTypeString(const char *str, Oid *typeid_p, int32 *typmod_p, bool missing_ok)
Datum InputFunctionCall(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
char * SPI_getrelname(Relation rel)
static void plperl_create_sub(plperl_proc_desc *desc, char *s, Oid fn_oid)
static void plperl_inline_callback(void *arg)
pqsigfunc pqsignal(int signum, pqsigfunc handler)
static SV * plperl_trigger_build_args(FunctionCallInfo fcinfo)
EXTERN_C void boot_PostgreSQL__InServer__Util(pTHX_ CV *cv)
SetFunctionReturnMode returnMode
#define HeapTupleIsValid(tuple)
static char * plperl_on_plperl_init
#define CALLED_AS_TRIGGER(fcinfo)
#define Assert(condition)
static bool plperl_use_strict
char * SPI_getnspname(Relation rel)
Oid arg_arraytype[FUNC_MAX_ARGS]
void BeginInternalSubTransaction(char *name)
void plperl_return_next(SV *sv)
static SV * plperl_event_trigger_build_args(FunctionCallInfo fcinfo)
#define HeapTupleHeaderGetRawXmin(tup)
static char * strip_trailing_ws(const char *msg)
#define HeapTupleGetDatum(tuple)
void * hash_seq_search(HASH_SEQ_STATUS *status)
static char * plperl_on_plperlu_init
MemoryContext ecxt_per_query_memory
struct plperl_proc_key plperl_proc_key
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
static HeapTuple plperl_build_tuple_result(HV *perlhash, TupleDesc td)
Oid get_transform_tosql(Oid typid, Oid langid, List *trftypes)
Tuplestorestate * setResult
#define DatumGetPointer(X)
static void check_spi_usage_allowed(void)
PG_FUNCTION_INFO_V1(plperl_call_handler)
#define TRIGGER_FIRED_BEFORE(event)
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
static void plperl_compile_callback(void *arg)
int SPI_freeplan(SPIPlanPtr plan)
static Datum values[MAXATTR]
void SPI_cursor_close(Portal portal)
#define TRIGGER_FIRED_INSTEAD(event)
static PerlInterpreter * plperl_held_interp
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
Oid get_base_element_type(Oid typid)
void SPI_restore_connection(void)
static OP * pp_require_safe(pTHX)
static HTAB * plperl_interp_hash
#define TRIGGER_FIRED_BY_INSERT(event)
void(* callback)(void *arg)
char * OidOutputFunctionCall(Oid functionId, Datum val)
#define ALLOCSET_SMALL_MAXSIZE
FormData_pg_language * Form_pg_language
Datum plperlu_validator(PG_FUNCTION_ARGS)
int errmsg(const char *fmt,...)
void list_free(List *list)
#define ALLOCSET_DEFAULT_INITSIZE
Datum plperl_inline_handler(PG_FUNCTION_ARGS)
void FloatExceptionHandler(SIGNAL_ARGS)
Oid getTypeIOParam(HeapTuple typeTuple)
void pg_bindtextdomain(const char *domain)
#define FunctionCall1(flinfo, arg1)
struct plperl_query_entry plperl_query_entry
void SPI_cursor_fetch(Portal portal, bool forward, long count)
bool pg_verifymbstr(const char *mbstr, int len, bool noError)
#define ALLOCSET_DEFAULT_MAXSIZE
plperl_proc_desc * prodesc
#define CHECK_FOR_INTERRUPTS()
HV * plperl_spi_exec(char *query, int limit)
static void _sv_to_datum_finfo(Oid typid, FmgrInfo *finfo, Oid *typioparam)
static void array_to_datum_internal(AV *av, ArrayBuildState *astate, int *ndims, int *dims, int cur_depth, Oid arraytypid, Oid elemtypid, int32 typmod, FmgrInfo *finfo, Oid typioparam)
#define HeapTupleGetOid(tuple)
static void static void status(const char *fmt,...) pg_attribute_printf(1
#define ReleaseTupleDesc(tupdesc)
plperl_interp_desc * interp
#define TRIGGER_FIRED_FOR_ROW(event)
struct plperl_array_info plperl_array_info
void DefineCustomBoolVariable(const char *name, const char *short_desc, const char *long_desc, bool *valueAddr, bool bootValue, GucContext context, int flags, GucBoolCheckHook check_hook, GucBoolAssignHook assign_hook, GucShowHook show_hook)
Datum plperl_validator(PG_FUNCTION_ARGS)
static plperl_call_data * current_call_data
#define TRIGGER_FIRED_BY_UPDATE(event)
Datum plperlu_call_handler(PG_FUNCTION_ARGS)
Datum plperlu_inline_handler(PG_FUNCTION_ARGS)
HV * plperl_spi_exec_prepared(char *query, HV *attr, int argc, SV **argv)
static SV * plperl_call_perl_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo, SV *td)
static char * sv2cstr(SV *sv)
static SV * plperl_call_perl_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo)
int SPI_execute(const char *src, bool read_only, long tcount)
struct plperl_proc_ptr plperl_proc_ptr
#define HeapTupleHeaderGetDatumLength(tup)
#define DatumGetArrayTypeP(X)
void get_type_io_data(Oid typid, IOFuncSelector which_func, int16 *typlen, bool *typbyval, char *typalign, char *typdelim, Oid *typioparam, Oid *func)
plperl_query_desc * query_data