33 #include "utils/fmgroids.h" 44 #define TEXTDOMAIN PG_TEXTDOMAIN("plperl") 48 #include "perlchunks.h" 52 #include "plperl_opmask.h" 129 #define increment_prodesc_refcount(prodesc) \ 130 ((prodesc)->fn_refcount++) 131 #define decrement_prodesc_refcount(prodesc) \ 133 Assert((prodesc)->fn_refcount > 0); \ 134 if (--((prodesc)->fn_refcount) == 0) \ 135 free_plperl_function(prodesc); \ 239 static OP *(*pp_require_orig) (
pTHX) = NULL;
263 bool is_event_trigger);
278 int *ndims,
int *dims,
int cur_depth,
302 static char *setlocale_perl(
int category,
char *
locale);
361 sv = HeSVKEY_force(he);
390 static bool inited =
false;
405 gettext_noop(
"If true, trusted and untrusted Perl code will be compiled in strict mode."),
419 gettext_noop(
"Perl initialization code to execute when a Perl interpreter is initialized."),
441 gettext_noop(
"Perl initialization code to execute once when plperl is first used."),
449 gettext_noop(
"Perl initialization code to execute once when plperlu is first used."),
463 plperl_interp_hash =
hash_create(
"PL/Perl interpreters",
470 plperl_proc_hash =
hash_create(
"PL/Perl procedures",
558 PerlInterpreter *
interp = NULL;
566 interp_desc =
hash_search(plperl_interp_hash, &user_id,
572 interp_desc->
interp = NULL;
631 plperl_active_interp = NULL;
642 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
643 errmsg(
"cannot allocate multiple Perl interpreters on this platform")));
659 newXS(
"PostgreSQL::InServer::SPI::bootstrap",
662 eval_pv(
"PostgreSQL::InServer::SPI::bootstrap()", FALSE);
665 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
667 errcontext(
"while executing PostgreSQL::InServer::SPI::bootstrap")));
674 plperl_active_interp = interp_desc;
686 if (interp_desc && plperl_active_interp != interp_desc)
689 PERL_SET_CONTEXT(interp_desc->
interp);
692 plperl_active_interp = interp_desc;
704 static PerlInterpreter *
707 PerlInterpreter *plperl;
709 static char *embedding[3 + 2] = {
710 "",
"-e", PLC_PERLBOOT
744 save_collate = loc ?
pstrdup(loc) : NULL;
746 save_ctype = loc ?
pstrdup(loc) : NULL;
748 save_monetary = loc ?
pstrdup(loc) : NULL;
750 save_numeric = loc ?
pstrdup(loc) : NULL;
752 save_time = loc ?
pstrdup(loc) : NULL;
754 #define PLPERL_RESTORE_LOCALE(name, saved) \ 756 if (saved != NULL) { setlocale_perl(name, saved); pfree(saved); } \ 762 embedding[nargs++] =
"-e";
775 #if defined(PERL_SYS_INIT3) && !defined(MYMALLOC) 777 static int perl_sys_init_done;
780 if (!perl_sys_init_done)
782 char *dummy_env[1] = {NULL};
784 PERL_SYS_INIT3(&nargs, (
char ***) &embedding, (
char ***) &dummy_env);
797 perl_sys_init_done = 1;
804 plperl = perl_alloc();
806 elog(
ERROR,
"could not allocate Perl interpreter");
808 PERL_SET_CONTEXT(plperl);
809 perl_construct(plperl);
819 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
834 #ifdef PLPERL_ENABLE_OPMASK_EARLY 847 nargs, embedding, NULL) != 0)
849 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
851 errcontext(
"while parsing Perl initialization")));
853 if (perl_run(plperl) != 0)
855 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
857 errcontext(
"while running Perl initialization")));
859 #ifdef PLPERL_RESTORE_LOCALE 860 PLPERL_RESTORE_LOCALE(LC_COLLATE, save_collate);
861 PLPERL_RESTORE_LOCALE(LC_CTYPE, save_ctype);
862 PLPERL_RESTORE_LOCALE(LC_MONETARY, save_monetary);
863 PLPERL_RESTORE_LOCALE(LC_NUMERIC, save_numeric);
864 PLPERL_RESTORE_LOCALE(LC_TIME, save_time);
890 name = SvPV(sv, len);
891 if (!(name && len > 0 && *name))
894 svp = hv_fetch(GvHVn(PL_incgv), name, len, 0);
898 DIE(
aTHX_ "Unable to load %s into plperl", name);
920 if (interp && *interp)
935 if (PL_exit_flags & PERL_EXIT_DESTRUCT_END)
942 if (PL_endav && !PL_minus_c)
943 call_list(PL_scopestack_ix, PL_endav);
972 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
981 eval_pv(
"my $a=chr(0x100); return $a =~ /\\xa9/i", FALSE);
984 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
1003 stash = gv_stashpv(
"DynaLoader", GV_ADDWARN);
1005 while ((sv = hv_iternextsv(stash, &key, &klen)))
1009 SvREFCNT_dec(GvCV(sv));
1015 ++PL_sub_generation;
1016 hv_clear(PL_stashcache);
1027 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
1029 errcontext(
"while executing plperl.on_plperl_init")));
1050 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
1052 errcontext(
"while executing plperl.on_plperlu_init")));
1064 int len = strlen(res);
1066 while (len > 0 && isspace((
unsigned char) res[len - 1]))
1085 memset(nulls,
true,
sizeof(
bool) * td->
natts);
1087 hv_iterinit(perlhash);
1088 while ((he = hv_iternext(perlhash)))
1090 SV *
val = HeVAL(he);
1097 (
errcode(ERRCODE_UNDEFINED_COLUMN),
1098 errmsg(
"Perl hash contains nonexistent column \"%s\"",
1102 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1103 errmsg(
"cannot set system attribute \"%s\"",
1116 hv_iterinit(perlhash);
1142 if (SvOK(sv) && SvROK(sv))
1144 if (SvTYPE(SvRV(sv)) == SVt_PVAV)
1146 else if (sv_isa(sv,
"PostgreSQL::InServer::ARRAY"))
1148 HV *hv = (HV *) SvRV(sv);
1151 if (*sav && SvOK(*sav) && SvROK(*sav) &&
1152 SvTYPE(SvRV(*sav)) == SVt_PVAV)
1155 elog(
ERROR,
"could not get array reference from PostgreSQL::InServer::ARRAY object");
1166 int *ndims,
int *dims,
int cur_depth,
1172 int len = av_len(av) + 1;
1174 for (i = 0; i < len; i++)
1177 SV **svp = av_fetch(av, i, FALSE);
1185 AV *nav = (AV *) SvRV(sav);
1188 if (cur_depth + 1 >
MAXDIM)
1190 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1191 errmsg(
"number of array dimensions (%d) exceeds the maximum allowed (%d)",
1192 cur_depth + 1,
MAXDIM)));
1195 if (i == 0 && *ndims == cur_depth)
1197 dims[*ndims] = av_len(nav) + 1;
1200 else if (av_len(nav) + 1 != dims[cur_depth])
1202 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1203 errmsg(
"multidimensional arrays must have array expressions with matching dimensions")));
1207 ndims, dims, cur_depth + 1,
1208 arraytypid, elemtypid, typmod,
1217 if (*ndims != cur_depth)
1219 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1220 errmsg(
"multidimensional arrays must have array expressions with matching dimensions")));
1255 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1256 errmsg(
"cannot convert Perl array to non-array type %s",
1263 memset(dims, 0,
sizeof(dims));
1264 dims[0] = av_len((AV *) SvRV(src)) + 1;
1268 typid, elemtypid, typmod,
1269 &finfo, typioparam);
1275 for (i = 0; i < ndims; i++)
1290 &typinput, typioparam);
1325 if (!sv || !SvOK(sv) || typid == VOIDOID)
1349 else if (SvTYPE(SvRV(sv)) == SVt_PVHV)
1358 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1359 errmsg(
"cannot convert Perl hash to non-composite type %s",
1366 isdomain = (typid != td->
tdtypeid);
1380 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1381 errmsg(
"function returning record called in context " 1382 "that cannot accept type record")));
1403 fcinfo, finfo, typioparam,
1439 (
errcode(ERRCODE_UNDEFINED_OBJECT),
1440 errmsg(
"lookup failed for type %s", fqtypename)));
1451 &typoutput, &typisvarlena);
1473 Oid transform_funcid;
1489 &typlen, &typbyval, &typalign,
1490 &typdelim, &typioparam, &typoutputfunc);
1510 if (info->
ndims == 0)
1522 info->
nelems[0] = nitems;
1523 for (i = 1; i < info->
ndims; i++)
1530 (void) hv_store(hv,
"array", 5, av, 0);
1531 (void) hv_store(hv,
"typeoid", 7,
newSVuv(typid), 0);
1534 gv_stashpv(
"PostgreSQL::InServer::ARRAY", 0));
1556 if (nest >= info->
ndims - 1)
1560 for (i = first; i < last; i += info->
nelems[nest + 1])
1565 av_push(result, ref);
1579 AV *result = newAV();
1581 for (i = first; i < last; i++)
1589 av_push(result, newSV(0));
1604 av_push(result,
cstr2sv(val));
1707 when =
"INSTEAD OF";
1715 level =
"STATEMENT";
1760 (
errcode(ERRCODE_UNDEFINED_COLUMN),
1761 errmsg(
"$_TD->{new} does not exist")));
1762 if (!SvOK(*svp) || !SvROK(*svp) || SvTYPE(SvRV(*svp)) != SVt_PVHV)
1764 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1765 errmsg(
"$_TD->{new} is not a hash reference")));
1766 hvNew = (HV *) SvRV(*svp);
1769 natts = tupdesc->
natts;
1772 modnulls = (
bool *)
palloc0(natts *
sizeof(
bool));
1773 modrepls = (
bool *)
palloc0(natts *
sizeof(
bool));
1776 while ((he = hv_iternext(hvNew)))
1779 SV *
val = HeVAL(he);
1785 (
errcode(ERRCODE_UNDEFINED_COLUMN),
1786 errmsg(
"Perl hash contains nonexistent column \"%s\"",
1790 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1791 errmsg(
"cannot set system attribute \"%s\"",
1793 if (attr->attgenerated)
1795 (
errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
1796 errmsg(
"cannot set generated column \"%s\"",
1805 &modnulls[attn - 1]);
1806 modrepls[attn - 1] =
true;
1842 MemSet(&this_call_data, 0,
sizeof(this_call_data));
1843 this_call_data.
fcinfo = fcinfo;
1847 current_call_data = &this_call_data;
1860 current_call_data = save_call_data;
1888 MemSet(&this_call_data, 0,
sizeof(this_call_data));
1893 pl_error_context.
arg = NULL;
1902 MemSet(&flinfo, 0,
sizeof(flinfo));
1903 MemSet(&desc, 0,
sizeof(desc));
1904 fake_fcinfo->flinfo = &flinfo;
1908 desc.
proname =
"inline_code_block";
1922 this_call_data.
fcinfo = fake_fcinfo;
1923 this_call_data.
prodesc = &desc;
1930 current_call_data = &this_call_data;
1933 elog(
ERROR,
"could not connect to SPI manager");
1940 elog(
ERROR,
"could not create internal procedure for anonymous code block");
1953 current_call_data = save_call_data;
1981 bool is_trigger =
false;
1982 bool is_event_trigger =
false;
1991 elog(
ERROR,
"cache lookup failed for function %u", funcoid);
1998 if (functyptype == TYPTYPE_PSEUDO)
2000 if (proc->prorettype == TRIGGEROID)
2002 else if (proc->prorettype == EVENT_TRIGGEROID)
2003 is_event_trigger =
true;
2004 else if (proc->prorettype != RECORDOID &&
2005 proc->prorettype != VOIDOID)
2007 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2008 errmsg(
"PL/Perl functions cannot return type %s",
2014 &argtypes, &argnames, &argmodes);
2015 for (i = 0; i < numargs; i++)
2018 argtypes[i] != RECORDOID)
2020 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2021 errmsg(
"PL/Perl functions cannot accept type %s",
2082 HV *pragma_hv = newHV();
2095 PUSHs(sv_2mortal(
cstr2sv(subname)));
2104 PUSHs(sv_2mortal(
cstr2sv(s)));
2112 count = perl_call_pv(
"PostgreSQL::InServer::mkfunc",
2113 G_SCALAR | G_EVAL | G_KEEPERR);
2118 SV *sub_rv = (SV *) POPs;
2120 if (sub_rv && SvROK(sub_rv) && SvTYPE(SvRV(sub_rv)) == SVt_PVCV)
2132 (
errcode(ERRCODE_SYNTAX_ERROR),
2137 (
errcode(ERRCODE_SYNTAX_ERROR),
2138 errmsg(
"didn't get a CODE reference from compiling function \"%s\"",
2152 char *file = __FILE__;
2155 newXS(
"PostgreSQL::InServer::Util::bootstrap",
2169 Oid *argtypes = NULL;
2176 EXTEND(sp, desc->
nargs);
2183 for (i = 0; i < desc->
nargs; i++)
2191 PUSHs(sv_2mortal(sv));
2212 PUSHs(sv_2mortal(sv));
2218 count = perl_call_sv(desc->
reference, G_SCALAR | G_EVAL);
2228 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
2229 errmsg(
"didn't get a return item from function")));
2240 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
2244 retval = newSVsv(POPs);
2269 TDsv =
get_sv(
"main::_TD", 0);
2272 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
2273 errmsg(
"couldn't fetch $_TD")));
2279 EXTEND(sp, tg_trigger->
tgnargs);
2281 for (i = 0; i < tg_trigger->
tgnargs; i++)
2286 count = perl_call_sv(desc->
reference, G_SCALAR | G_EVAL);
2296 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
2297 errmsg(
"didn't get a return item from trigger function")));
2308 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
2312 retval = newSVsv(POPs);
2336 TDsv =
get_sv(
"main::_TD", 0);
2339 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
2340 errmsg(
"couldn't fetch $_TD")));
2349 count = perl_call_sv(desc->
reference, G_SCALAR | G_EVAL);
2359 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
2360 errmsg(
"didn't get a return item from trigger function")));
2371 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
2375 retval = newSVsv(POPs);
2393 nonatomic = fcinfo->context &&
2398 elog(
ERROR,
"could not connect to SPI manager");
2401 current_call_data->
prodesc = prodesc;
2418 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2419 errmsg(
"set-valued function called in context that " 2420 "cannot accept a set")));
2452 AV *rav = (AV *) SvRV(sav);
2454 while ((svp = av_fetch(rav, i, FALSE)) != NULL)
2460 else if (SvOK(perlret))
2463 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2464 errmsg(
"set-returning PL/Perl function must return " 2465 "reference to array or use return_next")));
2513 elog(
ERROR,
"could not connect to SPI manager");
2522 current_call_data->
prodesc = prodesc;
2535 hvTD = (HV *) SvRV(svTD);
2546 if (perlret == NULL || !SvOK(perlret))
2584 (
errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
2585 errmsg(
"ignoring modified row in DELETE trigger")));
2592 (
errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
2593 errmsg(
"result of PL/Perl trigger function must be undef, " 2594 "\"SKIP\", or \"MODIFY\"")));
2621 elog(
ERROR,
"could not connect to SPI manager");
2625 current_call_data->
prodesc = prodesc;
2652 if (proc_ptr && proc_ptr->
proc_ptr)
2711 elog(
ERROR,
"cache lookup failed for function %u", fn_oid);
2723 proc_ptr =
hash_search(plperl_proc_hash, &proc_key,
2734 proc_ptr =
hash_search(plperl_proc_hash, &proc_key,
2754 plperl_error_context.
arg =
NameStr(procStruct->proname);
2763 Datum protrftypes_datum;
2784 prodesc->
fn_cxt = proc_cxt;
2788 prodesc->
nargs = procStruct->pronargs;
2796 (procStruct->provolatile != PROVOLATILE_VOLATILE);
2800 Anum_pg_proc_protrftypes, &isnull);
2811 elog(
ERROR,
"cache lookup failed for language %u",
2812 procStruct->prolang);
2814 prodesc->
lang_oid = langStruct->oid;
2822 if (!is_trigger && !is_event_trigger)
2824 Oid rettype = procStruct->prorettype;
2828 elog(
ERROR,
"cache lookup failed for type %u", rettype);
2832 if (typeStruct->typtype == TYPTYPE_PSEUDO)
2834 if (rettype == VOIDOID ||
2835 rettype == RECORDOID)
2837 else if (rettype == TRIGGEROID ||
2838 rettype == EVENT_TRIGGEROID)
2840 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2841 errmsg(
"trigger functions can only be called " 2845 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2846 errmsg(
"PL/Perl functions cannot return type %s",
2867 if (!is_trigger && !is_event_trigger)
2871 for (i = 0; i < prodesc->
nargs; i++)
2873 Oid argtype = procStruct->proargtypes.values[
i];
2877 elog(
ERROR,
"cache lookup failed for type %u", argtype);
2881 if (typeStruct->typtype == TYPTYPE_PSEUDO &&
2882 argtype != RECORDOID)
2884 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2885 errmsg(
"PL/Perl functions cannot accept type %s",
2899 if (IsTrueArrayType(typeStruct))
2914 Anum_pg_proc_prosrc, &isnull);
2934 elog(
ERROR,
"could not create PL/Perl internal procedure");
2944 proc_ptr =
hash_search(plperl_proc_hash, &proc_key,
3017 hv_ksplit(hv, tupdesc->
natts);
3019 for (i = 0; i < tupdesc->
natts; i++)
3028 if (att->attisdropped)
3031 if (att->attgenerated)
3034 if (!include_generated)
3038 attname =
NameStr(att->attname);
3093 croak(
"SPI functions can not be used in END blocks");
3172 (processed > (uint64)
UV_MAX) ?
3173 newSVnv((
NV) processed) :
3176 if (status > 0 && tuptable)
3185 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3186 errmsg(
"query result has too many rows to fit in a Perl array")));
3189 av_extend(rows, processed);
3190 for (i = 0; i < processed; i++)
3249 prodesc = current_call_data->
prodesc;
3250 fcinfo = current_call_data->
fcinfo;
3255 (
errcode(ERRCODE_SYNTAX_ERROR),
3256 errmsg(
"cannot use return_next in a non-SETOF function")));
3278 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3279 errmsg(
"function returning record called in context " 3280 "that cannot accept type record")));
3289 if (tupdesc == NULL || tupdesc->
natts != 1)
3290 elog(
ERROR,
"expected single-column result descriptor for non-composite SETOF result");
3313 if (!current_call_data->
tmp_cxt)
3317 "PL/Perl return_next temporary cxt",
3327 if (!(SvOK(sv) && SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVHV))
3329 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3330 errmsg(
"SETOF-composite-returning PL/Perl function " 3331 "must call return_next with reference to hash")));
3402 elog(
ERROR,
"SPI_cursor_open() failed:%s",
3559 "PL/Perl spi_prepare query",
3565 qdesc->
nargs = argc;
3576 "PL/Perl spi_prepare workspace",
3585 for (i = 0; i < argc; i++)
3713 if (hash_entry == NULL)
3714 elog(
ERROR,
"spi_exec_prepared: Invalid prepared query passed");
3718 elog(
ERROR,
"spi_exec_prepared: plperl query_hash value vanished");
3720 if (qdesc->
nargs != argc)
3721 elog(
ERROR,
"spi_exec_prepared: expected %d argument(s), %d passed",
3722 qdesc->
nargs, argc);
3731 if (sv && *sv && SvIOK(*sv))
3739 nulls = (
char *)
palloc(argc);
3748 for (i = 0; i < argc; i++)
3759 nulls[
i] = isnull ?
'n' :
' ';
3836 if (hash_entry == NULL)
3837 elog(
ERROR,
"spi_query_prepared: Invalid prepared query passed");
3841 elog(
ERROR,
"spi_query_prepared: plperl query_hash value vanished");
3843 if (qdesc->
nargs != argc)
3844 elog(
ERROR,
"spi_query_prepared: expected %d argument(s), %d passed",
3845 qdesc->
nargs, argc);
3852 nulls = (
char *)
palloc(argc);
3861 for (i = 0; i < argc; i++)
3872 nulls[
i] = isnull ?
'n' :
' ';
3886 elog(
ERROR,
"SPI_cursor_open() failed:%s",
3934 if (hash_entry == NULL)
3935 elog(
ERROR,
"spi_freeplan: Invalid prepared query passed");
3939 elog(
ERROR,
"spi_freeplan: plperl query_hash value vanished");
4019 char *
volatile cmsg = NULL;
4024 elog(level,
"%s", cmsg);
4063 hlen = -(int) strlen(hkey);
4064 ret = hv_store(hv, hkey, hlen, val, 0);
4087 hlen = -(int) strlen(hkey);
4088 ret = hv_fetch(hv, hkey, hlen, 0);
4102 char *procname = (
char *) arg;
4105 errcontext(
"PL/Perl function \"%s\"", procname);
4114 char *procname = (
char *) arg;
4117 errcontext(
"compilation of PL/Perl function \"%s\"", procname);
4136 setlocale_perl(
int category,
char *
locale)
4139 char *RETVAL =
setlocale(category, locale);
4143 #ifdef USE_LOCALE_CTYPE 4144 if (category == LC_CTYPE
4146 || category == LC_ALL
4153 if (category == LC_ALL)
4158 new_ctype(newctype);
4161 #ifdef USE_LOCALE_COLLATE 4162 if (category == LC_COLLATE
4164 || category == LC_ALL
4171 if (category == LC_ALL)
4176 new_collate(newcoll);
4180 #ifdef USE_LOCALE_NUMERIC 4181 if (category == LC_NUMERIC
4183 || category == LC_ALL
4190 if (category == LC_ALL)
4195 new_numeric(newnum);
int SPI_fnumber(TupleDesc tupdesc, const char *fname)
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, Datum *values, bool *isnull)
void UnpinPortal(Portal portal)
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)
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)
#define AllocSetContextCreate
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)
int SPI_connect_ext(int options)
EXTERN_C void boot_DynaLoader(pTHX_ CV *cv)
SV * plperl_spi_query(char *query)
#define castNode(_type_, nodeptr)
static HeapTuple plperl_modify_tuple(HV *hvTD, TriggerData *tdata, HeapTuple otup)
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)
#define TupleDescAttr(tupdesc, i)
ResourceOwner CurrentResourceOwner
char * pstrdup(const char *in)
SPIPlanPtr SPI_prepare(const char *src, int nargs, Oid *argtypes)
#define ALLOCSET_SMALL_SIZES
void ReleaseCurrentSubTransaction(void)
#define SizeForFunctionCallInfo(nargs)
static void set_interp_require(bool trusted)
struct plperl_interp_desc plperl_interp_desc
int get_func_arg_info(HeapTuple procTup, Oid **p_argtypes, char ***p_argnames, char **p_argmodes)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Oid get_func_signature(Oid funcid, Oid **argtypes, int *nargs)
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)
void plperl_spi_cursor_close(char *cursor)
static plperl_interp_desc * plperl_active_interp
#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)
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)
void(* callback)(void *arg)
struct ErrorContextCallback * previous
#define OidIsValid(objectId)
#define DatumGetHeapTupleHeader(X)
SV * plperl_spi_prepare(char *query, int argc, SV **argv)
static OP *(* pp_require_orig)(pTHX)
void FlushErrorState(void)
#define TRIGGER_FIRED_FOR_STATEMENT(event)
static void plperl_event_trigger_handler(PG_FUNCTION_ARGS)
TupleDesc lookup_rowtype_tupdesc_domain(Oid type_id, int32 typmod, bool noError)
char * pg_server_to_any(const char *s, int len, int encoding)
void plperl_spi_commit(void)
#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)
#define SPI_OPT_NONATOMIC
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
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)
#define ALLOCSET_DEFAULT_SIZES
void tuplestore_puttuple(Tuplestorestate *state, HeapTuple tuple)
static plperl_proc_desc * compile_plperl_function(Oid fn_oid, bool is_trigger, bool is_event_trigger)
int SPI_keepplan(SPIPlanPtr plan)
Datum plperl_call_handler(PG_FUNCTION_ARGS)
static void plperl_trusted_init(void)
void RollbackAndReleaseCurrentSubTransaction(void)
void PinPortal(Portal portal)
void check_stack_depth(void)
static void plperl_fini(int code, Datum arg)
#define SPI_ERROR_NOATTRIBUTE
#define CStringGetDatum(X)
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
static void activate_interpreter(plperl_interp_desc *interp_desc)
FormData_pg_attribute * Form_pg_attribute
static Datum plperl_hash_to_datum(SV *src, TupleDesc td)
MemoryContext CurrentMemoryContext
bool type_is_rowtype(Oid typid)
static void plperl_exec_callback(void *arg)
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
#define increment_prodesc_refcount(prodesc)
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
int SPI_register_trigger_data(TriggerData *tdata)
void plperl_util_elog(int level, SV *msg)
MemoryContext TopMemoryContext
unsigned long fn_refcount
char * plperl_sv_to_literal(SV *sv, char *fqtypename)
#define heap_getattr(tup, attnum, tupleDesc, isnull)
void SPI_freetuptable(SPITupleTable *tuptable)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
#define TRIGGER_FIRED_BY_DELETE(event)
Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes)
#define TextDatumGetCString(d)
static void plperl_return_next_internal(SV *sv)
Datum regtypein(PG_FUNCTION_ARGS)
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)
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)
static void croak_cstr(const char *str)
#define HeapTupleHeaderGetTypeId(tup)
Tuplestorestate * tuple_store
void domain_check(Datum value, bool isnull, Oid domainType, void **extra, MemoryContext mcxt)
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 SvREFCNT_dec_current(SV *sv)
bool pg_verifymbstr(const char *mbstr, int len, bool noError)
#define ereport(elevel,...)
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)
#define LOCAL_FCINFO(name, nargs)
SetFunctionReturnMode returnMode
#define HeapTupleIsValid(tuple)
static char * plperl_on_plperl_init
#define CALLED_AS_TRIGGER(fcinfo)
#define Assert(condition)
static bool plperl_use_strict
void BeginInternalSubTransaction(const char *name)
char * SPI_getnspname(Relation rel)
FormData_pg_type * Form_pg_type
void plperl_return_next(SV *sv)
void MemoryContextSetIdentifier(MemoryContext context, const char *id)
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)
const char * GetCommandTagName(CommandTag commandTag)
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)
static OP * pp_require_safe(pTHX)
static HTAB * plperl_interp_hash
#define TRIGGER_FIRED_BY_INSERT(event)
char * OidOutputFunctionCall(Oid functionId, Datum val)
FormData_pg_language * Form_pg_language
Datum plperlu_validator(PG_FUNCTION_ARGS)
int errmsg(const char *fmt,...)
void plperl_spi_rollback(void)
static SV * plperl_hash_from_tuple(HeapTuple tuple, TupleDesc tupdesc, bool include_generated)
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)
static HV * plperl_spi_execute_fetch_result(SPITupleTable *, uint64, int)
struct plperl_query_entry plperl_query_entry
void SPI_cursor_fetch(Portal portal, bool forward, long count)
static void plperl_create_sub(plperl_proc_desc *desc, const char *s, Oid fn_oid)
void SPI_start_transaction(void)
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)
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)
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, bool *replIsnull, bool *doReplace)
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)
#define PG_USED_FOR_ASSERTS_ONLY
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