3333 * ENHANCEMENTS, OR MODIFICATIONS.
3434 *
3535 * IDENTIFICATION
36- * $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.57 2004/11/17 21:23:36 tgl Exp $
36+ * $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.58 2004/11/18 21:35:42 tgl Exp $
3737 *
3838 **********************************************************************/
3939
@@ -240,7 +240,6 @@ plperl_init_interp(void)
240240 * Initialize the proc and query hash tables
241241 ************************************************************/
242242plperl_proc_hash = newHV ();
243-
244243}
245244
246245
@@ -497,10 +496,7 @@ plperl_get_elem(HV *hash, char *key)
497496{
498497SV * * svp = hv_fetch (hash ,key ,strlen (key ), FALSE);
499498if (!svp )
500- {
501499elog (ERROR ,"plperl: key '%s' not found" ,key );
502- return NULL ;
503- }
504500return SvTYPE (* svp )== SVt_NULL ?NULL :SvPV (* svp ,PL_na );
505501}
506502
@@ -659,7 +655,10 @@ plperl_create_sub(char *s, bool trusted)
659655int count ;
660656
661657if (trusted && !plperl_safe_init_done )
658+ {
662659plperl_safe_init ();
660+ SPAGAIN ;
661+ }
663662
664663ENTER ;
665664SAVETMPS ;
@@ -760,50 +759,40 @@ plperl_call_perl_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo)
760759XPUSHs (sv_2mortal (newSVpv ("undef" ,0 )));
761760for (i = 0 ;i < desc -> nargs ;i ++ )
762761{
763- if (desc -> arg_is_rowtype [i ])
762+ if (fcinfo -> argnull [i ])
763+ XPUSHs (& PL_sv_undef );
764+ else if (desc -> arg_is_rowtype [i ])
764765{
765- if (fcinfo -> argnull [i ])
766- XPUSHs (& PL_sv_undef );
767- else
768- {
769- HeapTupleHeader td ;
770- Oid tupType ;
771- int32 tupTypmod ;
772- TupleDesc tupdesc ;
773- HeapTupleData tmptup ;
774- SV * hashref ;
775-
776- td = DatumGetHeapTupleHeader (fcinfo -> arg [i ]);
777- /* Extract rowtype info and find a tupdesc */
778- tupType = HeapTupleHeaderGetTypeId (td );
779- tupTypmod = HeapTupleHeaderGetTypMod (td );
780- tupdesc = lookup_rowtype_tupdesc (tupType ,tupTypmod );
781- /* Build a temporary HeapTuple control structure */
782- tmptup .t_len = HeapTupleHeaderGetDatumLength (td );
783- tmptup .t_data = td ;
784-
785- /*
786- * plperl_build_tuple_argument better return a mortal SV.
787- */
788- hashref = plperl_build_tuple_argument (& tmptup ,tupdesc );
789- XPUSHs (hashref );
790- }
766+ HeapTupleHeader td ;
767+ Oid tupType ;
768+ int32 tupTypmod ;
769+ TupleDesc tupdesc ;
770+ HeapTupleData tmptup ;
771+ SV * hashref ;
772+
773+ td = DatumGetHeapTupleHeader (fcinfo -> arg [i ]);
774+ /* Extract rowtype info and find a tupdesc */
775+ tupType = HeapTupleHeaderGetTypeId (td );
776+ tupTypmod = HeapTupleHeaderGetTypMod (td );
777+ tupdesc = lookup_rowtype_tupdesc (tupType ,tupTypmod );
778+ /* Build a temporary HeapTuple control structure */
779+ tmptup .t_len = HeapTupleHeaderGetDatumLength (td );
780+ tmptup .t_data = td ;
781+
782+ /* plperl_build_tuple_argument better return a mortal SV */
783+ hashref = plperl_build_tuple_argument (& tmptup ,tupdesc );
784+ XPUSHs (hashref );
791785}
792786else
793787{
794- if (fcinfo -> argnull [i ])
795- XPUSHs (& PL_sv_undef );
796- else
797- {
798- char * tmp ;
799-
800- tmp = DatumGetCString (FunctionCall3 (& (desc -> arg_out_func [i ]),
801- fcinfo -> arg [i ],
802- ObjectIdGetDatum (desc -> arg_typioparam [i ]),
803- Int32GetDatum (-1 )));
804- XPUSHs (sv_2mortal (newSVpv (tmp ,0 )));
805- pfree (tmp );
806- }
788+ char * tmp ;
789+
790+ tmp = DatumGetCString (FunctionCall3 (& (desc -> arg_out_func [i ]),
791+ fcinfo -> arg [i ],
792+ ObjectIdGetDatum (desc -> arg_typioparam [i ]),
793+ Int32GetDatum (-1 )));
794+ XPUSHs (sv_2mortal (newSVpv (tmp ,0 )));
795+ pfree (tmp );
807796}
808797}
809798PUTBACK ;
@@ -848,6 +837,7 @@ plperl_call_perl_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo, S
848837{
849838dSP ;
850839SV * retval ;
840+ Trigger * tg_trigger ;
851841int i ;
852842int count ;
853843
@@ -856,8 +846,9 @@ plperl_call_perl_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo, S
856846
857847PUSHMARK (sp );
858848XPUSHs (td );
859- for (i = 0 ;i < ((TriggerData * )fcinfo -> context )-> tg_trigger -> tgnargs ;i ++ )
860- XPUSHs (sv_2mortal (newSVpv (((TriggerData * )fcinfo -> context )-> tg_trigger -> tgargs [i ],0 )));
849+ tg_trigger = ((TriggerData * )fcinfo -> context )-> tg_trigger ;
850+ for (i = 0 ;i < tg_trigger -> tgnargs ;i ++ )
851+ XPUSHs (sv_2mortal (newSVpv (tg_trigger -> tgargs [i ],0 )));
861852PUTBACK ;
862853
863854count = perl_call_sv (desc -> reference ,G_SCALAR |G_EVAL |G_KEEPERR );