pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Alexander Lakhin <exclusion@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17912: Invalid memory access when converting plpython' array containing empty array
Date: Sat, 29 Apr 2023 13:16:30 -0400
Message-ID: <1805878.1682788590@sss.pgh.pa.us> (raw)
In-Reply-To: <5ebae5e4-d401-fadf-8585-ac3eaf53219c@gmail.com>
References: <17912-82ceed78731d9cdc@postgresql.org>
	<1392974.1682694846@sss.pgh.pa.us>
	<bf33fe9b-f2f8-5885-aae3-537cd4591386@gmail.com>
	<1440309.1682705916@sss.pgh.pa.us>
	<1483429.1682709429@sss.pgh.pa.us>
	<5ebae5e4-d401-fadf-8585-ac3eaf53219c@gmail.com>

Alexander Lakhin <exclusion@gmail.com> writes:
> Thanks for fixing this!
> Now python's handling of arrays is much nicer and is aligned with the plperl'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 to
> 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





view thread (12+ messages)  latest in thread

Message-ID: <1805878.1682788590@sss.pgh.pa.us>
Permalink:  ../1805878.1682788590@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1805878.1682788590@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, exclusion@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #17912: Invalid memory access when converting plpython' array containing empty array
  In-Reply-To: <1805878.1682788590@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox