3333 * ENHANCEMENTS, OR MODIFICATIONS.
3434 *
3535 * IDENTIFICATION
36- * $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.58 2004/11/18 21:35:42 tgl Exp $
36+ * $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.59 2004/11/20 19:07:40 tgl Exp $
3737 *
3838 **********************************************************************/
3939
4040#include "postgres.h"
4141
4242/* system stuff */
43+ #include <ctype.h>
4344#include <fcntl.h>
4445#include <unistd.h>
4546
@@ -281,6 +282,21 @@ plperl_safe_init(void)
281282}
282283
283284
285+ /*
286+ * Perl likes to put a newline after its error messages; clean up such
287+ */
288+ static char *
289+ strip_trailing_ws (const char * msg )
290+ {
291+ char * res = pstrdup (msg );
292+ int len = strlen (res );
293+
294+ while (len > 0 && isspace ((unsignedchar )res [len - 1 ]))
295+ res [-- len ]= '\0' ;
296+ return res ;
297+ }
298+
299+
284300static HV *
285301plperl_hash_from_tuple (HeapTuple tuple ,TupleDesc tupdesc )
286302{
@@ -496,7 +512,7 @@ plperl_get_elem(HV *hash, char *key)
496512{
497513SV * * svp = hv_fetch (hash ,key ,strlen (key ), FALSE);
498514if (!svp )
499- elog (ERROR ,"plperl: key'%s' not found" ,key );
515+ elog (ERROR ,"plperl: key\"%s\" not found" ,key );
500516return SvTYPE (* svp )== SVt_NULL ?NULL :SvPV (* svp ,PL_na );
501517}
502518
@@ -533,7 +549,7 @@ plperl_modify_tuple(HV *hvTD, TriggerData *tdata, HeapTuple otup, Oid fn_oid)
533549plkeys = plperl_get_keys (hvNew );
534550natts = av_len (plkeys )+ 1 ;
535551if (natts != tupdesc -> natts )
536- elog (ERROR ,"plperl: $_TD->{new} has an incorrect number of keys. " );
552+ elog (ERROR ,"plperl: $_TD->{new} has an incorrect number of keys" );
537553
538554modattrs = palloc0 (natts * sizeof (int ));
539555modvalues = palloc0 (natts * sizeof (Datum ));
@@ -550,7 +566,7 @@ plperl_modify_tuple(HV *hvTD, TriggerData *tdata, HeapTuple otup, Oid fn_oid)
550566attn = modattrs [i ]= SPI_fnumber (tupdesc ,platt );
551567
552568if (attn == SPI_ERROR_NOATTRIBUTE )
553- elog (ERROR ,"plperl: invalid attribute`%s' in tuple. " ,platt );
569+ elog (ERROR ,"plperl: invalid attribute\"%s\" in tuple" ,platt );
554570atti = attn - 1 ;
555571
556572plval = plperl_get_elem (hvNew ,platt );
@@ -581,7 +597,7 @@ plperl_modify_tuple(HV *hvTD, TriggerData *tdata, HeapTuple otup, Oid fn_oid)
581597pfree (modvalues );
582598pfree (modnulls );
583599if (rtup == NULL )
584- elog (ERROR ,"plperl: SPI_modifytuple failed -- error: %d" ,SPI_result );
600+ elog (ERROR ,"plperl: SPI_modifytuple failed -- error: %d" ,SPI_result );
585601
586602return rtup ;
587603}
@@ -690,7 +706,8 @@ plperl_create_sub(char *s, bool trusted)
690706PUTBACK ;
691707FREETMPS ;
692708LEAVE ;
693- elog (ERROR ,"creation of function failed: %s" ,SvPV (ERRSV ,PL_na ));
709+ elog (ERROR ,"creation of function failed: %s" ,
710+ strip_trailing_ws (SvPV (ERRSV ,PL_na )));
694711}
695712
696713/*
@@ -816,7 +833,8 @@ plperl_call_perl_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo)
816833PUTBACK ;
817834FREETMPS ;
818835LEAVE ;
819- elog (ERROR ,"error from function: %s" ,SvPV (ERRSV ,PL_na ));
836+ elog (ERROR ,"error from function: %s" ,
837+ strip_trailing_ws (SvPV (ERRSV ,PL_na )));
820838}
821839
822840retval = newSVsv (POPs );
@@ -860,7 +878,7 @@ plperl_call_perl_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo, S
860878PUTBACK ;
861879FREETMPS ;
862880LEAVE ;
863- elog (ERROR ,"plperl: didn't get a return item from function" );
881+ elog (ERROR ,"didn't get a return item from trigger function" );
864882}
865883
866884if (SvTRUE (ERRSV ))
@@ -869,7 +887,8 @@ plperl_call_perl_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo, S
869887PUTBACK ;
870888FREETMPS ;
871889LEAVE ;
872- elog (ERROR ,"plperl: error from function: %s" ,SvPV (ERRSV ,PL_na ));
890+ elog (ERROR ,"error from trigger function: %s" ,
891+ strip_trailing_ws (SvPV (ERRSV ,PL_na )));
873892}
874893
875894retval = newSVsv (POPs );