Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit84d73a6

Browse files
committed
Add a validator function for plperl. Andrew Dunstan
1 parent676bb1a commit84d73a6

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

‎src/bin/scripts/createlang.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
8-
* $PostgreSQL: pgsql/src/bin/scripts/createlang.c,v 1.16 2005/06/14 02:57:45 momjian Exp $
8+
* $PostgreSQL: pgsql/src/bin/scripts/createlang.c,v 1.17 2005/06/22 16:45:50 tgl Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -191,12 +191,14 @@ main(int argc, char *argv[])
191191
{
192192
trusted= true;
193193
handler="plperl_call_handler";
194+
validator="plperl_validator";
194195
object="plperl";
195196
}
196197
elseif (strcmp(langname,"plperlu")==0)
197198
{
198199
trusted= false;
199200
handler="plperl_call_handler";
201+
validator="plperl_validator";
200202
object="plperl";
201203
}
202204
elseif (strcmp(langname,"plpythonu")==0)

‎src/pl/plperl/plperl.c

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* ENHANCEMENTS, OR MODIFICATIONS.
3434
*
3535
* IDENTIFICATION
36-
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.77 2005/06/15 00:35:16 momjian Exp $
36+
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.78 2005/06/22 16:45:51 tgl Exp $
3737
*
3838
**********************************************************************/
3939

@@ -114,6 +114,7 @@ static void plperl_init_all(void);
114114
staticvoidplperl_init_interp(void);
115115

116116
Datumplperl_call_handler(PG_FUNCTION_ARGS);
117+
Datumplperl_validator(PG_FUNCTION_ARGS);
117118
voidplperl_init(void);
118119

119120
HV*plperl_spi_exec(char*query,intlimit);
@@ -506,10 +507,11 @@ plperl_modify_tuple(HV *hvTD, TriggerData *tdata, HeapTuple otup)
506507
}
507508

508509

509-
/* This is the only externally-visible part of the plperl interface.
510+
/*
511+
* This is the only externally-visible part of the plperl call interface.
510512
* The Postgres function and trigger managers call it to execute a
511-
* perl function. */
512-
513+
* perl function.
514+
*/
513515
PG_FUNCTION_INFO_V1(plperl_call_handler);
514516

515517
Datum
@@ -541,6 +543,44 @@ plperl_call_handler(PG_FUNCTION_ARGS)
541543
returnretval;
542544
}
543545

546+
/*
547+
* This is the other externally visible function - it is called when CREATE
548+
* FUNCTION is issued to validate the function being created/replaced.
549+
*/
550+
PG_FUNCTION_INFO_V1(plperl_validator);
551+
552+
Datum
553+
plperl_validator(PG_FUNCTION_ARGS)
554+
{
555+
Oidfuncoid=PG_GETARG_OID(0);
556+
HeapTupletuple;
557+
Form_pg_procproc;
558+
boolistrigger= false;
559+
plperl_proc_desc*prodesc;
560+
561+
plperl_init_all();
562+
563+
/* Get the new function's pg_proc entry */
564+
tuple=SearchSysCache(PROCOID,
565+
ObjectIdGetDatum(funcoid),
566+
0,0,0);
567+
if (!HeapTupleIsValid(tuple))
568+
elog(ERROR,"cache lookup failed for function %u",funcoid);
569+
proc= (Form_pg_proc)GETSTRUCT(tuple);
570+
571+
/* we assume OPAQUE with no arguments means a trigger */
572+
if (proc->prorettype==TRIGGEROID||
573+
(proc->prorettype==OPAQUEOID&&proc->pronargs==0))
574+
istrigger= true;
575+
576+
ReleaseSysCache(tuple);
577+
578+
prodesc=compile_plperl_function(funcoid,istrigger);
579+
580+
/* the result of a validator is ignored */
581+
PG_RETURN_VOID();
582+
}
583+
544584

545585
/* Uses mksafefunc/mkunsafefunc to create an anonymous sub whose text is
546586
* supplied in s, and returns a reference to the closure. */
@@ -600,7 +640,7 @@ plperl_create_sub(char *s, bool trusted)
600640
*/
601641
subref=newSVsv(POPs);
602642

603-
if (!SvROK(subref))
643+
if (!SvROK(subref)||SvTYPE(SvRV(subref))!=SVt_PVCV)
604644
{
605645
PUTBACK;
606646
FREETMPS;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp