Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZgbJM-0003FS-Hv for pgsql-bugs@arkaria.postgresql.org; Mon, 28 Sep 2015 16:29:56 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZgbJM-0006C6-0r for pgsql-bugs@arkaria.postgresql.org; Mon, 28 Sep 2015 16:29:56 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZgbIj-0005VK-VO for pgsql-bugs@postgresql.org; Mon, 28 Sep 2015 16:29:18 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZgbIg-0007fg-Jf for pgsql-bugs@postgresql.org; Mon, 28 Sep 2015 16:29:16 +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 t8SGS3sU023014; Mon, 28 Sep 2015 12:28:03 -0400 From: Tom Lane To: Alex Hunsaker cc: Tim Bunce , Alvaro Herrera , lei@aswsyst.cz, pgsql-bugs Subject: Re: BUG #13638: Exception texts from plperl has bad encoding In-reply-to: References: <20150925112345.26913.28407@wrigleys.postgresql.org> <18105.1443208708@sss.pgh.pa.us> <18478.1443209624@sss.pgh.pa.us> <20150925195120.GL295765@alvherre.pgsql> <20150927141148.GA1416@timac.local> <13303.1443397579@sss.pgh.pa.us> Comments: In-reply-to Alex Hunsaker message dated "Sun, 27 Sep 2015 18:20:23 -0600" Date: Mon, 28 Sep 2015 12:28:03 -0400 Message-ID: <23013.1443457683@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 Alex Hunsaker writes: > Yeah, I was just looking at that. I couldn't find a good way to support > 5.8. Doing: ... > Works, but screws up the error line numbers. I looked into this and determined that the problem is that the location info doesn't get appended to ERRSV until after Perl has popped the stack. A possibly-entirely-wrong hack that seems to fix that is to use mess() to construct the SV, *and* append the location info, before we croak. I tried this implementation of croak_cstr: char *utf8_str = utf_e2u(str); SV *ssv = mess("%s", utf8_str); SV *errsv = get_sv("@", GV_ADD); SvUTF8_on(ssv); pfree(utf8_str); sv_setsv(errsv, ssv); croak(NULL); with Perl 5.8.9 and it passed your proposed regression test. Obvious questions include: * I don't see mess() in the perlapi man page, so is it okay to use? * Is there any leakage involved in this? (I don't know what prompted you to add sv_2mortal() to the other implementation, but maybe we need it here too?) * Is there some other reason why this is wrong or a bad idea? Since we'd only use this with versions lacking croak_sv(), future-proofing doesn't seem like a good argument against it, but maybe there is another one. BTW, I think we can't actually use this regression test case, because it won't work as-is in non-UTF8 encodings. But the use of UTF8 characters in the string doesn't seem like an essential property of the test. However, other test cases may already provide sufficient coverage if we're not going to test encoding conversion. Also, I'm inclined to leave do_util_elog() alone other than replacing croak("%s", edata->message) with croak_cstr(edata->message). Since we have to have croak_cstr() anyway, there seems little value in taking any risk that we've missed some reason why the existing coding there is important. 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