*** plperl.c.orig	Mon Nov 29 21:11:05 2004
--- plperl.c	Sun Dec  5 19:09:08 2004
***************
*** 50,55 ****
--- 50,56 ----
  #include "funcapi.h"
  #include "utils/lsyscache.h"
  #include "utils/typcache.h"
+ #include "mb/pg_wchar.h"
  
  /* perl stuff */
  #include "EXTERN.h"
***************
*** 705,716 ****
  		else
  		{
  			char	   *tmp;
  
  			tmp = DatumGetCString(FunctionCall3(&(desc->arg_out_func[i]),
  												fcinfo->arg[i],
  									ObjectIdGetDatum(desc->arg_typioparam[i]),
  												Int32GetDatum(-1)));
! 			XPUSHs(sv_2mortal(newSVpv(tmp, 0)));
  			pfree(tmp);
  		}
  	}
--- 706,722 ----
  		else
  		{
  			char	   *tmp;
+ 			SV			*sv;
  
  			tmp = DatumGetCString(FunctionCall3(&(desc->arg_out_func[i]),
  												fcinfo->arg[i],
  									ObjectIdGetDatum(desc->arg_typioparam[i]),
  												Int32GetDatum(-1)));
! 			sv = newSVpv(tmp, 0);
! #if PERL_BCDVERSION >= 0x5006000L
! 			if (GetDatabaseEncoding() == PG_UTF8) SvUTF8_on(sv);
! #endif
! 			XPUSHs(sv_2mortal(sv));
  			pfree(tmp);
  		}
  	}
***************
*** 1390,1396 ****
  		Oid			typioparam;
  		bool		typisvarlena;
  		int			namelen;
! 
  		if (tupdesc->attrs[i]->attisdropped)
  			continue;
  
--- 1396,1403 ----
  		Oid			typioparam;
  		bool		typisvarlena;
  		int			namelen;
! 		SV			*sv;
! 		
  		if (tupdesc->attrs[i]->attisdropped)
  			continue;
  
***************
*** 1413,1420 ****
  													 attr,
  											ObjectIdGetDatum(typioparam),
  						   Int32GetDatum(tupdesc->attrs[i]->atttypmod)));
! 
! 		hv_store(hv, attname, namelen, newSVpv(outputstr, 0), 0);
  	}
  
  	return newRV_noinc((SV *) hv);
--- 1420,1430 ----
  													 attr,
  											ObjectIdGetDatum(typioparam),
  						   Int32GetDatum(tupdesc->attrs[i]->atttypmod)));
! 		sv = newSVpv(outputstr, 0);
! #if PERL_BCDVERSION >= 0x5006000L
! 		if (GetDatabaseEncoding() == PG_UTF8) SvUTF8_on(sv);
! #endif
! 		hv_store(hv, attname, namelen, sv, 0);
  	}
  
  	return newRV_noinc((SV *) hv);
