Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1psoBc-000427-SN for pgsql-bugs@arkaria.postgresql.org; Sat, 29 Apr 2023 17:16:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1psoBb-0004vF-OO for pgsql-bugs@arkaria.postgresql.org; Sat, 29 Apr 2023 17:16:39 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1psoBb-0004uz-FV for pgsql-bugs@lists.postgresql.org; Sat, 29 Apr 2023 17:16:39 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1psoBU-002YpF-Nb for pgsql-bugs@lists.postgresql.org; Sat, 29 Apr 2023 17:16:38 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 33THGUp41805879; Sat, 29 Apr 2023 13:16:30 -0400 From: Tom Lane To: Alexander Lakhin cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17912: Invalid memory access when converting plpython' array containing empty array In-reply-to: <5ebae5e4-d401-fadf-8585-ac3eaf53219c@gmail.com> References: <17912-82ceed78731d9cdc@postgresql.org> <1392974.1682694846@sss.pgh.pa.us> <1440309.1682705916@sss.pgh.pa.us> <1483429.1682709429@sss.pgh.pa.us> <5ebae5e4-d401-fadf-8585-ac3eaf53219c@gmail.com> Comments: In-reply-to Alexander Lakhin message dated "Sat, 29 Apr 2023 16:00:00 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1805877.1682788590.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 29 Apr 2023 13:16:30 -0400 Message-ID: <1805878.1682788590@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Alexander Lakhin writes: > Thanks for fixing this! > Now python's handling of arrays is much nicer and is aligned with the pl= perl's behaviour: Well, mostly. As you noticed, it's a bit weird about zero-length sub-lists, treating those as scalars. I had been intending to keep the existing behavior there, but now that I see that plperl does it the other way (that is, you end up with an overall empty output array) I think we ought to make plpython do likewise. > While playing with plperl, I found that it handles arrays not perfectly = too: > CREATE OR REPLACE FUNCTION test_pl() RETURNS text[] AS $$return [1, []];= $$ LANGUAGE plperl; > SELECT * FROM test_pl(); Ugh. I pushed a fix for that. On the whole, I like plperl's implementation of this better, that is it scans the data structure just once and uses an ArrayBuildState to accumulate the datums. So now I'm thinking about throwing out the code in PLySequence_ToArray[_recurse] altogether and borrowing plperl's logic. I think that would make it easier to deal with zero-length sublists correctly. Haven't written the patch yet though. > I suppose that waiting for v17 is preferable if the patch is considered = as > bringing a new feature (it's not the case) or could require extra time t= o > stabilize. But I'm afraid that anomalies, that would require additional > fixes for the change stabilization, could be related to the existing > code, and thus that extra time will be invested in improving v16- too. I'm a little uncomfortable with changing the semantics of non-failing cases in the back branches. regards, tom lane