Re: BUG #13638: Exception texts from plperl has bad encoding

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: lei(at)aswsyst(dot)cz
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #13638: Exception texts from plperl has bad encoding
Date: 2015-09-25 19:18:28
Message-ID: 18105.1443208708@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

lei(at)aswsyst(dot)cz writes:
> I have UTF-8 database and using UTF-8 text in plpgsql and plperl functions.
> Everything works ok, only exceptions from plperl functions have bad encoding
> (maybe double encoded).

> Compare output of these 2 functions:

> create or replace function perl_test() returns text
> language plperl as $$
> return "esk text ";
> $$;

> create or replace function perl_test_err() returns text
> language plperl as $$
> elog(ERROR, "esk chyba ");
> $$;

I traced through this example to the extent of finding that:

* The string passed to elog() in do_util_elog() seems correctly
encoded.

* So does the string passed to croak() after elog does its longjmp,
which is unsurprising since elog.c doesn't really do anything to it.

* Back in plperl_call_perl_func, we use sv2cstr(ERRSV) to get the
error string. sv2cstr calls "SvPVutf8(sv, len)", and that is what
is giving back the bogusly-encoded data.

I suspect the root problem is that instead of baldly doing

croak("%s", edata->message);

in do_util_elog(), we need to do something to inform Perl what encoding
the message string is in. This is beyond my Perl-fu, however.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2015-09-25 19:33:44 Re: BUG #13638: Exception texts from plperl has bad encoding
Previous Message finzelj 2015-09-25 18:38:59 BUG #13640: Delete isn't using available Index Only Scan