Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZfYVw-0000Ny-Ju for pgsql-bugs@arkaria.postgresql.org; Fri, 25 Sep 2015 19:18:36 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZfYVv-0005Yi-Qh for pgsql-bugs@arkaria.postgresql.org; Fri, 25 Sep 2015 19:18:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZfYVv-0005YL-40 for pgsql-bugs@postgresql.org; Fri, 25 Sep 2015 19:18:35 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZfYVs-000691-AW for pgsql-bugs@postgresql.org; Fri, 25 Sep 2015 19:18:34 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id t8PJISaF018106; Fri, 25 Sep 2015 15:18:28 -0400 From: Tom Lane To: lei@aswsyst.cz cc: pgsql-bugs@postgresql.org Subject: Re: BUG #13638: Exception texts from plperl has bad encoding In-reply-to: <20150925112345.26913.28407@wrigleys.postgresql.org> References: <20150925112345.26913.28407@wrigleys.postgresql.org> Comments: In-reply-to lei@aswsyst.cz message dated "Fri, 25 Sep 2015 11:23:45 -0000" Date: Fri, 25 Sep 2015 15:18:28 -0400 Message-ID: <18105.1443208708@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org lei@aswsyst.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 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs