pgsql: Make plperl's handling of Perl hashes more consistent.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Make plperl's handling of Perl hashes more consistent.
Date: 2026-08-18 21:47:20
Message-ID: E1wwReQ-000000017Iz-46V7@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Make plperl's handling of Perl hashes more consistent.

Make hek2cstr() available in plperl.h, so that it can be used
in hstore_plperl and jsonb_plperl. Those modules were previously
using different coding techniques that probably don't get
conversion from Perl strings to the database encoding quite right.
(I'd prefer to make hek2cstr() non-inline, but cross-extension calls
are messy and plperl has avoided them up to now, so stick with the
existing approach.)

Consistently use hv_iternext, hek2cstr, and HeVAL for hash iterations,
with one exception in plperl_trusted_init: there, hv_iternextsv is
fine since we don't actually care about the hash keys. (A later
patch will remove the HeVAL calls again, but for now we just want
consistency.)

Remove unnecessary extra calls of hv_iterinit.

Remove duplicative pstrdup's in plperl_to_hstore.

The meat of this change is to use hek2cstr() in the contrib modules,
which makes a user-visible change in encoding conversion behavior.
While it's certainly a bug fix, we've had no field complaints about
those modules, so I'm hesitant to make this change in the back
branches. Hence, apply to master only.

Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Reviewed-by: Andrey Rachitskiy <pl0h0yp1(at)gmail(dot)com>
Discussion: https://postgr.es/m/569769.1786901901@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/5bf8fee543a19ca9ffa5aa99046adae34ba6a864

Modified Files
--------------
contrib/hstore_plperl/hstore_plperl.c | 6 ++--
contrib/jsonb_plperl/jsonb_plperl.c | 13 ++++----
src/pl/plperl/plperl.c | 59 +----------------------------------
src/pl/plperl/plperl.h | 55 ++++++++++++++++++++++++++++++++
4 files changed, 66 insertions(+), 67 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2026-08-19 00:52:46 pgsql: Report single-page checksum failures in pg_stat_database
Previous Message Tom Lane 2026-08-18 21:34:21 pgsql: Defend against null "SV *" pointers in plperl modules.